Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get numeric error-level from os.execute #333

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function update_tag(file,content,tagname,tagdate)
end

function tag_hook(tagname)
os.execute('git commit -a -m "Step release tag"')
return select(3, os.execute('git commit -a -m "Step release tag"'))
end

if not release_date then
Expand Down
6 changes: 3 additions & 3 deletions l3build-check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ function base_compare(test_type,name,engine,cleanup)
if compare then
return compare(difffile, reffile, genfile, cleanup, name, engine)
end
local errorlevel = execute(os_diffexe .. " "
local errorlevel = execute_with_errorlevel(os_diffexe .. " "
.. normalize_path(reffile .. " " .. genfile .. " > " .. difffile))
if errorlevel == 0 or cleanup then
remove(difffile)
Expand All @@ -722,14 +722,14 @@ function compare_tlg(difffile, tlgfile, logfile, cleanup, name, engine)
local luatlgfile = testdir .. "/" .. testname .. tlgext
rewrite(tlgfile,luatlgfile,normalize_lua_log)
rewrite(logfile,lualogfile,normalize_lua_log,true)
errorlevel = execute(os_diffexe .. " "
errorlevel = execute_with_errorlevel(os_diffexe .. " "
.. normalize_path(luatlgfile .. " " .. lualogfile .. " > " .. difffile))
if cleanup then
remove(lualogfile)
remove(luatlgfile)
end
else
errorlevel = execute(os_diffexe .. " "
errorlevel = execute_with_errorlevel(os_diffexe .. " "
.. normalize_path(tlgfile .. " " .. logfile .. " > " .. difffile))
end
if errorlevel == 0 or cleanup then
Expand Down
24 changes: 14 additions & 10 deletions l3build-file-functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ function fileexists(file)
end
end

function execute_with_errorlevel(command)
return select(3, execute(command))
end

-- Copy files 'quietly'
function cp(glob, source, dest)
local errorlevel
Expand All @@ -233,12 +237,12 @@ function cp(glob, source, dest)
-- p_cwd is the counterpart relative to the current working directory
if os_type == "windows" then
if direxists(p.cwd) then
errorlevel = execute(
errorlevel = execute_with_errorlevel(
'xcopy /y /e /i "' .. unix_to_win(p.cwd) .. '" '
.. unix_to_win(dest .. '/' .. escapepath(p.src)) .. ' > nul'
) and 0 or 1
else
errorlevel = execute(
errorlevel = execute_with_errorlevel(
'xcopy /y "' .. unix_to_win(p.cwd) .. '" '
.. unix_to_win(dest .. '/') .. ' > nul'
) and 0 or 1
Expand All @@ -249,7 +253,7 @@ function cp(glob, source, dest)
errorlevel = mkdir(dirname(dest))
if errorlevel ~=0 then return errorlevel end
end
errorlevel = execute(
errorlevel = execute_with_errorlevel(
"cp -RLf '" .. p.cwd .. "' " .. dest
) and 0 or 1
end
Expand Down Expand Up @@ -377,11 +381,11 @@ function mkdir(dir)
-- Windows (with the extensions) will automatically make directory trees
-- but issues a warning if the dir already exists: avoid by including a test
dir = unix_to_win(dir)
return execute(
return execute_with_errorlevel(
"if not exist " .. dir .. "\\nul " .. "mkdir " .. dir
)
else
return execute("mkdir -p " .. dir)
return execute_with_errorlevel("mkdir -p " .. dir)
end
end

Expand All @@ -391,9 +395,9 @@ function ren(dir, source, dest)
if os_type == "windows" then
source = gsub(source, "^%.+/", "")
dest = gsub(dest, "^%.+/", "")
return execute("ren " .. unix_to_win(dir) .. source .. " " .. dest)
return execute_with_errorlevel("ren " .. unix_to_win(dir) .. source .. " " .. dest)
else
return execute("mv " .. dir .. source .. " " .. dir .. dest)
return execute_with_errorlevel("mv " .. dir .. source .. " " .. dir .. dest)
end
end

Expand All @@ -418,15 +422,15 @@ function rmdir(dir)
-- First, make sure it exists to avoid any errors
mkdir(dir)
if os_type == "windows" then
return execute("rmdir /s /q " .. unix_to_win(dir))
return execute_with_errorlevel("rmdir /s /q " .. unix_to_win(dir))
else
return execute("rm -r " .. dir)
return execute_with_errorlevel("rm -r " .. dir)
end
end

-- Run a command in a given directory
function run(dir, cmd)
return execute("cd " .. dir .. os_concat .. cmd)
return execute_with_errorlevel("cd " .. dir .. os_concat .. cmd)
end

-- Split a path into file and directory component
Expand Down
Loading