Skip to content

Commit 58bf7ae

Browse files
committed
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
1 parent ce7dd92 commit 58bf7ae

File tree

2 files changed

+100
-26
lines changed

2 files changed

+100
-26
lines changed

static-test-tools/Dockerfile

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,6 @@ ENV LC_ALL C.UTF-8
99
ENV LANG C.UTF-8
1010

1111
RUN \
12-
echo 'Update the package index files to latest available versions' >&2 && \
13-
apt-get update && \
14-
echo 'Installing static test tools' >&2 && \
15-
apt-get -y --no-install-recommends install \
16-
coccinelle \
17-
cppcheck \
18-
doxygen \
19-
graphviz \
20-
less \
21-
make \
22-
pcregrep \
23-
shellcheck \
24-
vera++ \
25-
wget \
26-
&& \
27-
echo 'Cleaning up installation files' >&2 && \
28-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
29-
30-
# Install required Python packages
31-
COPY requirements.txt /tmp/requirements.txt
32-
RUN echo 'Installing python3 packages' >&2 && \
33-
pip3 install --no-cache-dir -r /tmp/requirements.txt && \
34-
rm -f /tmp/requirements.txt
35-
36-
# Install uncrustify
37-
COPY --from=ghcr.io/kaspar030/uncrustify-builder:latest /usr/bin/uncrustify /usr/bin/uncrustify
12+
--mount=type=bind,source=build.sh,target=/root/build.sh \
13+
--mount=type=bind,source=requirements.txt,target=/root/requirements.txt \
14+
cd /root && ./build.sh

static-test-tools/build.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
# Automatically exit on error
4+
set -e
5+
6+
COUNTER_STEP=0
7+
COUNTER_SUBSTEP=0
8+
BLUE="\e[34m"
9+
BOLD="\e[1m"
10+
NORMAL="\e[0m"
11+
12+
UNCRUSTIFY_VERSION="0.76.0"
13+
UNCRUSTIFY_SHA256="32e2f95485a933fc5667880f1a09a964ae83132c235bb606abbb0a659453acb3"
14+
UNCRUSTIFY_URL="https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-$UNCRUSTIFY_VERSION.tar.gz"
15+
16+
step() {
17+
COUNTER_SUBSTEP=0
18+
COUNTER_STEP=$(("$COUNTER_STEP" + 1))
19+
printf "${BLUE}${BOLD}==>${NORMAL}${BOLD} Step %d:${NORMAL} %s\n" "$COUNTER_STEP" "$1"
20+
}
21+
22+
substep() {
23+
COUNTER_SUBSTEP=$(("$COUNTER_SUBSTEP" + 1))
24+
printf "${BLUE}${BOLD} -->${NORMAL}${BOLD} Step %d.%d:${NORMAL} %s\n" \
25+
"$COUNTER_STEP" "$COUNTER_SUBSTEP" "$1"
26+
}
27+
28+
step_prepare_apt() {
29+
step "Updating apt package index"
30+
apt-get update
31+
}
32+
33+
step_install_apt_packages() {
34+
step "Installing packages via apt package manager"
35+
36+
substep "Installing base shell utilities"
37+
apt-get -y --no-install-recommends install wget less pcregrep
38+
39+
substep "Installing tools to generate documentation"
40+
apt-get -y --no-install-recommends install make doxygen graphviz
41+
42+
substep "Installing linting tools"
43+
apt-get -y --no-install-recommends install coccinelle cppcheck shellcheck vera++
44+
}
45+
46+
step_install_pip_packages() {
47+
step "Installing python packages via pip"
48+
pip3 install --no-cache-dir -r requirements.txt
49+
}
50+
51+
step_build_uncrustify() {
52+
step "Building uncrustify"
53+
54+
local olddir
55+
olddir="$(pwd)"
56+
57+
substep "Installing build requirements"
58+
apt-get -y --no-install-recommends install cmake g++
59+
60+
substep "Preparing build dir and downloading source"
61+
cd /tmp
62+
wget "$UNCRUSTIFY_URL"
63+
64+
substep "Verifying and unpacking source"
65+
echo "$UNCRUSTIFY_SHA256 $(basename "$UNCRUSTIFY_URL")" | sha256sum -c -
66+
tar xf "$(basename "$UNCRUSTIFY_URL")"
67+
mkdir "uncrustify-uncrustify-$UNCRUSTIFY_VERSION"/build
68+
cd "uncrustify-uncrustify-$UNCRUSTIFY_VERSION"/build
69+
70+
substep "Running cmake"
71+
cmake .. -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" -DCMAKE_EXE_LINKER_FLAGS="-static"
72+
73+
substep "Running make"
74+
make
75+
76+
substep "Strip and install binary"
77+
strip uncrustify
78+
install -Dm755 uncrustify /usr/bin/uncrustify
79+
80+
substep "Cleaning up build files and removing build dependencies"
81+
cd "$olddir"
82+
apt-get -y purge cmake g++
83+
rm -rf /tmp/uncrustify-*
84+
}
85+
86+
step_clean_apt() {
87+
step "Cleaning up apt package index and temporary files"
88+
apt-get clean
89+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
90+
}
91+
92+
step_prepare_apt
93+
step_install_apt_packages
94+
step_install_pip_packages
95+
step_build_uncrustify
96+
step_clean_apt
97+
exit 0

0 commit comments

Comments
 (0)