diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/config.go | 12 | ||||
| -rw-r--r-- | android/mutator.go | 8 | ||||
| -rw-r--r-- | android/package.go | 2 | ||||
| -rw-r--r-- | android/package_ctx.go | 23 | ||||
| -rw-r--r-- | android/package_test.go | 2 | ||||
| -rw-r--r-- | android/sdk.go | 2 | ||||
| -rw-r--r-- | android/visibility.go | 51 | ||||
| -rw-r--r-- | android/visibility_test.go | 8 |
8 files changed, 63 insertions, 45 deletions
diff --git a/android/config.go b/android/config.go index 1e5a24de9..271a54a07 100644 --- a/android/config.go +++ b/android/config.go @@ -418,6 +418,18 @@ func (c *config) HostToolPath(ctx PathContext, tool string) Path { return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool) } +func (c *config) HostJNIToolPath(ctx PathContext, path string) Path { + ext := ".so" + if runtime.GOOS == "darwin" { + ext = ".dylib" + } + return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext) +} + +func (c *config) HostJavaToolPath(ctx PathContext, path string) Path { + return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path) +} + // HostSystemTool looks for non-hermetic tools from the system we're running on. // Generally shouldn't be used, but useful to find the XCode SDK, etc. func (c *config) HostSystemTool(name string) string { diff --git a/android/mutator.go b/android/mutator.go index eba0e2fd4..e9ccd7f00 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -78,11 +78,11 @@ var preArch = []RegisterMutatorFunc{ registerLoadHookMutator, RegisterNamespaceMutator, // Rename package module types. - registerPackageRenamer, + RegisterPackageRenamer, RegisterPrebuiltsPreArchMutators, - registerVisibilityRuleChecker, + RegisterVisibilityRuleChecker, RegisterDefaultsPreArchMutators, - registerVisibilityRuleGatherer, + RegisterVisibilityRuleGatherer, } func registerArchMutator(ctx RegisterMutatorsContext) { @@ -99,7 +99,7 @@ var preDeps = []RegisterMutatorFunc{ var postDeps = []RegisterMutatorFunc{ registerPathDepsMutator, RegisterPrebuiltsPostDepsMutators, - registerVisibilityRuleEnforcer, + RegisterVisibilityRuleEnforcer, registerNeverallowMutator, RegisterOverridePostDepsMutators, } diff --git a/android/package.go b/android/package.go index 880d6a97b..ed604c606 100644 --- a/android/package.go +++ b/android/package.go @@ -98,7 +98,7 @@ func PackageFactory() Module { } // Registers the function that renames the packages. -func registerPackageRenamer(ctx RegisterMutatorsContext) { +func RegisterPackageRenamer(ctx RegisterMutatorsContext) { ctx.BottomUp("packageRenamer", packageRenamer).Parallel() ctx.BottomUp("packageErrorReporter", packageErrorReporter).Parallel() } diff --git a/android/package_ctx.go b/android/package_ctx.go index cf8facef4..d3527fa20 100644 --- a/android/package_ctx.go +++ b/android/package_ctx.go @@ -16,7 +16,6 @@ package android import ( "fmt" - "runtime" "strings" "github.com/google/blueprint" @@ -177,46 +176,30 @@ func (p PackageContext) SourcePathVariableWithEnvOverride(name, path, env string // package-scoped variable's initialization. func (p PackageContext) HostBinToolVariable(name, path string) blueprint.Variable { return p.VariableFunc(name, func(ctx PackageVarContext) string { - return p.HostBinToolPath(ctx, path).String() + return ctx.Config().HostToolPath(ctx, path).String() }) } -func (p PackageContext) HostBinToolPath(ctx PackageVarContext, path string) Path { - return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin", path) -} - // HostJNIToolVariable returns a Variable whose value is the path to a host tool // in the lib directory for host targets. It may only be called during a Go // package's initialization - either from the init() function or as part of a // package-scoped variable's initialization. func (p PackageContext) HostJNIToolVariable(name, path string) blueprint.Variable { return p.VariableFunc(name, func(ctx PackageVarContext) string { - return p.HostJNIToolPath(ctx, path).String() + return ctx.Config().HostJNIToolPath(ctx, path).String() }) } -func (p PackageContext) HostJNIToolPath(ctx PackageVarContext, path string) Path { - ext := ".so" - if runtime.GOOS == "darwin" { - ext = ".dylib" - } - return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "lib64", path+ext) -} - // HostJavaToolVariable returns a Variable whose value is the path to a host // tool in the frameworks directory for host targets. It may only be called // during a Go package's initialization - either from the init() function or as // part of a package-scoped variable's initialization. func (p PackageContext) HostJavaToolVariable(name, path string) blueprint.Variable { return p.VariableFunc(name, func(ctx PackageVarContext) string { - return p.HostJavaToolPath(ctx, path).String() + return ctx.Config().HostJavaToolPath(ctx, path).String() }) } -func (p PackageContext) HostJavaToolPath(ctx PackageVarContext, path string) Path { - return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", path) -} - // IntermediatesPathVariable returns a Variable whose value is the intermediate // directory appended with the supplied path. It may only be called during a Go // package's initialization - either from the init() function or as part of a diff --git a/android/package_test.go b/android/package_test.go index ae286d662..8071c51b0 100644 --- a/android/package_test.go +++ b/android/package_test.go @@ -88,7 +88,7 @@ func testPackage(fs map[string][]byte) (*TestContext, []error) { ctx := NewTestArchContext() ctx.RegisterModuleType("package", PackageFactory) - ctx.PreArchMutators(registerPackageRenamer) + ctx.PreArchMutators(RegisterPackageRenamer) ctx.Register() ctx.MockFileSystem(fs) diff --git a/android/sdk.go b/android/sdk.go index b9220ca69..533bd0ee6 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -178,7 +178,7 @@ type SnapshotBuilder interface { // prefer=true. And one that is not versioned, not marked as prefer=true and // will only be used if the equivalently named non-prebuilt module is not // present. - AddPrebuiltModule(name string, moduleType string) BpModule + AddPrebuiltModule(member SdkMember, moduleType string) BpModule } // A set of properties for use in a .bp file. diff --git a/android/visibility.go b/android/visibility.go index a7e718ba7..c28ec93f4 100644 --- a/android/visibility.go +++ b/android/visibility.go @@ -117,12 +117,15 @@ func (c compositeRule) matches(m qualifiedModuleName) bool { } func (c compositeRule) String() string { + return "[" + strings.Join(c.Strings(), ", ") + "]" +} + +func (c compositeRule) Strings() []string { s := make([]string, 0, len(c)) for _, r := range c { s = append(s, r.String()) } - - return "[" + strings.Join(s, ", ") + "]" + return s } // A packageRule is a visibility rule that matches modules in a specific package (i.e. directory). @@ -189,7 +192,7 @@ func moduleToVisibilityRuleMap(ctx BaseModuleContext) *sync.Map { // The rule checker needs to be registered before defaults expansion to correctly check that // //visibility:xxx isn't combined with other packages in the same list in any one module. -func registerVisibilityRuleChecker(ctx RegisterMutatorsContext) { +func RegisterVisibilityRuleChecker(ctx RegisterMutatorsContext) { ctx.BottomUp("visibilityRuleChecker", visibilityRuleChecker).Parallel() } @@ -199,12 +202,12 @@ func registerVisibilityRuleChecker(ctx RegisterMutatorsContext) { // having to process multiple variants for each module. This goes after defaults expansion to gather // the complete visibility lists from flat lists and after the package info is gathered to ensure // that default_visibility is available. -func registerVisibilityRuleGatherer(ctx RegisterMutatorsContext) { +func RegisterVisibilityRuleGatherer(ctx RegisterMutatorsContext) { ctx.BottomUp("visibilityRuleGatherer", visibilityRuleGatherer).Parallel() } // This must be registered after the deps have been resolved. -func registerVisibilityRuleEnforcer(ctx RegisterMutatorsContext) { +func RegisterVisibilityRuleEnforcer(ctx RegisterMutatorsContext) { ctx.TopDown("visibilityRuleEnforcer", visibilityRuleEnforcer).Parallel() } @@ -384,8 +387,6 @@ func visibilityRuleEnforcer(ctx TopDownMutatorContext) { qualified := createQualifiedModuleName(ctx) - moduleToVisibilityRule := moduleToVisibilityRuleMap(ctx) - // Visit all the dependencies making sure that this module has access to them all. ctx.VisitDirectDeps(func(dep Module) { depName := ctx.OtherModuleName(dep) @@ -397,19 +398,25 @@ func visibilityRuleEnforcer(ctx TopDownMutatorContext) { return } - value, ok := moduleToVisibilityRule.Load(depQualified) - var rule compositeRule - if ok { - rule = value.(compositeRule) - } else { - rule = packageDefaultVisibility(ctx, depQualified) - } + rule := effectiveVisibilityRules(ctx, depQualified) if rule != nil && !rule.matches(qualified) { ctx.ModuleErrorf("depends on %s which is not visible to this module", depQualified) } }) } +func effectiveVisibilityRules(ctx BaseModuleContext, qualified qualifiedModuleName) compositeRule { + moduleToVisibilityRule := moduleToVisibilityRuleMap(ctx) + value, ok := moduleToVisibilityRule.Load(qualified) + var rule compositeRule + if ok { + rule = value.(compositeRule) + } else { + rule = packageDefaultVisibility(ctx, qualified) + } + return rule +} + func createQualifiedModuleName(ctx BaseModuleContext) qualifiedModuleName { moduleName := ctx.ModuleName() dir := ctx.ModuleDir() @@ -433,3 +440,19 @@ func packageDefaultVisibility(ctx BaseModuleContext, moduleId qualifiedModuleNam packageQualifiedId = packageQualifiedId.getContainingPackageId() } } + +// Get the effective visibility rules, i.e. the actual rules that affect the visibility of the +// property irrespective of where they are defined. +// +// Includes visibility rules specified by package default_visibility and/or on defaults. +// Short hand forms, e.g. //:__subpackages__ are replaced with their full form, e.g. +// //package/containing/rule:__subpackages__. +func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) []string { + moduleName := ctx.OtherModuleName(module) + dir := ctx.OtherModuleDir(module) + qualified := qualifiedModuleName{dir, moduleName} + + rule := effectiveVisibilityRules(ctx, qualified) + + return rule.Strings() +} diff --git a/android/visibility_test.go b/android/visibility_test.go index fd9e98c55..1984a2189 100644 --- a/android/visibility_test.go +++ b/android/visibility_test.go @@ -874,11 +874,11 @@ func testVisibility(buildDir string, fs map[string][]byte) (*TestContext, []erro ctx.RegisterModuleType("package", PackageFactory) ctx.RegisterModuleType("mock_library", newMockLibraryModule) ctx.RegisterModuleType("mock_defaults", defaultsFactory) - ctx.PreArchMutators(registerPackageRenamer) - ctx.PreArchMutators(registerVisibilityRuleChecker) + ctx.PreArchMutators(RegisterPackageRenamer) + ctx.PreArchMutators(RegisterVisibilityRuleChecker) ctx.PreArchMutators(RegisterDefaultsPreArchMutators) - ctx.PreArchMutators(registerVisibilityRuleGatherer) - ctx.PostDepsMutators(registerVisibilityRuleEnforcer) + ctx.PreArchMutators(RegisterVisibilityRuleGatherer) + ctx.PostDepsMutators(RegisterVisibilityRuleEnforcer) ctx.Register() ctx.MockFileSystem(fs) |