Merge changes I404f6e5c,I0d2d86f0

* changes:
  Add explicit visibility on the self package in EffectiveVisibilityRules.
  Don't print :__pkg__ for package rules, since that's the default.
This commit is contained in:
Martin Stjernholm 2020-05-14 21:49:05 +00:00 committed by Gerrit Code Review
commit 08f72a9709
2 changed files with 25 additions and 6 deletions

View File

@ -140,7 +140,7 @@ func (r packageRule) matches(m qualifiedModuleName) bool {
}
func (r packageRule) String() string {
return fmt.Sprintf("//%s:__pkg__", r.pkg)
return fmt.Sprintf("//%s", r.pkg) // :__pkg__ is the default, so skip it.
}
// A subpackagesRule is a visibility rule that matches modules in a specific package (i.e.
@ -496,6 +496,13 @@ func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) []string {
rule := effectiveVisibilityRules(ctx.Config(), qualified)
// Modules are implicitly visible to other modules in the same package,
// without checking the visibility rules. Here we need to add that visibility
// explicitly.
if rule != nil && !rule.matches(qualified) {
rule = append(rule, packageRule{dir})
}
return rule.Strings()
}

View File

@ -155,14 +155,20 @@ func TestSnapshotVisibility(t *testing.T) {
java_import {
name: "mysdk_myjavalib@current",
sdk_member_name: "myjavalib",
visibility: ["//other/foo:__pkg__"],
visibility: [
"//other/foo",
"//package",
],
jars: ["java/myjavalib.jar"],
}
java_import {
name: "myjavalib",
prefer: false,
visibility: ["//other/foo:__pkg__"],
visibility: [
"//other/foo",
"//package",
],
jars: ["java/myjavalib.jar"],
}
@ -183,21 +189,27 @@ java_import {
java_import {
name: "mysdk_mydefaultedjavalib@current",
sdk_member_name: "mydefaultedjavalib",
visibility: ["//other/bar:__pkg__"],
visibility: [
"//other/bar",
"//package",
],
jars: ["java/mydefaultedjavalib.jar"],
}
java_import {
name: "mydefaultedjavalib",
prefer: false,
visibility: ["//other/bar:__pkg__"],
visibility: [
"//other/bar",
"//package",
],
jars: ["java/mydefaultedjavalib.jar"],
}
sdk_snapshot {
name: "mysdk@current",
visibility: [
"//other/foo:__pkg__",
"//other/foo",
"//package:__subpackages__",
],
java_header_libs: [