diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-05 20:06:06 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-08 16:50:24 +0300 |
commit | 7fdc55efe423f58e5ce03e7f758ace6443800b7a (patch) | |
tree | abca1c7f4f9ebcf1fbc292ff76469f72ded6ee77 /libbuild2 | |
parent | 10a4ed7c470d3fed8e2bb6b2089de68c61f9064b (diff) |
Cleanup script command failure diagnostics
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/script/run.cxx | 31 | ||||
-rw-r--r-- | libbuild2/script/script.cxx | 6 | ||||
-rw-r--r-- | libbuild2/script/script.hxx | 4 |
3 files changed, 23 insertions, 18 deletions
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 5629a15..46c061c 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -939,8 +939,6 @@ namespace build2 env.clean ({cl.type, move (np)}, false); } - bool eq (c.exit.comparison == exit_comparison::eq); - // If stdin file descriptor is not open then this is the first pipeline // command. // @@ -1012,11 +1010,8 @@ namespace build2 if (c.err) fail (ll) << "exit builtin stderr cannot be redirected"; - // We can't make sure that there is no exit code check. Let's, at - // least, check that non-zero code is not expected. - // - if (eq != (c.exit.code == 0)) - fail (ll) << "exit builtin exit code cannot be non-zero"; + if (c.exit) + fail (ll) << "exit builtin exit code cannot be checked"; if (verb >= 2) print_process (process_args ()); @@ -1168,8 +1163,8 @@ namespace build2 if (c.err) fail (ll) << "set builtin stderr cannot be redirected"; - if (eq != (c.exit.code == 0)) - fail (ll) << "set builtin exit code cannot be non-zero"; + if (c.exit) + fail (ll) << "set builtin exit code cannot be checked"; if (verb >= 2) print_process (process_args ()); @@ -1677,8 +1672,7 @@ namespace build2 // If there is no valid exit code available by whatever reason then we // print the proper diagnostics, dump stderr (if cached and not too // large) and fail the whole script. Otherwise if the exit code is not - // correct then we print diagnostics if requested and fail the - // pipeline. + // correct then we print diagnostics if requested and fail the pipeline. // bool valid (exit->normal ()); @@ -1690,7 +1684,11 @@ namespace build2 valid = exit->code () < 256; #endif - success = valid && eq == (exit->code () == c.exit.code); + exit_comparison cmp (c.exit ? c.exit->comparison : exit_comparison::eq); + uint16_t exc (c.exit ? c.exit->code : 0); + + success = valid && + (cmp == exit_comparison::eq) == (exc == exit->code ()); if (!valid || (!success && diag)) { @@ -1710,8 +1708,13 @@ namespace build2 else if (!success) { if (diag) - d << pr << " exit code " << ec << (eq ? " != " : " == ") - << static_cast<uint16_t> (c.exit.code); + { + if (c.exit) + d << pr << " exit code " << ec + << (cmp == exit_comparison::eq ? " != " : " == ") << exc; + else + d << pr << " exited with code " << ec; + } } else assert (false); diff --git a/libbuild2/script/script.cxx b/libbuild2/script/script.cxx index c9b3a5e..d0d3304 100644 --- a/libbuild2/script/script.cxx +++ b/libbuild2/script/script.cxx @@ -406,15 +406,15 @@ namespace build2 print_path (p.path); } - if (c.exit.comparison != exit_comparison::eq || c.exit.code != 0) + if (c.exit) { - switch (c.exit.comparison) + switch (c.exit->comparison) { case exit_comparison::eq: o << " == "; break; case exit_comparison::ne: o << " != "; break; } - o << static_cast<uint16_t> (c.exit.code); + o << static_cast<uint16_t> (c.exit->code); } } diff --git a/libbuild2/script/script.hxx b/libbuild2/script/script.hxx index 31527a0..d751169 100644 --- a/libbuild2/script/script.hxx +++ b/libbuild2/script/script.hxx @@ -314,7 +314,9 @@ namespace build2 script::cleanups cleanups; - command_exit exit {exit_comparison::eq, 0}; + // If nullopt, then the command is expected to succeed (0 exit code). + // + optional<command_exit> exit; }; enum class command_to_stream: uint16_t |