Handle universal APK case in extract_apks
Cherrypick of ag/11553550 Bug: 157081961 Test: manual and builtin Merged-In: I5ac64c845328a54024171da41c369050243462b0 Change-Id: I3ebc4a84501623774b78c9c19628994c1d71dc64
This commit is contained in:
@@ -374,6 +374,10 @@ func (apkSet *ApkSet) writeApks(selected SelectionResult, config TargetConfig,
|
|||||||
regexp.MustCompile(`^.*/` + selected.moduleName + `(-.*\.apk)$`),
|
regexp.MustCompile(`^.*/` + selected.moduleName + `(-.*\.apk)$`),
|
||||||
config.stem + `$1`,
|
config.stem + `$1`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
regexp.MustCompile(`^universal\.apk$`),
|
||||||
|
config.stem + ".apk",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
renamer := func(path string) (string, bool) {
|
renamer := func(path string) (string, bool) {
|
||||||
for _, rr := range renameRules {
|
for _, rr := range renameRules {
|
||||||
|
@@ -24,19 +24,19 @@ import (
|
|||||||
"android/soong/third_party/zip"
|
"android/soong/third_party/zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestConfigDesc struct {
|
type testConfigDesc struct {
|
||||||
name string
|
name string
|
||||||
targetConfig TargetConfig
|
targetConfig TargetConfig
|
||||||
expected SelectionResult
|
expected SelectionResult
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestDesc struct {
|
type testDesc struct {
|
||||||
protoText string
|
protoText string
|
||||||
configs []TestConfigDesc
|
configs []testConfigDesc
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectApks_ApkSet(t *testing.T) {
|
func TestSelectApks_ApkSet(t *testing.T) {
|
||||||
testCases := []TestDesc{
|
testCases := []testDesc{
|
||||||
{
|
{
|
||||||
protoText: `
|
protoText: `
|
||||||
variant {
|
variant {
|
||||||
@@ -117,7 +117,7 @@ bundletool {
|
|||||||
version: "0.10.3" }
|
version: "0.10.3" }
|
||||||
|
|
||||||
`,
|
`,
|
||||||
configs: []TestConfigDesc{
|
configs: []testConfigDesc{
|
||||||
{
|
{
|
||||||
name: "one",
|
name: "one",
|
||||||
targetConfig: TargetConfig{
|
targetConfig: TargetConfig{
|
||||||
@@ -209,7 +209,7 @@ variant {
|
|||||||
value { min { value: 21 } } } }
|
value { min { value: 21 } } } }
|
||||||
path: "splits/base-master.apk"
|
path: "splits/base-master.apk"
|
||||||
split_apk_metadata { is_master_split: true } } } }`,
|
split_apk_metadata { is_master_split: true } } } }`,
|
||||||
configs: []TestConfigDesc{
|
configs: []testConfigDesc{
|
||||||
{
|
{
|
||||||
name: "Prerelease",
|
name: "Prerelease",
|
||||||
targetConfig: TargetConfig{
|
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 {
|
for _, testCase := range testCases {
|
||||||
var toc bp.BuildApksResult
|
var toc bp.BuildApksResult
|
||||||
@@ -241,7 +265,7 @@ variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectApks_ApexSet(t *testing.T) {
|
func TestSelectApks_ApexSet(t *testing.T) {
|
||||||
testCases := []TestDesc{
|
testCases := []testDesc{
|
||||||
{
|
{
|
||||||
protoText: `
|
protoText: `
|
||||||
variant {
|
variant {
|
||||||
@@ -300,7 +324,7 @@ bundletool {
|
|||||||
version: "0.10.3" }
|
version: "0.10.3" }
|
||||||
|
|
||||||
`,
|
`,
|
||||||
configs: []TestConfigDesc{
|
configs: []testConfigDesc{
|
||||||
{
|
{
|
||||||
name: "order matches priorities",
|
name: "order matches priorities",
|
||||||
targetConfig: TargetConfig{
|
targetConfig: TargetConfig{
|
||||||
@@ -406,24 +430,48 @@ func (w testZip2ZipWriter) CopyFrom(file *zip.File, out string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteZip(t *testing.T) {
|
type testCaseWriteZip struct {
|
||||||
|
name string
|
||||||
|
moduleName string
|
||||||
|
stem string
|
||||||
// what we write from what
|
// what we write from what
|
||||||
expected := map[string]string{
|
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.apk": "splits/mybase-master.apk",
|
||||||
"Foo-xhdpi.apk": "splits/mybase-xhdpi.apk",
|
"Foo-xhdpi.apk": "splits/mybase-xhdpi.apk",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "universal",
|
||||||
|
moduleName: "base",
|
||||||
|
stem: "Bar",
|
||||||
|
expected: map[string]string{
|
||||||
|
"Bar.apk": "universal.apk",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
apkSet := ApkSet{entries: make(map[string]*zip.File)}
|
apkSet := ApkSet{entries: make(map[string]*zip.File)}
|
||||||
sel := SelectionResult{moduleName: "mybase"}
|
sel := SelectionResult{moduleName: testCase.moduleName}
|
||||||
for _, in := range expected {
|
for _, in := range testCase.expected {
|
||||||
apkSet.entries[in] = &zip.File{FileHeader: zip.FileHeader{Name: in}}
|
apkSet.entries[in] = &zip.File{FileHeader: zip.FileHeader{Name: in}}
|
||||||
sel.entries = append(sel.entries, in)
|
sel.entries = append(sel.entries, in)
|
||||||
}
|
}
|
||||||
writer := testZip2ZipWriter{make(map[string]string)}
|
writer := testZip2ZipWriter{make(map[string]string)}
|
||||||
config := TargetConfig{stem: "Foo"}
|
config := TargetConfig{stem: testCase.stem}
|
||||||
if err := apkSet.writeApks(sel, config, writer); err != nil {
|
if err := apkSet.writeApks(sel, config, writer); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(expected, writer.entries) {
|
if !reflect.DeepEqual(testCase.expected, writer.entries) {
|
||||||
t.Errorf("expected %v, got %v", expected, writer.entries)
|
t.Errorf("expected %v, got %v", testCase.expected, writer.entries)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user