From e0d3535c057a68d09a7e1a06d157ea0424d07853 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Mon, 6 Jan 2025 16:47:58 -0800 Subject: [PATCH] make-compilation-db: trigger relevant dependency fetches in script. Move the burden to make sure all dependencies are prefetched from the caller of make-compilation-db.sh to the script itself. --- .github/bin/make-compilation-db.sh | 37 ++++++++++++++++++++++-------- .github/workflows/verible-ci.yml | 17 ++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/bin/make-compilation-db.sh b/.github/bin/make-compilation-db.sh index b7b030a08..75694d893 100755 --- a/.github/bin/make-compilation-db.sh +++ b/.github/bin/make-compilation-db.sh @@ -16,19 +16,38 @@ set -u set -e -BANT=${BANT:-bant} +# Which bazel and bant to use can be chosen by environment variables +BAZEL=${BAZEL:-bazel} +BANT=${BANT:-needs-to-be-compiled-locally} -if [ ! -e bazel-bin ]; then - echo "Before creating compilation DB, run bazel build first to fetch deps." - exit 1 +BAZEL_OPTS="-c opt --noshow_progress" +if [ "${BANT}" = "needs-to-be-compiled-locally" ]; then + # Bant not given, compile from bzlmod dep. We need to do that before + # we run other bazel rules below as we change the cxxopt flags. Remember + # the full realpath of the resulting binary to be immune to symbolic-link + # switcharoo by bazel. + ${BAZEL} build ${BAZEL_OPTS} --cxxopt=-std=c++20 @bant//bant:bant + BANT=$(realpath bazel-bin/external/bant*/bant/bant) fi -bazel run --cxxopt=-std=c++20 @bant//bant:bant -- \ - -C $(pwd) compile-flags 2>/dev/null > compile_flags.txt +# Bazel-build all targets that generate files, so that they can be +# seen in dependency analysis. +${BAZEL} build ${BAZEL_OPTS} $(${BANT} list-targets | \ + egrep "genrule|cc_proto_library|genlex|genyacc" | awk '{print $3}') -# Bant does not see yet the flex dependency inside the toolchain +# Some selected targets to trigger all dependency fetches from MODULE.bazel +# verilog-y-final to create a header, kzip creator to trigger build of any.pb.h +# and some test that triggers fetching nlohmann_json and gtest +${BAZEL} build ${BAZEL_OPTS} //verible/verilog/parser:verilog-y-final \ + //verible/verilog/tools/kythe:verible-verilog-kythe-kzip-writer \ + //verible/common/lsp:json-rpc-dispatcher_test + +# bant does not distinguish the includes per file yet, so instead of +# a compile_commands.json, we can just as well create a simpler +# compile_flags.txt which is easier to digest for all kinds of tools anyway. +${BANT} compile-flags 2>/dev/null > compile_flags.txt + +# Bant does not see the flex dependency inside the toolchain yet. for d in bazel-out/../../../external/*flex*/src/FlexLexer.h ; do echo "-I$(dirname $d)" >> compile_flags.txt done - -echo "Now, re-run original build to make all artifacts visible to clang-tidy" diff --git a/.github/workflows/verible-ci.yml b/.github/workflows/verible-ci.yml index 9f27c9391..368afe6c2 100644 --- a/.github/workflows/verible-ci.yml +++ b/.github/workflows/verible-ci.yml @@ -72,11 +72,11 @@ jobs: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421 wget https://apt.llvm.org/llvm.sh chmod +x ./llvm.sh - ./llvm.sh 17 + ./llvm.sh 18 - name: Install other Dependencies run: | - apt -qq -y install clang-tidy-11 clang-tidy-17 build-essential git wget + apt -qq -y install clang-tidy-11 clang-tidy-18 build-essential git wget source ./.github/settings.sh ./.github/bin/install-bazel.sh @@ -97,24 +97,17 @@ jobs: - name: Run clang tidy run: | - echo "::group::Trigger fetch and preparation" - bazel build -c opt :install-binaries - echo "::endgroup::" - echo "::group::Make Compilation DB" .github/bin/make-compilation-db.sh cat compile_flags.txt echo "::endgroup::" - echo "::group::Re-etablish links" - bazel build -c opt :install-binaries - echo "::endgroup::" - - # For runtime references, use clang-tidy 11 that still has it, everything else: latest. + # For runtime references, use clang-tidy 11 that still has it, + # everything else: latest. CLANG_TIDY=clang-tidy-11 ./.github/bin/run-clang-tidy-cached.cc --checks="-*,google-runtime-references" \ || ( cat verible_clang-tidy.out ; exit 1) - CLANG_TIDY=clang-tidy-17 ./.github/bin/run-clang-tidy-cached.cc \ + CLANG_TIDY=clang-tidy-18 ./.github/bin/run-clang-tidy-cached.cc \ || ( cat verible_clang-tidy.out ; exit 1) - name: 📤 Upload performance graphs