-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·56 lines (48 loc) · 1.96 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
THIS_SCRIPT_LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
HOST_SRC_DIR_SHELL=${THIS_SCRIPT_LOCATION}/src
HOST_OUT_DIR_SHELL=${THIS_SCRIPT_LOCATION}/out/docker/linux
DOCKERFILE_DIRECTORY_SHELL=${THIS_SCRIPT_LOCATION}/src/build/docker/linux
if [ -x "$(command -v docker.exe)" ] && [ -x "$(command -v wslpath)" ]; then
# Presumably running from WSL with Docker Desktop for Windows.
DOCKER_COMMAND=docker.exe
HOST_SRC_DIR=$(wslpath -aw $HOST_SRC_DIR_SHELL)
HOST_OUT_DIR=$(wslpath -aw $HOST_OUT_DIR_SHELL)
DOCKERFILE_DIRECTORY=$(wslpath -aw $DOCKERFILE_DIRECTORY_SHELL)
elif [ -x "$(command -v docker)" ]; then
DOCKER_COMMAND=docker
HOST_SRC_DIR=${HOST_SRC_DIR_SHELL}
HOST_OUT_DIR=${HOST_OUT_DIR_SHELL}
DOCKERFILE_DIRECTORY=${DOCKERFILE_DIRECTORY_SHELL}
else
echo "Cannot find docker in path."
exit 1
fi
#If we're running on MSYS we need to prepend "winpty" to the docker command.
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
DOCKER_COMMAND="winpty ${DOCKER_COMMAND}"
fi
# Make sure the host output directory exists.
mkdir -p $HOST_OUT_DIR_SHELL
# The leading double slash is to workaround a path conversion issue when using
# MSYS.
RUN_COMMAND="python3 //build/src/build/build.py --out_folder=//build/out"
# Enable the user to override some default settings via command line parameters.
while getopts r: option
do
case "${option}"
in
# The 'r' flag lets a user specify a custom command to run the container with.
r) RUN_COMMAND=${OPTARG};;
esac
done
# Make sure the Docker container image containing the build environment is
# up to date and then run the actual build command inside the container.
${DOCKER_COMMAND} build -q -t test_build ${DOCKERFILE_DIRECTORY} && \
${DOCKER_COMMAND} run \
--rm \
--name test_run \
-t \
--mount type=bind,source=${HOST_SRC_DIR},target=/build/src,readonly \
--mount type=bind,source=${HOST_OUT_DIR},target=/build/out \
test_build \
${RUN_COMMAND}