Skip to content

Commit 15eaeba

Browse files
committed
Docker CMake support
1 parent 3201e21 commit 15eaeba

File tree

5 files changed

+69
-27
lines changed

5 files changed

+69
-27
lines changed

.dockerignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
.git/
12
.vagrant/
2-
obj/
3+
.vscode/
4+
/build/
5+
/obj/
6+
/tools/
7+
/downloads/

Dockerfile

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
1-
FROM ubuntu:bionic
1+
FROM ubuntu:focal
22

3-
# Configuration
4-
VOLUME /home/src/
5-
WORKDIR /home/src/
6-
ARG TOOLCHAIN_VERSION_SHORT
7-
ENV TOOLCHAIN_VERSION_SHORT ${TOOLCHAIN_VERSION_SHORT:-"9-2019q4"}
8-
ARG TOOLCHAIN_VERSION_LONG
9-
ENV TOOLCHAIN_VERSION_LONG ${TOOLCHAIN_VERSION_LONG:-"9-2019-q4-major"}
3+
ENV DEBIAN_FRONTEND noninteractive
104

11-
# Essentials
12-
RUN mkdir -p /home/src && \
13-
apt-get update && \
14-
apt-get install -y software-properties-common ruby make git gcc wget curl bzip2
15-
16-
# Toolchain
17-
RUN wget -P /tmp "https://developer.arm.com/-/media/Files/downloads/gnu-rm/$TOOLCHAIN_VERSION_SHORT/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG-x86_64-linux.tar.bz2"
18-
RUN mkdir -p /opt && \
19-
cd /opt && \
20-
tar xvjf "/tmp/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG-x86_64-linux.tar.bz2" -C /opt && \
21-
chmod -R -w "/opt/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG"
22-
23-
ENV PATH="/opt/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG/bin:$PATH"
5+
RUN apt-get update && apt-get install -y git cmake make ruby gcc
246

257
RUN useradd inav
8+
269
USER inav
10+
11+
VOLUME /src
12+
13+
WORKDIR /src/build
14+
ENTRYPOINT ["/src/cmake/docker.sh"]

build.sh

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
if [ -z "$1" ]; then
2-
echo "Usage syntax: ./build.sh <TARGET>"
1+
set -e
2+
3+
if [[ $# == 0 ]]; then
4+
echo -e "\
5+
Usage syntax: ./build.sh <TARGET>
6+
7+
Notes:
8+
* You can specify multiple targets.
9+
* If no targets are specified, *all* of them will be built.
10+
* To clean a target prefix it with \"clean_\".
11+
* To clean all targets just use \"clean\"."
312
exit 1
413
fi
514

615
if [ -z "$(docker images -q inav-build)" ]; then
716
echo -e "*** Building image\n"
817
docker build -t inav-build .
18+
echo -ne "\n"
19+
fi
20+
21+
if [ ! -d ./build ]; then
22+
echo -e "*** Creating build directory\n"
23+
mkdir ./build
924
fi
1025

11-
echo -e "*** Building target $1\n"
12-
docker run --rm -v "$(pwd)":/home/src/ inav-build make TARGET="$1"
26+
echo -e "*** Building targets [$@]\n"
27+
docker run --rm -it -v "$(pwd)":/src inav-build $@
28+
29+
if ls ./build/*.hex &> /dev/null; then
30+
echo -e "\n*** Built targets in ./build:"
31+
stat -c "%n (%.19y)" ./build/*.hex
32+
fi

cmake/docker.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
set -e
3+
4+
LAST_CMAKE_AT_REV_FILE="docker_cmake.rev"
5+
CURR_REV="$(git rev-parse HEAD)"
6+
7+
initialize_cmake() {
8+
echo -e "*** CMake was not initialized yet, doing it now.\n"
9+
cmake ..
10+
echo "$CURR_REV" > "$LAST_CMAKE_AT_REV_FILE"
11+
}
12+
13+
# Check if CMake has never been initialized
14+
if [ ! -f Makefile ]; then
15+
initialize_cmake
16+
fi
17+
18+
# Check if CMake was initialized for a different Git revision (new targets may have been added)
19+
if [ -f "$LAST_CMAKE_AT_REV_FILE" ]; then
20+
LAST_CMAKE_AT_REV="$(cat $LAST_CMAKE_AT_REV_FILE)"
21+
if [[ "$LAST_CMAKE_AT_REV" != "SKIP" ]] && [[ "$LAST_CMAKE_AT_REV" != "$CURR_REV" ]]; then
22+
initialize_cmake
23+
fi
24+
else
25+
initialize_cmake
26+
fi
27+
28+
# Let Make handle the arguments coming from the build script
29+
make "$@"

docs/development/Building in Docker.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You'll have to manually execute the same steps that the build script does:
2828

2929
1. `docker build -t inav-build .`
3030
+ This step is only needed the first time.
31-
2. `docker run --rm -v <PATH_TO_REPO>:/home/src/ inav-build make TARGET=<TARGET>`
31+
2. `docker run --rm -it -v <PATH_TO_REPO>:/src inav-build <TARGET>`
3232
+ Where `<PATH_TO_REPO>` must be replaced with the absolute path of where you cloned this repo (see above), and `<TARGET>` with the name of the target that you want to build.
3333

3434
Refer to the [Linux](#Linux) instructions or the [build script](/build.sh) for more details.

0 commit comments

Comments
 (0)