update docker entrypoint to support setting build directory via -B or --workdir arguments (#3011)

This commit is contained in:
E.T.
2026-02-20 10:29:22 +01:00
committed by GitHub
parent 0685fb7a9f
commit f8ed7489c9
+36 -32
View File
@@ -23,63 +23,67 @@
set -e # exit immediately on any failure set -e # exit immediately on any failure
# 1. PARSE ARGUMENTS BUILD_DIR="build"
# We separate arguments into two lists: CMAKE_ARGS=()
# - CMAKE_OPTS: Anything starting with -D (e.g., -DFLASH_MB_SIZE=4)
# - BUILD_ARGS: Everything else (e.g., make, ninja, -j20)
CMAKE_OPTS=()
BUILD_ARGS=() BUILD_ARGS=()
for arg in "$@"; do parse_build_args() {
if [[ "$arg" == -D* ]]; then # 1. PARSE BUILD ARGUMENTS
CMAKE_OPTS+=("$arg") # We separate arguments into two lists, and possibly get an override for the build dir:
else # - BUILD_DIR: Defaults to build, can be overriden (e.g., -B build-4mb, --workdir build-praline)
BUILD_ARGS+=("$arg") # - CMAKE_ARGS: Anything starting with -D (e.g., -DFLASH_MB_SIZE=4)
fi # - BUILD_ARGS: Everything else (e.g., make, ninja, -j20)
done
# Reset the script arguments ($1, $2...) to contain only the BUILD_ARGS. This allows the original logic below to work exactly as before. while [[ $# -gt 0 ]]; do
set -- "${BUILD_ARGS[@]}" if [[ "$1" == -B ]] || [[ "$1" == "--workdir" ]]; then
shift
BUILD_DIR=$1
shift
elif [[ "$1" == -D* ]]; then
CMAKE_ARGS+=("$1")
shift
else
BUILD_ARGS+=("$1")
shift
fi
done
}
build_make() { build_make() {
parse_build_args "$@"
echo "Building in workdir: \"$BUILD_DIR\" using CMake options: \"${CMAKE_ARGS[@]}\" and make options: \"${BUILD_ARGS[@]}\""
cd .. cd ..
mkdir -p build mkdir -p "$BUILD_DIR"
cd build cd "$BUILD_DIR"
cmake "${CMAKE_OPTS[@]}" .. cmake "${CMAKE_ARGS[@]}" ..
make "$@" make "${BUILD_ARGS[@]}"
exit 0 exit 0
} }
build_ninja() { build_ninja() {
parse_build_args "$@"
echo "Building in workdir: \"$BUILD_DIR\" using CMake options: \"${CMAKE_ARGS[@]}\" and ninja options: \"${BUILD_ARGS[@]}\""
cd .. cd ..
mkdir -p build mkdir -p "$BUILD_DIR"
cd build cd "$BUILD_DIR"
cmake -G Ninja "${CMAKE_OPTS[@]}" .. cmake -G Ninja "${CMAKE_ARGS[@]}" ..
ninja "$@" ninja "${BUILD_ARGS[@]}"
exit 0 exit 0
} }
if [ "$1" = 'make' ]; then if [ "$1" = 'make' ]; then
# User explicitly typed 'make' # User explicitly typed 'make'
shift shift
build_make "$@" build_make "$@"
elif [[ $1 == -j* ]]; then elif [[ $1 == -* ]]; then
# User passed -j20 directly (Implied make) # User passed a switch not a command as first argument. Assuming make. (e.g., -j20)
build_make "$@" build_make "$@"
elif [ "$1" = 'ninja' ]; then elif [ "$1" = 'ninja' ]; then
# User explicitly typed 'ninja' # User explicitly typed 'ninja'
shift shift
build_ninja "$@" build_ninja "$@"
elif [ ${#CMAKE_OPTS[@]} -gt 0 ] && [ ${#BUILD_ARGS[@]} -eq 0 ]; then
# User passed ONLY CMake flags (e.g. "-DFLASH_MB_SIZE=4")
# We assume they want to run a default 'make' build.
build_make
fi fi
# Fallback for other commands (e.g. /bin/bash) # Fallback for other commands (e.g. /bin/bash)