@@ -3,8 +3,9 @@ ARG UBUNTU_VERSION
33FROM ubuntu:${UBUNTU_VERSION} AS base
44
55# Use Bash as the default shell for RUN commands, using the options
6- # `set -o errexit -o pipefail`.
6+ # `set -o errexit -o pipefail`, and as the entrypoint .
77SHELL ["/bin/bash" , "-e" , "-o" , "pipefail" , "-c" ]
8+ ENTRYPOINT ["/bin/bash" ]
89
910# Ensure any packages installed directly or indirectly via dpkg do not require
1011# manual interaction.
@@ -58,7 +59,7 @@ RUN useradd -ms /bin/bash ${NONROOT_USER}
5859# ====================== GCC IMAGE ======================
5960FROM base AS gcc
6061
61- # Install GCC.
62+ # Install GCC and create the necessary symlinks .
6263ARG GCC_VERSION
6364RUN <<EOF
6465apt-get update
@@ -77,14 +78,19 @@ update-alternatives \
7778EOF
7879ENV CC=/usr/bin/gcc
7980ENV CXX=/usr/bin/g++
80- # Sanity check.
81+
82+ # Check that the installed GCC version matches the expected version.
8183RUN <<EOF
82- if [[ "$(${CC} -dumpversion)" != "${GCC_VERSION}" ]]; then
83- echo "ERROR: gcc -dumpversion does not match expected version '${GCC_VERSION}'"
84+ CC_VER=$(${CC} -dumpversion)
85+ CC_VER=${CC_VER%%.*}
86+ if [[ "${CC_VER}" != "${GCC_VERSION}" ]]; then
87+ echo "ERROR: 'gcc -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
8488 exit 1
8589fi
86- if [[ "$(${CXX} -dumpversion)" != "${GCC_VERSION}" ]]; then
87- echo "ERROR: g++ -dumpversion does not match expected version '${GCC_VERSION}'"
90+ CXX_VER=$(${CXX} -dumpversion)
91+ CXX_VER=${CXX_VER%%.*}
92+ if [[ "${CXX_VER}" != "${GCC_VERSION}" ]]; then
93+ echo "ERROR: g++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
8894 exit 1
8995fi
9096EOF
134140ENV CC=/usr/bin/clang-${CLANG_VERSION}
135141ENV CXX=/usr/bin/clang++-${CLANG_VERSION}
136142
143+ # Check that the installed Clang version matches the expected version.
144+ RUN <<EOF
145+ CC_VER=$(${CC} -dumpversion)
146+ CC_VER=${CC_VER%%.*}
147+ if [[ "${CC_VER}" != "${CLANG_VERSION}" ]]; then
148+ echo "ERROR: 'clang -dumpversion' gives '${CC_VER}', which does not match expected version '${GCC_VERSION}'."
149+ exit 1
150+ fi
151+ CXX_VER=$(${CXX} -dumpversion)
152+ CXX_VER=${CXX_VER%%.*}
153+ if [[ "${CXX_VER}" != "${CLANG_VERSION}" ]]; then
154+ echo "ERROR: clang++ -dumpversion gives '${CXX_VER}', which does not match expected version '${GCC_VERSION}'."
155+ exit 1
156+ fi
157+ EOF
158+
137159# Switch to the non-root user.
138160USER ${NONROOT_USER}
139161WORKDIR /home/${NONROOT_USER}
@@ -155,11 +177,11 @@ cat >>~/.conan2/profiles/default <<EOT
155177[conf]
156178tools.build:compiler_executables={"c" : "${CC}" , "cpp" : "${CXX}" }
157179EOT
158- if [[ $(clang-${CLANG_VERSION} --version | head -1 | grep -Po 'version \K [0-9]{2}' ) -ge 20 ]]; then
180+ if [[ ${CC_VER} -ge 20 ]]; then
159181 cat >>~/.conan2/profiles/default <<EOT
160182tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw' , '-Wno-deprecated-declarations' ]
161183EOT
162- elif [[ $(clang-${CLANG_VERSION} --version | head -1 | grep -Po 'version \K [0-9]{2}' ) -eq 19 ]]; then
184+ elif [[ ${CC_VER} -eq 19 ]]; then
163185 cat >>~/.conan2/profiles/default <<EOT
164186tools.build:cxxflags=['-Wno-missing-template-arg-list-after-template-kw' ]
165187EOT
0 commit comments