aboutsummaryrefslogtreecommitdiff
path: root/dexpreopt/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'dexpreopt/config.go')
-rw-r--r--dexpreopt/config.go50
1 files changed, 46 insertions, 4 deletions
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index af09dbcca..1fb652c3c 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -101,6 +101,10 @@ type GlobalConfig struct {
// "true" to force preopt with CMC GC (a.k.a., UFFD GC); "false" to force preopt with CC GC;
// "default" to determine the GC type based on the kernel version file.
EnableUffdGc string
+
+ // The target's `SDK_INT` (ro.build.version.sdk) string value. "" for undefined/indeterminate.
+ // Conditionally used to set assumed values in AOT-compilation.
+ PlatformSdkVersion string
}
var allPlatformSystemServerJarsKey = android.NewOnceKey("allPlatformSystemServerJars")
@@ -162,6 +166,7 @@ type GlobalSoongConfig struct {
ManifestCheck android.Path
ConstructContext android.Path
UffdGcFlag android.WritablePath
+ AssumeValueFlags android.WritablePath
}
type ModuleConfig struct {
@@ -469,8 +474,8 @@ func (d dex2oatDependencyTag) AllowDisabledModuleDependency(target android.Modul
func (d dex2oatDependencyTag) AllowDisabledModuleDependencyProxy(
ctx android.OtherModuleProviderContext, target android.ModuleProxy) bool {
- return android.OtherModulePointerProviderOrDefault(
- ctx, target, android.CommonModuleInfoProvider).ReplacedByPrebuilt
+ return android.OtherModuleProviderOrDefault(
+ ctx, target, android.PrebuiltInfoProvider).ReplacedByPrebuilt
}
// Dex2oatDepTag represents the dependency onto the dex2oatd module. It is added to any module that
@@ -514,7 +519,11 @@ func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
// prebuilt explicitly here instead.
var dex2oatModule android.ModuleProxy
ctx.WalkDepsProxy(func(child, parent android.ModuleProxy) bool {
- prebuiltInfo, isPrebuilt := android.OtherModuleProvider(ctx, child, android.PrebuiltModuleInfoProvider)
+ var isPrebuilt, usePrebuilt bool
+ if prebuiltInfo, ok := android.OtherModuleProvider(ctx, child, android.PrebuiltInfoProvider); ok {
+ isPrebuilt = prebuiltInfo.IsPrebuilt
+ usePrebuilt = prebuiltInfo.UsePrebuilt
+ }
if android.EqualModules(parent, ctx.Module()) && ctx.OtherModuleDependencyTag(child) == Dex2oatDepTag {
// Found the source module, or prebuilt module that has replaced the source.
dex2oatModule = child
@@ -525,7 +534,7 @@ func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
}
}
if android.EqualModules(parent, dex2oatModule) && ctx.OtherModuleDependencyTag(child) == android.PrebuiltDepTag {
- if isPrebuilt && prebuiltInfo.UsePrebuilt {
+ if isPrebuilt && usePrebuilt {
dex2oatModule = child // Found a prebuilt that should be used.
}
}
@@ -557,6 +566,7 @@ func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
ManifestCheck: ctx.Config().HostToolPath(ctx, "manifest_check"),
ConstructContext: ctx.Config().HostToolPath(ctx, "construct_context"),
UffdGcFlag: getUffdGcFlagPath(ctx),
+ AssumeValueFlags: getAssumeValueFlagsPath(ctx),
}
}
@@ -609,6 +619,7 @@ type globalJsonSoongConfig struct {
ManifestCheck string
ConstructContext string
UffdGcFlag string
+ AssumeValueFlags string
}
// ParseGlobalSoongConfig parses the given data assumed to be read from the
@@ -631,6 +642,7 @@ func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongC
ManifestCheck: constructPath(ctx, jc.ManifestCheck),
ConstructContext: constructPath(ctx, jc.ConstructContext),
UffdGcFlag: constructWritablePath(ctx, jc.UffdGcFlag),
+ AssumeValueFlags: constructWritablePath(ctx, jc.AssumeValueFlags),
}
return config, nil
@@ -671,6 +683,8 @@ func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonC
return
}
+ buildAssumedValues(ctx, global, config)
+
jc := globalJsonSoongConfig{
Profman: config.Profman.String(),
Dex2oat: config.Dex2oat.String(),
@@ -680,6 +694,7 @@ func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonC
ManifestCheck: config.ManifestCheck.String(),
ConstructContext: config.ConstructContext.String(),
UffdGcFlag: config.UffdGcFlag.String(),
+ AssumeValueFlags: config.AssumeValueFlags.String(),
}
data, err := json.Marshal(jc)
@@ -711,6 +726,7 @@ func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
config.ManifestCheck.String(),
config.ConstructContext.String(),
config.UffdGcFlag.String(),
+ config.AssumeValueFlags.String(),
}, " "))
}
@@ -737,6 +753,27 @@ func buildUffdGcFlag(ctx android.BuilderContext, global *GlobalConfig) {
}
}
+func buildAssumedValues(ctx android.BuilderContext, global *GlobalConfig, globalSoong *GlobalSoongConfig) {
+ assumeValueFlags := getAssumeValueFlagsPath(ctx)
+
+ if global.PlatformSdkVersion != "" {
+ maybeAssumedValues := fmt.Sprintf(`'--assume-value=Landroid/os/Build$VERSION;->SDK_INT:%s'`, global.PlatformSdkVersion)
+ rule := android.NewRuleBuilder(pctx, ctx)
+ cmd := rule.Command()
+ // First check dex2oat to see if it supports `--assume-value=` arguments.
+ // If it does, stash the assumed value args in a reusable output file for compilation.
+ // Otherwise, just create an empty placeholder file that becomes a no-op.
+ // TODO(b/204924812): Remove the args check after prebuilt ART modules are updated from source.
+ cmd.Text("if (").Tool(globalSoong.Dex2oat).Text("--help 2>&1 | grep -q -- --assume-value)").
+ Text("; then echo").Text(maybeAssumedValues).Text(">").Output(assumeValueFlags).
+ Text("; else >").Output(assumeValueFlags).
+ Text("; fi")
+ rule.Restat().Build("dexpreopt_assume_value_flags", "dexpreopt_assume_value_flags")
+ } else {
+ android.WriteFileRuleVerbatim(ctx, assumeValueFlags, "")
+ }
+}
+
func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig {
return &GlobalConfig{
DisablePreopt: false,
@@ -791,6 +828,7 @@ func globalSoongConfigForTests(ctx android.BuilderContext) *GlobalSoongConfig {
ManifestCheck: android.PathForTesting("manifest_check"),
ConstructContext: android.PathForTesting("construct_context"),
UffdGcFlag: android.PathForOutput(ctx, "dexpreopt_test", "uffd_gc_flag.txt"),
+ AssumeValueFlags: android.PathForOutput(ctx, "dexpreopt_test", "assume_value_flags.txt"),
}
}
@@ -806,3 +844,7 @@ func GetDexpreoptDirName(ctx android.PathContext) string {
func getUffdGcFlagPath(ctx android.PathContext) android.WritablePath {
return android.PathForOutput(ctx, "dexpreopt/uffd_gc_flag.txt")
}
+
+func getAssumeValueFlagsPath(ctx android.PathContext) android.WritablePath {
+ return android.PathForOutput(ctx, "dexpreopt/assume_value_flags.txt")
+}