Skip to content

Commit

Permalink
fixing build.sh not returning error in build (InfiniTimeOrg#1460)
Browse files Browse the repository at this point in the history
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: InfiniTimeOrg#1292
  • Loading branch information
cybuzuma authored Dec 13, 2022
1 parent 1062fec commit 081cc60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion .devcontainer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ main() {
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() {
Expand Down Expand Up @@ -74,4 +76,12 @@ CmakeBuild() {
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
12 changes: 11 additions & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ main() {
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() {
Expand Down Expand Up @@ -77,4 +79,12 @@ CmakeBuild() {
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

0 comments on commit 081cc60

Please sign in to comment.