2024-08-08 13:12:37 -07:00
|
|
|
#!/bin/bash
|
|
|
|
on_err() {
|
|
|
|
code=$?
|
|
|
|
if echo -n "$BASH_COMMAND" | grep "^docker" >/dev/null 2>/dev/null; then
|
|
|
|
exit $code
|
|
|
|
fi
|
|
|
|
echo "Error: Command exited with non-zero status ($code)" >&2
|
|
|
|
echo "Command: $BASH_COMMAND"
|
|
|
|
exit $code
|
|
|
|
}
|
|
|
|
have_image() {
|
2024-09-16 15:05:53 -07:00
|
|
|
IMAGES="$(docker images --format json)"
|
|
|
|
if echo "$IMAGES" | jq '.Repository' | grep '^null$'; then
|
|
|
|
IMAGES="$(echo "$IMAGES" | jq '.[].Names' | grep -v null | jq '.[]' --raw-output)"
|
|
|
|
else
|
|
|
|
IMAGES="$(echo "$IMAGES" | jq '.Repository' --raw-output)"
|
|
|
|
fi
|
|
|
|
echo "$IMAGES" | sed 's/:.*$//' | sed 's@^.*/@@' | grep -Fx "$1" >/dev/null 2>/dev/null
|
2024-08-08 13:12:37 -07:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
trap on_err ERR
|
|
|
|
export first_arg="$1"
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
export first_arg="build"
|
|
|
|
fi
|
|
|
|
shift || true
|
|
|
|
build_cmake() {
|
|
|
|
pushd "$1"
|
|
|
|
shift
|
|
|
|
git submodule update --init --recursive
|
|
|
|
mkdir -p "build-docker" && cd "build-docker"
|
|
|
|
cmake ..
|
|
|
|
cmake --build . "$@"
|
|
|
|
cmake --install .
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
if [ "$first_arg" = "in-docker" ]; then
|
|
|
|
ARGS=( "$@" )
|
|
|
|
cd /src
|
2024-09-16 15:05:53 -07:00
|
|
|
git config --global --add safe.directory /src
|
2024-08-08 13:12:37 -07:00
|
|
|
build_cmake subprojects/protobuf "${ARGS[@]}"
|
|
|
|
pushd subprojects/grpc
|
|
|
|
git apply ../../grpc.patch || true
|
|
|
|
popd
|
|
|
|
build_cmake subprojects/grpc "${ARGS[@]}"
|
|
|
|
mkdir -p /src/build-docker && cd /src/build-docker
|
|
|
|
export CMAKE_EXPORT_COMPILE_COMMANDS=ON
|
|
|
|
cmake -DDISABLE_GTK_UI=ON -DCMAKE_BUILD_TYPE=Debug ..
|
|
|
|
cmake --build . "${ARGS[@]}"
|
|
|
|
else
|
|
|
|
export second_arg="$1"
|
|
|
|
shift || true
|
|
|
|
if [ -z "$second_arg" ]; then
|
|
|
|
export second_arg="debian"
|
|
|
|
fi
|
|
|
|
export tag="looper-build-$second_arg"
|
|
|
|
if [ "$first_arg" = "env" ]; then
|
|
|
|
if [ -d "build-env/$second_arg" ]; then
|
|
|
|
docker build "build-env/$second_arg" -t "$tag"
|
|
|
|
fi
|
|
|
|
elif [ "$first_arg" = "build" ]; then
|
|
|
|
if ! have_image "$tag"; then
|
|
|
|
"$0" env "$second_arg"
|
|
|
|
fi
|
|
|
|
docker run -v $PWD:/src "$tag" "/src/build-docker.sh" "in-docker" "$@"
|
|
|
|
fi
|
|
|
|
fi
|