mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-12 19:10:27 +03:00
Docker CMake support
This commit is contained in:
parent
3201e21292
commit
15eaeba4e8
5 changed files with 69 additions and 27 deletions
|
@ -1,2 +1,7 @@
|
||||||
|
.git/
|
||||||
.vagrant/
|
.vagrant/
|
||||||
obj/
|
.vscode/
|
||||||
|
/build/
|
||||||
|
/obj/
|
||||||
|
/tools/
|
||||||
|
/downloads/
|
||||||
|
|
30
Dockerfile
30
Dockerfile
|
@ -1,26 +1,14 @@
|
||||||
FROM ubuntu:bionic
|
FROM ubuntu:focal
|
||||||
|
|
||||||
# Configuration
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
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"}
|
|
||||||
|
|
||||||
# Essentials
|
RUN apt-get update && apt-get install -y git cmake make ruby gcc
|
||||||
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 useradd inav
|
RUN useradd inav
|
||||||
|
|
||||||
USER inav
|
USER inav
|
||||||
|
|
||||||
|
VOLUME /src
|
||||||
|
|
||||||
|
WORKDIR /src/build
|
||||||
|
ENTRYPOINT ["/src/cmake/docker.sh"]
|
||||||
|
|
28
build.sh
28
build.sh
|
@ -1,12 +1,32 @@
|
||||||
if [ -z "$1" ]; then
|
set -e
|
||||||
echo "Usage syntax: ./build.sh <TARGET>"
|
|
||||||
|
if [[ $# == 0 ]]; then
|
||||||
|
echo -e "\
|
||||||
|
Usage syntax: ./build.sh <TARGET>
|
||||||
|
|
||||||
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$(docker images -q inav-build)" ]; then
|
if [ -z "$(docker images -q inav-build)" ]; then
|
||||||
echo -e "*** Building image\n"
|
echo -e "*** Building image\n"
|
||||||
docker build -t inav-build .
|
docker build -t inav-build .
|
||||||
|
echo -ne "\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "*** Building target $1\n"
|
if [ ! -d ./build ]; then
|
||||||
docker run --rm -v "$(pwd)":/home/src/ inav-build make TARGET="$1"
|
echo -e "*** Creating build directory\n"
|
||||||
|
mkdir ./build
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
29
cmake/docker.sh
Executable file
29
cmake/docker.sh
Executable file
|
@ -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 "$@"
|
|
@ -28,7 +28,7 @@ You'll have to manually execute the same steps that the build script does:
|
||||||
|
|
||||||
1. `docker build -t inav-build .`
|
1. `docker build -t inav-build .`
|
||||||
+ This step is only needed the first time.
|
+ This step is only needed the first time.
|
||||||
2. `docker run --rm -v <PATH_TO_REPO>:/home/src/ inav-build make TARGET=<TARGET>`
|
2. `docker run --rm -it -v <PATH_TO_REPO>:/src inav-build <TARGET>`
|
||||||
+ 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.
|
+ 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.
|
||||||
|
|
||||||
Refer to the [Linux](#Linux) instructions or the [build script](/build.sh) for more details.
|
Refer to the [Linux](#Linux) instructions or the [build script](/build.sh) for more details.
|
Loading…
Add table
Add a link
Reference in a new issue