From c88e16026fc85845ab947e51d7f8e7d995095efa Mon Sep 17 00:00:00 2001 From: Leandro Belli Date: Mon, 12 Feb 2024 21:14:22 +0000 Subject: [PATCH] docker: Update Dockerfile and cleanup dependencies This patch refactors the Dockerfile setup process, by optimizing the installation of tools and dependencies. It simplifies the environment setup by using ARGs for tool versions. This updated Dockerfile allows to be used for `x86_64` and `aarch64` host machines. Also, it fixes the group ID extraction bug in the init script. Signed-off-by: Leandro Belli Change-Id: I38b999b2c54230af5e26b359823815f3194de511 --- docker/Dockerfile | 268 +++++++++--------- docker/installer-scripts/install-cmake.sh | 29 ++ docker/installer-scripts/install-cppcheck.sh | 29 ++ docker/installer-scripts/install-doxygen.sh | 37 +++ .../install-gcc-aarch64-none-elf.sh | 29 ++ .../install-gcc-arm-none-eabi.sh | 29 ++ .../install-llvm.sh} | 121 +++++--- docker/rootfs/usr/local/bin/init | 2 +- tools/check_spacing.py | 2 + 9 files changed, 376 insertions(+), 170 deletions(-) create mode 100644 docker/installer-scripts/install-cmake.sh create mode 100644 docker/installer-scripts/install-cppcheck.sh create mode 100644 docker/installer-scripts/install-doxygen.sh create mode 100644 docker/installer-scripts/install-gcc-aarch64-none-elf.sh create mode 100644 docker/installer-scripts/install-gcc-arm-none-eabi.sh rename docker/{rootfs/usr/local/bin/prepare_llvm => installer-scripts/install-llvm.sh} (55%) diff --git a/docker/Dockerfile b/docker/Dockerfile index 623e90665..8387dd7d0 100755 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,149 +1,129 @@ # # Arm SCP/MCP Software -# Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved. +# Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # -FROM ubuntu:20.04@sha256:9fa30fcef427e5e88c76bc41ad37b7cc573e1d79cecb23035e413c4be6e476ab as ci +FROM ubuntu:20.04@sha256:9fa30fcef427e5e88c76bc41ad37b7cc573e1d79cecb23035e413c4be6e476ab AS common -ARG ARM_GNU_RM_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2" -ARG DOXYGEN_URL="https://sourceforge.net/projects/doxygen/files/rel-1.8.13/doxygen-1.8.13.linux.bin.tar.gz" -ARG CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v3.25.2/cmake-3.25.2-linux-x86_64.tar.gz" -ARG AARCH64_GCC_URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf.tar.xz" -ARG CPPCHECK_SRC_URL="https://github.com/danmar/cppcheck.git" -ARG CPPCHECK_CHECKOUT_TAG="1.90" -ARG IWYU_SRC_URL="https://github.com/include-what-you-use/include-what-you-use.git" -ARG LINUX_SCRIPTS_URL="https://raw.githubusercontent.com/torvalds/linux/master/scripts" - -ARG ROOTFS_PATH="docker/rootfs" - -ENV ARMLMD_LICENSE_FILE= +ARG ARM_NONE_EABI_VERSION="10.3-2021.10" +ARG AARCH64_NONE_ELF_VERSION="9.2-2019.12" +ARG CMAKE_VERSION="3.25.2" +ARG LLVM_VERSION="13" +ARG CPPCHECK_VERSION="1.90" +ARG DOXYGEN_VERSION="1.8.13" ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ apt-get dist-upgrade -y && \ - apt-get update && \ apt-get install -y --no-install-recommends \ - bundler gcc g++ gpg-agent git gosu lsb-release make ninja-build \ - xz-utils python3 python3-pip software-properties-common wget lcov && \ - apt-get update && \ - python3 -m pip install --upgrade pip && \ - gem install bundler + gcc \ + g++ \ + git \ + make \ + ninja-build \ + python-is-python3 \ + python3 \ + python3-pip \ + software-properties-common \ + wget \ + xz-utils && \ + python3 -m pip install --upgrade pip ENV DEBIAN_FRONTEND= -RUN mkdir "/opt/arm-gnu-rm" && \ - wget -nv -O - -c "${ARM_GNU_RM_URL}" | \ - tar -jxf - -C "/opt/arm-gnu-rm" --strip-components=1 && \ - echo 'export PATH=/opt/arm-gnu-rm/bin:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" +# Install GCC arm-none-eabi +FROM common AS arm-none-eabi +COPY docker/installer-scripts/install-gcc-arm-none-eabi.sh \ + /tmp +RUN bash /tmp/install-gcc-arm-none-eabi.sh /opt/arm-none-eabi \ + "${ARM_NONE_EABI_VERSION}" -ENV PATH="/opt/arm-gnu-rm/bin:${PATH}" -VOLUME "/opt/arm-compiler-6" -ENV PATH="/opt/arm-compiler-6/bin:${PATH}" -RUN mkdir "/opt/doxygen" && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - libclang1-9 libclang-9-dev libclang-cpp9 && \ - wget -nv -O - -c "${DOXYGEN_URL}" | \ - tar -zxf - -C "/opt/doxygen" --strip-components=1 && \ - echo 'export PATH=/opt/doxygen/bin:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" +# Install GCC aarch64-none-elf +FROM common AS aarch64-none-elf +COPY docker/installer-scripts/install-gcc-aarch64-none-elf.sh \ + /tmp +RUN bash /tmp/install-gcc-aarch64-none-elf.sh /opt/aarch64-none-elf \ + "${AARCH64_NONE_ELF_VERSION}"; -ENV PATH="/opt/doxygen/bin:${PATH}" -RUN mkdir "/opt/cmake" && \ - wget -nv -O - -c "${CMAKE_URL}" | \ - tar -zxf - -C "/opt/cmake" --strip-components=1 && \ - echo 'export PATH=/opt/cmake/bin:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" +# Install CMake, it needs to be installed before LLVM and cppcheck +FROM common AS cmake +COPY docker/installer-scripts/install-cmake.sh /tmp +RUN bash /tmp/install-cmake.sh /opt/cmake ${CMAKE_VERSION}; +ENV PATH="${PATH}:/opt/cmake/bin" -ENV PATH="/opt/cmake/bin:${PATH}" -RUN apt-get update && \ - wget --no-check-certificate -O - \ - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ - add-apt-repository \ - 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main' && \ - apt-get update && \ - apt-get install -y --no-install-recommends \ - clang-tidy-13 clang-13 llvm-13 libclang-13-dev llvm-13-dev lld-13 +# Install LLVM compiler and build libclang_rt.builtins +FROM common AS llvm +COPY --from=arm-none-eabi /opt/arm-none-eabi /opt/arm-none-eabi +COPY --from=cmake /opt/cmake /opt/cmake +ENV PATH="${PATH}:/opt/arm-none-eabi/bin" +ENV PATH="${PATH}:/opt/cmake/bin" +COPY docker/installer-scripts/install-llvm.sh /tmp +RUN bash /tmp/install-llvm.sh "${LLVM_VERSION}" -COPY ${ROOTFS_PATH}/usr/local/bin/prepare_llvm /usr/local/bin/prepare_llvm -RUN chmod 755 "/usr/local/bin/prepare_llvm" -RUN prepare_llvm -RUN mkdir "/opt/aarch64-gcc" && \ - wget -nv -O - -c "${AARCH64_GCC_URL}" | \ - tar -Jxf - -C "/opt/aarch64-gcc" --strip-components=1 && \ - echo 'export PATH=/opt/aarch64-gcc/bin:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" +# Build and install cppcheck tool +FROM cmake AS cppcheck +COPY docker/installer-scripts/install-cppcheck.sh /tmp +RUN bash /tmp/install-cppcheck.sh /opt/cppcheck "${CPPCHECK_VERSION}" -ENV PATH="/opt/aarch64-gcc/bin:${PATH}" -RUN cwd=$PWD && mkdir "/opt/cppcheck" && cd "/opt/cppcheck" && \ - git clone --depth 1 --branch "${CPPCHECK_CHECKOUT_TAG}" \ - "${CPPCHECK_SRC_URL}" source && \ - cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX=/opt/cppcheck \ - -DFILESDIR=/opt/cppcheck ./source && \ - cmake --build . -- install && cd $cwd && \ - echo 'export PATH=/opt/cppcheck/bin:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" +# Install Doxygen tool +FROM cmake AS doxygen +COPY docker/installer-scripts/install-doxygen.sh /tmp +RUN bash /tmp/install-doxygen.sh /opt/doxygen "${DOXYGEN_VERSION}" -ENV PATH="/opt/cppcheck/bin:${PATH}" -RUN cwd=$PWD && mkdir "/opt/iwyu" && cd "/opt/iwyu" && \ - git clone "${IWYU_SRC_URL}" -b clang_13 --single-branch iwyu-13 && \ - cmake -G "Ninja" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-13g \ - ./iwyu-13 && cmake --build . && \ - cd bin && ln -s include-what-you-use iwyu && cd $cwd && \ - echo 'export PATH=/opt/iwyu/bin:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" - -ENV PATH="/opt/iwyu/bin:${PATH}" +FROM llvm AS ci +ENV ARMLMD_LICENSE_FILE= +ENV LM_LICENSE_FILE= -RUN cwd=$PWD && mkdir "/opt/checkpatch" && cd "/opt/checkpatch" && \ - wget -nvc "${LINUX_SCRIPTS_URL}/checkpatch.pl" && \ - wget -nvc "${LINUX_SCRIPTS_URL}/spelling.txt" && \ - wget -nvc "${LINUX_SCRIPTS_URL}/const_structs.checkpatch" && \ - chmod 755 "/opt/checkpatch/checkpatch.pl" && \ - echo 'export PATH=/opt/checkpatch:${PATH}' >> \ - "/etc/profile.d/50-scp-firmware-env.sh" +VOLUME "/opt/arm-compiler-6" +ENV PATH="${PATH}:/opt/arm-compiler-6/bin" + +COPY --from=arm-none-eabi /opt/arm-none-eabi /opt/arm-none-eabi +COPY --from=aarch64-none-elf /opt/aarch64-none-elf /opt/aarch64-none-elf +COPY --from=cmake /opt/cmake /opt/cmake +COPY --from=cppcheck /opt/cppcheck /opt/cppcheck +COPY --from=doxygen /opt/doxygen/source/build/bin/ /opt/doxygen/bin +ENV PATH="${PATH}:/opt/arm-none-eabi/bin" +ENV PATH="${PATH}:/opt/aarch64-none-elf/bin" +ENV PATH="${PATH}:/opt/cmake/bin" +ENV PATH="${PATH}:/opt/cppcheck/bin" +ENV PATH="${PATH}:/opt/doxygen/bin" -ENV PATH="/opt/checkpatch:${PATH}" +ENV DEBIAN_FRONTEND=noninteractive -COPY ${ROOTFS_PATH}/usr/local/bin/init /usr/local/bin/init -RUN chmod 755 "/usr/local/bin/init" +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + bundler \ + bzip2 \ + gpg-agent \ + gosu \ + lsb-release \ + lcov && \ + gem install bundler -v 2.4.22 -RUN ln -s /usr/bin/python3 /usr/bin/python +ENV DEBIAN_FRONTEND= +# Install SCP-Firmware requirements COPY requirements.txt . -RUN PIP_ROOT_USER_ACTION=ignore python3 -m pip install -r requirements.txt +RUN PIP_ROOT_USER_ACTION=ignore \ + python3 -m pip install --ignore-installed -r requirements.txt COPY Gemfile . RUN BUNDLE_SILENCE_ROOT_WARNING=true bundler install -ENTRYPOINT [ "sh", "/usr/local/bin/init" ] +ENTRYPOINT ["sh"] -FROM ci as jenkins -ARG JENKINS_UID=1000 -ARG JENKINS_GID=1000 - -RUN addgroup --gid "${JENKINS_GID}" jenkins && \ - adduser --uid "${JENKINS_UID}" --gid "${JENKINS_GID}" --disabled-password \ - --gecos "" jenkins - -ENTRYPOINT [ "sh", "-c" ] - -FROM ci as dev - -VOLUME /scp-firmware -WORKDIR /scp-firmware +FROM ci as user ENV DEBIAN_FRONTEND=noninteractive @@ -153,50 +133,80 @@ RUN apt-get update && \ ENV DEBIAN_FRONTEND= -RUN adduser --disabled-password --gecos "" user && \ - usermod -aG sudo user && \ - passwd -d user +COPY "docker/rootfs/usr/local/bin/init" "/usr/local/bin/init" +RUN chmod +x /usr/local/bin/init + + +FROM user as dev + +VOLUME /scp-firmware +WORKDIR /scp-firmware + +ARG USER_UID=1000 +ARG USER_GID=1000 +ARG USERNAME=user + +RUN groupadd -g ${USER_GID} ${USERNAME} || true && \ + useradd -l -u ${USER_UID} -g ${USERNAME} -m ${USERNAME} || true && \ + usermod -aG sudo ${USERNAME} && \ + echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME && \ + chmod 0400 /etc/sudoers.d/$USERNAME ENV NOTVISIBLE="in users profile" RUN echo "export VISIBLE=now" >> "/etc/profile" -RUN echo "\nexport USER=user" >> "/home/user/.bashrc" -ENV PATH="/home/user/.local/bin:${PATH}" +RUN echo "\nexport USER=${USERNAME}" >> "/home/${USERNAME}/.bashrc" +ENV PATH="/home/${USERNAME}/.local/bin:${PATH}" -ENTRYPOINT [ "sh", "/usr/local/bin/init" ] +ENTRYPOINT [ "bash", "/usr/local/bin/init" ] -FROM dev as vagrant + +FROM user as vagrant VOLUME /vagrant WORKDIR /vagrant +# Set a default username argument (vagrant by default) +ARG USERNAME=vagrant + +# Update package lists and install necessary packages + ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get dist-upgrade -y && \ - apt-get install -y --no-install-recommends openssh-server && \ - mkdir "/run/sshd" + apt-get install -y \ + sudo \ + openssh-server ENV DEBIAN_FRONTEND= -RUN adduser --disabled-password --gecos "" vagrant && \ - usermod -aG sudo vagrant && \ - passwd -d vagrant -ENV NOTVISIBLE="in users profile" -RUN echo "export VISIBLE=now" >> "/etc/profile" +# Create the user and set up SSH access +RUN adduser --disabled-password --gecos "" $USERNAME && \ + usermod -aG sudo $USERNAME && \ + passwd -d vagrant && \ + mkdir -p "/home/$USERNAME/.ssh" && \ + chmod 700 "/home/$USERNAME/.ssh" -RUN printf "\nAcceptEnv ARMLMD_LICENSE_FILE" >> /etc/ssh/sshd_config +# Copy the authorized keys file +COPY docker/rootfs/home/$USERNAME/.ssh/authorized_keys \ + /home/$USERNAME/.ssh/authorized_keys -RUN mkdir -p "/home/vagrant/.ssh" && \ - chmod 755 "/home/vagrant/.ssh" +# Set proper permissions for the authorized keys file +RUN chmod 600 "/home/$USERNAME/.ssh/authorized_keys" && \ + chown -R $USERNAME:$USERNAME "/home/$USERNAME/.ssh" -COPY ${ROOTFS_PATH}/home/vagrant/.ssh/authorized_keys /home/vagrant/.ssh/authorized_keys -RUN chmod 644 "/home/vagrant/.ssh/authorized_keys" +# Set environment variables +ENV NOTVISIBLE="in users profile" \ + PATH="/home/$USERNAME/.local/bin:${PATH}" -RUN printf "\ncd /vagrant" >> "/home/vagrant/.bashrc" - -RUN echo "\nexport USER=vagrant" >> "/home/user/.bashrc" -ENV PATH="/home/vagrant/.local/bin:${PATH}" +# Add configuration to make the environment visible +RUN echo "export VISIBLE=now" >> "/etc/profile" && \ + printf "\nAcceptEnv ARMLMD_LICENSE_FILE" >> "/etc/ssh/sshd_config" && \ + printf "\ncd /$USERNAME" >> "/home/$USERNAME/.bashrc" +# Expose SSH port EXPOSE 22 + +# Set entrypoint to initialize services +ENTRYPOINT [ "bash", "/usr/local/bin/init" ] diff --git a/docker/installer-scripts/install-cmake.sh b/docker/installer-scripts/install-cmake.sh new file mode 100644 index 000000000..e3b1358fd --- /dev/null +++ b/docker/installer-scripts/install-cmake.sh @@ -0,0 +1,29 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +set -e + +tool_dir=$1 +version=$2 +hostarch=$(uname -m) + +toolchain="cmake-${version}-linux-${hostarch}" +url="https://github.com/Kitware/CMake/releases/download/v${version}/${toolchain}.tar.gz" + +echo -e "Installing ${toolchain}\n" + +# Create target folder +mkdir -p ${tool_dir} + +# Download +wget -nv ${url} + +# Extract +tar -xf ${toolchain}.tar.gz -C ${tool_dir} --strip-components=1 + +# Clean up +rm ${toolchain}.tar.gz diff --git a/docker/installer-scripts/install-cppcheck.sh b/docker/installer-scripts/install-cppcheck.sh new file mode 100644 index 000000000..2a3b0acb5 --- /dev/null +++ b/docker/installer-scripts/install-cppcheck.sh @@ -0,0 +1,29 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +set -e + +tool_dir=$1 +version=$2 + +url="https://github.com/danmar/cppcheck.git" + +echo -e "Installing cppcheck tool version: ${version}\n" + +# Create target folder +mkdir -p ${tool_dir} +pushd ${tool_dir} + +# Download +git clone "${url}" --depth 1 --branch "${version}" source + +# Build +cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX=${tool_dir} \ + -DFILESDIR=${tool_dir} ./source +cmake --build . -- install + +popd diff --git a/docker/installer-scripts/install-doxygen.sh b/docker/installer-scripts/install-doxygen.sh new file mode 100644 index 000000000..9c87d8b46 --- /dev/null +++ b/docker/installer-scripts/install-doxygen.sh @@ -0,0 +1,37 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +set -e + +tool_dir=$1 +version=$2 + +url="https://github.com/doxygen/doxygen.git" + +echo -e "Installing Doxygen tool version: ${version}\n" + +# Install dependencies + +apt-get install -y --no-install-recommends \ + flex \ + bison + +# Create target folder +mkdir -p ${tool_dir} + +# Download +git clone "${url}" --depth 1 --branch \ + "Release_$(echo $version | sed 's/\./_/g')" ${tool_dir}/source + +# Build +mkdir -p ${tool_dir}/source/build +pushd ${tool_dir}/source/build +cmake -G "Unix Makefiles" .. +make +make install/local + +popd diff --git a/docker/installer-scripts/install-gcc-aarch64-none-elf.sh b/docker/installer-scripts/install-gcc-aarch64-none-elf.sh new file mode 100644 index 000000000..2bf6526ce --- /dev/null +++ b/docker/installer-scripts/install-gcc-aarch64-none-elf.sh @@ -0,0 +1,29 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +set -e + +tool_dir=$1 +version=$2 +hostarch=$(uname -m) + +toolchain="gcc-arm-${version}-${hostarch}-aarch64-none-elf" +url="https://developer.arm.com/-/media/Files/downloads/gnu-a/${version}/binrel/${toolchain}.tar.xz" + +echo -e "Installing ${toolchain}\n" + +# Create target folder +mkdir -p ${tool_dir} + +# Download +wget -nv ${url} + +# Extract +tar -xf ${toolchain}.tar.xz -C ${tool_dir} --strip-components=1 + +# Clean up +rm ${toolchain}.tar.xz diff --git a/docker/installer-scripts/install-gcc-arm-none-eabi.sh b/docker/installer-scripts/install-gcc-arm-none-eabi.sh new file mode 100644 index 000000000..0faedd52b --- /dev/null +++ b/docker/installer-scripts/install-gcc-arm-none-eabi.sh @@ -0,0 +1,29 @@ +# +# Arm SCP/MCP Software +# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +set -e + +tool_dir=$1 +version=$2 +hostarch=$(uname -m) + +toolchain="gcc-arm-none-eabi-${version}-${hostarch}-linux" +url="https://developer.arm.com/-/media/Files/downloads/gnu-rm/${version}/${toolchain}.tar.bz2" + +echo -e "Installing ${toolchain}\n" + +# Create target folder +mkdir -p ${tool_dir} + +# Download +wget -nv ${url} + +# Extract +tar -xf ${toolchain}.tar.bz2 -C ${tool_dir} --strip-components=1 + +# Clean up +rm ${toolchain}.tar.bz2 diff --git a/docker/rootfs/usr/local/bin/prepare_llvm b/docker/installer-scripts/install-llvm.sh similarity index 55% rename from docker/rootfs/usr/local/bin/prepare_llvm rename to docker/installer-scripts/install-llvm.sh index f03fcfb07..008f3567e 100644 --- a/docker/rootfs/usr/local/bin/prepare_llvm +++ b/docker/installer-scripts/install-llvm.sh @@ -1,51 +1,89 @@ -#!/bin/bash - # # Arm SCP/MCP Software -# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. +# Copyright (c) 2023-2024, Arm Limited and Contributors. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # STEPS=4 -SCRIPT_NAME=$(basename $0) -TMP_FOLDER=/tmp/${SCRIPT_NAME} +llvm_version=$1 + +SCRIPT_NAME=$(basename "$0") +TMP_FOLDER=/tmp/"${SCRIPT_NAME}_data" LOG_OUTPUT_FILE=${TMP_FOLDER}/out.log # helper functions error() { >&2 echo "error: $@" - echo "error: $@" >> $LOG_OUTPUT_FILE + echo "error: $@" >> "$LOG_OUTPUT_FILE" +} + +log() { + echo -n "$@" >> "$LOG_OUTPUT_FILE" +} + +logln() { + echo "$@" >> "$LOG_OUTPUT_FILE" +} + +lindent() { + log " $@" +} + +lindentln() { + logln " $@" +} + +println() { + logln "$@" + echo "$@" } -log() { echo -n "$@" >> $LOG_OUTPUT_FILE; } -logln() { echo "$@" >> $LOG_OUTPUT_FILE; } -lindent() { log " $@"; } -lindentln() { logln " $@"; } -println() { logln "$@"; echo "$@"; } -indentln() { lindentln "$@"; echo " $@"; } -indent() { lindent "$@"; echo -n " $@"; } -input() { read -p $1 $2; logln "$1$$2"; } + +indentln() { + lindentln "$@" + echo " $@" +} + +indent() { + lindent "$@" + echo -n " $@" +} + +input() { + read -p "$1" "$2" + logln "$1$$2" +} + step() { - STEP=$1; - shift; + STEP=$1 + shift println "[$STEP/$STEPS] $@" } + eexit() { >&2 echo >&2 echo "error: please find the complete logs in ${LOG_OUTPUT_FILE}. Aborting..." exit 1 } + cmd() { logln "$ $@" - eval "$@" >> $LOG_OUTPUT_FILE 2>&1 - [[ $? -ne 0 ]] && echo "error!" && eexit + eval "$@" >> "$LOG_OUTPUT_FILE" 2>&1 || { echo "error!"; eexit; } } -cmdp() { logln $1; echo -n " $1..."; shift; cmd $@; echo "ok!"; } -echo "Setting up temporary directory" -mkdir -p $TMP_FOLDER -echo -n "" > $LOG_OUTPUT_FILE +cmdp() { + logln "$1" + echo -n " $1..." + shift + cmd "$@" + echo "ok!" +} + +echo "Setting up temporary directory at ${TMP_FOLDER}" +mkdir -p "$TMP_FOLDER" +echo -n "" > "$LOG_OUTPUT_FILE" + # Step 1 : obtaining the GNU Arm Embedded Toolchain sysroot for later... @@ -74,30 +112,29 @@ fi step 1 "Toolchain sysroot found at: ${SYSROOT}" -# Step 2: retrieve LLVM 13 -step 2 "Installing the LLVM 13 toolchain..." -lindentln "Checking if clang-13 is present in the path..." -if command -v clang-13 &> /dev/null; then - indentln "LLVM 13 is already installed! Skipping..." +# Step 2: retrieve LLVM +step 2 "Installing the LLVM ${llvm_version} toolchain..." +lindentln "Checking if clang-${llvm_version} is present in the path..." +if command -v clang-${llvm_version} &> /dev/null; then + indentln "LLVM {llvm_version} is already installed! Skipping..." else - lindentln "clang-13 was not found in the PATH. Proceeding to installation..." cmdp "Downloading the LLVM installation script" wget https://apt.llvm.org/llvm.sh -O $TMP_FOLDER/install-llvm.sh cmd chmod +x $TMP_FOLDER/install-llvm.sh - cmdp "Downloading and installing LLVM 13 (this will take a while)" $TMP_FOLDER/install-llvm.sh 13 + cmdp "Downloading and installing LLVM ${llvm_version} (this will take a while)" $TMP_FOLDER/install-llvm.sh ${llvm_version} fi # Step 3: Retrieving Compiler-RT source code step 3 "Installing the Compiler-RT Arm builtins..." -cmdp "Downloading the source code" wget https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/compiler-rt-13.0.1.src.tar.xz -O ${TMP_FOLDER}/rt-src.tar.xz +cmdp "Downloading the source code" wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${llvm_version}.0.1/compiler-rt-${llvm_version}.0.1.src.tar.xz -O ${TMP_FOLDER}/rt-src.tar.xz cmdp "Extracting the source code" tar -xf ${TMP_FOLDER}/rt-src.tar.xz -C ${TMP_FOLDER} -cmd cd ${TMP_FOLDER}/compiler-rt-13.0.1.src +cmd cd ${TMP_FOLDER}/compiler-rt-${llvm_version}.0.1.src -BAREMETAL_PATH=$(clang-13 -print-resource-dir)/lib/baremetal +BAREMETAL_PATH=$(clang-${llvm_version} -print-resource-dir)/lib/baremetal cmd mkdir -p $BAREMETAL_PATH for ARCH in armv7m armv7em armv8m.main armv8.1m.main; do cmdp "Preparing Compiler-RT builtins for target ${ARCH}" cmake -GNinja \ - -DLLVM_CONFIG_PATH=$(command -v llvm-config-13) \ + -DLLVM_CONFIG_PATH=$(command -v llvm-config-${llvm_version}) \ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \ -DCOMPILER_RT_OS_DIR="baremetal" \ -DCOMPILER_RT_BUILD_BUILTINS=ON \ @@ -105,19 +142,23 @@ for ARCH in armv7m armv7em armv8m.main armv8.1m.main; do -DCOMPILER_RT_BUILD_XRAY=OFF \ -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ -DCOMPILER_RT_BUILD_PROFILE=OFF \ - -DCMAKE_C_COMPILER=$(command -v clang-13) \ + -DCMAKE_C_COMPILER=$(command -v clang-${llvm_version}) \ -DCMAKE_C_COMPILER_TARGET="${ARCH}-none-eabi" \ -DCMAKE_ASM_COMPILER_TARGET="${ARCH}-none-eabi" \ - -DCMAKE_AR=$(command -v llvm-ar-13) \ - -DCMAKE_NM=$(command -v llvm-nm-13) \ - -DCMAKE_RANLIB=$(command -v llvm-ranlib-13) \ + -DCMAKE_AR=$(command -v llvm-ar-${llvm_version}) \ + -DCMAKE_NM=$(command -v llvm-nm-${llvm_version}) \ + -DCMAKE_RANLIB=$(command -v llvm-ranlib-${llvm_version}) \ -DCOMPILER_RT_BAREMETAL_BUILD=ON \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \ -DCOMPILER_RT_INCLUDE_TESTS=OFF \ - -DCMAKE_C_FLAGS=\"-march=${ARCH} -mthumb -mfpu=none -mfloat-abi=soft -I${SYSROOT}/include\" \ - -DCMAKE_ASM_FLAGS=\"-march=${ARCH} -mthumb -mfpu=none -mfloat-abi=soft -I${SYSROOT}/include\" + -DCMAKE_C_FLAGS=\"-march=${ARCH} -mthumb -mfpu=none -mfloat-abi=soft \ + -I${SYSROOT}/include\" \ + -DCMAKE_ASM_FLAGS=\"-march=${ARCH} -mthumb -mfpu=none -mfloat-abi=soft \ + -I${SYSROOT}/include\" cmdp "Building builtins for target ${ARCH}" ninja builtins - cmdp "Installing the builtins" cp ./lib/baremetal/libclang_rt.builtins-arm.a ${BAREMETAL_PATH}/libclang_rt.builtins-${ARCH}.a + cmdp "Installing the builtins" \ + cp ./lib/baremetal/libclang_rt.builtins-arm.a \ + ${BAREMETAL_PATH}/libclang_rt.builtins-${ARCH}.a done echo diff --git a/docker/rootfs/usr/local/bin/init b/docker/rootfs/usr/local/bin/init index 09e45da4e..1c0a99c12 100755 --- a/docker/rootfs/usr/local/bin/init +++ b/docker/rootfs/usr/local/bin/init @@ -17,7 +17,7 @@ if [ -z "${user}" ]; then exec $@ else uid=$(stat -c "%u" ".") - gid=$(stat -c "%u" ".") + gid=$(stat -c "%g" ".") usermod -u ${uid} ${user} groupmod -g ${gid} ${user} diff --git a/tools/check_spacing.py b/tools/check_spacing.py index baaff8b84..9e4da0afc 100755 --- a/tools/check_spacing.py +++ b/tools/check_spacing.py @@ -47,6 +47,8 @@ 'CMakeLists.txt', '*.yml', '*.yaml', + 'Dockerfile', + '*.sh', ] #