From 08051e5b1cfe28088d00602b2bde8429eaead7d4 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Fri, 27 Sep 2024 17:02:52 -0700 Subject: [PATCH] Switch to hedronvision/bazel-compile-commands for compilation db. The grailbio/bazel-compilation-database only works for non-bzlmod and is not maintained anymore, while hedronvision works for old and new bazel and currently is maintained. It is slower and more invasive (creating unwanted links and adds things to .git), so mostly reluctant change, but it keeps the light on. --- .github/bin/make-compilation-db.sh | 14 +------------ .github/bin/run-clang-format.sh | 2 +- .github/workflows/verible-ci.yml | 23 ++++++++++++++++----- MODULE.bazel | 33 +++++++++++++++++++++--------- WORKSPACE | 28 ++++++++++++++++++------- WORKSPACE.bzlmod | 13 ------------ 6 files changed, 64 insertions(+), 49 deletions(-) diff --git a/.github/bin/make-compilation-db.sh b/.github/bin/make-compilation-db.sh index 32b0b264d..68d523bad 100755 --- a/.github/bin/make-compilation-db.sh +++ b/.github/bin/make-compilation-db.sh @@ -13,16 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -u -set -e - -readonly OUTPUT_BASE="$(bazel info output_base)" - -readonly COMPDB_SCRIPT="${OUTPUT_BASE}/external/rules_compdb/generate.py" -[ -r "${COMPDB_SCRIPT}" ] || bazel fetch ... - -python3 "${COMPDB_SCRIPT}" - -# Remove a flags observed in the wild that clang-tidy doesn't understand. -sed -i -e 's/-fno-canonical-system-headers//g; s/DEBUG_PREFIX_MAP_PWD=.//g' \ - compile_commands.json +bazel run @hedron_compile_commands//:refresh_all diff --git a/.github/bin/run-clang-format.sh b/.github/bin/run-clang-format.sh index 33e1116ad..27ed23a2d 100755 --- a/.github/bin/run-clang-format.sh +++ b/.github/bin/run-clang-format.sh @@ -37,7 +37,7 @@ find . -name "*.h" -o -name "*.cc" \ # If we have buildifier installed, use that on BUILD files if command -v ${BUILDIFIER} >/dev/null; then echo "Run $(buildifier --version)" - ${BUILDIFIER} -lint=fix WORKSPACE $(find . -name BUILD -o -name "*.bzl") + ${BUILDIFIER} -lint=fix WORKSPACE* MODULE.bazel $(find . -name BUILD -o -name "*.bzl") fi # Check if we got any diff diff --git a/.github/workflows/verible-ci.yml b/.github/workflows/verible-ci.yml index 5202674bb..3ac2ab9d3 100644 --- a/.github/workflows/verible-ci.yml +++ b/.github/workflows/verible-ci.yml @@ -92,15 +92,28 @@ jobs: path: | /root/.cache/clang-tidy /root/.cache/bazel - key: clang-tidy-${{ steps.cache_timestamp.outputs.time }} - restore-keys: clang-tidy- + key: clang-tidy-2-${{ steps.cache_timestamp.outputs.time }} + restore-keys: clang-tidy-2- - - name: Run clang tidy + - name: Make compilation DB run: | - echo "::group::Make Compilation DB" .github/bin/make-compilation-db.sh wc -l compile_commands.json - echo "::endgroup::" + + - name: Build generated files + run: | + bazel build //common/lsp:jcxxgen-testfile-gen \ + //common/lsp:lsp-protocol-gen \ + //common/util:version-header \ + //verilog/CST:verilog-nonterminals-foreach-gen \ + //verilog/parser:verilog-parse-interface \ + //verilog/parser:gen-verilog-token-enum \ + //third_party/proto/kythe:storage_cc_proto \ + //third_party/proto/kythe:analysis_cc_proto + + - name: Run clang tidy + run: | + wc -l compile_commands.json # 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) diff --git a/MODULE.bazel b/MODULE.bazel index f1dc33971..8728cc042 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,74 +4,87 @@ module( bazel_dep(name = "platforms", version = "0.0.8") bazel_dep(name = "bazel_skylib", version = "1.5.0") - bazel_dep(name = "rules_license", version = "0.0.8") bazel_dep(name = "rules_proto", version = "6.0.0-rc2") bazel_dep(name = "rules_cc", version = "0.0.9") # Register m4 rules and toolchain. bazel_dep(name = "rules_m4", version = "0.2.3") + m4 = use_extension( "@rules_m4//m4/extensions:m4_repository_ext.bzl", "m4_repository_ext", ) m4.repository( name = "m4", - version = "1.4.18", extra_copts = ["-O3"], + version = "1.4.18", ) use_repo(m4, "m4") + register_toolchains("@m4//:toolchain") # Register bison rules and toolchain. bazel_dep(name = "rules_bison", version = "0.2.2") + bison = use_extension( "@rules_bison//bison/extensions:bison_repository_ext.bzl", "bison_repository_ext", ) bison.repository( name = "bison", - version = "3.3.2", extra_copts = ["-O3"], + version = "3.3.2", ) use_repo(bison, "bison") + register_toolchains("@bison//:toolchain") # Register flex rules and toolchain. bazel_dep(name = "rules_flex", version = "0.2.1") + flex = use_extension( "@rules_flex//flex/extensions:flex_repository_ext.bzl", "flex_repository_ext", ) flex.repository( name = "flex", - version = "2.6.4", extra_copts = ["-O3"], + version = "2.6.4", ) use_repo(flex, "flex") + register_toolchains("@flex//:toolchain") # abseil-cpp can not be updated beyond the following curringly, as newer # ones use googletest that is not compatible with bazel 6 anymore. -bazel_dep(name = "abseil-cpp", version = "20240116.2", repo_name="com_google_absl") +bazel_dep(name = "abseil-cpp", version = "20240116.2", repo_name = "com_google_absl") single_version_override( module_name = "abseil-cpp", patch_strip = 1, - version = "20240116.2", patches = ["//bazel:absl.patch"], + version = "20240116.2", ) # Json module only provide the multi-header target, but that will # make misc-inlude-cleaner complain about not direct includes. -bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name="jsonhpp") +bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "jsonhpp") single_version_override( module_name = "nlohmann_json", patches = ["//bazel:nlohmann_module.patch"], ) -bazel_dep(name = "re2", version = "2023-09-01", repo_name="com_googlesource_code_re2") +bazel_dep(name = "re2", version = "2023-09-01", repo_name = "com_googlesource_code_re2") # Newer versions require bazel 7, so this is the last we can use currently. -bazel_dep(name = "googletest", version = "1.14.0.bcr.1", repo_name="com_google_googletest") -bazel_dep(name = "protobuf", version = "26.0", repo_name="com_google_protobuf") +bazel_dep(name = "googletest", version = "1.14.0.bcr.1", repo_name = "com_google_googletest") +bazel_dep(name = "protobuf", version = "26.0", repo_name = "com_google_protobuf") bazel_dep(name = "zlib", version = "1.3.1") + +# Make compilation DB +bazel_dep(name = "hedron_compile_commands", dev_dependency = True) +git_override( + module_name = "hedron_compile_commands", + commit = "1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93", + remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git", +) diff --git a/WORKSPACE b/WORKSPACE index cd03b8bbb..de8accec4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,3 +1,4 @@ +# Legacy workspace for bazel5. Will go away. workspace(name = "com_google_verible") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") @@ -177,14 +178,27 @@ http_archive( ], ) -# 2024-02-06 +# Hedron's Compile Commands Extractor for Bazel +# https://github.com/hedronvision/bazel-compile-commands-extractor http_archive( - name = "rules_compdb", - sha256 = "70232adda61e89a4192be43b4719d35316ed7159466d0ab4f3da0ecb1fbf00b2", - strip_prefix = "bazel-compilation-database-fa872dd80742b3dccd79a711f52f286cbde33676", - urls = ["https://github.com/grailbio/bazel-compilation-database/archive/fa872dd80742b3dccd79a711f52f286cbde33676.tar.gz"], + name = "hedron_compile_commands", + sha256 = "044b148b111e17cee61d8c3aaeed42069f7325460382340afca4919f8265094c", + strip_prefix = "bazel-compile-commands-extractor-1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93", + url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93.tar.gz", ) -load("@rules_compdb//:deps.bzl", "rules_compdb_deps") +load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup") -rules_compdb_deps() +hedron_compile_commands_setup() + +load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive") + +hedron_compile_commands_setup_transitive() + +load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive") + +hedron_compile_commands_setup_transitive_transitive() + +load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive") + +hedron_compile_commands_setup_transitive_transitive_transitive() diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index 61d94c7ac..0e29a353d 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -1,7 +1,6 @@ workspace(name = "com_google_verible") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") # # External tools needed @@ -27,15 +26,3 @@ install_rules_dependencies() load("@com_github_google_rules_install//:setup.bzl", "install_rules_setup") install_rules_setup() - -# 2024-02-06 -http_archive( - name = "rules_compdb", - sha256 = "70232adda61e89a4192be43b4719d35316ed7159466d0ab4f3da0ecb1fbf00b2", - strip_prefix = "bazel-compilation-database-fa872dd80742b3dccd79a711f52f286cbde33676", - urls = ["https://github.com/grailbio/bazel-compilation-database/archive/fa872dd80742b3dccd79a711f52f286cbde33676.tar.gz"], -) - -load("@rules_compdb//:deps.bzl", "rules_compdb_deps") - -rules_compdb_deps()