Author: cybuzuma <106408965+cybuzuma@users.noreply.github.com>
fixing build.sh not returning error in build (#1460) Return the build status as return code from the `main` helper function. In the process convert the handling if the file was sourced or directly executed into an explicit if/else statement to make the intent clearer. In case of an build error the error is now reported at the build step, where the error happened. Fixes: https://github.com/InfiniTimeOrg/InfiniTime/issues/1292
.devcontainer/build.sh | 12 +++++++++++- docker/build.sh | 12 +++++++++++-
diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh index 3d8aecbff32c5b799b6eabedb81c201542909fe8..b4f080dd9276147acdc1bc3bf58b3edd1f9f8e7e 100644 --- a/.devcontainer/build.sh +++ b/.devcontainer/build.sh @@ -35,6 +35,8 @@ BUILD_RESULT=$? if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then source "$BUILD_DIR/post_build.sh" fi + # assuming post_build.sh will never fail on a successful build + return $BUILD_RESULT } GetGcc() { @@ -74,4 +76,12 @@ then return 0; else return 1; fi } -[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" \ No newline at end of file +if [[ $SOURCED == "false" ]]; then + # It is important to return exit code of main + # To be future-proof, this is handled explicitely + main "$@" + BUILD_RESULT=$? + exit $BUILD_RESULT +else + echo "Sourced!" +fi diff --git a/docker/build.sh b/docker/build.sh index 07e0d17e49f92b333f6593a82e1600bd1d727848..b9034a532c20bf52e317fb2df0a13be6eee1fa47 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -41,6 +41,8 @@ BUILD_RESULT=$? if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then source "$BUILD_DIR/post_build.sh" fi + # assuming post_build.sh will never fail on a successful build + return $BUILD_RESULT } GetGcc() { @@ -77,4 +79,12 @@ then return 0; else return 1; fi } -[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" +if [[ $SOURCED == "false" ]]; then + # It is important to return exit code of main + # To be future-proof, this is handled explicitely + main "$@" + BUILD_RESULT=$? + exit $BUILD_RESULT +else + echo "Sourced!" +fi