2017-11-23 08:19:37 +08:00
|
|
|
// Copyright 2017 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 (
|
2018-04-19 02:06:47 +08:00
|
|
|
"fmt"
|
2018-10-03 13:03:40 +08:00
|
|
|
"path/filepath"
|
2017-11-23 08:19:37 +08:00
|
|
|
"reflect"
|
2017-12-02 02:48:26 +08:00
|
|
|
"sort"
|
2018-04-19 02:06:47 +08:00
|
|
|
"strings"
|
2017-11-23 08:19:37 +08:00
|
|
|
"testing"
|
2019-04-27 05:31:50 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
2021-03-23 00:02:28 +08:00
|
|
|
"android/soong/dexpreopt"
|
2021-03-23 01:31:52 +08:00
|
|
|
"android/soong/genrule"
|
2017-11-23 08:19:37 +08:00
|
|
|
)
|
|
|
|
|
2021-03-22 23:36:52 +08:00
|
|
|
// testApp runs tests using the prepareForJavaTest
|
2021-03-13 10:19:32 +08:00
|
|
|
//
|
|
|
|
// See testJava for an explanation as to how to stop using this deprecated method.
|
|
|
|
//
|
|
|
|
// deprecated
|
|
|
|
func testApp(t *testing.T, bp string) *android.TestContext {
|
|
|
|
t.Helper()
|
2021-03-22 23:36:52 +08:00
|
|
|
result := prepareForJavaTest.RunTestWithBp(t, bp)
|
2021-03-13 10:19:32 +08:00
|
|
|
return result.TestContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApp(t *testing.T) {
|
|
|
|
resourceFiles := []string{
|
2017-11-23 08:19:37 +08:00
|
|
|
"res/layout/layout.xml",
|
|
|
|
"res/values/strings.xml",
|
|
|
|
"res/values-en-rUS/strings.xml",
|
|
|
|
}
|
|
|
|
|
2021-03-13 10:19:32 +08:00
|
|
|
compiledResourceFiles := []string{
|
2017-11-23 08:19:37 +08:00
|
|
|
"aapt2/res/layout_layout.xml.flat",
|
|
|
|
"aapt2/res/values_strings.arsc.flat",
|
|
|
|
"aapt2/res/values-en-rUS_strings.arsc.flat",
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
for _, moduleType := range []string{"android_app", "android_library"} {
|
|
|
|
t.Run(moduleType, func(t *testing.T) {
|
2021-03-22 23:36:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
2021-03-13 10:19:32 +08:00
|
|
|
android.FixtureModifyMockFS(func(fs android.MockFS) {
|
|
|
|
for _, file := range resourceFiles {
|
|
|
|
fs[file] = nil
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, moduleType+` {
|
2018-03-29 05:58:31 +08:00
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current"
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2021-03-13 10:19:32 +08:00
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2018-05-25 07:11:20 +08:00
|
|
|
var expectedLinkImplicits []string
|
|
|
|
|
|
|
|
manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml")
|
|
|
|
expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String())
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2021-03-13 10:19:32 +08:00
|
|
|
frameworkRes := result.ModuleForTests("framework-res", "android_common")
|
2018-03-29 05:58:31 +08:00
|
|
|
expectedLinkImplicits = append(expectedLinkImplicits,
|
|
|
|
frameworkRes.Output("package-res.apk").Output.String())
|
|
|
|
|
|
|
|
// Test the mapping from input files to compiled output file names
|
|
|
|
compile := foo.Output(compiledResourceFiles[0])
|
2021-03-13 10:19:32 +08:00
|
|
|
android.AssertDeepEquals(t, "aapt2 compile inputs", resourceFiles, compile.Inputs.Strings())
|
2018-03-29 05:58:31 +08:00
|
|
|
|
|
|
|
compiledResourceOutputs := compile.Outputs.Strings()
|
|
|
|
sort.Strings(compiledResourceOutputs)
|
|
|
|
|
|
|
|
expectedLinkImplicits = append(expectedLinkImplicits, compiledResourceOutputs...)
|
|
|
|
|
|
|
|
list := foo.Output("aapt2/res.list")
|
|
|
|
expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String())
|
|
|
|
|
|
|
|
// Check that the link rule uses
|
2021-03-13 10:19:32 +08:00
|
|
|
res := result.ModuleForTests("foo", "android_common").Output("package-res.apk")
|
|
|
|
android.AssertDeepEquals(t, "aapt2 link implicits", expectedLinkImplicits, res.Implicits.Strings())
|
2018-03-29 05:58:31 +08:00
|
|
|
})
|
2017-11-23 08:19:37 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
|
2019-03-20 07:03:11 +08:00
|
|
|
func TestAppSplits(t *testing.T) {
|
|
|
|
ctx := testApp(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
package_splits: ["v4", "v7,hdpi"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current"
|
2019-03-20 07:03:11 +08:00
|
|
|
}`)
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
|
|
|
|
expectedOutputs := []string{
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/foo/android_common/foo.apk",
|
|
|
|
"out/soong/.intermediates/foo/android_common/foo_v4.apk",
|
|
|
|
"out/soong/.intermediates/foo/android_common/foo_v7_hdpi.apk",
|
2019-03-20 07:03:11 +08:00
|
|
|
}
|
|
|
|
for _, expectedOutput := range expectedOutputs {
|
|
|
|
foo.Output(expectedOutput)
|
|
|
|
}
|
|
|
|
|
2019-05-30 05:40:35 +08:00
|
|
|
outputFiles, err := foo.Module().(*AndroidApp).OutputFiles("")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, `OutputFiles("")`, expectedOutputs, outputFiles)
|
2019-03-20 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 14:54:27 +08:00
|
|
|
func TestPlatformAPIs(t *testing.T) {
|
|
|
|
testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testJavaError(t, "platform_apis must be true when sdk_version is empty.", `
|
|
|
|
android_app {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testJavaError(t, "platform_apis must be false when sdk_version is not empty.", `
|
|
|
|
android_app {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2019-12-06 23:16:24 +08:00
|
|
|
func TestAndroidAppLinkType(t *testing.T) {
|
|
|
|
testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
static_libs: ["baz"],
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "baz",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-11-18 05:44:36 +08:00
|
|
|
testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", `
|
2019-12-06 23:16:24 +08:00
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "current",
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "baz",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "baz",
|
|
|
|
sdk_version: "system_current",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2020-11-18 05:44:36 +08:00
|
|
|
testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", `
|
2019-12-06 23:16:24 +08:00
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["bar"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
static_libs: ["baz"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-04-09 02:09:30 +08:00
|
|
|
func TestUpdatableApps(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Stable public SDK",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "29",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Stable system SDK",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "system_29",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Current public SDK",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Current system SDK",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "system_current",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Current module SDK",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "module_current",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Current core SDK",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "core_current",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "No Platform APIs",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
platform_apis: true,
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
expectedError: "Updatable apps must use stable SDKs",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "No Core Platform APIs",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "core_platform",
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
expectedError: "Updatable apps must use stable SDKs",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "No unspecified APIs",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
updatable: true,
|
2020-04-16 20:43:02 +08:00
|
|
|
min_sdk_version: "29",
|
2020-04-09 02:09:30 +08:00
|
|
|
}`,
|
|
|
|
expectedError: "Updatable apps must use stable SDK",
|
|
|
|
},
|
2020-04-16 20:43:02 +08:00
|
|
|
{
|
|
|
|
name: "Must specify min_sdk_version",
|
|
|
|
bp: `android_app {
|
|
|
|
name: "app_without_min_sdk_version",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "29",
|
|
|
|
updatable: true,
|
|
|
|
}`,
|
|
|
|
expectedError: "updatable apps must set min_sdk_version.",
|
|
|
|
},
|
2020-04-09 02:09:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2021-03-14 08:36:50 +08:00
|
|
|
errorHandler := android.FixtureExpectsNoErrors
|
|
|
|
if test.expectedError != "" {
|
|
|
|
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError)
|
2020-04-09 02:09:30 +08:00
|
|
|
}
|
2021-03-22 23:36:52 +08:00
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{
|
2021-03-13 10:36:00 +08:00
|
|
|
"29": {"foo"},
|
|
|
|
})).
|
2021-03-14 08:36:50 +08:00
|
|
|
ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, test.bp)
|
2020-04-09 02:09:30 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 10:03:39 +08:00
|
|
|
func TestUpdatableApps_TransitiveDepsShouldSetMinSdkVersion(t *testing.T) {
|
|
|
|
testJavaError(t, `module "bar".*: should support min_sdk_version\(29\)`, cc.GatherRequiredDepsForTest(android.Android)+`
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
updatable: true,
|
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
|
|
|
static_libs: ["bar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2020-04-29 13:01:06 +08:00
|
|
|
func TestUpdatableApps_JniLibsShouldShouldSupportMinSdkVersion(t *testing.T) {
|
|
|
|
testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
updatable: true,
|
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "current",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) {
|
|
|
|
bp := cc.GatherRequiredDepsForTest(android.Android) + `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
updatable: true,
|
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
sdk_version: "29",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
fs := map[string][]byte{
|
|
|
|
"prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtbegin_so.o": nil,
|
|
|
|
"prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtend_so.o": nil,
|
|
|
|
"prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtbegin_so.o": nil,
|
|
|
|
"prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtend_so.o": nil,
|
|
|
|
}
|
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
ctx, _ := testJavaWithFS(t, bp, fs)
|
2020-04-29 13:01:06 +08:00
|
|
|
|
|
|
|
inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits
|
|
|
|
var crtbeginFound, crtendFound bool
|
2020-07-16 04:33:30 +08:00
|
|
|
expectedCrtBegin := ctx.ModuleForTests("crtbegin_so",
|
|
|
|
"android_arm64_armv8-a_sdk_29").Rule("partialLd").Output
|
|
|
|
expectedCrtEnd := ctx.ModuleForTests("crtend_so",
|
|
|
|
"android_arm64_armv8-a_sdk_29").Rule("partialLd").Output
|
|
|
|
implicits := []string{}
|
2020-04-29 13:01:06 +08:00
|
|
|
for _, input := range inputs {
|
2020-07-16 04:33:30 +08:00
|
|
|
implicits = append(implicits, input.String())
|
|
|
|
if strings.HasSuffix(input.String(), expectedCrtBegin.String()) {
|
2020-04-29 13:01:06 +08:00
|
|
|
crtbeginFound = true
|
2020-07-16 04:33:30 +08:00
|
|
|
} else if strings.HasSuffix(input.String(), expectedCrtEnd.String()) {
|
2020-04-29 13:01:06 +08:00
|
|
|
crtendFound = true
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 04:33:30 +08:00
|
|
|
if !crtbeginFound {
|
|
|
|
t.Error(fmt.Sprintf(
|
|
|
|
"expected implicit with suffix %q, have the following implicits:\n%s",
|
|
|
|
expectedCrtBegin, strings.Join(implicits, "\n")))
|
|
|
|
}
|
|
|
|
if !crtendFound {
|
|
|
|
t.Error(fmt.Sprintf(
|
|
|
|
"expected implicit with suffix %q, have the following implicits:\n%s",
|
|
|
|
expectedCrtEnd, strings.Join(implicits, "\n")))
|
2020-04-29 13:01:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdatableApps_ErrorIfJniLibDoesntSupportMinSdkVersion(t *testing.T) {
|
|
|
|
bp := cc.GatherRequiredDepsForTest(android.Android) + `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
updatable: true,
|
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29", // this APK should support 29
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
stl: "none",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
testJavaError(t, `"libjni" .*: sdk_version\(current\) is higher than min_sdk_version\(29\)`, bp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdatableApps_ErrorIfDepSdkVersionIsHigher(t *testing.T) {
|
|
|
|
bp := cc.GatherRequiredDepsForTest(android.Android) + `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
updatable: true,
|
|
|
|
sdk_version: "current",
|
|
|
|
min_sdk_version: "29", // this APK should support 29
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
stl: "none",
|
|
|
|
shared_libs: ["libbar"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
sdk_version: "27",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
testJavaError(t, `"libjni" .*: links "libbar" built against newer API version "current"`, bp)
|
|
|
|
}
|
|
|
|
|
2019-02-08 07:30:01 +08:00
|
|
|
func TestResourceDirs(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
prop string
|
|
|
|
resources []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no resource_dirs",
|
|
|
|
prop: "",
|
|
|
|
resources: []string{"res/res/values/strings.xml"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "resource_dirs",
|
|
|
|
prop: `resource_dirs: ["res"]`,
|
|
|
|
resources: []string{"res/res/values/strings.xml"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty resource_dirs",
|
|
|
|
prop: `resource_dirs: []`,
|
|
|
|
resources: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
fs := android.MockFS{
|
2019-02-08 07:30:01 +08:00
|
|
|
"res/res/values/strings.xml": nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-02-08 07:30:01 +08:00
|
|
|
%s
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
PrepareForTestWithOverlayBuildComponents,
|
|
|
|
fs.AddToFixture(),
|
|
|
|
).RunTestWithBp(t, fmt.Sprintf(bp, testCase.prop))
|
2019-02-08 07:30:01 +08:00
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
module := result.ModuleForTests("foo", "android_common")
|
2019-02-08 07:30:01 +08:00
|
|
|
resourceList := module.MaybeOutput("aapt2/res.list")
|
|
|
|
|
|
|
|
var resources []string
|
|
|
|
if resourceList.Rule != nil {
|
|
|
|
for _, compiledResource := range resourceList.Inputs.Strings() {
|
|
|
|
resources = append(resources, module.Output(compiledResource).Inputs.Strings()...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertDeepEquals(t, "resource files", testCase.resources, resources)
|
2019-02-08 07:30:01 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
func TestLibraryAssets(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
sdk_version: "current",
|
|
|
|
static_libs: ["lib1", "lib2", "lib3"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib1",
|
|
|
|
sdk_version: "current",
|
|
|
|
asset_dirs: ["assets_a"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib2",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib3",
|
|
|
|
sdk_version: "current",
|
|
|
|
static_libs: ["lib4"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib4",
|
|
|
|
sdk_version: "current",
|
|
|
|
asset_dirs: ["assets_b"],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
assetFlag string
|
|
|
|
assetPackages []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "foo",
|
|
|
|
// lib1 has its own asset. lib3 doesn't have any, but provides lib4's transitively.
|
|
|
|
assetPackages: []string{
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/foo/android_common/aapt2/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib1/android_common/assets.zip",
|
|
|
|
"out/soong/.intermediates/lib3/android_common/assets.zip",
|
2020-01-16 06:15:10 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "lib1",
|
|
|
|
assetFlag: "-A assets_a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "lib2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "lib3",
|
|
|
|
assetPackages: []string{
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib3/android_common/aapt2/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib4/android_common/assets.zip",
|
2020-01-16 06:15:10 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "lib4",
|
|
|
|
assetFlag: "-A assets_b",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx := testApp(t, bp)
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
m := ctx.ModuleForTests(test.name, "android_common")
|
|
|
|
|
|
|
|
// Check asset flag in aapt2 link flags
|
|
|
|
var aapt2link android.TestingBuildParams
|
|
|
|
if len(test.assetPackages) > 0 {
|
|
|
|
aapt2link = m.Output("aapt2/package-res.apk")
|
|
|
|
} else {
|
|
|
|
aapt2link = m.Output("package-res.apk")
|
|
|
|
}
|
2021-03-29 07:42:57 +08:00
|
|
|
aapt2link = aapt2link
|
2020-01-16 06:15:10 +08:00
|
|
|
aapt2Flags := aapt2link.Args["flags"]
|
|
|
|
if test.assetFlag != "" {
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringDoesContain(t, "asset flag", aapt2Flags, test.assetFlag)
|
2020-01-16 06:15:10 +08:00
|
|
|
} else {
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringDoesNotContain(t, "aapt2 link flags", aapt2Flags, " -A ")
|
2020-01-16 06:15:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check asset merge rule.
|
|
|
|
if len(test.assetPackages) > 0 {
|
|
|
|
mergeAssets := m.Output("package-res.apk")
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs)
|
2020-01-16 06:15:10 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 06:54:36 +08:00
|
|
|
func TestAppJavaResources(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
sdk_version: "current",
|
|
|
|
java_resources: ["resources/a"],
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "bar",
|
|
|
|
sdk_version: "current",
|
|
|
|
java_resources: ["resources/a"],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
ctx := testApp(t, bp)
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
fooResources := foo.Output("res/foo.jar")
|
|
|
|
fooDexJar := foo.Output("dex-withres/foo.jar")
|
|
|
|
fooDexJarAligned := foo.Output("dex-withres-aligned/foo.jar")
|
|
|
|
fooApk := foo.Rule("combineApk")
|
|
|
|
|
|
|
|
if g, w := fooDexJar.Inputs.Strings(), fooResources.Output.String(); !android.InList(w, g) {
|
|
|
|
t.Errorf("expected resource jar %q in foo dex jar inputs %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := fooDexJarAligned.Input.String(), fooDexJar.Output.String(); g != w {
|
|
|
|
t.Errorf("expected dex jar %q in foo aligned dex jar inputs %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
if g, w := fooApk.Inputs.Strings(), fooDexJarAligned.Output.String(); !android.InList(w, g) {
|
|
|
|
t.Errorf("expected aligned dex jar %q in foo apk inputs %q", w, g)
|
|
|
|
}
|
|
|
|
|
|
|
|
bar := ctx.ModuleForTests("bar", "android_common")
|
|
|
|
barResources := bar.Output("res/bar.jar")
|
|
|
|
barApk := bar.Rule("combineApk")
|
|
|
|
|
|
|
|
if g, w := barApk.Inputs.Strings(), barResources.Output.String(); !android.InList(w, g) {
|
|
|
|
t.Errorf("expected resources jar %q in bar apk inputs %q", w, g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 05:15:46 +08:00
|
|
|
func TestAndroidResources(t *testing.T) {
|
2019-02-02 03:44:44 +08:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
enforceRROTargets []string
|
|
|
|
enforceRROExcludedOverlays []string
|
2019-02-14 05:15:46 +08:00
|
|
|
resourceFiles map[string][]string
|
2019-02-02 03:44:44 +08:00
|
|
|
overlayFiles map[string][]string
|
|
|
|
rroDirs map[string][]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no RRO",
|
|
|
|
enforceRROTargets: nil,
|
|
|
|
enforceRROExcludedOverlays: nil,
|
2019-02-14 05:15:46 +08:00
|
|
|
resourceFiles: map[string][]string{
|
|
|
|
"foo": nil,
|
|
|
|
"bar": {"bar/res/res/values/strings.xml"},
|
|
|
|
"lib": nil,
|
|
|
|
"lib2": {"lib2/res/res/values/strings.xml"},
|
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
overlayFiles: map[string][]string{
|
2019-02-14 05:15:46 +08:00
|
|
|
"foo": {
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib2/android_common/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib/android_common/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib3/android_common/package-res.apk",
|
2019-02-01 06:44:30 +08:00
|
|
|
"foo/res/res/values/strings.xml",
|
2019-02-02 03:44:44 +08:00
|
|
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
|
|
|
"device/vendor/blah/overlay/foo/res/values/strings.xml",
|
2019-03-18 23:53:16 +08:00
|
|
|
"product/vendor/blah/overlay/foo/res/values/strings.xml",
|
2019-02-02 03:44:44 +08:00
|
|
|
},
|
2019-02-14 05:15:46 +08:00
|
|
|
"bar": {
|
2019-02-02 03:44:44 +08:00
|
|
|
"device/vendor/blah/static_overlay/bar/res/values/strings.xml",
|
|
|
|
"device/vendor/blah/overlay/bar/res/values/strings.xml",
|
|
|
|
},
|
2019-02-14 05:15:46 +08:00
|
|
|
"lib": {
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib2/android_common/package-res.apk",
|
2019-02-14 05:15:46 +08:00
|
|
|
"lib/res/res/values/strings.xml",
|
|
|
|
"device/vendor/blah/overlay/lib/res/values/strings.xml",
|
|
|
|
},
|
2019-01-24 22:39:19 +08:00
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
rroDirs: map[string][]string{
|
|
|
|
"foo": nil,
|
|
|
|
"bar": nil,
|
2019-01-24 22:39:19 +08:00
|
|
|
},
|
2017-12-01 12:13:19 +08:00
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
{
|
|
|
|
name: "enforce RRO on foo",
|
|
|
|
enforceRROTargets: []string{"foo"},
|
|
|
|
enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
|
2019-02-14 05:15:46 +08:00
|
|
|
resourceFiles: map[string][]string{
|
|
|
|
"foo": nil,
|
|
|
|
"bar": {"bar/res/res/values/strings.xml"},
|
|
|
|
"lib": nil,
|
|
|
|
"lib2": {"lib2/res/res/values/strings.xml"},
|
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
overlayFiles: map[string][]string{
|
2019-02-14 05:15:46 +08:00
|
|
|
"foo": {
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib2/android_common/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib/android_common/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib3/android_common/package-res.apk",
|
2019-02-01 06:44:30 +08:00
|
|
|
"foo/res/res/values/strings.xml",
|
|
|
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
|
|
|
},
|
2019-02-14 05:15:46 +08:00
|
|
|
"bar": {
|
2019-02-02 03:44:44 +08:00
|
|
|
"device/vendor/blah/static_overlay/bar/res/values/strings.xml",
|
|
|
|
"device/vendor/blah/overlay/bar/res/values/strings.xml",
|
|
|
|
},
|
2019-02-14 05:15:46 +08:00
|
|
|
"lib": {
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib2/android_common/package-res.apk",
|
2019-02-14 05:15:46 +08:00
|
|
|
"lib/res/res/values/strings.xml",
|
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
},
|
2019-02-01 03:42:41 +08:00
|
|
|
|
2019-02-02 03:44:44 +08:00
|
|
|
rroDirs: map[string][]string{
|
2019-02-14 05:15:46 +08:00
|
|
|
"foo": {
|
2019-03-18 23:53:16 +08:00
|
|
|
"device:device/vendor/blah/overlay/foo/res",
|
|
|
|
"product:product/vendor/blah/overlay/foo/res",
|
2020-10-07 09:56:10 +08:00
|
|
|
"device:device/vendor/blah/overlay/lib/res",
|
2019-02-01 03:42:41 +08:00
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
"bar": nil,
|
2020-10-07 09:56:10 +08:00
|
|
|
"lib": {"device:device/vendor/blah/overlay/lib/res"},
|
2019-01-24 22:39:19 +08:00
|
|
|
},
|
2017-12-01 12:13:19 +08:00
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
{
|
|
|
|
name: "enforce RRO on all",
|
|
|
|
enforceRROTargets: []string{"*"},
|
|
|
|
enforceRROExcludedOverlays: []string{
|
|
|
|
// Excluding specific apps/res directories also allowed.
|
|
|
|
"device/vendor/blah/static_overlay/foo",
|
|
|
|
"device/vendor/blah/static_overlay/bar/res",
|
|
|
|
},
|
2019-02-14 05:15:46 +08:00
|
|
|
resourceFiles: map[string][]string{
|
|
|
|
"foo": nil,
|
|
|
|
"bar": {"bar/res/res/values/strings.xml"},
|
|
|
|
"lib": nil,
|
|
|
|
"lib2": {"lib2/res/res/values/strings.xml"},
|
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
overlayFiles: map[string][]string{
|
2019-02-14 05:15:46 +08:00
|
|
|
"foo": {
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib2/android_common/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib/android_common/package-res.apk",
|
|
|
|
"out/soong/.intermediates/lib3/android_common/package-res.apk",
|
2019-02-01 06:44:30 +08:00
|
|
|
"foo/res/res/values/strings.xml",
|
|
|
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml",
|
|
|
|
},
|
2019-02-14 05:15:46 +08:00
|
|
|
"bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
|
|
|
|
"lib": {
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/lib2/android_common/package-res.apk",
|
2019-02-14 05:15:46 +08:00
|
|
|
"lib/res/res/values/strings.xml",
|
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
},
|
|
|
|
rroDirs: map[string][]string{
|
2019-02-14 05:15:46 +08:00
|
|
|
"foo": {
|
2019-03-18 23:53:16 +08:00
|
|
|
"device:device/vendor/blah/overlay/foo/res",
|
|
|
|
"product:product/vendor/blah/overlay/foo/res",
|
|
|
|
// Lib dep comes after the direct deps
|
|
|
|
"device:device/vendor/blah/overlay/lib/res",
|
2019-02-01 03:42:41 +08:00
|
|
|
},
|
2019-03-18 23:53:16 +08:00
|
|
|
"bar": {"device:device/vendor/blah/overlay/bar/res"},
|
|
|
|
"lib": {"device:device/vendor/blah/overlay/lib/res"},
|
2019-02-02 03:44:44 +08:00
|
|
|
},
|
2017-12-01 12:13:19 +08:00
|
|
|
},
|
2019-02-02 03:44:44 +08:00
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
|
2019-03-18 23:53:16 +08:00
|
|
|
deviceResourceOverlays := []string{
|
2017-12-01 12:13:19 +08:00
|
|
|
"device/vendor/blah/overlay",
|
|
|
|
"device/vendor/blah/overlay2",
|
|
|
|
"device/vendor/blah/static_overlay",
|
|
|
|
}
|
|
|
|
|
2019-03-18 23:53:16 +08:00
|
|
|
productResourceOverlays := []string{
|
|
|
|
"product/vendor/blah/overlay",
|
|
|
|
}
|
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
fs := android.MockFS{
|
2017-12-01 12:13:19 +08:00
|
|
|
"foo/res/res/values/strings.xml": nil,
|
|
|
|
"bar/res/res/values/strings.xml": nil,
|
2019-02-01 06:44:30 +08:00
|
|
|
"lib/res/res/values/strings.xml": nil,
|
2019-02-14 05:15:46 +08:00
|
|
|
"lib2/res/res/values/strings.xml": nil,
|
2017-12-01 12:13:19 +08:00
|
|
|
"device/vendor/blah/overlay/foo/res/values/strings.xml": nil,
|
|
|
|
"device/vendor/blah/overlay/bar/res/values/strings.xml": nil,
|
2019-02-01 06:44:30 +08:00
|
|
|
"device/vendor/blah/overlay/lib/res/values/strings.xml": nil,
|
2017-12-01 12:13:19 +08:00
|
|
|
"device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil,
|
|
|
|
"device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil,
|
|
|
|
"device/vendor/blah/overlay2/res/values/strings.xml": nil,
|
2019-03-18 23:53:16 +08:00
|
|
|
"product/vendor/blah/overlay/foo/res/values/strings.xml": nil,
|
2017-12-01 12:13:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bp := `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2017-12-01 12:13:19 +08:00
|
|
|
resource_dirs: ["foo/res"],
|
2019-03-18 23:53:16 +08:00
|
|
|
static_libs: ["lib", "lib3"],
|
2017-12-01 12:13:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "bar",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2017-12-01 12:13:19 +08:00
|
|
|
resource_dirs: ["bar/res"],
|
|
|
|
}
|
2019-02-01 06:44:30 +08:00
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib",
|
2019-11-01 14:28:00 +08:00
|
|
|
sdk_version: "current",
|
2019-02-01 06:44:30 +08:00
|
|
|
resource_dirs: ["lib/res"],
|
2019-02-14 05:15:46 +08:00
|
|
|
static_libs: ["lib2"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib2",
|
2019-11-01 14:28:00 +08:00
|
|
|
sdk_version: "current",
|
2019-02-14 05:15:46 +08:00
|
|
|
resource_dirs: ["lib2/res"],
|
2019-02-01 06:44:30 +08:00
|
|
|
}
|
2019-03-18 23:53:16 +08:00
|
|
|
|
|
|
|
// This library has the same resources as lib (should not lead to dupe RROs)
|
|
|
|
android_library {
|
|
|
|
name: "lib3",
|
2019-11-01 14:28:00 +08:00
|
|
|
sdk_version: "current",
|
2019-03-18 23:53:16 +08:00
|
|
|
resource_dirs: ["lib/res"]
|
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
`
|
|
|
|
|
2019-02-02 03:44:44 +08:00
|
|
|
for _, testCase := range testCases {
|
2017-12-01 12:13:19 +08:00
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
PrepareForTestWithOverlayBuildComponents,
|
|
|
|
fs.AddToFixture(),
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.DeviceResourceOverlays = deviceResourceOverlays
|
|
|
|
variables.ProductResourceOverlays = productResourceOverlays
|
|
|
|
if testCase.enforceRROTargets != nil {
|
|
|
|
variables.EnforceRROTargets = testCase.enforceRROTargets
|
|
|
|
}
|
|
|
|
if testCase.enforceRROExcludedOverlays != nil {
|
|
|
|
variables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, bp)
|
2017-12-01 12:13:19 +08:00
|
|
|
|
2019-02-14 05:15:46 +08:00
|
|
|
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
|
|
|
|
for _, o := range list {
|
|
|
|
res := module.MaybeOutput(o)
|
|
|
|
if res.Rule != nil {
|
|
|
|
// If the overlay is compiled as part of this module (i.e. a .arsc.flat file),
|
|
|
|
// verify the inputs to the .arsc.flat rule.
|
|
|
|
files = append(files, res.Inputs.Strings()...)
|
|
|
|
} else {
|
|
|
|
// Otherwise, verify the full path to the output of the other module
|
|
|
|
files = append(files, o)
|
2019-01-31 00:03:37 +08:00
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
}
|
2019-02-14 05:15:46 +08:00
|
|
|
return files
|
|
|
|
}
|
|
|
|
|
|
|
|
getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) {
|
2021-03-23 01:31:52 +08:00
|
|
|
module := result.ModuleForTests(moduleName, "android_common")
|
2019-02-14 05:15:46 +08:00
|
|
|
resourceList := module.MaybeOutput("aapt2/res.list")
|
|
|
|
if resourceList.Rule != nil {
|
2021-03-23 01:31:52 +08:00
|
|
|
resourceFiles = resourceListToFiles(module, android.PathsRelativeToTop(resourceList.Inputs))
|
2019-02-14 05:15:46 +08:00
|
|
|
}
|
|
|
|
overlayList := module.MaybeOutput("aapt2/overlay.list")
|
|
|
|
if overlayList.Rule != nil {
|
2021-03-23 01:31:52 +08:00
|
|
|
overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs))
|
2019-02-14 05:15:46 +08:00
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
|
2019-03-18 23:53:16 +08:00
|
|
|
for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() {
|
|
|
|
var prefix string
|
|
|
|
if d.overlayType == device {
|
|
|
|
prefix = "device:"
|
|
|
|
} else if d.overlayType == product {
|
|
|
|
prefix = "product:"
|
|
|
|
} else {
|
|
|
|
t.Fatalf("Unexpected overlayType %d", d.overlayType)
|
|
|
|
}
|
2021-03-23 01:31:52 +08:00
|
|
|
rroDirs = append(rroDirs, prefix+android.PathRelativeToTop(d.path))
|
2019-03-18 23:53:16 +08:00
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
|
2019-02-14 05:15:46 +08:00
|
|
|
return resourceFiles, overlayFiles, rroDirs
|
2017-12-01 12:13:19 +08:00
|
|
|
}
|
|
|
|
|
2019-02-14 05:15:46 +08:00
|
|
|
modules := []string{"foo", "bar", "lib", "lib2"}
|
|
|
|
for _, module := range modules {
|
|
|
|
resourceFiles, overlayFiles, rroDirs := getResources(module)
|
2017-12-01 12:13:19 +08:00
|
|
|
|
2019-02-14 05:15:46 +08:00
|
|
|
if !reflect.DeepEqual(resourceFiles, testCase.resourceFiles[module]) {
|
|
|
|
t.Errorf("expected %s resource files:\n %#v\n got:\n %#v",
|
|
|
|
module, testCase.resourceFiles[module], resourceFiles)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[module]) {
|
2019-01-24 22:39:19 +08:00
|
|
|
t.Errorf("expected %s overlay files:\n %#v\n got:\n %#v",
|
2019-02-14 05:15:46 +08:00
|
|
|
module, testCase.overlayFiles[module], overlayFiles)
|
2019-01-24 22:39:19 +08:00
|
|
|
}
|
2019-02-14 05:15:46 +08:00
|
|
|
if !reflect.DeepEqual(rroDirs, testCase.rroDirs[module]) {
|
2019-01-24 22:39:19 +08:00
|
|
|
t.Errorf("expected %s rroDirs: %#v\n got:\n %#v",
|
2019-02-14 05:15:46 +08:00
|
|
|
module, testCase.rroDirs[module], rroDirs)
|
2019-01-24 22:39:19 +08:00
|
|
|
}
|
2017-12-01 12:13:19 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 02:06:47 +08:00
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
func checkSdkVersion(t *testing.T, result *android.TestResult, expectedSdkVersion string) {
|
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
2020-08-06 22:00:37 +08:00
|
|
|
link := foo.Output("package-res.apk")
|
|
|
|
linkFlags := strings.Split(link.Args["flags"], " ")
|
|
|
|
min := android.IndexList("--min-sdk-version", linkFlags)
|
|
|
|
target := android.IndexList("--target-sdk-version", linkFlags)
|
|
|
|
|
|
|
|
if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 {
|
|
|
|
t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags)
|
|
|
|
}
|
|
|
|
|
|
|
|
gotMinSdkVersion := linkFlags[min+1]
|
|
|
|
gotTargetSdkVersion := linkFlags[target+1]
|
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
android.AssertStringEquals(t, "incorrect --min-sdk-version", expectedSdkVersion, gotMinSdkVersion)
|
2020-08-06 22:00:37 +08:00
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
android.AssertStringEquals(t, "incorrect --target-sdk-version", expectedSdkVersion, gotTargetSdkVersion)
|
2020-08-06 22:00:37 +08:00
|
|
|
}
|
|
|
|
|
2018-04-19 02:06:47 +08:00
|
|
|
func TestAppSdkVersion(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
sdkVersion string
|
|
|
|
platformSdkInt int
|
|
|
|
platformSdkCodename string
|
|
|
|
platformSdkFinal bool
|
|
|
|
expectedMinSdkVersion string
|
2019-07-11 14:54:27 +08:00
|
|
|
platformApis bool
|
2020-07-24 08:32:15 +08:00
|
|
|
activeCodenames []string
|
2018-04-19 02:06:47 +08:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "current final SDK",
|
|
|
|
sdkVersion: "current",
|
|
|
|
platformSdkInt: 27,
|
|
|
|
platformSdkCodename: "REL",
|
|
|
|
platformSdkFinal: true,
|
|
|
|
expectedMinSdkVersion: "27",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "current non-final SDK",
|
|
|
|
sdkVersion: "current",
|
|
|
|
platformSdkInt: 27,
|
|
|
|
platformSdkCodename: "OMR1",
|
|
|
|
platformSdkFinal: false,
|
|
|
|
expectedMinSdkVersion: "OMR1",
|
2020-07-24 08:32:15 +08:00
|
|
|
activeCodenames: []string{"OMR1"},
|
2018-04-19 02:06:47 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "default final SDK",
|
|
|
|
sdkVersion: "",
|
2019-07-11 14:54:27 +08:00
|
|
|
platformApis: true,
|
2018-04-19 02:06:47 +08:00
|
|
|
platformSdkInt: 27,
|
|
|
|
platformSdkCodename: "REL",
|
|
|
|
platformSdkFinal: true,
|
|
|
|
expectedMinSdkVersion: "27",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "default non-final SDK",
|
|
|
|
sdkVersion: "",
|
2019-07-11 14:54:27 +08:00
|
|
|
platformApis: true,
|
2018-04-19 02:06:47 +08:00
|
|
|
platformSdkInt: 27,
|
|
|
|
platformSdkCodename: "OMR1",
|
|
|
|
platformSdkFinal: false,
|
|
|
|
expectedMinSdkVersion: "OMR1",
|
2020-07-24 08:32:15 +08:00
|
|
|
activeCodenames: []string{"OMR1"},
|
2018-04-19 02:06:47 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "14",
|
|
|
|
sdkVersion: "14",
|
|
|
|
expectedMinSdkVersion: "14",
|
2020-07-24 08:32:15 +08:00
|
|
|
platformSdkCodename: "S",
|
|
|
|
activeCodenames: []string{"S"},
|
2018-04-19 02:06:47 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, moduleType := range []string{"android_app", "android_library"} {
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(moduleType+" "+test.name, func(t *testing.T) {
|
2019-07-11 14:54:27 +08:00
|
|
|
platformApiProp := ""
|
|
|
|
if test.platformApis {
|
|
|
|
platformApiProp = "platform_apis: true,"
|
|
|
|
}
|
2018-04-19 02:06:47 +08:00
|
|
|
bp := fmt.Sprintf(`%s {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "%s",
|
2019-07-11 14:54:27 +08:00
|
|
|
%s
|
|
|
|
}`, moduleType, test.sdkVersion, platformApiProp)
|
2018-04-19 02:06:47 +08:00
|
|
|
|
2021-03-22 23:36:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
2021-03-14 08:36:50 +08:00
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.Platform_sdk_version = &test.platformSdkInt
|
|
|
|
variables.Platform_sdk_codename = &test.platformSdkCodename
|
|
|
|
variables.Platform_version_active_codenames = test.activeCodenames
|
|
|
|
variables.Platform_sdk_final = &test.platformSdkFinal
|
|
|
|
}),
|
2021-03-13 10:36:00 +08:00
|
|
|
FixtureWithPrebuiltApis(map[string][]string{
|
|
|
|
"14": {"foo"},
|
|
|
|
}),
|
2021-03-14 08:36:50 +08:00
|
|
|
).RunTestWithBp(t, bp)
|
2018-04-19 02:06:47 +08:00
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
checkSdkVersion(t, result, test.expectedMinSdkVersion)
|
2020-08-06 22:00:37 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 02:06:47 +08:00
|
|
|
|
2020-08-06 22:00:37 +08:00
|
|
|
func TestVendorAppSdkVersion(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
sdkVersion string
|
|
|
|
platformSdkInt int
|
|
|
|
platformSdkCodename string
|
|
|
|
platformSdkFinal bool
|
|
|
|
deviceCurrentApiLevelForVendorModules string
|
|
|
|
expectedMinSdkVersion string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "current final SDK",
|
|
|
|
sdkVersion: "current",
|
|
|
|
platformSdkInt: 29,
|
|
|
|
platformSdkCodename: "REL",
|
|
|
|
platformSdkFinal: true,
|
|
|
|
deviceCurrentApiLevelForVendorModules: "29",
|
|
|
|
expectedMinSdkVersion: "29",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "current final SDK",
|
|
|
|
sdkVersion: "current",
|
|
|
|
platformSdkInt: 29,
|
|
|
|
platformSdkCodename: "REL",
|
|
|
|
platformSdkFinal: true,
|
|
|
|
deviceCurrentApiLevelForVendorModules: "28",
|
|
|
|
expectedMinSdkVersion: "28",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "current final SDK",
|
|
|
|
sdkVersion: "current",
|
|
|
|
platformSdkInt: 29,
|
|
|
|
platformSdkCodename: "Q",
|
|
|
|
platformSdkFinal: false,
|
|
|
|
deviceCurrentApiLevelForVendorModules: "28",
|
|
|
|
expectedMinSdkVersion: "28",
|
|
|
|
},
|
|
|
|
}
|
2018-04-19 02:06:47 +08:00
|
|
|
|
2020-08-06 22:00:37 +08:00
|
|
|
for _, moduleType := range []string{"android_app", "android_library"} {
|
|
|
|
for _, sdkKind := range []string{"", "system_"} {
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(moduleType+" "+test.name, func(t *testing.T) {
|
|
|
|
bp := fmt.Sprintf(`%s {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "%s%s",
|
|
|
|
vendor: true,
|
|
|
|
}`, moduleType, sdkKind, test.sdkVersion)
|
|
|
|
|
2021-03-22 23:36:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
2021-03-14 08:36:50 +08:00
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.Platform_sdk_version = &test.platformSdkInt
|
|
|
|
variables.Platform_sdk_codename = &test.platformSdkCodename
|
|
|
|
variables.Platform_sdk_final = &test.platformSdkFinal
|
|
|
|
variables.DeviceCurrentApiLevelForVendorModules = &test.deviceCurrentApiLevelForVendorModules
|
|
|
|
variables.DeviceSystemSdkVersions = []string{"28", "29"}
|
|
|
|
}),
|
2021-03-13 10:36:00 +08:00
|
|
|
FixtureWithPrebuiltApis(map[string][]string{
|
|
|
|
"28": {"foo"},
|
|
|
|
"29": {"foo"},
|
|
|
|
"current": {"foo"},
|
|
|
|
}),
|
2021-03-14 08:36:50 +08:00
|
|
|
).RunTestWithBp(t, bp)
|
|
|
|
|
|
|
|
checkSdkVersion(t, result, test.expectedMinSdkVersion)
|
2020-08-06 22:00:37 +08:00
|
|
|
})
|
|
|
|
}
|
2018-04-19 02:06:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 13:03:40 +08:00
|
|
|
|
2019-06-12 20:25:22 +08:00
|
|
|
func TestJNIABI(t *testing.T) {
|
2019-07-18 02:15:09 +08:00
|
|
|
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
2019-06-12 20:25:22 +08:00
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
system_shared_libs: [],
|
2020-04-08 00:50:32 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test",
|
|
|
|
sdk_version: "core_platform",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test_first",
|
|
|
|
sdk_version: "core_platform",
|
|
|
|
compile_multilib: "first",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test_both",
|
|
|
|
sdk_version: "core_platform",
|
|
|
|
compile_multilib: "both",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test_32",
|
|
|
|
sdk_version: "core_platform",
|
|
|
|
compile_multilib: "32",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test_64",
|
|
|
|
sdk_version: "core_platform",
|
|
|
|
compile_multilib: "64",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
abis []string
|
|
|
|
}{
|
|
|
|
{"test", []string{"arm64-v8a"}},
|
|
|
|
{"test_first", []string{"arm64-v8a"}},
|
|
|
|
{"test_both", []string{"arm64-v8a", "armeabi-v7a"}},
|
|
|
|
{"test_32", []string{"armeabi-v7a"}},
|
|
|
|
{"test_64", []string{"arm64-v8a"}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
app := ctx.ModuleForTests(test.name, "android_common")
|
|
|
|
jniLibZip := app.Output("jnilibs.zip")
|
|
|
|
var abis []string
|
|
|
|
args := strings.Fields(jniLibZip.Args["jarArgs"])
|
|
|
|
for i := 0; i < len(args); i++ {
|
|
|
|
if args[i] == "-P" {
|
|
|
|
abis = append(abis, filepath.Base(args[i+1]))
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(abis, test.abis) {
|
|
|
|
t.Errorf("want abis %v, got %v", test.abis, abis)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:44:45 +08:00
|
|
|
func TestAppSdkVersionByPartition(t *testing.T) {
|
|
|
|
testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
vendor: true,
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
for _, enforce := range []bool{true, false} {
|
|
|
|
bp := `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
product_specific: true,
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
`
|
2019-12-14 12:41:13 +08:00
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
errorHandler := android.FixtureExpectsNoErrors
|
2019-10-29 14:44:45 +08:00
|
|
|
if enforce {
|
2021-03-23 01:31:52 +08:00
|
|
|
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern("sdk_version must have a value when the module is located at vendor or product")
|
2019-10-29 14:44:45 +08:00
|
|
|
}
|
2021-03-23 01:31:52 +08:00
|
|
|
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
|
|
|
|
}),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(errorHandler).
|
|
|
|
RunTestWithBp(t, bp)
|
2019-10-29 14:44:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 20:25:22 +08:00
|
|
|
func TestJNIPackaging(t *testing.T) {
|
2019-07-18 02:15:09 +08:00
|
|
|
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
2019-06-12 20:25:22 +08:00
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-02-16 02:38:00 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "app",
|
|
|
|
jni_libs: ["libjni"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "app_noembed",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
use_embedded_native_libs: false,
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "app_embed",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
use_embedded_native_libs: true,
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test",
|
2020-04-08 00:50:32 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "test_noembed",
|
2020-04-08 00:50:32 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
jni_libs: ["libjni"],
|
|
|
|
use_embedded_native_libs: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test_helper_app {
|
|
|
|
name: "test_helper",
|
2020-04-08 00:50:32 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
jni_libs: ["libjni"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test_helper_app {
|
|
|
|
name: "test_helper_noembed",
|
2020-04-08 00:50:32 +08:00
|
|
|
sdk_version: "current",
|
2019-06-12 20:25:22 +08:00
|
|
|
jni_libs: ["libjni"],
|
|
|
|
use_embedded_native_libs: false,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
packaged bool
|
|
|
|
compressed bool
|
|
|
|
}{
|
|
|
|
{"app", false, false},
|
|
|
|
{"app_noembed", false, false},
|
|
|
|
{"app_embed", true, false},
|
|
|
|
{"test", true, false},
|
|
|
|
{"test_noembed", true, true},
|
|
|
|
{"test_helper", true, false},
|
|
|
|
{"test_helper_noembed", true, true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
app := ctx.ModuleForTests(test.name, "android_common")
|
|
|
|
jniLibZip := app.MaybeOutput("jnilibs.zip")
|
|
|
|
if g, w := (jniLibZip.Rule != nil), test.packaged; g != w {
|
|
|
|
t.Errorf("expected jni packaged %v, got %v", w, g)
|
|
|
|
}
|
2019-03-27 01:51:39 +08:00
|
|
|
|
2019-06-12 20:25:22 +08:00
|
|
|
if jniLibZip.Rule != nil {
|
|
|
|
if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w {
|
|
|
|
t.Errorf("expected jni compressed %v, got %v", w, g)
|
|
|
|
}
|
2020-04-08 00:50:32 +08:00
|
|
|
|
|
|
|
if !strings.Contains(jniLibZip.Implicits[0].String(), "_sdk_") {
|
|
|
|
t.Errorf("expected input %q to use sdk variant", jniLibZip.Implicits[0].String())
|
|
|
|
}
|
2019-06-12 20:25:22 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-03-27 01:51:39 +08:00
|
|
|
}
|
|
|
|
|
2020-05-09 02:20:24 +08:00
|
|
|
func TestJNISDK(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "app_platform",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
platform_apis: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "app_sdk",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "app_force_platform",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
sdk_version: "current",
|
|
|
|
jni_uses_platform_apis: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "app_force_sdk",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
platform_apis: true,
|
|
|
|
jni_uses_sdk_apis: true,
|
|
|
|
}
|
2020-05-14 02:05:02 +08:00
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libvendorjni",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
vendor: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "app_vendor",
|
|
|
|
jni_libs: ["libvendorjni"],
|
|
|
|
sdk_version: "current",
|
|
|
|
vendor: true,
|
|
|
|
}
|
2020-05-09 02:20:24 +08:00
|
|
|
`)
|
|
|
|
|
|
|
|
testCases := []struct {
|
2020-05-14 02:05:02 +08:00
|
|
|
name string
|
|
|
|
sdkJNI bool
|
|
|
|
vendorJNI bool
|
2020-05-09 02:20:24 +08:00
|
|
|
}{
|
2020-05-14 02:05:02 +08:00
|
|
|
{name: "app_platform"},
|
|
|
|
{name: "app_sdk", sdkJNI: true},
|
|
|
|
{name: "app_force_platform"},
|
|
|
|
{name: "app_force_sdk", sdkJNI: true},
|
|
|
|
{name: "app_vendor", vendorJNI: true},
|
2020-05-09 02:20:24 +08:00
|
|
|
}
|
|
|
|
|
2020-05-14 02:05:02 +08:00
|
|
|
platformJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared").
|
|
|
|
Output("libjni.so").Output.String()
|
|
|
|
sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").
|
|
|
|
Output("libjni.so").Output.String()
|
|
|
|
vendorJNI := ctx.ModuleForTests("libvendorjni", "android_arm64_armv8-a_shared").
|
|
|
|
Output("libvendorjni.so").Output.String()
|
|
|
|
|
2020-05-09 02:20:24 +08:00
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
app := ctx.ModuleForTests(test.name, "android_common")
|
|
|
|
|
|
|
|
jniLibZip := app.MaybeOutput("jnilibs.zip")
|
|
|
|
if len(jniLibZip.Implicits) != 1 {
|
|
|
|
t.Fatalf("expected exactly one jni library, got %q", jniLibZip.Implicits.Strings())
|
|
|
|
}
|
|
|
|
gotJNI := jniLibZip.Implicits[0].String()
|
|
|
|
|
|
|
|
if test.sdkJNI {
|
|
|
|
if gotJNI != sdkJNI {
|
|
|
|
t.Errorf("expected SDK JNI library %q, got %q", sdkJNI, gotJNI)
|
|
|
|
}
|
2020-05-14 02:05:02 +08:00
|
|
|
} else if test.vendorJNI {
|
|
|
|
if gotJNI != vendorJNI {
|
|
|
|
t.Errorf("expected platform JNI library %q, got %q", vendorJNI, gotJNI)
|
|
|
|
}
|
2020-05-09 02:20:24 +08:00
|
|
|
} else {
|
|
|
|
if gotJNI != platformJNI {
|
|
|
|
t.Errorf("expected platform JNI library %q, got %q", platformJNI, gotJNI)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("jni_uses_platform_apis_error", func(t *testing.T) {
|
|
|
|
testJavaError(t, `jni_uses_platform_apis: can only be set for modules that set sdk_version`, `
|
|
|
|
android_test {
|
|
|
|
name: "app_platform",
|
|
|
|
platform_apis: true,
|
|
|
|
jni_uses_platform_apis: true,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("jni_uses_sdk_apis_error", func(t *testing.T) {
|
|
|
|
testJavaError(t, `jni_uses_sdk_apis: can only be set for modules that do not set sdk_version`, `
|
|
|
|
android_test {
|
|
|
|
name: "app_sdk",
|
|
|
|
sdk_version: "current",
|
|
|
|
jni_uses_sdk_apis: true,
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-19 06:27:16 +08:00
|
|
|
func TestCertificates(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
certificateOverride string
|
2020-05-08 04:24:05 +08:00
|
|
|
expectedLineage string
|
|
|
|
expectedCertificate string
|
2019-01-19 06:27:16 +08:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "default",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
certificateOverride: "",
|
2020-05-08 04:24:05 +08:00
|
|
|
expectedLineage: "",
|
|
|
|
expectedCertificate: "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8",
|
2019-01-19 06:27:16 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "module certificate property",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
certificate: ":new_certificate",
|
|
|
|
sdk_version: "current",
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "new_certificate",
|
2020-05-09 02:20:24 +08:00
|
|
|
certificate: "cert/new_cert",
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
certificateOverride: "",
|
2020-05-08 04:24:05 +08:00
|
|
|
expectedLineage: "",
|
|
|
|
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
2019-01-19 06:27:16 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "path certificate property",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
certificate: "expiredkey",
|
|
|
|
sdk_version: "current",
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
certificateOverride: "",
|
2020-05-08 04:24:05 +08:00
|
|
|
expectedLineage: "",
|
|
|
|
expectedCertificate: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
2019-01-19 06:27:16 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "certificate overrides",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
certificate: "expiredkey",
|
|
|
|
sdk_version: "current",
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "new_certificate",
|
2020-05-09 02:20:24 +08:00
|
|
|
certificate: "cert/new_cert",
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
certificateOverride: "foo:new_certificate",
|
2020-05-08 04:24:05 +08:00
|
|
|
expectedLineage: "",
|
|
|
|
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "certificate lineage",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
certificate: ":new_certificate",
|
|
|
|
lineage: "lineage.bin",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "new_certificate",
|
|
|
|
certificate: "cert/new_cert",
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
certificateOverride: "",
|
|
|
|
expectedLineage: "--lineage lineage.bin",
|
|
|
|
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
2019-01-19 06:27:16 +08:00
|
|
|
},
|
2021-03-10 07:02:31 +08:00
|
|
|
{
|
|
|
|
name: "lineage from filegroup",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
certificate: ":new_certificate",
|
|
|
|
lineage: ":lineage_bin",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "new_certificate",
|
|
|
|
certificate: "cert/new_cert",
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "lineage_bin",
|
|
|
|
srcs: ["lineage.bin"],
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
certificateOverride: "",
|
|
|
|
expectedLineage: "--lineage lineage.bin",
|
|
|
|
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
|
|
|
},
|
2019-01-19 06:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
if test.certificateOverride != "" {
|
|
|
|
variables.CertificateOverrides = []string{test.certificateOverride}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, test.bp)
|
2019-01-19 06:27:16 +08:00
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
2019-01-19 06:27:16 +08:00
|
|
|
|
|
|
|
signapk := foo.Output("foo.apk")
|
2020-05-08 04:24:05 +08:00
|
|
|
signCertificateFlags := signapk.Args["certificates"]
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringEquals(t, "certificates flags", test.expectedCertificate, signCertificateFlags)
|
2020-05-08 04:24:05 +08:00
|
|
|
|
|
|
|
signFlags := signapk.Args["flags"]
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringEquals(t, "signing flags", test.expectedLineage, signFlags)
|
2019-01-19 06:27:16 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-01-24 08:27:47 +08:00
|
|
|
|
2020-03-25 11:32:24 +08:00
|
|
|
func TestRequestV4SigningFlag(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "default",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "default",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
v4_signature: false,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expected: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "module certificate property",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
v4_signature: true,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expected: "--enable-v4",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
).RunTestWithBp(t, test.bp)
|
2020-03-25 11:32:24 +08:00
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
2020-03-25 11:32:24 +08:00
|
|
|
|
|
|
|
signapk := foo.Output("foo.apk")
|
|
|
|
signFlags := signapk.Args["flags"]
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringEquals(t, "signing flags", test.expected, signFlags)
|
2020-03-25 11:32:24 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 08:27:47 +08:00
|
|
|
func TestPackageNameOverride(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
packageNameOverride string
|
|
|
|
expected []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "default",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-01-24 08:27:47 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
packageNameOverride: "",
|
|
|
|
expected: []string{
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/foo/android_common/foo.apk",
|
|
|
|
"out/soong/target/product/test_device/system/app/foo/foo.apk",
|
2019-01-24 08:27:47 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "overridden",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-01-24 08:27:47 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
packageNameOverride: "foo:bar",
|
|
|
|
expected: []string{
|
|
|
|
// The package apk should be still be the original name for test dependencies.
|
2021-03-23 01:31:52 +08:00
|
|
|
"out/soong/.intermediates/foo/android_common/bar.apk",
|
|
|
|
"out/soong/target/product/test_device/system/app/bar/bar.apk",
|
2019-01-24 08:27:47 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
if test.packageNameOverride != "" {
|
|
|
|
variables.PackageNameOverrides = []string{test.packageNameOverride}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, test.bp)
|
2019-01-24 08:27:47 +08:00
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
|
|
|
|
|
|
|
outSoongDir := result.Config.BuildDir()
|
2019-01-24 08:27:47 +08:00
|
|
|
|
|
|
|
outputs := foo.AllOutputs()
|
|
|
|
outputMap := make(map[string]bool)
|
|
|
|
for _, o := range outputs {
|
2021-03-23 01:31:52 +08:00
|
|
|
outputMap[android.StringPathRelativeToTop(outSoongDir, o)] = true
|
2019-01-24 08:27:47 +08:00
|
|
|
}
|
|
|
|
for _, e := range test.expected {
|
|
|
|
if _, exist := outputMap[e]; !exist {
|
|
|
|
t.Errorf("Can't find %q in output files.\nAll outputs:%v", e, outputs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-02-28 08:26:28 +08:00
|
|
|
|
|
|
|
func TestInstrumentationTargetOverridden(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-02-28 08:26:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "bar",
|
|
|
|
instrumentation_for: "foo",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-02-28 08:26:28 +08:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, bp)
|
2019-02-28 08:26:28 +08:00
|
|
|
|
2021-03-23 01:31:52 +08:00
|
|
|
bar := result.ModuleForTests("bar", "android_common")
|
2019-02-28 08:26:28 +08:00
|
|
|
res := bar.Output("package-res.apk")
|
|
|
|
aapt2Flags := res.Args["flags"]
|
|
|
|
e := "--rename-instrumentation-target-package org.dandroid.bp"
|
|
|
|
if !strings.Contains(aapt2Flags, e) {
|
|
|
|
t.Errorf("target package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 07:35:54 +08:00
|
|
|
|
|
|
|
func TestOverrideAndroidApp(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(
|
|
|
|
t, `
|
2019-03-01 07:35:54 +08:00
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-03-28 02:17:14 +08:00
|
|
|
certificate: "expiredkey",
|
2019-05-11 06:16:29 +08:00
|
|
|
overrides: ["qux"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-03-01 07:35:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "bar",
|
|
|
|
base: "foo",
|
|
|
|
certificate: ":new_certificate",
|
2020-05-08 04:24:05 +08:00
|
|
|
lineage: "lineage.bin",
|
2020-02-12 09:27:19 +08:00
|
|
|
logging_parent: "bah",
|
2019-03-01 07:35:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "new_certificate",
|
|
|
|
certificate: "cert/new_cert",
|
|
|
|
}
|
2019-03-14 01:13:24 +08:00
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "baz",
|
|
|
|
base: "foo",
|
|
|
|
package_name: "org.dandroid.bp",
|
|
|
|
}
|
2020-06-19 03:44:06 +08:00
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "baz_no_rename_resources",
|
|
|
|
base: "foo",
|
|
|
|
package_name: "org.dandroid.bp",
|
|
|
|
rename_resources_package: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "foo_no_rename_resources",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
certificate: "expiredkey",
|
|
|
|
overrides: ["qux"],
|
|
|
|
rename_resources_package: false,
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "baz_base_no_rename_resources",
|
|
|
|
base: "foo_no_rename_resources",
|
|
|
|
package_name: "org.dandroid.bp",
|
|
|
|
}
|
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "baz_override_base_rename_resources",
|
|
|
|
base: "foo_no_rename_resources",
|
|
|
|
package_name: "org.dandroid.bp",
|
|
|
|
rename_resources_package: true,
|
|
|
|
}
|
2019-03-01 07:35:54 +08:00
|
|
|
`)
|
|
|
|
|
|
|
|
expectedVariants := []struct {
|
2020-06-19 03:44:06 +08:00
|
|
|
name string
|
|
|
|
moduleName string
|
|
|
|
variantName string
|
|
|
|
apkName string
|
|
|
|
apkPath string
|
|
|
|
certFlag string
|
|
|
|
lineageFlag string
|
|
|
|
overrides []string
|
|
|
|
packageFlag string
|
|
|
|
renameResources bool
|
|
|
|
logging_parent string
|
2019-03-01 07:35:54 +08:00
|
|
|
}{
|
|
|
|
{
|
2020-06-19 03:44:06 +08:00
|
|
|
name: "foo",
|
|
|
|
moduleName: "foo",
|
|
|
|
variantName: "android_common",
|
2021-03-23 01:31:52 +08:00
|
|
|
apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk",
|
2020-06-19 03:44:06 +08:00
|
|
|
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
|
|
|
lineageFlag: "",
|
|
|
|
overrides: []string{"qux"},
|
|
|
|
packageFlag: "",
|
|
|
|
renameResources: false,
|
|
|
|
logging_parent: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "foo",
|
|
|
|
moduleName: "bar",
|
|
|
|
variantName: "android_common_bar",
|
2021-03-23 01:31:52 +08:00
|
|
|
apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk",
|
2020-06-19 03:44:06 +08:00
|
|
|
certFlag: "cert/new_cert.x509.pem cert/new_cert.pk8",
|
|
|
|
lineageFlag: "--lineage lineage.bin",
|
|
|
|
overrides: []string{"qux", "foo"},
|
|
|
|
packageFlag: "",
|
|
|
|
renameResources: false,
|
|
|
|
logging_parent: "bah",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "foo",
|
|
|
|
moduleName: "baz",
|
|
|
|
variantName: "android_common_baz",
|
2021-03-23 01:31:52 +08:00
|
|
|
apkPath: "out/soong/target/product/test_device/system/app/baz/baz.apk",
|
2020-06-19 03:44:06 +08:00
|
|
|
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
|
|
|
lineageFlag: "",
|
|
|
|
overrides: []string{"qux", "foo"},
|
|
|
|
packageFlag: "org.dandroid.bp",
|
|
|
|
renameResources: true,
|
|
|
|
logging_parent: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "foo",
|
|
|
|
moduleName: "baz_no_rename_resources",
|
|
|
|
variantName: "android_common_baz_no_rename_resources",
|
2021-03-23 01:31:52 +08:00
|
|
|
apkPath: "out/soong/target/product/test_device/system/app/baz_no_rename_resources/baz_no_rename_resources.apk",
|
2020-06-19 03:44:06 +08:00
|
|
|
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
|
|
|
lineageFlag: "",
|
|
|
|
overrides: []string{"qux", "foo"},
|
|
|
|
packageFlag: "org.dandroid.bp",
|
|
|
|
renameResources: false,
|
|
|
|
logging_parent: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "foo_no_rename_resources",
|
|
|
|
moduleName: "baz_base_no_rename_resources",
|
|
|
|
variantName: "android_common_baz_base_no_rename_resources",
|
2021-03-23 01:31:52 +08:00
|
|
|
apkPath: "out/soong/target/product/test_device/system/app/baz_base_no_rename_resources/baz_base_no_rename_resources.apk",
|
2020-06-19 03:44:06 +08:00
|
|
|
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
|
|
|
lineageFlag: "",
|
|
|
|
overrides: []string{"qux", "foo_no_rename_resources"},
|
|
|
|
packageFlag: "org.dandroid.bp",
|
|
|
|
renameResources: false,
|
|
|
|
logging_parent: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "foo_no_rename_resources",
|
|
|
|
moduleName: "baz_override_base_rename_resources",
|
|
|
|
variantName: "android_common_baz_override_base_rename_resources",
|
2021-03-23 01:31:52 +08:00
|
|
|
apkPath: "out/soong/target/product/test_device/system/app/baz_override_base_rename_resources/baz_override_base_rename_resources.apk",
|
2020-06-19 03:44:06 +08:00
|
|
|
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
|
|
|
|
lineageFlag: "",
|
|
|
|
overrides: []string{"qux", "foo_no_rename_resources"},
|
|
|
|
packageFlag: "org.dandroid.bp",
|
|
|
|
renameResources: true,
|
|
|
|
logging_parent: "",
|
2019-03-01 07:35:54 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, expected := range expectedVariants {
|
2021-03-23 01:31:52 +08:00
|
|
|
variant := result.ModuleForTests(expected.name, expected.variantName)
|
2019-03-01 07:35:54 +08:00
|
|
|
|
|
|
|
// Check the final apk name
|
2021-03-23 01:31:52 +08:00
|
|
|
variant.Output(expected.apkPath)
|
2019-03-01 07:35:54 +08:00
|
|
|
|
|
|
|
// Check the certificate paths
|
2019-11-08 06:14:38 +08:00
|
|
|
signapk := variant.Output(expected.moduleName + ".apk")
|
2020-05-08 04:24:05 +08:00
|
|
|
certFlag := signapk.Args["certificates"]
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringEquals(t, "certificates flags", expected.certFlag, certFlag)
|
2020-05-08 04:24:05 +08:00
|
|
|
|
|
|
|
// Check the lineage flags
|
|
|
|
lineageFlag := signapk.Args["flags"]
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringEquals(t, "signing flags", expected.lineageFlag, lineageFlag)
|
2019-03-01 07:35:54 +08:00
|
|
|
|
2019-03-14 01:13:24 +08:00
|
|
|
// Check if the overrides field values are correctly aggregated.
|
2019-03-01 07:35:54 +08:00
|
|
|
mod := variant.Module().(*AndroidApp)
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.appProperties.Overrides)
|
2019-03-14 01:13:24 +08:00
|
|
|
|
2020-02-12 09:27:19 +08:00
|
|
|
// Test Overridable property: Logging_parent
|
|
|
|
logging_parent := mod.aapt.LoggingParent
|
2021-03-23 01:31:52 +08:00
|
|
|
android.AssertStringEquals(t, "overrides property value for logging parent", expected.logging_parent, logging_parent)
|
2020-02-12 09:27:19 +08:00
|
|
|
|
2020-05-20 03:15:37 +08:00
|
|
|
// Check the package renaming flag, if exists.
|
2019-03-14 01:13:24 +08:00
|
|
|
res := variant.Output("package-res.apk")
|
|
|
|
aapt2Flags := res.Args["flags"]
|
2020-06-19 03:44:06 +08:00
|
|
|
checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag)
|
|
|
|
expectedPackage := expected.packageFlag
|
|
|
|
if !expected.renameResources {
|
|
|
|
expectedPackage = ""
|
2020-05-20 03:15:37 +08:00
|
|
|
}
|
2020-06-19 03:44:06 +08:00
|
|
|
checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expectedPackage)
|
2019-03-01 07:35:54 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-16 00:48:31 +08:00
|
|
|
|
2019-05-11 06:16:29 +08:00
|
|
|
func TestOverrideAndroidAppDependency(t *testing.T) {
|
2019-07-18 02:15:09 +08:00
|
|
|
ctx, _ := testJava(t, `
|
2019-05-11 06:16:29 +08:00
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-11 06:16:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "bar",
|
|
|
|
base: "foo",
|
|
|
|
package_name: "org.dandroid.bp",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
instrumentation_for: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "qux",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
instrumentation_for: "bar",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
// Verify baz, which depends on the overridden module foo, has the correct classpath javac arg.
|
2021-03-29 07:42:57 +08:00
|
|
|
javac := ctx.ModuleForTests("baz", "android_common").Rule("javac")
|
2021-03-23 01:31:52 +08:00
|
|
|
fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar"
|
2019-05-11 06:16:29 +08:00
|
|
|
if !strings.Contains(javac.Args["classpath"], fooTurbine) {
|
|
|
|
t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify qux, which depends on the overriding module bar, has the correct classpath javac arg.
|
2021-03-29 07:42:57 +08:00
|
|
|
javac = ctx.ModuleForTests("qux", "android_common").Rule("javac")
|
2021-03-23 01:31:52 +08:00
|
|
|
barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar"
|
2019-05-11 06:16:29 +08:00
|
|
|
if !strings.Contains(javac.Args["classpath"], barTurbine) {
|
|
|
|
t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:45:58 +08:00
|
|
|
func TestOverrideAndroidTest(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
package_name: "com.android.foo",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "bar",
|
|
|
|
base: "foo",
|
|
|
|
package_name: "com.android.bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "foo_test",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
instrumentation_for: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
override_android_test {
|
|
|
|
name: "bar_test",
|
|
|
|
base: "foo_test",
|
|
|
|
package_name: "com.android.bar.test",
|
|
|
|
instrumentation_for: "bar",
|
|
|
|
instrumentation_target_package: "com.android.bar",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
expectedVariants := []struct {
|
|
|
|
moduleName string
|
|
|
|
variantName string
|
|
|
|
apkPath string
|
|
|
|
overrides []string
|
|
|
|
targetVariant string
|
|
|
|
packageFlag string
|
|
|
|
targetPackageFlag string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
variantName: "android_common",
|
2019-11-22 02:41:00 +08:00
|
|
|
apkPath: "/target/product/test_device/testcases/foo_test/arm64/foo_test.apk",
|
2019-06-06 23:45:58 +08:00
|
|
|
overrides: nil,
|
|
|
|
targetVariant: "android_common",
|
|
|
|
packageFlag: "",
|
|
|
|
targetPackageFlag: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
variantName: "android_common_bar_test",
|
2019-11-22 02:41:00 +08:00
|
|
|
apkPath: "/target/product/test_device/testcases/bar_test/arm64/bar_test.apk",
|
2019-06-06 23:45:58 +08:00
|
|
|
overrides: []string{"foo_test"},
|
|
|
|
targetVariant: "android_common_bar",
|
|
|
|
packageFlag: "com.android.bar.test",
|
|
|
|
targetPackageFlag: "com.android.bar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, expected := range expectedVariants {
|
|
|
|
variant := ctx.ModuleForTests("foo_test", expected.variantName)
|
|
|
|
|
|
|
|
// Check the final apk name
|
2021-03-23 01:31:52 +08:00
|
|
|
variant.Output("out/soong" + expected.apkPath)
|
2019-06-06 23:45:58 +08:00
|
|
|
|
|
|
|
// Check if the overrides field values are correctly aggregated.
|
|
|
|
mod := variant.Module().(*AndroidTest)
|
|
|
|
if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) {
|
|
|
|
t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
|
|
|
|
expected.overrides, mod.appProperties.Overrides)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides.
|
2021-03-29 07:42:57 +08:00
|
|
|
javac := variant.Rule("javac")
|
2021-03-23 01:31:52 +08:00
|
|
|
turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar")
|
2019-06-06 23:45:58 +08:00
|
|
|
if !strings.Contains(javac.Args["classpath"], turbine) {
|
|
|
|
t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check aapt2 flags.
|
|
|
|
res := variant.Output("package-res.apk")
|
|
|
|
aapt2Flags := res.Args["flags"]
|
|
|
|
checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag)
|
2020-06-19 03:44:06 +08:00
|
|
|
checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expected.packageFlag)
|
2019-06-06 23:45:58 +08:00
|
|
|
checkAapt2LinkFlag(t, aapt2Flags, "rename-instrumentation-target-package", expected.targetPackageFlag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 02:27:18 +08:00
|
|
|
func TestAndroidTest_FixTestConfig(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
package_name: "com.android.foo",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "foo_test",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
instrumentation_for: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "bar_test",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
package_name: "com.android.bar.test",
|
|
|
|
instrumentation_for: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
override_android_test {
|
|
|
|
name: "baz_test",
|
|
|
|
base: "foo_test",
|
|
|
|
package_name: "com.android.baz.test",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
moduleName string
|
|
|
|
variantName string
|
|
|
|
expectedFlags []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleName: "foo_test",
|
|
|
|
variantName: "android_common",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleName: "bar_test",
|
|
|
|
variantName: "android_common",
|
|
|
|
expectedFlags: []string{
|
2021-03-23 01:31:52 +08:00
|
|
|
"--manifest out/soong/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml",
|
2020-01-15 02:27:18 +08:00
|
|
|
"--package-name com.android.bar.test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleName: "foo_test",
|
|
|
|
variantName: "android_common_baz_test",
|
|
|
|
expectedFlags: []string{
|
2021-03-23 01:31:52 +08:00
|
|
|
"--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
|
2020-01-15 02:27:18 +08:00
|
|
|
"--package-name com.android.baz.test",
|
|
|
|
"--test-file-name baz_test.apk",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
variant := ctx.ModuleForTests(test.moduleName, test.variantName)
|
2021-03-29 07:42:57 +08:00
|
|
|
params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml")
|
2020-01-15 02:27:18 +08:00
|
|
|
|
|
|
|
if len(test.expectedFlags) > 0 {
|
|
|
|
if params.Rule == nil {
|
|
|
|
t.Errorf("test_config_fixer was expected to run, but didn't")
|
|
|
|
} else {
|
|
|
|
for _, flag := range test.expectedFlags {
|
|
|
|
if !strings.Contains(params.RuleParams.Command, flag) {
|
|
|
|
t.Errorf("Flag %q was not found in command: %q", flag, params.RuleParams.Command)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if params.Rule != nil {
|
|
|
|
t.Errorf("test_config_fixer was not expected to run, but did: %q", params.RuleParams.Command)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 06:48:44 +08:00
|
|
|
func TestStl(t *testing.T) {
|
2019-07-18 02:15:09 +08:00
|
|
|
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
2019-05-07 06:48:44 +08:00
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
2019-12-18 08:46:18 +08:00
|
|
|
sdk_version: "current",
|
|
|
|
stl: "c++_shared",
|
2019-05-07 06:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "stl",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
compile_multilib: "both",
|
|
|
|
sdk_version: "current",
|
|
|
|
stl: "c++_shared",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test {
|
|
|
|
name: "system",
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
compile_multilib: "both",
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
jnis []string
|
|
|
|
}{
|
|
|
|
{"stl",
|
|
|
|
[]string{
|
|
|
|
"libjni.so",
|
2019-06-05 02:53:47 +08:00
|
|
|
"libc++_shared.so",
|
2019-05-07 06:48:44 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{"system",
|
|
|
|
[]string{
|
|
|
|
"libjni.so",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
app := ctx.ModuleForTests(test.name, "android_common")
|
|
|
|
jniLibZip := app.Output("jnilibs.zip")
|
|
|
|
var jnis []string
|
|
|
|
args := strings.Fields(jniLibZip.Args["jarArgs"])
|
|
|
|
for i := 0; i < len(args); i++ {
|
|
|
|
if args[i] == "-f" {
|
|
|
|
jnis = append(jnis, args[i+1])
|
|
|
|
i += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jnisJoined := strings.Join(jnis, " ")
|
|
|
|
for _, jni := range test.jnis {
|
|
|
|
if !strings.Contains(jnisJoined, jni) {
|
|
|
|
t.Errorf("missing jni %q in %q", jni, jnis)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 03:28:22 +08:00
|
|
|
|
|
|
|
func TestUsesLibraries(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["foo"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-17 03:28:22 +08:00
|
|
|
}
|
|
|
|
|
2020-05-15 17:20:31 +08:00
|
|
|
java_sdk_library {
|
|
|
|
name: "qux",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["qux"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "quuz",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["quuz"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:50:22 +08:00
|
|
|
java_sdk_library {
|
|
|
|
name: "fred",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["fred"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
2019-05-17 03:28:22 +08:00
|
|
|
java_sdk_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["bar"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-17 03:28:22 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 21:58:01 +08:00
|
|
|
java_sdk_library {
|
|
|
|
name: "runtime-library",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "static-runtime-helper",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
libs: ["runtime-library"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
2021-02-26 22:49:07 +08:00
|
|
|
// A library that has to use "provides_uses_lib", because:
|
|
|
|
// - it is not an SDK library
|
|
|
|
// - its library name is different from its module name
|
|
|
|
java_library {
|
|
|
|
name: "non-sdk-lib",
|
|
|
|
provides_uses_lib: "com.non.sdk.lib",
|
|
|
|
installable: true,
|
|
|
|
srcs: ["a.java"],
|
|
|
|
}
|
|
|
|
|
2019-05-17 03:28:22 +08:00
|
|
|
android_app {
|
|
|
|
name: "app",
|
|
|
|
srcs: ["a.java"],
|
2021-02-26 22:49:07 +08:00
|
|
|
libs: [
|
|
|
|
"qux",
|
|
|
|
"quuz.stubs"
|
|
|
|
],
|
2020-12-04 00:50:22 +08:00
|
|
|
static_libs: [
|
|
|
|
"static-runtime-helper",
|
|
|
|
// statically linked component libraries should not pull their SDK libraries,
|
|
|
|
// so "fred" should not be added to class loader context
|
|
|
|
"fred.stubs",
|
|
|
|
],
|
2021-02-26 22:49:07 +08:00
|
|
|
uses_libs: [
|
|
|
|
"foo",
|
|
|
|
"non-sdk-lib"
|
|
|
|
],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-17 03:28:22 +08:00
|
|
|
optional_uses_libs: [
|
|
|
|
"bar",
|
|
|
|
"baz",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_import {
|
|
|
|
name: "prebuilt",
|
|
|
|
apk: "prebuilts/apk/app.apk",
|
|
|
|
certificate: "platform",
|
2021-02-26 22:49:07 +08:00
|
|
|
uses_libs: [
|
|
|
|
"foo",
|
|
|
|
"non-sdk-lib",
|
|
|
|
"android.test.runner"
|
|
|
|
],
|
2019-05-17 03:28:22 +08:00
|
|
|
optional_uses_libs: [
|
|
|
|
"bar",
|
|
|
|
"baz",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-03-22 23:36:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
2021-03-13 10:36:00 +08:00
|
|
|
PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
FixtureWithLastReleaseApis("runtime-library", "foo", "quuz", "qux", "bar", "fred"),
|
2021-03-13 07:04:46 +08:00
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.MissingUsesLibraries = []string{"baz"}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, bp)
|
2019-05-17 03:28:22 +08:00
|
|
|
|
2021-03-13 07:04:46 +08:00
|
|
|
app := result.ModuleForTests("app", "android_common")
|
|
|
|
prebuilt := result.ModuleForTests("prebuilt", "android_common")
|
2019-05-17 03:28:22 +08:00
|
|
|
|
2020-05-15 17:20:31 +08:00
|
|
|
// Test that implicit dependencies on java_sdk_library instances are passed to the manifest.
|
2021-02-26 20:05:11 +08:00
|
|
|
// This should not include explicit `uses_libs`/`optional_uses_libs` entries.
|
|
|
|
actualManifestFixerArgs := app.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
|
|
|
|
expectManifestFixerArgs := `--extract-native-libs=true ` +
|
|
|
|
`--uses-library qux ` +
|
|
|
|
`--uses-library quuz ` +
|
|
|
|
`--uses-library foo ` + // TODO(b/132357300): "foo" should not be passed to manifest_fixer
|
2021-02-26 19:38:21 +08:00
|
|
|
`--uses-library com.non.sdk.lib ` + // TODO(b/132357300): "com.non.sdk.lib" should not be passed to manifest_fixer
|
2021-02-26 20:05:11 +08:00
|
|
|
`--uses-library bar ` + // TODO(b/132357300): "bar" should not be passed to manifest_fixer
|
2021-02-26 19:38:21 +08:00
|
|
|
`--uses-library runtime-library`
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringEquals(t, "manifest_fixer args", expectManifestFixerArgs, actualManifestFixerArgs)
|
2020-05-15 17:20:31 +08:00
|
|
|
|
2021-02-26 20:05:11 +08:00
|
|
|
// Test that all libraries are verified (library order matters).
|
|
|
|
verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command
|
|
|
|
verifyArgs := `--uses-library foo ` +
|
2021-02-26 19:38:21 +08:00
|
|
|
`--uses-library com.non.sdk.lib ` +
|
2021-02-26 20:05:11 +08:00
|
|
|
`--uses-library qux ` +
|
|
|
|
`--uses-library quuz ` +
|
|
|
|
`--uses-library runtime-library ` +
|
|
|
|
`--optional-uses-library bar ` +
|
|
|
|
`--optional-uses-library baz `
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "verify cmd args", verifyCmd, verifyArgs)
|
2019-05-17 03:28:22 +08:00
|
|
|
|
2021-02-26 20:05:11 +08:00
|
|
|
// Test that all libraries are verified for an APK (library order matters).
|
|
|
|
verifyApkCmd := prebuilt.Rule("verify_uses_libraries").RuleParams.Command
|
2021-03-04 00:38:37 +08:00
|
|
|
verifyApkArgs := `--uses-library foo ` +
|
|
|
|
`--uses-library com.non.sdk.lib ` +
|
|
|
|
`--uses-library android.test.runner ` +
|
|
|
|
`--optional-uses-library bar ` +
|
|
|
|
`--optional-uses-library baz `
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "verify apk cmd args", verifyApkCmd, verifyApkArgs)
|
2019-05-17 03:28:22 +08:00
|
|
|
|
2020-10-07 22:17:13 +08:00
|
|
|
// Test that all present libraries are preopted, including implicit SDK dependencies, possibly stubs
|
2021-02-26 20:05:11 +08:00
|
|
|
cmd := app.Rule("dexpreopt").RuleParams.Command
|
2020-10-07 22:17:13 +08:00
|
|
|
w := `--target-context-for-sdk any ` +
|
|
|
|
`PCL[/system/framework/qux.jar]#` +
|
2020-11-03 23:15:46 +08:00
|
|
|
`PCL[/system/framework/quuz.jar]#` +
|
|
|
|
`PCL[/system/framework/foo.jar]#` +
|
2021-02-26 22:49:07 +08:00
|
|
|
`PCL[/system/framework/non-sdk-lib.jar]#` +
|
2020-11-03 23:15:46 +08:00
|
|
|
`PCL[/system/framework/bar.jar]#` +
|
|
|
|
`PCL[/system/framework/runtime-library.jar]`
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "dexpreopt app cmd args", cmd, w)
|
2019-05-17 03:28:22 +08:00
|
|
|
|
2020-10-07 22:05:21 +08:00
|
|
|
// Test conditional context for target SDK version 28.
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "dexpreopt app cmd 28", cmd,
|
|
|
|
`--target-context-for-sdk 28`+
|
|
|
|
` PCL[/system/framework/org.apache.http.legacy.jar] `)
|
2020-10-07 22:05:21 +08:00
|
|
|
|
|
|
|
// Test conditional context for target SDK version 29.
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "dexpreopt app cmd 29", cmd,
|
|
|
|
`--target-context-for-sdk 29`+
|
|
|
|
` PCL[/system/framework/android.hidl.manager-V1.0-java.jar]`+
|
|
|
|
`#PCL[/system/framework/android.hidl.base-V1.0-java.jar] `)
|
2020-10-07 22:05:21 +08:00
|
|
|
|
|
|
|
// Test conditional context for target SDK version 30.
|
2020-10-21 20:20:55 +08:00
|
|
|
// "android.test.mock" is absent because "android.test.runner" is not used.
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "dexpreopt app cmd 30", cmd,
|
|
|
|
`--target-context-for-sdk 30`+
|
|
|
|
` PCL[/system/framework/android.test.base.jar] `)
|
2020-10-07 22:05:21 +08:00
|
|
|
|
2020-08-19 23:32:54 +08:00
|
|
|
cmd = prebuilt.Rule("dexpreopt").RuleParams.Command
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "dexpreopt prebuilt cmd", cmd,
|
|
|
|
`--target-context-for-sdk any`+
|
|
|
|
` PCL[/system/framework/foo.jar]`+
|
|
|
|
`#PCL[/system/framework/non-sdk-lib.jar]`+
|
|
|
|
`#PCL[/system/framework/android.test.runner.jar]`+
|
|
|
|
`#PCL[/system/framework/bar.jar] `)
|
2020-10-07 22:05:21 +08:00
|
|
|
|
|
|
|
// Test conditional context for target SDK version 30.
|
2020-10-21 20:20:55 +08:00
|
|
|
// "android.test.mock" is present because "android.test.runner" is used.
|
2021-03-13 07:04:46 +08:00
|
|
|
android.AssertStringDoesContain(t, "dexpreopt prebuilt cmd 30", cmd,
|
|
|
|
`--target-context-for-sdk 30`+
|
|
|
|
` PCL[/system/framework/android.test.base.jar]`+
|
|
|
|
`#PCL[/system/framework/android.test.mock.jar] `)
|
2019-05-17 03:28:22 +08:00
|
|
|
}
|
2019-05-31 06:51:14 +08:00
|
|
|
|
2021-03-23 00:02:28 +08:00
|
|
|
func TestDexpreoptBcp(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["foo"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["bar"],
|
|
|
|
permitted_packages: ["bar"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "app",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
with bool
|
|
|
|
expect string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "with updatable bcp",
|
|
|
|
with: true,
|
|
|
|
expect: "/system/framework/foo.jar:/system/framework/bar.jar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "without updatable bcp",
|
|
|
|
with: false,
|
|
|
|
expect: "/system/framework/foo.jar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
|
|
|
PrepareForTestWithJavaSdkLibraryFiles,
|
|
|
|
FixtureWithLastReleaseApis("runtime-library", "foo", "bar"),
|
|
|
|
dexpreopt.FixtureSetBootJars("platform:foo"),
|
|
|
|
dexpreopt.FixtureSetUpdatableBootJars("platform:bar"),
|
|
|
|
dexpreopt.FixtureSetPreoptWithUpdatableBcp(test.with),
|
|
|
|
).RunTestWithBp(t, bp)
|
|
|
|
|
|
|
|
app := result.ModuleForTests("app", "android_common")
|
|
|
|
cmd := app.Rule("dexpreopt").RuleParams.Command
|
|
|
|
bcp := " -Xbootclasspath-locations:" + test.expect + " " // space at the end matters
|
|
|
|
android.AssertStringDoesContain(t, "dexpreopt app bcp", cmd, bcp)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 06:51:14 +08:00
|
|
|
func TestCodelessApp(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
noCode bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "normal",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
noCode: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "app without sources",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
noCode: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "app with libraries",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
static_libs: ["lib"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "lib",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
noCode: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "app with sourceless libraries",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
static_libs: ["lib"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "lib",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-05-31 06:51:14 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
// TODO(jungjw): this should probably be true
|
|
|
|
noCode: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
ctx := testApp(t, test.bp)
|
|
|
|
|
|
|
|
foo := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
|
|
|
|
if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode {
|
|
|
|
t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 08:40:56 +08:00
|
|
|
|
|
|
|
func TestEmbedNotice(t *testing.T) {
|
2021-03-23 01:31:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
PrepareForTestWithJavaDefaultModules,
|
|
|
|
cc.PrepareForTestWithCcDefaultModules,
|
|
|
|
genrule.PrepareForTestWithGenRuleBuildComponents,
|
|
|
|
android.MockFS{
|
|
|
|
"APP_NOTICE": nil,
|
|
|
|
"GENRULE_NOTICE": nil,
|
|
|
|
"LIB_NOTICE": nil,
|
|
|
|
"TOOL_NOTICE": nil,
|
|
|
|
}.AddToFixture(),
|
|
|
|
).RunTestWithBp(t, `
|
2019-06-18 08:40:56 +08:00
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
static_libs: ["javalib"],
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
notice: "APP_NOTICE",
|
|
|
|
embed_notices: true,
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-18 08:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// No embed_notice flag
|
|
|
|
android_app {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
jni_libs: ["libjni"],
|
|
|
|
notice: "APP_NOTICE",
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-18 08:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// No NOTICE files
|
|
|
|
android_app {
|
|
|
|
name: "baz",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
embed_notices: true,
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-18 08:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libjni",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
notice: "LIB_NOTICE",
|
2020-02-16 02:38:00 +08:00
|
|
|
sdk_version: "current",
|
2019-06-18 08:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "javalib",
|
|
|
|
srcs: [
|
|
|
|
":gen",
|
|
|
|
],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-18 08:40:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
genrule {
|
|
|
|
name: "gen",
|
|
|
|
tools: ["gentool"],
|
|
|
|
out: ["gen.java"],
|
|
|
|
notice: "GENRULE_NOTICE",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_binary_host {
|
|
|
|
name: "gentool",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
notice: "TOOL_NOTICE",
|
|
|
|
}
|
2021-03-23 01:31:52 +08:00
|
|
|
`)
|
2019-06-18 08:40:56 +08:00
|
|
|
|
|
|
|
// foo has NOTICE files to process, and embed_notices is true.
|
2021-03-23 01:31:52 +08:00
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
2019-06-18 08:40:56 +08:00
|
|
|
// verify merge notices rule.
|
|
|
|
mergeNotices := foo.Rule("mergeNoticesRule")
|
|
|
|
noticeInputs := mergeNotices.Inputs.Strings()
|
|
|
|
// TOOL_NOTICE should be excluded as it's a host module.
|
|
|
|
if len(mergeNotices.Inputs) != 3 {
|
|
|
|
t.Errorf("number of input notice files: expected = 3, actual = %q", noticeInputs)
|
|
|
|
}
|
|
|
|
if !inList("APP_NOTICE", noticeInputs) {
|
|
|
|
t.Errorf("APP_NOTICE is missing from notice files, %q", noticeInputs)
|
|
|
|
}
|
|
|
|
if !inList("LIB_NOTICE", noticeInputs) {
|
|
|
|
t.Errorf("LIB_NOTICE is missing from notice files, %q", noticeInputs)
|
|
|
|
}
|
|
|
|
if !inList("GENRULE_NOTICE", noticeInputs) {
|
|
|
|
t.Errorf("GENRULE_NOTICE is missing from notice files, %q", noticeInputs)
|
|
|
|
}
|
|
|
|
// aapt2 flags should include -A <NOTICE dir> so that its contents are put in the APK's /assets.
|
2021-03-29 07:42:57 +08:00
|
|
|
res := foo.Output("package-res.apk")
|
2019-06-18 08:40:56 +08:00
|
|
|
aapt2Flags := res.Args["flags"]
|
2021-03-23 01:31:52 +08:00
|
|
|
e := "-A out/soong/.intermediates/foo/android_common/NOTICE"
|
|
|
|
android.AssertStringDoesContain(t, "expected.apkPath", aapt2Flags, e)
|
2019-06-18 08:40:56 +08:00
|
|
|
|
|
|
|
// bar has NOTICE files to process, but embed_notices is not set.
|
2021-03-23 01:31:52 +08:00
|
|
|
bar := result.ModuleForTests("bar", "android_common")
|
2021-03-29 07:42:57 +08:00
|
|
|
res = bar.Output("package-res.apk")
|
2019-07-02 08:15:13 +08:00
|
|
|
aapt2Flags = res.Args["flags"]
|
2021-03-23 01:31:52 +08:00
|
|
|
e = "-A out/soong/.intermediates/bar/android_common/NOTICE"
|
|
|
|
android.AssertStringDoesNotContain(t, "bar shouldn't have the asset dir flag for NOTICE", aapt2Flags, e)
|
2019-06-18 08:40:56 +08:00
|
|
|
|
|
|
|
// baz's embed_notice is true, but it doesn't have any NOTICE files.
|
2021-03-23 01:31:52 +08:00
|
|
|
baz := result.ModuleForTests("baz", "android_common")
|
2019-07-02 08:15:13 +08:00
|
|
|
res = baz.Output("package-res.apk")
|
|
|
|
aapt2Flags = res.Args["flags"]
|
2021-03-23 01:31:52 +08:00
|
|
|
e = "-A out/soong/.intermediates/baz/android_common/NOTICE"
|
2019-07-02 08:15:13 +08:00
|
|
|
if strings.Contains(aapt2Flags, e) {
|
|
|
|
t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e)
|
2019-06-18 08:40:56 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 04:35:30 +08:00
|
|
|
|
|
|
|
func TestUncompressDex(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
|
|
|
|
uncompressedPlatform bool
|
|
|
|
uncompressedUnbundled bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "normal",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-26 04:35:30 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
uncompressedPlatform: true,
|
|
|
|
uncompressedUnbundled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "use_embedded_dex",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
use_embedded_dex: true,
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-26 04:35:30 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
uncompressedPlatform: true,
|
|
|
|
uncompressedUnbundled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "privileged",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
privileged: true,
|
|
|
|
srcs: ["a.java"],
|
2019-07-11 14:54:27 +08:00
|
|
|
sdk_version: "current",
|
2019-06-26 04:35:30 +08:00
|
|
|
}
|
|
|
|
`,
|
|
|
|
uncompressedPlatform: true,
|
|
|
|
uncompressedUnbundled: true,
|
|
|
|
},
|
2020-05-21 05:20:28 +08:00
|
|
|
{
|
|
|
|
name: "normal_uncompress_dex_true",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
uncompress_dex: true,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
uncompressedPlatform: true,
|
|
|
|
uncompressedUnbundled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "normal_uncompress_dex_false",
|
|
|
|
bp: `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
uncompress_dex: false,
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
uncompressedPlatform: false,
|
|
|
|
uncompressedUnbundled: false,
|
|
|
|
},
|
2019-06-26 04:35:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test := func(t *testing.T, bp string, want bool, unbundled bool) {
|
|
|
|
t.Helper()
|
|
|
|
|
2021-03-22 23:36:52 +08:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
2021-03-13 10:36:00 +08:00
|
|
|
PrepareForTestWithPrebuiltsOfCurrentApi,
|
2021-03-14 08:36:50 +08:00
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
if unbundled {
|
|
|
|
variables.Unbundled_build = proptools.BoolPtr(true)
|
|
|
|
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, bp)
|
2019-06-26 04:35:30 +08:00
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
foo := result.ModuleForTests("foo", "android_common")
|
2019-06-26 04:35:30 +08:00
|
|
|
dex := foo.Rule("r8")
|
|
|
|
uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0")
|
|
|
|
aligned := foo.MaybeRule("zipalign").Rule != nil
|
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
android.AssertBoolEquals(t, "uncompressed in dex", want, uncompressedInDexJar)
|
2019-06-26 04:35:30 +08:00
|
|
|
|
2021-03-14 08:36:50 +08:00
|
|
|
android.AssertBoolEquals(t, "aligne", want, aligned)
|
2019-06-26 04:35:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testCases {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Run("platform", func(t *testing.T) {
|
|
|
|
test(t, tt.bp, tt.uncompressedPlatform, false)
|
|
|
|
})
|
|
|
|
t.Run("unbundled", func(t *testing.T) {
|
|
|
|
test(t, tt.bp, tt.uncompressedUnbundled, true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 23:45:58 +08:00
|
|
|
|
|
|
|
func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string) {
|
|
|
|
if expectedValue != "" {
|
|
|
|
expectedFlag := "--" + flagName + " " + expectedValue
|
|
|
|
if !strings.Contains(aapt2Flags, expectedFlag) {
|
|
|
|
t.Errorf("%q is missing in aapt2 link flags, %q", expectedFlag, aapt2Flags)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unexpectedFlag := "--" + flagName
|
|
|
|
if strings.Contains(aapt2Flags, unexpectedFlag) {
|
|
|
|
t.Errorf("unexpected flag, %q is found in aapt2 link flags, %q", unexpectedFlag, aapt2Flags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-19 02:33:43 +08:00
|
|
|
|
2020-10-23 05:05:24 +08:00
|
|
|
func TestExportedProguardFlagFiles(t *testing.T) {
|
|
|
|
ctx, _ := testJava(t, `
|
|
|
|
android_app {
|
|
|
|
name: "foo",
|
|
|
|
sdk_version: "current",
|
|
|
|
static_libs: ["lib1"],
|
|
|
|
}
|
|
|
|
|
|
|
|
android_library {
|
|
|
|
name: "lib1",
|
|
|
|
sdk_version: "current",
|
|
|
|
optimize: {
|
|
|
|
proguard_flags_files: ["lib1proguard.cfg"],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
m := ctx.ModuleForTests("foo", "android_common")
|
|
|
|
hasLib1Proguard := false
|
|
|
|
for _, s := range m.Rule("java.r8").Implicits.Strings() {
|
|
|
|
if s == "lib1proguard.cfg" {
|
|
|
|
hasLib1Proguard = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !hasLib1Proguard {
|
|
|
|
t.Errorf("App does not use library proguard config")
|
|
|
|
}
|
|
|
|
}
|