From aef204461c93ae3de8a33d278d0e508643d9e1da Mon Sep 17 00:00:00 2001 From: Laurent Cheylus Date: Mon, 1 Jan 2024 23:44:10 +0100 Subject: [PATCH] util: modify scripts for code coverage to be compatible with BSD OS - Use /usr/bin/env bash instead of /bin/sh to use OSTYPE - Use readlink from GNU coreutils on BSD OS in util/build-code_coverage.sh and util/show-code_coverage.sh scripts Signed-off-by: Laurent Cheylus --- util/build-code_coverage.sh | 18 ++++++++++++++---- util/show-code_coverage.sh | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/util/build-code_coverage.sh b/util/build-code_coverage.sh index 4082bc13d..bbe4abaab 100755 --- a/util/build-code_coverage.sh +++ b/util/build-code_coverage.sh @@ -1,15 +1,25 @@ -#!/bin/sh +#!/usr/bin/env bash # spell-checker:ignore (abbrevs/acronyms) HTML gcno llvm # spell-checker:ignore (jargon) toolchain # spell-checker:ignore (rust) Ccodegen Cinline Coverflow Cpanic RUSTC RUSTDOCFLAGS RUSTFLAGS RUSTUP Zpanic -# spell-checker:ignore (shell) OSID esac -# spell-checker:ignore (utils) genhtml grcov lcov readlink sccache shellcheck uutils +# spell-checker:ignore (shell) OSID OSTYPE esac +# spell-checker:ignore (utils) genhtml grcov lcov greadlink readlink sccache shellcheck uutils FEATURES_OPTION="--features feat_os_unix" +# Use GNU coreutils for readlink on *BSD +case "$OSTYPE" in + *bsd*) + READLINK="greadlink" + ;; + *) + READLINK="readlink" + ;; +esac + ME="${0}" -ME_dir="$(dirname -- "$(readlink -fm -- "${ME}")")" +ME_dir="$(dirname -- "$("${READLINK}" -fm -- "${ME}")")" REPO_main_dir="$(dirname -- "${ME_dir}")" cd "${REPO_main_dir}" && diff --git a/util/show-code_coverage.sh b/util/show-code_coverage.sh index 3f51462c9..8c6f5e20a 100755 --- a/util/show-code_coverage.sh +++ b/util/show-code_coverage.sh @@ -1,9 +1,19 @@ -#!/bin/sh +#!/usr/bin/env bash -# spell-checker:ignore (vars) OSID binfmt +# spell-checker:ignore (vars) OSID OSTYPE binfmt greadlink + +# Use GNU coreutils for readlink on *BSD +case "$OSTYPE" in + *bsd*) + READLINK="greadlink" + ;; + *) + READLINK="readlink" + ;; +esac ME="${0}" -ME_dir="$(dirname -- "$(readlink -fm -- "${ME}")")" +ME_dir="$(dirname -- "$("${READLINK}" -fm -- "${ME}")")" REPO_main_dir="$(dirname -- "${ME_dir}")" export COVERAGE_REPORT_DIR="${REPO_main_dir}/target/debug/coverage-nix"