Refactor hiddenAPIEncodeDex for use by bootclasspath_fragment am: 0916595b1c

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1710511

Change-Id: Iaf4d6c9cb9e24f060c663c62840a0d504149400b
This commit is contained in:
Paul Duffin
2021-05-23 15:30:58 +00:00
committed by Automerger Merge Worker

View File

@@ -145,15 +145,13 @@ func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android
} }
uncompressDex := *h.uncompressDexState uncompressDex := *h.uncompressDexState
hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", dexJar.Base()).OutputPath
// Create a copy of the dex jar which has been encoded with hiddenapi flags. // Create a copy of the dex jar which has been encoded with hiddenapi flags.
hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexJar, uncompressDex) flagsCSV := hiddenAPISingletonPaths(ctx).flags
outputDir := android.PathForModuleOut(ctx, "hiddenapi").OutputPath
encodedDex := hiddenAPIEncodeDex(ctx, dexJar, flagsCSV, uncompressDex, outputDir)
// Use the encoded dex jar from here onwards. // Use the encoded dex jar from here onwards.
dexJar = hiddenAPIJar return encodedDex
return 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
@@ -243,35 +241,37 @@ var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", bluepr
}, },
}, "flagsCsv", "hiddenapiFlags", "tmpDir", "soongZipFlags") }, "flagsCsv", "hiddenapiFlags", "tmpDir", "soongZipFlags")
func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, dexInput android.Path, // hiddenAPIEncodeDex generates the build rule that will encode the supplied dex jar and place the
uncompressDex bool) { // encoded dex jar in a file of the same name in the output directory.
//
// The encode dex rule requires unzipping, encoding and rezipping the classes.dex files along with
// all the resources from the input jar. It also ensures that if it was uncompressed in the input
// it stays uncompressed in the output.
func hiddenAPIEncodeDex(ctx android.ModuleContext, dexInput, flagsCSV android.Path, uncompressDex bool, outputDir android.OutputPath) android.OutputPath {
flagsCSV := hiddenAPISingletonPaths(ctx).flags // The output file has the same name as the input file and is in the output directory.
output := outputDir.Join(ctx, dexInput.Base())
// The encode dex rule requires unzipping and rezipping the classes.dex files, ensure that if it was uncompressed // Create a jar specific temporary directory in which to do the work just in case this is called
// in the input it stays uncompressed in the output. // with the same output directory for multiple modules.
tmpDir := outputDir.Join(ctx, dexInput.Base()+"-tmp")
// If the input is uncompressed then generate the output of the encode rule to an intermediate
// file as the final output will need further processing after encoding.
soongZipFlags := "" soongZipFlags := ""
hiddenapiFlags := "" encodeRuleOutput := output
tmpOutput := output
tmpDir := android.PathForModuleOut(ctx, "hiddenapi", "dex")
if uncompressDex { if uncompressDex {
soongZipFlags = "-L 0" soongZipFlags = "-L 0"
tmpOutput = android.PathForModuleOut(ctx, "hiddenapi", "unaligned", "unaligned.jar") encodeRuleOutput = outputDir.Join(ctx, "unaligned", dexInput.Base())
tmpDir = android.PathForModuleOut(ctx, "hiddenapi", "unaligned")
} }
enforceHiddenApiFlagsToAllMembers := true
// b/149353192: when a module is instrumented, jacoco adds synthetic members // b/149353192: when a module is instrumented, jacoco adds synthetic members
// $jacocoData and $jacocoInit. Since they don't exist when building the hidden API flags, // $jacocoData and $jacocoInit. Since they don't exist when building the hidden API flags,
// don't complain when we don't find hidden API flags for the synthetic members. // don't complain when we don't find hidden API flags for the synthetic members.
hiddenapiFlags := ""
if j, ok := ctx.Module().(interface { if j, ok := ctx.Module().(interface {
shouldInstrument(android.BaseModuleContext) bool shouldInstrument(android.BaseModuleContext) bool
}); ok && j.shouldInstrument(ctx) { }); ok && j.shouldInstrument(ctx) {
enforceHiddenApiFlagsToAllMembers = false
}
if !enforceHiddenApiFlagsToAllMembers {
hiddenapiFlags = "--no-force-assign-all" hiddenapiFlags = "--no-force-assign-all"
} }
@@ -279,7 +279,7 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath,
Rule: hiddenAPIEncodeDexRule, Rule: hiddenAPIEncodeDexRule,
Description: "hiddenapi encode dex", Description: "hiddenapi encode dex",
Input: dexInput, Input: dexInput,
Output: tmpOutput, Output: encodeRuleOutput,
Implicit: flagsCSV, Implicit: flagsCSV,
Args: map[string]string{ Args: map[string]string{
"flagsCsv": flagsCSV.String(), "flagsCsv": flagsCSV.String(),
@@ -290,8 +290,10 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath,
}) })
if uncompressDex { if uncompressDex {
TransformZipAlign(ctx, output, tmpOutput) TransformZipAlign(ctx, output, encodeRuleOutput)
} }
return output
} }
type hiddenApiAnnotationsDependencyTag struct { type hiddenApiAnnotationsDependencyTag struct {