Skip to content

Commit

Permalink
static-test-tools: Split out build logic
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
maribu committed Feb 25, 2023
1 parent ce7dd92 commit 58bf7ae
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 26 deletions.
29 changes: 3 additions & 26 deletions static-test-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
97 changes: 97 additions & 0 deletions static-test-tools/build.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 58bf7ae

Please sign in to comment.