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
commit 17b9a5b8b4
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 // 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(). // ModuleConfig. The produced files and their install locations will be available through rule.Installs().
func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongConfig, 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) { rule *android.RuleBuilder, err error) {
defer func() { defer func() {
@ -94,7 +94,7 @@ func GenerateDexpreoptRule(ctx android.BuilderContext, globalSoong *GlobalSoongC
for archIdx, _ := range module.Archs { for archIdx, _ := range module.Archs {
dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage, 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, func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig,
global *GlobalConfig, module *ModuleConfig, rule *android.RuleBuilder, archIdx int, 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] arch := module.Archs[archIdx]
@ -277,7 +277,7 @@ func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig
clcTarget = append(clcTarget, GetSystemServerDexLocation(ctx, global, lib)) 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. // Copy the system server jar to a predefined location where dex2oat will find it.
dexPathHost := SystemServerDexJarHostPath(ctx, module.Name) dexPathHost := SystemServerDexJarHostPath(ctx, module.Name)
rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String())) 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) 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( dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
ctx, globalSoong, global, module, android.PathForTesting(productPackagesPath)) ctx, globalSoong, global, module, android.PathForTesting(productPackagesPath), cpApexSscpServerJar)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -101,7 +101,7 @@ func TestDexPreopt(t *testing.T) {
module := testSystemModuleConfig(ctx, "test") module := testSystemModuleConfig(ctx, "test")
productPackages := android.PathForTesting("product_packages.txt") 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -161,7 +161,7 @@ func TestDexPreoptSystemOther(t *testing.T) {
for _, test := range tests { for _, test := range tests {
global.PatternsOnSystemOther = test.patterns global.PatternsOnSystemOther = test.patterns
for _, mt := range test.moduleTests { 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -181,6 +181,11 @@ func TestDexPreoptSystemOther(t *testing.T) {
} }
func TestDexPreoptApexSystemServerJars(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) config := android.TestConfig("out", nil, "", nil)
ctx := android.BuilderContextForTesting(config) ctx := android.BuilderContextForTesting(config)
globalSoong := globalSoongConfigForTests(ctx) globalSoong := globalSoongConfigForTests(ctx)
@ -191,7 +196,7 @@ func TestDexPreoptApexSystemServerJars(t *testing.T) {
global.ApexSystemServerJars = android.CreateTestConfiguredJarList( global.ApexSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"com.android.apex1:service-A"}) []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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -202,6 +207,18 @@ func TestDexPreoptApexSystemServerJars(t *testing.T) {
} }
android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) 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) { func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
@ -215,7 +232,7 @@ func TestDexPreoptStandaloneSystemServerJars(t *testing.T) {
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"platform:service-A"}) []string{"platform:service-A"})
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages) rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module, productPackages, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -239,7 +256,7 @@ func TestDexPreoptSystemExtSystemServerJars(t *testing.T) {
global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"system_ext:service-A"}) []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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -263,7 +280,7 @@ func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) {
global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList( global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(
[]string{"com.android.apex1:service-A"}) []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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -286,7 +303,7 @@ func TestDexPreoptProfile(t *testing.T) {
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile")) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -243,10 +243,6 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName s
return true return true
} }
if disableSourceApexVariant(ctx) {
return true
}
if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex { if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex {
// dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes
return false return false
@ -501,8 +497,12 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa
Output(appProductPackages) Output(appProductPackages)
productPackagesRule.Restat().Build("product_packages."+dexJarStem, "dexpreopt product_packages") productPackagesRule.Restat().Build("product_packages."+dexJarStem, "dexpreopt product_packages")
// Prebuilts are active, do not copy the dexpreopt'd source javalib to out/soong/system_server_dexjars
// The javalib from the deapexed prebuilt will be copied to this location.
// TODO (b/331665856): Implement a principled solution for this.
copyApexSystemServerJarDex := !disableSourceApexVariant(ctx)
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule( dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
ctx, globalSoong, global, dexpreoptConfig, appProductPackages) ctx, globalSoong, global, dexpreoptConfig, appProductPackages, copyApexSystemServerJarDex)
if err != nil { if err != nil {
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error()) ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
return return

View file

@ -886,6 +886,12 @@ func init() {
} }
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if disableSourceApexVariant(ctx) {
// Prebuilts are active, do not create the installation rules for the source javalib.
// Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules.
// TODO (b/331665856): Implement a principled solution for this.
j.HideFromMake()
}
j.provideHiddenAPIPropertyInfo(ctx) j.provideHiddenAPIPropertyInfo(ctx)
j.sdkVersion = j.SdkVersion(ctx) j.sdkVersion = j.SdkVersion(ctx)

View file

@ -1562,6 +1562,12 @@ func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
} }
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if disableSourceApexVariant(ctx) {
// Prebuilts are active, do not create the installation rules for the source javalib.
// Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules.
// TODO (b/331665856): Implement a principled solution for this.
module.HideFromMake()
}
if proptools.String(module.deviceProperties.Min_sdk_version) != "" { if proptools.String(module.deviceProperties.Min_sdk_version) != "" {
module.CheckMinSdkVersion(ctx) module.CheckMinSdkVersion(ctx)
} }