From f74616ce9e16e503287115b589f9aea2052c4852 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 11:35:51 +0200 Subject: [PATCH 01/22] ci: build multi OS for Docker --- .github/workflows/ci.yml | 24 ++++++---- .github/workflows/docker-build.sh | 32 +++++++++++++ .github/workflows/release.yml | 26 ++++++---- Dockerfile | 80 +++++++++++++++++++++++-------- 4 files changed, 123 insertions(+), 39 deletions(-) create mode 100755 .github/workflows/docker-build.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 762bb69e..9f151700 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,18 @@ jobs: name: Build and push to Docker Hub needs: [build-linux, build-osx, build-freebsd] runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - { + BUILD_OS: "alpine", + IMAGE_TAG_SUFFIX: "-alpine" + } + - { + BUILD_OS: "debian", + IMAGE_TAG_SUFFIX: "" + } environment: name: "Docker Hub" url: https://hub.docker.com/r/kcov/kcov @@ -106,16 +118,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build and push the docker image (latest) - # https://github.com/docker/buildx#building - run: | - docker buildx build \ - --tag $IMAGE_TAG \ - --platform $PLATFORM \ - --push \ - . + - name: Build and push the docker image (latest/${{ matrix.BUILD_OS }}) + run: .github/workflows/docker-build.sh ${{ matrix.BUILD_OS }} env: - IMAGE_TAG: kcov/kcov:latest + IMAGE_TAG: kcov/kcov:latest${{ matrix.IMAGE_TAG_SUFFIX }} # All (build on the base image): # - linux/386 # - linux/amd64 diff --git a/.github/workflows/docker-build.sh b/.github/workflows/docker-build.sh new file mode 100755 index 00000000..2fd207ba --- /dev/null +++ b/.github/workflows/docker-build.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -eu + +if [ "${1:-}" = "alpine" ]; then + BUILD_OS="alpine" + BUILD_BASE="3.20" +elif [ "${1:-}" = "debian" ]; then + BUILD_OS="debian" + BUILD_BASE="bookworm-slim" +else + echo "Usage: docker-build.sh alpine" + echo "Usage: docker-build.sh debian" + exit 1 +fi + +set -x + +echo "Building for: ${BUILD_OS}" + +# https://github.com/docker/buildx#building +docker buildx build \ + --build-arg VCS_REF="$(git rev-parse HEAD)" \ + --build-arg BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ + --build-arg BUILD_OS="${BUILD_OS}" \ + --build-arg BUILD_BASE="${BUILD_BASE}" \ + --tag ${IMAGE_TAG:-kcov} \ + --progress ${PROGRESS_MODE:-plain} \ + --platform ${PLATFORM:-linux/amd64} \ + --pull \ + --${ACTION:-load} \ + . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6cff164e..2e27e099 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,18 @@ jobs: name: Build and push to Docker Hub needs: [build] runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - { + BUILD_OS: "alpine", + IMAGE_TAG_SUFFIX: "-alpine" + } + - { + BUILD_OS: "debian", + IMAGE_TAG_SUFFIX: "" + } environment: name: "Docker Hub" url: https://hub.docker.com/r/kcov/kcov @@ -58,16 +70,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build and push the docker image (${{ env.RELEASE_TAG }}) - # https://github.com/docker/buildx#building - run: | - docker buildx build \ - --tag $IMAGE_TAG \ - --platform $PLATFORM \ - --push \ - . + - name: Build and push the docker image (v${{ env.RELEASE_TAG }}/${{ matrix.BUILD_OS }}) + run: .github/workflows/docker-build.sh ${{ matrix.BUILD_OS }} env: - IMAGE_TAG: kcov/kcov:${{ env.RELEASE_TAG }} + IMAGE_TAG: kcov/kcov:${{ env.RELEASE_TAG }}${{ matrix.IMAGE_TAG_SUFFIX }} # All (build on the base image): # - linux/386 # - linux/amd64 @@ -83,7 +89,7 @@ jobs: # - linux/mips64le # No users on this platform: # - linux/ppc64le - PLATFORM: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/riscv64 + PLATFORM: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/riscv64 create_release: name: Create release diff --git a/Dockerfile b/Dockerfile index c0045717..964483e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,45 +1,75 @@ -FROM alpine:3.20 AS builder +ARG BUILD_OS +ARG BUILD_BASE -RUN apk add --update --no-cache \ +FROM ${BUILD_OS}:${BUILD_BASE} AS builder + +ARG BUILD_OS +ARG BUILD_BASE + +RUN set -eux; \ + echo "Building for: ${BUILD_OS}"; \ + if [ "${BUILD_OS}" = "alpine" ]; then \ + apk add --update --no-cache \ binutils-dev \ - # Debian: build-essential build-base \ cmake \ git \ - # Debian: libcurl4-openssl-dev curl-dev \ curl-static \ - # Debian: libdw-dev libdw \ - # Debian, alpine bundled in binutils-dev - # libiberty-dev \ - # Debian: libssl-dev openssl-dev \ ninja-build \ python3 \ - # Debian: zlib1g-dev zlib-dev \ - # Debian: libelf-dev elfutils-dev \ - # Debian: libstdc++-12-dev libstdc++-dev \ - ; + ; \ + elif [ "${BUILD_OS}" = "debian" ]; then \ + apt-get update; \ + apt-get install -y --no-install-recommends --no-install-suggests \ + binutils-dev \ + build-essential \ + cmake \ + git \ + libcurl4-openssl-dev \ + libdw-dev \ + # Alpine: bundled in binutils-dev + libiberty-dev \ + libssl-dev \ + ninja-build \ + python3 \ + zlib1g-dev \ + libelf-dev \ + libstdc++-12-dev \ + ; \ + fi ADD . /src/ -RUN mkdir /src/build && \ - cd /src/build && \ - export PATH="$PATH:/usr/lib/ninja-build/bin/" && \ - cmake -G 'Ninja' .. && \ - cmake --build . && \ - cmake --build . --target install +RUN set -eux; \ + mkdir /src/build; \ + cd /src/build; \ + if [ "${BUILD_OS}" = "alpine" ]; then \ + export PATH="$PATH:/usr/lib/ninja-build/bin/"; \ + fi; \ + cmake -G 'Ninja' ..; \ + cmake --build .; \ + cmake --build . --target install; -FROM alpine:3.20 +ARG BUILD_OS +ARG BUILD_BASE + +FROM ${BUILD_OS}:${BUILD_BASE} + +ARG BUILD_OS +ARG BUILD_BASE COPY --from=builder /usr/local/bin/kcov* /usr/local/bin/ COPY --from=builder /usr/local/share/doc/kcov /usr/local/share/doc/kcov RUN set -eux; \ + echo "Building for: ${BUILD_OS}"; \ + if [ "${BUILD_OS}" = "alpine" ]; then \ apk add --update --no-cache \ bash \ libcurl \ @@ -48,8 +78,18 @@ RUN set -eux; \ libgcc \ libstdc++ \ ; \ + elif [ "${BUILD_OS}" = "debian" ]; then \ + apt-get update; \ + apt-get install -y --no-install-recommends --no-install-suggests \ + libcurl4 \ + libdw1 \ + zlib1g \ + ; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/*; \ + fi; \ # Write a test script - echo -e '#!/usr/bin/env bash\nif [[ true ]]; then\necho "Hello, kcov!"\nfi' > /tmp/test-executable.sh; \ + printf '#!/usr/bin/env bash\nif [[ true ]]; then\necho "Hello, kcov!"\nfi' > /tmp/test-executable.sh; \ # Test kcov kcov --include-pattern=/tmp/test-executable.sh /tmp/coverage /tmp/test-executable.sh; \ # Display From f6f8c113e2cf024d4809430a86a0535342fb34f5 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 11:35:51 +0200 Subject: [PATCH 02/22] docs: update INSTALL.md --- INSTALL.md | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index dc298e85..a1cab838 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -10,14 +10,24 @@ elfutils-devel and *not* elfutils-libelf-devel. FreeBSD ------- + +```sh pkg install binutils cmake elfutils python +``` -Ubuntu ------- -Install +Alpine +------- +```sh +apk add --update --no-cache curl-dev curl-static libdw openssl-dev zlib-dev elfutils-dev libstdc++-dev ``` - apt-get install binutils-dev libssl-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev + +Ubuntu / Debian +--------------- +Install + +```sh +apt-get install binutils-dev libssl-dev libcurl4-openssl-dev libelf-dev libstdc++-12-dev zlib1g-dev libdw-dev libiberty-dev ``` Fedora / Centos / RHEL @@ -28,7 +38,7 @@ Mac OS X -------- Install dependencies: -``` +```sh brew install zlib bash cmake pkgconfig dwarfutils openssl ``` @@ -36,7 +46,7 @@ OSX build instructions (see Issue #166 / Issue #357): Create an empty build dir and do the following steps (adjust openssl path, can also be in /opt): -``` +```sh cd cmake -G make -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib make @@ -48,7 +58,7 @@ If the binary needs to be signed, try these instructions: First get a code signing identity, since debug support is needed to run as non-root: -``` +```sh codesign -s - --entitlements /osx-entitlements.xml -f ./src/Release/kcov ``` @@ -57,16 +67,18 @@ Building Create an empty build dir and do the following steps: - cmake [options] - make - make install +```sh +cmake [options] +make +make install +``` Useful options include -DCMAKE_INSTALL_PREFIX= (installation prefix), -DCMAKE_BUILD_TYPE= and -DCMAKE_C_FLAGS=. Basic example: -``` +```sh cd /path/to/kcov/source/dir mkdir build cd build @@ -77,7 +89,7 @@ Basic example: More advanced example: -``` +```sh cd /path/to/kcov/source/dir mkdir build cd build @@ -100,7 +112,7 @@ Troubleshooting If you have elfutils installed, but cmake fails to find it, specify elfutils install prefix explicitly to cmake. Here is an example: -``` +```sh cd kcov CMAKE_PREFIX_PATH=/opt/elfutils-dir/ \ cmake . From f69e13cc315b0772405f1f177678cdbf88c4ee16 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 11:48:15 +0200 Subject: [PATCH 03/22] ci: add metadata to the Docker image --- .github/workflows/docker-build.sh | 5 +++++ Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.github/workflows/docker-build.sh b/.github/workflows/docker-build.sh index 2fd207ba..00e0d3e1 100755 --- a/.github/workflows/docker-build.sh +++ b/.github/workflows/docker-build.sh @@ -14,6 +14,10 @@ else exit 1 fi +if [ -z "${RELEASE_VERSION:-}" ]; then + RELEASE_VERSION="$(git describe --abbrev=4 --tags HEAD)" +fi + set -x echo "Building for: ${BUILD_OS}" @@ -23,6 +27,7 @@ docker buildx build \ --build-arg VCS_REF="$(git rev-parse HEAD)" \ --build-arg BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ --build-arg BUILD_OS="${BUILD_OS}" \ + --build-arg RELEASE_VERSION="${RELEASE_VERSION}" \ --build-arg BUILD_BASE="${BUILD_BASE}" \ --tag ${IMAGE_TAG:-kcov} \ --progress ${PROGRESS_MODE:-plain} \ diff --git a/Dockerfile b/Dockerfile index 964483e8..5474f7f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -100,4 +100,29 @@ RUN set -eux; \ # Cleanup rm -r /tmp/coverage /tmp/test-executable.sh; +# Metadata +LABEL org.label-schema.vendor="Kcov" \ + org.label-schema.url="https://github.com/SimonKagstrom/kcov#readme" \ + org.label-schema.name="The docker image for kcov" \ + org.label-schema.description="A docker image for kcov" \ + org.label-schema.version=${RELEASE_VERSION} \ + org.label-schema.vcs-url="https://github.com/SimonKagstrom/kcov.git" \ + org.label-schema.vcs-ref=${VCS_REF} \ + org.label-schema.build-date=${BUILD_DATE} \ + org.label-schema.docker.schema-version="1.0" \ + \ + com.docker.extension.publisher-url="https://github.com/SimonKagstrom" \ + \ + org.opencontainers.image.title="The docker image for kcov" \ + org.opencontainers.image.description="A docker image for kcov" \ + org.opencontainers.image.authors="https://github.com/SimonKagstrom" \ + org.opencontainers.image.url="https://github.com/SimonKagstrom/kcov#readme" \ + org.opencontainers.image.documentation="https://github.com/SimonKagstrom/kcov#readme" \ + org.opencontainers.image.source="https://github.com/SimonKagstrom/kcov" \ + org.opencontainers.image.vendor="Kcov" \ + org.opencontainers.image.licenses="GPL-2.0" \ + org.opencontainers.image.created=${BUILD_DATE} \ + org.opencontainers.image.version=${RELEASE_VERSION} \ + org.opencontainers.image.revision=${VCS_REF} + CMD ["/usr/local/bin/kcov"] From d49c5a6fda5c53680a107a18cf12a1ddea688724 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 11:54:19 +0200 Subject: [PATCH 04/22] ci: Allow to manually trigger docker builds --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f151700..26a99a4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI permissions: contents: read -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: build-linux: @@ -99,7 +99,7 @@ jobs: environment: name: "Docker Hub" url: https://hub.docker.com/r/kcov/kcov - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' or ${{ github.event_name == 'workflow_dispatch' }} steps: - uses: actions/checkout@v4 with: From 985c9fbcf7f4d1513b9c1f94945682151afd30b1 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 11:54:31 +0200 Subject: [PATCH 05/22] ci: Add an Alpine build --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26a99a4e..29c81b96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,6 +80,33 @@ jobs: .github/workflows/freebsd-build.sh x86_64 .github/workflows/ci-run-tests.sh + build-alpine: + runs-on: alpine:3.20 + name: Build and test Alpine executable + steps: + - uses: actions/checkout@v4 + - name: Install dependencies and tools + run: | + apk add --update --no-cache \ + binutils-dev \ + build-base \ + cmake \ + git \ + curl-dev \ + curl-static \ + libdw \ + openssl-dev \ + ninja-build \ + python3 \ + zlib-dev \ + elfutils-dev \ + libstdc++-dev + - name: Run the tests + run: | + chmod u+x .github/workflows/freebsd-build.sh .github/workflows/ci-run-tests.sh + .github/workflows/freebsd-build.sh x86_64 + .github/workflows/ci-run-tests.sh + build-and-push-docker-image: name: Build and push to Docker Hub needs: [build-linux, build-osx, build-freebsd] From 847fecd8ed8478d275b0e004fc27e21023b7e06b Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 12:03:23 +0200 Subject: [PATCH 06/22] ci: use push for Docker buildx and fix Alpine --- .github/workflows/ci.yml | 5 ++++- .github/workflows/release.yml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29c81b96..591f672a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,7 +81,9 @@ jobs: .github/workflows/ci-run-tests.sh build-alpine: - runs-on: alpine:3.20 + runs-on: ubuntu-22.04 + container: + image: alpine:3.20 name: Build and test Alpine executable steps: - uses: actions/checkout@v4 @@ -148,6 +150,7 @@ jobs: - name: Build and push the docker image (latest/${{ matrix.BUILD_OS }}) run: .github/workflows/docker-build.sh ${{ matrix.BUILD_OS }} env: + ACTION: push IMAGE_TAG: kcov/kcov:latest${{ matrix.IMAGE_TAG_SUFFIX }} # All (build on the base image): # - linux/386 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e27e099..9b489f79 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -73,6 +73,7 @@ jobs: - name: Build and push the docker image (v${{ env.RELEASE_TAG }}/${{ matrix.BUILD_OS }}) run: .github/workflows/docker-build.sh ${{ matrix.BUILD_OS }} env: + ACTION: push IMAGE_TAG: kcov/kcov:${{ env.RELEASE_TAG }}${{ matrix.IMAGE_TAG_SUFFIX }} # All (build on the base image): # - linux/386 From 6bb737605cf51c367ee7ebf89189c5f39cb6d65a Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 12:04:15 +0200 Subject: [PATCH 07/22] ci: add bash for Alpine --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 591f672a..0ee4e936 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,6 +90,7 @@ jobs: - name: Install dependencies and tools run: | apk add --update --no-cache \ + bash \ binutils-dev \ build-base \ cmake \ From 9331711b2479c0f8440cc2f6cb17b9ea70f6722f Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 12:12:22 +0200 Subject: [PATCH 08/22] ci: add more libs to link for gcc (alpine) --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ee4e936..f01191cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,10 +87,16 @@ jobs: name: Build and test Alpine executable steps: - uses: actions/checkout@v4 - - name: Install dependencies and tools + - name: Install tools and dependencies run: | apk add --update --no-cache \ bash \ + libcurl \ + libdw \ + zlib \ + libgcc \ + libstdc++ \ + \ binutils-dev \ build-base \ cmake \ From ad89c0f79de11058877d44be1f6919078ef0c26d Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 13:17:51 +0200 Subject: [PATCH 09/22] ci: also fetch tags for git describe --- .github/workflows/ci.yml | 1 + .github/workflows/release.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f01191cb..f4664e47 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,6 +140,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: true - name: Docker Hub login uses: docker/login-action@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b489f79..845cd864 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,6 +56,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: true - name: Docker Hub login uses: docker/login-action@v3 From 191540c8d8df20934ae47520002f2493430669b1 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 13:53:06 +0200 Subject: [PATCH 10/22] ci: also allow not having tags (repo fork for example) --- .github/workflows/docker-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.sh b/.github/workflows/docker-build.sh index 00e0d3e1..7c5978b0 100755 --- a/.github/workflows/docker-build.sh +++ b/.github/workflows/docker-build.sh @@ -15,7 +15,7 @@ else fi if [ -z "${RELEASE_VERSION:-}" ]; then - RELEASE_VERSION="$(git describe --abbrev=4 --tags HEAD)" + RELEASE_VERSION="$(git describe --abbrev=4 --tags HEAD || git describe --abbrev=4 HEAD)" fi set -x From 5bf11c14c571a8f1e266cba2630346d44d048f1c Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 17:03:06 +0200 Subject: [PATCH 11/22] ci: fix Alpine builds --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4664e47..72f99fd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,8 @@ jobs: runs-on: ubuntu-22.04 container: image: alpine:3.20 + # Needed to attach to a binary + options: --security-opt seccomp=unconfined name: Build and test Alpine executable steps: - uses: actions/checkout@v4 From 37af413478c3289263cce98352403957efe78441 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 17:34:50 +0200 Subject: [PATCH 12/22] ci: add libbfd-dev for Docker --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 5474f7f0..b9d96558 100644 --- a/Dockerfile +++ b/Dockerfile @@ -77,6 +77,8 @@ RUN set -eux; \ zlib \ libgcc \ libstdc++ \ + # libbfd.so + binutils-dev \ ; \ elif [ "${BUILD_OS}" = "debian" ]; then \ apt-get update; \ @@ -84,6 +86,7 @@ RUN set -eux; \ libcurl4 \ libdw1 \ zlib1g \ + libbfd-dev \ ; \ apt-get clean; \ rm -rf /var/lib/apt/lists/*; \ From 99343a3da9fe72f5d71519a73c5f4764c7f948a3 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 17:42:00 +0200 Subject: [PATCH 13/22] ci: add patchelf for tests --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72f99fd8..626cf619 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,13 +92,15 @@ jobs: - name: Install tools and dependencies run: | apk add --update --no-cache \ - bash \ libcurl \ libdw \ zlib \ libgcc \ libstdc++ \ \ + bash \ + patchelf \ + \ binutils-dev \ build-base \ cmake \ From e26723ecfcf6f417151dcbfc2790876bf94fa7e3 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 17:38:35 +0200 Subject: [PATCH 14/22] ci: improve logic syntax --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 626cf619..86699f65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -139,7 +139,7 @@ jobs: environment: name: "Docker Hub" url: https://hub.docker.com/r/kcov/kcov - if: github.ref == 'refs/heads/master' or ${{ github.event_name == 'workflow_dispatch' }} + if: ${{ github.ref == 'refs/heads/master' }} or ${{ github.event_name == 'workflow_dispatch' }} steps: - uses: actions/checkout@v4 with: From c7c97539b8b6811e1bd663a185da38087c97b272 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 18:13:49 +0200 Subject: [PATCH 15/22] ci: provide "python" in the path --- .github/workflows/ci.yml | 1 + Dockerfile | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86699f65..7c49db99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,6 +100,7 @@ jobs: \ bash \ patchelf \ + python3 \ \ binutils-dev \ build-base \ diff --git a/Dockerfile b/Dockerfile index b9d96558..2eab6e81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -79,6 +79,8 @@ RUN set -eux; \ libstdc++ \ # libbfd.so binutils-dev \ + # To avoid changing the value of --python-parser + python3 \ ; \ elif [ "${BUILD_OS}" = "debian" ]; then \ apt-get update; \ @@ -87,6 +89,8 @@ RUN set -eux; \ libdw1 \ zlib1g \ libbfd-dev \ + # To avoid changing the value of --python-parser + python-is-python3 \ ; \ apt-get clean; \ rm -rf /var/lib/apt/lists/*; \ From e4fd20d9a481504345cefe644d01180e1d8e3bbd Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 18:17:15 +0200 Subject: [PATCH 16/22] ci: add binutils for objcopy --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c49db99..85aea6f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,6 +100,7 @@ jobs: \ bash \ patchelf \ + binutils \ python3 \ \ binutils-dev \ From 178e11f6bd58a374b32a861e40f32f5d823227ee Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 16:23:12 +0200 Subject: [PATCH 17/22] ci: add a fallback and print the release version --- .github/workflows/docker-build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.sh b/.github/workflows/docker-build.sh index 7c5978b0..c1777de8 100755 --- a/.github/workflows/docker-build.sh +++ b/.github/workflows/docker-build.sh @@ -15,12 +15,13 @@ else fi if [ -z "${RELEASE_VERSION:-}" ]; then - RELEASE_VERSION="$(git describe --abbrev=4 --tags HEAD || git describe --abbrev=4 HEAD)" + RELEASE_VERSION="$(git describe --abbrev=4 --tags HEAD || git describe --abbrev=4 HEAD || git rev-parse HEAD)" fi set -x echo "Building for: ${BUILD_OS}" +echo "Release: ${RELEASE_VERSION}" # https://github.com/docker/buildx#building docker buildx build \ From 9b7cb54f3d8ea393de39576082d1e62ebbcc4947 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 18:23:16 +0200 Subject: [PATCH 18/22] tests: lower timeout of attach_process_* tests --- tests/tools/test_compiled.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tools/test_compiled.py b/tests/tools/test_compiled.py index 69fa61e8..ff2a3054 100644 --- a/tests/tools/test_compiled.py +++ b/tests/tools/test_compiled.py @@ -292,6 +292,8 @@ def runTest(self): + self.binaries + "/issue31", False, + # 60 seconds + timeout=60 ) dom = cobertura.parseFile(self.outbase + "/kcov/issue31/cobertura.xml") self.skipTest("Fickle test, ignoring") @@ -313,6 +315,8 @@ def runTest(self): + self.binaries + "/thread-test", False, + # 60 seconds + timeout=60 ) dom = cobertura.parseFile(self.outbase + "/kcov/thread-test/cobertura.xml") self.skipTest("Fickle test, ignoring") From 6611829f3b542505ff799795800624a7ab500d76 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 18:34:43 +0200 Subject: [PATCH 19/22] ci: provide usr/bin/env to some scripts (alpine) With coreutils-env --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85aea6f9..18ec3658 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,6 +102,7 @@ jobs: patchelf \ binutils \ python3 \ + coreutils-env \ \ binutils-dev \ build-base \ From df77f82566233ff8d6d00efff51050b2bf9ba85a Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 18:47:53 +0200 Subject: [PATCH 20/22] ci: fix PATH for tests --- tests/tools/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/test_basic.py b/tests/tools/test_basic.py index b8f9d10e..064020aa 100644 --- a/tests/tools/test_basic.py +++ b/tests/tools/test_basic.py @@ -26,7 +26,7 @@ def runTest(self): class lookup_binary_in_path(libkcov.TestCase): @unittest.expectedFailure def runTest(self): - os.environ["PATH"] += self.sources + "/tests/python" + os.environ["PATH"] += os.pathsep + self.sources + "/tests/python" noKcovRv, o = self.do(self.sources + "/tests/python/main 5") rv, o = self.do(self.kcov + " " + self.outbase + "/kcov " + "main 5") From e7f41cc4bba932f086c9ee3a9021f5af4f49e109 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 19:48:45 +0200 Subject: [PATCH 21/22] docs: Docker instructions --- README.md | 10 +++++----- doc/docker.md | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 doc/docker.md diff --git a/README.md b/README.md index 5556dfff..5cbd546c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ For a video introduction, [look at this presentation from SwedenCPP](https://www Installing ---------- -Refer to the [INSTALL](INSTALL.md) file for build instructions, or use our official Docker images: +Refer to the [INSTALL](INSTALL.md) file for build instructions, or use our official Docker image (`kcov/kcov`): * [kcov/kcov](https://hub.docker.com/r/kcov/kcov/) for releases since v31. @@ -27,7 +27,7 @@ How to use it ------------- Basic usage is straight-forward: -``` +```sh kcov /path/to/outdir executable [args for the executable] ``` @@ -41,7 +41,7 @@ Filtering output It's often useful to filter output, since e.g., /usr/include is seldom of interest. This can be done in two ways: -``` +```sh kcov --exclude-pattern=/usr/include --include-pattern=part/of/path,other/path \ /path/to/outdir executable ``` @@ -50,7 +50,7 @@ which will do a string-comparison and include everything which contains *part/of/path* or *other/path* but exclude everything that has the */usr/include* string in it. -``` +```sh kcov --include-path=/my/src/path /path/to/outdir executable kcov --exclude-path=/usr/include /path/to/outdir executable ``` @@ -63,7 +63,7 @@ Kcov can also merge the results of multiple earlier runs. To use this mode, call kcov with `--merge`, an output path and one or more paths to an earlier run, e.g., -``` +```sh kcov --merge /tmp/merged-output /tmp/kcov-output1 /tmp/kcov-output2 kcov --merge /tmp/merged-output /tmp/kcov-output* # With a wildcard ``` diff --git a/doc/docker.md b/doc/docker.md new file mode 100644 index 00000000..a51f58af --- /dev/null +++ b/doc/docker.md @@ -0,0 +1,16 @@ +# The docker image + +Kcov has a docker image: [kcov/kcov](https://hub.docker.com/r/kcov/kcov/) and tags since v31. + +There is two variants (tags): +- `latest` or `vXX` that are Debian based +- `latest-alpine` or `vXX-alpine` that are Alpine based + +## Permissions + +kcov needs access the following system calls: +- [`ptrace`](https://linux.die.net/man/2/ptrace) +- [`process_vm_readv`](https://linux.die.net/man/2/process_vm_readv)/[`process_vm_writev`](https://linux.die.net/man/2/process_vm_writev) +- [`personality`](https://linux.die.net/man/2/personality) + +You may need to use `--security-opt seccomp=unconfined` as a docker run option to attach to processes. From c7a27000c7eca3137ddd511412a481096b1bdd00 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 14 Jul 2024 19:49:26 +0200 Subject: [PATCH 22/22] ci: fixup platforms for Debian --- .github/workflows/ci.yml | 15 +++++++++------ .github/workflows/release.yml | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18ec3658..33a3749c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,11 +133,13 @@ jobs: include: - { BUILD_OS: "alpine", - IMAGE_TAG_SUFFIX: "-alpine" + IMAGE_TAG_SUFFIX: "-alpine", + PLATFORM: "linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/riscv64" } - { BUILD_OS: "debian", - IMAGE_TAG_SUFFIX: "" + IMAGE_TAG_SUFFIX: "", + PLATFORM: "linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8" } environment: name: "Docker Hub" @@ -167,19 +169,20 @@ jobs: env: ACTION: push IMAGE_TAG: kcov/kcov:latest${{ matrix.IMAGE_TAG_SUFFIX }} - # All (build on the base image): + # All (built on the base image): # - linux/386 # - linux/amd64 - # - linux/arm/v6 + # - linux/arm/v6 -> Only Alpine + # - linux/arm/v5 -> Only Debian # - linux/arm/v7 # - linux/arm64/v8 # - linux/ppc64le # - linux/mips64le - # - linux/riscv64 + # - linux/riscv64 -> Only Alpine # - linux/s390x # Does not build: # - linux/s390x # - linux/mips64le # No users on this platform: # - linux/ppc64le - PLATFORM: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/riscv64 + PLATFORM: ${{ matrix.PLATFORM }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 845cd864..dd4a1ba3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,11 +43,13 @@ jobs: include: - { BUILD_OS: "alpine", - IMAGE_TAG_SUFFIX: "-alpine" + IMAGE_TAG_SUFFIX: "-alpine", + PLATFORM: "linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/riscv64" } - { BUILD_OS: "debian", - IMAGE_TAG_SUFFIX: "" + IMAGE_TAG_SUFFIX: "", + PLATFORM: "linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8" } environment: name: "Docker Hub" @@ -76,22 +78,23 @@ jobs: env: ACTION: push IMAGE_TAG: kcov/kcov:${{ env.RELEASE_TAG }}${{ matrix.IMAGE_TAG_SUFFIX }} - # All (build on the base image): + # All (built on the base image): # - linux/386 # - linux/amd64 - # - linux/arm/v6 + # - linux/arm/v6 -> Only Alpine + # - linux/arm/v5 -> Only Debian # - linux/arm/v7 # - linux/arm64/v8 # - linux/ppc64le # - linux/mips64le - # - linux/riscv64 + # - linux/riscv64 -> Only Alpine # - linux/s390x # Does not build: # - linux/s390x # - linux/mips64le # No users on this platform: # - linux/ppc64le - PLATFORM: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/riscv64 + PLATFORM: ${{ matrix.PLATFORM }} create_release: name: Create release