Commit 809dbeda authored by cjhopman's avatar cjhopman Committed by Commit bot

GN: fix datadeps visibility check

The visibility check was checking the origin of deps[i] instead of
datadeps[i].

Review URL: https://codereview.chromium.org/551843006

Cr-Commit-Position: refs/heads/master@{#295102}
parent 777f920e
...@@ -362,7 +362,7 @@ bool Target::CheckVisibility(Err* err) const { ...@@ -362,7 +362,7 @@ bool Target::CheckVisibility(Err* err) const {
} }
for (size_t i = 0; i < datadeps_.size(); i++) { for (size_t i = 0; i < datadeps_.size(); i++) {
if (deps_[i].origin && if (datadeps_[i].origin &&
!Visibility::CheckItemVisibility(this, datadeps_[i].ptr, err)) !Visibility::CheckItemVisibility(this, datadeps_[i].ptr, err))
return false; return false;
} }
......
...@@ -373,6 +373,28 @@ TEST(Target, VisibilityFails) { ...@@ -373,6 +373,28 @@ TEST(Target, VisibilityFails) {
ASSERT_FALSE(a.OnResolved(&err)); ASSERT_FALSE(a.OnResolved(&err));
} }
// Test visibility with a single datadep.
TEST(Target, VisibilityDatadeps) {
TestWithScope setup;
Err err;
Target b(setup.settings(), Label(SourceDir("//public/"), "b"));
b.set_output_type(Target::STATIC_LIBRARY);
b.SetToolchain(setup.toolchain());
b.visibility().SetPublic();
ASSERT_TRUE(b.OnResolved(&err));
// Make a target depending on "b". The dependency must have an origin to mark
// it as user-set so we check visibility. This check should fail.
Target a(setup.settings(), Label(SourceDir("//app/"), "a"));
a.set_output_type(Target::EXECUTABLE);
a.datadeps().push_back(LabelTargetPair(&b));
IdentifierNode origin; // Dummy origin.
a.datadeps()[0].origin = &origin;
a.SetToolchain(setup.toolchain());
ASSERT_TRUE(a.OnResolved(&err)) << err.help_text();
}
// Tests that A -> Group -> B where the group is visible from A but B isn't, // Tests that A -> Group -> B where the group is visible from A but B isn't,
// passes visibility even though the group's deps get expanded into A. // passes visibility even though the group's deps get expanded into A.
TEST(Target, VisibilityGroup) { TEST(Target, VisibilityGroup) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment