Move monolithic stub flags generation to platform_bootclasspath
As part of that this change: * Moves code that will be common to platform_bootclasspath and bootclasspath_fragment from hiddenapi_singleton.go into hiddenapi_modular.go. * Fixes the tests in hiddenapi_singleton_test.go but intentionally does not rename them or move them into a more appropriate place so as to make it easier to see the differences. A TODO has been added and these will be cleaned up in a follow up change. Bug: 179354495 Test: verified that the monolithic out/soong/hiddenapi/... files are unchanged by this change Change-Id: I680e4dab2e6bdf4a655fa9f255c195175904667e
This commit is contained in:
@@ -127,8 +127,6 @@ func (h *hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext)
|
||||
return
|
||||
}
|
||||
|
||||
stubFlagsRule(ctx)
|
||||
|
||||
// If there is a prebuilt hiddenapi dir, generate rules to use the
|
||||
// files within. Generally, we build the hiddenapi files from source
|
||||
// during the build, ensuring consistency. It's possible, in a split
|
||||
@@ -160,137 +158,6 @@ func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) {
|
||||
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String())
|
||||
}
|
||||
|
||||
// hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs
|
||||
// needed to produce the hidden API monolithic stub flags file.
|
||||
func hiddenAPIComputeMonolithicStubLibModules(ctx android.BuilderContext) map[android.SdkKind][]string {
|
||||
var publicStubModules []string
|
||||
var systemStubModules []string
|
||||
var testStubModules []string
|
||||
var corePlatformStubModules []string
|
||||
|
||||
if ctx.Config().AlwaysUsePrebuiltSdks() {
|
||||
// Build configuration mandates using prebuilt stub modules
|
||||
publicStubModules = append(publicStubModules, "sdk_public_current_android")
|
||||
systemStubModules = append(systemStubModules, "sdk_system_current_android")
|
||||
testStubModules = append(testStubModules, "sdk_test_current_android")
|
||||
} else {
|
||||
// Use stub modules built from source
|
||||
publicStubModules = append(publicStubModules, "android_stubs_current")
|
||||
systemStubModules = append(systemStubModules, "android_system_stubs_current")
|
||||
testStubModules = append(testStubModules, "android_test_stubs_current")
|
||||
}
|
||||
// We do not have prebuilts of the core platform api yet
|
||||
corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs")
|
||||
|
||||
// Allow products to define their own stubs for custom product jars that apps can use.
|
||||
publicStubModules = append(publicStubModules, ctx.Config().ProductHiddenAPIStubs()...)
|
||||
systemStubModules = append(systemStubModules, ctx.Config().ProductHiddenAPIStubsSystem()...)
|
||||
testStubModules = append(testStubModules, ctx.Config().ProductHiddenAPIStubsTest()...)
|
||||
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") {
|
||||
publicStubModules = append(publicStubModules, "jacoco-stubs")
|
||||
}
|
||||
|
||||
m := map[android.SdkKind][]string{}
|
||||
m[android.SdkPublic] = publicStubModules
|
||||
m[android.SdkSystem] = systemStubModules
|
||||
m[android.SdkTest] = testStubModules
|
||||
m[android.SdkCorePlatform] = corePlatformStubModules
|
||||
return m
|
||||
}
|
||||
|
||||
// stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image
|
||||
// modules.
|
||||
func stubFlagsRule(ctx android.SingletonContext) {
|
||||
|
||||
sdkKindToModules := hiddenAPIComputeMonolithicStubLibModules(ctx)
|
||||
|
||||
// Create a set of path slices into which the DexJarBuildPath from the stub modules can be stored.
|
||||
sdkKindToPathList := map[android.SdkKind]android.Paths{}
|
||||
for sdkKind, modules := range sdkKindToModules {
|
||||
sdkKindToPathList[sdkKind] = make(android.Paths, len(modules))
|
||||
}
|
||||
|
||||
var bootDexJars android.Paths
|
||||
ctx.VisitAllModules(func(module android.Module) {
|
||||
// Collect dex jar paths for the modules listed above.
|
||||
if j, ok := module.(UsesLibraryDependency); ok {
|
||||
name := ctx.ModuleName(module)
|
||||
for _, sdkKind := range hiddenAPIRelevantSdkKinds {
|
||||
if i := android.IndexList(name, sdkKindToModules[sdkKind]); i != -1 {
|
||||
sdkKindToPathList[sdkKind][i] = j.DexJarBuildPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect dex jar paths for modules that had hiddenapi encode called on them.
|
||||
if h, ok := module.(hiddenAPIIntf); ok {
|
||||
if jar := h.bootDexJar(); jar != nil {
|
||||
bootDexJars = append(bootDexJars, jar)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var missingDeps []string
|
||||
// Ensure all modules were converted to paths
|
||||
for _, sdkKind := range hiddenAPIRelevantSdkKinds {
|
||||
pathList := sdkKindToPathList[sdkKind]
|
||||
for i := range pathList {
|
||||
if pathList[i] == nil {
|
||||
moduleName := sdkKindToModules[sdkKind][i]
|
||||
pathList[i] = android.PathForOutput(ctx, "missing/module", moduleName)
|
||||
if ctx.Config().AllowMissingDependencies() {
|
||||
missingDeps = append(missingDeps, moduleName)
|
||||
} else {
|
||||
ctx.Errorf("failed to find dex jar path for module %q", moduleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outputPath := hiddenAPISingletonPaths(ctx).stubFlags
|
||||
rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToPathList)
|
||||
rule.MissingDeps(missingDeps)
|
||||
rule.Build("hiddenAPIStubFlagsFile", "hiddenapi stub flags")
|
||||
}
|
||||
|
||||
var sdkKindToHiddenapiListOption = map[android.SdkKind]string{
|
||||
android.SdkPublic: "public-stub-classpath",
|
||||
android.SdkSystem: "system-stub-classpath",
|
||||
android.SdkTest: "test-stub-classpath",
|
||||
android.SdkCorePlatform: "core-platform-stub-classpath",
|
||||
}
|
||||
|
||||
// ruleToGenerateHiddenAPIStubFlagsFile creates a rule to create a hidden API stub flags file.
|
||||
//
|
||||
// The rule is initialized but not built so that the caller can modify it and select an appropriate
|
||||
// name.
|
||||
func ruleToGenerateHiddenAPIStubFlagsFile(ctx android.SingletonContext, outputPath android.OutputPath, bootDexJars android.Paths, sdkKindToPathList map[android.SdkKind]android.Paths) *android.RuleBuilder {
|
||||
// Singleton rule which applies hiddenapi on all boot class path dex files.
|
||||
rule := android.NewRuleBuilder(pctx, ctx)
|
||||
|
||||
tempPath := tempPathForRestat(ctx, outputPath)
|
||||
|
||||
command := rule.Command().
|
||||
Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")).
|
||||
Text("list").
|
||||
FlagForEachInput("--boot-dex=", bootDexJars)
|
||||
|
||||
// Iterate over the sdk
|
||||
for _, sdkKind := range hiddenAPIRelevantSdkKinds {
|
||||
paths := sdkKindToPathList[sdkKind]
|
||||
if len(paths) > 0 {
|
||||
option := sdkKindToHiddenapiListOption[sdkKind]
|
||||
command.FlagWithInputList("--"+option+"=", paths, ":")
|
||||
}
|
||||
}
|
||||
|
||||
// Add the output path.
|
||||
command.FlagWithOutput("--out-api-flags=", tempPath)
|
||||
|
||||
commitChangeForRestat(rule, tempPath, outputPath)
|
||||
return rule
|
||||
}
|
||||
|
||||
// Checks to see whether the supplied module variant is in the list of boot jars.
|
||||
//
|
||||
// This is similar to logic in getBootImageJar() so any changes needed here are likely to be needed
|
||||
|
Reference in New Issue
Block a user