Simplify visibility rules that include //visibility:public
While it is invalid to mix //visibility:public with other rules in the
visibility property in a .bp file tt was possible, by overriding
defaults, to have //visibility:public mixed in with other rules in the
effective visibility rules. That caused problems when those effective
rules were used in an sdk snapshot.
This change replaces any set of rules that include //visibility:public
with just the //visibility:public rule. That simplifies those rules,
making them cheaper to process and ensures that the effective rules are
valid in the visibility property.
Adding test support required some refactoring of the
effectiveVisibilityRules(BaseModuleContext, ...) and underlying methods
to take a Config instead of BaseModuleContext as the tests do not have
access to BaseModuleContext.
Bug: 142935992
Test: m nothing - new tests failed without change, work with it
Add dex2oat to art-module-host-exports, build it and check the
generated Android.bp file in the snapshot to ensure the
visibility property for the dex2oat prebuilt does not mix
//visibility:public with other rules.
Change-Id: I08e7f0dcb40838d426fe88fedf69eae27b77473c
diff --git a/android/visibility_test.go b/android/visibility_test.go
index 6006072..8dd6a8f 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -1,15 +1,17 @@
package android
import (
+ "reflect"
"testing"
"github.com/google/blueprint"
)
var visibilityTests = []struct {
- name string
- fs map[string][]byte
- expectedErrors []string
+ name string
+ fs map[string][]byte
+ expectedErrors []string
+ effectiveVisibility map[qualifiedModuleName][]string
}{
{
name: "invalid visibility: empty list",
@@ -493,6 +495,9 @@
deps: ["libexample"],
}`),
},
+ effectiveVisibility: map[qualifiedModuleName][]string{
+ qualifiedModuleName{pkg: "top", name: "libexample"}: {"//visibility:public"},
+ },
},
{
name: "//visibility:public mixed with other from different defaults 1",
@@ -903,13 +908,27 @@
func TestVisibility(t *testing.T) {
for _, test := range visibilityTests {
t.Run(test.name, func(t *testing.T) {
- _, errs := testVisibility(buildDir, test.fs)
+ ctx, errs := testVisibility(buildDir, test.fs)
CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
+
+ if test.effectiveVisibility != nil {
+ checkEffectiveVisibility(t, ctx, test.effectiveVisibility)
+ }
})
}
}
+func checkEffectiveVisibility(t *testing.T, ctx *TestContext, effectiveVisibility map[qualifiedModuleName][]string) {
+ for moduleName, expectedRules := range effectiveVisibility {
+ rule := effectiveVisibilityRules(ctx.config, moduleName)
+ stringRules := rule.Strings()
+ if !reflect.DeepEqual(expectedRules, stringRules) {
+ t.Errorf("effective rules mismatch: expected %q, found %q", expectedRules, stringRules)
+ }
+ }
+}
+
func testVisibility(buildDir string, fs map[string][]byte) (*TestContext, []error) {
// Create a new config per test as visibility information is stored in the config.