Browse Source

Second round at build and packaging scripts.

pull/585/head
triton 10 years ago
parent
commit
de5e364a8a
  1. 26
      build/ci/package_llvm_windows.bat
  2. 118
      build/ci/vagrant/ubuntu_x64/Vagrantfile
  3. 7
      build/ci/vagrant/ubuntu_x64/vmsettings.cfg
  4. 36
      build/scripts/Build.lua
  5. 44
      build/scripts/Dependencies.lua
  6. 117
      build/scripts/LLVM.lua
  7. 26
      build/scripts/PackageLLVM.bat
  8. 31
      build/scripts/PackageLLVM.sh
  9. 2
      build/scripts/Provision.sh
  10. 92
      build/scripts/Utils.lua
  11. 40
      build/scripts/Vagrantfile

26
build/ci/package_llvm_windows.bat

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
rmdir /s /q out
mkdir out
mkdir out\tools\clang
mkdir out\tools\clang\lib\CodeGen
mkdir out\tools\clang\lib\Driver
mkdir out\build\
mkdir out\build\tools\clang\
set rbcopy=%systemroot%\System32\robocopy /NDL /NFL /NJH /NJS
set dircopy=%rbcopy% /E
%dircopy% include\ out\include
%dircopy% build\include\ out\build\include
%dircopy% build\RelWithDebInfo\lib out\build\RelWithDebInfo\lib
%dircopy% tools\clang\include\ out\tools\clang\include
copy /Y tools\clang\lib\CodeGen\*.h out\tools\clang\lib\CodeGen >nul
copy /Y tools\clang\lib\Driver\*.h out\tools\clang\lib\Driver >nul
%dircopy% build\tools\clang\include\ out\build\tools\clang\include
del out\build\RelWithDebInfo\lib\LLVM*ObjCARCOpts*.lib
del out\build\RelWithDebInfo\lib\clang*ARC*.lib
del out\build\RelWithDebInfo\lib\clang*Matchers*.lib
del out\build\RelWithDebInfo\lib\clang*Rewrite*.lib
del out\build\RelWithDebInfo\lib\clang*StaticAnalyzer*.lib
del out\build\RelWithDebInfo\lib\clang*Tooling*.lib

118
build/ci/vagrant/ubuntu_x64/Vagrantfile vendored

