diff options
| -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 | ||||
| -rw-r--r-- | apex/builder.go | 2 | ||||
| -rw-r--r-- | cc/cc.go | 34 | ||||
| -rw-r--r-- | cc/compiler.go | 2 | ||||
| -rw-r--r-- | cc/config/clang.go | 15 | ||||
| -rw-r--r-- | cc/config/global.go | 4 | ||||
| -rw-r--r-- | cc/library.go | 42 | ||||
| -rw-r--r-- | cc/ndk_library.go | 1 | ||||
| -rw-r--r-- | cc/prebuilt.go | 1 | ||||
| -rw-r--r-- | cc/rs.go | 2 | ||||
| -rw-r--r-- | cc/vndk.go | 2 | ||||
| -rw-r--r-- | java/config/config.go | 10 | ||||
| -rw-r--r-- | java/droiddoc.go | 2 | ||||
| -rw-r--r-- | java/hiddenapi_singleton.go | 2 | ||||
| -rw-r--r-- | java/java.go | 2 | ||||
| -rw-r--r-- | sdk/cc_sdk_test.go | 4 | ||||
| -rw-r--r-- | sdk/java_sdk_test.go | 12 | ||||
| -rw-r--r-- | sdk/sdk_test.go | 120 | ||||
| -rw-r--r-- | sdk/testing.go | 16 | ||||
| -rw-r--r-- | sdk/update.go | 18 |
27 files changed, 293 insertions, 106 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) diff --git a/apex/builder.go b/apex/builder.go index 0232c1e4e..7fe0af33e 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -43,7 +43,7 @@ func init() { if !ctx.Config().FrameworksBaseDirExists(ctx) { return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool) } else { - return pctx.HostBinToolPath(ctx, tool).String() + return ctx.Config().HostToolPath(ctx, tool).String() } }) } @@ -94,6 +94,7 @@ type Deps struct { GeneratedSources []string GeneratedHeaders []string + GeneratedDeps []string ReexportGeneratedHeaders []string @@ -120,14 +121,16 @@ type PathDeps struct { // Paths to generated source files GeneratedSources android.Paths GeneratedHeaders android.Paths + GeneratedDeps android.Paths - Flags []string - IncludeDirs android.Paths - SystemIncludeDirs android.Paths - ReexportedDirs android.Paths - ReexportedSystemDirs android.Paths - ReexportedFlags []string - ReexportedDeps android.Paths + Flags []string + IncludeDirs android.Paths + SystemIncludeDirs android.Paths + ReexportedDirs android.Paths + ReexportedSystemDirs android.Paths + ReexportedFlags []string + ReexportedGeneratedHeaders android.Paths + ReexportedDeps android.Paths // Paths to crt*.o files CrtBegin, CrtEnd android.OptionalPath @@ -894,6 +897,13 @@ func (c *Module) ExportedDeps() android.Paths { return nil } +func (c *Module) ExportedGeneratedHeaders() android.Paths { + if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok { + return flagsProducer.exportedGeneratedHeaders() + } + return nil +} + func isBionic(name string) bool { switch name { case "libc", "libm", "libdl", "libdl_android", "linker": @@ -1905,6 +1915,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...) depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...) depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...) + depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...) } ctx.VisitDirectDeps(func(dep android.Module) { @@ -1928,11 +1939,15 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { case genHeaderDepTag, genHeaderExportDepTag: if genRule, ok := dep.(genrule.SourceFileGenerator); ok { depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, + genRule.GeneratedSourceFiles()...) + depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, genRule.GeneratedDeps()...) dirs := genRule.GeneratedHeaderDirs() depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...) if depTag == genHeaderExportDepTag { depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...) + depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, + genRule.GeneratedSourceFiles()...) depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...) // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...) @@ -2045,7 +2060,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { if _, ok := ccDep.(*Module); ok { if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok { depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...) - depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...) + depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...) + depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...) depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...) if t.ReexportFlags { @@ -2243,10 +2259,12 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs) depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs) depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders) + depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps) depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs) depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs) depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags) depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps) + depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders) if c.sabi != nil { c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes) diff --git a/cc/compiler.go b/cc/compiler.go index 2bc6ae26e..1ced451fa 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -560,7 +560,7 @@ func ndkPathDeps(ctx ModuleContext) android.Paths { } func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { - pathDeps := deps.GeneratedHeaders + pathDeps := deps.GeneratedDeps pathDeps = append(pathDeps, ndkPathDeps(ctx)...) buildFlags := flagsToBuilderFlags(flags) diff --git a/cc/config/clang.go b/cc/config/clang.go index 8618d0955..eddc34104 100644 --- a/cc/config/clang.go +++ b/cc/config/clang.go @@ -132,10 +132,6 @@ func init() { // Disable -Winconsistent-missing-override until we can clean up the existing // codebase for it. "-Wno-inconsistent-missing-override", - - // Warnings from clang-10 - // Nested and array designated initialization is nice to have. - "-Wno-c99-designator", }, " ")) pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{ @@ -165,10 +161,6 @@ func init() { // new warnings are fixed. "-Wno-tautological-constant-compare", "-Wno-tautological-type-limit-compare", - // http://b/145210666 - "-Wno-reorder-init-list", - // http://b/145211066 - "-Wno-implicit-int-float-conversion", }, " ")) // Extra cflags for external third-party projects to disable warnings that @@ -184,13 +176,6 @@ func init() { // Bug: http://b/29823425 Disable -Wnull-dereference until the // new instances detected by this warning are fixed. "-Wno-null-dereference", - - // http://b/145211477 - "-Wno-pointer-compare", - // http://b/145211022 - "-Wno-xor-used-as-pow", - // http://b/145211022 - "-Wno-final-dtor-non-final-class", }, " ")) } diff --git a/cc/config/global.go b/cc/config/global.go index bae5555f9..0a09fa4e7 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -126,8 +126,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r370808" - ClangDefaultShortVersion = "10.0.1" + ClangDefaultVersion = "clang-r365631b" + ClangDefaultShortVersion = "9.0.7" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ diff --git a/cc/library.go b/cc/library.go index 60b00b193..4b8e05205 100644 --- a/cc/library.go +++ b/cc/library.go @@ -238,6 +238,7 @@ type flagExporter struct { systemDirs android.Paths flags []string deps android.Paths + headers android.Paths } func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths { @@ -281,6 +282,12 @@ func (f *flagExporter) reexportDeps(deps ...android.Path) { f.deps = append(f.deps, deps...) } +// addExportedGeneratedHeaders does nothing but collects generated header files. +// This can be differ to exportedDeps which may contain phony files to minimize ninja. +func (f *flagExporter) addExportedGeneratedHeaders(headers ...android.Path) { + f.headers = append(f.headers, headers...) +} + func (f *flagExporter) exportedDirs() android.Paths { return f.dirs } @@ -297,11 +304,16 @@ func (f *flagExporter) exportedDeps() android.Paths { return f.deps } +func (f *flagExporter) exportedGeneratedHeaders() android.Paths { + return f.headers +} + type exportedFlagsProducer interface { exportedDirs() android.Paths exportedSystemDirs() android.Paths exportedFlags() []string exportedDeps() android.Paths + exportedGeneratedHeaders() android.Paths } var _ exportedFlagsProducer = (*flagExporter)(nil) @@ -967,12 +979,16 @@ func (library *libraryDecorator) link(ctx ModuleContext, library.reexportSystemDirs(deps.ReexportedSystemDirs...) library.reexportFlags(deps.ReexportedFlags...) library.reexportDeps(deps.ReexportedDeps...) + library.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) if Bool(library.Properties.Aidl.Export_aidl_headers) { if library.baseCompiler.hasSrcExt(".aidl") { dir := android.PathForModuleGen(ctx, "aidl") library.reexportDirs(dir) - library.reexportDeps(library.baseCompiler.pathDeps...) // TODO: restrict to aidl deps + + // TODO: restrict to aidl deps + library.reexportDeps(library.baseCompiler.pathDeps...) + library.addExportedGeneratedHeaders(library.baseCompiler.pathDeps...) } } @@ -984,7 +1000,10 @@ func (library *libraryDecorator) link(ctx ModuleContext, } includes = append(includes, flags.proto.Dir) library.reexportDirs(includes...) - library.reexportDeps(library.baseCompiler.pathDeps...) // TODO: restrict to proto deps + + // TODO: restrict to proto deps + library.reexportDeps(library.baseCompiler.pathDeps...) + library.addExportedGeneratedHeaders(library.baseCompiler.pathDeps...) } } @@ -1002,6 +1021,7 @@ func (library *libraryDecorator) link(ctx ModuleContext, library.reexportDirs(dir) library.reexportDeps(library.baseCompiler.pathDeps...) + library.addExportedGeneratedHeaders(library.baseCompiler.pathDeps...) } if library.buildStubs() { @@ -1435,10 +1455,10 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { // copy exported header files and stub *.so files func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { info := organizeVariants(member) - buildSharedNativeLibSnapshot(sdkModuleContext, info, builder) + buildSharedNativeLibSnapshot(sdkModuleContext, info, builder, member) } -func buildSharedNativeLibSnapshot(sdkModuleContext android.ModuleContext, info *nativeLibInfo, builder android.SnapshotBuilder) { +func buildSharedNativeLibSnapshot(sdkModuleContext android.ModuleContext, info *nativeLibInfo, builder android.SnapshotBuilder, member android.SdkMember) { // a function for emitting include dirs printExportedDirCopyCommandsForNativeLibs := func(lib archSpecificNativeLibInfo) { includeDirs := lib.exportedIncludeDirs @@ -1448,7 +1468,7 @@ func buildSharedNativeLibSnapshot(sdkModuleContext android.ModuleContext, info * } for _, dir := range includeDirs { if _, gen := dir.(android.WritablePath); gen { - // generated headers are copied via exportedDeps. See below. + // generated headers are copied via exportedGeneratedHeaders. See below. continue } targetDir := nativeIncludeDir @@ -1465,7 +1485,7 @@ func buildSharedNativeLibSnapshot(sdkModuleContext android.ModuleContext, info * } } - genHeaders := lib.exportedDeps + genHeaders := lib.exportedGeneratedHeaders for _, file := range genHeaders { targetDir := nativeGeneratedIncludeDir if info.hasArchSpecificFlags { @@ -1489,10 +1509,10 @@ func buildSharedNativeLibSnapshot(sdkModuleContext android.ModuleContext, info * } } - info.generatePrebuiltLibrary(sdkModuleContext, builder) + info.generatePrebuiltLibrary(sdkModuleContext, builder, member) } -func (info *nativeLibInfo) generatePrebuiltLibrary(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) { +func (info *nativeLibInfo) generatePrebuiltLibrary(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { // a function for emitting include dirs addExportedDirsForNativeLibs := func(lib archSpecificNativeLibInfo, properties android.BpPropertySet, systemInclude bool) { @@ -1509,7 +1529,7 @@ func (info *nativeLibInfo) generatePrebuiltLibrary(sdkModuleContext android.Modu properties.AddProperty(propertyName, includeDirs) } - pbm := builder.AddPrebuiltModule(info.name, "cc_prebuilt_library_shared") + pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_library_shared") if !info.hasArchSpecificFlags { addExportedDirsForNativeLibs(info.archVariants[0], pbm, false /*systemInclude*/) @@ -1574,7 +1594,7 @@ type archSpecificNativeLibInfo struct { exportedIncludeDirs android.Paths exportedSystemIncludeDirs android.Paths exportedFlags []string - exportedDeps android.Paths + exportedGeneratedHeaders android.Paths outputFile android.Path } @@ -1608,7 +1628,7 @@ func organizeVariants(member android.SdkMember) *nativeLibInfo { exportedIncludeDirs: ccModule.ExportedIncludeDirs(), exportedSystemIncludeDirs: ccModule.ExportedSystemIncludeDirs(), exportedFlags: ccModule.ExportedFlags(), - exportedDeps: ccModule.ExportedDeps(), + exportedGeneratedHeaders: ccModule.ExportedGeneratedHeaders(), outputFile: ccModule.OutputFile().Path(), }) } diff --git a/cc/ndk_library.go b/cc/ndk_library.go index da94d331c..c47cbf077 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -261,7 +261,6 @@ func addStubLibraryCompilerFlags(flags Flags) Flags { // We're knowingly doing some otherwise unsightly things with builtin // functions here. We're just generating stub libraries, so ignore it. "-Wno-incompatible-library-redeclaration", - "-Wno-incomplete-setjmp-declaration", "-Wno-builtin-requires-header", "-Wno-invalid-noreturn", "-Wall", diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 4e6cdd755..32676d6f5 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -90,6 +90,7 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext, p.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...) p.libraryDecorator.reexportFlags(deps.ReexportedFlags...) p.libraryDecorator.reexportDeps(deps.ReexportedDeps...) + p.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) builderFlags := flagsToBuilderFlags(flags) @@ -29,7 +29,7 @@ func init() { // Use RenderScript prebuilts for unbundled builds but not PDK builds return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin/llvm-rs-cc") } else { - return pctx.HostBinToolPath(ctx, "llvm-rs-cc").String() + return ctx.Config().HostToolPath(ctx, "llvm-rs-cc").String() } }) } diff --git a/cc/vndk.go b/cc/vndk.go index f25861af9..5aeb2e635 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -704,7 +704,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex // We glob headers from include directories inside source tree. So we first gather // all include directories inside our source tree. On the contrast, we manually // collect generated headers from dependencies as they can't globbed. - generatedHeaders = append(generatedHeaders, l.exportedDeps()...) + generatedHeaders = append(generatedHeaders, l.exportedGeneratedHeaders()...) for _, dir := range append(l.exportedDirs(), l.exportedSystemDirs()...) { exportedIncludes[dir.String()] = true } diff --git a/java/config/config.go b/java/config/config.go index 333de32d6..fee6341c3 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -124,7 +124,7 @@ func init() { if ctx.Config().UnbundledBuild() { return "prebuilts/build-tools/common/framework/" + turbine } else { - return pctx.HostJavaToolPath(ctx, turbine).String() + return ctx.Config().HostJavaToolPath(ctx, turbine).String() } }) @@ -170,7 +170,7 @@ func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) { if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() { return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin", tool) } else { - return pctx.HostBinToolPath(ctx, tool).String() + return ctx.Config().HostToolPath(ctx, tool).String() } }) } @@ -180,7 +180,7 @@ func hostJavaToolVariableWithSdkToolsPrebuilt(name, tool string) { if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() { return filepath.Join("prebuilts/sdk/tools/lib", tool+".jar") } else { - return pctx.HostJavaToolPath(ctx, tool+".jar").String() + return ctx.Config().HostJavaToolPath(ctx, tool+".jar").String() } }) } @@ -194,7 +194,7 @@ func hostJNIToolVariableWithSdkToolsPrebuilt(name, tool string) { } return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "lib64", tool+ext) } else { - return pctx.HostJNIToolPath(ctx, tool).String() + return ctx.Config().HostJNIToolPath(ctx, tool).String() } }) } @@ -204,7 +204,7 @@ func hostBinToolVariableWithBuildToolsPrebuilt(name, tool string) { if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() { return filepath.Join("prebuilts/build-tools", ctx.Config().PrebuiltOS(), "bin", tool) } else { - return pctx.HostBinToolPath(ctx, tool).String() + return ctx.Config().HostToolPath(ctx, tool).String() } }) } diff --git a/java/droiddoc.go b/java/droiddoc.go index 45a72e14d..76cdaeac6 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -2000,6 +2000,6 @@ func (mt *droidStubsSdkMemberType) BuildSnapshot(sdkModuleContext android.Module snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources") builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir) - pbm := builder.AddPrebuiltModule(sdkModuleContext.OtherModuleName(d), "prebuilt_stubs_sources") + pbm := builder.AddPrebuiltModule(member, "prebuilt_stubs_sources") pbm.AddProperty("srcs", []string{snapshotRelativeDir}) } diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index c0ef444fc..ad84cdea2 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -190,7 +190,7 @@ func stubFlagsRule(ctx android.SingletonContext) { rule.MissingDeps(missingDeps) rule.Command(). - Tool(pctx.HostBinToolPath(ctx, "hiddenapi")). + Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). Text("list"). FlagForEachInput("--boot-dex=", bootDexJars). FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":"). diff --git a/java/java.go b/java/java.go index f933d8dac..f58e5ba24 100644 --- a/java/java.go +++ b/java/java.go @@ -1760,7 +1760,7 @@ func (mt *librarySdkMemberType) buildSnapshot( } } - module := builder.AddPrebuiltModule(sdkModuleContext.OtherModuleName(j), "java_import") + module := builder.AddPrebuiltModule(member, "java_import") module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) } diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 315669afe..7620ec1ab 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -164,7 +164,7 @@ func TestSnapshotWithCcShared(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "android_common", + result.CheckSnapshot("mysdk", "android_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -263,7 +263,7 @@ func TestHostSnapshotWithCcShared(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "linux_glibc_common", + result.CheckSnapshot("mysdk", "linux_glibc_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 5b7224879..1aa918469 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -123,7 +123,7 @@ func TestSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "android_common", + result.CheckSnapshot("mysdk", "android_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -178,7 +178,7 @@ func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "linux_glibc_common", + result.CheckSnapshot("mysdk", "linux_glibc_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -232,7 +232,7 @@ func TestSnapshotWithJavaImplLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "android_common", + result.CheckSnapshot("mysdk", "android_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -287,7 +287,7 @@ func TestHostSnapshotWithJavaImplLibrary(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "linux_glibc_common", + result.CheckSnapshot("mysdk", "linux_glibc_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -379,7 +379,7 @@ func TestSnapshotWithDroidstubs(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "android_common", + result.CheckSnapshot("mysdk", "android_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -428,7 +428,7 @@ func TestHostSnapshotWithDroidstubs(t *testing.T) { } `) - result.CheckSnapshot("mysdk", "linux_glibc_common", + result.CheckSnapshot("mysdk", "linux_glibc_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index f4e944a80..d376e5906 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -79,3 +79,123 @@ func TestDepNotInRequiredSdks(t *testing.T) { } `) } + +// Ensure that prebuilt modules have the same effective visibility as the source +// modules. +func TestSnapshotVisibility(t *testing.T) { + packageBp := ` + package { + default_visibility: ["//other/foo"], + } + + sdk { + name: "mysdk", + visibility: [ + "//other/foo", + // This short form will be replaced with //package:__subpackages__ in the + // generated sdk_snapshot. + ":__subpackages__", + ], + java_header_libs: [ + "myjavalib", + "mypublicjavalib", + "mydefaultedjavalib", + ], + } + + java_library { + name: "myjavalib", + // Uses package default visibility + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + } + + java_library { + name: "mypublicjavalib", + visibility: ["//visibility:public"], + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + } + + java_defaults { + name: "myjavadefaults", + visibility: ["//other/bar"], + } + + java_library { + name: "mydefaultedjavalib", + defaults: ["myjavadefaults"], + srcs: ["Test.java"], + system_modules: "none", + sdk_version: "none", + } + ` + + result := testSdkWithFs(t, ``, + map[string][]byte{ + "package/Test.java": nil, + "package/Android.bp": []byte(packageBp), + }) + + result.CheckSnapshot("mysdk", "android_common", "package", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +java_import { + name: "mysdk_myjavalib@current", + sdk_member_name: "myjavalib", + visibility: ["//other/foo:__pkg__"], + jars: ["java/myjavalib.jar"], +} + +java_import { + name: "myjavalib", + prefer: false, + visibility: ["//other/foo:__pkg__"], + jars: ["java/myjavalib.jar"], +} + +java_import { + name: "mysdk_mypublicjavalib@current", + sdk_member_name: "mypublicjavalib", + visibility: ["//visibility:public"], + jars: ["java/mypublicjavalib.jar"], +} + +java_import { + name: "mypublicjavalib", + prefer: false, + visibility: ["//visibility:public"], + jars: ["java/mypublicjavalib.jar"], +} + +java_import { + name: "mysdk_mydefaultedjavalib@current", + sdk_member_name: "mydefaultedjavalib", + visibility: ["//other/bar:__pkg__"], + jars: ["java/mydefaultedjavalib.jar"], +} + +java_import { + name: "mydefaultedjavalib", + prefer: false, + visibility: ["//other/bar:__pkg__"], + jars: ["java/mydefaultedjavalib.jar"], +} + +sdk_snapshot { + name: "mysdk@current", + visibility: [ + "//other/foo:__pkg__", + "//package:__subpackages__", + ], + java_header_libs: [ + "mysdk_myjavalib@current", + "mysdk_mypublicjavalib@current", + "mysdk_mydefaultedjavalib@current", + ], +} +`)) +} diff --git a/sdk/testing.go b/sdk/testing.go index 604fa1690..bd929a4f8 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -33,7 +33,12 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr ctx := android.NewTestArchContext() // from android package + ctx.PreArchMutators(android.RegisterPackageRenamer) + ctx.PreArchMutators(android.RegisterVisibilityRuleChecker) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) + ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer) + ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer) + ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel() }) @@ -41,9 +46,11 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel() ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel() }) + ctx.RegisterModuleType("package", android.PackageFactory) // from java package ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) + ctx.RegisterModuleType("java_defaults", java.DefaultsFactory) ctx.RegisterModuleType("java_library", java.LibraryFactory) ctx.RegisterModuleType("java_import", java.ImportFactory) ctx.RegisterModuleType("droidstubs", java.DroidstubsFactory) @@ -115,7 +122,7 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr func testSdkWithFs(t *testing.T, bp string, fs map[string][]byte) *testSdkResult { t.Helper() ctx, config := testSdkContext(bp, fs) - _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) + _, errs := ctx.ParseBlueprintsFiles(".") android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) android.FailIfErrored(t, errs) @@ -268,7 +275,7 @@ func (r *testSdkResult) pathsRelativeToBuildDir(paths android.Paths) []string { // Takes a list of functions which check different facets of the snapshot build rules. // Allows each test to customize what is checked without duplicating lots of code // or proliferating check methods of different flavors. -func (r *testSdkResult) CheckSnapshot(name string, variant string, checkers ...snapshotBuildInfoChecker) { +func (r *testSdkResult) CheckSnapshot(name string, variant string, dir string, checkers ...snapshotBuildInfoChecker) { r.t.Helper() sdk := r.Module(name, variant).(*sdk) @@ -282,8 +289,11 @@ func (r *testSdkResult) CheckSnapshot(name string, variant string, checkers ...s // Make sure that the generated zip file is in the correct place. actual := snapshotBuildInfo.outputZip + if dir != "" { + dir = filepath.Clean(dir) + "/" + } r.AssertStringEquals("Snapshot zip file in wrong place", - fmt.Sprintf(".intermediates/%s/%s/%s-current.zip", name, variant, name), actual) + fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual) // Populate a mock filesystem with the files that would have been copied by // the rules. diff --git a/sdk/update.go b/sdk/update.go index 7731fbb3e..7fad5c745 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -211,6 +211,13 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version snapshotModule := bpFile.newModule("sdk_snapshot") snapshotModule.AddProperty("name", snapshotName) + + // Make sure that the snapshot has the same visibility as the sdk. + visibility := android.EffectiveVisibilityRules(ctx, s) + if len(visibility) != 0 { + snapshotModule.AddProperty("visibility", visibility) + } + addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule) for _, memberListProperty := range sdkMemberListProperties { names := memberListProperty.getter(&s.properties) @@ -368,13 +375,22 @@ func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) s.zipsToMerge = append(s.zipsToMerge, tmpZipPath) } -func (s *snapshotBuilder) AddPrebuiltModule(name string, moduleType string) android.BpModule { +func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType string) android.BpModule { + name := member.Name() if s.prebuiltModules[name] != nil { panic(fmt.Sprintf("Duplicate module detected, module %s has already been added", name)) } m := s.bpFile.newModule(moduleType) m.AddProperty("name", name) + + // Extract visibility information from a member variant. All variants have the same + // visibility so it doesn't matter which one is used. + visibility := android.EffectiveVisibilityRules(s.ctx, member.Variants()[0]) + if len(visibility) != 0 { + m.AddProperty("visibility", visibility) + } + addHostDeviceSupportedProperties(&s.sdk.ModuleBase, m) s.prebuiltModules[name] = m |