From 74d18d1d6ff1ad8ec47c34182d1a22945e05e9d5 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 14 May 2021 14:18:47 +0100 Subject: [PATCH] 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 --- java/base.go | 4 ++-- java/hiddenapi.go | 41 ++++++++++++++++++----------------------- java/java.go | 14 +++++--------- java/sdk_library.go | 3 +-- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/java/base.go b/java/base.go index 5a4898b46..4b56a300b 100644 --- a/java/base.go +++ b/java/base.go @@ -1217,8 +1217,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { return } - // Update hidden API paths. - j.hiddenAPIUpdatePaths(ctx, dexOutputFile, j.implementationJarFile) + // Initialize the hiddenapi structure. + j.initHiddenAPI(ctx, dexOutputFile, j.implementationJarFile) // Encode hidden API flags in dex file. dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex)) diff --git a/java/hiddenapi.go b/java/hiddenapi.go index fe7bd65dc..37f1b995c 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -79,12 +79,29 @@ type hiddenAPIIntf interface { var _ hiddenAPIIntf = (*hiddenAPI)(nil) // 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 ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { 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 // been configured then it is not possible to do hidden API encoding. 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 // bootclassloader. If information is gathered for modules not on the list then that will cause // failures in the CtsHiddenApiBlocklist... tests. - module := ctx.Module() h.active = isModuleInBootClassPath(ctx, module) if !h.active { // 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 } -// 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 // from the classes jars and stub-flags.csv files. // diff --git a/java/java.go b/java/java.go index 515d20429..d4a52086e 100644 --- a/java/java.go +++ b/java/java.go @@ -481,9 +481,6 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo } func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { - // Initialize the hiddenapi structure. - j.initHiddenAPI(ctx) - j.sdkVersion = j.SdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx) @@ -1239,9 +1236,6 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.sdkVersion = j.SdkVersion(ctx) j.minSdkVersion = j.MinSdkVersion(ctx) - // Initialize the hiddenapi structure. - j.initHiddenAPI(ctx) - if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() { j.hideApexVariantFromMake = true } @@ -1313,7 +1307,9 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) if dexOutputPath := di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar"); dexOutputPath != nil { j.dexJarFile = dexOutputPath - j.hiddenAPIUpdatePaths(ctx, dexOutputPath, outputFile) + + // Initialize the hiddenapi structure. + j.initHiddenAPI(ctx, dexOutputPath, outputFile) } else { // 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. @@ -1344,8 +1340,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { return } - // Update hidden API paths. - j.hiddenAPIUpdatePaths(ctx, dexOutputFile, outputFile) + // Initialize the hiddenapi structure. + j.initHiddenAPI(ctx, dexOutputFile, outputFile) // Encode hidden API flags in dex file. dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex)) diff --git a/java/sdk_library.go b/java/sdk_library.go index 1d14d8686..1866a538e 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2121,8 +2121,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) if dexOutputPath := di.PrebuiltExportPath(module.BaseModuleName(), ".dexjar"); dexOutputPath != nil { module.dexJarFile = dexOutputPath - module.initHiddenAPI(ctx) - module.hiddenAPIUpdatePaths(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0]) + module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0]) } else { // 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.