Skip to content

Commit 5b5161f

Browse files
Merge pull request #10982 from Lebensgefahr/master
Fixes Building in Docker
2 parents 060ac77 + 0133632 commit 5b5161f

4 files changed

Lines changed: 54 additions & 20 deletions

File tree

Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ FROM ubuntu:jammy
22

33
ARG USER_ID
44
ARG GROUP_ID
5-
ENV DEBIAN_FRONTEND noninteractive
5+
ARG GDB
66

7-
RUN apt-get update && apt-get install -y git cmake make ruby gcc python3 python3-pip gcc-arm-none-eabi ninja-build
7+
ENV DEBIAN_FRONTEND=noninteractive
88

9-
RUN if [ "$GDB" = "yes" ]; then apt-get install -y gdb; fi
9+
RUN apt-get update && apt-get install -y git cmake make ruby gcc python3 python3-yaml ninja-build gcc-arm-none-eabi
1010

11-
RUN pip install pyyaml
11+
RUN if [ "$GDB" = "yes" ]; then apt-get install -y gdb; fi
1212

13-
# if either of these are already set the same as the user's machine, leave them be and ignore the error
14-
RUN addgroup --gid $GROUP_ID inav; exit 0;
15-
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID inav; exit 0;
13+
# If a group and user with the same IDs already exist, rename the group and recreate the user after deleting the existing one.
14+
RUN GROUP="$(id -n -g $GROUP_ID)"; if [ -n "$GROUP" ]; then groupmod -n inav "$GROUP"; else groupadd --gid $GROUP_ID inav; fi
15+
RUN USER="$(id -n -u $USER_ID)"; if [ -n "$USER" ]; then userdel -r "$USER"; fi && useradd -m --uid $USER_ID --gid $GROUP_ID inav
1616

1717
USER inav
1818

1919
RUN git config --global --add safe.directory /src
2020

21-
VOLUME /src
22-
2321
WORKDIR /src/build
22+
2423
ENTRYPOINT ["/src/cmake/docker.sh"]

build.sh

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -euo pipefail
33

44
if [[ $# == 0 ]]; then
55
echo -e "\
@@ -8,6 +8,10 @@ Usage syntax: ./build.sh <TARGET>
88
Notes:
99
* You can specify multiple targets.
1010
./build.sh <TARGET_1> <TARGET_2> <TARGET_N>
11+
* To get a list of release targets use \"release_targets\"
12+
./build.sh release_targets
13+
* To get a list of valid targets use \"valid_targets\"
14+
./build.sh valid_targets
1115
* To get a list of all targets use \"help\". Hint: pipe the output through a pager.
1216
./build.sh help | less
1317
* To build all targets use \"all\"
@@ -19,10 +23,20 @@ Notes:
1923
exit 1
2024
fi
2125

26+
run_docker() {
27+
docker run --rm -it -v "$(pwd)":/src inav-build "$@"
28+
}
29+
2230
if [ -z "$(docker images -q inav-build)" ]; then
23-
echo -e "*** Building image\n"
24-
docker build -t inav-build --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -g)" .
25-
echo -ne "\n"
31+
echo "*** Building Docker image"
32+
docker build -t inav-build \
33+
--build-arg USER_ID="$(id -u)" \
34+
--build-arg GROUP_ID="$(id -g)" .
35+
else
36+
docker build -q -t inav-build \
37+
--build-arg USER_ID="$(id -u)" \
38+
--build-arg GROUP_ID="$(id -g)" . >/dev/null ||
39+
{ echo "*** Building Docker image: ERROR"; exit 1; }
2640
fi
2741

2842
if [ ! -d ./build ]; then
@@ -40,10 +54,20 @@ if [ ! -d ./tools ]; then
4054
mkdir ./tools && chmod 777 ./tools
4155
fi
4256

43-
echo -e "*** Building targets [$@]\n"
44-
docker run --rm -it -v "$(pwd)":/src inav-build $@
57+
case "$1" in
58+
release_targets)
59+
run_docker targets | sed -n 's/^Release targets: \(.*\)/\1/p'|tr ' ' '\n'
60+
;;
61+
valid_targets)
62+
run_docker targets | sed -n 's/^Valid targets: \(.*\)/\1/p'|tr ' ' '\n'
63+
;;
64+
*)
65+
echo -e "*** Building targets [$@]\n"
66+
run_docker "$@"
67+
if ls ./build/*.hex &> /dev/null; then
68+
echo -e "\n*** Built targets in ./build:"
69+
stat -c "%n (%.19y)" ./build/*.hex
70+
fi
71+
;;
72+
esac
4573

46-
if [ -z "$(ls ./build/*.hex &> /dev/null)" ]; then
47-
echo -e "\n*** Built targets in ./build:"
48-
stat -c "%n (%.19y)" ./build/*.hex
49-
fi

cmake/arm-none-eabi-checks.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,23 @@ function(arm_none_eabi_gcc_check)
125125
if(NOT version)
126126
message("-- could not find ${prog}")
127127
arm_none_eabi_gcc_install()
128+
gcc_get_version(version
129+
TRIPLET ${arm_none_eabi_triplet}
130+
PROGRAM_NAME prog
131+
PROGRAM_PATH prog_path
132+
)
128133
return()
129134
endif()
130135
message("-- found ${prog} ${version} at ${prog_path}")
131136
if(COMPILER_VERSION_CHECK AND NOT arm_none_eabi_gcc_version STREQUAL version)
132137
message("-- expecting ${prog} version ${arm_none_eabi_gcc_version}, but got version ${version} instead")
133138
arm_none_eabi_gcc_install()
139+
unset(gcc CACHE)
140+
gcc_get_version(version
141+
TRIPLET ${arm_none_eabi_triplet}
142+
PROGRAM_NAME prog
143+
PROGRAM_PATH prog_path
144+
)
134145
return()
135146
endif()
136147
endfunction()

cmake/docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ initialize_cmake() {
1111
}
1212

1313
# Check if CMake has never been initialized
14-
if [ ! -f Makefile ]; then
14+
if [ ! -f build.ninja ]; then
1515
initialize_cmake
1616
fi
1717

0 commit comments

Comments
 (0)