From 3842cfd853930814d27a6cd9df79ba80a69bf500 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 18 Oct 2019 11:31:48 +0100 Subject: [PATCH 1/5] Attempt at getting the retcode of the test process --- cibuildwheel/linux.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index ddcec627..7a7de88a 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -57,6 +57,8 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef mkdir /output cd /project + test_retcode=0 + {environment_exports} for PYBIN in {pybin_paths}; do @@ -110,6 +112,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef # Run the tests from a different directory pushd $HOME sh -c {test_command} + test_retcode=$(( $test_retcode || $? )) popd ) @@ -121,6 +124,8 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef mv "$delocated_wheel" /output chown {uid}:{gid} "/output/$(basename "$delocated_wheel")" done + + exit $test_retcode '''.format( pybin_paths=' '.join(c.path+'/bin' for c in platform_configs), test_requires=' '.join(test_requires), From 0c33a585791cf09e56240e7bb7cca21866e8885c Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 18 Oct 2019 11:45:48 +0100 Subject: [PATCH 2/5] failing test breaks out of subshell --- cibuildwheel/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 7a7de88a..453bcde9 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -112,9 +112,9 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef # Run the tests from a different directory pushd $HOME sh -c {test_command} - test_retcode=$(( $test_retcode || $? )) popd ) + test_retcode=$(( $test_retcode || $? )) # clean up rm -rf "$venv_dir" From e0eb375449d29a0996da89ca0b8358bbd3e596b5 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Mon, 21 Oct 2019 11:42:43 +0100 Subject: [PATCH 3/5] Returncode fix (#1) Some trial and error to make sure it works reliably. * remove test_retcode * debug local bash settings * set errexit explicitly in subshell * set errexit also in the subshell in parenthesis * debugging * more debugging (exit code of sh) * is the venv subshell returning exit 1? * what if we remove the additional subshell? * then we need to unquote the command * if statement needs test command quoted * simple if statement * echo command needs to be removed of course * remove debug statements * check if setting errexit here is needed * these settings can be removed At this point ("before") the shell already has errexit set. * setting errexit in the sh invocation is needed This is not inherited, so it's good to specify it. * just double checking that the subshell doesn't exit * use solution from fvue.nl * Solution doesn't seem to work, even popd is run So now I'm putting back the if statement, it seems to be the simplest and most effective solution. * add a comment * prove that errexit is necessary * errexit is indeed needed for chaining --- cibuildwheel/linux.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 453bcde9..2ca2b8df 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -57,8 +57,6 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef mkdir /output cd /project - test_retcode=0 - {environment_exports} for PYBIN in {pybin_paths}; do @@ -111,10 +109,13 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef # Run the tests from a different directory pushd $HOME - sh -c {test_command} + sh -o errexit -c {test_command} popd ) - test_retcode=$(( $test_retcode || $? )) + # exit if tests failed + if [ $? -ne 0 ]; then + exit 1; + fi # clean up rm -rf "$venv_dir" @@ -124,8 +125,6 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef mv "$delocated_wheel" /output chown {uid}:{gid} "/output/$(basename "$delocated_wheel")" done - - exit $test_retcode '''.format( pybin_paths=' '.join(c.path+'/bin' for c in platform_configs), test_requires=' '.join(test_requires), From def8f9a2e3493ac88fcf5f4af131af9f64c00097 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 8 Nov 2019 10:53:06 +0000 Subject: [PATCH 4/5] Remove errexit flag for test command subshell --- cibuildwheel/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 1ac2e67e..d3c13c09 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -114,7 +114,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef # Run the tests from a different directory pushd $HOME - sh -o errexit -c {test_command} + sh -c {test_command} popd ) # exit if tests failed From 5210ad361033913d511f3ed9480f794c86827971 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 8 Nov 2019 10:53:18 +0000 Subject: [PATCH 5/5] clarify comment at if statement --- cibuildwheel/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index d3c13c09..7605c943 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -117,7 +117,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef sh -c {test_command} popd ) - # exit if tests failed + # exit if tests failed (needed for older bash versions) if [ $? -ne 0 ]; then exit 1; fi