Example build hardening (#1430)

* run_example.sh checks example existens

the script exits if without example name parameter
or if example directory doesn't exist

* Update examples/run_example.sh

Co-authored-by: Simon <simon@siku2.io>

* Update examples/run_example.sh

Co-authored-by: Simon <simon@siku2.io>

Co-authored-by: Simon <simon@siku2.io>
This commit is contained in:
Алексей Пастухов 2020-07-22 16:30:36 +02:00 committed by GitHub
parent 7f6543a1b9
commit fb27791332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,8 +58,20 @@ on_exit() {
trap on_exit EXIT
if [[ -z "$EXAMPLE" ]]; then
fail "$0 requires the name of the example as the first argument"
info "See the README.md file for help"
exit
fi
SRCDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" # this source dir
if [[ ! -d "$SRCDIR/$EXAMPLE" || "$EXAMPLE" = "common" || "$EXAMPLE" = "server" ]]; then
fail "$EXAMPLE: no such example"
info "See the README.md file for help"
exit
fi
cd "$SRCDIR/$EXAMPLE" # "$SRCDIR" ensures that this script can be run from anywhere.
# When using $CARGO_TARGET_DIR -> binary is located in different folder