Merge "Allow dexpreopt of source sdklib in prebuilt apex builds" into main

This commit is contained in:
Treehugger Robot
2024-04-18 01:25:15 +00:00
committed by Gerrit Code Review
6 changed files with 47 additions and 17 deletions

View File

@@ -52,7 +52,7 @@ var DexpreoptRunningInSoong = false
// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
// ModuleConfig. The produced files and their install locations will be available through rule.Installs().
func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongConfig,
global *GlobalConfig, module *ModuleConfig, productPackages android.Path) (
global *GlobalConfig, module *ModuleConfig, productPackages android.Path, copyApexSystemServerJarDex bool) (
rule *android.RuleBuilder, err error) {
defer func() {
@@ -94,7 +94,7 @@ func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongC
for archIdx, _ := range module.Archs {
dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage,
generateDM, productPackages)
generateDM, productPackages, copyApexSystemServerJarDex)
}
}
}
@@ -231,7 +231,7 @@ func ToOdexPath(path string, arch android.ArchType) string {
func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig,
global *GlobalConfig, module *ModuleConfig, rule *android.RuleBuilder, archIdx int,
profile android.WritablePath, appImage bool, generateDM bool, productPackages android.Path) {
profile android.WritablePath, appImage bool, generateDM bool, productPackages android.Path, copyApexSystemServerJarDex bool) {
arch := module.Archs[archIdx]
@@ -277,7 +277,7 @@ func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig
clcTarget = append(clcTarget, GetSystemServerDexLocation(ctx, global, lib))
}
if DexpreoptRunningInSoong {
if DexpreoptRunningInSoong && copyApexSystemServerJarDex {
// Copy the system server jar to a predefined location where dex2oat will find it.
dexPathHost := SystemServerDexJarHostPath(ctx, module.Name)
rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String()))

View File

@@ -205,8 +205,9 @@ func writeScripts(ctx android.BuilderContext, globalSoong *dexpreopt.GlobalSoong
panic(err)
}
}
cpApexSscpServerJar := false // dexpreopt_gen operates on make modules, and since sscp libraries are in soong, this should be a noop
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
ctx, globalSoong, global, module, android.PathForTesting(productPackagesPath))
ctx, globalSoong, global, module, android.PathForTesting(productPackagesPath), cpApexSscpServerJar)
if err != nil {
panic(err)
}

View File

@@ -101,7 +101,7 @@ func TestDexPreopt(t *testing.T) {
module := testSystemModuleConfig(ctx, "test")
productPackages := android.PathForTesting("product_packages.txt")
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -161,7 +161,7 @@ func TestDexPreoptSystemOther(t *testing.T) {
for _, test := range tests {
global.PatternsOnSystemOther = test.patterns
for _, mt := range test.moduleTests {
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -181,6 +181,11 @@ func TestDexPreoptSystemOther(t *testing.T) {
}
func TestDexPreoptApexSystemServerJars(t *testing.T) {
// modify the global variable for test
var oldDexpreoptRunningInSoong = DexpreoptRunningInSoong
DexpreoptRunningInSoong = true
// test begin
config := android.TestConfig("out", nil, "", nil)
ctx := android.BuilderContextForTesting(config)
globalSoong := globalSoongConfigForTests(ctx)
@@ -191,7 +196,7 @@ func TestDexPreoptApexSystemServerJars(t *testing.T) {
global.ApexSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"com.android.apex1:service-A"})
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -202,6 +207,18 @@ func TestDexPreoptApexSystemServerJars(t *testing.T) {
}
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String())
android.AssertStringListContains(t, "apex sscp jar copy", rule.Outputs().Strings(), "out/soong/system_server_dexjars/service-A.jar")
// rule with apex sscp cp as false
rule, err = GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, false)
if err != nil {
t.Fatal(err)
}
android.AssertStringListDoesNotContain(t, "apex sscp jar copy", rule.Outputs().Strings(), "out/soong/system_server_dexjars/service-A.jar")
// cleanup the global variable for test
DexpreoptRunningInSoong = oldDexpreoptRunningInSoong
}
func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
@@ -215,7 +232,7 @@ func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"platform:service-A"})
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -239,7 +256,7 @@ func TestDexPreoptSystemExtSystemServerJars(t *testing.T) {
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"system_ext:service-A"})
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -263,7 +280,7 @@ func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) {
global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"com.android.apex1:service-A"})
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}
@@ -286,7 +303,7 @@ func TestDexPreoptProfile(t *testing.T) {
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages)
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil {
t.Fatal(err)
}