Dedup hidden API rule generation

Bug: 179354495
Test: verified that the monolithic out/soong/hiddenapi/... files are
      unchanged by this change
Change-Id: I54b677c97712a7573ff5eed017c1b2198b80bc51
This commit is contained in:
Paul Duffin 2021-05-14 09:58:48 +01:00
parent 34827d4c0e
commit 850e61f234
2 changed files with 30 additions and 39 deletions

View file

@ -260,23 +260,40 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa
stubFlagsCSV := hiddenAPISingletonPaths(ctx).stubFlags
flagsCSV := android.PathForModuleOut(ctx, "hiddenapi", "flags.csv")
h.flagsCSVPath = flagsCSV
buildRuleToGenerateAnnotationFlags(ctx, "hiddenapi flags", classesJars, stubFlagsCSV, flagsCSV)
metadataCSV := android.PathForModuleOut(ctx, "hiddenapi", "metadata.csv")
h.metadataCSVPath = metadataCSV
buildRuleToGenerateMetadata(ctx, "hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV)
indexCSV := android.PathForModuleOut(ctx, "hiddenapi", "index.csv")
h.indexCSVPath = indexCSV
buildRuleToGenerateIndex(ctx, "Merged Hidden API index", classesJars, indexCSV)
}
// buildRuleToGenerateAnnotationFlags builds a ninja rule to generate the annotation-flags.csv file
// from the classes jars and stub-flags.csv files.
func buildRuleToGenerateAnnotationFlags(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, outputPath android.WritablePath) {
ctx.Build(pctx, android.BuildParams{
Rule: hiddenAPIGenerateCSVRule,
Description: "hiddenapi flags",
Description: desc,
Inputs: classesJars,
Output: flagsCSV,
Output: outputPath,
Implicit: stubFlagsCSV,
Args: map[string]string{
"outFlag": "--write-flags-csv",
"stubAPIFlags": stubFlagsCSV.String(),
},
})
h.flagsCSVPath = flagsCSV
}
metadataCSV := android.PathForModuleOut(ctx, "hiddenapi", "metadata.csv")
// buildRuleToGenerateMetadata builds a ninja rule to generate the metadata.csv file from
// the classes jars and stub-flags.csv files.
func buildRuleToGenerateMetadata(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, metadataCSV android.WritablePath) {
ctx.Build(pctx, android.BuildParams{
Rule: hiddenAPIGenerateCSVRule,
Description: "hiddenapi metadata",
Description: desc,
Inputs: classesJars,
Output: metadataCSV,
Implicit: stubFlagsCSV,
@ -285,9 +302,11 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa
"stubAPIFlags": stubFlagsCSV.String(),
},
})
h.metadataCSVPath = metadataCSV
}
indexCSV := android.PathForModuleOut(ctx, "hiddenapi", "index.csv")
// buildRuleToGenerateMetadata builds a ninja rule to generate the index.csv file from the classes
// jars.
func buildRuleToGenerateIndex(ctx android.ModuleContext, desc string, classesJars android.Paths, indexCSV android.WritablePath) {
rule := android.NewRuleBuilder(pctx, ctx)
rule.Command().
BuiltTool("merge_csv").
@ -295,8 +314,7 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa
Flag("--key_field signature").
FlagWithOutput("--output=", indexCSV).
Inputs(classesJars)
rule.Build("merged-hiddenapi-index", "Merged Hidden API index")
h.indexCSVPath = indexCSV
rule.Build(desc, desc)
}
var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", blueprint.RuleParams{

View file

@ -517,42 +517,15 @@ func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext
// Generate the set of flags from the annotations in the source code.
annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv")
ctx.Build(pctx, android.BuildParams{
Rule: hiddenAPIGenerateCSVRule,
Description: "modular hiddenapi annotation flags",
Inputs: classesJars,
Output: annotationFlagsCSV,
Implicit: stubFlagsCSV,
Args: map[string]string{
"outFlag": "--write-flags-csv",
"stubAPIFlags": stubFlagsCSV.String(),
},
})
buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV)
// Generate the metadata from the annotations in the source code.
metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv")
ctx.Build(pctx, android.BuildParams{
Rule: hiddenAPIGenerateCSVRule,
Description: "modular hiddenapi metadata",
Inputs: classesJars,
Output: metadataCSV,
Implicit: stubFlagsCSV,
Args: map[string]string{
"outFlag": "--write-metadata-csv",
"stubAPIFlags": stubFlagsCSV.String(),
},
})
buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV)
// Generate the index file from the annotations in the source code.
indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv")
rule = android.NewRuleBuilder(pctx, ctx)
rule.Command().
BuiltTool("merge_csv").
Flag("--zip_input").
Flag("--key_field signature").
FlagWithOutput("--output=", indexCSV).
Inputs(classesJars)
rule.Build("modular-hiddenapi-index", "modular hiddenapi index")
buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV)
// Removed APIs need to be marked and in order to do that the flagFileInfo needs to specify files
// containing dex signatures of all the removed APIs. In the monolithic files that is done by