premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.2k stars 618 forks source link

Make failing Command Tokens fail the build #2200

Closed Tisten closed 6 months ago

Tisten commented 6 months ago

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"
}
Jarod42 commented 6 months ago

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

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