diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/sdk_library.go | 155 |
1 files changed, 120 insertions, 35 deletions
diff --git a/java/sdk_library.go b/java/sdk_library.go index 63ebe6352..503ad5914 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -629,6 +629,16 @@ func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android return true } +// Module name of the runtime implementation library +func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { + return c.moduleBase.BaseModuleName() + ".impl" +} + +// Module name of the XML file for the lib +func (c *commonToSdkLibraryAndImport) xmlPermissionsModuleName() string { + return c.moduleBase.BaseModuleName() + sdkXmlFileSuffix +} + // Name of the java_library module that compiles the stubs source. func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName()) @@ -858,7 +868,7 @@ type SdkLibraryComponentDependency interface { var _ SdkLibraryComponentDependency = (*Library)(nil) var _ SdkLibraryComponentDependency = (*Import)(nil) var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) -var _ SdkLibraryComponentDependency = (*sdkLibraryImport)(nil) +var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) // Provides access to sdk_version related header and implentation jars. type SdkLibraryDependency interface { @@ -944,16 +954,24 @@ func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) return generatedScopes } -var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"} +type sdkLibraryComponentTag struct { + blueprint.BaseDependencyTag + name string +} + +// Mark this tag so dependencies that use it are excluded from visibility enforcement. +func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} + +var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { - if dt, ok := depTag.(dependencyTag); ok { + if dt, ok := depTag.(sdkLibraryComponentTag); ok { return dt == xmlPermissionsFileTag } return false } -var implLibraryTag = dependencyTag{name: "impl-library"} +var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { for _, apiScope := range module.getGeneratedApiScopes(ctx) { @@ -978,7 +996,7 @@ func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { if module.sharedLibrary() { // Add dependency to the rule for generating the xml permissions file - ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName()) + ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) } // Only add the deps for the library if it is actually going to be built. @@ -1025,20 +1043,10 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { } entriesList := module.Library.AndroidMkEntries() entries := &entriesList[0] - entries.Required = append(entries.Required, module.xmlFileName()) + entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) return entriesList } -// Module name of the runtime implementation library -func (module *SdkLibrary) implLibraryModuleName() string { - return module.BaseModuleName() + ".impl" -} - -// Module name of the XML file for the lib -func (module *SdkLibrary) xmlFileName() string { - return module.BaseModuleName() + sdkXmlFileSuffix -} - // The dist path of the stub artifacts func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { if module.ModuleBase.Owner() != "" { @@ -1329,7 +1337,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { Lib_name *string Apex_available []string }{ - Name: proptools.StringPtr(module.xmlFileName()), + Name: proptools.StringPtr(module.xmlPermissionsModuleName()), Lib_name: proptools.StringPtr(module.BaseModuleName()), Apex_available: module.ApexProperties.Apex_available, } @@ -1377,7 +1385,7 @@ func getApexNameForModule(module android.Module) string { // // If either this or the other module are on the platform then this will return // false. -func (module *SdkLibrary) withinSameApexAs(other android.Module) bool { +func withinSameApexAs(module android.ApexModule, other android.Module) bool { name := module.ApexName() return name != "" && getApexNameForModule(other) == name } @@ -1398,7 +1406,7 @@ func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkS // Only allow access to the implementation library in the following condition: // * No sdk_version specified on the referencing module. // * The referencing module is in the same apex as this. - if sdkVersion.kind == sdkPrivate || module.withinSameApexAs(ctx.Module()) { + if sdkVersion.kind == sdkPrivate || withinSameApexAs(module, ctx.Module()) { if headerJars { return module.HeaderJars() } else { @@ -1702,7 +1710,7 @@ type sdkLibraryImportProperties struct { Libs []string } -type sdkLibraryImport struct { +type SdkLibraryImport struct { android.ModuleBase android.DefaultableModuleBase prebuilt android.Prebuilt @@ -1715,9 +1723,17 @@ type sdkLibraryImport struct { scopeProperties map[*apiScope]*sdkLibraryScopeProperties commonToSdkLibraryAndImport + + // The reference to the implementation library created by the source module. + // Is nil if the source module does not exist. + implLibraryModule *Library + + // The reference to the xml permissions module created by the source module. + // Is nil if the source module does not exist. + xmlPermissionsFileModule *sdkLibraryXml } -var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) +var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) // The type of a structure that contains a field of type sdkLibraryScopeProperties // for each apiscope in allApiScopes, e.g. something like: @@ -1759,7 +1775,7 @@ func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProp // java_sdk_library_import imports a prebuilt java_sdk_library. func sdkLibraryImportFactory() android.Module { - module := &sdkLibraryImport{} + module := &SdkLibraryImport{} allScopeProperties, scopeToProperties := createPropertiesInstance() module.scopeProperties = scopeToProperties @@ -1781,15 +1797,15 @@ func sdkLibraryImportFactory() android.Module { return module } -func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt { +func (module *SdkLibraryImport) Prebuilt() *android.Prebuilt { return &module.prebuilt } -func (module *sdkLibraryImport) Name() string { +func (module *SdkLibraryImport) Name() string { return module.prebuilt.Name(module.ModuleBase.Name()) } -func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { +func (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { // If the build is configured to use prebuilts then force this to be preferred. if mctx.Config().UnbundledBuildUsePrebuiltSdks() { @@ -1814,7 +1830,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHo *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } -func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { +func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { // Creates a java import for the jar with ".stubs" suffix props := struct { Name *string @@ -1836,7 +1852,7 @@ func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.Defaultabl mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary()) } -func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { +func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { props := struct { Name *string Srcs []string @@ -1850,7 +1866,7 @@ func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.Defaulta props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) } -func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { +func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { for apiScope, scopeProperties := range module.scopeProperties { if len(scopeProperties.Jars) == 0 { continue @@ -1864,13 +1880,35 @@ func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope)) } } + + implName := module.implLibraryModuleName() + if ctx.OtherModuleExists(implName) { + ctx.AddVariationDependencies(nil, implLibraryTag, implName) + + xmlPermissionsModuleName := module.xmlPermissionsModuleName() + if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) { + // Add dependency to the rule for generating the xml permissions file + ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName) + } + } } -func (module *sdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { +func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { + depTag := mctx.OtherModuleDependencyTag(dep) + if depTag == xmlPermissionsFileTag { + return true + } + + // None of the other dependencies of the java_sdk_library_import are in the same apex + // as the one that references this module. + return false +} + +func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { return module.commonOutputFiles(tag) } -func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Record the paths to the prebuilt stubs library and stubs source. ctx.VisitDirectDeps(func(to android.Module) { tag := ctx.OtherModuleDependencyTag(to) @@ -1883,6 +1921,18 @@ func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo // Extract information from the dependency. The exact information extracted // is determined by the nature of the dependency which is determined by the tag. scopeTag.extractDepInfo(ctx, to, scopePaths) + } else if tag == implLibraryTag { + if implLibrary, ok := to.(*Library); ok { + module.implLibraryModule = implLibrary + } else { + ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) + } + } else if tag == xmlPermissionsFileTag { + if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { + module.xmlPermissionsFileModule = xmlPermissionsFileModule + } else { + ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) + } } }) @@ -1898,20 +1948,55 @@ func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo } } -func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { +func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { + + // For consistency with SdkLibrary make the implementation jar available to libraries that + // are within the same APEX. + implLibraryModule := module.implLibraryModule + if implLibraryModule != nil && withinSameApexAs(module, ctx.Module()) { + if headerJars { + return implLibraryModule.HeaderJars() + } else { + return implLibraryModule.ImplementationJars() + } + } + return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) } // to satisfy SdkLibraryDependency interface -func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { +func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { // This module is just a wrapper for the prebuilt stubs. - return module.sdkJars(ctx, sdkVersion) + return module.sdkJars(ctx, sdkVersion, true) } // to satisfy SdkLibraryDependency interface -func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { +func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { // This module is just a wrapper for the stubs. - return module.sdkJars(ctx, sdkVersion) + return module.sdkJars(ctx, sdkVersion, false) +} + +// to satisfy apex.javaDependency interface +func (module *SdkLibraryImport) DexJarBuildPath() android.Path { + if module.implLibraryModule == nil { + return nil + } else { + return module.implLibraryModule.DexJarBuildPath() + } +} + +// to satisfy apex.javaDependency interface +func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { + if module.implLibraryModule == nil { + return nil + } else { + return module.implLibraryModule.JacocoReportClassesFile() + } +} + +// to satisfy apex.javaDependency interface +func (module *SdkLibraryImport) Stem() string { + return module.BaseModuleName() } // |