2020-12-21 21:29:12 +01:00
|
|
|
// Copyright 2020 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2021-03-22 18:31:52 +01:00
|
|
|
"fmt"
|
2020-12-21 21:29:12 +01:00
|
|
|
"reflect"
|
2021-11-12 21:19:42 +01:00
|
|
|
"strings"
|
2020-12-21 21:29:12 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAndroidAppSet(t *testing.T) {
|
2021-11-12 21:19:42 +01:00
|
|
|
result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, `
|
2020-12-21 21:29:12 +01:00
|
|
|
android_app_set {
|
|
|
|
name: "foo",
|
|
|
|
set: "prebuilts/apks/app.apks",
|
|
|
|
prerelease: true,
|
|
|
|
}`)
|
2021-11-12 21:19:42 +01:00
|
|
|
module := result.ModuleForTests("foo", "android_common")
|
2020-12-21 21:29:12 +01:00
|
|
|
const packedSplitApks = "foo.zip"
|
|
|
|
params := module.Output(packedSplitApks)
|
|
|
|
if params.Rule == nil {
|
|
|
|
t.Errorf("expected output %s is missing", packedSplitApks)
|
|
|
|
}
|
|
|
|
if s := params.Args["allow-prereleased"]; s != "true" {
|
|
|
|
t.Errorf("wrong allow-prereleased value: '%s', expected 'true'", s)
|
|
|
|
}
|
|
|
|
if s := params.Args["partition"]; s != "system" {
|
|
|
|
t.Errorf("wrong partition value: '%s', expected 'system'", s)
|
|
|
|
}
|
2021-11-12 21:19:42 +01:00
|
|
|
|
|
|
|
android.AssertPathRelativeToTopEquals(t, "incorrect output path",
|
|
|
|
"out/soong/.intermediates/foo/android_common/foo.apk", params.Output)
|
|
|
|
|
|
|
|
android.AssertPathsRelativeToTopEquals(t, "incorrect implicit output paths",
|
|
|
|
[]string{
|
|
|
|
"out/soong/.intermediates/foo/android_common/foo.zip",
|
|
|
|
"out/soong/.intermediates/foo/android_common/apkcerts.txt",
|
|
|
|
},
|
|
|
|
params.ImplicitOutputs.Paths())
|
|
|
|
|
|
|
|
mkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, module.Module())[0]
|
2020-12-21 21:29:12 +01:00
|
|
|
actualInstallFile := mkEntries.EntryMap["LOCAL_APK_SET_INSTALL_FILE"]
|
2021-11-12 21:19:42 +01:00
|
|
|
expectedInstallFile := []string{
|
|
|
|
strings.Replace(params.ImplicitOutputs[0].String(), android.OutSoongDir, result.Config.SoongOutDir(), 1),
|
|
|
|
}
|
2020-12-21 21:29:12 +01:00
|
|
|
if !reflect.DeepEqual(actualInstallFile, expectedInstallFile) {
|
|
|
|
t.Errorf("Unexpected LOCAL_APK_SET_INSTALL_FILE value: '%s', expected: '%s',",
|
|
|
|
actualInstallFile, expectedInstallFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAndroidAppSet_Variants(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
android_app_set {
|
|
|
|
name: "foo",
|
|
|
|
set: "prebuilts/apks/app.apks",
|
|
|
|
}`
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
targets []android.Target
|
|
|
|
aaptPrebuiltDPI []string
|
|
|
|
sdkVersion int
|
|
|
|
expected map[string]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "One",
|
|
|
|
targets: []android.Target{
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
|
|
|
|
},
|
|
|
|
aaptPrebuiltDPI: []string{"ldpi", "xxhdpi"},
|
|
|
|
sdkVersion: 29,
|
|
|
|
expected: map[string]string{
|
|
|
|
"abis": "X86",
|
|
|
|
"allow-prereleased": "false",
|
|
|
|
"screen-densities": "LDPI,XXHDPI",
|
|
|
|
"sdk-version": "29",
|
2023-03-21 00:19:53 +01:00
|
|
|
"skip-sdk-check": "false",
|
2020-12-21 21:29:12 +01:00
|
|
|
"stem": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Two",
|
|
|
|
targets: []android.Target{
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.X86_64}},
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.X86}},
|
|
|
|
},
|
|
|
|
aaptPrebuiltDPI: nil,
|
|
|
|
sdkVersion: 30,
|
|
|
|
expected: map[string]string{
|
|
|
|
"abis": "X86_64,X86",
|
|
|
|
"allow-prereleased": "false",
|
|
|
|
"screen-densities": "all",
|
|
|
|
"sdk-version": "30",
|
2023-03-21 00:19:53 +01:00
|
|
|
"skip-sdk-check": "false",
|
2020-12-21 21:29:12 +01:00
|
|
|
"stem": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
2021-03-22 18:31:52 +01:00
|
|
|
ctx := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI
|
|
|
|
variables.Platform_sdk_version = &test.sdkVersion
|
|
|
|
}),
|
|
|
|
android.FixtureModifyConfig(func(config android.Config) {
|
|
|
|
config.Targets[android.Android] = test.targets
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, bp)
|
|
|
|
|
2020-12-21 21:29:12 +01:00
|
|
|
module := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
const packedSplitApks = "foo.zip"
|
|
|
|
params := module.Output(packedSplitApks)
|
|
|
|
for k, v := range test.expected {
|
2021-03-22 18:31:52 +01:00
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
android.AssertStringEquals(t, fmt.Sprintf("arg value for `%s`", k), v, params.Args[k])
|
|
|
|
})
|
2020-12-21 21:29:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|