diff --git a/src/compile_commands.bzl b/src/compile_commands.bzl index 12eb8257..618102da 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 @@ -111,6 +112,11 @@ def get_compile_flags(ctx, dep): 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: + external_include = "." + options.append(EXTERNAL_INCLUDE + external_include) for attr in SOURCE_ATTR: if not hasattr(ctx.rule.attr, attr): @@ -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) + 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 def get_sources(ctx): diff --git a/test/unit/external_repository/test_external_repo.py b/test/unit/external_repository/test_external_repo.py index 12c6d764..49af98e4 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/" @@ -159,8 +159,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): """ @@ -175,8 +174,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__":