Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// Copyright 2018 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 apex
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-11-06 15:53:07 +08:00
|
|
|
"path"
|
2019-07-17 09:25:41 +08:00
|
|
|
"reflect"
|
2019-10-18 15:26:59 +08:00
|
|
|
"sort"
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-12-19 16:12:36 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
2020-01-13 23:18:16 +08:00
|
|
|
"android/soong/dexpreopt"
|
2019-02-11 10:38:15 +08:00
|
|
|
"android/soong/java"
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
)
|
|
|
|
|
2019-06-19 04:09:13 +08:00
|
|
|
var buildDir string
|
|
|
|
|
2019-08-09 11:57:43 +08:00
|
|
|
// names returns name list from white space separated string
|
|
|
|
func names(s string) (ns []string) {
|
|
|
|
for _, n := range strings.Split(s, " ") {
|
|
|
|
if len(n) > 0 {
|
|
|
|
ns = append(ns, n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
|
|
|
|
t.Helper()
|
|
|
|
ctx, config := testApexContext(t, bp, handlers...)
|
2019-06-27 10:30:33 +08:00
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
|
|
if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, pattern, errs)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
|
|
|
|
t.Helper()
|
|
|
|
ctx, config := testApexContext(t, bp, handlers...)
|
2019-06-27 10:30:33 +08:00
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
android.FailIfErrored(t, errs)
|
2019-07-17 09:25:41 +08:00
|
|
|
return ctx, config
|
2019-06-27 10:30:33 +08:00
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
type testCustomizer func(fs map[string][]byte, config android.Config)
|
|
|
|
|
|
|
|
func withFiles(files map[string][]byte) testCustomizer {
|
|
|
|
return func(fs map[string][]byte, config android.Config) {
|
|
|
|
for k, v := range files {
|
|
|
|
fs[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
|
|
|
|
return func(fs map[string][]byte, config android.Config) {
|
|
|
|
for k, v := range targets {
|
|
|
|
config.Targets[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:51:07 +08:00
|
|
|
func withManifestPackageNameOverrides(specs []string) testCustomizer {
|
|
|
|
return func(fs map[string][]byte, config android.Config) {
|
|
|
|
config.TestProductVariables.ManifestPackageNameOverrides = specs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 15:26:59 +08:00
|
|
|
func withBinder32bit(fs map[string][]byte, config android.Config) {
|
|
|
|
config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2020-01-14 08:22:18 +08:00
|
|
|
func withUnbundledBuild(fs map[string][]byte, config android.Config) {
|
|
|
|
config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
|
2019-12-17 11:47:13 +08:00
|
|
|
android.ClearApexDependency()
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
bp = bp + `
|
2019-11-20 01:26:02 +08:00
|
|
|
filegroup {
|
|
|
|
name: "myapex-file_contexts",
|
|
|
|
srcs: [
|
|
|
|
"system/sepolicy/apex/myapex-file_contexts",
|
|
|
|
],
|
|
|
|
}
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
`
|
2019-12-14 12:41:13 +08:00
|
|
|
|
2020-02-16 03:29:50 +08:00
|
|
|
bp = bp + cc.GatherRequiredDepsForTest(android.Android)
|
|
|
|
|
2019-10-27 07:29:22 +08:00
|
|
|
bp = bp + java.GatherRequiredDepsForTest()
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
fs := map[string][]byte{
|
2019-11-20 01:26:02 +08:00
|
|
|
"a.java": nil,
|
|
|
|
"PrebuiltAppFoo.apk": nil,
|
|
|
|
"PrebuiltAppFooPriv.apk": nil,
|
|
|
|
"build/make/target/product/security": nil,
|
|
|
|
"apex_manifest.json": nil,
|
|
|
|
"AndroidManifest.xml": nil,
|
|
|
|
"system/sepolicy/apex/myapex-file_contexts": nil,
|
2020-02-19 15:29:35 +08:00
|
|
|
"system/sepolicy/apex/myapex.updatable-file_contexts": nil,
|
2020-01-14 17:38:44 +08:00
|
|
|
"system/sepolicy/apex/myapex2-file_contexts": nil,
|
2019-11-20 01:26:02 +08:00
|
|
|
"system/sepolicy/apex/otherapex-file_contexts": nil,
|
|
|
|
"system/sepolicy/apex/commonapex-file_contexts": nil,
|
|
|
|
"system/sepolicy/apex/com.android.vndk-file_contexts": nil,
|
2019-12-14 12:41:13 +08:00
|
|
|
"mylib.cpp": nil,
|
|
|
|
"mylib_common.cpp": nil,
|
|
|
|
"mytest.cpp": nil,
|
|
|
|
"mytest1.cpp": nil,
|
|
|
|
"mytest2.cpp": nil,
|
|
|
|
"mytest3.cpp": nil,
|
|
|
|
"myprebuilt": nil,
|
|
|
|
"my_include": nil,
|
|
|
|
"foo/bar/MyClass.java": nil,
|
|
|
|
"prebuilt.jar": nil,
|
2020-04-07 22:25:44 +08:00
|
|
|
"prebuilt.so": nil,
|
2019-12-14 12:41:13 +08:00
|
|
|
"vendor/foo/devkeys/test.x509.pem": nil,
|
|
|
|
"vendor/foo/devkeys/test.pk8": nil,
|
|
|
|
"testkey.x509.pem": nil,
|
|
|
|
"testkey.pk8": nil,
|
|
|
|
"testkey.override.x509.pem": nil,
|
|
|
|
"testkey.override.pk8": nil,
|
|
|
|
"vendor/foo/devkeys/testkey.avbpubkey": nil,
|
|
|
|
"vendor/foo/devkeys/testkey.pem": nil,
|
|
|
|
"NOTICE": nil,
|
|
|
|
"custom_notice": nil,
|
2020-03-17 18:16:40 +08:00
|
|
|
"custom_notice_for_static_lib": nil,
|
2019-12-14 12:41:13 +08:00
|
|
|
"testkey2.avbpubkey": nil,
|
|
|
|
"testkey2.pem": nil,
|
|
|
|
"myapex-arm64.apex": nil,
|
|
|
|
"myapex-arm.apex": nil,
|
|
|
|
"frameworks/base/api/current.txt": nil,
|
|
|
|
"framework/aidl/a.aidl": nil,
|
|
|
|
"build/make/core/proguard.flags": nil,
|
|
|
|
"build/make/core/proguard_basic_keeps.flags": nil,
|
|
|
|
"dummy.txt": nil,
|
|
|
|
}
|
|
|
|
|
2020-02-16 03:29:50 +08:00
|
|
|
cc.GatherRequiredFilesForTest(fs)
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
for _, handler := range handlers {
|
|
|
|
// The fs now needs to be populated before creating the config, call handlers twice
|
|
|
|
// for now, once to get any fs changes, and later after the config was created to
|
|
|
|
// set product variables or targets.
|
|
|
|
tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
|
|
|
|
handler(fs, tempConfig)
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
config := android.TestArchConfig(buildDir, nil, bp, fs)
|
|
|
|
config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
|
|
|
|
config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
|
|
|
|
config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
|
|
|
|
config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
|
|
|
|
config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
|
|
|
|
config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
for _, handler := range handlers {
|
2019-12-14 12:41:13 +08:00
|
|
|
// The fs now needs to be populated before creating the config, call handlers twice
|
|
|
|
// for now, earlier to get any fs changes, and now after the config was created to
|
|
|
|
// set product variables or targets.
|
|
|
|
tempFS := map[string][]byte{}
|
|
|
|
handler(tempFS, config)
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
ctx := android.NewTestArchContext()
|
|
|
|
ctx.RegisterModuleType("apex", BundleFactory)
|
|
|
|
ctx.RegisterModuleType("apex_test", testApexBundleFactory)
|
|
|
|
ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
|
|
|
|
ctx.RegisterModuleType("apex_key", ApexKeyFactory)
|
|
|
|
ctx.RegisterModuleType("apex_defaults", defaultsFactory)
|
|
|
|
ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
|
|
|
|
ctx.RegisterModuleType("override_apex", overrideApexFactory)
|
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
|
|
|
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
|
|
|
|
|
2019-12-20 00:01:36 +08:00
|
|
|
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
2019-12-14 12:41:13 +08:00
|
|
|
ctx.RegisterModuleType("cc_test", cc.TestFactory)
|
|
|
|
ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
|
|
|
|
ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
|
|
|
|
ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
|
2020-01-28 01:01:16 +08:00
|
|
|
ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory)
|
2019-12-14 12:41:13 +08:00
|
|
|
ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
2019-12-19 03:51:55 +08:00
|
|
|
java.RegisterJavaBuildComponents(ctx)
|
2019-12-19 19:18:54 +08:00
|
|
|
java.RegisterSystemModulesBuildComponents(ctx)
|
2019-12-19 03:51:55 +08:00
|
|
|
java.RegisterAppBuildComponents(ctx)
|
2019-12-18 14:34:32 +08:00
|
|
|
ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
|
2019-12-14 12:41:13 +08:00
|
|
|
|
|
|
|
ctx.PreDepsMutators(RegisterPreDepsMutators)
|
|
|
|
ctx.PostDepsMutators(RegisterPostDepsMutators)
|
|
|
|
|
|
|
|
ctx.Register(config)
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
2019-06-27 10:30:33 +08:00
|
|
|
return ctx, config
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:20:53 +08:00
|
|
|
func setUp() {
|
|
|
|
var err error
|
|
|
|
buildDir, err = ioutil.TempDir("", "soong_apex_test")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
if err != nil {
|
2019-06-26 02:20:53 +08:00
|
|
|
panic(err)
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:20:53 +08:00
|
|
|
func tearDown() {
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
os.RemoveAll(buildDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure that 'result' contains 'expected'
|
|
|
|
func ensureContains(t *testing.T, result string, expected string) {
|
2019-06-27 10:30:33 +08:00
|
|
|
t.Helper()
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
if !strings.Contains(result, expected) {
|
|
|
|
t.Errorf("%q is not found in %q", expected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensures that 'result' does not contain 'notExpected'
|
|
|
|
func ensureNotContains(t *testing.T, result string, notExpected string) {
|
2019-06-27 10:30:33 +08:00
|
|
|
t.Helper()
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
if strings.Contains(result, notExpected) {
|
|
|
|
t.Errorf("%q is found in %q", notExpected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureListContains(t *testing.T, result []string, expected string) {
|
2019-06-27 10:30:33 +08:00
|
|
|
t.Helper()
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
if !android.InList(expected, result) {
|
|
|
|
t.Errorf("%q is not found in %v", expected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureListNotContains(t *testing.T, result []string, notExpected string) {
|
2019-06-27 10:30:33 +08:00
|
|
|
t.Helper()
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
if android.InList(notExpected, result) {
|
|
|
|
t.Errorf("%q is found in %v", notExpected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 16:41:43 +08:00
|
|
|
func ensureListEmpty(t *testing.T, result []string) {
|
|
|
|
t.Helper()
|
|
|
|
if len(result) > 0 {
|
|
|
|
t.Errorf("%q is expected to be empty", result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// Minimal test
|
|
|
|
func TestBasicApex(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-02-07 15:27:23 +08:00
|
|
|
apex_defaults {
|
|
|
|
name: "myapex-defaults",
|
2019-02-13 20:33:49 +08:00
|
|
|
manifest: ":myapex.manifest",
|
|
|
|
androidManifest: ":myapex.androidmanifest",
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
2019-01-19 06:37:31 +08:00
|
|
|
multilib: {
|
|
|
|
both: {
|
|
|
|
binaries: ["foo",],
|
|
|
|
}
|
2019-07-25 21:02:35 +08:00
|
|
|
},
|
2019-12-23 14:38:34 +08:00
|
|
|
java_libs: ["myjar"],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 15:27:23 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
defaults: ["myapex-defaults"],
|
|
|
|
}
|
|
|
|
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
2019-02-13 20:33:49 +08:00
|
|
|
filegroup {
|
|
|
|
name: "myapex.manifest",
|
|
|
|
srcs: ["apex_manifest.json"],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "myapex.androidmanifest",
|
|
|
|
srcs: ["AndroidManifest.xml"],
|
|
|
|
}
|
|
|
|
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["mylib2"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
2019-01-19 06:37:31 +08:00
|
|
|
cc_binary {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
compile_multilib: "both",
|
|
|
|
multilib: {
|
|
|
|
lib32: {
|
|
|
|
suffix: "32",
|
|
|
|
},
|
|
|
|
lib64: {
|
|
|
|
suffix: "64",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
symlinks: ["foo_link_"],
|
|
|
|
symlink_preferred_arch: true,
|
|
|
|
system_shared_libs: [],
|
|
|
|
static_executable: true,
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-01-19 06:37:31 +08:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:25:44 +08:00
|
|
|
cc_library_shared {
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2019-03-18 11:01:38 +08:00
|
|
|
notice: "custom_notice",
|
2020-03-17 18:16:40 +08:00
|
|
|
static_libs: ["libstatic"],
|
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:25:44 +08:00
|
|
|
cc_prebuilt_library_shared {
|
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["prebuilt.so"],
|
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2020-03-17 18:16:40 +08:00
|
|
|
cc_library_static {
|
|
|
|
name: "libstatic",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
notice: "custom_notice_for_static_lib",
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
2019-07-25 21:02:35 +08:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
static_libs: ["myotherjar"],
|
2019-12-27 13:11:47 +08:00
|
|
|
libs: ["mysharedjar"],
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-07-25 21:02:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myotherjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-31 01:49:53 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-07-25 21:02:35 +08:00
|
|
|
}
|
2019-12-27 13:11:47 +08:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "mysharedjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
}
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
2019-04-01 10:15:50 +08:00
|
|
|
|
|
|
|
optFlags := apexRule.Args["opt_flags"]
|
|
|
|
ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
|
2019-06-19 04:09:13 +08:00
|
|
|
// Ensure that the NOTICE output is being packaged as an asset.
|
2019-10-22 12:58:29 +08:00
|
|
|
ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
|
2019-04-01 10:15:50 +08:00
|
|
|
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that main rule creates an output
|
|
|
|
ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
|
|
|
|
|
|
|
|
// Ensure that apex variant is created for the direct dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
|
2019-07-25 21:02:35 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that apex variant is created for the indirect dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
|
2019-07-25 21:02:35 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that both direct and indirect deps are copied into apex
|
2018-11-30 09:12:15 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
|
2019-07-25 21:02:35 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
|
|
|
|
// .. but not for java libs
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
|
2018-12-26 15:32:21 +08:00
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
// Ensure that the platform variant ends with _shared or _common
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
|
2019-07-25 21:02:35 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
|
|
|
|
|
|
|
|
// Ensure that dynamic dependency to java libs are not included
|
|
|
|
ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
|
2019-01-19 06:37:31 +08:00
|
|
|
|
|
|
|
// Ensure that all symlinks are present.
|
|
|
|
found_foo_link_64 := false
|
|
|
|
found_foo := false
|
|
|
|
for _, cmd := range strings.Split(copyCmds, " && ") {
|
2020-01-14 08:22:18 +08:00
|
|
|
if strings.HasPrefix(cmd, "ln -sfn foo64") {
|
2019-01-19 06:37:31 +08:00
|
|
|
if strings.HasSuffix(cmd, "bin/foo") {
|
|
|
|
found_foo = true
|
|
|
|
} else if strings.HasSuffix(cmd, "bin/foo_link_64") {
|
|
|
|
found_foo_link_64 = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
good := found_foo && found_foo_link_64
|
|
|
|
if !good {
|
|
|
|
t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
|
|
|
|
}
|
2019-03-18 11:01:38 +08:00
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
|
2019-06-18 08:40:56 +08:00
|
|
|
noticeInputs := mergeNoticesRule.Inputs.Strings()
|
2020-03-17 18:16:40 +08:00
|
|
|
if len(noticeInputs) != 3 {
|
|
|
|
t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs))
|
2019-03-18 11:01:38 +08:00
|
|
|
}
|
|
|
|
ensureListContains(t, noticeInputs, "NOTICE")
|
|
|
|
ensureListContains(t, noticeInputs, "custom_notice")
|
2020-03-17 18:16:40 +08:00
|
|
|
ensureListContains(t, noticeInputs, "custom_notice_for_static_lib")
|
2020-01-14 17:38:44 +08:00
|
|
|
|
|
|
|
depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n")
|
2020-02-07 16:25:49 +08:00
|
|
|
ensureListContains(t, depsInfo, "myjar <- myapex")
|
|
|
|
ensureListContains(t, depsInfo, "mylib <- myapex")
|
|
|
|
ensureListContains(t, depsInfo, "mylib2 <- mylib")
|
|
|
|
ensureListContains(t, depsInfo, "myotherjar <- myjar")
|
|
|
|
ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar")
|
2018-11-30 09:12:15 +08:00
|
|
|
}
|
|
|
|
|
2019-12-16 21:32:06 +08:00
|
|
|
func TestDefaults(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex_defaults {
|
|
|
|
name: "myapex-defaults",
|
|
|
|
key: "myapex.key",
|
|
|
|
prebuilts: ["myetc"],
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
java_libs: ["myjar"],
|
|
|
|
apps: ["AppFoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt_etc {
|
|
|
|
name: "myetc",
|
|
|
|
src: "myprebuilt",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
defaults: ["myapex-defaults"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-12-16 21:32:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-12-16 21:32:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "AppFoo",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-12-16 21:32:06 +08:00
|
|
|
}
|
|
|
|
`)
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
2019-12-16 21:32:06 +08:00
|
|
|
"etc/myetc",
|
|
|
|
"javalib/myjar.jar",
|
|
|
|
"lib64/mylib.so",
|
|
|
|
"app/AppFoo/AppFoo.apk",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-02 01:52:25 +08:00
|
|
|
func TestApexManifest(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-11-12 12:03:50 +08:00
|
|
|
args := module.Rule("apexRule").Args
|
|
|
|
if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
|
|
|
|
t.Error("manifest should be apex_manifest.pb, but " + manifest)
|
|
|
|
}
|
2019-11-02 01:52:25 +08:00
|
|
|
}
|
|
|
|
|
2018-11-30 09:12:15 +08:00
|
|
|
func TestBasicZipApex(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2018-11-30 09:12:15 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
payload_type: "zip",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["mylib2"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2018-11-30 09:12:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2018-11-30 09:12:15 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
|
2018-11-30 09:12:15 +08:00
|
|
|
copyCmds := zipApexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that main rule creates an output
|
|
|
|
ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
|
|
|
|
|
|
|
|
// Ensure that APEX variant is created for the direct dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
|
2018-11-30 09:12:15 +08:00
|
|
|
|
|
|
|
// Ensure that APEX variant is created for the indirect dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
|
2018-11-30 09:12:15 +08:00
|
|
|
|
|
|
|
// Ensure that both direct and indirect deps are copied into apex
|
|
|
|
ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
|
|
|
|
ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestApexWithStubs(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib", "mylib3"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["mylib2", "mylib3"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["mylib.cpp"],
|
2018-12-13 17:37:29 +08:00
|
|
|
cflags: ["-include mylib.h"],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["1", "2", "3"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib3",
|
2018-12-07 21:42:47 +08:00
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["mylib4"],
|
|
|
|
system_shared_libs: [],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["10", "11", "12"],
|
|
|
|
},
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
2018-12-07 21:42:47 +08:00
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib4",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2018-12-07 21:42:47 +08:00
|
|
|
}
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that direct non-stubs dep is always included
|
2018-11-30 09:12:15 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that indirect stubs dep is not included
|
2018-11-30 09:12:15 +08:00
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that direct stubs dep is included
|
2018-11-30 09:12:15 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that mylib is linking with the latest version of stubs for mylib2
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... and not linking to the non-stub (impl) variant of mylib2
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// .. and not linking to the stubs variant of mylib3
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
|
2018-12-13 17:37:29 +08:00
|
|
|
|
|
|
|
// Ensure that stubs libs are built without -include flags
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-31 01:49:53 +08:00
|
|
|
mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
|
2018-12-13 17:37:29 +08:00
|
|
|
ensureNotContains(t, mylib2Cflags, "-include ")
|
2018-12-07 15:25:39 +08:00
|
|
|
|
|
|
|
// Ensure that genstub is invoked with --apex
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
|
2019-12-17 11:47:13 +08:00
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
2019-12-17 11:47:13 +08:00
|
|
|
"lib64/mylib.so",
|
|
|
|
"lib64/mylib3.so",
|
|
|
|
"lib64/mylib4.so",
|
|
|
|
})
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
func TestApexWithExplicitStubsDependency(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
apex {
|
2020-01-14 17:38:44 +08:00
|
|
|
name: "myapex2",
|
|
|
|
key: "myapex2.key",
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
2020-01-14 17:38:44 +08:00
|
|
|
name: "myapex2.key",
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["libfoo#10"],
|
2020-02-07 16:25:49 +08:00
|
|
|
static_libs: ["libbaz"],
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex2" ],
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["libbar"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["10", "20", "30"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
|
2020-02-07 16:25:49 +08:00
|
|
|
cc_library_static {
|
|
|
|
name: "libbaz",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex2" ],
|
|
|
|
}
|
|
|
|
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
`)
|
|
|
|
|
2020-01-14 17:38:44 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that direct non-stubs dep is always included
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
|
|
|
|
|
|
|
|
// Ensure that indirect stubs dep is not included
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
|
|
|
|
|
|
|
|
// Ensure that dependency of stubs is not included
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
|
|
|
|
|
2020-01-14 17:38:44 +08:00
|
|
|
mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
|
|
|
|
// Ensure that mylib is linking with version 10 of libfoo
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
// ... and not linking to the non-stub (impl) variant of libfoo
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
|
2019-12-27 13:11:47 +08:00
|
|
|
libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
|
|
|
|
// Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
|
|
|
|
ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
|
2020-01-14 17:38:44 +08:00
|
|
|
|
|
|
|
depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n")
|
2020-02-07 16:25:49 +08:00
|
|
|
|
|
|
|
ensureListContains(t, depsInfo, "mylib <- myapex2")
|
|
|
|
ensureListContains(t, depsInfo, "libbaz <- mylib")
|
|
|
|
ensureListContains(t, depsInfo, "libfoo (external) <- mylib")
|
Don't create unnecessary APEX variations
This change fixes a problem that APEX variations are created for the
modules that actually shouldn't built for any APEX. For example,
consider this case.
apex { name: "myapex", native_shared_libs: ["mylib"],}
cc_library { name: "mylib", shared_libs: ["libfoo#10"],}
cc_library { name: "libfoo",
shared_libs: ["libbar"],
stubs: { versions: ["10"], }, }
cc_library { name: "libbar", ...}
Before this change, both the stubs and non-stubs variations of libfoo
were mutated with apexMuator, which is incorrect for the non-stubs
varia; there is no dependency chain from the apex "myapex" to the
non-stubs variation, but to the stubs variation due to the #10 syntax.
This was happening becauses we used the name of the module to determine
whether it should be built for APEX or not. Both stubs and non-stubs
variations have the same module name "libfoo".
Fixing this issue by recording the list of APEX variations required
directly on the module. So, the stubs variation of libfoo has myapex in
its apex variations list, but the non-stubs variation doesn't, and thus
apexMutator does not pick up the non-stubs variation.
Test: m (apex_test updated and passing)
Test: cherry-pick ag/5747464 and m
Change-Id: I31e618626809a828a55fff513ef5f81f79637afa
2018-12-11 00:35:25 +08:00
|
|
|
}
|
|
|
|
|
2019-08-09 11:57:43 +08:00
|
|
|
func TestApexWithRuntimeLibsDependency(t *testing.T) {
|
|
|
|
/*
|
|
|
|
myapex
|
|
|
|
|
|
|
|
|
v (runtime_libs)
|
|
|
|
mylib ------+------> libfoo [provides stub]
|
|
|
|
|
|
|
|
|
`------> libbar
|
|
|
|
*/
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
runtime_libs: ["libfoo", "libbar"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-09 11:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["10", "20", "30"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-09 11:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
2019-08-09 11:57:43 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that direct non-stubs dep is always included
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
|
|
|
|
|
|
|
|
// Ensure that indirect stubs dep is not included
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
|
|
|
|
|
|
|
|
// Ensure that runtime_libs dep in included
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
|
2019-09-26 23:38:03 +08:00
|
|
|
ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
|
|
|
|
ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
|
2019-08-09 11:57:43 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-13 14:23:36 +08:00
|
|
|
func TestApexDependsOnLLNDKTransitively(t *testing.T) {
|
|
|
|
testcases := []struct {
|
|
|
|
name string
|
|
|
|
minSdkVersion string
|
|
|
|
shouldLink string
|
|
|
|
shouldNotLink []string
|
|
|
|
}{
|
|
|
|
{
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
name: "should link to the latest",
|
2020-03-13 14:23:36 +08:00
|
|
|
minSdkVersion: "current",
|
|
|
|
shouldLink: "30",
|
|
|
|
shouldNotLink: []string{"29"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "should link to llndk#29",
|
|
|
|
minSdkVersion: "29",
|
|
|
|
shouldLink: "29",
|
|
|
|
shouldNotLink: []string{"30"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testcases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
use_vendor: true,
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
min_sdk_version: "`+tc.minSdkVersion+`",
|
|
|
|
}
|
2019-08-20 16:30:57 +08:00
|
|
|
|
2020-03-13 14:23:36 +08:00
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
2019-08-20 16:30:57 +08:00
|
|
|
|
2020-03-13 14:23:36 +08:00
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
vendor_available: true,
|
|
|
|
shared_libs: ["libbar"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
2019-08-20 16:30:57 +08:00
|
|
|
|
2020-03-13 14:23:36 +08:00
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: { versions: ["29","30"] },
|
|
|
|
}
|
2019-08-20 16:30:57 +08:00
|
|
|
|
2020-03-13 14:23:36 +08:00
|
|
|
llndk_library {
|
|
|
|
name: "libbar",
|
|
|
|
symbol_file: "",
|
|
|
|
}
|
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
setUseVendorWhitelistForTest(config, []string{"myapex"})
|
|
|
|
}, withUnbundledBuild)
|
|
|
|
|
|
|
|
// Ensure that LLNDK dep is not included
|
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
|
|
|
"lib64/mylib.so",
|
|
|
|
})
|
|
|
|
|
|
|
|
// Ensure that LLNDK dep is required
|
|
|
|
apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
|
|
|
|
ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
|
|
|
|
ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
|
|
|
|
|
|
|
|
mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
|
|
|
|
ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so")
|
|
|
|
for _, ver := range tc.shouldNotLink {
|
|
|
|
ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so")
|
|
|
|
}
|
2019-08-20 16:30:57 +08:00
|
|
|
|
2020-03-13 14:23:36 +08:00
|
|
|
mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
|
|
|
|
ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink)
|
|
|
|
})
|
|
|
|
}
|
2019-08-20 16:30:57 +08:00
|
|
|
}
|
|
|
|
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
func TestApexWithSystemLibsStubs(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["libdl#27"],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_shared {
|
|
|
|
name: "mylib_shared",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["libdl#27"],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
|
|
|
|
2018-12-20 21:10:17 +08:00
|
|
|
cc_library {
|
|
|
|
name: "libBootstrap",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
stl: "none",
|
|
|
|
bootstrap: true,
|
|
|
|
}
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that mylib, libm, libdl are included.
|
2018-11-30 09:12:15 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
|
2018-12-20 21:10:17 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
|
2018-12-20 21:10:17 +08:00
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
|
|
|
|
mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
|
|
|
|
mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
|
|
|
|
// For dependency to libc
|
|
|
|
// Ensure that mylib is linking with the latest version of stubs
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... and not linking to the non-stub (impl) variant
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... Cflags from stub is correctly exported to mylib
|
|
|
|
ensureContains(t, mylibCFlags, "__LIBC_API__=29")
|
|
|
|
ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
|
|
|
|
|
|
|
|
// For dependency to libm
|
|
|
|
// Ensure that mylib is linking with the non-stub (impl) variant
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... and not linking to the stub variant
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... and is not compiling with the stub
|
|
|
|
ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
|
|
|
|
ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
|
|
|
|
|
|
|
|
// For dependency to libdl
|
|
|
|
// Ensure that mylib is linking with the specified version of stubs
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... and not linking to the other versions of stubs
|
2019-12-27 13:11:47 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
|
|
|
|
ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... and not linking to the non-stub (impl) variant
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
// ... Cflags from stub is correctly exported to mylib
|
|
|
|
ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
|
|
|
|
ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
|
2018-12-20 21:10:17 +08:00
|
|
|
|
|
|
|
// Ensure that libBootstrap is depending on the platform variant of bionic libs
|
2019-11-21 08:39:12 +08:00
|
|
|
libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
|
|
|
|
ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
|
|
|
|
ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
|
|
|
|
ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
|
Stubs variant is used when building for APEX
When a native module is built for an APEX and is depending on a native
library having stubs (i.e. stubs.versions property is set), the stubs
variant is used unless the dependent lib is directly included in the
same APEX with the depending module.
Example:
apex {
name: "myapex",
native_shared_libs: ["libX", "libY"],
}
cc_library {
name: "libX",
shared_libs: ["libY", "libZ"],
}
cc_library {
name: "libY",
stubs: { versions: ["1", "2"], },
}
cc_library {
name: "libZ",
stubs: { versions: ["1", "2"], },
}
In this case, libX is linking to the impl variant of libY (that provides
private APIs) while libY is linking to the version 2 stubs of libZ. This is
because libY is directly included in the same apex via
native_shared_libs property, but libZ isn't.
Bug: 112672359
Test: apex_test added
Change-Id: If9871b70dc74a06bd828dd4cd1aeebd2e68b837c
2018-11-18 17:02:45 +08:00
|
|
|
}
|
2018-12-06 23:42:25 +08:00
|
|
|
|
2020-02-26 21:45:42 +08:00
|
|
|
func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) {
|
|
|
|
// there are three links between liba --> libz
|
|
|
|
// 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1
|
|
|
|
// 2) otherapex -> liby -> liba -> libz : this should be #3 link
|
|
|
|
// 3) (platform) -> liba -> libz : this should be non-stub link
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
min_sdk_version: "2",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "otherapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["liby"],
|
|
|
|
min_sdk_version: "3",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
shared_libs: ["liba"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "liby",
|
|
|
|
shared_libs: ["liba"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "otherapex" ],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "liba",
|
|
|
|
shared_libs: ["libz"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:anyapex",
|
|
|
|
"//apex_available:platform",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libz",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["1", "3"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, withUnbundledBuild)
|
|
|
|
|
|
|
|
expectLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
expectNoLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
// platform liba is linked to non-stub version
|
|
|
|
expectLink("liba", "shared", "libz", "shared")
|
|
|
|
// liba in myapex is linked to #1
|
|
|
|
expectLink("liba", "shared_myapex", "libz", "shared_1")
|
|
|
|
expectNoLink("liba", "shared_myapex", "libz", "shared_3")
|
|
|
|
expectNoLink("liba", "shared_myapex", "libz", "shared")
|
|
|
|
// liba in otherapex is linked to #3
|
|
|
|
expectLink("liba", "shared_otherapex", "libz", "shared_3")
|
|
|
|
expectNoLink("liba", "shared_otherapex", "libz", "shared_1")
|
|
|
|
expectNoLink("liba", "shared_otherapex", "libz", "shared")
|
|
|
|
}
|
|
|
|
|
2020-04-02 00:41:41 +08:00
|
|
|
func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
min_sdk_version: "R",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
shared_libs: ["libz"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libz",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["29", "R"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
config.TestProductVariables.Platform_version_active_codenames = []string{"R"}
|
|
|
|
})
|
|
|
|
|
|
|
|
expectLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
expectNoLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
// 9000 is quite a magic number.
|
|
|
|
// Finalized SDK codenames are mapped as P(28), Q(29), ...
|
|
|
|
// And, codenames which are not finalized yet(active_codenames + future_codenames) are numbered from 9000, 9001, ...
|
|
|
|
// to distinguish them from finalized and future_api(10000)
|
|
|
|
// In this test, "R" is assumed not finalized yet( listed in Platform_version_active_codenames) and translated into 9000
|
|
|
|
// (refer android/api_levels.go)
|
|
|
|
expectLink("libx", "shared_myapex", "libz", "shared_9000")
|
|
|
|
expectNoLink("libx", "shared_myapex", "libz", "shared_29")
|
|
|
|
expectNoLink("libx", "shared_myapex", "libz", "shared")
|
|
|
|
}
|
|
|
|
|
2020-02-26 21:45:42 +08:00
|
|
|
func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
shared_libs: ["libz"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libz",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["1", "2"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
expectLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
expectNoLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
expectLink("libx", "shared_myapex", "libz", "shared_2")
|
|
|
|
expectNoLink("libx", "shared_myapex", "libz", "shared_1")
|
|
|
|
expectNoLink("libx", "shared_myapex", "libz", "shared")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPlatformUsesLatestStubsFromApexes(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
stubs: {
|
|
|
|
versions: ["1", "2"],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libz",
|
|
|
|
shared_libs: ["libx"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
expectLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
expectNoLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
|
|
|
|
ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
|
|
|
expectLink("libz", "shared", "libx", "shared_2")
|
|
|
|
expectNoLink("libz", "shared", "libz", "shared_1")
|
|
|
|
expectNoLink("libz", "shared", "libz", "shared")
|
|
|
|
}
|
|
|
|
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) {
|
2020-02-26 21:45:42 +08:00
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
shared_libs: ["libbar"],
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
stubs: {
|
|
|
|
versions: ["29", "30"],
|
|
|
|
},
|
|
|
|
}
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
|
|
|
|
})
|
2020-02-26 21:45:42 +08:00
|
|
|
expectLink := func(from, from_variant, to, to_variant string) {
|
|
|
|
ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld")
|
|
|
|
libFlags := ld.Args["libFlags"]
|
|
|
|
ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
|
|
|
|
}
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
expectLink("libx", "shared_hwasan_myapex", "libbar", "shared_30")
|
2020-02-26 21:45:42 +08:00
|
|
|
}
|
|
|
|
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
func TestQTargetApexUsesStaticUnwinder(t *testing.T) {
|
2020-02-26 21:45:42 +08:00
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
`)
|
2020-02-26 21:45:42 +08:00
|
|
|
|
|
|
|
// ensure apex variant of c++ is linked with static unwinder
|
|
|
|
cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module)
|
|
|
|
ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
|
|
|
|
// note that platform variant is not.
|
|
|
|
cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module)
|
|
|
|
ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidMinSdkVersion(t *testing.T) {
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
testApexError(t, `"libz" .*: not found a version\(<=29\)`, `
|
2020-02-26 21:45:42 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libx"],
|
|
|
|
min_sdk_version: "29",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libx",
|
|
|
|
shared_libs: ["libz"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libz",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["30"],
|
|
|
|
},
|
|
|
|
}
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
`)
|
2020-02-26 21:45:42 +08:00
|
|
|
|
2020-04-02 00:41:41 +08:00
|
|
|
testApexError(t, `"myapex" .*: min_sdk_version: SDK version should be .*`, `
|
2020-02-26 21:45:42 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2020-04-02 00:41:41 +08:00
|
|
|
min_sdk_version: "abc",
|
2020-02-26 21:45:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2018-12-06 23:42:25 +08:00
|
|
|
func TestFilesInSubDir(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2018-12-06 23:42:25 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2019-02-01 11:03:59 +08:00
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
binaries: ["mybin"],
|
2018-12-06 23:42:25 +08:00
|
|
|
prebuilts: ["myetc"],
|
2019-02-01 11:03:59 +08:00
|
|
|
compile_multilib: "both",
|
2018-12-06 23:42:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
prebuilt_etc {
|
|
|
|
name: "myetc",
|
|
|
|
src: "myprebuilt",
|
|
|
|
sub_dir: "foo/bar",
|
|
|
|
}
|
2019-02-01 11:03:59 +08:00
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
relative_install_path: "foo/bar",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-02-01 11:03:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_binary {
|
|
|
|
name: "mybin",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
relative_install_path: "foo/bar",
|
|
|
|
system_shared_libs: [],
|
|
|
|
static_executable: true,
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-02-01 11:03:59 +08:00
|
|
|
}
|
2018-12-06 23:42:25 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
|
2018-12-06 23:42:25 +08:00
|
|
|
dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
|
|
|
|
|
2019-02-01 11:03:59 +08:00
|
|
|
// Ensure that the subdirectories are all listed
|
2018-12-06 23:42:25 +08:00
|
|
|
ensureListContains(t, dirs, "etc")
|
|
|
|
ensureListContains(t, dirs, "etc/foo")
|
|
|
|
ensureListContains(t, dirs, "etc/foo/bar")
|
2019-02-01 11:03:59 +08:00
|
|
|
ensureListContains(t, dirs, "lib64")
|
|
|
|
ensureListContains(t, dirs, "lib64/foo")
|
|
|
|
ensureListContains(t, dirs, "lib64/foo/bar")
|
|
|
|
ensureListContains(t, dirs, "lib")
|
|
|
|
ensureListContains(t, dirs, "lib/foo")
|
|
|
|
ensureListContains(t, dirs, "lib/foo/bar")
|
|
|
|
|
2019-03-15 17:10:35 +08:00
|
|
|
ensureListContains(t, dirs, "bin")
|
|
|
|
ensureListContains(t, dirs, "bin/foo")
|
|
|
|
ensureListContains(t, dirs, "bin/foo/bar")
|
2018-12-06 23:42:25 +08:00
|
|
|
}
|
2018-12-19 16:12:36 +08:00
|
|
|
|
|
|
|
func TestUseVendor(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2018-12-19 16:12:36 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
use_vendor: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["mylib2"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
vendor_available: true,
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2018-12-19 16:12:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
vendor_available: true,
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2018-12-19 16:12:36 +08:00
|
|
|
}
|
2019-11-01 02:14:38 +08:00
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
setUseVendorWhitelistForTest(config, []string{"myapex"})
|
|
|
|
})
|
2018-12-19 16:12:36 +08:00
|
|
|
|
|
|
|
inputsList := []string{}
|
2019-10-22 12:58:29 +08:00
|
|
|
for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
|
2018-12-19 16:12:36 +08:00
|
|
|
for _, implicit := range i.Implicits {
|
|
|
|
inputsList = append(inputsList, implicit.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputsString := strings.Join(inputsList, " ")
|
|
|
|
|
|
|
|
// ensure that the apex includes vendor variants of the direct and indirect deps
|
2019-11-21 09:12:35 +08:00
|
|
|
ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
|
|
|
|
ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
|
2018-12-19 16:12:36 +08:00
|
|
|
|
|
|
|
// ensure that the apex does not include core variants
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
|
|
|
|
ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
|
2018-12-19 16:12:36 +08:00
|
|
|
}
|
2018-12-20 17:18:08 +08:00
|
|
|
|
2019-11-01 02:14:38 +08:00
|
|
|
func TestUseVendorRestriction(t *testing.T) {
|
|
|
|
testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
use_vendor: true,
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
setUseVendorWhitelistForTest(config, []string{""})
|
|
|
|
})
|
|
|
|
// no error with whitelist
|
|
|
|
testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
use_vendor: true,
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
setUseVendorWhitelistForTest(config, []string{"myapex"})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-27 10:30:33 +08:00
|
|
|
func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
|
|
|
|
testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
use_vendor: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2018-12-20 17:18:08 +08:00
|
|
|
func TestStaticLinking(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2018-12-20 17:18:08 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
stubs: {
|
|
|
|
versions: ["1", "2", "3"],
|
|
|
|
},
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2018-12-20 17:18:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_binary {
|
|
|
|
name: "not_in_apex",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
static_libs: ["mylib"],
|
|
|
|
static_executable: true,
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
|
2018-12-20 17:18:08 +08:00
|
|
|
|
|
|
|
// Ensure that not_in_apex is linking with the static variant of mylib
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
|
2018-12-20 17:18:08 +08:00
|
|
|
}
|
2018-12-24 10:31:58 +08:00
|
|
|
|
|
|
|
func TestKeys(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2018-12-24 10:31:58 +08:00
|
|
|
apex {
|
2019-02-11 10:38:15 +08:00
|
|
|
name: "myapex_keytest",
|
2018-12-24 10:31:58 +08:00
|
|
|
key: "myapex.key",
|
2019-02-11 10:38:15 +08:00
|
|
|
certificate: ":myapex.certificate",
|
2018-12-24 10:31:58 +08:00
|
|
|
native_shared_libs: ["mylib"],
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2018-12-24 10:31:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex_keytest" ],
|
2018-12-24 10:31:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
2019-02-11 10:38:15 +08:00
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.certificate",
|
|
|
|
certificate: "testkey",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.certificate.override",
|
|
|
|
certificate: "testkey.override",
|
|
|
|
}
|
|
|
|
|
2018-12-24 10:31:58 +08:00
|
|
|
`)
|
|
|
|
|
|
|
|
// check the APEX keys
|
2019-03-15 01:13:21 +08:00
|
|
|
keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
|
2018-12-24 10:31:58 +08:00
|
|
|
|
|
|
|
if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
|
|
|
|
t.Errorf("public key %q is not %q", keys.public_key_file.String(),
|
|
|
|
"vendor/foo/devkeys/testkey.avbpubkey")
|
|
|
|
}
|
|
|
|
if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
|
|
|
|
t.Errorf("private key %q is not %q", keys.private_key_file.String(),
|
|
|
|
"vendor/foo/devkeys/testkey.pem")
|
|
|
|
}
|
|
|
|
|
2019-02-11 10:38:15 +08:00
|
|
|
// check the APK certs. It should be overridden to myapex.certificate.override
|
2019-10-22 12:58:29 +08:00
|
|
|
certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
|
2019-02-11 10:38:15 +08:00
|
|
|
if certs != "testkey.override.x509.pem testkey.override.pk8" {
|
2018-12-24 10:31:58 +08:00
|
|
|
t.Errorf("cert and private key %q are not %q", certs,
|
2019-02-11 10:38:15 +08:00
|
|
|
"testkey.override.509.pem testkey.override.pk8")
|
2018-12-24 10:31:58 +08:00
|
|
|
}
|
|
|
|
}
|
2019-01-19 18:24:06 +08:00
|
|
|
|
2019-12-17 13:30:11 +08:00
|
|
|
func TestCertificate(t *testing.T) {
|
|
|
|
t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}`)
|
|
|
|
rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
|
|
|
|
expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
|
|
|
|
if actual := rule.Args["certificates"]; actual != expected {
|
|
|
|
t.Errorf("certificates should be %q, not %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("override when unspecified", func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex_keytest",
|
|
|
|
key: "myapex.key",
|
|
|
|
file_contexts: ":myapex-file_contexts",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.certificate.override",
|
|
|
|
certificate: "testkey.override",
|
|
|
|
}`)
|
|
|
|
rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
|
|
|
|
expected := "testkey.override.x509.pem testkey.override.pk8"
|
|
|
|
if actual := rule.Args["certificates"]; actual != expected {
|
|
|
|
t.Errorf("certificates should be %q, not %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
certificate: ":myapex.certificate",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.certificate",
|
|
|
|
certificate: "testkey",
|
|
|
|
}`)
|
|
|
|
rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
|
|
|
|
expected := "testkey.x509.pem testkey.pk8"
|
|
|
|
if actual := rule.Args["certificates"]; actual != expected {
|
|
|
|
t.Errorf("certificates should be %q, not %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("override when specifiec as <:module>", func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex_keytest",
|
|
|
|
key: "myapex.key",
|
|
|
|
file_contexts: ":myapex-file_contexts",
|
|
|
|
certificate: ":myapex.certificate",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.certificate.override",
|
|
|
|
certificate: "testkey.override",
|
|
|
|
}`)
|
|
|
|
rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
|
|
|
|
expected := "testkey.override.x509.pem testkey.override.pk8"
|
|
|
|
if actual := rule.Args["certificates"]; actual != expected {
|
|
|
|
t.Errorf("certificates should be %q, not %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
certificate: "testkey",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}`)
|
|
|
|
rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
|
|
|
|
expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
|
|
|
|
if actual := rule.Args["certificates"]; actual != expected {
|
|
|
|
t.Errorf("certificates should be %q, not %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("override when specified as <name>", func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex_keytest",
|
|
|
|
key: "myapex.key",
|
|
|
|
file_contexts: ":myapex-file_contexts",
|
|
|
|
certificate: "testkey",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
android_app_certificate {
|
|
|
|
name: "myapex.certificate.override",
|
|
|
|
certificate: "testkey.override",
|
|
|
|
}`)
|
|
|
|
rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
|
|
|
|
expected := "testkey.override.x509.pem testkey.override.pk8"
|
|
|
|
if actual := rule.Args["certificates"]; actual != expected {
|
|
|
|
t.Errorf("certificates should be %q, not %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-19 18:24:06 +08:00
|
|
|
func TestMacro(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-01-19 18:24:06 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2020-03-02 16:44:33 +08:00
|
|
|
native_shared_libs: ["mylib", "mylib2"],
|
2019-01-19 18:24:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "otherapex",
|
|
|
|
key: "myapex.key",
|
2020-03-02 16:44:33 +08:00
|
|
|
native_shared_libs: ["mylib", "mylib2"],
|
2020-03-07 02:45:53 +08:00
|
|
|
min_sdk_version: "29",
|
2019-01-19 18:24:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
"otherapex",
|
|
|
|
],
|
2020-03-21 22:20:55 +08:00
|
|
|
recovery_available: true,
|
2019-01-19 18:24:06 +08:00
|
|
|
}
|
2020-03-02 16:44:33 +08:00
|
|
|
cc_library {
|
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
|
|
|
"otherapex",
|
|
|
|
],
|
|
|
|
use_apex_name_macro: true,
|
|
|
|
}
|
2019-01-19 18:24:06 +08:00
|
|
|
`)
|
|
|
|
|
2020-03-02 16:44:33 +08:00
|
|
|
// non-APEX variant does not have __ANDROID_APEX__ defined
|
2019-11-21 08:39:12 +08:00
|
|
|
mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
|
2019-10-30 07:29:25 +08:00
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
Enforce apex.min_sdk_version for bundled builds
Previously, when Q-targeting apexes are bundled-built, they are built
against the latest stubs.
It was because unwinder is linked dynamically in R and APIs are provided
by libc while Q apexes should run on Q where libc doesn't provide those
APIs. To make Q apexes run on Q device, libc++ should be linked with
static unwinder. But, because libc++ with static unwinder may cause problem
on HWASAN build, Q apexes were built against the latest stubs for bundled
build.
However, Q apexes should be built against Q stubs.
Now, only for HWASAN builds, Q apexes are built against the latest stubs
(and native modules are not linked with static unwinder).
Bug: 151912436
Test: TARGET_SANITIZE=hwaddress m
=> Q apexes(media, resolv, ..) are linked with the latest stubs
m
=> Q apexes are linked with Q stubs,
and Q apexes' libc++ is linked with static unwinder
Change-Id: If32f1b547e6d93e3955c7521eec8aef5851f908c
2020-03-20 03:29:24 +08:00
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__")
|
2020-03-02 16:44:33 +08:00
|
|
|
|
2020-03-07 02:45:53 +08:00
|
|
|
// APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
|
2020-03-02 16:44:33 +08:00
|
|
|
mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
|
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
2020-03-07 02:45:53 +08:00
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
|
2019-10-18 15:26:16 +08:00
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
|
2020-03-02 16:44:33 +08:00
|
|
|
|
2020-03-07 02:45:53 +08:00
|
|
|
// APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
|
2020-03-02 16:44:33 +08:00
|
|
|
mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
|
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
2020-03-07 02:45:53 +08:00
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29")
|
2019-10-18 15:26:16 +08:00
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
|
2019-01-19 18:24:06 +08:00
|
|
|
|
2020-03-02 16:44:33 +08:00
|
|
|
// When cc_library sets use_apex_name_macro: true
|
|
|
|
// apex variants define additional macro to distinguish which apex variant it is built for
|
|
|
|
|
|
|
|
// non-APEX variant does not have __ANDROID_APEX__ defined
|
|
|
|
mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
|
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
|
|
|
|
|
|
|
// APEX variant has __ANDROID_APEX__ defined
|
|
|
|
mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
|
2019-10-30 07:29:25 +08:00
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
2019-10-18 15:26:16 +08:00
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
|
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
|
2019-01-19 18:24:06 +08:00
|
|
|
|
2020-03-02 16:44:33 +08:00
|
|
|
// APEX variant has __ANDROID_APEX__ defined
|
|
|
|
mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
|
2019-10-30 07:29:25 +08:00
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
2019-10-18 15:26:16 +08:00
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
|
|
|
|
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
|
2020-03-21 22:20:55 +08:00
|
|
|
|
|
|
|
// recovery variant does not set __ANDROID_SDK_VERSION__
|
|
|
|
mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
|
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
|
|
|
|
ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__")
|
2019-01-19 18:24:06 +08:00
|
|
|
}
|
2019-01-28 15:16:54 +08:00
|
|
|
|
|
|
|
func TestHeaderLibsDependency(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-01-28 15:16:54 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_headers {
|
|
|
|
name: "mylib_headers",
|
|
|
|
export_include_dirs: ["my_include"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-31 01:49:53 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-01-28 15:16:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
header_libs: ["mylib_headers"],
|
|
|
|
export_header_lib_headers: ["mylib_headers"],
|
|
|
|
stubs: {
|
|
|
|
versions: ["1", "2", "3"],
|
|
|
|
},
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-01-28 15:16:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "otherlib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
|
2019-01-28 15:16:54 +08:00
|
|
|
|
|
|
|
// Ensure that the include path of the header lib is exported to 'otherlib'
|
|
|
|
ensureContains(t, cFlags, "-Imy_include")
|
|
|
|
}
|
2019-01-30 10:07:33 +08:00
|
|
|
|
2020-01-14 08:22:18 +08:00
|
|
|
type fileInApex struct {
|
|
|
|
path string // path in apex
|
2020-01-23 13:36:59 +08:00
|
|
|
src string // src path
|
2020-01-14 08:22:18 +08:00
|
|
|
isLink bool
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
|
2019-10-18 15:26:59 +08:00
|
|
|
t.Helper()
|
2020-01-23 13:36:59 +08:00
|
|
|
apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
|
2019-10-18 15:26:59 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
imageApexDir := "/image.apex/"
|
2020-01-14 08:22:18 +08:00
|
|
|
var ret []fileInApex
|
2019-10-18 15:26:59 +08:00
|
|
|
for _, cmd := range strings.Split(copyCmds, "&&") {
|
|
|
|
cmd = strings.TrimSpace(cmd)
|
|
|
|
if cmd == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
terms := strings.Split(cmd, " ")
|
2020-01-23 13:36:59 +08:00
|
|
|
var dst, src string
|
2020-01-14 08:22:18 +08:00
|
|
|
var isLink bool
|
2019-10-18 15:26:59 +08:00
|
|
|
switch terms[0] {
|
|
|
|
case "mkdir":
|
|
|
|
case "cp":
|
2020-01-14 08:22:18 +08:00
|
|
|
if len(terms) != 3 && len(terms) != 4 {
|
2019-10-18 15:26:59 +08:00
|
|
|
t.Fatal("copyCmds contains invalid cp command", cmd)
|
|
|
|
}
|
2020-01-14 08:22:18 +08:00
|
|
|
dst = terms[len(terms)-1]
|
2020-01-23 13:36:59 +08:00
|
|
|
src = terms[len(terms)-2]
|
2020-01-14 08:22:18 +08:00
|
|
|
isLink = false
|
|
|
|
case "ln":
|
|
|
|
if len(terms) != 3 && len(terms) != 4 {
|
|
|
|
// ln LINK TARGET or ln -s LINK TARGET
|
|
|
|
t.Fatal("copyCmds contains invalid ln command", cmd)
|
|
|
|
}
|
|
|
|
dst = terms[len(terms)-1]
|
2020-01-23 13:36:59 +08:00
|
|
|
src = terms[len(terms)-2]
|
2020-01-14 08:22:18 +08:00
|
|
|
isLink = true
|
|
|
|
default:
|
|
|
|
t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
|
|
|
|
}
|
|
|
|
if dst != "" {
|
2019-10-18 15:26:59 +08:00
|
|
|
index := strings.Index(dst, imageApexDir)
|
|
|
|
if index == -1 {
|
|
|
|
t.Fatal("copyCmds should copy a file to image.apex/", cmd)
|
|
|
|
}
|
|
|
|
dstFile := dst[index+len(imageApexDir):]
|
2020-01-23 13:36:59 +08:00
|
|
|
ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
|
2019-10-18 15:26:59 +08:00
|
|
|
}
|
|
|
|
}
|
2020-01-14 08:22:18 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
|
|
|
|
t.Helper()
|
2020-01-14 08:22:18 +08:00
|
|
|
var failed bool
|
|
|
|
var surplus []string
|
|
|
|
filesMatched := make(map[string]bool)
|
2020-01-23 13:36:59 +08:00
|
|
|
for _, file := range getFiles(t, ctx, moduleName, variant) {
|
2020-02-27 12:31:56 +08:00
|
|
|
mactchFound := false
|
2020-01-14 08:22:18 +08:00
|
|
|
for _, expected := range files {
|
|
|
|
if matched, _ := path.Match(expected, file.path); matched {
|
|
|
|
filesMatched[expected] = true
|
2020-02-27 12:31:56 +08:00
|
|
|
mactchFound = true
|
|
|
|
break
|
2020-01-14 08:22:18 +08:00
|
|
|
}
|
|
|
|
}
|
2020-02-27 12:31:56 +08:00
|
|
|
if !mactchFound {
|
|
|
|
surplus = append(surplus, file.path)
|
|
|
|
}
|
2020-01-14 08:22:18 +08:00
|
|
|
}
|
2019-10-18 15:26:59 +08:00
|
|
|
|
|
|
|
if len(surplus) > 0 {
|
2019-11-06 15:53:07 +08:00
|
|
|
sort.Strings(surplus)
|
2019-10-18 15:26:59 +08:00
|
|
|
t.Log("surplus files", surplus)
|
|
|
|
failed = true
|
|
|
|
}
|
2019-11-06 15:53:07 +08:00
|
|
|
|
|
|
|
if len(files) > len(filesMatched) {
|
|
|
|
var missing []string
|
|
|
|
for _, expected := range files {
|
|
|
|
if !filesMatched[expected] {
|
|
|
|
missing = append(missing, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(missing)
|
2019-10-18 15:26:59 +08:00
|
|
|
t.Log("missing files", missing)
|
|
|
|
failed = true
|
|
|
|
}
|
|
|
|
if failed {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
func TestVndkApexCurrent(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libvndk",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libvndksp",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
support_system_process: true,
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
2019-11-06 15:53:07 +08:00
|
|
|
`+vndkLibrariesTxtFiles("current"))
|
2019-08-23 10:17:39 +08:00
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
|
2019-10-18 15:26:59 +08:00
|
|
|
"lib/libvndk.so",
|
|
|
|
"lib/libvndksp.so",
|
2020-02-27 12:31:56 +08:00
|
|
|
"lib/libc++.so",
|
2019-10-18 15:26:59 +08:00
|
|
|
"lib64/libvndk.so",
|
|
|
|
"lib64/libvndksp.so",
|
2020-02-27 12:31:56 +08:00
|
|
|
"lib64/libc++.so",
|
2019-11-06 15:53:07 +08:00
|
|
|
"etc/llndk.libraries.VER.txt",
|
|
|
|
"etc/vndkcore.libraries.VER.txt",
|
|
|
|
"etc/vndksp.libraries.VER.txt",
|
|
|
|
"etc/vndkprivate.libraries.VER.txt",
|
2019-10-18 15:26:59 +08:00
|
|
|
})
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestVndkApexWithPrebuilt(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_prebuilt_library_shared {
|
2019-10-18 15:26:59 +08:00
|
|
|
name: "libvndk",
|
|
|
|
srcs: ["libvndk.so"],
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-10-18 15:26:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_prebuilt_library_shared {
|
|
|
|
name: "libvndk.arm",
|
|
|
|
srcs: ["libvndk.arm.so"],
|
2019-08-23 10:17:39 +08:00
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
2019-10-18 15:26:59 +08:00
|
|
|
enabled: false,
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
},
|
2019-08-23 10:17:39 +08:00
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
2019-11-06 15:53:07 +08:00
|
|
|
`+vndkLibrariesTxtFiles("current"),
|
|
|
|
withFiles(map[string][]byte{
|
|
|
|
"libvndk.so": nil,
|
|
|
|
"libvndk.arm.so": nil,
|
|
|
|
}))
|
2019-08-23 10:17:39 +08:00
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
|
2019-10-18 15:26:59 +08:00
|
|
|
"lib/libvndk.so",
|
|
|
|
"lib/libvndk.arm.so",
|
|
|
|
"lib64/libvndk.so",
|
2020-02-27 12:31:56 +08:00
|
|
|
"lib/libc++.so",
|
|
|
|
"lib64/libc++.so",
|
2019-11-06 15:53:07 +08:00
|
|
|
"etc/*",
|
2019-10-18 15:26:59 +08:00
|
|
|
})
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-06 15:53:07 +08:00
|
|
|
func vndkLibrariesTxtFiles(vers ...string) (result string) {
|
|
|
|
for _, v := range vers {
|
|
|
|
if v == "current" {
|
2019-12-30 10:12:55 +08:00
|
|
|
for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
|
2019-11-06 15:53:07 +08:00
|
|
|
result += `
|
|
|
|
vndk_libraries_txt {
|
|
|
|
name: "` + txt + `.libraries.txt",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
|
|
|
|
result += `
|
|
|
|
prebuilt_etc {
|
|
|
|
name: "` + txt + `.libraries.` + v + `.txt",
|
|
|
|
src: "dummy.txt",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
func TestVndkApexVersion(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex_v27",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-23 10:17:39 +08:00
|
|
|
vndk_version: "27",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
2019-10-18 15:26:59 +08:00
|
|
|
vndk_prebuilt_shared {
|
|
|
|
name: "libvndk27",
|
|
|
|
version: "27",
|
2019-08-23 10:17:39 +08:00
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
2019-10-18 15:26:59 +08:00
|
|
|
target_arch: "arm64",
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: ["libvndk27_arm.so"],
|
|
|
|
},
|
|
|
|
arm64: {
|
|
|
|
srcs: ["libvndk27_arm64.so"],
|
|
|
|
},
|
|
|
|
},
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex_v27" ],
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
vndk_prebuilt_shared {
|
|
|
|
name: "libvndk27",
|
|
|
|
version: "27",
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
2019-10-18 15:26:59 +08:00
|
|
|
target_arch: "x86_64",
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
srcs: ["libvndk27_x86.so"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
srcs: ["libvndk27_x86_64.so"],
|
|
|
|
},
|
|
|
|
},
|
2019-11-06 15:53:07 +08:00
|
|
|
}
|
|
|
|
`+vndkLibrariesTxtFiles("27"),
|
|
|
|
withFiles(map[string][]byte{
|
|
|
|
"libvndk27_arm.so": nil,
|
|
|
|
"libvndk27_arm64.so": nil,
|
|
|
|
"libvndk27_x86.so": nil,
|
|
|
|
"libvndk27_x86_64.so": nil,
|
|
|
|
}))
|
2019-08-23 10:17:39 +08:00
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
|
2019-10-18 15:26:59 +08:00
|
|
|
"lib/libvndk27_arm.so",
|
|
|
|
"lib64/libvndk27_arm64.so",
|
2019-11-06 15:53:07 +08:00
|
|
|
"etc/*",
|
2019-10-18 15:26:59 +08:00
|
|
|
})
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
|
|
|
|
testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex_v27",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-23 10:17:39 +08:00
|
|
|
vndk_version: "27",
|
|
|
|
}
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex_v27_other",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-23 10:17:39 +08:00
|
|
|
vndk_version: "27",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libvndk",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
vndk_prebuilt_shared {
|
|
|
|
name: "libvndk",
|
|
|
|
version: "27",
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
srcs: ["libvndk.so"],
|
|
|
|
}
|
|
|
|
`, withFiles(map[string][]byte{
|
|
|
|
"libvndk.so": nil,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2019-10-01 19:02:42 +08:00
|
|
|
func TestVndkApexNameRule(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-10-01 19:02:42 +08:00
|
|
|
}
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex_v28",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-10-01 19:02:42 +08:00
|
|
|
vndk_version: "28",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
2019-11-06 15:53:07 +08:00
|
|
|
}`+vndkLibrariesTxtFiles("28", "current"))
|
2019-10-01 19:02:42 +08:00
|
|
|
|
|
|
|
assertApexName := func(expected, moduleName string) {
|
2020-01-23 13:36:59 +08:00
|
|
|
bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
|
2019-10-01 19:02:42 +08:00
|
|
|
actual := proptools.String(bundle.properties.Apex_name)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Errorf("Got '%v', expected '%v'", actual, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assertApexName("com.android.vndk.vVER", "myapex")
|
|
|
|
assertApexName("com.android.vndk.v28", "myapex_v28")
|
|
|
|
}
|
|
|
|
|
2019-08-23 10:17:39 +08:00
|
|
|
func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libvndk",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
vendor_available: true,
|
|
|
|
native_bridge_supported: true,
|
|
|
|
host_supported: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
2019-11-06 15:53:07 +08:00
|
|
|
`+vndkLibrariesTxtFiles("current"),
|
|
|
|
withTargets(map[android.OsType][]android.Target{
|
|
|
|
android.Android: []android.Target{
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
|
|
|
|
},
|
|
|
|
}))
|
2019-08-23 10:17:39 +08:00
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
|
2019-10-18 15:26:59 +08:00
|
|
|
"lib/libvndk.so",
|
|
|
|
"lib64/libvndk.so",
|
2020-02-27 12:31:56 +08:00
|
|
|
"lib/libc++.so",
|
|
|
|
"lib64/libc++.so",
|
2019-11-06 15:53:07 +08:00
|
|
|
"etc/*",
|
2019-10-18 15:26:59 +08:00
|
|
|
})
|
2019-08-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
|
|
|
|
testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
|
|
|
|
apex_vndk {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-23 10:17:39 +08:00
|
|
|
native_bridge_supported: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libvndk",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
vendor_available: true,
|
|
|
|
native_bridge_supported: true,
|
|
|
|
host_supported: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2019-10-18 15:26:59 +08:00
|
|
|
func TestVndkApexWithBinder32(t *testing.T) {
|
2019-11-06 15:53:07 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-10-18 15:26:59 +08:00
|
|
|
apex_vndk {
|
|
|
|
name: "myapex_v27",
|
|
|
|
key: "myapex.key",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-10-18 15:26:59 +08:00
|
|
|
vndk_version: "27",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
vndk_prebuilt_shared {
|
|
|
|
name: "libvndk27",
|
|
|
|
version: "27",
|
|
|
|
target_arch: "arm",
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: ["libvndk27.so"],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
vndk_prebuilt_shared {
|
|
|
|
name: "libvndk27",
|
|
|
|
version: "27",
|
|
|
|
target_arch: "arm",
|
|
|
|
binder32bit: true,
|
|
|
|
vendor_available: true,
|
|
|
|
vndk: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: ["libvndk27binder32.so"],
|
|
|
|
}
|
|
|
|
},
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex_v27" ],
|
2019-10-18 15:26:59 +08:00
|
|
|
}
|
2019-11-06 15:53:07 +08:00
|
|
|
`+vndkLibrariesTxtFiles("27"),
|
2019-10-18 15:26:59 +08:00
|
|
|
withFiles(map[string][]byte{
|
|
|
|
"libvndk27.so": nil,
|
|
|
|
"libvndk27binder32.so": nil,
|
|
|
|
}),
|
|
|
|
withBinder32bit,
|
|
|
|
withTargets(map[android.OsType][]android.Target{
|
|
|
|
android.Android: []android.Target{
|
|
|
|
{Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
|
2019-10-18 15:26:59 +08:00
|
|
|
"lib/libvndk27binder32.so",
|
2019-11-06 15:53:07 +08:00
|
|
|
"etc/*",
|
2019-10-18 15:26:59 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-01 16:41:43 +08:00
|
|
|
func TestDependenciesInApexManifest(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex_nodep",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["lib_nodep"],
|
|
|
|
compile_multilib: "both",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex_dep",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["lib_dep"],
|
|
|
|
compile_multilib: "both",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex_provider",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
compile_multilib: "both",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "myapex_selfcontained",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["lib_dep", "libfoo"],
|
|
|
|
compile_multilib: "both",
|
2019-11-20 01:26:02 +08:00
|
|
|
file_contexts: ":myapex-file_contexts",
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "lib_nodep",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex_nodep" ],
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "lib_dep",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["libfoo"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [
|
|
|
|
"myapex_dep",
|
|
|
|
"myapex_provider",
|
|
|
|
"myapex_selfcontained",
|
|
|
|
],
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["mytest.cpp"],
|
|
|
|
stubs: {
|
|
|
|
versions: ["1"],
|
|
|
|
},
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [
|
|
|
|
"myapex_provider",
|
|
|
|
"myapex_selfcontained",
|
|
|
|
],
|
2019-08-01 16:41:43 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-09-26 23:38:03 +08:00
|
|
|
var apexManifestRule android.TestingBuildParams
|
2019-08-01 16:41:43 +08:00
|
|
|
var provideNativeLibs, requireNativeLibs []string
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
|
2019-09-26 23:38:03 +08:00
|
|
|
provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
|
|
|
|
requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
|
2019-08-01 16:41:43 +08:00
|
|
|
ensureListEmpty(t, provideNativeLibs)
|
|
|
|
ensureListEmpty(t, requireNativeLibs)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
|
2019-09-26 23:38:03 +08:00
|
|
|
provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
|
|
|
|
requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
|
2019-08-01 16:41:43 +08:00
|
|
|
ensureListEmpty(t, provideNativeLibs)
|
|
|
|
ensureListContains(t, requireNativeLibs, "libfoo.so")
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
|
2019-09-26 23:38:03 +08:00
|
|
|
provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
|
|
|
|
requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
|
2019-08-01 16:41:43 +08:00
|
|
|
ensureListContains(t, provideNativeLibs, "libfoo.so")
|
|
|
|
ensureListEmpty(t, requireNativeLibs)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
|
2019-09-26 23:38:03 +08:00
|
|
|
provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
|
|
|
|
requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
|
2019-08-01 16:41:43 +08:00
|
|
|
ensureListContains(t, provideNativeLibs, "libfoo.so")
|
|
|
|
ensureListEmpty(t, requireNativeLibs)
|
|
|
|
}
|
|
|
|
|
2019-09-26 23:38:03 +08:00
|
|
|
func TestApexName(t *testing.T) {
|
2020-02-05 16:19:28 +08:00
|
|
|
ctx, config := testApex(t, `
|
2019-09-26 23:38:03 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
apex_name: "com.android.myapex",
|
2020-02-05 16:19:28 +08:00
|
|
|
native_shared_libs: ["mylib"],
|
2019-09-26 23:38:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
2020-02-05 16:19:28 +08:00
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
2019-09-26 23:38:03 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-09-26 23:38:03 +08:00
|
|
|
apexManifestRule := module.Rule("apexManifestRule")
|
|
|
|
ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
|
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
|
2020-02-05 16:19:28 +08:00
|
|
|
|
|
|
|
apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
|
|
|
|
data := android.AndroidMkDataForTest(t, config, "", apexBundle)
|
|
|
|
name := apexBundle.BaseModuleName()
|
|
|
|
prefix := "TARGET_"
|
|
|
|
var builder strings.Builder
|
|
|
|
data.Custom(&builder, name, prefix, "", data)
|
|
|
|
androidMk := builder.String()
|
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n")
|
|
|
|
ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
|
2019-09-26 23:38:03 +08:00
|
|
|
}
|
|
|
|
|
2019-02-08 05:20:53 +08:00
|
|
|
func TestNonTestApex(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-02-08 05:20:53 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib_common"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib_common",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-02-08 05:20:53 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-02-08 05:20:53 +08:00
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
|
|
|
|
t.Log("Apex was a test apex!")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
// Ensure that main rule creates an output
|
|
|
|
ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
|
|
|
|
|
|
|
|
// Ensure that apex variant is created for the direct dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
|
2019-02-08 05:20:53 +08:00
|
|
|
|
|
|
|
// Ensure that both direct and indirect deps are copied into apex
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
|
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
// Ensure that the platform variant ends with _shared
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
|
2019-02-08 05:20:53 +08:00
|
|
|
|
|
|
|
if !android.InAnyApex("mylib_common") {
|
|
|
|
t.Log("Found mylib_common not in any apex!")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTestApex(t *testing.T) {
|
|
|
|
if android.InAnyApex("mylib_common_test") {
|
|
|
|
t.Fatal("mylib_common_test must not be used in any other tests since this checks that global state is not updated in an illegal way!")
|
|
|
|
}
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-02-08 05:20:53 +08:00
|
|
|
apex_test {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib_common_test"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib_common_test",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-02-08 05:20:53 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-02-08 05:20:53 +08:00
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
|
|
|
|
t.Log("Apex was not a test apex!")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
// Ensure that main rule creates an output
|
|
|
|
ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
|
|
|
|
|
|
|
|
// Ensure that apex variant is created for the direct dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
|
2019-02-08 05:20:53 +08:00
|
|
|
|
|
|
|
// Ensure that both direct and indirect deps are copied into apex
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
|
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
// Ensure that the platform variant ends with _shared
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
|
2019-02-08 05:20:53 +08:00
|
|
|
}
|
|
|
|
|
2019-01-30 10:07:33 +08:00
|
|
|
func TestApexWithTarget(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-01-30 10:07:33 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
multilib: {
|
|
|
|
first: {
|
|
|
|
native_shared_libs: ["mylib_common"],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
android: {
|
|
|
|
multilib: {
|
|
|
|
first: {
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
host: {
|
|
|
|
multilib: {
|
|
|
|
first: {
|
|
|
|
native_shared_libs: ["mylib2"],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-01-30 10:07:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib_common",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
compile_multilib: "first",
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-01-30 10:07:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib2",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
compile_multilib: "first",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
2019-01-30 10:07:33 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that main rule creates an output
|
|
|
|
ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
|
|
|
|
|
|
|
|
// Ensure that apex variant is created for the direct dep
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
|
2019-01-30 10:07:33 +08:00
|
|
|
|
|
|
|
// Ensure that both direct and indirect deps are copied into apex
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
|
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
// Ensure that the platform variant ends with _shared
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
|
2019-01-30 10:07:33 +08:00
|
|
|
}
|
2019-02-05 23:16:29 +08:00
|
|
|
|
|
|
|
func TestApexWithShBinary(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-02-05 23:16:29 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
binaries: ["myscript"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
sh_binary {
|
|
|
|
name: "myscript",
|
|
|
|
src: "mylib.cpp",
|
|
|
|
filename: "myscript.sh",
|
|
|
|
sub_dir: "script",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
2019-02-05 23:16:29 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
|
|
|
|
}
|
2019-03-15 01:13:21 +08:00
|
|
|
|
2019-11-20 00:49:42 +08:00
|
|
|
func TestApexInVariousPartition(t *testing.T) {
|
|
|
|
testcases := []struct {
|
|
|
|
propName, parition, flattenedPartition string
|
|
|
|
}{
|
|
|
|
{"", "system", "system_ext"},
|
|
|
|
{"product_specific: true", "product", "product"},
|
|
|
|
{"soc_specific: true", "vendor", "vendor"},
|
|
|
|
{"proprietary: true", "vendor", "vendor"},
|
|
|
|
{"vendor: true", "vendor", "vendor"},
|
|
|
|
{"system_ext_specific: true", "system_ext", "system_ext"},
|
|
|
|
}
|
|
|
|
for _, tc := range testcases {
|
|
|
|
t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
`+tc.propName+`
|
|
|
|
}
|
2019-03-15 01:13:21 +08:00
|
|
|
|
2019-11-20 00:49:42 +08:00
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
2019-03-15 01:13:21 +08:00
|
|
|
|
2019-11-20 00:49:42 +08:00
|
|
|
apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
|
|
|
|
expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
|
|
|
|
actual := apex.installDir.String()
|
|
|
|
if actual != expected {
|
|
|
|
t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
|
|
|
|
}
|
2019-03-15 01:13:21 +08:00
|
|
|
|
2019-11-20 00:49:42 +08:00
|
|
|
flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
|
|
|
|
expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
|
|
|
|
actual = flattened.installDir.String()
|
|
|
|
if actual != expected {
|
|
|
|
t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
|
|
|
|
}
|
|
|
|
})
|
2019-03-15 01:13:21 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 00:11:21 +08:00
|
|
|
|
2019-11-20 01:26:02 +08:00
|
|
|
func TestFileContexts(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
actual := apexRule.Args["file_contexts"]
|
|
|
|
expected := "system/sepolicy/apex/myapex-file_contexts"
|
|
|
|
if actual != expected {
|
|
|
|
t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
file_contexts: "my_own_file_contexts",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`, withFiles(map[string][]byte{
|
|
|
|
"my_own_file_contexts": nil,
|
|
|
|
}))
|
|
|
|
|
|
|
|
testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
product_specific: true,
|
|
|
|
file_contexts: "product_specific_file_contexts",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
ctx, _ = testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
product_specific: true,
|
|
|
|
file_contexts: "product_specific_file_contexts",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`, withFiles(map[string][]byte{
|
|
|
|
"product_specific_file_contexts": nil,
|
|
|
|
}))
|
|
|
|
module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
|
|
|
apexRule = module.Rule("apexRule")
|
|
|
|
actual = apexRule.Args["file_contexts"]
|
|
|
|
expected = "product_specific_file_contexts"
|
|
|
|
if actual != expected {
|
|
|
|
t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, _ = testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
product_specific: true,
|
|
|
|
file_contexts: ":my-file-contexts",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "my-file-contexts",
|
|
|
|
srcs: ["product_specific_file_contexts"],
|
|
|
|
}
|
|
|
|
`, withFiles(map[string][]byte{
|
|
|
|
"product_specific_file_contexts": nil,
|
|
|
|
}))
|
|
|
|
module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
|
|
|
apexRule = module.Rule("apexRule")
|
|
|
|
actual = apexRule.Args["file_contexts"]
|
|
|
|
expected = "product_specific_file_contexts"
|
|
|
|
if actual != expected {
|
|
|
|
t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 00:11:21 +08:00
|
|
|
func TestApexKeyFromOtherModule(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-03-21 00:11:21 +08:00
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: ":my.avbpubkey",
|
|
|
|
private_key: ":my.pem",
|
|
|
|
product_specific: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "my.avbpubkey",
|
|
|
|
srcs: ["testkey2.avbpubkey"],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "my.pem",
|
|
|
|
srcs: ["testkey2.pem"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
|
|
|
|
expected_pubkey := "testkey2.avbpubkey"
|
|
|
|
actual_pubkey := apex_key.public_key_file.String()
|
|
|
|
if actual_pubkey != expected_pubkey {
|
|
|
|
t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
|
|
|
|
}
|
|
|
|
expected_privkey := "testkey2.pem"
|
|
|
|
actual_privkey := apex_key.private_key_file.String()
|
|
|
|
if actual_privkey != expected_privkey {
|
|
|
|
t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 06:07:36 +08:00
|
|
|
|
|
|
|
func TestPrebuilt(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-03-27 06:07:36 +08:00
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex",
|
2019-03-29 13:23:10 +08:00
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
src: "myapex-arm64.apex",
|
|
|
|
},
|
|
|
|
arm: {
|
|
|
|
src: "myapex-arm.apex",
|
|
|
|
},
|
|
|
|
},
|
2019-03-27 06:07:36 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
|
|
|
|
|
2019-03-29 13:23:10 +08:00
|
|
|
expectedInput := "myapex-arm64.apex"
|
|
|
|
if prebuilt.inputApex.String() != expectedInput {
|
|
|
|
t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
|
|
|
|
}
|
2019-03-27 06:07:36 +08:00
|
|
|
}
|
2019-04-05 01:09:48 +08:00
|
|
|
|
|
|
|
func TestPrebuiltFilenameOverride(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-04-05 01:09:48 +08:00
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex",
|
|
|
|
src: "myapex-arm.apex",
|
|
|
|
filename: "notmyapex.apex",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
|
|
|
|
|
|
|
|
expected := "notmyapex.apex"
|
|
|
|
if p.installFilename != expected {
|
|
|
|
t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 02:20:53 +08:00
|
|
|
|
2019-07-17 09:25:41 +08:00
|
|
|
func TestPrebuiltOverrides(t *testing.T) {
|
|
|
|
ctx, config := testApex(t, `
|
|
|
|
prebuilt_apex {
|
|
|
|
name: "myapex.prebuilt",
|
|
|
|
src: "myapex-arm.apex",
|
|
|
|
overrides: [
|
|
|
|
"myapex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
|
|
|
|
|
|
|
|
expected := []string{"myapex"}
|
2019-12-03 12:24:29 +08:00
|
|
|
actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
|
2019-07-17 09:25:41 +08:00
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
2019-11-14 16:17:03 +08:00
|
|
|
t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
|
2019-07-17 09:25:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 19:48:34 +08:00
|
|
|
func TestApexWithTests(t *testing.T) {
|
2019-07-29 23:22:59 +08:00
|
|
|
ctx, config := testApex(t, `
|
2019-06-26 19:48:34 +08:00
|
|
|
apex_test {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
tests: [
|
|
|
|
"mytest",
|
2019-06-28 22:41:19 +08:00
|
|
|
"mytests",
|
2019-06-26 19:48:34 +08:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_test {
|
|
|
|
name: "mytest",
|
|
|
|
gtest: false,
|
|
|
|
srcs: ["mytest.cpp"],
|
|
|
|
relative_install_path: "test",
|
|
|
|
system_shared_libs: [],
|
|
|
|
static_executable: true,
|
|
|
|
stl: "none",
|
|
|
|
}
|
2019-06-28 22:41:19 +08:00
|
|
|
|
|
|
|
cc_test {
|
|
|
|
name: "mytests",
|
|
|
|
gtest: false,
|
|
|
|
srcs: [
|
|
|
|
"mytest1.cpp",
|
|
|
|
"mytest2.cpp",
|
|
|
|
"mytest3.cpp",
|
|
|
|
],
|
|
|
|
test_per_src: true,
|
|
|
|
relative_install_path: "test",
|
|
|
|
system_shared_libs: [],
|
|
|
|
static_executable: true,
|
|
|
|
stl: "none",
|
|
|
|
}
|
2019-06-26 19:48:34 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
|
2019-06-26 19:48:34 +08:00
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
// Ensure that test dep is copied into apex.
|
|
|
|
ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
|
2019-06-28 22:41:19 +08:00
|
|
|
|
|
|
|
// Ensure that test deps built with `test_per_src` are copied into apex.
|
|
|
|
ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
|
2019-07-29 23:22:59 +08:00
|
|
|
|
|
|
|
// Ensure the module is correctly translated.
|
2019-10-22 12:58:29 +08:00
|
|
|
apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
|
2019-07-29 23:22:59 +08:00
|
|
|
data := android.AndroidMkDataForTest(t, config, "", apexBundle)
|
|
|
|
name := apexBundle.BaseModuleName()
|
|
|
|
prefix := "TARGET_"
|
|
|
|
var builder strings.Builder
|
|
|
|
data.Custom(&builder, name, prefix, "", data)
|
|
|
|
androidMk := builder.String()
|
2019-10-18 15:26:59 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
|
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
|
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
|
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
|
2019-11-12 12:03:50 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
|
2019-10-18 15:26:59 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
|
2019-07-29 23:22:59 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
|
2019-06-26 19:48:34 +08:00
|
|
|
}
|
|
|
|
|
2019-12-05 15:27:44 +08:00
|
|
|
func TestInstallExtraFlattenedApexes(t *testing.T) {
|
|
|
|
ctx, config := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
|
|
|
|
})
|
|
|
|
ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
|
2020-01-14 17:38:44 +08:00
|
|
|
ensureListContains(t, ab.requiredDeps, "myapex.flattened")
|
2019-12-05 15:27:44 +08:00
|
|
|
mk := android.AndroidMkDataForTest(t, config, "", ab)
|
|
|
|
var builder strings.Builder
|
|
|
|
mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
|
|
|
|
androidMk := builder.String()
|
|
|
|
ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
|
|
|
|
}
|
|
|
|
|
2019-06-27 10:30:33 +08:00
|
|
|
func TestApexUsesOtherApex(t *testing.T) {
|
2019-07-17 09:25:41 +08:00
|
|
|
ctx, _ := testApex(t, `
|
2019-06-27 10:30:33 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
uses: ["commonapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "commonapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libcommon"],
|
|
|
|
provide_cpp_shared_libs: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["libcommon"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-06-27 10:30:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libcommon",
|
|
|
|
srcs: ["mylib_common.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
// TODO: remove //apex_available:platform
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"commonapex",
|
|
|
|
"myapex",
|
|
|
|
],
|
2019-06-27 10:30:33 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-06-27 10:30:33 +08:00
|
|
|
apexRule1 := module1.Rule("apexRule")
|
|
|
|
copyCmds1 := apexRule1.Args["copy_commands"]
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
|
2019-06-27 10:30:33 +08:00
|
|
|
apexRule2 := module2.Rule("apexRule")
|
|
|
|
copyCmds2 := apexRule2.Args["copy_commands"]
|
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
|
2019-06-27 10:30:33 +08:00
|
|
|
ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
|
|
|
|
ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
|
|
|
|
ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApexUsesFailsIfNotProvided(t *testing.T) {
|
|
|
|
testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
uses: ["commonapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "commonapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
testApexError(t, `uses: "commonapex" is not a provider`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
uses: ["commonapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "commonapex",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
|
|
|
|
testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
use_vendor: true,
|
|
|
|
uses: ["commonapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "commonapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
provide_cpp_shared_libs: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
2019-11-01 02:14:38 +08:00
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
setUseVendorWhitelistForTest(config, []string{"myapex"})
|
|
|
|
})
|
2019-06-27 10:30:33 +08:00
|
|
|
}
|
|
|
|
|
2019-08-23 10:18:57 +08:00
|
|
|
func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
|
|
|
|
testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
enabled: false,
|
2020-03-10 05:23:13 +08:00
|
|
|
apex_available: ["myapex"],
|
2019-08-23 10:18:57 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
java_libs: ["myjar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
enabled: false,
|
2020-03-10 05:23:13 +08:00
|
|
|
apex_available: ["myapex"],
|
2019-08-23 10:18:57 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:55:42 +08:00
|
|
|
func TestApexWithApps(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
apps: [
|
|
|
|
"AppFoo",
|
2019-10-17 11:54:30 +08:00
|
|
|
"AppFooPriv",
|
2019-08-27 12:55:42 +08:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "AppFoo",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
2019-11-08 14:53:48 +08:00
|
|
|
jni_libs: ["libjni"],
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-08-27 12:55:42 +08:00
|
|
|
}
|
2019-10-17 11:54:30 +08:00
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "AppFooPriv",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
privileged: true,
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-10-17 11:54:30 +08:00
|
|
|
}
|
2019-11-08 14:53:48 +08:00
|
|
|
|
|
|
|
cc_library_shared {
|
|
|
|
name: "libjni",
|
|
|
|
srcs: ["mylib.cpp"],
|
2020-02-25 15:59:29 +08:00
|
|
|
shared_libs: ["libfoo"],
|
2019-11-08 14:53:48 +08:00
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-31 01:49:53 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2020-02-25 15:59:29 +08:00
|
|
|
sdk_version: "current",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_shared {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
sdk_version: "current",
|
2019-11-08 14:53:48 +08:00
|
|
|
}
|
2019-08-27 12:55:42 +08:00
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-08-27 12:55:42 +08:00
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
|
2019-10-17 11:54:30 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
|
2019-11-11 09:14:32 +08:00
|
|
|
|
2020-02-25 15:59:29 +08:00
|
|
|
appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs")
|
|
|
|
// JNI libraries are uncompressed
|
2019-11-11 09:14:32 +08:00
|
|
|
if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
|
2020-02-25 15:59:29 +08:00
|
|
|
t.Errorf("jni libs are not uncompressed for AppFoo")
|
|
|
|
}
|
|
|
|
// JNI libraries including transitive deps are
|
|
|
|
for _, jni := range []string{"libjni", "libfoo"} {
|
|
|
|
jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
|
|
|
|
// ... embedded inside APK (jnilibs.zip)
|
|
|
|
ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String())
|
|
|
|
// ... and not directly inside the APEX
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so")
|
2019-11-11 09:14:32 +08:00
|
|
|
}
|
2019-10-27 07:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestApexWithAppImports(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
apps: [
|
|
|
|
"AppFooPrebuilt",
|
|
|
|
"AppFooPrivPrebuilt",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_import {
|
|
|
|
name: "AppFooPrebuilt",
|
|
|
|
apk: "PrebuiltAppFoo.apk",
|
|
|
|
presigned: true,
|
|
|
|
dex_preopt: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app_import {
|
|
|
|
name: "AppFooPrivPrebuilt",
|
|
|
|
apk: "PrebuiltAppFooPriv.apk",
|
|
|
|
privileged: true,
|
|
|
|
presigned: true,
|
|
|
|
dex_preopt: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
2019-10-22 12:58:29 +08:00
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
2019-10-27 07:29:22 +08:00
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
2019-08-27 12:55:42 +08:00
|
|
|
|
2019-10-27 07:29:22 +08:00
|
|
|
ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
|
2019-08-27 12:55:42 +08:00
|
|
|
}
|
|
|
|
|
2019-12-21 06:58:03 +08:00
|
|
|
func TestApexWithTestHelperApp(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
apps: [
|
|
|
|
"TesterHelpAppFoo",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_test_helper_app {
|
|
|
|
name: "TesterHelpAppFoo",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-12-21 06:58:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
|
|
|
|
}
|
|
|
|
|
2019-11-13 09:50:48 +08:00
|
|
|
func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
|
|
|
|
// libfoo's apex_available comes from cc_defaults
|
2020-03-10 05:23:13 +08:00
|
|
|
testApexError(t, `requires "libfoo" that is not available for the APEX`, `
|
2019-11-13 09:50:48 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "otherapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_defaults {
|
|
|
|
name: "libfoo-defaults",
|
|
|
|
apex_available: ["otherapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
defaults: ["libfoo-defaults"],
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
}`)
|
|
|
|
}
|
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
func TestApexAvailable_DirectDep(t *testing.T) {
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
// libfoo is not available to myapex, but only to otherapex
|
|
|
|
testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "otherapex",
|
|
|
|
key: "otherapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "otherapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: ["otherapex"],
|
|
|
|
}`)
|
2020-03-31 00:54:29 +08:00
|
|
|
}
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
func TestApexAvailable_IndirectDep(t *testing.T) {
|
2020-03-10 05:23:13 +08:00
|
|
|
// libbbaz is an indirect dep
|
2020-03-31 00:58:21 +08:00
|
|
|
testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path:
|
2020-03-31 18:31:36 +08:00
|
|
|
.*via tag apex\.dependencyTag.*"sharedLib".*
|
2020-03-31 00:58:21 +08:00
|
|
|
.*-> libfoo.*link:shared.*
|
2020-03-31 22:23:40 +08:00
|
|
|
.*via tag cc\.DependencyTag.*"shared".*
|
2020-03-31 00:58:21 +08:00
|
|
|
.*-> libbar.*link:shared.*
|
2020-03-31 22:23:40 +08:00
|
|
|
.*via tag cc\.DependencyTag.*"shared".*
|
|
|
|
.*-> libbaz.*link:shared.*`, `
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
shared_libs: ["libbar"],
|
|
|
|
system_shared_libs: [],
|
2020-03-10 05:23:13 +08:00
|
|
|
apex_available: ["myapex"],
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
stl: "none",
|
2020-03-10 05:23:13 +08:00
|
|
|
shared_libs: ["libbaz"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbaz",
|
|
|
|
stl: "none",
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
system_shared_libs: [],
|
|
|
|
}`)
|
2020-03-31 00:54:29 +08:00
|
|
|
}
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
func TestApexAvailable_InvalidApexName(t *testing.T) {
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
testApexError(t, "\"otherapex\" is not a valid module name", `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: ["otherapex"],
|
|
|
|
}`)
|
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
testApex(t, `
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo", "libbar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
2020-03-01 16:29:06 +08:00
|
|
|
runtime_libs: ["libbaz"],
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
apex_available: ["myapex"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbar",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: ["//apex_available:anyapex"],
|
2020-03-01 16:29:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libbaz",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
stubs: {
|
|
|
|
versions: ["10", "20", "30"],
|
|
|
|
},
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
}`)
|
2020-03-31 00:54:29 +08:00
|
|
|
}
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
func TestApexAvailable_CreatedForPlatform(t *testing.T) {
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
// check that libfoo and libbar are created only for myapex, but not for the platform
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-31 01:49:53 +08:00
|
|
|
// TODO(jiyong) the checks for the platform variant are removed because we now create
|
|
|
|
// the platform variant regardless of the apex_availability. Instead, we will make sure that
|
|
|
|
// the platform variants are not used from other platform modules. When that is done,
|
|
|
|
// these checks will be replaced by expecting a specific error message that will be
|
|
|
|
// emitted when the platform variant is used.
|
|
|
|
// ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
// ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
|
|
|
|
// ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
// ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
ctx, _ := testApex(t, `
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: ["//apex_available:platform"],
|
|
|
|
}`)
|
|
|
|
|
|
|
|
// check that libfoo is created only for the platform
|
2019-11-21 08:39:12 +08:00
|
|
|
ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
|
2020-03-31 00:54:29 +08:00
|
|
|
}
|
2019-10-07 14:47:24 +08:00
|
|
|
|
2020-03-31 00:54:29 +08:00
|
|
|
func TestApexAvailable_CreatedForApex(t *testing.T) {
|
|
|
|
testApex(t, `
|
2019-10-07 14:47:24 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["libfoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "libfoo",
|
|
|
|
stl: "none",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: ["myapex"],
|
|
|
|
static: {
|
|
|
|
apex_available: ["//apex_available:platform"],
|
|
|
|
},
|
|
|
|
}`)
|
|
|
|
|
|
|
|
// shared variant of libfoo is only available to myapex
|
apex_available tracks static dependencies
This change fixes a bug that apex_available is not enforced for static
dependencies. For example, a module with 'apex_available:
["//apex_available:platform"]' was able to be statically linked to any
APEX. This was happening because the check was done on the modules that
are actually installed to an APEX. Static dependencies of the modules
were not counted as they are not installed to the APEX as files.
Fixing this bug by doing the check by traversing the tree in the method
checkApexAvailability.
This change includes a few number of related changes:
1) DepIsInSameApex implementation for cc.Module was changed as well.
Previuosly, it returned false only when the dependency is actually a
stub variant of a lib. Now, it returns false when the dependency has one
or more stub variants. To understand why, we need to recall that when
there is a dependency to a lib having stubs, we actually create two
dependencies: to the non-stub variant and to the stub variant during the
DepsMutator phase. And later in the build action generation phase, we
choose one of them depending on the context. Also recall that an APEX
variant is created only when DepIsInSameApex returns true. Given these,
with the previous implementatin of DepIsInSameApex, we did create apex
variants of the non-stub variant of the dependency, while not creating
the apex variant for the stub variant. This is not right; we needlessly
created the apex variant. The extra apex variant has caused no harm so
far, but since the apex_available check became more correct, it actually
breaks the build. To fix the issue, we stop creating the APEX variant
both for non-stub and stub variants.
2) platform variant is created regardless of the apex_available value.
This is required for the case when a library X that provides stub is in
an APEX A and is configured to be available only for A. In that case,
libs in other APEX can't use the stub library since the stub library is
mutated only for apex A. By creating the platform variant for the stub
library, it can be used from outside as the default dependency variation
is set to the platform variant when creating the APEX variations.
3) The ApexAvailableWhitelist is added with the dependencies that were
revealed with this change.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
(cherry picked from commit fa89944c79f19552e906b41fd03a4981903eee7e)
Change-Id: Iaedc05494085ff4e8af227a6392bdd0c338b8e6e
2020-01-31 01:49:53 +08:00
|
|
|
// TODO(jiyong) the checks for the platform variant are removed because we now create
|
|
|
|
// the platform variant regardless of the apex_availability. Instead, we will make sure that
|
|
|
|
// the platform variants are not used from other platform modules. When that is done,
|
|
|
|
// these checks will be replaced by expecting a specific error message that will be
|
|
|
|
// emitted when the platform variant is used.
|
|
|
|
// ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
|
|
|
|
// ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
|
|
|
|
// // but the static variant is available to both myapex and the platform
|
|
|
|
// ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
|
|
|
|
// ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
|
Add apex_available to control the availablity of a module to APEXes
apex_available property controls the availability of a module to APEXes.
For example, `apex_available: ["myapex", "otherapex"]` makes the module
available only to the two APEXes: myapex and otherapex, and nothing
else, even to the platform.
If the module is intended to be available to any APEX, then a pseudo
name "//apex_available:anyapex" can be used.
If the module is intended to be available to the platform, then another
pseudo name "//apex_available:platform" is used.
For now, if unspecified, this property defaults to ["//apex_available:platform",
"//apex_available:anyapex"], which means the module is available to everybody.
This will be reduced to ["//apex_available:platform"], when marking for
apex_available for existing modules are finished.
Bug: 139870423
Bug: 128708192
Test: m
Change-Id: Id4b233c3056c7858f984cbf9427cfac4118b2682
2019-09-30 15:04:35 +08:00
|
|
|
}
|
|
|
|
|
2019-11-15 17:40:32 +08:00
|
|
|
func TestOverrideApex(t *testing.T) {
|
2019-11-23 06:50:42 +08:00
|
|
|
ctx, config := testApex(t, `
|
2019-11-15 17:40:32 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
apps: ["app"],
|
2019-12-20 09:32:06 +08:00
|
|
|
overrides: ["oldapex"],
|
2019-11-15 17:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
override_apex {
|
|
|
|
name: "override_myapex",
|
|
|
|
base: "myapex",
|
|
|
|
apps: ["override_app"],
|
2019-12-20 09:32:06 +08:00
|
|
|
overrides: ["unknownapex"],
|
2020-02-20 13:29:28 +08:00
|
|
|
logging_parent: "com.foo.bar",
|
2020-03-16 04:01:05 +08:00
|
|
|
package_name: "test.overridden.package",
|
2019-11-15 17:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "app",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
package_name: "foo",
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-11-15 17:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
override_android_app {
|
|
|
|
name: "override_app",
|
|
|
|
base: "app",
|
|
|
|
package_name: "bar",
|
|
|
|
}
|
2020-03-03 10:45:41 +08:00
|
|
|
`, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"}))
|
2019-11-15 17:40:32 +08:00
|
|
|
|
2019-12-05 12:20:58 +08:00
|
|
|
originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
|
|
|
|
overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
|
|
|
|
if originalVariant.GetOverriddenBy() != "" {
|
|
|
|
t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
|
|
|
|
}
|
|
|
|
if overriddenVariant.GetOverriddenBy() != "override_myapex" {
|
|
|
|
t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
|
|
|
|
}
|
|
|
|
|
2019-11-15 17:40:32 +08:00
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
|
|
|
|
apexRule := module.Rule("apexRule")
|
|
|
|
copyCmds := apexRule.Args["copy_commands"]
|
|
|
|
|
|
|
|
ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
|
|
|
|
ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
|
2019-11-23 06:50:42 +08:00
|
|
|
|
|
|
|
apexBundle := module.Module().(*apexBundle)
|
|
|
|
name := apexBundle.Name()
|
|
|
|
if name != "override_myapex" {
|
|
|
|
t.Errorf("name should be \"override_myapex\", but was %q", name)
|
|
|
|
}
|
|
|
|
|
2020-02-20 13:29:28 +08:00
|
|
|
if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" {
|
|
|
|
t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent)
|
|
|
|
}
|
|
|
|
|
2020-03-03 10:45:41 +08:00
|
|
|
optFlags := apexRule.Args["opt_flags"]
|
2020-03-16 04:01:05 +08:00
|
|
|
ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package")
|
2020-03-03 10:45:41 +08:00
|
|
|
|
2019-11-23 06:50:42 +08:00
|
|
|
data := android.AndroidMkDataForTest(t, config, "", apexBundle)
|
|
|
|
var builder strings.Builder
|
|
|
|
data.Custom(&builder, name, "TARGET_", "", data)
|
|
|
|
androidMk := builder.String()
|
2019-11-18 14:39:01 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
|
2019-11-23 06:50:42 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
|
|
|
|
ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
|
2019-12-20 09:32:06 +08:00
|
|
|
ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
|
2019-11-23 06:50:42 +08:00
|
|
|
ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
|
2019-11-18 14:39:01 +08:00
|
|
|
ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
|
2019-11-23 06:50:42 +08:00
|
|
|
ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
|
|
|
|
ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
|
2019-11-15 17:40:32 +08:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:03:50 +08:00
|
|
|
func TestLegacyAndroid10Support(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
2020-02-13 09:13:25 +08:00
|
|
|
native_shared_libs: ["mylib"],
|
2020-03-12 17:37:20 +08:00
|
|
|
min_sdk_version: "29",
|
2019-11-12 12:03:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
2020-02-13 09:13:25 +08:00
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
stl: "libc++",
|
|
|
|
system_shared_libs: [],
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
`, withUnbundledBuild)
|
2019-11-12 12:03:50 +08:00
|
|
|
|
|
|
|
module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
|
|
|
|
args := module.Rule("apexRule").Args
|
|
|
|
ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
|
2020-01-15 07:50:25 +08:00
|
|
|
ensureNotContains(t, args["opt_flags"], "--no_hashtree")
|
2020-02-13 09:13:25 +08:00
|
|
|
|
|
|
|
// The copies of the libraries in the apex should have one more dependency than
|
|
|
|
// the ones outside the apex, namely the unwinder. Ideally we should check
|
|
|
|
// the dependency names directly here but for some reason the names are blank in
|
|
|
|
// this test.
|
|
|
|
for _, lib := range []string{"libc++", "mylib"} {
|
|
|
|
apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits
|
|
|
|
nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits
|
|
|
|
if len(apexImplicits) != len(nonApexImplicits)+1 {
|
|
|
|
t.Errorf("%q missing unwinder dep", lib)
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 12:03:50 +08:00
|
|
|
}
|
|
|
|
|
2019-12-18 14:34:32 +08:00
|
|
|
func TestJavaSDKLibrary(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
java_libs: ["foo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_sdk_library {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
api_packages: ["foo"],
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-12-18 14:34:32 +08:00
|
|
|
}
|
|
|
|
`, withFiles(map[string][]byte{
|
|
|
|
"api/current.txt": nil,
|
|
|
|
"api/removed.txt": nil,
|
|
|
|
"api/system-current.txt": nil,
|
|
|
|
"api/system-removed.txt": nil,
|
|
|
|
"api/test-current.txt": nil,
|
|
|
|
"api/test-removed.txt": nil,
|
|
|
|
}))
|
|
|
|
|
|
|
|
// java_sdk_library installs both impl jar and permission XML
|
2020-01-23 13:36:59 +08:00
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
2019-12-18 14:34:32 +08:00
|
|
|
"javalib/foo.jar",
|
|
|
|
"etc/permissions/foo.xml",
|
|
|
|
})
|
|
|
|
// Permission XML should point to the activated path of impl jar of java_sdk_library
|
2020-02-17 16:28:10 +08:00
|
|
|
sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml")
|
|
|
|
ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`)
|
2019-12-18 14:34:32 +08:00
|
|
|
}
|
|
|
|
|
2020-01-28 01:01:16 +08:00
|
|
|
func TestCompatConfig(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
prebuilts: ["myjar-platform-compat-config"],
|
|
|
|
java_libs: ["myjar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_compat_config {
|
|
|
|
name: "myjar-platform-compat-config",
|
|
|
|
src: ":myjar",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
|
|
|
|
"etc/compatconfig/myjar-platform-compat-config.xml",
|
|
|
|
"javalib/myjar.jar",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-12-16 10:47:12 +08:00
|
|
|
func TestRejectNonInstallableJavaLibrary(t *testing.T) {
|
|
|
|
testApexError(t, `"myjar" is not configured to be compiled into dex`, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
java_libs: ["myjar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
2020-02-11 08:16:01 +08:00
|
|
|
compile_dex: false,
|
2020-03-10 05:23:13 +08:00
|
|
|
apex_available: ["myapex"],
|
2019-12-16 10:47:12 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2019-12-30 15:56:33 +08:00
|
|
|
func TestCarryRequiredModuleNames(t *testing.T) {
|
|
|
|
ctx, config := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
required: ["a", "b"],
|
|
|
|
host_required: ["c", "d"],
|
|
|
|
target_required: ["e", "f"],
|
2020-01-10 23:12:39 +08:00
|
|
|
apex_available: [ "myapex" ],
|
2019-12-30 15:56:33 +08:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
|
|
|
|
data := android.AndroidMkDataForTest(t, config, "", apexBundle)
|
|
|
|
name := apexBundle.BaseModuleName()
|
|
|
|
prefix := "TARGET_"
|
|
|
|
var builder strings.Builder
|
|
|
|
data.Custom(&builder, name, prefix, "", data)
|
|
|
|
androidMk := builder.String()
|
|
|
|
ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
|
|
|
|
ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
|
|
|
|
ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
|
|
|
|
}
|
|
|
|
|
2020-01-14 08:22:18 +08:00
|
|
|
func TestSymlinksFromApexToSystem(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
java_libs: ["myjar"],
|
|
|
|
}
|
|
|
|
|
2020-02-19 15:29:35 +08:00
|
|
|
apex {
|
|
|
|
name: "myapex.updatable",
|
|
|
|
key: "myapex.key",
|
|
|
|
native_shared_libs: ["mylib"],
|
|
|
|
java_libs: ["myjar"],
|
|
|
|
updatable: true,
|
|
|
|
}
|
|
|
|
|
2020-01-14 08:22:18 +08:00
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "mylib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
shared_libs: ["myotherlib"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
2020-02-19 15:29:35 +08:00
|
|
|
"myapex.updatable",
|
2020-01-14 08:22:18 +08:00
|
|
|
"//apex_available:platform",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "myotherlib",
|
|
|
|
srcs: ["mylib.cpp"],
|
|
|
|
system_shared_libs: [],
|
|
|
|
stl: "none",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
2020-02-19 15:29:35 +08:00
|
|
|
"myapex.updatable",
|
2020-01-14 08:22:18 +08:00
|
|
|
"//apex_available:platform",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
libs: ["myotherjar"],
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
2020-02-19 15:29:35 +08:00
|
|
|
"myapex.updatable",
|
2020-01-14 08:22:18 +08:00
|
|
|
"//apex_available:platform",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "myotherjar",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
apex_available: [
|
|
|
|
"myapex",
|
2020-02-19 15:29:35 +08:00
|
|
|
"myapex.updatable",
|
2020-01-14 08:22:18 +08:00
|
|
|
"//apex_available:platform",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
|
|
|
|
for _, f := range files {
|
|
|
|
if f.path == file {
|
|
|
|
if f.isLink {
|
|
|
|
t.Errorf("%q is not a real file", file)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Errorf("%q is not found", file)
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
|
|
|
|
for _, f := range files {
|
|
|
|
if f.path == file {
|
|
|
|
if !f.isLink {
|
|
|
|
t.Errorf("%q is not a symlink", file)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Errorf("%q is not found", file)
|
|
|
|
}
|
|
|
|
|
2020-02-19 15:29:35 +08:00
|
|
|
// For unbundled build, symlink shouldn't exist regardless of whether an APEX
|
|
|
|
// is updatable or not
|
2020-01-14 08:22:18 +08:00
|
|
|
ctx, _ := testApex(t, bp, withUnbundledBuild)
|
2020-01-23 13:36:59 +08:00
|
|
|
files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
|
2020-01-14 08:22:18 +08:00
|
|
|
ensureRealfileExists(t, files, "javalib/myjar.jar")
|
|
|
|
ensureRealfileExists(t, files, "lib64/mylib.so")
|
|
|
|
ensureRealfileExists(t, files, "lib64/myotherlib.so")
|
|
|
|
|
2020-02-19 15:29:35 +08:00
|
|
|
files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
|
|
|
|
ensureRealfileExists(t, files, "javalib/myjar.jar")
|
|
|
|
ensureRealfileExists(t, files, "lib64/mylib.so")
|
|
|
|
ensureRealfileExists(t, files, "lib64/myotherlib.so")
|
|
|
|
|
|
|
|
// For bundled build, symlink to the system for the non-updatable APEXes only
|
2020-01-14 08:22:18 +08:00
|
|
|
ctx, _ = testApex(t, bp)
|
2020-01-23 13:36:59 +08:00
|
|
|
files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
|
2020-01-14 08:22:18 +08:00
|
|
|
ensureRealfileExists(t, files, "javalib/myjar.jar")
|
|
|
|
ensureRealfileExists(t, files, "lib64/mylib.so")
|
|
|
|
ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
|
2020-02-19 15:29:35 +08:00
|
|
|
|
|
|
|
files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image")
|
|
|
|
ensureRealfileExists(t, files, "javalib/myjar.jar")
|
|
|
|
ensureRealfileExists(t, files, "lib64/mylib.so")
|
|
|
|
ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
|
2020-01-14 08:22:18 +08:00
|
|
|
}
|
|
|
|
|
2020-04-17 12:43:10 +08:00
|
|
|
func TestApexMutatorsDontRunIfDisabled(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
}
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
`, func(fs map[string][]byte, config android.Config) {
|
|
|
|
delete(config.Targets, android.Android)
|
|
|
|
config.AndroidCommonTarget = android.Target{}
|
|
|
|
})
|
|
|
|
|
|
|
|
if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) {
|
|
|
|
t.Errorf("Expected variants: %v, but got: %v", expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 14:22:21 +08:00
|
|
|
func TestAppBundle(t *testing.T) {
|
|
|
|
ctx, _ := testApex(t, `
|
|
|
|
apex {
|
|
|
|
name: "myapex",
|
|
|
|
key: "myapex.key",
|
|
|
|
apps: ["AppFoo"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "myapex.key",
|
|
|
|
public_key: "testkey.avbpubkey",
|
|
|
|
private_key: "testkey.pem",
|
|
|
|
}
|
|
|
|
|
|
|
|
android_app {
|
|
|
|
name: "AppFoo",
|
|
|
|
srcs: ["foo/bar/MyClass.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
apex_available: [ "myapex" ],
|
|
|
|
}
|
2020-02-28 15:51:07 +08:00
|
|
|
`, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"}))
|
2020-02-28 14:22:21 +08:00
|
|
|
|
|
|
|
bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
|
|
|
|
content := bundleConfigRule.Args["content"]
|
|
|
|
|
|
|
|
ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
|
2020-02-28 15:51:07 +08:00
|
|
|
ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`)
|
2020-02-28 14:22:21 +08:00
|
|
|
}
|
|
|
|
|
2020-01-13 23:18:16 +08:00
|
|
|
func testNoUpdatableJarsInBootImage(t *testing.T, errmsg, bp string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
bp = bp + `
|
|
|
|
filegroup {
|
|
|
|
name: "some-updatable-apex-file_contexts",
|
|
|
|
srcs: [
|
|
|
|
"system/sepolicy/apex/some-updatable-apex-file_contexts",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
bp += cc.GatherRequiredDepsForTest(android.Android)
|
|
|
|
bp += java.GatherRequiredDepsForTest()
|
|
|
|
bp += dexpreopt.BpToolModulesForTest()
|
|
|
|
|
|
|
|
fs := map[string][]byte{
|
|
|
|
"a.java": nil,
|
|
|
|
"a.jar": nil,
|
|
|
|
"build/make/target/product/security": nil,
|
|
|
|
"apex_manifest.json": nil,
|
|
|
|
"AndroidManifest.xml": nil,
|
|
|
|
"system/sepolicy/apex/some-updatable-apex-file_contexts": nil,
|
|
|
|
"system/sepolicy/apex/com.android.art.something-file_contexts": nil,
|
|
|
|
"framework/aidl/a.aidl": nil,
|
|
|
|
}
|
|
|
|
cc.GatherRequiredFilesForTest(fs)
|
|
|
|
|
|
|
|
ctx := android.NewTestArchContext()
|
|
|
|
ctx.RegisterModuleType("apex", BundleFactory)
|
|
|
|
ctx.RegisterModuleType("apex_key", ApexKeyFactory)
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
|
|
|
java.RegisterJavaBuildComponents(ctx)
|
|
|
|
java.RegisterSystemModulesBuildComponents(ctx)
|
|
|
|
java.RegisterAppBuildComponents(ctx)
|
|
|
|
java.RegisterDexpreoptBootJarsComponents(ctx)
|
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
|
|
|
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
|
|
|
|
ctx.PreDepsMutators(RegisterPreDepsMutators)
|
|
|
|
ctx.PostDepsMutators(RegisterPostDepsMutators)
|
|
|
|
|
|
|
|
config := android.TestArchConfig(buildDir, nil, bp, fs)
|
|
|
|
ctx.Register(config)
|
|
|
|
|
|
|
|
_ = dexpreopt.GlobalSoongConfigForTests(config)
|
|
|
|
dexpreopt.RegisterToolModulesForTest(ctx)
|
|
|
|
pathCtx := android.PathContextForTesting(config)
|
|
|
|
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
|
|
|
|
transformDexpreoptConfig(dexpreoptConfig)
|
|
|
|
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
|
|
|
|
|
|
|
|
_, errs := ctx.ParseBlueprintsFiles("Android.bp")
|
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
if errmsg == "" {
|
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
} else if len(errs) > 0 {
|
|
|
|
android.FailIfNoMatchingErrors(t, errmsg, errs)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
t.Fatalf("missing expected error %q (0 errors are returned)", errmsg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoUpdatableJarsInBootImage(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
java_library {
|
|
|
|
name: "some-updatable-apex-lib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
apex_available: [
|
|
|
|
"some-updatable-apex",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "some-platform-lib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
installable: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "some-art-lib",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
apex_available: [
|
|
|
|
"com.android.art.something",
|
|
|
|
],
|
|
|
|
hostdex: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "some-updatable-apex",
|
|
|
|
key: "some-updatable-apex.key",
|
|
|
|
java_libs: ["some-updatable-apex-lib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "some-updatable-apex.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
apex {
|
|
|
|
name: "com.android.art.something",
|
|
|
|
key: "com.android.art.something.key",
|
|
|
|
java_libs: ["some-art-lib"],
|
|
|
|
}
|
|
|
|
|
|
|
|
apex_key {
|
|
|
|
name: "com.android.art.something.key",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var error string
|
|
|
|
var transform func(*dexpreopt.GlobalConfig)
|
|
|
|
|
|
|
|
// updatable jar from ART apex in the ART boot image => ok
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.ArtApexJars = []string{"some-art-lib"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, "", bp, transform)
|
|
|
|
|
|
|
|
// updatable jar from ART apex in the framework boot image => error
|
|
|
|
error = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image"
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.BootJars = []string{"some-art-lib"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, error, bp, transform)
|
|
|
|
|
|
|
|
// updatable jar from some other apex in the ART boot image => error
|
|
|
|
error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image"
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.ArtApexJars = []string{"some-updatable-apex-lib"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, error, bp, transform)
|
|
|
|
|
|
|
|
// updatable jar from some other apex in the framework boot image => error
|
|
|
|
error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image"
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.BootJars = []string{"some-updatable-apex-lib"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, error, bp, transform)
|
|
|
|
|
|
|
|
// nonexistent jar in the ART boot image => error
|
|
|
|
error = "failed to find a dex jar path for module 'nonexistent'"
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.ArtApexJars = []string{"nonexistent"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, error, bp, transform)
|
|
|
|
|
|
|
|
// nonexistent jar in the framework boot image => error
|
|
|
|
error = "failed to find a dex jar path for module 'nonexistent'"
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.BootJars = []string{"nonexistent"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, error, bp, transform)
|
|
|
|
|
|
|
|
// platform jar in the ART boot image => error
|
|
|
|
error = "module 'some-platform-lib' is part of the platform and not allowed in the ART boot image"
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.ArtApexJars = []string{"some-platform-lib"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, error, bp, transform)
|
|
|
|
|
|
|
|
// platform jar in the framework boot image => ok
|
|
|
|
transform = func(config *dexpreopt.GlobalConfig) {
|
|
|
|
config.BootJars = []string{"some-platform-lib"}
|
|
|
|
}
|
|
|
|
testNoUpdatableJarsInBootImage(t, "", bp, transform)
|
|
|
|
}
|
|
|
|
|
2019-06-26 02:20:53 +08:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
run := func() int {
|
|
|
|
setUp()
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
return m.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(run())
|
|
|
|
}
|