Skip to content

Commit d249428

Browse files
Rajneesh Lakkundifacebook-github-bot
authored andcommitted
Override visibility only if current package's visibility is set
Summary: The visibility of a PACKAGE should use the parent's visibility if it does not call package() explicitly. Reviewed By: stepancheg Differential Revision: D62501751 fbshipit-source-id: 2b20bda5c772d9b7dadf6486051dcca38cc1f425
1 parent 55e4a40 commit d249428

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

app/buck2_interpreter_for_build/src/super_package/eval_ctx.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,31 @@ impl PackageFileEvalCtx {
8383
let merged_package_values =
8484
SuperPackageValuesImpl::merge(self.parent.package_values(), package_values)?;
8585

86-
let PackageFileVisibilityFields {
87-
visibility,
88-
within_view,
89-
inherit,
90-
} = self.visibility.into_inner().unwrap_or_default();
91-
92-
let (visibility, within_view) = if inherit {
93-
(
94-
self.parent.visibility().extend_with(&visibility),
95-
self.parent.within_view().extend_with(&within_view),
96-
)
97-
} else {
98-
(visibility, within_view)
86+
let (visibility, within_view) = match self.visibility.into_inner() {
87+
Some(package_visibility) => {
88+
if package_visibility.inherit {
89+
(
90+
self.parent
91+
.visibility()
92+
.extend_with(&package_visibility.visibility),
93+
self.parent
94+
.within_view()
95+
.extend_with(&package_visibility.within_view),
96+
)
97+
} else {
98+
(
99+
package_visibility.visibility,
100+
package_visibility.within_view,
101+
)
102+
}
103+
}
104+
None => {
105+
// If the package file does not specify any visibility, default to the parent visibility.
106+
(
107+
self.parent.visibility().to_owned(),
108+
self.parent.within_view().to_owned(),
109+
)
110+
}
99111
};
100112

101113
Ok(SuperPackage::new(

tests/e2e/interpreter/test_package_file_visibility.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@
99

1010

1111
from buck2.tests.e2e_util.api.buck import Buck
12-
from buck2.tests.e2e_util.asserts import expect_failure
1312
from buck2.tests.e2e_util.buck_workspace import buck_test
1413

1514

1615
@buck_test(inplace=False)
1716
async def test_no_package_call_does_not_reset_visibility(buck: Buck) -> None:
1817
# Test that PACKAGE file without package() call does not reset visibility inherited from parent PACKAGE file.
1918

20-
# TODO(rajneesh): This test is currently broken. The nested_package:bottom target
21-
# should not reset visibility if the PACKAGE file does not call the package() function.
22-
await expect_failure(
23-
buck.build("root//b:top"),
24-
stderr_regex=".*`root//a/nested_package:bottom` is not visible to `root//b:top`.*",
25-
)
19+
await buck.build("root//b:top")

0 commit comments

Comments
 (0)