Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/compile_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Comment on lines +144 to +147

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have a test.

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):
Expand Down
12 changes: 5 additions & 7 deletions test/unit/external_repository/test_external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/"
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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__":
Expand Down
Loading