From 15eaeba4e8b2d1769d2f347833d735bf6b9fa449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= Date: Tue, 22 Sep 2020 18:56:03 +0200 Subject: [PATCH] Docker CMake support --- .dockerignore | 7 +++++- Dockerfile | 30 ++++++++------------------ build.sh | 28 ++++++++++++++++++++---- cmake/docker.sh | 29 +++++++++++++++++++++++++ docs/development/Building in Docker.md | 2 +- 5 files changed, 69 insertions(+), 27 deletions(-) create mode 100755 cmake/docker.sh diff --git a/.dockerignore b/.dockerignore index f6718b745..12934f01a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,7 @@ +.git/ .vagrant/ -obj/ +.vscode/ +/build/ +/obj/ +/tools/ +/downloads/ diff --git a/Dockerfile b/Dockerfile index 746733bbe..96f5c6ce4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,14 @@ -FROM ubuntu:bionic +FROM ubuntu:focal -# Configuration -VOLUME /home/src/ -WORKDIR /home/src/ -ARG TOOLCHAIN_VERSION_SHORT -ENV TOOLCHAIN_VERSION_SHORT ${TOOLCHAIN_VERSION_SHORT:-"9-2019q4"} -ARG TOOLCHAIN_VERSION_LONG -ENV TOOLCHAIN_VERSION_LONG ${TOOLCHAIN_VERSION_LONG:-"9-2019-q4-major"} +ENV DEBIAN_FRONTEND noninteractive -# Essentials -RUN mkdir -p /home/src && \ - apt-get update && \ - apt-get install -y software-properties-common ruby make git gcc wget curl bzip2 - -# Toolchain -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" -RUN mkdir -p /opt && \ - cd /opt && \ - tar xvjf "/tmp/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG-x86_64-linux.tar.bz2" -C /opt && \ - chmod -R -w "/opt/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG" - -ENV PATH="/opt/gcc-arm-none-eabi-$TOOLCHAIN_VERSION_LONG/bin:$PATH" +RUN apt-get update && apt-get install -y git cmake make ruby gcc RUN useradd inav + USER inav + +VOLUME /src + +WORKDIR /src/build +ENTRYPOINT ["/src/cmake/docker.sh"] diff --git a/build.sh b/build.sh index d514ddfbf..59d9221b6 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,32 @@ -if [ -z "$1" ]; then - echo "Usage syntax: ./build.sh " +set -e + +if [[ $# == 0 ]]; then + echo -e "\ +Usage syntax: ./build.sh + +Notes: + * You can specify multiple targets. + * If no targets are specified, *all* of them will be built. + * To clean a target prefix it with \"clean_\". + * To clean all targets just use \"clean\"." exit 1 fi if [ -z "$(docker images -q inav-build)" ]; then echo -e "*** Building image\n" docker build -t inav-build . + echo -ne "\n" +fi + +if [ ! -d ./build ]; then + echo -e "*** Creating build directory\n" + mkdir ./build fi -echo -e "*** Building target $1\n" -docker run --rm -v "$(pwd)":/home/src/ inav-build make TARGET="$1" +echo -e "*** Building targets [$@]\n" +docker run --rm -it -v "$(pwd)":/src inav-build $@ + +if ls ./build/*.hex &> /dev/null; then + echo -e "\n*** Built targets in ./build:" + stat -c "%n (%.19y)" ./build/*.hex +fi diff --git a/cmake/docker.sh b/cmake/docker.sh new file mode 100755 index 000000000..3c10ebc8e --- /dev/null +++ b/cmake/docker.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +LAST_CMAKE_AT_REV_FILE="docker_cmake.rev" +CURR_REV="$(git rev-parse HEAD)" + +initialize_cmake() { + echo -e "*** CMake was not initialized yet, doing it now.\n" + cmake .. + echo "$CURR_REV" > "$LAST_CMAKE_AT_REV_FILE" +} + +# Check if CMake has never been initialized +if [ ! -f Makefile ]; then + initialize_cmake +fi + +# Check if CMake was initialized for a different Git revision (new targets may have been added) +if [ -f "$LAST_CMAKE_AT_REV_FILE" ]; then + LAST_CMAKE_AT_REV="$(cat $LAST_CMAKE_AT_REV_FILE)" + if [[ "$LAST_CMAKE_AT_REV" != "SKIP" ]] && [[ "$LAST_CMAKE_AT_REV" != "$CURR_REV" ]]; then + initialize_cmake + fi +else + initialize_cmake +fi + +# Let Make handle the arguments coming from the build script +make "$@" diff --git a/docs/development/Building in Docker.md b/docs/development/Building in Docker.md index 8fc0b3f70..7e370cf91 100755 --- a/docs/development/Building in Docker.md +++ b/docs/development/Building in Docker.md @@ -28,7 +28,7 @@ You'll have to manually execute the same steps that the build script does: 1. `docker build -t inav-build .` + This step is only needed the first time. -2. `docker run --rm -v :/home/src/ inav-build make TARGET=` +2. `docker run --rm -it -v :/src inav-build ` + Where `` must be replaced with the absolute path of where you cloned this repo (see above), and `` with the name of the target that you want to build. Refer to the [Linux](#Linux) instructions or the [build script](/build.sh) for more details. \ No newline at end of file