From cefd9321cac2948eca6070c89fb1754d0d56fe74 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 10:04:14 +0200 Subject: [PATCH 1/5] Fixed issues with --features=external_include_paths --- src/compile_commands.bzl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 12eb8257..72b29e9d 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -76,6 +76,7 @@ _cc_rules = [ SYSTEM_INCLUDE = "-isystem " QUOTE_INCLUDE = "-iquote " +EXTERNAL_INCLUDE = "-isystem " # Function copied from https://gist.github.com/oquenchil/7e2c2bd761aa1341b458cc25608da50c # NOTE: added local_defines @@ -112,6 +113,11 @@ def get_compile_flags(ctx, dep): quote_include = "." options.append(QUOTE_INCLUDE + quote_include) + for external_include in compilation_context.external_includes.to_list(): + if len(external_include) == 0: + external_include = "." + options.append(EXTERNAL_INCLUDE + external_include) + for attr in SOURCE_ATTR: if not hasattr(ctx.rule.attr, attr): continue @@ -135,6 +141,16 @@ def get_compile_flags(ctx, dep): system_include = "." options.append(SYSTEM_INCLUDE + system_include) + for quote_include in compilation_context.quote_includes.to_list(): + if len(quote_include) == 0: + quote_include = "." + options.append(QUOTE_INCLUDE + quote_include) + + for external_include in compilation_context.external_includes.to_list(): + if len(external_include) == 0: + external_include = "." + options.append(EXTERNAL_INCLUDE + external_include) + return options def get_sources(ctx): From eea1a90094ea2af1c4881487829c82d4d914d8a8 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 10:51:21 +0200 Subject: [PATCH 2/5] Ignore improvements for Bazel 6 --- README.md | 5 +++++ src/compile_commands.bzl | 20 +++++++++---------- .../external_repository/test_external_repo.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b8d5e702..c9215043 100644 --- a/README.md +++ b/README.md @@ -427,3 +427,8 @@ After that you can find all artifacts in `bazel-bin` directory: # compile_commands.json for compile_commands_pass cat bazel-bin/test/compile_commands_pass/compile_commands.json + + +Limitations: +------------ +In Bazel 6, we do not support using the `--features=external_include_paths` flag. diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 72b29e9d..618102da 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -112,11 +112,11 @@ def get_compile_flags(ctx, dep): if len(quote_include) == 0: quote_include = "." options.append(QUOTE_INCLUDE + quote_include) - - for external_include in compilation_context.external_includes.to_list(): - if len(external_include) == 0: - external_include = "." - options.append(EXTERNAL_INCLUDE + external_include) + if hasattr(compilation_context, "external_includes"): + for external_include in compilation_context.external_includes.to_list(): + if len(external_include) == 0: + external_include = "." + options.append(EXTERNAL_INCLUDE + external_include) for attr in SOURCE_ATTR: if not hasattr(ctx.rule.attr, attr): @@ -145,11 +145,11 @@ def get_compile_flags(ctx, dep): if len(quote_include) == 0: quote_include = "." options.append(QUOTE_INCLUDE + quote_include) - - for external_include in compilation_context.external_includes.to_list(): - if len(external_include) == 0: - external_include = "." - options.append(EXTERNAL_INCLUDE + external_include) + if hasattr(compilation_context, "external_includes"): + for external_include in compilation_context.external_includes.to_list(): + if len(external_include) == 0: + external_include = "." + options.append(EXTERNAL_INCLUDE + external_include) return options diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index 12c6d764..81171100 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -154,6 +154,11 @@ def test_codechecker_external_include_paths(self): --experimental_cc_implementation_deps --enable_bzlmod --features=external_include_paths """ + if int(self.BAZEL_VERSION[0]) <= 6: # pyright: ignore + self.skipTest( + "For Bazel 6 and older we do not support: " + "--features=external_include_paths" + ) ret, _, stderr = self.run_command( "bazel test :codechecker_external_deps " "--experimental_cc_implementation_deps --enable_bzlmod " @@ -170,6 +175,11 @@ def test_per_file_external_include_paths(self): --experimental_cc_implementation_deps --features=external_include_paths """ + if int(self.BAZEL_VERSION[0]) <= 6: # pyright: ignore + self.skipTest( + "For Bazel 6 and older we do not support: " + "--features=external_include_paths" + ) ret, _, stderr = self.run_command( "bazel test :per_file_external_deps " "--experimental_cc_implementation_deps --enable_bzlmod " From 57ace182a5ca857d3c4e18f9f9059686fa658dbe Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 10:58:27 +0200 Subject: [PATCH 3/5] Fix pylint --- test/unit/external_repository/test_external_repo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index 81171100..db7ace25 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -32,7 +32,7 @@ class TestImplDepExternalDep(TestBase): __test_path__ = os.path.dirname(os.path.abspath(__file__)) BAZEL_BIN_DIR = os.path.join("bazel-bin") BAZEL_TESTLOGS_DIR = os.path.join("bazel-testlogs") - BAZEL_VERSION = None + BAZEL_VERSION: str = "" @final @classmethod @@ -104,13 +104,13 @@ def test_compile_commands_external_lib(self): ) # The ~override part is a consquence of using Bzlmod. - if self.BAZEL_VERSION.startswith("6"): # type: ignore + if self.BAZEL_VERSION.startswith("6"): pattern1 = "-isystem external/external_lib~override/include" pattern2 = ( "-isystem bazel-out/k8-fastbuild/bin/external/" "external_lib~override/include" ) - elif self.BAZEL_VERSION.startswith("7"): # type: ignore + elif self.BAZEL_VERSION.startswith("7"): pattern1 = "-isystem external/external_lib~/include" pattern2 = ( "-isystem bazel-out/k8-fastbuild/bin/external/" @@ -154,7 +154,7 @@ def test_codechecker_external_include_paths(self): --experimental_cc_implementation_deps --enable_bzlmod --features=external_include_paths """ - if int(self.BAZEL_VERSION[0]) <= 6: # pyright: ignore + if int(self.BAZEL_VERSION[0]) <= 6: self.skipTest( "For Bazel 6 and older we do not support: " "--features=external_include_paths" @@ -175,7 +175,7 @@ def test_per_file_external_include_paths(self): --experimental_cc_implementation_deps --features=external_include_paths """ - if int(self.BAZEL_VERSION[0]) <= 6: # pyright: ignore + if int(self.BAZEL_VERSION[0]) <= 6: self.skipTest( "For Bazel 6 and older we do not support: " "--features=external_include_paths" From e037af22aa645ba74df8c64d1c57844878b70846 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 11:00:08 +0200 Subject: [PATCH 4/5] Enable tests --- test/unit/external_repository/test_external_repo.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index db7ace25..cb91333c 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -164,8 +164,7 @@ def test_codechecker_external_include_paths(self): "--experimental_cc_implementation_deps --enable_bzlmod " "--features=external_include_paths" ) - # FIXME: Should find nothing.h and finish with exit code 0 - self.assertEqual(ret, 1, stderr) + self.assertEqual(ret, 0, stderr) def test_per_file_external_include_paths(self): """ @@ -185,8 +184,7 @@ def test_per_file_external_include_paths(self): "--experimental_cc_implementation_deps --enable_bzlmod " "--features=external_include_paths" ) - # FIXME: Should find nothing.h and finish with exit code 0 - self.assertEqual(ret, 3, stderr) + self.assertEqual(ret, 0, stderr) if __name__ == "__main__": From e1b26ffcac5cbbebac1b73c07f29c8a461d216e4 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 11:48:20 +0200 Subject: [PATCH 5/5] Remove bazel 6 specific modifications --- README.md | 5 ----- test/unit/external_repository/test_external_repo.py | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/README.md b/README.md index c9215043..b8d5e702 100644 --- a/README.md +++ b/README.md @@ -427,8 +427,3 @@ After that you can find all artifacts in `bazel-bin` directory: # compile_commands.json for compile_commands_pass cat bazel-bin/test/compile_commands_pass/compile_commands.json - - -Limitations: ------------- -In Bazel 6, we do not support using the `--features=external_include_paths` flag. diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index cb91333c..49af98e4 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -154,11 +154,6 @@ def test_codechecker_external_include_paths(self): --experimental_cc_implementation_deps --enable_bzlmod --features=external_include_paths """ - if int(self.BAZEL_VERSION[0]) <= 6: - self.skipTest( - "For Bazel 6 and older we do not support: " - "--features=external_include_paths" - ) ret, _, stderr = self.run_command( "bazel test :codechecker_external_deps " "--experimental_cc_implementation_deps --enable_bzlmod " @@ -174,11 +169,6 @@ def test_per_file_external_include_paths(self): --experimental_cc_implementation_deps --features=external_include_paths """ - if int(self.BAZEL_VERSION[0]) <= 6: - self.skipTest( - "For Bazel 6 and older we do not support: " - "--features=external_include_paths" - ) ret, _, stderr = self.run_command( "bazel test :per_file_external_deps " "--experimental_cc_implementation_deps --enable_bzlmod "