Merge "Extract common stub flags code" am: d631512659
am: d8d72e85f6
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1683865 Change-Id: I2aa0acb55e98e1399516f582525419d93fbadc14
This commit is contained in:
@@ -21,6 +21,15 @@ import (
|
|||||||
|
|
||||||
// Contains support for processing hiddenAPI in a modular fashion.
|
// Contains support for processing hiddenAPI in a modular fashion.
|
||||||
|
|
||||||
|
// hiddenAPIRelevantSdkKinds lists all the android.SdkKind instances that are needed by the hidden
|
||||||
|
// API processing.
|
||||||
|
var hiddenAPIRelevantSdkKinds = []android.SdkKind{
|
||||||
|
android.SdkPublic,
|
||||||
|
android.SdkSystem,
|
||||||
|
android.SdkTest,
|
||||||
|
android.SdkCorePlatform,
|
||||||
|
}
|
||||||
|
|
||||||
// HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the
|
// HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the
|
||||||
// information obtained from annotations within the source code in order to create the complete set
|
// information obtained from annotations within the source code in order to create the complete set
|
||||||
// of flags that should be applied to the dex implementation jars on the bootclasspath.
|
// of flags that should be applied to the dex implementation jars on the bootclasspath.
|
||||||
|
@@ -160,9 +160,9 @@ func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) {
|
|||||||
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String())
|
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image
|
// hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs
|
||||||
// modules.
|
// needed to produce the hidden API monolithic stub flags file.
|
||||||
func stubFlagsRule(ctx android.SingletonContext) {
|
func hiddenAPIComputeMonolithicStubLibModules(ctx android.BuilderContext) map[android.SdkKind][]string {
|
||||||
var publicStubModules []string
|
var publicStubModules []string
|
||||||
var systemStubModules []string
|
var systemStubModules []string
|
||||||
var testStubModules []string
|
var testStubModules []string
|
||||||
@@ -190,27 +190,34 @@ func stubFlagsRule(ctx android.SingletonContext) {
|
|||||||
publicStubModules = append(publicStubModules, "jacoco-stubs")
|
publicStubModules = append(publicStubModules, "jacoco-stubs")
|
||||||
}
|
}
|
||||||
|
|
||||||
publicStubPaths := make(android.Paths, len(publicStubModules))
|
m := map[android.SdkKind][]string{}
|
||||||
systemStubPaths := make(android.Paths, len(systemStubModules))
|
m[android.SdkPublic] = publicStubModules
|
||||||
testStubPaths := make(android.Paths, len(testStubModules))
|
m[android.SdkSystem] = systemStubModules
|
||||||
corePlatformStubPaths := make(android.Paths, len(corePlatformStubModules))
|
m[android.SdkTest] = testStubModules
|
||||||
|
m[android.SdkCorePlatform] = corePlatformStubModules
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
moduleListToPathList := map[*[]string]android.Paths{
|
// stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image
|
||||||
&publicStubModules: publicStubPaths,
|
// modules.
|
||||||
&systemStubModules: systemStubPaths,
|
func stubFlagsRule(ctx android.SingletonContext) {
|
||||||
&testStubModules: testStubPaths,
|
|
||||||
&corePlatformStubModules: corePlatformStubPaths,
|
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
|
var bootDexJars android.Paths
|
||||||
|
|
||||||
ctx.VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
// Collect dex jar paths for the modules listed above.
|
// Collect dex jar paths for the modules listed above.
|
||||||
if j, ok := module.(UsesLibraryDependency); ok {
|
if j, ok := module.(UsesLibraryDependency); ok {
|
||||||
name := ctx.ModuleName(module)
|
name := ctx.ModuleName(module)
|
||||||
for moduleList, pathList := range moduleListToPathList {
|
for _, sdkKind := range hiddenAPIRelevantSdkKinds {
|
||||||
if i := android.IndexList(name, *moduleList); i != -1 {
|
if i := android.IndexList(name, sdkKindToModules[sdkKind]); i != -1 {
|
||||||
pathList[i] = j.DexJarBuildPath()
|
sdkKindToPathList[sdkKind][i] = j.DexJarBuildPath()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,42 +232,63 @@ func stubFlagsRule(ctx android.SingletonContext) {
|
|||||||
|
|
||||||
var missingDeps []string
|
var missingDeps []string
|
||||||
// Ensure all modules were converted to paths
|
// Ensure all modules were converted to paths
|
||||||
for moduleList, pathList := range moduleListToPathList {
|
for _, sdkKind := range hiddenAPIRelevantSdkKinds {
|
||||||
|
pathList := sdkKindToPathList[sdkKind]
|
||||||
for i := range pathList {
|
for i := range pathList {
|
||||||
if pathList[i] == nil {
|
if pathList[i] == nil {
|
||||||
moduleName := (*moduleList)[i]
|
moduleName := sdkKindToModules[sdkKind][i]
|
||||||
pathList[i] = android.PathForOutput(ctx, "missing/module", moduleName)
|
pathList[i] = android.PathForOutput(ctx, "missing/module", moduleName)
|
||||||
if ctx.Config().AllowMissingDependencies() {
|
if ctx.Config().AllowMissingDependencies() {
|
||||||
missingDeps = append(missingDeps, moduleName)
|
missingDeps = append(missingDeps, moduleName)
|
||||||
} else {
|
} else {
|
||||||
ctx.Errorf("failed to find dex jar path for module %q",
|
ctx.Errorf("failed to find dex jar path for module %q", moduleName)
|
||||||
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.
|
// Singleton rule which applies hiddenapi on all boot class path dex files.
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
|
|
||||||
outputPath := hiddenAPISingletonPaths(ctx).stubFlags
|
|
||||||
tempPath := tempPathForRestat(ctx, outputPath)
|
tempPath := tempPathForRestat(ctx, outputPath)
|
||||||
|
|
||||||
rule.MissingDeps(missingDeps)
|
command := rule.Command().
|
||||||
|
|
||||||
rule.Command().
|
|
||||||
Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")).
|
Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")).
|
||||||
Text("list").
|
Text("list").
|
||||||
FlagForEachInput("--boot-dex=", bootDexJars).
|
FlagForEachInput("--boot-dex=", bootDexJars)
|
||||||
FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":").
|
|
||||||
FlagWithInputList("--system-stub-classpath=", systemStubPaths, ":").
|
// Iterate over the sdk
|
||||||
FlagWithInputList("--test-stub-classpath=", testStubPaths, ":").
|
for _, sdkKind := range hiddenAPIRelevantSdkKinds {
|
||||||
FlagWithInputList("--core-platform-stub-classpath=", corePlatformStubPaths, ":").
|
paths := sdkKindToPathList[sdkKind]
|
||||||
FlagWithOutput("--out-api-flags=", tempPath)
|
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)
|
commitChangeForRestat(rule, tempPath, outputPath)
|
||||||
|
return rule
|
||||||
rule.Build("hiddenAPIStubFlagsFile", "hiddenapi stub flags")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks to see whether the supplied module variant is in the list of boot jars.
|
// Checks to see whether the supplied module variant is in the list of boot jars.
|
||||||
|
Reference in New Issue
Block a user