Skip to content

Commit

Permalink
feat(ncs): add support for sphinx, codechecker, clangd tools
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoSagadin committed Aug 23, 2024
1 parent 59c529f commit 263681a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 46 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added

All below changes are related to the ncs-zephyr Docker image:

- Support for building the documentation with the Sphinx documentation tool.
- Support for running Codechecker and various static analysis tools: clangsa, clang-tidy and
cppcheck.
- Support for clangd language server, useful for code navigation and completion inside VSCode's dev
container.

## [1.3.2] - 2024-08-16

### Removed
Expand Down Expand Up @@ -48,4 +58,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[1.2.0]: https://github.com/IRNAS/irnas-docker-software/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/IRNAS/irnas-docker-software/compare/v1.0.1...v1.1.0
[1.0.1]: https://github.com/IRNAS/irnas-docker-software/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/IRNAS/irnas-docker-software/compare/b08044e0137bcbbf5f060545de6b2d2a9f1ee8d8...v1.0.0
[1.0.0]:
https://github.com/IRNAS/irnas-docker-software/compare/b08044e0137bcbbf5f060545de6b2d2a9f1ee8d8...v1.0.0
109 changes: 75 additions & 34 deletions ncs-zephyr/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
ARG NCS_SDK_VERSION

##############
# Base image #
##############
FROM ubuntu:22.04 AS base

# Stages building from base inherit below env vars.
ENV EAST_DONT_USE_TOOLCHAIN_MANAGER=1
ENV EAST_CODECHECKER_CI_MODE=1

# OS dependencies and packages
# gcc-multilib make = Host tools for native_sim build
# python 3.8 is installed by toolchain manager hence older version of libffi is
# required. This argument is used in both images, that's why it's defined here.
ARG APT_PACKAGES="wget curl unzip lcov gcc-multilib make libffi7 ca-certificates ssh"
# python 3.8 is installed by some older NCS versions hence older version of
# libffi is required.
RUN \
apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
wget curl unzip lcov gcc-multilib make ca-certificates ssh doxygen \
graphviz librsvg2-bin texlive-latex-base texlive-latex-extra latexmk libffi7 \
texlive-fonts-recommended imagemagick mscgen software-properties-common \
&& wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \
&& add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" \
&& apt-get -y install --no-install-recommends clang-18 clang-tidy-18 clangd-18 cppcheck \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Create simlink for clang-18 and clang-tidy-18, otherwise Codechecker fails to
# find them.
RUN ln -s /usr/bin/clang-tidy-18 /usr/bin/clang-tidy && \
ln -s /usr/bin/clang-18 /usr/bin/clang

############
# CI image #
############
FROM ubuntu:22.04 AS ci
FROM base AS ci

ARG NCS_SDK_VERSION=v2.6.0
ARG NCS_SDK_VERSION
ARG NRFUTIL_VERSION=7.11.1
ARG TOOLCHAIN_MANAGER_VERSION=0.15.0
ARG APT_PACKAGES
ARG CODECHECKER_VERSION=6.23.1

RUN \
apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
$APT_PACKAGES \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
SHELL [ "/bin/bash", "-euxo", "pipefail", "-c" ]

# NCS SDK
RUN \
Expand All @@ -33,43 +54,52 @@ RUN \
&& rm -fr /root/ncs/tmp \
&& rm -fr /root/ncs/downloads

# Install all Python dependencies.
RUN <<EOT
mngr() {
nrfutil toolchain-manager launch -- $@
}

# Install yq, a lightweight and portable command-line YAML processor
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O yq
chmod +x yq

# Get the SDK Zephyr version from the sdk-nrf's west.yml file
SDK_ZEPHYR_VERSION=$(wget -O - \
https://raw.githubusercontent.com/nrfconnect/sdk-nrf/$NCS_SDK_VERSION/west.yml \
| ./yq '.manifest.projects[] | select(.repo-path == "sdk-zephyr") | .revision')

# Install Python packages and doc requirements. If first sdk-zephyr link fails, try the second.
mngr pip install --no-cache-dir east-tool pre-commit codechecker==$CODECHECKER_VERSION
mngr pip install --no-cache-dir -r \
https://raw.githubusercontent.com/nrfconnect/sdk-zephyr/$SDK_ZEPHYR_VERSION/doc/requirements.txt || \
mngr pip install --no-cache-dir -r https://raw.githubusercontent.com/nrfconnect/sdk-zephyr/$SDK_ZEPHYR_VERSION/scripts/requirements-doc.txt
rm ./yq
EOT

SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["nrfutil", "toolchain-manager", "launch", "--shell"]

#############
# Dev image #
#############

FROM ubuntu:22.04 AS dev
FROM base AS dev

ARG UID=1000
ARG GID=1000

ARG arch=amd64
ARG NORDIC_COMMAND_LINE_TOOLS_VERSION="10-24-2/nrf-command-line-tools-10.24.2"
ARG APT_PACKAGES

SHELL [ "/bin/bash", "-euxo", "pipefail", "-c" ]

RUN \
apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends \
$APT_PACKAGES \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install Nordic command line tools
# Releases: https://www.nordicsemi.com/Products/Development-tools/nrf-command-line-tools/download
RUN <<EOT
NCLT_BASE=https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/desktop-software/nrf-command-line-tools/sw/versions-10-x-x
echo "Host architecture: $arch"
case $arch in
"amd64")
NCLT_URL="${NCLT_BASE}/${NORDIC_COMMAND_LINE_TOOLS_VERSION}_linux-amd64.tar.gz"
;;
"arm64")
NCLT_URL="${NCLT_BASE}/${NORDIC_COMMAND_LINE_TOOLS_VERSION}_linux-arm64.tar.gz"
;;
esac
NCLT_URL="${NCLT_BASE}/${NORDIC_COMMAND_LINE_TOOLS_VERSION}_linux-${arch}.tar.gz"
echo "NCLT_URL=${NCLT_URL}"
if [ ! -z "$NCLT_URL" ]; then
mkdir -p temporary && cd temporary
Expand Down Expand Up @@ -105,10 +135,21 @@ COPY --from=ci --chown=user:user /usr/bin/nrfutil /usr/bin/nrfutil
COPY --from=ci --chown=user:user /root/.nrfutil /home/user/.nrfutil
COPY --from=ci --chown=user:user /root/ncs /home/user/ncs


# All shebangs of the python binaries currently point to the original location
# of the installed interpreter, which is under /root/ncs/toolchains/.
# If this is unchanged, not a single python package works.
# The solution is to change the shebangs of all python binaries to
# '#!/usr/bin/env python'.
# If any specific Python version errors are encountered, is probably just best
# to repeat the nrfutil toolchain installation, instead of copying it from the
# CI stage.
RUN find /home/user/ncs/toolchains/ -path '**/usr/local/bin/*' | \
grep -v '__pycache__' | \
xargs -I {} sh -c "sed -i '1 s|.*root/ncs/toolchains.*python.*|#\!/usr/bin/env python|g' {}"

# Make 'user' default on launch
USER user

RUN nrfutil toolchain-manager launch -- pip install --no-cache-dir east-tool pre-commit

SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["nrfutil", "toolchain-manager", "launch", "--shell"]
10 changes: 5 additions & 5 deletions ncs-zephyr/build_ci.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env bash
NCS_SDK_VERSION=v2.6.0
NCS_SDK_VERSION=v2.7.0

docker build \
--build-arg "ZEPHYR_VERSION=$NCS_SDK_VERSION" \
-f "Dockerfile" \
--target ci \
-t "irnas/ncs-zephyr-$NCS_SDK_VERSION-ci:latest" .
--build-arg "NCS_SDK_VERSION=$NCS_SDK_VERSION" \
-f "Dockerfile" \
--target ci \
-t "irnas/ncs-zephyr-$NCS_SDK_VERSION-ci:latest" .
10 changes: 5 additions & 5 deletions ncs-zephyr/build_dev.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env bash
NCS_SDK_VERSION=v2.6.0
NCS_SDK_VERSION=v2.7.0

docker build \
--build-arg "NCS_SDK_VERSION=$NCS_SDK_VERSION" \
--target dev \
-f "Dockerfile" \
-t "irnas/ncs-zephyr-$NCS_SDK_VERSION-dev:latest" .
--build-arg "NCS_SDK_VERSION=$NCS_SDK_VERSION" \
--target dev \
-f "Dockerfile" \
-t "irnas/ncs-zephyr-$NCS_SDK_VERSION-dev:latest" .
5 changes: 4 additions & 1 deletion ncs-zephyr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ docker run -it --rm \
--volume /dev:/dev \
--workdir /home/user/workdir \
--device-cgroup-rule='c 166:* rmw' \
irnas/ncs-zephyr-v2.6.0-dev:latest
--publish 8080:8080 \
--publish 8081:8081 \
--publish 8090:8090 \
irnas/ncs-zephyr-v2.7.0-dev:latest

0 comments on commit 263681a

Please sign in to comment.