Browse Source

Improver error handling when executing shell commands in build scripts.

pull/621/head
Joao Matos 10 years ago
parent
commit
62fe33efad
  1. 6
      build/scripts/Build.lua
  2. 10
      build/scripts/LLVM.lua
  3. 16
      build/scripts/Utils.lua

6
build/scripts/Build.lua

@ -22,7 +22,7 @@ function msbuild(sln, conf) @@ -22,7 +22,7 @@ function msbuild(sln, conf)
cmd = cmd .. " /p:Configuration=" .. conf
end
execute(cmd)
execute_or_die(cmd)
end
function ninja(dir, action)
@ -30,7 +30,7 @@ function ninja(dir, action) @@ -30,7 +30,7 @@ function ninja(dir, action)
if action then
cmd = cmd .. " " .. action
end
return execute(cmd)
return execute_or_die(cmd)
end
function run_premake(file, action)
@ -40,7 +40,7 @@ function run_premake(file, action) @@ -40,7 +40,7 @@ function run_premake(file, action)
end
local cmd = string.format("%s --file=%s %s", _PREMAKE_COMMAND, file, action)
return execute(cmd)
return execute_or_die(cmd)
end
function build_cppsharp()

10
build/scripts/LLVM.lua

@ -68,12 +68,12 @@ function get_llvm_configuration_name(debug) @@ -68,12 +68,12 @@ function get_llvm_configuration_name(debug)
end
function extract_7z(archive, dest_dir)
return execute(string.format("7z x %s -o%s -y", archive, dest_dir), true)
return execute_or_die(string.format("7z x %s -o%s -y", archive, dest_dir), true)
end
function extract_tar_xz(archive, dest_dir)
execute("mkdir -p " .. dest_dir, true)
return execute(string.format("tar xJf %s -C %s", archive, dest_dir), true)
return execute_or_die(string.format("tar xJf %s -C %s", archive, dest_dir), true)
end
local use_7zip = os.is("windows")
@ -180,7 +180,7 @@ function cmake(gen, conf, options) @@ -180,7 +180,7 @@ function cmake(gen, conf, options)
.. ' -DLLVM_TARGETS_TO_BUILD="X86"'
.. ' -DCMAKE_BUILD_TYPE=' .. conf .. ' ..'
.. ' ' .. options
execute(cmd)
execute_or_die(cmd)
os.chdir(cwd)
end
@ -262,9 +262,9 @@ function archive_llvm(dir) @@ -262,9 +262,9 @@ function archive_llvm(dir)
local cwd = os.getcwd()
os.chdir(dir)
if use_7zip then
execute("7z a " .. path.join("..", archive) .. " *")
execute_or_die("7z a " .. path.join("..", archive) .. " *")
else
execute("tar cJf " .. path.join("..", archive) .. " *")
execute_or_die("tar cJf " .. path.join("..", archive) .. " *")
end
os.chdir(cwd)
if is_vagrant() then

16
build/scripts/Utils.lua

@ -21,6 +21,14 @@ function execute(cmd, quiet) @@ -21,6 +21,14 @@ function execute(cmd, quiet)
end
end
function execute_or_die(cmd, quiet)
local res = execute(cmd, quiet)
if res > 0 then
error("Error executing shell command, aborting...")
end
return res
end
function sudo(cmd)
return os.execute("sudo " .. cmd)
end
@ -39,22 +47,22 @@ function git.clone(dir, url, target) @@ -39,22 +47,22 @@ function git.clone(dir, url, target)
if target ~= nil then
cmd = cmd .. " " .. target
end
return execute(cmd)
return execute_or_die(cmd)
end
function git.pull_rebase(dir)
local cmd = "git -C " .. path.translate(dir, sep) .. " pull --rebase"
return execute(cmd)
return execute_or_die(cmd)
end
function git.reset_hard(dir, rev)
local cmd = "git -C " .. path.translate(dir, sep) .. " reset --hard " .. rev
return execute(cmd)
return execute_or_die(cmd)
end
function git.checkout(dir, rev)
local cmd = "git -C " .. path.translate(dir, sep) .. " checkout " .. rev
return execute(cmd)
return execute_or_die(cmd)
end
function git.rev_parse(dir, rev)

Loading…
Cancel
Save