@ -1,118 +0,0 @@ @@ -1,118 +0,0 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
SCRIPT
Vagrant.configure(2) do |config|
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
config.vm.box = "ubuntu/trusty64"
#load external box config
external = File.read 'vmsettings.cfg'
eval external
# this function fixes errors with ubuntu interactive shell
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
#this section runs as root
config.vm.provision "shell", privileged: true , inline: <<-SHELL
# Add Repos
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo add-apt-repository ppa:george-edison55/cmake-3.x
apt-get update
# Build tools
apt-get install -y git build-essential clang cmake ninja-build
apt-get install -y p7zip-full
# Mono
apt-get install -y mono-devel
SHELL
#this section runs as normal user
config.vm.provision "shell", privileged: false , inline: <<-SHELL
function mkcd () { mkdir -p "$@" && cd "$@"; }
git clone https://github.com/mono/CppSharp.git
cd CppSharp/deps/
git clone https://github.com/llvm-mirror/llvm.git
cd llvm/
llvm_commit=`cat ../../build/LLVM-commit`
git reset --hard $llvm_commit
cd tools/
git clone https://github.com/llvm-mirror/clang.git
cd clang/
clang_commit=`cat ../../../../build/Clang-commit`
git reset --hard $clang_commit
mkcd ../../build
cmake -G Ninja -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false -DCMAKE_BUILD_TYPE=Release ..
ninja
ninja clang-headers
# make the output package
cd ..
if [ -d "out" ]; then rm -rf out; fi
mkdir out
mkdir -p out/lib/clang
mkdir -p out/tools/clang
mkdir -p out/tools/clang/lib/CodeGen
mkdir -p out/tools/clang/lib/Driver
mkdir -p out/build/
mkdir -p out/build/lib
mkdir -p out/build/tools/clang
mkdir -p out/build/tools/clang/lib
cp -R include/ out/
cp -R build/include/ out/build
cp build/lib/*.a out/build/lib
cp -R tools/clang/include/ out/tools/clang
cp -R tools/clang/lib/CodeGen/*.h out/tools/clang/lib/CodeGen
cp -R tools/clang/lib/Driver/*.h out/tools/clang/lib/Driver
cp -R build/lib/clang out/lib/clang
cp -R build/tools/clang/include/ out/build/tools/clang
rm out/build/lib/libllvm*ObjCARCOpts*.a
rm out/build/lib/libclang*ARC*.a
rm out/build/lib/libclang*Matchers*.a
rm out/build/lib/libclang*Rewrite*.a
rm out/build/lib/libclang*StaticAnalyzer*.a
rm out/build/lib/libclang*Tooling*.a
7z a llvm_linux_x86_64.7z ./out/*
# upload to dropbox
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
echo APPKEY= > ~/.dropbox_uploader
echo APPSECRET= >> ~/.dropbox_uploader
echo ACCESS_LEVEL=sandbox >> ~/.dropbox_uploader
echo OAUTH_ACCESS_TOKEN= >> ~/.dropbox_uploader
echo OAUTH_ACCESS_TOKEN_SECRET= >> ~/.dropbox_uploader
./dropbox_uploader.sh upload llvm_linux_x86_64.7z llvm_linux_x86_64.7z
SHELL
end

7
build/ci/vagrant/ubuntu_x64/vmsettings.cfg

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
# Vm config
# Config your vm settings here
config.vm.provider "virtualbox" do |v|
v.memory = 8192
v.cpus = 4
end

36
build/scripts/Build.lua

@ -1,23 +1,7 @@ @@ -1,23 +1,7 @@
require "Utils"
local llvm_build = "../../deps/llvm/build"
function clean_build()
os.rmdir(llvm_build)
os.mkdir(llvm_build)
end
function cmake(gen)
os.chdir(llvm_build)
local cmd = "cmake -G " .. '"' .. gen .. '"'
.. " -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false"
.. ' -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86"'
.. ' -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false -DCMAKE_BUILD_TYPE=Release ..'
execute(cmd)
end
function get_msbuild_path()
local msbuild = '%WINDIR%\\system32\\reg.exe query "HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0" /v MSBuildToolsPath'
local msbuild = '%SystemRoot%\\system32\\reg.exe query "HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0" /v MSBuildToolsPath'
local val = execute(msbuild)
for i in string.gmatch(val, "%S+") do
@ -29,15 +13,17 @@ function get_msbuild_path() @@ -29,15 +13,17 @@ function get_msbuild_path()
error("MSBuild path could not be found in Windows registry.")
end
function msbuild()
function msbuild(sln, conf)
local msbuild_path = path.normalize(path.join(get_msbuild_path(), "msbuild.exe"))
execute(msbuild_path .. " " .. llvm_build)
end
local sln = path.normalize(sln)
local cmd = msbuild_path .. " " .. sln
if conf ~= nil then
cmd = cmd .. " /p:Configuration=" .. conf
end
function ninja()
execute("ninja")
execute("ninja clang-headers")
execute(cmd)
end
clean_build()
cmake("Visual Studio 14 2015")

44
build/scripts/Dependencies.lua

@ -1,39 +1,7 @@ @@ -1,39 +1,7 @@
require "Utils"
function clone()
if not os.isdir("../deps") then
print("mkdir")
os.mkdir(".../deps")
end
local llvm_release = cat("LLVM-commit")
print("LLVM release: " .. llvm_release)
local clang_release = cat("Clang-commit")
print("Clang release: " .. clang_release)
if not os.isdir("../deps/llvm") then
git.clone("../deps/llvm", "http://llvm.org/git/llvm.git")
git.checkout("../deps/llvm", llvm_release)
end
if not os.isdir("../deps/llvm/tools/clang") then
git.clone("../deps/llvm/tools/clang", "http://llvm.org/git/clang.git")
git.checkout("../deps/llvm/tools/clang", clang_release)
end
end
function download()
if os.is("windows") then
http.download("https://dl.dropboxusercontent.com/u/194502/CppSharp/llvm_windows_x86.7z")
end
-- extract the package
7z x llvm_windows_x86.7z -o%DEPS_PATH%\llvm -y > nul
end
function nuget()
if not os.isfile("nuget.exe")
if not os.isfile("nuget.exe") then
http.download("https://nuget.org/nuget.exe")
end
@ -41,17 +9,19 @@ function nuget() @@ -41,17 +9,19 @@ function nuget()
execute(nugetexe .. " restore packages.config -PackagesDirectory ../deps")
end
clone()
if _ACTION == "nuget" then
nuget()
os.exit()
end
if _ACTION == "clone" then
clone()
if _ACTION == "clone_llvm" then
clone_llvm()
os.exit()
end
if _ACTION == "download" then
download()
if _ACTION == "download_llvm" then
download_llvm()
os.exit()
end

117
build/scripts/LLVM.lua

@ -0,0 +1,117 @@ @@ -0,0 +1,117 @@
require "Build"
require "Utils"
local llvm = "../../deps/llvm/"
local llvm_build = "../../deps/llvm/" .. os.get()
function clone_llvm()
local llvm_release = cat("LLVM-commit")
print("LLVM release: " .. llvm_release)
local clang_release = cat("Clang-commit")
print("Clang release: " .. clang_release)
if not os.isdir(llvm) then
git.clone(llvm, "http://llvm.org/git/llvm.git")
git.checkout(llvm, llvm_release)
end
if not os.isdir(llvm .. "/tools/clang") then
git.clone(llvm .. "/tools/clang", "http://llvm.org/git/clang.git")
git.checkout(llvm .. "/tools/clang", clang_release)
end
end
function download_llvm()
if os.is("windows") then
http.download("https://dl.dropboxusercontent.com/u/194502/CppSharp/llvm_windows_x86.7z")
end
-- extract the package
execute("7z x llvm_windows_x86.7z -o%DEPS_PATH%\llvm -y > nul")
end
function cmake(gen, conf)
print(os.getcwd())
print(llvm_build)
os.chdir(llvm_build)
print(os.getcwd())
local cmd = "cmake -G " .. '"' .. gen .. '"'
.. ' -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false'
.. ' -DCLANG_ENABLE_ARCMT=false -DCLANG_ENABLE_REWRITER=false -DCLANG_ENABLE_STATIC_ANALYZER=false'
.. ' -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false'
.. ' -DLLVM_TARGETS_TO_BUILD="X86"'
.. ' -DCMAKE_BUILD_TYPE=' .. conf .. ' ..'
execute(cmd)
end
function clean_llvm(llvm_build)
if os.isdir(llvm_build) then os.rmdir(llvm_build) end
os.mkdir(llvm_build)
end
function build_llvm(llvm_build)
if os.is("windows") then
cmake("Visual Studio 12 2013", "RelWithDebInfo")
local llvm_sln = path.join(llvm_build, "LLVM.sln")
msbuild(llvm_sln, "RelWithDebInfo")
else
cmake("Ninja", "Release")
execute("ninja")
execute("ninja clang-headers")
end
end
function package_llvm(conf, llvm, llvm_build)
local out = "llvm-" .. os.get() .. "-" .. conf
if os.isdir(out) then os.rmdir(out) end
os.mkdir(out)
os.copydir(llvm .. "/include", out .. "/include")
os.copydir(llvm_build .. "/include", out .. "/build/include")
local lib_dir = os.is("windows") and "/" .. conf .. "/lib" or "/lib"
local llvm_build_libdir = llvm_build .. lib_dir
if os.is("windows") then
os.copydir(llvm_build_libdir, out .. "/build" .. lib_dir, "*.lib")
else
os.copydir(llvm_build_libdir, out .. "/build/lib", "*.a")
end
os.copydir(llvm .. "/tools/clang/include", out .. "/tools/clang/include")
os.copydir(llvm_build .. "/tools/clang/include", out .. "/build/tools/clang/include")
os.copydir(llvm .. "/tools/clang/lib/CodeGen", out .. "/tools/clang/lib/CodeGen", "*.h")
os.copydir(llvm .. "/tools/clang/lib/Driver", out .. "/tools/clang/lib/Driver", "*.h")
local out_lib_dir = out .. "/build" .. lib_dir
if os.is("windows") then
os.rmfiles(out_lib_dir, "LLVM*ObjCARCOpts*.lib")
os.rmfiles(out_lib_dir, "clang*ARC*.lib")
os.rmfiles(out_lib_dir, "clang*Matchers*.lib")
os.rmfiles(out_lib_dir, "clang*Rewrite*.lib")
os.rmfiles(out_lib_dir, "clang*StaticAnalyzer*.lib")
os.rmfiles(out_lib_dir, "clang*Tooling*.lib")
else
os.rmfiles(out_lib_dir, "libllvm*ObjCARCOpts*.a")
os.rmfiles(out_lib_dir, "libclang*ARC*.a")
os.rmfiles(out_lib_dir, "libclang*Matchers*.a")
os.rmfiles(out_lib_dir, "libclang*Rewrite*.a")
os.rmfiles(out_lib_dir, "libclang*StaticAnalyzer*.a")
os.rmfiles(out_lib_dir, "libclang*Tooling*.a")
end
return out
end
function archive_llvm(dir)
execute("7z a " .. out .. ".7z " .. "./" .. out .. "/*")
end
clean_llvm(llvm_build)
build_llvm(llvm_build)
--local out = package_llvm("RelWithDebInfo", llvm, llvm_build)
--archive_llvm(out)

26
build/scripts/PackageLLVM.bat

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
rmdir /s /q out
mkdir out
mkdir out\tools\clang
mkdir out\tools\clang\lib\CodeGen
mkdir out\tools\clang\lib\Driver
mkdir out\build\
mkdir out\build\tools\clang\
set rbcopy=%systemroot%\System32\robocopy /NDL /NFL /NJH /NJS
set dircopy=%rbcopy% /E
%dircopy% include\ out\include
%dircopy% build\include\ out\build\include
%dircopy% build\RelWithDebInfo\lib out\build\RelWithDebInfo\lib
%dircopy% tools\clang\include\ out\tools\clang\include
copy /Y tools\clang\lib\CodeGen\*.h out\tools\clang\lib\CodeGen >nul
copy /Y tools\clang\lib\Driver\*.h out\tools\clang\lib\Driver >nul
%dircopy% build\tools\clang\include\ out\build\tools\clang\include
del out\build\RelWithDebInfo\lib\LLVM*ObjCARCOpts*.lib
del out\build\RelWithDebInfo\lib\clang*ARC*.lib
del out\build\RelWithDebInfo\lib\clang*Matchers*.lib
del out\build\RelWithDebInfo\lib\clang*Rewrite*.lib
del out\build\RelWithDebInfo\lib\clang*StaticAnalyzer*.lib
del out\build\RelWithDebInfo\lib\clang*Tooling*.lib

31
build/scripts/PackageLLVM.sh

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
cd ../../deps/llvm
if [ -d "out" ]; then rm -rf out; fi
mkdir out
mkdir -p out/lib/clang
mkdir -p out/tools/clang
mkdir -p out/tools/clang/lib/CodeGen
mkdir -p out/tools/clang/lib/Driver
mkdir -p out/build/
mkdir -p out/build/lib
mkdir -p out/build/tools/clang
mkdir -p out/build/tools/clang/lib
cp -R include/ out/
cp -R build/include/ out/build
cp build/lib/*.a out/build/lib
cp -R tools/clang/include/ out/tools/clang
cp -R tools/clang/lib/CodeGen/*.h out/tools/clang/lib/CodeGen
cp -R tools/clang/lib/Driver/*.h out/tools/clang/lib/Driver
cp -R build/lib/clang out/lib/clang
cp -R build/tools/clang/include/ out/build/tools/clang
rm out/build/lib/libllvm*ObjCARCOpts*.a
rm out/build/lib/libclang*ARC*.a
rm out/build/lib/libclang*Matchers*.a
rm out/build/lib/libclang*Rewrite*.a
rm out/build/lib/libclang*StaticAnalyzer*.a
rm out/build/lib/libclang*Tooling*.a
7z a llvm_linux_x86_64.7z ./out/*

2
build/scripts/Provision.sh

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo add-apt-repository ppa:george-edison55/cmake-3.x
add-apt-repository ppa:george-edison55/cmake-3.x
apt-get update
# Build tools

92
build/scripts/Utils.lua

@ -48,4 +48,96 @@ function download(url, file) @@ -48,4 +48,96 @@ function download(url, file)
if res == nil then
error("Error downloading file " .. file)
end
end
--
-- Allows copying directories.
-- It uses the premake patterns (**=recursive match, *=file match)
-- NOTE: It won't copy empty directories!
-- Example: we have a file: src/test.h
-- os.copydir("src", "include") simple copy, makes include/test.h
-- os.copydir("src", "include", "*.h") makes include/test.h
-- os.copydir(".", "include", "src/*.h") makes include/src/test.h
-- os.copydir(".", "include", "**.h") makes include/src/test.h
-- os.copydir(".", "include", "**.h", true) will force it to include dir, makes include/test.h
--
-- @param src_dir
-- Source directory, which will be copied to dst_dir.
-- @param dst_dir
-- Destination directory.
-- @param filter
-- Optional, defaults to "**". Only filter matches will be copied. It can contain **(recursive) and *(filename).
-- @param single_dst_dir
-- Optional, defaults to false. Allows putting all files to dst_dir without subdirectories.
-- Only useful with recursive (**) filter.
-- @returns
-- True if successful, otherwise nil.
--
function os.copydir(src_dir, dst_dir, filter, single_dst_dir)
filter = filter or "**"
src_dir = src_dir .. "/"
print('copy "' .. path.getabsolute(src_dir) .. filter .. '" to "' .. dst_dir .. '".')
if not os.isdir(src_dir) then error(src_dir .. " is not an existing directory!") end
dst_dir = dst_dir .. "/"
local dir = path.rebase(".",path.getabsolute("."), src_dir) -- root dir, relative from src_dir
os.chdir( src_dir ) -- change current directory to src_dir
local matches = os.matchfiles(filter)
os.chdir( dir ) -- change current directory back to root
local counter = 0
for k, v in ipairs(matches) do
local target = iif(single_dst_dir, path.getname(v), v)
--make sure, that directory exists or os.copyfile() fails
os.mkdir( path.getdirectory(dst_dir .. target))
if os.copyfile( src_dir .. v, dst_dir .. target) then
counter = counter + 1
end
end
if counter == #matches then
print( counter .. " files copied.")
return true
else
print( "Error: " .. counter .. "/" .. #matches .. " files copied.")
return nil
end
end
--
-- Allows removing files from directories.
-- It uses the premake patterns (**=recursive match, *=file match)
--
-- @param src_dir
-- Source directory, which will be copied to dst_dir.
-- @param filter
-- Optional, defaults to "**". Only filter matches will be copied. It can contain **(recursive) and *(filename).
-- @returns
-- True if successful, otherwise nil.
--
function os.rmfiles(src_dir, filter)
filter = filter or "**"
src_dir = src_dir .. "/"
print('rm "' .. path.getabsolute(src_dir) .. filter)
if not os.isdir(src_dir) then error(src_dir .. " is not an existing directory!") end
local dir = path.rebase(".",path.getabsolute("."), src_dir) -- root dir, relative from src_dir
os.chdir( src_dir ) -- change current directory to src_dir
local matches = os.matchfiles(filter)
os.chdir( dir ) -- change current directory back to root
local counter = 0
for k, v in ipairs(matches) do
if os.remove( src_dir .. v) then
counter = counter + 1
end
end
if counter == #matches then
print( counter .. " files removed.")
return true
else
print( "Error: " .. counter .. "/" .. #matches .. " files removed.")
return nil
end
end

40
build/scripts/Vagrantfile vendored

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
SCRIPT
Vagrant.configure(2) do |config|
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
config.vm.box = "ubuntu/trusty64"
#load external box config
config.vm.provider "virtualbox" do |vb|
vb.memory = 8192
vb.cpus = 4
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate//cppsharp","1"]
end
config.vm.synced_folder "../..", "/cppsharp"
# this function fixes errors with ubuntu interactive shell
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
#this section runs as root
config.vm.provision "shell", privileged: true , inline: <<-SHELL
cd /cppsharp/
sudo sh ./build/scripts/Provision.sh
SHELL
#this section runs as normal user
config.vm.provision "shell", privileged: false , inline: <<-SHELL
SHELL
end
Loading…
Cancel
Save