Skip to content

Commit

Permalink
fix(aspect): Allow multiple dependencies providing the same header
Browse files Browse the repository at this point in the history
Such cases shall not cause the DWYU dependency to report an unused
dependency.
  • Loading branch information
martis42 committed Sep 17, 2024
1 parent 2848385 commit f152ed6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/analyze_includes/evaluate_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def _check_for_invalid_includes(
):
legal_include = True
dep.usage.update(usage)
break
if not legal_include:
# Might be a file from the target under inspection
legal_include = does_include_match_available_files(
Expand Down
19 changes: 19 additions & 0 deletions src/analyze_includes/test/evaluate_includes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,25 @@ def test_public_dependencies_which_should_be_private_disabled(self) -> None:

self.assertTrue(result.is_ok())

def test_include_matching_multiple_dependencies(self) -> None:
result = evaluate_includes(
public_includes=[Include(file=Path("file1"), include="bar.h")],
private_includes=[],
system_under_inspection=SystemUnderInspection(
target_under_inspection=CcTarget(name="foo", header_files=[]),
deps=[
CcTarget(name="fizz", header_files=["bar.h"]),
CcTarget(name="buzz", header_files=["bar.h"]),
],
impl_deps=[],
include_paths=[""],
defines=[],
),
ensure_private_deps=False,
)

self.assertTrue(result.is_ok())


if __name__ == "__main__":
unittest.main()
18 changes: 18 additions & 0 deletions test/aspect/multiple_deps_for_one_header/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cc_library(
name = "foo",
hdrs = ["foo.h"],
deps = [
":bar_a",
":bar_b",
],
)

cc_library(
name = "bar_a",
hdrs = ["bar.h"],
)

cc_library(
name = "bar_b",
hdrs = ["bar.h"],
)
Empty file.
1 change: 1 addition & 0 deletions test/aspect/multiple_deps_for_one_header/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "multiple_deps_for_one_header/bar.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from result import ExpectedResult, Result
from test_case import TestCaseBase


class TestCase(TestCaseBase):
def execute_test_logic(self) -> Result:
"""
Multiple dependencies providing the same header can be considered an antipattern. Still, with respect to the
DWYU principles it is not wrong. Such cases should not cause a DWYU error.
"""
expected = ExpectedResult(success=True)
actual = self._run_dwyu(target="//multiple_deps_for_one_header:foo", aspect=self.default_aspect)

return self._check_result(actual=actual, expected=expected)

0 comments on commit f152ed6

Please sign in to comment.