Skip to content

Instantly share code, notes, and snippets.

@tomilov
Last active November 24, 2015 05:33
Show Gist options
  • Save tomilov/a5442309c9e3302d24e3 to your computer and use it in GitHub Desktop.
Save tomilov/a5442309c9e3302d24e3 to your computer and use it in GitHub Desktop.
Lua script to clone latest revision of boost repository and to clone latest revisions of all the submodules. Also containing hints of how to build and install boost complitely. The download traffic is minimal possible: only single branch, only latest revision of the branch.
-- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
local branch = arg[3] or 'master'
function execute(command)
print('# ' .. command)
return os.execute(command)
end
-- execute('rm -rf ' .. module)
if not execute('git clone --single-branch --branch ' .. branch .. ' --depth=1 ' .. module_url .. ' ' .. module) then
io.stderr:write('can\'t clone repository from ' .. module_url .. ' to ' .. module .. '\n')
return 1
end
-- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
execute('mkdir -p ' .. module .. '/.git/modules')
assert(io.input(module .. '/.gitmodules'))
local lines = {}
for line in io.lines() do
table.insert(lines, line)
end
local submodule
local path
local submodule_url
for _, line in ipairs(lines) do
local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
if submodule_ then
submodule = submodule_
path = nil
submodule_url = nil
else
local path_ = line:match('^%s*path = (.+)$')
if path_ then
path = path_
else
submodule_url = line:match('^%s*url = (.+)$')
end
if submodule and path and submodule_url then
-- execute('rm -rf ' .. path)
local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
-- execute('rm -rf ' .. git_dir)
execute('mkdir -p $(dirname "' .. git_dir .. '")')
if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
io.stderr:write('can\'t clone submodule ' .. submodule .. '\n')
return 1
end
path = nil
submodule_url = nil
end
end
end
--[[
# after cloning
export CC=clang
export CFLAGS="-march=native"
export CXX=clang++
export CXXFLAGS="-march=native -std=gnu++1z"
export LFLAGS="-march=native"
bash bootstrap.sh --with-toolset=clang
sudo apt-get install libbz2-dev zlibc zlib1g zlib1g-dev
sudo ./b2 -j`nproc` toolset=clang --build-dir=/tmp/build-boost --without-mpi install
# you should to add "-a" key to completely rebuild
# maybe you'll need run this command twice
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment