From 591e59e511b29604a5e48240cf159e7b0e40f1c9 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Wed, 20 May 2020 13:10:59 -0700 Subject: [PATCH] Handle universal APK case in extract_apks Cherrypick of ag/11553550 Bug: 157081961 Bug: 162464887 Test: manual and builtin Merged-In: I5ac64c845328a54024171da41c369050243462b0 Merged-In: I3ebc4a84501623774b78c9c19628994c1d71dc64 Change-Id: I5ac64c845328a54024171da41c369050243462b0 --- cmd/extract_apks/main.go | 4 ++ cmd/extract_apks/main_test.go | 98 ++++++++++++++++++++++++++--------- 2 files changed, 77 insertions(+), 25 deletions(-) diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go index a638db2a8..e9a850ee8 100644 --- a/cmd/extract_apks/main.go +++ b/cmd/extract_apks/main.go @@ -374,6 +374,10 @@ func (apkSet *ApkSet) writeApks(selected SelectionResult, config TargetConfig, regexp.MustCompile(`^.*/` + selected.moduleName + `(-.*\.apk)$`), config.stem + `$1`, }, + { + regexp.MustCompile(`^universal\.apk$`), + config.stem + ".apk", + }, } renamer := func(path string) (string, bool) { for _, rr := range renameRules { diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go index bc4d377c8..bdd4becce 100644 --- a/cmd/extract_apks/main_test.go +++ b/cmd/extract_apks/main_test.go @@ -24,19 +24,19 @@ import ( "android/soong/third_party/zip" ) -type TestConfigDesc struct { +type testConfigDesc struct { name string targetConfig TargetConfig expected SelectionResult } -type TestDesc struct { +type testDesc struct { protoText string - configs []TestConfigDesc + configs []testConfigDesc } func TestSelectApks_ApkSet(t *testing.T) { - testCases := []TestDesc{ + testCases := []testDesc{ { protoText: ` variant { @@ -117,7 +117,7 @@ bundletool { version: "0.10.3" } `, - configs: []TestConfigDesc{ + configs: []testConfigDesc{ { name: "one", targetConfig: TargetConfig{ @@ -209,7 +209,7 @@ variant { value { min { value: 21 } } } } path: "splits/base-master.apk" split_apk_metadata { is_master_split: true } } } }`, - configs: []TestConfigDesc{ + configs: []testConfigDesc{ { name: "Prerelease", targetConfig: TargetConfig{ @@ -225,6 +225,30 @@ variant { }, }, }, + { + protoText: ` +variant { + targeting { + sdk_version_targeting { + value { min { value: 29 } } } } + apk_set { + module_metadata { + name: "base" targeting {} delivery_type: INSTALL_TIME } + apk_description { + targeting {} + path: "universal.apk" + standalone_apk_metadata { fused_module_name: "base" } } } }`, + configs: []testConfigDesc{ + { + name: "Universal", + targetConfig: TargetConfig{sdkVersion: 30}, + expected: SelectionResult{ + "base", + []string{"universal.apk"}, + }, + }, + }, + }, } for _, testCase := range testCases { var toc bp.BuildApksResult @@ -241,7 +265,7 @@ variant { } func TestSelectApks_ApexSet(t *testing.T) { - testCases := []TestDesc{ + testCases := []testDesc{ { protoText: ` variant { @@ -300,7 +324,7 @@ bundletool { version: "0.10.3" } `, - configs: []TestConfigDesc{ + configs: []testConfigDesc{ { name: "order matches priorities", targetConfig: TargetConfig{ @@ -406,24 +430,48 @@ func (w testZip2ZipWriter) CopyFrom(file *zip.File, out string) error { return nil } -func TestWriteZip(t *testing.T) { +type testCaseWriteZip struct { + name string + moduleName string + stem string // what we write from what - expected := map[string]string{ - "Foo.apk": "splits/mybase-master.apk", - "Foo-xhdpi.apk": "splits/mybase-xhdpi.apk", + expected map[string]string +} + +func TestWriteZip(t *testing.T) { + testCases := []testCaseWriteZip{ + { + name: "splits", + moduleName: "mybase", + stem: "Foo", + expected: map[string]string{ + "Foo.apk": "splits/mybase-master.apk", + "Foo-xhdpi.apk": "splits/mybase-xhdpi.apk", + }, + }, + { + name: "universal", + moduleName: "base", + stem: "Bar", + expected: map[string]string{ + "Bar.apk": "universal.apk", + }, + }, } - apkSet := ApkSet{entries: make(map[string]*zip.File)} - sel := SelectionResult{moduleName: "mybase"} - for _, in := range expected { - apkSet.entries[in] = &zip.File{FileHeader: zip.FileHeader{Name: in}} - sel.entries = append(sel.entries, in) - } - writer := testZip2ZipWriter{make(map[string]string)} - config := TargetConfig{stem: "Foo"} - if err := apkSet.writeApks(sel, config, writer); err != nil { - t.Error(err) - } - if !reflect.DeepEqual(expected, writer.entries) { - t.Errorf("expected %v, got %v", expected, writer.entries) + for _, testCase := range testCases { + apkSet := ApkSet{entries: make(map[string]*zip.File)} + sel := SelectionResult{moduleName: testCase.moduleName} + for _, in := range testCase.expected { + apkSet.entries[in] = &zip.File{FileHeader: zip.FileHeader{Name: in}} + sel.entries = append(sel.entries, in) + } + writer := testZip2ZipWriter{make(map[string]string)} + config := TargetConfig{stem: testCase.stem} + if err := apkSet.writeApks(sel, config, writer); err != nil { + t.Error(err) + } + if !reflect.DeepEqual(testCase.expected, writer.entries) { + t.Errorf("expected %v, got %v", testCase.expected, writer.entries) + } } }