Merge "Stop generating unnecessary hidden API rules" am: b7c78731d4
am: 97961f4837
am: d12106540b
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1707574 Change-Id: I592af32aa225403d5ba1d1a4c89dda84d3aad0ba
This commit is contained in:
commit
63472fe5ba
|
@ -1223,9 +1223,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hidden API CSV generation and dex encoding
|
// Update hidden API paths.
|
||||||
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, j.implementationJarFile,
|
j.hiddenAPIUpdatePaths(ctx, dexOutputFile, j.implementationJarFile)
|
||||||
proptools.Bool(j.dexProperties.Uncompress_dex))
|
|
||||||
|
// Encode hidden API flags in dex file.
|
||||||
|
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex))
|
||||||
|
|
||||||
// merge dex jar with resources if necessary
|
// merge dex jar with resources if necessary
|
||||||
if j.resourceJar != nil {
|
if j.resourceJar != nil {
|
||||||
|
|
|
@ -56,35 +56,6 @@ type hiddenAPI struct {
|
||||||
// this file so using the encoded dex jar here would result in a cycle in the ninja rules.
|
// this file so using the encoded dex jar here would result in a cycle in the ninja rules.
|
||||||
bootDexJarPath android.Path
|
bootDexJarPath android.Path
|
||||||
|
|
||||||
// The path to the CSV file that contains mappings from Java signature to various flags derived
|
|
||||||
// from annotations in the source, e.g. whether it is public or the sdk version above which it
|
|
||||||
// can no longer be used.
|
|
||||||
//
|
|
||||||
// It is created by the Class2NonSdkList tool which processes the .class files in the class
|
|
||||||
// implementation jar looking for UnsupportedAppUsage and CovariantReturnType annotations. The
|
|
||||||
// tool also consumes the hiddenAPISingletonPathsStruct.stubFlags file in order to perform
|
|
||||||
// consistency checks on the information in the annotations and to filter out bridge methods
|
|
||||||
// that are already part of the public API.
|
|
||||||
flagsCSVPath android.Path
|
|
||||||
|
|
||||||
// The path to the CSV file that contains mappings from Java signature to the value of properties
|
|
||||||
// specified on UnsupportedAppUsage annotations in the source.
|
|
||||||
//
|
|
||||||
// Like the flagsCSVPath file this is also created by the Class2NonSdkList in the same way.
|
|
||||||
// Although the two files could potentially be created in a single invocation of the
|
|
||||||
// Class2NonSdkList at the moment they are created using their own invocation, with the behavior
|
|
||||||
// being determined by the property that is used.
|
|
||||||
metadataCSVPath android.Path
|
|
||||||
|
|
||||||
// The path to the CSV file that contains mappings from Java signature to source location
|
|
||||||
// information.
|
|
||||||
//
|
|
||||||
// It is created by the merge_csv tool which processes the class implementation jar, extracting
|
|
||||||
// all the files ending in .uau (which are CSV files) and merges them together. The .uau files are
|
|
||||||
// created by the unsupported app usage annotation processor during compilation of the class
|
|
||||||
// implementation jar.
|
|
||||||
indexCSVPath android.Path
|
|
||||||
|
|
||||||
// The paths to the classes jars that contain classes and class members annotated with
|
// The paths to the classes jars that contain classes and class members annotated with
|
||||||
// the UnsupportedAppUsage annotation that need to be extracted as part of the hidden API
|
// the UnsupportedAppUsage annotation that need to be extracted as part of the hidden API
|
||||||
// processing.
|
// processing.
|
||||||
|
@ -182,25 +153,14 @@ func isModuleInBootClassPath(ctx android.BaseModuleContext, module android.Modul
|
||||||
return active
|
return active
|
||||||
}
|
}
|
||||||
|
|
||||||
// hiddenAPIExtractAndEncode is called by any module that could contribute to the hiddenapi
|
// hiddenAPIEncodeDex is called by any module that needs to encode dex files.
|
||||||
// processing.
|
|
||||||
//
|
//
|
||||||
// It ignores any module that has not had initHiddenApi() called on it and which is not in the boot
|
// It ignores any module that has not had initHiddenApi() called on it and which is not in the boot
|
||||||
// jar list.
|
// jar list. In that case it simply returns the supplied dex jar path.
|
||||||
//
|
//
|
||||||
// Otherwise, it generates ninja rules to do the following:
|
// Otherwise, it creates a copy of the supplied dex file into which it has encoded the hiddenapi
|
||||||
// 1. Extract information needed for hiddenapi processing from the module and output it into CSV
|
// flags and returns this instead of the supplied dex jar.
|
||||||
// files.
|
func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android.OutputPath, uncompressDex bool) android.OutputPath {
|
||||||
// 2. Conditionally adds the supplied dex file to the list of files used to generate the
|
|
||||||
// hiddenAPISingletonPathsStruct.stubsFlag file.
|
|
||||||
// 3. Conditionally creates a copy of the supplied dex file into which it has encoded the hiddenapi
|
|
||||||
// flags and returns this instead of the supplied dex jar, otherwise simply returns the supplied
|
|
||||||
// dex jar.
|
|
||||||
func (h *hiddenAPI) hiddenAPIExtractAndEncode(ctx android.ModuleContext, dexJar android.OutputPath,
|
|
||||||
implementationJar android.Path, uncompressDex bool) android.OutputPath {
|
|
||||||
|
|
||||||
// Call before checking if this is active as it will update the hiddenAPI structure.
|
|
||||||
h.hiddenAPIExtractInformation(ctx, dexJar, implementationJar)
|
|
||||||
|
|
||||||
if !h.active {
|
if !h.active {
|
||||||
return dexJar
|
return dexJar
|
||||||
|
@ -217,12 +177,12 @@ func (h *hiddenAPI) hiddenAPIExtractAndEncode(ctx android.ModuleContext, dexJar
|
||||||
return dexJar
|
return dexJar
|
||||||
}
|
}
|
||||||
|
|
||||||
// hiddenAPIExtractInformation generates ninja rules to extract the information from the classes
|
// hiddenAPIUpdatePaths generates ninja rules to extract the information from the classes
|
||||||
// jar, and outputs it to the appropriate module specific CSV file.
|
// jar, and outputs it to the appropriate module specific CSV file.
|
||||||
//
|
//
|
||||||
// It also makes the dex jar available for use when generating the
|
// It also makes the dex jar available for use when generating the
|
||||||
// hiddenAPISingletonPathsStruct.stubFlags.
|
// hiddenAPISingletonPathsStruct.stubFlags.
|
||||||
func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJar, classesJar android.Path) {
|
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
|
// Save the classes jars even if this is not active as they may be used by modular hidden API
|
||||||
// processing.
|
// processing.
|
||||||
|
@ -236,35 +196,20 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa
|
||||||
// Save the unencoded dex jar so it can be used when generating the
|
// Save the unencoded dex jar so it can be used when generating the
|
||||||
// hiddenAPISingletonPathsStruct.stubFlags file.
|
// hiddenAPISingletonPathsStruct.stubFlags file.
|
||||||
h.bootDexJarPath = dexJar
|
h.bootDexJarPath = dexJar
|
||||||
|
|
||||||
if !h.active {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// More than one library with the same classes may need to be encoded but only one should be
|
|
||||||
// used as a source of information for hidden API processing otherwise it will result in
|
|
||||||
// duplicate entries in the files.
|
|
||||||
if !h.primary {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// 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.
|
||||||
|
//
|
||||||
|
// The annotation-flags.csv file contains mappings from Java signature to various flags derived from
|
||||||
|
// annotations in the source, e.g. whether it is public or the sdk version above which it can no
|
||||||
|
// longer be used.
|
||||||
|
//
|
||||||
|
// It is created by the Class2NonSdkList tool which processes the .class files in the class
|
||||||
|
// implementation jar looking for UnsupportedAppUsage and CovariantReturnType annotations. The
|
||||||
|
// tool also consumes the hiddenAPISingletonPathsStruct.stubFlags file in order to perform
|
||||||
|
// consistency checks on the information in the annotations and to filter out bridge methods
|
||||||
|
// that are already part of the public API.
|
||||||
func buildRuleToGenerateAnnotationFlags(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, outputPath android.WritablePath) {
|
func buildRuleToGenerateAnnotationFlags(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, outputPath android.WritablePath) {
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: hiddenAPIGenerateCSVRule,
|
Rule: hiddenAPIGenerateCSVRule,
|
||||||
|
@ -281,6 +226,14 @@ func buildRuleToGenerateAnnotationFlags(ctx android.ModuleContext, desc string,
|
||||||
|
|
||||||
// buildRuleToGenerateMetadata builds a ninja rule to generate the metadata.csv file from
|
// buildRuleToGenerateMetadata builds a ninja rule to generate the metadata.csv file from
|
||||||
// the classes jars and stub-flags.csv files.
|
// the classes jars and stub-flags.csv files.
|
||||||
|
//
|
||||||
|
// The metadata.csv file contains mappings from Java signature to the value of properties specified
|
||||||
|
// on UnsupportedAppUsage annotations in the source.
|
||||||
|
//
|
||||||
|
// Like the annotation-flags.csv file this is also created by the Class2NonSdkList in the same way.
|
||||||
|
// Although the two files could potentially be created in a single invocation of the
|
||||||
|
// Class2NonSdkList at the moment they are created using their own invocation, with the behavior
|
||||||
|
// being determined by the property that is used.
|
||||||
func buildRuleToGenerateMetadata(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, metadataCSV android.WritablePath) {
|
func buildRuleToGenerateMetadata(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, metadataCSV android.WritablePath) {
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: hiddenAPIGenerateCSVRule,
|
Rule: hiddenAPIGenerateCSVRule,
|
||||||
|
@ -295,8 +248,15 @@ func buildRuleToGenerateMetadata(ctx android.ModuleContext, desc string, classes
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildRuleToGenerateMetadata builds a ninja rule to generate the index.csv file from the classes
|
// buildRuleToGenerateIndex builds a ninja rule to generate the index.csv file from the classes
|
||||||
// jars.
|
// jars.
|
||||||
|
//
|
||||||
|
// The index.csv file contains mappings from Java signature to source location information.
|
||||||
|
//
|
||||||
|
// It is created by the merge_csv tool which processes the class implementation jar, extracting
|
||||||
|
// all the files ending in .uau (which are CSV files) and merges them together. The .uau files are
|
||||||
|
// created by the unsupported app usage annotation processor during compilation of the class
|
||||||
|
// implementation jar.
|
||||||
func buildRuleToGenerateIndex(ctx android.ModuleContext, desc string, classesJars android.Paths, indexCSV android.WritablePath) {
|
func buildRuleToGenerateIndex(ctx android.ModuleContext, desc string, classesJars android.Paths, indexCSV android.WritablePath) {
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
rule.Command().
|
rule.Command().
|
||||||
|
|
10
java/java.go
10
java/java.go
|
@ -1315,7 +1315,7 @@ 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.hiddenAPIExtractInformation(ctx, dexOutputPath, outputFile)
|
j.hiddenAPIUpdatePaths(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.
|
||||||
|
@ -1346,9 +1346,11 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hidden API CSV generation and dex encoding
|
// Update hidden API paths.
|
||||||
dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, outputFile,
|
j.hiddenAPIUpdatePaths(ctx, dexOutputFile, outputFile)
|
||||||
proptools.Bool(j.dexProperties.Uncompress_dex))
|
|
||||||
|
// Encode hidden API flags in dex file.
|
||||||
|
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile, proptools.Bool(j.dexProperties.Uncompress_dex))
|
||||||
|
|
||||||
j.dexJarFile = dexOutputFile
|
j.dexJarFile = dexOutputFile
|
||||||
}
|
}
|
||||||
|
|
|
@ -2128,7 +2128,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
|
||||||
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.configurationName)
|
module.initHiddenAPI(ctx, module.configurationName)
|
||||||
module.hiddenAPIExtractInformation(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.
|
||||||
|
|
Loading…
Reference in New Issue