premake / premake-core

Premake

Home Page:https://premake.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make failing Command Tokens fail the build

Tisten opened this issue · comments

What problem will this solve?
When using multiple command tokens only the last one will represent the failure state, thus each of the Command tokens ought to abort on error.

What might be a solution?
As an example, instead of expanding {COPYFILE} to copy /B /Y {args} on DOS/cmd if might expand to copy /B /Y {args}\nif %errorlevel% neq 0 (echo copy FAILED && exit /b %errorlevel%) then the postbuild would abort with an error which e.g Visual Studio picks up.

On Windows I commonly post copy the build results, e.g

postbuildcommands {
    "{MKDIR} " .. path,
    "{COPYFILE} file1 " .. path .. "file1",
    "{COPYFILE} file2 " .. path .. "file2"
}

If the copy of file1 fails but file2 succeeds then the entire postbuildcommands is a success and the build will not fail, thus the file1 wont be copied in the next build. Since Windows locks files which are used this happens surprisingly often in my team.

What other alternatives have you already considered?
The alternative is to always insert this extra code myself, but I really like the readability and platform portability of the Command tokens.

postbuildcommands {
    "{MKDIR} " .. path,
    "if %errorlevel% neq 0 (echo mkdir FAILED && exit /b %errorlevel%)",
    "{COPYFILE} file.dll " .. path .. "file.dll",
    "if %errorlevel% neq 0 (echo copy FAILED && exit /b %errorlevel%)",
    "{COPYFILE} file.pdb " .. path .. "file.pdb"
}

There is still && which should work for your case:

postbuildcommands {
    "{MKDIR} %[" .. path .. "] && {COPYFILE} %[file1] %[" .. path .. "file1] && {COPYFILE} %[file2] %[" .. path .. "file2]"
}