From 58bf7aeb5671461077315398c336abb634ef667a Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 22 Feb 2023 13:35:59 +0100 Subject: [PATCH] static-test-tools: Split out build logic - Move build logic to ./build.sh to reduce the number of layers generated - Build uncrustify from source - this allows updating it to newer versions without having to touch two repositories - Update uncrustify to the latest stable release --- static-test-tools/Dockerfile | 29 ++--------- static-test-tools/build.sh | 97 ++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 26 deletions(-) create mode 100755 static-test-tools/build.sh diff --git a/static-test-tools/Dockerfile b/static-test-tools/Dockerfile index d13cd4be..425f5dab 100644 --- a/static-test-tools/Dockerfile +++ b/static-test-tools/Dockerfile @@ -9,29 +9,6 @@ ENV LC_ALL C.UTF-8 ENV LANG C.UTF-8 RUN \ - echo 'Update the package index files to latest available versions' >&2 && \ - apt-get update && \ - echo 'Installing static test tools' >&2 && \ - apt-get -y --no-install-recommends install \ - coccinelle \ - cppcheck \ - doxygen \ - graphviz \ - less \ - make \ - pcregrep \ - shellcheck \ - vera++ \ - wget \ - && \ - echo 'Cleaning up installation files' >&2 && \ - apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -# Install required Python packages -COPY requirements.txt /tmp/requirements.txt -RUN echo 'Installing python3 packages' >&2 && \ - pip3 install --no-cache-dir -r /tmp/requirements.txt && \ - rm -f /tmp/requirements.txt - -# Install uncrustify -COPY --from=ghcr.io/kaspar030/uncrustify-builder:latest /usr/bin/uncrustify /usr/bin/uncrustify + --mount=type=bind,source=build.sh,target=/root/build.sh \ + --mount=type=bind,source=requirements.txt,target=/root/requirements.txt \ + cd /root && ./build.sh diff --git a/static-test-tools/build.sh b/static-test-tools/build.sh new file mode 100755 index 00000000..dfd6204d --- /dev/null +++ b/static-test-tools/build.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# Automatically exit on error +set -e + +COUNTER_STEP=0 +COUNTER_SUBSTEP=0 +BLUE="\e[34m" +BOLD="\e[1m" +NORMAL="\e[0m" + +UNCRUSTIFY_VERSION="0.76.0" +UNCRUSTIFY_SHA256="32e2f95485a933fc5667880f1a09a964ae83132c235bb606abbb0a659453acb3" +UNCRUSTIFY_URL="https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-$UNCRUSTIFY_VERSION.tar.gz" + +step() { + COUNTER_SUBSTEP=0 + COUNTER_STEP=$(("$COUNTER_STEP" + 1)) + printf "${BLUE}${BOLD}==>${NORMAL}${BOLD} Step %d:${NORMAL} %s\n" "$COUNTER_STEP" "$1" +} + +substep() { + COUNTER_SUBSTEP=$(("$COUNTER_SUBSTEP" + 1)) + printf "${BLUE}${BOLD} -->${NORMAL}${BOLD} Step %d.%d:${NORMAL} %s\n" \ + "$COUNTER_STEP" "$COUNTER_SUBSTEP" "$1" +} + +step_prepare_apt() { + step "Updating apt package index" + apt-get update +} + +step_install_apt_packages() { + step "Installing packages via apt package manager" + + substep "Installing base shell utilities" + apt-get -y --no-install-recommends install wget less pcregrep + + substep "Installing tools to generate documentation" + apt-get -y --no-install-recommends install make doxygen graphviz + + substep "Installing linting tools" + apt-get -y --no-install-recommends install coccinelle cppcheck shellcheck vera++ +} + +step_install_pip_packages() { + step "Installing python packages via pip" + pip3 install --no-cache-dir -r requirements.txt +} + +step_build_uncrustify() { + step "Building uncrustify" + + local olddir + olddir="$(pwd)" + + substep "Installing build requirements" + apt-get -y --no-install-recommends install cmake g++ + + substep "Preparing build dir and downloading source" + cd /tmp + wget "$UNCRUSTIFY_URL" + + substep "Verifying and unpacking source" + echo "$UNCRUSTIFY_SHA256 $(basename "$UNCRUSTIFY_URL")" | sha256sum -c - + tar xf "$(basename "$UNCRUSTIFY_URL")" + mkdir "uncrustify-uncrustify-$UNCRUSTIFY_VERSION"/build + cd "uncrustify-uncrustify-$UNCRUSTIFY_VERSION"/build + + substep "Running cmake" + cmake .. -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" -DCMAKE_EXE_LINKER_FLAGS="-static" + + substep "Running make" + make + + substep "Strip and install binary" + strip uncrustify + install -Dm755 uncrustify /usr/bin/uncrustify + + substep "Cleaning up build files and removing build dependencies" + cd "$olddir" + apt-get -y purge cmake g++ + rm -rf /tmp/uncrustify-* +} + +step_clean_apt() { + step "Cleaning up apt package index and temporary files" + apt-get clean + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +} + +step_prepare_apt +step_install_apt_packages +step_install_pip_packages +step_build_uncrustify +step_clean_apt +exit 0