Allow modules to disable stripping when dexpreopting
Add a no_stripping property and pass it to dexpreopt to disable stripping for a module. Bug: 122610462 Test: dexpreopt_test.go Change-Id: I5a4b005633bb8b1ea373e9eeb420aa0999de17ab
This commit is contained in:
@@ -113,6 +113,7 @@ type ModuleConfig struct {
|
||||
|
||||
PresignedPrebuilt bool
|
||||
|
||||
NoStripping bool
|
||||
StripInputPath string
|
||||
StripOutputPath string
|
||||
}
|
||||
|
@@ -454,6 +454,10 @@ func shouldStripDex(module ModuleConfig, global GlobalConfig) bool {
|
||||
strip = false
|
||||
}
|
||||
|
||||
if module.NoStripping {
|
||||
strip = false
|
||||
}
|
||||
|
||||
// Don't strip modules that are not on the system partition in case the oat/vdex version in system ROM
|
||||
// doesn't match the one in other partitions. It needs to be able to fall back to the APK for that case.
|
||||
if !strings.HasPrefix(module.DexLocation, SystemPartition) {
|
||||
|
@@ -82,6 +82,7 @@ var testModuleConfig = ModuleConfig{
|
||||
NoCreateAppImage: false,
|
||||
ForceCreateAppImage: false,
|
||||
PresignedPrebuilt: false,
|
||||
NoStripping: false,
|
||||
StripInputPath: "",
|
||||
StripOutputPath: "",
|
||||
}
|
||||
@@ -162,47 +163,60 @@ func TestDexPreoptProfile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStripDex(t *testing.T) {
|
||||
global, module := testGlobalConfig, testModuleConfig
|
||||
|
||||
module.Name = "test"
|
||||
module.DexLocation = "/system/app/test/test.apk"
|
||||
module.BuildPath = "out/test/test.apk"
|
||||
module.Archs = []string{"arm"}
|
||||
module.StripInputPath = "$1"
|
||||
module.StripOutputPath = "$2"
|
||||
|
||||
rule, err := GenerateStripRule(global, module)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func(global *GlobalConfig, module *ModuleConfig)
|
||||
strip bool
|
||||
}{
|
||||
{
|
||||
name: "default strip",
|
||||
setup: func(global *GlobalConfig, module *ModuleConfig) {},
|
||||
strip: true,
|
||||
},
|
||||
{
|
||||
name: "global no stripping",
|
||||
setup: func(global *GlobalConfig, module *ModuleConfig) { global.DefaultNoStripping = true },
|
||||
strip: false,
|
||||
},
|
||||
{
|
||||
name: "module no stripping",
|
||||
setup: func(global *GlobalConfig, module *ModuleConfig) { module.NoStripping = true },
|
||||
strip: false,
|
||||
},
|
||||
}
|
||||
|
||||
want := `zip2zip -i $1 -o $2 -x "classes*.dex"`
|
||||
if len(rule.Commands()) < 1 || !strings.Contains(rule.Commands()[0], want) {
|
||||
t.Errorf("\nwant commands[0] to have:\n %v\ngot:\n %v", want, rule.Commands()[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoStripDex(t *testing.T) {
|
||||
global, module := testGlobalConfig, testModuleConfig
|
||||
|
||||
global.DefaultNoStripping = true
|
||||
|
||||
module.Name = "test"
|
||||
module.DexLocation = "/system/app/test/test.apk"
|
||||
module.BuildPath = "out/test/test.apk"
|
||||
module.Archs = []string{"arm"}
|
||||
module.StripInputPath = "$1"
|
||||
module.StripOutputPath = "$2"
|
||||
|
||||
rule, err := GenerateStripRule(global, module)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
wantCommands := []string{
|
||||
"cp -f $1 $2",
|
||||
}
|
||||
if !reflect.DeepEqual(rule.Commands(), wantCommands) {
|
||||
t.Errorf("\nwant commands:\n %v\ngot:\n %v", wantCommands, rule.Commands())
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
global, module := testGlobalConfig, testModuleConfig
|
||||
|
||||
module.Name = "test"
|
||||
module.DexLocation = "/system/app/test/test.apk"
|
||||
module.BuildPath = "out/test/test.apk"
|
||||
module.Archs = []string{"arm"}
|
||||
module.StripInputPath = "$1"
|
||||
module.StripOutputPath = "$2"
|
||||
|
||||
test.setup(&global, &module)
|
||||
|
||||
rule, err := GenerateStripRule(global, module)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if test.strip {
|
||||
want := `zip2zip -i $1 -o $2 -x "classes*.dex"`
|
||||
if len(rule.Commands()) < 1 || !strings.Contains(rule.Commands()[0], want) {
|
||||
t.Errorf("\nwant commands[0] to have:\n %v\ngot:\n %v", want, rule.Commands()[0])
|
||||
}
|
||||
} else {
|
||||
wantCommands := []string{
|
||||
"cp -f $1 $2",
|
||||
}
|
||||
if !reflect.DeepEqual(rule.Commands(), wantCommands) {
|
||||
t.Errorf("\nwant commands:\n %v\ngot:\n %v", wantCommands, rule.Commands())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -43,6 +43,9 @@ type DexpreoptProperties struct {
|
||||
// true.
|
||||
Enabled *bool
|
||||
|
||||
// If true, never strip the dex files from the final jar when dexpreopting. Defaults to false.
|
||||
No_stripping *bool
|
||||
|
||||
// If true, generate an app image (.art file) for this module.
|
||||
App_image *bool
|
||||
|
||||
@@ -171,6 +174,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
|
||||
NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true),
|
||||
ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false),
|
||||
|
||||
NoStripping: Bool(d.dexpreoptProperties.Dex_preopt.No_stripping),
|
||||
StripInputPath: dexJarFile.String(),
|
||||
StripOutputPath: strippedDexJarFile.String(),
|
||||
}
|
||||
|
Reference in New Issue
Block a user