Merge initHiddenAPI and hiddenAPIUpdatePaths

These two methods did very similar jobs and merging them together
simplifies the behavior.

Bug: 179354495
Test: m droid
Change-Id: Ibe1a23d54105e6a0e5693079cd8743679301fc85
This commit is contained in:
Paul Duffin
2021-05-14 14:18:47 +01:00
parent 66cdbf07ef
commit 74d18d1d6f
4 changed files with 26 additions and 36 deletions

View File

@@ -1217,8 +1217,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
return return
} }
// Update hidden API paths. // Initialize the hiddenapi structure.
j.hiddenAPIUpdatePaths(ctx, dexOutputFile, j.implementationJarFile) j.initHiddenAPI(ctx, dexOutputFile, j.implementationJarFile)
// Encode hidden API flags in dex file. // Encode hidden API flags in dex file.
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex)) dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex))

View File

@@ -79,12 +79,29 @@ type hiddenAPIIntf interface {
var _ hiddenAPIIntf = (*hiddenAPI)(nil) var _ hiddenAPIIntf = (*hiddenAPI)(nil)
// Initialize the hiddenapi structure // Initialize the hiddenapi structure
func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext) { func (h *hiddenAPI) initHiddenAPI(ctx android.ModuleContext, dexJar, classesJar android.Path) {
// Save the classes jars even if this is not active as they may be used by modular hidden API
// processing.
classesJars := android.Paths{classesJar}
ctx.VisitDirectDepsWithTag(hiddenApiAnnotationsTag, func(dep android.Module) {
javaInfo := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
classesJars = append(classesJars, javaInfo.ImplementationJars...)
})
h.classesJarPaths = classesJars
// Save the unencoded dex jar so it can be used when generating the
// hiddenAPISingletonPathsStruct.stubFlags file.
h.bootDexJarPath = dexJar
// If hiddenapi processing is disabled treat this as inactive. // If hiddenapi processing is disabled treat this as inactive.
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
return return
} }
// The context module must implement hiddenAPIModule.
module := ctx.Module().(hiddenAPIModule)
// If the frameworks/base directories does not exist and no prebuilt hidden API flag files have // If the frameworks/base directories does not exist and no prebuilt hidden API flag files have
// been configured then it is not possible to do hidden API encoding. // been configured then it is not possible to do hidden API encoding.
if !ctx.Config().FrameworksBaseDirExists(ctx) && ctx.Config().PrebuiltHiddenApiDir(ctx) == "" { if !ctx.Config().FrameworksBaseDirExists(ctx) && ctx.Config().PrebuiltHiddenApiDir(ctx) == "" {
@@ -95,7 +112,6 @@ func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext) {
// on the boot jars list because the runtime only enforces access to the hidden API for the // on the boot jars list because the runtime only enforces access to the hidden API for the
// bootclassloader. If information is gathered for modules not on the list then that will cause // bootclassloader. If information is gathered for modules not on the list then that will cause
// failures in the CtsHiddenApiBlocklist... tests. // failures in the CtsHiddenApiBlocklist... tests.
module := ctx.Module()
h.active = isModuleInBootClassPath(ctx, module) h.active = isModuleInBootClassPath(ctx, module)
if !h.active { if !h.active {
// The rest of the properties will be ignored if active is false. // The rest of the properties will be ignored if active is false.
@@ -170,27 +186,6 @@ func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android
return dexJar return dexJar
} }
// hiddenAPIUpdatePaths generates ninja rules to extract the information from the classes
// jar, and outputs it to the appropriate module specific CSV file.
//
// It also makes the dex jar available for use when generating the
// hiddenAPISingletonPathsStruct.stubFlags.
func (h *hiddenAPI) hiddenAPIUpdatePaths(ctx android.ModuleContext, dexJar, classesJar android.Path) {
// Save the classes jars even if this is not active as they may be used by modular hidden API
// processing.
classesJars := android.Paths{classesJar}
ctx.VisitDirectDepsWithTag(hiddenApiAnnotationsTag, func(dep android.Module) {
javaInfo := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
classesJars = append(classesJars, javaInfo.ImplementationJars...)
})
h.classesJarPaths = classesJars
// Save the unencoded dex jar so it can be used when generating the
// hiddenAPISingletonPathsStruct.stubFlags file.
h.bootDexJarPath = dexJar
}
// buildRuleToGenerateAnnotationFlags builds a ninja rule to generate the annotation-flags.csv file // buildRuleToGenerateAnnotationFlags builds a ninja rule to generate the annotation-flags.csv file
// from the classes jars and stub-flags.csv files. // from the classes jars and stub-flags.csv files.
// //

View File

@@ -481,9 +481,6 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo
} }
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Initialize the hiddenapi structure.
j.initHiddenAPI(ctx)
j.sdkVersion = j.SdkVersion(ctx) j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx)
@@ -1239,9 +1236,6 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.sdkVersion = j.SdkVersion(ctx) j.sdkVersion = j.SdkVersion(ctx)
j.minSdkVersion = j.MinSdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx)
// Initialize the hiddenapi structure.
j.initHiddenAPI(ctx)
if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() { if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
j.hideApexVariantFromMake = true j.hideApexVariantFromMake = true
} }
@@ -1313,7 +1307,9 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
if dexOutputPath := di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar"); dexOutputPath != nil { if dexOutputPath := di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
j.dexJarFile = dexOutputPath j.dexJarFile = dexOutputPath
j.hiddenAPIUpdatePaths(ctx, dexOutputPath, outputFile)
// Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexOutputPath, outputFile)
} else { } else {
// This should never happen as a variant for a prebuilt_apex is only created if the // This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file. // prebuilt_apex has been configured to export the java library dex file.
@@ -1344,8 +1340,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
return return
} }
// Update hidden API paths. // Initialize the hiddenapi structure.
j.hiddenAPIUpdatePaths(ctx, dexOutputFile, outputFile) j.initHiddenAPI(ctx, dexOutputFile, outputFile)
// Encode hidden API flags in dex file. // Encode hidden API flags in dex file.
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex)) dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex))

View File

@@ -2121,8 +2121,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
if dexOutputPath := di.PrebuiltExportPath(module.BaseModuleName(), ".dexjar"); dexOutputPath != nil { if dexOutputPath := di.PrebuiltExportPath(module.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
module.dexJarFile = dexOutputPath module.dexJarFile = dexOutputPath
module.initHiddenAPI(ctx) module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0])
module.hiddenAPIUpdatePaths(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0])
} else { } else {
// This should never happen as a variant for a prebuilt_apex is only created if the // This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file. // prebuilt_apex has been configured to export the java library dex file.