summaryrefslogtreecommitdiff
path: root/java/hiddenapi_modular.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2021-05-14 18:52:11 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2021-05-14 18:52:11 +0000
commit21f62ef8677d1e657bb92e9b71117422d8f0c121 (patch)
tree0922204b7f59253bc09ef727cdc2de27fece666b /java/hiddenapi_modular.go
parent2bc8b3a646001a79409ecdd40584c762c4ed40b5 (diff)
parent537ea3d04cf9587809b832b11c9830c433dc8267 (diff)
Merge "Generate monolithic hidden API files direct from class jars"
Diffstat (limited to 'java/hiddenapi_modular.go')
-rw-r--r--java/hiddenapi_modular.go77
1 files changed, 51 insertions, 26 deletions
diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go
index 9989ab149..2dceb6535 100644
--- a/java/hiddenapi_modular.go
+++ b/java/hiddenapi_modular.go
@@ -422,12 +422,12 @@ func pathForValidation(ctx android.PathContext, path android.WritablePath) andro
// an entry for every single member in the dex implementation jars of the individual modules. Every
// signature in any of the other files MUST be included in this file.
//
-// moduleSpecificFlagsPaths are the paths to the flags files generated by each module using
-// information from the baseFlagsPath as well as from annotations within the source.
+// annotationFlags is the path to the annotation flags file generated from annotation information
+// in each module.
//
-// augmentationInfo is a struct containing paths to files that augment the information provided by
-// the moduleSpecificFlagsPaths.
-func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc string, outputPath android.WritablePath, baseFlagsPath android.Path, moduleSpecificFlagsPaths android.Paths, flagFileInfo *hiddenAPIFlagFileInfo) {
+// flagFileInfo is a struct containing paths to files that augment the information provided by
+// the annotationFlags.
+func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc string, outputPath android.WritablePath, baseFlagsPath android.Path, annotationFlags android.Path, flagFileInfo *hiddenAPIFlagFileInfo) {
// The file which is used to record that the flags file is valid.
var validFile android.WritablePath
@@ -457,7 +457,7 @@ func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc st
command := rule.Command().
BuiltTool("generate_hiddenapi_lists").
FlagWithInput("--csv ", baseFlagsPath).
- Inputs(moduleSpecificFlagsPaths).
+ Input(annotationFlags).
FlagWithOutput("--output ", tempPath)
// Add the options for the different categories of flag files.
@@ -495,31 +495,18 @@ func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc st
// * metadata.csv
// * index.csv
// * all-flags.csv
-func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext, contents []android.Module, stubJarsByKind map[android.SdkKind]android.Paths, flagFileInfo *hiddenAPIFlagFileInfo) {
-
+func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext, contents []hiddenAPIModule, stubJarsByKind map[android.SdkKind]android.Paths, flagFileInfo *hiddenAPIFlagFileInfo) {
hiddenApiSubDir := "modular-hiddenapi"
- bootDexJars := android.Paths{}
- classesJars := android.Paths{}
- for _, module := range contents {
- if hiddenAPI, ok := module.(hiddenAPIIntf); ok {
- classesJars = append(classesJars, hiddenAPI.classesJars()...)
- bootDexJar := hiddenAPI.bootDexJar()
- if bootDexJar == nil {
- ctx.ModuleErrorf("module %s does not provide a dex jar", module)
- } else {
- bootDexJars = append(bootDexJars, bootDexJar)
- }
- } else {
- ctx.ModuleErrorf("module %s does not implement hiddenAPIIntf", module)
- }
- }
-
// Generate the stub-flags.csv.
+ bootDexJars := extractBootDexJarsFromHiddenAPIModules(ctx, contents)
stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv")
rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, stubFlagsCSV, bootDexJars, stubJarsByKind)
rule.Build("modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags")
+ // Extract the classes jars from the contents.
+ classesJars := extractClassJarsFromHiddenAPIModules(ctx, contents)
+
// Generate the set of flags from the annotations in the source code.
annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv")
buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV)
@@ -528,7 +515,7 @@ func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext
metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv")
buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV)
- // Generate the index file from the annotations in the source code.
+ // Generate the index file from the CSV files in the classes jars.
indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv")
buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV)
@@ -542,7 +529,7 @@ func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext
// Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex
// files.
outputPath := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv")
- buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", outputPath, stubFlagsCSV, android.Paths{annotationFlagsCSV}, flagFileInfo)
+ buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", outputPath, stubFlagsCSV, annotationFlagsCSV, flagFileInfo)
// Store the paths in the info for use by other modules and sdk snapshot generation.
flagFileInfo.StubFlagsPaths = android.Paths{stubFlagsCSV}
@@ -551,3 +538,41 @@ func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext
flagFileInfo.IndexPaths = android.Paths{indexCSV}
flagFileInfo.AllFlagsPaths = android.Paths{outputPath}
}
+
+// gatherHiddenAPIModuleFromContents gathers the hiddenAPIModule from the supplied contents.
+func gatherHiddenAPIModuleFromContents(ctx android.ModuleContext, contents []android.Module) []hiddenAPIModule {
+ hiddenAPIModules := []hiddenAPIModule{}
+ for _, module := range contents {
+ if hiddenAPI, ok := module.(hiddenAPIModule); ok {
+ hiddenAPIModules = append(hiddenAPIModules, hiddenAPI)
+ } else if _, ok := module.(*DexImport); ok {
+ // Ignore this for the purposes of hidden API processing
+ } else {
+ ctx.ModuleErrorf("module %s does not implement hiddenAPIModule", module)
+ }
+ }
+ return hiddenAPIModules
+}
+
+// extractBootDexJarsFromHiddenAPIModules extracts the boot dex jars from the supplied modules.
+func extractBootDexJarsFromHiddenAPIModules(ctx android.ModuleContext, contents []hiddenAPIModule) android.Paths {
+ bootDexJars := android.Paths{}
+ for _, module := range contents {
+ bootDexJar := module.bootDexJar()
+ if bootDexJar == nil {
+ ctx.ModuleErrorf("module %s does not provide a dex jar", module)
+ } else {
+ bootDexJars = append(bootDexJars, bootDexJar)
+ }
+ }
+ return bootDexJars
+}
+
+// extractClassJarsFromHiddenAPIModules extracts the class jars from the supplied modules.
+func extractClassJarsFromHiddenAPIModules(ctx android.ModuleContext, contents []hiddenAPIModule) android.Paths {
+ classesJars := android.Paths{}
+ for _, module := range contents {
+ classesJars = append(classesJars, module.classesJars()...)
+ }
+ return classesJars
+}