From 779ed9db7193b95ecc3f68e54555a92f67b903f5 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Sun, 29 Nov 2015 00:19:38 +0000 Subject: [PATCH] Fourth round at build and packaging scripts. --- build/Helpers.lua | 1 + build/LLVM.lua | 19 ++++++++++++--- build/scripts/Build.lua | 8 +++---- build/scripts/Dependencies.lua | 17 -------------- build/scripts/LLVM.lua | 43 +++++++++++++++++++++++++--------- build/scripts/Provision.lua | 17 ++++++++++++-- src/CppParser/premake4.lua | 1 + 7 files changed, 69 insertions(+), 37 deletions(-) delete mode 100644 build/scripts/Dependencies.lua diff --git a/build/Helpers.lua b/build/Helpers.lua index ecec2879..7a2c0f8c 100644 --- a/build/Helpers.lua +++ b/build/Helpers.lua @@ -2,6 +2,7 @@ action = _ACTION or "" +basedir = path.getdirectory(_PREMAKE_COMMAND) depsdir = path.getabsolute("../deps"); srcdir = path.getabsolute("../src"); incdir = path.getabsolute("../include"); diff --git a/build/LLVM.lua b/build/LLVM.lua index 1722f57b..9f60f3ce 100644 --- a/build/LLVM.lua +++ b/build/LLVM.lua @@ -1,9 +1,22 @@ -- Setup the LLVM dependency directories -LLVMRootDir = "../../deps/llvm/" -LLVMBuildDir = "../../deps/llvm/build/" +LLVMRootDir = depsdir .. "/llvm/" +LLVMBuildDir = LLVMRootDir .. "llvm/build/" --- TODO: Search for available system dependencies +require "scripts/LLVM" + +function SearchLLVM() + local pkg_path = basedir .. "/scripts/" .. get_llvm_package_name() + print(path.getabsolute(pkg_path)) + if os.isdir(pkg_path) then + LLVMRootDir = pkg_path + elseif os.isdir(LLVMRootDir) then + else + error("Error finding an LLVM build") + end + + print("Using LLVM build: " .. LLVMRootDir) +end function SetupLLVMIncludes() local c = configuration() diff --git a/build/scripts/Build.lua b/build/scripts/Build.lua index eec669e9..8df639ac 100644 --- a/build/scripts/Build.lua +++ b/build/scripts/Build.lua @@ -25,7 +25,7 @@ function msbuild(sln, conf) execute(cmd) end -function premake(file, action) +function run_premake(file, action) -- search for file with extension Lua if os.isfile(file .. ".lua") then file = file .. ".lua" @@ -37,15 +37,15 @@ end function build_cppsharp() -- install dependencies - premake("Provision", "provision") + run_premake("Provision", "provision") -- if there is an llvm git clone then use it -- otherwise download and extract llvm/clang build - premake("LLVM", "download_llvm") + run_premake("LLVM", "download_llvm") -- generate project files - premake("../premake4", "gmake") + run_premake("../premake4", "gmake") -- build cppsharp --[[BUILD_CONF=release_x32; diff --git a/build/scripts/Dependencies.lua b/build/scripts/Dependencies.lua deleted file mode 100644 index aaafcc23..00000000 --- a/build/scripts/Dependencies.lua +++ /dev/null @@ -1,17 +0,0 @@ -require "Utils" - -function nuget() - if not os.isfile("nuget.exe") then - http.download("https://nuget.org/nuget.exe") - end - - local nugetexe = os.is("windows") and "NuGet.exe" or "mono ./NuGet.exe" - execute(nugetexe .. " restore packages.config -PackagesDirectory ../deps") -end - -clone() - -if _ACTION == "nuget" then - nuget() - os.exit() -end diff --git a/build/scripts/LLVM.lua b/build/scripts/LLVM.lua index e2cf76f0..ccbc84ae 100644 --- a/build/scripts/LLVM.lua +++ b/build/scripts/LLVM.lua @@ -1,7 +1,8 @@ require "Build" require "Utils" +require "../Helpers" -local llvm = "../../deps/llvm" +local llvm = basedir .. "/../../deps/llvm" -- If we are inside vagrant then clone and build LLVM outside the shared folder, -- otherwise file I/O performance will be terrible. @@ -11,11 +12,19 @@ end local llvm_build = llvm .. "/" .. os.get() +function get_llvm_rev() + return cat(basedir .. "/LLVM-commit") +end + +function get_clang_rev() + return cat(basedir .. "/Clang-commit") +end + function clone_llvm() - local llvm_release = cat("../LLVM-commit") + local llvm_release = get_llvm_rev() print("LLVM release: " .. llvm_release) - local clang_release = cat("../Clang-commit") + local clang_release = get_clang_rev() print("Clang release: " .. clang_release) if os.isdir(llvm) and not os.isdir(llvm .. "/.git") then @@ -42,18 +51,28 @@ function clone_llvm() end function get_llvm_package_name(rev, conf) + if not rev then + rev = get_llvm_rev() + end + if not conf then + conf = get_llvm_configuration_name() + end + + rev = string.sub(rev, 0, 6) return table.concat({"llvm", rev, os.get(), conf}, "-") end +function get_llvm_configuration_name() + return os.is("windows") and "RelWithDebInfo" or "Release" +end + function extract_7z(archive, dest_dir) return execute(string.format("7z x %s -o%s -y", archive, dest_dir), true) end function download_llvm() local base = "https://dl.dropboxusercontent.com/u/194502/CppSharp/llvm/" - local conf = os.is("windows") and "RelWithDebInfo" or "Release" - local rev = string.sub(cat("../LLVM-commit"), 0, 6) - local pkg_name = get_llvm_package_name(rev, conf) + local pkg_name = get_llvm_package_name() local archive = pkg_name .. ".7z" -- check if we already have the file downloaded @@ -86,20 +105,21 @@ function clean_llvm(llvm_build) end function build_llvm(llvm_build) + local conf = get_llvm_configuration_name() if os.is("windows") then - cmake("Visual Studio 12 2013", "RelWithDebInfo") + cmake("Visual Studio 12 2013", conf) local llvm_sln = path.join(llvm_build, "LLVM.sln") - msbuild(llvm_sln, "RelWithDebInfo") + msbuild(llvm_sln, conf) else - cmake("Ninja", "Release") + cmake("Ninja", conf) execute("ninja") execute("ninja clang-headers") end end function package_llvm(conf, llvm, llvm_build) - local rev = string.sub(git.rev_parse(llvm, "HEAD"), 0, 6) + local rev = git.rev_parse(llvm, "HEAD") local out = get_llvm_package_name(rev, conf) if os.isdir(out) then os.rmdir(out) end @@ -159,7 +179,8 @@ if _ACTION == "build_llvm" then end if _ACTION == "package_llvm" then - local pkg = package_llvm("RelWithDebInfo", llvm, llvm_build) + local conf = get_llvm_configuration_name() + local pkg = package_llvm(conf, llvm, llvm_build) archive_llvm(pkg) os.exit() end diff --git a/build/scripts/Provision.lua b/build/scripts/Provision.lua index 40d5a4ad..b9d6d011 100644 --- a/build/scripts/Provision.lua +++ b/build/scripts/Provision.lua @@ -45,12 +45,23 @@ function download_cmake() end end +function download_nuget() + if not os.isfile("nuget.exe") then + download("https://nuget.org/nuget.exe", "nuget.exe") + end +end + +function restore_nuget_packages() + local nugetexe = os.is("windows") and "NuGet.exe" or "mono ./NuGet.exe" + execute(nugetexe .. " restore packages.config -PackagesDirectory " .. depsdir) +end + local compile_llvm = is_vagrant() function provision_linux() -- Add Repos - sudo("apt-key adv --keyserver http:////keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF") - sudo("echo \"deb http:////download.mono-project.com/repo/debian wheezy main\" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list") + sudo("apt-key adv --keyserver http://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF") + sudo("echo \"deb http://download.mono-project.com/repo/debian wheezy main\" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list") if is_vagrant() then sudo("add-apt-repository -y ppa:george-edison55/cmake-3.x") @@ -96,3 +107,5 @@ if _ACTION == "provision" then end os.exit() end + + diff --git a/src/CppParser/premake4.lua b/src/CppParser/premake4.lua index 83d0b390..1a04d8a9 100644 --- a/src/CppParser/premake4.lua +++ b/src/CppParser/premake4.lua @@ -37,6 +37,7 @@ project "CppSharp.CppParser" "*.lua" } + SearchLLVM() SetupLLVMIncludes() SetupLLVMLibs()