From bd2bd1cbe0a6ab06ce6b47b9a9d5f87f149a9cf0 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 10:04:14 +0200 Subject: [PATCH 1/6] 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 4c1a3b94f9d4e39a99ee73dd36543598f5c5e80f Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 10:51:21 +0200 Subject: [PATCH 2/6] 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 22dbdaf1..5c27ab76 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -147,6 +147,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 " @@ -163,6 +168,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 21bd5fda4b3a3d1229f306e96ac58ee055100b99 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 10:58:27 +0200 Subject: [PATCH 3/6] Fix pylint --- test/unit/external_repository/test_external_repo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index 5c27ab76..6d2ec083 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 @@ -147,7 +147,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" @@ -168,7 +168,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 c832ad50d263d8597912e58ebc3822ef08bff0d8 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 11:00:08 +0200 Subject: [PATCH 4/6] 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 6d2ec083..b3f278a2 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -157,8 +157,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): """ @@ -178,8 +177,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 44387c4e4cf7abeb8e5c077146aa9eb5c2c08b9b Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 16 Jun 2026 11:48:20 +0200 Subject: [PATCH 5/6] 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 b3f278a2..0e924227 100644 --- a/test/unit/external_repository/test_external_repo.py +++ b/test/unit/external_repository/test_external_repo.py @@ -147,11 +147,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 " @@ -167,11 +162,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 " From bfc52de1fedc56fe4837118b62da7539e0b812f2 Mon Sep 17 00:00:00 2001 From: "F.Tibor" Date: Tue, 30 Jun 2026 10:15:13 +0200 Subject: [PATCH 6/6] Remove quote includes from transitive targets --- src/compile_commands.bzl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 618102da..efc2da6d 100644 --- a/src/compile_commands.bzl +++ b/src/compile_commands.bzl @@ -141,10 +141,6 @@ 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) if hasattr(compilation_context, "external_includes"): for external_include in compilation_context.external_includes.to_list(): if len(external_include) == 0: