From bdccf53eec0aa47b6316c691e9ab54308e7853db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Mon, 2 Mar 2020 21:03:38 +0100 Subject: [PATCH] Make sure b2 exits immediately on syntax errors (#540) Add test verifying Jam syntax error results in non-zero exit status. Refines #538 Fixes #539 --- src/engine/jam.cpp | 42 +++++++++++++++------------ test/core_syntax_error_exit_status.py | 23 +++++++++++++++ test/test_all.py | 1 + 3 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 test/core_syntax_error_exit_status.py diff --git a/src/engine/jam.cpp b/src/engine/jam.cpp index a6a01de3c..eab9bae2d 100644 --- a/src/engine/jam.cpp +++ b/src/engine/jam.cpp @@ -649,28 +649,32 @@ int main( int argc, char * * argv, char * * arg_environ ) parse_file( constant_plus, frame ); } + /* FIXME: What shall we do if builtin_update_now, + * the sole place setting last_update_now_status, + * failed earlier? + */ + status = yyanyerrors(); - if ( status && !last_update_now_status ) - last_update_now_status = status; - - /* Manually touch -t targets. */ - for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) + if ( !status ) { - OBJECT * const target = object_new( s ); - touch_target( target ); - object_free( target ); - } + /* Manually touch -t targets. */ + for ( n = 0; ( s = getoptval( optv, 't', n ) ); ++n ) + { + OBJECT * const target = object_new( s ); + touch_target( target ); + object_free( target ); + } - - /* Now make target. */ - { - PROFILE_ENTER( MAIN_MAKE ); - LIST * const targets = targets_to_update(); - if ( !list_empty( targets ) ) - status |= make( targets, anyhow ); - else - status = last_update_now_status; - PROFILE_EXIT( MAIN_MAKE ); + /* Now make target. */ + { + PROFILE_ENTER( MAIN_MAKE ); + LIST * const targets = targets_to_update(); + if ( !list_empty( targets ) ) + status |= make( targets, anyhow ); + else + status = last_update_now_status; + PROFILE_EXIT( MAIN_MAKE ); + } } PROFILE_EXIT( MAIN ); diff --git a/test/core_syntax_error_exit_status.py b/test/core_syntax_error_exit_status.py new file mode 100644 index 000000000..452ea4304 --- /dev/null +++ b/test/core_syntax_error_exit_status.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +# Copyright (C) Mateusz Loskot 2020. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Test that Jam syntax error results in non-zero exit status + +import BoostBuild + +# Create a temporary working directory. +t = BoostBuild.Tester() + +# Create the needed files. +t.write("jamroot.jam", """ +exe hello : hello.cpp + +""") + +t.run_build_system(status=1) + +t.cleanup() diff --git a/test/test_all.py b/test/test_all.py index 98fcb487f..ebb6a8cf9 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -195,6 +195,7 @@ tests = ["absolute_sources", "core_actions_quietly", "core_at_file", "core_bindrule", + "core_syntax_error_exit_status", "core_fail_expected", "core_jamshell", "core_multifile_actions",