Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package apex |
| 16 | |
| 17 | import ( |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 18 | "io/ioutil" |
| 19 | "os" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 20 | "path" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 21 | "reflect" |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 22 | "regexp" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 23 | "sort" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 24 | "strings" |
| 25 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 26 | |
| 27 | "github.com/google/blueprint/proptools" |
| 28 | |
| 29 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 30 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 31 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 32 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 33 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 34 | "android/soong/java" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 35 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 36 | ) |
| 37 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 38 | var buildDir string |
| 39 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 40 | // names returns name list from white space separated string |
| 41 | func names(s string) (ns []string) { |
| 42 | for _, n := range strings.Split(s, " ") { |
| 43 | if len(n) > 0 { |
| 44 | ns = append(ns, n) |
| 45 | } |
| 46 | } |
| 47 | return |
| 48 | } |
| 49 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 50 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 51 | t.Helper() |
| 52 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 53 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 54 | if len(errs) > 0 { |
| 55 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 56 | return |
| 57 | } |
| 58 | _, errs = ctx.PrepareBuildActions(config) |
| 59 | if len(errs) > 0 { |
| 60 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 65 | } |
| 66 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 67 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 68 | t.Helper() |
| 69 | ctx, config := testApexContext(t, bp, handlers...) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 70 | _, errs := ctx.ParseBlueprintsFiles(".") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 71 | android.FailIfErrored(t, errs) |
| 72 | _, errs = ctx.PrepareBuildActions(config) |
| 73 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 74 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 75 | } |
| 76 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 77 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 78 | |
| 79 | func withFiles(files map[string][]byte) testCustomizer { |
| 80 | return func(fs map[string][]byte, config android.Config) { |
| 81 | for k, v := range files { |
| 82 | fs[k] = v |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 88 | return func(fs map[string][]byte, config android.Config) { |
| 89 | for k, v := range targets { |
| 90 | config.Targets[k] = v |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 95 | // withNativeBridgeTargets sets configuration with targets including: |
| 96 | // - X86_64 (primary) |
| 97 | // - X86 (secondary) |
| 98 | // - Arm64 on X86_64 (native bridge) |
| 99 | // - Arm on X86 (native bridge) |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 100 | func withNativeBridgeEnabled(_ map[string][]byte, config android.Config) { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 101 | config.Targets[android.Android] = []android.Target{ |
| 102 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 103 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 104 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 105 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 106 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 107 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 108 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 109 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 110 | } |
| 111 | } |
| 112 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 113 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 114 | return func(fs map[string][]byte, config android.Config) { |
| 115 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 116 | } |
| 117 | } |
| 118 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 119 | func withBinder32bit(_ map[string][]byte, config android.Config) { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 120 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 121 | } |
| 122 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 123 | func withUnbundledBuild(_ map[string][]byte, config android.Config) { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 124 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 125 | } |
| 126 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 127 | func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 128 | android.ClearApexDependency() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 129 | |
| 130 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 131 | filegroup { |
| 132 | name: "myapex-file_contexts", |
| 133 | srcs: [ |
| 134 | "system/sepolicy/apex/myapex-file_contexts", |
| 135 | ], |
| 136 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 137 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 138 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 139 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 140 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 141 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 142 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 143 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 144 | "a.java": nil, |
| 145 | "PrebuiltAppFoo.apk": nil, |
| 146 | "PrebuiltAppFooPriv.apk": nil, |
| 147 | "build/make/target/product/security": nil, |
| 148 | "apex_manifest.json": nil, |
| 149 | "AndroidManifest.xml": nil, |
| 150 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 151 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 152 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 153 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 154 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
| 155 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 156 | "mylib.cpp": nil, |
| 157 | "mylib_common.cpp": nil, |
| 158 | "mytest.cpp": nil, |
| 159 | "mytest1.cpp": nil, |
| 160 | "mytest2.cpp": nil, |
| 161 | "mytest3.cpp": nil, |
| 162 | "myprebuilt": nil, |
| 163 | "my_include": nil, |
| 164 | "foo/bar/MyClass.java": nil, |
| 165 | "prebuilt.jar": nil, |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 166 | "prebuilt.so": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 167 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 168 | "vendor/foo/devkeys/test.pk8": nil, |
| 169 | "testkey.x509.pem": nil, |
| 170 | "testkey.pk8": nil, |
| 171 | "testkey.override.x509.pem": nil, |
| 172 | "testkey.override.pk8": nil, |
| 173 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 174 | "vendor/foo/devkeys/testkey.pem": nil, |
| 175 | "NOTICE": nil, |
| 176 | "custom_notice": nil, |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 177 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 178 | "testkey2.avbpubkey": nil, |
| 179 | "testkey2.pem": nil, |
| 180 | "myapex-arm64.apex": nil, |
| 181 | "myapex-arm.apex": nil, |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 182 | "myapex.apks": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 183 | "frameworks/base/api/current.txt": nil, |
| 184 | "framework/aidl/a.aidl": nil, |
| 185 | "build/make/core/proguard.flags": nil, |
| 186 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 187 | "dummy.txt": nil, |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 188 | "baz": nil, |
| 189 | "bar/baz": nil, |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 190 | "testdata/baz": nil, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 191 | "AppSet.apks": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 192 | } |
| 193 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 194 | cc.GatherRequiredFilesForTest(fs) |
| 195 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 196 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 197 | // The fs now needs to be populated before creating the config, call handlers twice |
| 198 | // for now, once to get any fs changes, and later after the config was created to |
| 199 | // set product variables or targets. |
| 200 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 201 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 202 | } |
| 203 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 204 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 205 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 206 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 207 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 208 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 209 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 210 | config.TestProductVariables.Platform_version_active_codenames = []string{"Q"} |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 211 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 212 | |
| 213 | for _, handler := range handlers { |
| 214 | // The fs now needs to be populated before creating the config, call handlers twice |
| 215 | // for now, earlier to get any fs changes, and now after the config was created to |
| 216 | // set product variables or targets. |
| 217 | tempFS := map[string][]byte{} |
| 218 | handler(tempFS, config) |
| 219 | } |
| 220 | |
| 221 | ctx := android.NewTestArchContext() |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 222 | |
| 223 | // from android package |
| 224 | android.RegisterPackageBuildComponents(ctx) |
| 225 | ctx.PreArchMutators(android.RegisterVisibilityRuleChecker) |
| 226 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 227 | ctx.RegisterModuleType("apex", BundleFactory) |
| 228 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 229 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 230 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 231 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 232 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 233 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 234 | ctx.RegisterModuleType("apex_set", apexSetFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 235 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 236 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 237 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 238 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 239 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 240 | android.RegisterPrebuiltMutators(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 241 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 242 | // Register these after the prebuilt mutators have been registered to match what |
| 243 | // happens at runtime. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 244 | ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer) |
| 245 | ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer) |
| 246 | |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 247 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 248 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 249 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 250 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
| 251 | ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 252 | prebuilt_etc.RegisterPrebuiltEtcBuildComponents(ctx) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 253 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 254 | ctx.RegisterModuleType("sh_binary", sh.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 255 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 256 | java.RegisterJavaBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 257 | java.RegisterSystemModulesBuildComponents(ctx) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 258 | java.RegisterAppBuildComponents(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 259 | java.RegisterSdkLibraryBuildComponents(ctx) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 260 | ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 261 | ctx.RegisterModuleType("bpf", bpf.BpfFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 262 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 263 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 264 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 265 | |
| 266 | ctx.Register(config) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 267 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 268 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 269 | } |
| 270 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 271 | func setUp() { |
| 272 | var err error |
| 273 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 274 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 275 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 276 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 277 | } |
| 278 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 279 | func tearDown() { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 280 | _ = os.RemoveAll(buildDir) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 281 | } |
| 282 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 283 | // ensure that 'result' equals 'expected' |
| 284 | func ensureEquals(t *testing.T, result string, expected string) { |
| 285 | t.Helper() |
| 286 | if result != expected { |
| 287 | t.Errorf("%q != %q", expected, result) |
| 288 | } |
| 289 | } |
| 290 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 291 | // ensure that 'result' contains 'expected' |
| 292 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 293 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 294 | if !strings.Contains(result, expected) { |
| 295 | t.Errorf("%q is not found in %q", expected, result) |
| 296 | } |
| 297 | } |
| 298 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 299 | // ensure that 'result' contains 'expected' exactly one time |
| 300 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 301 | t.Helper() |
| 302 | count := strings.Count(result, expected) |
| 303 | if count != 1 { |
| 304 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 305 | } |
| 306 | } |
| 307 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 308 | // ensures that 'result' does not contain 'notExpected' |
| 309 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 310 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 311 | if strings.Contains(result, notExpected) { |
| 312 | t.Errorf("%q is found in %q", notExpected, result) |
| 313 | } |
| 314 | } |
| 315 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 316 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 317 | ok, err := regexp.MatchString(expectedRex, result) |
| 318 | if err != nil { |
| 319 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 320 | return |
| 321 | } |
| 322 | if !ok { |
| 323 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 324 | } |
| 325 | } |
| 326 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 327 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 328 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 329 | if !android.InList(expected, result) { |
| 330 | t.Errorf("%q is not found in %v", expected, result) |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 335 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 336 | if android.InList(notExpected, result) { |
| 337 | t.Errorf("%q is found in %v", notExpected, result) |
| 338 | } |
| 339 | } |
| 340 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 341 | func ensureListEmpty(t *testing.T, result []string) { |
| 342 | t.Helper() |
| 343 | if len(result) > 0 { |
| 344 | t.Errorf("%q is expected to be empty", result) |
| 345 | } |
| 346 | } |
| 347 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 348 | // Minimal test |
| 349 | func TestBasicApex(t *testing.T) { |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 350 | ctx, config := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 351 | apex_defaults { |
| 352 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 353 | manifest: ":myapex.manifest", |
| 354 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 355 | key: "myapex.key", |
| 356 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 357 | multilib: { |
| 358 | both: { |
| 359 | binaries: ["foo",], |
| 360 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 361 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 362 | java_libs: [ |
| 363 | "myjar", |
| 364 | "myjar_dex", |
| 365 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 366 | } |
| 367 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 368 | apex { |
| 369 | name: "myapex", |
| 370 | defaults: ["myapex-defaults"], |
| 371 | } |
| 372 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 373 | apex_key { |
| 374 | name: "myapex.key", |
| 375 | public_key: "testkey.avbpubkey", |
| 376 | private_key: "testkey.pem", |
| 377 | } |
| 378 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 379 | filegroup { |
| 380 | name: "myapex.manifest", |
| 381 | srcs: ["apex_manifest.json"], |
| 382 | } |
| 383 | |
| 384 | filegroup { |
| 385 | name: "myapex.androidmanifest", |
| 386 | srcs: ["AndroidManifest.xml"], |
| 387 | } |
| 388 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 389 | cc_library { |
| 390 | name: "mylib", |
| 391 | srcs: ["mylib.cpp"], |
| 392 | shared_libs: ["mylib2"], |
| 393 | system_shared_libs: [], |
| 394 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 395 | // TODO: remove //apex_available:platform |
| 396 | apex_available: [ |
| 397 | "//apex_available:platform", |
| 398 | "myapex", |
| 399 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 400 | } |
| 401 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 402 | cc_binary { |
| 403 | name: "foo", |
| 404 | srcs: ["mylib.cpp"], |
| 405 | compile_multilib: "both", |
| 406 | multilib: { |
| 407 | lib32: { |
| 408 | suffix: "32", |
| 409 | }, |
| 410 | lib64: { |
| 411 | suffix: "64", |
| 412 | }, |
| 413 | }, |
| 414 | symlinks: ["foo_link_"], |
| 415 | symlink_preferred_arch: true, |
| 416 | system_shared_libs: [], |
| 417 | static_executable: true, |
| 418 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 419 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 420 | } |
| 421 | |
| 422 | apex { |
| 423 | name: "com.android.gki.fake", |
| 424 | binaries: ["foo"], |
| 425 | key: "myapex.key", |
| 426 | file_contexts: ":myapex-file_contexts", |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 429 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 430 | name: "mylib2", |
| 431 | srcs: ["mylib.cpp"], |
| 432 | system_shared_libs: [], |
| 433 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 434 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 435 | static_libs: ["libstatic"], |
| 436 | // TODO: remove //apex_available:platform |
| 437 | apex_available: [ |
| 438 | "//apex_available:platform", |
| 439 | "myapex", |
| 440 | ], |
| 441 | } |
| 442 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 443 | cc_prebuilt_library_shared { |
| 444 | name: "mylib2", |
| 445 | srcs: ["prebuilt.so"], |
| 446 | // TODO: remove //apex_available:platform |
| 447 | apex_available: [ |
| 448 | "//apex_available:platform", |
| 449 | "myapex", |
| 450 | ], |
| 451 | } |
| 452 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 453 | cc_library_static { |
| 454 | name: "libstatic", |
| 455 | srcs: ["mylib.cpp"], |
| 456 | system_shared_libs: [], |
| 457 | stl: "none", |
| 458 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 459 | // TODO: remove //apex_available:platform |
| 460 | apex_available: [ |
| 461 | "//apex_available:platform", |
| 462 | "myapex", |
| 463 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 464 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 465 | |
| 466 | java_library { |
| 467 | name: "myjar", |
| 468 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 469 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 470 | sdk_version: "none", |
| 471 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 472 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 473 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 474 | // TODO: remove //apex_available:platform |
| 475 | apex_available: [ |
| 476 | "//apex_available:platform", |
| 477 | "myapex", |
| 478 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 479 | } |
| 480 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 481 | dex_import { |
| 482 | name: "myjar_dex", |
| 483 | jars: ["prebuilt.jar"], |
| 484 | apex_available: [ |
| 485 | "//apex_available:platform", |
| 486 | "myapex", |
| 487 | ], |
| 488 | } |
| 489 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 490 | java_library { |
| 491 | name: "myotherjar", |
| 492 | srcs: ["foo/bar/MyClass.java"], |
| 493 | sdk_version: "none", |
| 494 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 495 | // TODO: remove //apex_available:platform |
| 496 | apex_available: [ |
| 497 | "//apex_available:platform", |
| 498 | "myapex", |
| 499 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 500 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 501 | |
| 502 | java_library { |
| 503 | name: "mysharedjar", |
| 504 | srcs: ["foo/bar/MyClass.java"], |
| 505 | sdk_version: "none", |
| 506 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 507 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 508 | `) |
| 509 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 510 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 511 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 512 | // Make sure that Android.mk is created |
| 513 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 514 | data := android.AndroidMkDataForTest(t, config, "", ab) |
| 515 | var builder strings.Builder |
| 516 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 517 | |
| 518 | androidMk := builder.String() |
| 519 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 520 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 521 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 522 | optFlags := apexRule.Args["opt_flags"] |
| 523 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 524 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 525 | ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 526 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 527 | copyCmds := apexRule.Args["copy_commands"] |
| 528 | |
| 529 | // Ensure that main rule creates an output |
| 530 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 531 | |
| 532 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 533 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 534 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 535 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 536 | |
| 537 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 538 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 539 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 540 | |
| 541 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 542 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 543 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 544 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 545 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 546 | // .. but not for java libs |
| 547 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 548 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 549 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 550 | // Ensure that the platform variant ends with _shared or _common |
| 551 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 552 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 553 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 554 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 555 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 556 | |
| 557 | // Ensure that dynamic dependency to java libs are not included |
| 558 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 559 | |
| 560 | // Ensure that all symlinks are present. |
| 561 | found_foo_link_64 := false |
| 562 | found_foo := false |
| 563 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 564 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 565 | if strings.HasSuffix(cmd, "bin/foo") { |
| 566 | found_foo = true |
| 567 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 568 | found_foo_link_64 = true |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | good := found_foo && found_foo_link_64 |
| 573 | if !good { |
| 574 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 575 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 576 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 577 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 578 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 579 | if len(noticeInputs) != 3 { |
| 580 | t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs)) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 581 | } |
| 582 | ensureListContains(t, noticeInputs, "NOTICE") |
| 583 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 584 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 585 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 586 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame^] | 587 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
| 588 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex") |
| 589 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 590 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 591 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 592 | |
| 593 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame^] | 594 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
| 595 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 596 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 597 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 598 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 601 | func TestDefaults(t *testing.T) { |
| 602 | ctx, _ := testApex(t, ` |
| 603 | apex_defaults { |
| 604 | name: "myapex-defaults", |
| 605 | key: "myapex.key", |
| 606 | prebuilts: ["myetc"], |
| 607 | native_shared_libs: ["mylib"], |
| 608 | java_libs: ["myjar"], |
| 609 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 610 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 611 | bpfs: ["bpf"], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | prebuilt_etc { |
| 615 | name: "myetc", |
| 616 | src: "myprebuilt", |
| 617 | } |
| 618 | |
| 619 | apex { |
| 620 | name: "myapex", |
| 621 | defaults: ["myapex-defaults"], |
| 622 | } |
| 623 | |
| 624 | apex_key { |
| 625 | name: "myapex.key", |
| 626 | public_key: "testkey.avbpubkey", |
| 627 | private_key: "testkey.pem", |
| 628 | } |
| 629 | |
| 630 | cc_library { |
| 631 | name: "mylib", |
| 632 | system_shared_libs: [], |
| 633 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 634 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | java_library { |
| 638 | name: "myjar", |
| 639 | srcs: ["foo/bar/MyClass.java"], |
| 640 | sdk_version: "none", |
| 641 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 642 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | android_app { |
| 646 | name: "AppFoo", |
| 647 | srcs: ["foo/bar/MyClass.java"], |
| 648 | sdk_version: "none", |
| 649 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 650 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 651 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 652 | |
| 653 | runtime_resource_overlay { |
| 654 | name: "rro", |
| 655 | theme: "blue", |
| 656 | } |
| 657 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 658 | bpf { |
| 659 | name: "bpf", |
| 660 | srcs: ["bpf.c", "bpf2.c"], |
| 661 | } |
| 662 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 663 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 664 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 665 | "etc/myetc", |
| 666 | "javalib/myjar.jar", |
| 667 | "lib64/mylib.so", |
| 668 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 669 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 670 | "etc/bpf/bpf.o", |
| 671 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 672 | }) |
| 673 | } |
| 674 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 675 | func TestApexManifest(t *testing.T) { |
| 676 | ctx, _ := testApex(t, ` |
| 677 | apex { |
| 678 | name: "myapex", |
| 679 | key: "myapex.key", |
| 680 | } |
| 681 | |
| 682 | apex_key { |
| 683 | name: "myapex.key", |
| 684 | public_key: "testkey.avbpubkey", |
| 685 | private_key: "testkey.pem", |
| 686 | } |
| 687 | `) |
| 688 | |
| 689 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 690 | args := module.Rule("apexRule").Args |
| 691 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 692 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 693 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 694 | } |
| 695 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 696 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 697 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 698 | apex { |
| 699 | name: "myapex", |
| 700 | key: "myapex.key", |
| 701 | payload_type: "zip", |
| 702 | native_shared_libs: ["mylib"], |
| 703 | } |
| 704 | |
| 705 | apex_key { |
| 706 | name: "myapex.key", |
| 707 | public_key: "testkey.avbpubkey", |
| 708 | private_key: "testkey.pem", |
| 709 | } |
| 710 | |
| 711 | cc_library { |
| 712 | name: "mylib", |
| 713 | srcs: ["mylib.cpp"], |
| 714 | shared_libs: ["mylib2"], |
| 715 | system_shared_libs: [], |
| 716 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 717 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | cc_library { |
| 721 | name: "mylib2", |
| 722 | srcs: ["mylib.cpp"], |
| 723 | system_shared_libs: [], |
| 724 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 725 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 726 | } |
| 727 | `) |
| 728 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 729 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 730 | copyCmds := zipApexRule.Args["copy_commands"] |
| 731 | |
| 732 | // Ensure that main rule creates an output |
| 733 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 734 | |
| 735 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 736 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 737 | |
| 738 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 739 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 740 | |
| 741 | // Ensure that both direct and indirect deps are copied into apex |
| 742 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 743 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 747 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 748 | apex { |
| 749 | name: "myapex", |
| 750 | key: "myapex.key", |
| 751 | native_shared_libs: ["mylib", "mylib3"], |
| 752 | } |
| 753 | |
| 754 | apex_key { |
| 755 | name: "myapex.key", |
| 756 | public_key: "testkey.avbpubkey", |
| 757 | private_key: "testkey.pem", |
| 758 | } |
| 759 | |
| 760 | cc_library { |
| 761 | name: "mylib", |
| 762 | srcs: ["mylib.cpp"], |
| 763 | shared_libs: ["mylib2", "mylib3"], |
| 764 | system_shared_libs: [], |
| 765 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 766 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | cc_library { |
| 770 | name: "mylib2", |
| 771 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 772 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 773 | system_shared_libs: [], |
| 774 | stl: "none", |
| 775 | stubs: { |
| 776 | versions: ["1", "2", "3"], |
| 777 | }, |
| 778 | } |
| 779 | |
| 780 | cc_library { |
| 781 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 782 | srcs: ["mylib.cpp"], |
| 783 | shared_libs: ["mylib4"], |
| 784 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 785 | stl: "none", |
| 786 | stubs: { |
| 787 | versions: ["10", "11", "12"], |
| 788 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 789 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 790 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 791 | |
| 792 | cc_library { |
| 793 | name: "mylib4", |
| 794 | srcs: ["mylib.cpp"], |
| 795 | system_shared_libs: [], |
| 796 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 797 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 798 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 799 | `) |
| 800 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 801 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 802 | copyCmds := apexRule.Args["copy_commands"] |
| 803 | |
| 804 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 805 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 806 | |
| 807 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 808 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 809 | |
| 810 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 811 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 812 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 813 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 814 | |
| 815 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 816 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 817 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 818 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 819 | |
| 820 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 821 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 822 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 823 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 824 | |
| 825 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 826 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 827 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 828 | |
| 829 | // Ensure that genstub is invoked with --apex |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 830 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 831 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 832 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 833 | "lib64/mylib.so", |
| 834 | "lib64/mylib3.so", |
| 835 | "lib64/mylib4.so", |
| 836 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 837 | } |
| 838 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 839 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 840 | t.Parallel() |
| 841 | ctx, _ := testApex(t, ` |
| 842 | apex { |
| 843 | name: "myapex", |
| 844 | key: "myapex.key", |
| 845 | native_shared_libs: ["mylib", "mylib3"], |
| 846 | min_sdk_version: "29", |
| 847 | } |
| 848 | |
| 849 | apex_key { |
| 850 | name: "myapex.key", |
| 851 | public_key: "testkey.avbpubkey", |
| 852 | private_key: "testkey.pem", |
| 853 | } |
| 854 | |
| 855 | cc_library { |
| 856 | name: "mylib", |
| 857 | srcs: ["mylib.cpp"], |
| 858 | shared_libs: ["mylib2", "mylib3"], |
| 859 | system_shared_libs: [], |
| 860 | stl: "none", |
| 861 | apex_available: [ "myapex" ], |
| 862 | min_sdk_version: "28", |
| 863 | } |
| 864 | |
| 865 | cc_library { |
| 866 | name: "mylib2", |
| 867 | srcs: ["mylib.cpp"], |
| 868 | cflags: ["-include mylib.h"], |
| 869 | system_shared_libs: [], |
| 870 | stl: "none", |
| 871 | stubs: { |
| 872 | versions: ["28", "29", "30", "current"], |
| 873 | }, |
| 874 | min_sdk_version: "28", |
| 875 | } |
| 876 | |
| 877 | cc_library { |
| 878 | name: "mylib3", |
| 879 | srcs: ["mylib.cpp"], |
| 880 | shared_libs: ["mylib4"], |
| 881 | system_shared_libs: [], |
| 882 | stl: "none", |
| 883 | stubs: { |
| 884 | versions: ["28", "29", "30", "current"], |
| 885 | }, |
| 886 | apex_available: [ "myapex" ], |
| 887 | min_sdk_version: "28", |
| 888 | } |
| 889 | |
| 890 | cc_library { |
| 891 | name: "mylib4", |
| 892 | srcs: ["mylib.cpp"], |
| 893 | system_shared_libs: [], |
| 894 | stl: "none", |
| 895 | apex_available: [ "myapex" ], |
| 896 | min_sdk_version: "28", |
| 897 | } |
| 898 | `) |
| 899 | |
| 900 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 901 | copyCmds := apexRule.Args["copy_commands"] |
| 902 | |
| 903 | // Ensure that direct non-stubs dep is always included |
| 904 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 905 | |
| 906 | // Ensure that indirect stubs dep is not included |
| 907 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 908 | |
| 909 | // Ensure that direct stubs dep is included |
| 910 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 911 | |
| 912 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 913 | |
| 914 | // Ensure that mylib is linking with the version 29 stubs for mylib2 |
| 915 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_29/mylib2.so") |
| 916 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 917 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 918 | |
| 919 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 920 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 921 | // .. and not linking to the stubs variant of mylib3 |
| 922 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 923 | |
| 924 | // Ensure that stubs libs are built without -include flags |
| 925 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 926 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 927 | |
| 928 | // Ensure that genstub is invoked with --apex |
| 929 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_29").Rule("genStubSrc").Args["flags"]) |
| 930 | |
| 931 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 932 | "lib64/mylib.so", |
| 933 | "lib64/mylib3.so", |
| 934 | "lib64/mylib4.so", |
| 935 | }) |
| 936 | } |
| 937 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 938 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 939 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 940 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 941 | name: "myapex2", |
| 942 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 943 | native_shared_libs: ["mylib"], |
| 944 | } |
| 945 | |
| 946 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 947 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 948 | public_key: "testkey.avbpubkey", |
| 949 | private_key: "testkey.pem", |
| 950 | } |
| 951 | |
| 952 | cc_library { |
| 953 | name: "mylib", |
| 954 | srcs: ["mylib.cpp"], |
| 955 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 956 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 957 | system_shared_libs: [], |
| 958 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 959 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | cc_library { |
| 963 | name: "libfoo", |
| 964 | srcs: ["mylib.cpp"], |
| 965 | shared_libs: ["libbar"], |
| 966 | system_shared_libs: [], |
| 967 | stl: "none", |
| 968 | stubs: { |
| 969 | versions: ["10", "20", "30"], |
| 970 | }, |
| 971 | } |
| 972 | |
| 973 | cc_library { |
| 974 | name: "libbar", |
| 975 | srcs: ["mylib.cpp"], |
| 976 | system_shared_libs: [], |
| 977 | stl: "none", |
| 978 | } |
| 979 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 980 | cc_library_static { |
| 981 | name: "libbaz", |
| 982 | srcs: ["mylib.cpp"], |
| 983 | system_shared_libs: [], |
| 984 | stl: "none", |
| 985 | apex_available: [ "myapex2" ], |
| 986 | } |
| 987 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 988 | `) |
| 989 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 990 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 991 | copyCmds := apexRule.Args["copy_commands"] |
| 992 | |
| 993 | // Ensure that direct non-stubs dep is always included |
| 994 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 995 | |
| 996 | // Ensure that indirect stubs dep is not included |
| 997 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 998 | |
| 999 | // Ensure that dependency of stubs is not included |
| 1000 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1001 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1002 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1003 | |
| 1004 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1005 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1006 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1007 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1008 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1009 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1010 | |
| 1011 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1012 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1013 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1014 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame^] | 1015 | ensureListContains(t, fullDepsInfo, " mylib(minSdkVersion:(no version)) <- myapex2") |
| 1016 | ensureListContains(t, fullDepsInfo, " libbaz(minSdkVersion:(no version)) <- mylib") |
| 1017 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1018 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1019 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame^] | 1020 | ensureListContains(t, flatDepsInfo, "mylib(minSdkVersion:(no version))") |
| 1021 | ensureListContains(t, flatDepsInfo, "libbaz(minSdkVersion:(no version))") |
| 1022 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1023 | } |
| 1024 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1025 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1026 | /* |
| 1027 | myapex |
| 1028 | | |
| 1029 | v (runtime_libs) |
| 1030 | mylib ------+------> libfoo [provides stub] |
| 1031 | | |
| 1032 | `------> libbar |
| 1033 | */ |
| 1034 | ctx, _ := testApex(t, ` |
| 1035 | apex { |
| 1036 | name: "myapex", |
| 1037 | key: "myapex.key", |
| 1038 | native_shared_libs: ["mylib"], |
| 1039 | } |
| 1040 | |
| 1041 | apex_key { |
| 1042 | name: "myapex.key", |
| 1043 | public_key: "testkey.avbpubkey", |
| 1044 | private_key: "testkey.pem", |
| 1045 | } |
| 1046 | |
| 1047 | cc_library { |
| 1048 | name: "mylib", |
| 1049 | srcs: ["mylib.cpp"], |
| 1050 | runtime_libs: ["libfoo", "libbar"], |
| 1051 | system_shared_libs: [], |
| 1052 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1053 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | cc_library { |
| 1057 | name: "libfoo", |
| 1058 | srcs: ["mylib.cpp"], |
| 1059 | system_shared_libs: [], |
| 1060 | stl: "none", |
| 1061 | stubs: { |
| 1062 | versions: ["10", "20", "30"], |
| 1063 | }, |
| 1064 | } |
| 1065 | |
| 1066 | cc_library { |
| 1067 | name: "libbar", |
| 1068 | srcs: ["mylib.cpp"], |
| 1069 | system_shared_libs: [], |
| 1070 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1071 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | `) |
| 1075 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1076 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1077 | copyCmds := apexRule.Args["copy_commands"] |
| 1078 | |
| 1079 | // Ensure that direct non-stubs dep is always included |
| 1080 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1081 | |
| 1082 | // Ensure that indirect stubs dep is not included |
| 1083 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1084 | |
| 1085 | // Ensure that runtime_libs dep in included |
| 1086 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1087 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1088 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1089 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1090 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1091 | |
| 1092 | } |
| 1093 | |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1094 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
| 1095 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1096 | bp := ` |
| 1097 | apex { |
| 1098 | name: "com.android.runtime", |
| 1099 | key: "com.android.runtime.key", |
| 1100 | native_shared_libs: ["libc"], |
| 1101 | } |
| 1102 | |
| 1103 | apex_key { |
| 1104 | name: "com.android.runtime.key", |
| 1105 | public_key: "testkey.avbpubkey", |
| 1106 | private_key: "testkey.pem", |
| 1107 | } |
| 1108 | |
| 1109 | cc_library { |
| 1110 | name: "libc", |
| 1111 | no_libcrt: true, |
| 1112 | nocrt: true, |
| 1113 | stl: "none", |
| 1114 | system_shared_libs: [], |
| 1115 | stubs: { versions: ["1"] }, |
| 1116 | apex_available: ["com.android.runtime"], |
| 1117 | |
| 1118 | sanitize: { |
| 1119 | hwaddress: true, |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | cc_prebuilt_library_shared { |
| 1124 | name: "libclang_rt.hwasan-aarch64-android", |
| 1125 | no_libcrt: true, |
| 1126 | nocrt: true, |
| 1127 | stl: "none", |
| 1128 | system_shared_libs: [], |
| 1129 | srcs: [""], |
| 1130 | stubs: { versions: ["1"] }, |
| 1131 | |
| 1132 | sanitize: { |
| 1133 | never: true, |
| 1134 | }, |
| 1135 | } |
| 1136 | ` |
| 1137 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1138 | fs["Android.bp"] = []byte(bp) |
| 1139 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1140 | }) |
| 1141 | |
| 1142 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1143 | "lib64/bionic/libc.so", |
| 1144 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1145 | }) |
| 1146 | |
| 1147 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1148 | |
| 1149 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1150 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1151 | |
| 1152 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1153 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1154 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1155 | } |
| 1156 | |
| 1157 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
| 1158 | ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) { |
| 1159 | bp := ` |
| 1160 | apex { |
| 1161 | name: "com.android.runtime", |
| 1162 | key: "com.android.runtime.key", |
| 1163 | native_shared_libs: ["libc"], |
| 1164 | } |
| 1165 | |
| 1166 | apex_key { |
| 1167 | name: "com.android.runtime.key", |
| 1168 | public_key: "testkey.avbpubkey", |
| 1169 | private_key: "testkey.pem", |
| 1170 | } |
| 1171 | |
| 1172 | cc_library { |
| 1173 | name: "libc", |
| 1174 | no_libcrt: true, |
| 1175 | nocrt: true, |
| 1176 | stl: "none", |
| 1177 | system_shared_libs: [], |
| 1178 | stubs: { versions: ["1"] }, |
| 1179 | apex_available: ["com.android.runtime"], |
| 1180 | } |
| 1181 | |
| 1182 | cc_prebuilt_library_shared { |
| 1183 | name: "libclang_rt.hwasan-aarch64-android", |
| 1184 | no_libcrt: true, |
| 1185 | nocrt: true, |
| 1186 | stl: "none", |
| 1187 | system_shared_libs: [], |
| 1188 | srcs: [""], |
| 1189 | stubs: { versions: ["1"] }, |
| 1190 | |
| 1191 | sanitize: { |
| 1192 | never: true, |
| 1193 | }, |
| 1194 | } |
| 1195 | ` |
| 1196 | // override bp to use hard-coded names: com.android.runtime and libc |
| 1197 | fs["Android.bp"] = []byte(bp) |
| 1198 | fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil |
| 1199 | |
| 1200 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1201 | }) |
| 1202 | |
| 1203 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1204 | "lib64/bionic/libc.so", |
| 1205 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1206 | }) |
| 1207 | |
| 1208 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1209 | |
| 1210 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1211 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1212 | |
| 1213 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1214 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1215 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1216 | } |
| 1217 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1218 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1219 | testcases := []struct { |
| 1220 | name string |
| 1221 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1222 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1223 | shouldLink string |
| 1224 | shouldNotLink []string |
| 1225 | }{ |
| 1226 | { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1227 | name: "should link to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1228 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1229 | apexVariant: "apex10000", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1230 | shouldLink: "30", |
| 1231 | shouldNotLink: []string{"29"}, |
| 1232 | }, |
| 1233 | { |
| 1234 | name: "should link to llndk#29", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1235 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1236 | apexVariant: "apex29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1237 | shouldLink: "29", |
| 1238 | shouldNotLink: []string{"30"}, |
| 1239 | }, |
| 1240 | } |
| 1241 | for _, tc := range testcases { |
| 1242 | t.Run(tc.name, func(t *testing.T) { |
| 1243 | ctx, _ := testApex(t, ` |
| 1244 | apex { |
| 1245 | name: "myapex", |
| 1246 | key: "myapex.key", |
| 1247 | use_vendor: true, |
| 1248 | native_shared_libs: ["mylib"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1249 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1250 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1251 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1252 | apex_key { |
| 1253 | name: "myapex.key", |
| 1254 | public_key: "testkey.avbpubkey", |
| 1255 | private_key: "testkey.pem", |
| 1256 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1257 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1258 | cc_library { |
| 1259 | name: "mylib", |
| 1260 | srcs: ["mylib.cpp"], |
| 1261 | vendor_available: true, |
| 1262 | shared_libs: ["libbar"], |
| 1263 | system_shared_libs: [], |
| 1264 | stl: "none", |
| 1265 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1266 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1267 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1268 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1269 | cc_library { |
| 1270 | name: "libbar", |
| 1271 | srcs: ["mylib.cpp"], |
| 1272 | system_shared_libs: [], |
| 1273 | stl: "none", |
| 1274 | stubs: { versions: ["29","30"] }, |
| 1275 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1276 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1277 | llndk_library { |
| 1278 | name: "libbar", |
| 1279 | symbol_file: "", |
| 1280 | } |
| 1281 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 1282 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1283 | }, withUnbundledBuild) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1284 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1285 | // Ensure that LLNDK dep is not included |
| 1286 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1287 | "lib64/mylib.so", |
| 1288 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1289 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1290 | // Ensure that LLNDK dep is required |
| 1291 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1292 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1293 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1294 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1295 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1296 | ensureContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
| 1297 | for _, ver := range tc.shouldNotLink { |
| 1298 | ensureNotContains(t, mylibLdFlags, "libbar.llndk/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
| 1299 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1300 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1301 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"] |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1302 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1303 | }) |
| 1304 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1305 | } |
| 1306 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1307 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1308 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1309 | apex { |
| 1310 | name: "myapex", |
| 1311 | key: "myapex.key", |
| 1312 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 1313 | } |
| 1314 | |
| 1315 | apex_key { |
| 1316 | name: "myapex.key", |
| 1317 | public_key: "testkey.avbpubkey", |
| 1318 | private_key: "testkey.pem", |
| 1319 | } |
| 1320 | |
| 1321 | cc_library { |
| 1322 | name: "mylib", |
| 1323 | srcs: ["mylib.cpp"], |
| 1324 | shared_libs: ["libdl#27"], |
| 1325 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1326 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | cc_library_shared { |
| 1330 | name: "mylib_shared", |
| 1331 | srcs: ["mylib.cpp"], |
| 1332 | shared_libs: ["libdl#27"], |
| 1333 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1334 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1338 | name: "libBootstrap", |
| 1339 | srcs: ["mylib.cpp"], |
| 1340 | stl: "none", |
| 1341 | bootstrap: true, |
| 1342 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1343 | `) |
| 1344 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1345 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1346 | copyCmds := apexRule.Args["copy_commands"] |
| 1347 | |
| 1348 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1349 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1350 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1351 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1352 | |
| 1353 | // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1354 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1355 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1356 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1357 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1358 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1359 | |
| 1360 | // For dependency to libc |
| 1361 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1362 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1363 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1364 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1365 | // ... Cflags from stub is correctly exported to mylib |
| 1366 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1367 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1368 | |
| 1369 | // For dependency to libm |
| 1370 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1371 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1372 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1373 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1374 | // ... and is not compiling with the stub |
| 1375 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1376 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1377 | |
| 1378 | // For dependency to libdl |
| 1379 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1380 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1381 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1382 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1383 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1384 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1385 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1386 | // ... Cflags from stub is correctly exported to mylib |
| 1387 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1388 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1389 | |
| 1390 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1391 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1392 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1393 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1394 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1395 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1396 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1397 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1398 | // there are three links between liba --> libz |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1399 | // 1) myapex -> libx -> liba -> libz : this should be #29 link, but fallback to #28 |
| 1400 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1401 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1402 | ctx, _ := testApex(t, ` |
| 1403 | apex { |
| 1404 | name: "myapex", |
| 1405 | key: "myapex.key", |
| 1406 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1407 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | apex { |
| 1411 | name: "otherapex", |
| 1412 | key: "myapex.key", |
| 1413 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1414 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | apex_key { |
| 1418 | name: "myapex.key", |
| 1419 | public_key: "testkey.avbpubkey", |
| 1420 | private_key: "testkey.pem", |
| 1421 | } |
| 1422 | |
| 1423 | cc_library { |
| 1424 | name: "libx", |
| 1425 | shared_libs: ["liba"], |
| 1426 | system_shared_libs: [], |
| 1427 | stl: "none", |
| 1428 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1429 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | cc_library { |
| 1433 | name: "liby", |
| 1434 | shared_libs: ["liba"], |
| 1435 | system_shared_libs: [], |
| 1436 | stl: "none", |
| 1437 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1438 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | cc_library { |
| 1442 | name: "liba", |
| 1443 | shared_libs: ["libz"], |
| 1444 | system_shared_libs: [], |
| 1445 | stl: "none", |
| 1446 | apex_available: [ |
| 1447 | "//apex_available:anyapex", |
| 1448 | "//apex_available:platform", |
| 1449 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1450 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | cc_library { |
| 1454 | name: "libz", |
| 1455 | system_shared_libs: [], |
| 1456 | stl: "none", |
| 1457 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1458 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1459 | }, |
| 1460 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1461 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1462 | |
| 1463 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1464 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1465 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1466 | } |
| 1467 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1468 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1469 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1470 | } |
| 1471 | // platform liba is linked to non-stub version |
| 1472 | expectLink("liba", "shared", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1473 | // liba in myapex is linked to #28 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1474 | expectLink("liba", "shared_apex29", "libz", "shared_28") |
| 1475 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
| 1476 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1477 | // liba in otherapex is linked to #30 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1478 | expectLink("liba", "shared_apex30", "libz", "shared_30") |
| 1479 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1480 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1481 | } |
| 1482 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1483 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
| 1484 | ctx, _ := testApex(t, ` |
| 1485 | apex { |
| 1486 | name: "myapex", |
| 1487 | key: "myapex.key", |
| 1488 | native_shared_libs: ["libx"], |
| 1489 | min_sdk_version: "R", |
| 1490 | } |
| 1491 | |
| 1492 | apex_key { |
| 1493 | name: "myapex.key", |
| 1494 | public_key: "testkey.avbpubkey", |
| 1495 | private_key: "testkey.pem", |
| 1496 | } |
| 1497 | |
| 1498 | cc_library { |
| 1499 | name: "libx", |
| 1500 | shared_libs: ["libz"], |
| 1501 | system_shared_libs: [], |
| 1502 | stl: "none", |
| 1503 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1504 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | cc_library { |
| 1508 | name: "libz", |
| 1509 | system_shared_libs: [], |
| 1510 | stl: "none", |
| 1511 | stubs: { |
| 1512 | versions: ["29", "R"], |
| 1513 | }, |
| 1514 | } |
| 1515 | `, func(fs map[string][]byte, config android.Config) { |
| 1516 | config.TestProductVariables.Platform_version_active_codenames = []string{"R"} |
| 1517 | }) |
| 1518 | |
| 1519 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1520 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1521 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1522 | } |
| 1523 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1524 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1525 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1526 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1527 | expectLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1528 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1529 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1530 | } |
| 1531 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1532 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1533 | ctx, _ := testApex(t, ` |
| 1534 | apex { |
| 1535 | name: "myapex", |
| 1536 | key: "myapex.key", |
| 1537 | native_shared_libs: ["libx"], |
| 1538 | } |
| 1539 | |
| 1540 | apex_key { |
| 1541 | name: "myapex.key", |
| 1542 | public_key: "testkey.avbpubkey", |
| 1543 | private_key: "testkey.pem", |
| 1544 | } |
| 1545 | |
| 1546 | cc_library { |
| 1547 | name: "libx", |
| 1548 | shared_libs: ["libz"], |
| 1549 | system_shared_libs: [], |
| 1550 | stl: "none", |
| 1551 | apex_available: [ "myapex" ], |
| 1552 | } |
| 1553 | |
| 1554 | cc_library { |
| 1555 | name: "libz", |
| 1556 | system_shared_libs: [], |
| 1557 | stl: "none", |
| 1558 | stubs: { |
| 1559 | versions: ["1", "2"], |
| 1560 | }, |
| 1561 | } |
| 1562 | `) |
| 1563 | |
| 1564 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1565 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1566 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1567 | } |
| 1568 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1569 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1570 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1571 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1572 | expectLink("libx", "shared_apex10000", "libz", "shared_2") |
| 1573 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
| 1574 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1578 | ctx, _ := testApex(t, ` |
| 1579 | apex { |
| 1580 | name: "myapex", |
| 1581 | key: "myapex.key", |
| 1582 | native_shared_libs: ["libx"], |
| 1583 | } |
| 1584 | |
| 1585 | apex_key { |
| 1586 | name: "myapex.key", |
| 1587 | public_key: "testkey.avbpubkey", |
| 1588 | private_key: "testkey.pem", |
| 1589 | } |
| 1590 | |
| 1591 | cc_library { |
| 1592 | name: "libx", |
| 1593 | system_shared_libs: [], |
| 1594 | stl: "none", |
| 1595 | apex_available: [ "myapex" ], |
| 1596 | stubs: { |
| 1597 | versions: ["1", "2"], |
| 1598 | }, |
| 1599 | } |
| 1600 | |
| 1601 | cc_library { |
| 1602 | name: "libz", |
| 1603 | shared_libs: ["libx"], |
| 1604 | system_shared_libs: [], |
| 1605 | stl: "none", |
| 1606 | } |
| 1607 | `) |
| 1608 | |
| 1609 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1610 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1611 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1612 | } |
| 1613 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1614 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1615 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1616 | } |
| 1617 | expectLink("libz", "shared", "libx", "shared_2") |
| 1618 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1619 | expectNoLink("libz", "shared", "libz", "shared") |
| 1620 | } |
| 1621 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1622 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1623 | ctx, _ := testApex(t, ` |
| 1624 | apex { |
| 1625 | name: "myapex", |
| 1626 | key: "myapex.key", |
| 1627 | native_shared_libs: ["libx"], |
| 1628 | min_sdk_version: "29", |
| 1629 | } |
| 1630 | |
| 1631 | apex_key { |
| 1632 | name: "myapex.key", |
| 1633 | public_key: "testkey.avbpubkey", |
| 1634 | private_key: "testkey.pem", |
| 1635 | } |
| 1636 | |
| 1637 | cc_library { |
| 1638 | name: "libx", |
| 1639 | shared_libs: ["libbar"], |
| 1640 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1641 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | cc_library { |
| 1645 | name: "libbar", |
| 1646 | stubs: { |
| 1647 | versions: ["29", "30"], |
| 1648 | }, |
| 1649 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1650 | `, func(fs map[string][]byte, config android.Config) { |
| 1651 | config.TestProductVariables.SanitizeDevice = []string{"hwaddress"} |
| 1652 | }) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1653 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1654 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1655 | libFlags := ld.Args["libFlags"] |
| 1656 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1657 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1658 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1659 | } |
| 1660 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1661 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1662 | ctx, _ := testApex(t, ` |
| 1663 | apex { |
| 1664 | name: "myapex", |
| 1665 | key: "myapex.key", |
| 1666 | native_shared_libs: ["libx"], |
| 1667 | min_sdk_version: "29", |
| 1668 | } |
| 1669 | |
| 1670 | apex_key { |
| 1671 | name: "myapex.key", |
| 1672 | public_key: "testkey.avbpubkey", |
| 1673 | private_key: "testkey.pem", |
| 1674 | } |
| 1675 | |
| 1676 | cc_library { |
| 1677 | name: "libx", |
| 1678 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1679 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1680 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1681 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1682 | |
| 1683 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1684 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_apex29").Module().(*cc.Module) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1685 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
| 1686 | // note that platform variant is not. |
| 1687 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 1688 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1689 | } |
| 1690 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1691 | func TestApexMinSdkVersion_ErrorIfIncompatibleStubs(t *testing.T) { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1692 | testApexError(t, `"libz" .*: not found a version\(<=29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1693 | apex { |
| 1694 | name: "myapex", |
| 1695 | key: "myapex.key", |
| 1696 | native_shared_libs: ["libx"], |
| 1697 | min_sdk_version: "29", |
| 1698 | } |
| 1699 | |
| 1700 | apex_key { |
| 1701 | name: "myapex.key", |
| 1702 | public_key: "testkey.avbpubkey", |
| 1703 | private_key: "testkey.pem", |
| 1704 | } |
| 1705 | |
| 1706 | cc_library { |
| 1707 | name: "libx", |
| 1708 | shared_libs: ["libz"], |
| 1709 | system_shared_libs: [], |
| 1710 | stl: "none", |
| 1711 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1712 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | cc_library { |
| 1716 | name: "libz", |
| 1717 | system_shared_libs: [], |
| 1718 | stl: "none", |
| 1719 | stubs: { |
| 1720 | versions: ["30"], |
| 1721 | }, |
| 1722 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1723 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1724 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1725 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1726 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1727 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1728 | apex { |
| 1729 | name: "myapex", |
| 1730 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1731 | native_shared_libs: ["mylib"], |
| 1732 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | apex_key { |
| 1736 | name: "myapex.key", |
| 1737 | public_key: "testkey.avbpubkey", |
| 1738 | private_key: "testkey.pem", |
| 1739 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1740 | |
| 1741 | cc_library { |
| 1742 | name: "mylib", |
| 1743 | srcs: ["mylib.cpp"], |
| 1744 | system_shared_libs: [], |
| 1745 | stl: "none", |
| 1746 | apex_available: [ |
| 1747 | "myapex", |
| 1748 | ], |
| 1749 | min_sdk_version: "30", |
| 1750 | } |
| 1751 | `) |
| 1752 | } |
| 1753 | |
| 1754 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1755 | testApex(t, ` |
| 1756 | apex { |
| 1757 | name: "myapex", |
| 1758 | key: "myapex.key", |
| 1759 | native_shared_libs: ["libfoo"], |
| 1760 | java_libs: ["libbar"], |
| 1761 | min_sdk_version: "29", |
| 1762 | } |
| 1763 | |
| 1764 | apex_key { |
| 1765 | name: "myapex.key", |
| 1766 | public_key: "testkey.avbpubkey", |
| 1767 | private_key: "testkey.pem", |
| 1768 | } |
| 1769 | |
| 1770 | cc_library { |
| 1771 | name: "libfoo", |
| 1772 | srcs: ["mylib.cpp"], |
| 1773 | shared_libs: ["libfoo_dep"], |
| 1774 | apex_available: ["myapex"], |
| 1775 | min_sdk_version: "29", |
| 1776 | } |
| 1777 | |
| 1778 | cc_library { |
| 1779 | name: "libfoo_dep", |
| 1780 | srcs: ["mylib.cpp"], |
| 1781 | apex_available: ["myapex"], |
| 1782 | min_sdk_version: "29", |
| 1783 | } |
| 1784 | |
| 1785 | java_library { |
| 1786 | name: "libbar", |
| 1787 | sdk_version: "current", |
| 1788 | srcs: ["a.java"], |
| 1789 | static_libs: ["libbar_dep"], |
| 1790 | apex_available: ["myapex"], |
| 1791 | min_sdk_version: "29", |
| 1792 | } |
| 1793 | |
| 1794 | java_library { |
| 1795 | name: "libbar_dep", |
| 1796 | sdk_version: "current", |
| 1797 | srcs: ["a.java"], |
| 1798 | apex_available: ["myapex"], |
| 1799 | min_sdk_version: "29", |
| 1800 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1801 | `) |
| 1802 | } |
| 1803 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1804 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1805 | testCases := []struct { |
| 1806 | name string |
| 1807 | expectedError string |
| 1808 | bp string |
| 1809 | }{ |
| 1810 | { |
| 1811 | name: "Non-updatable apex with non-stable dep", |
| 1812 | bp: ` |
| 1813 | apex { |
| 1814 | name: "myapex", |
| 1815 | java_libs: ["myjar"], |
| 1816 | key: "myapex.key", |
| 1817 | } |
| 1818 | apex_key { |
| 1819 | name: "myapex.key", |
| 1820 | public_key: "testkey.avbpubkey", |
| 1821 | private_key: "testkey.pem", |
| 1822 | } |
| 1823 | java_library { |
| 1824 | name: "myjar", |
| 1825 | srcs: ["foo/bar/MyClass.java"], |
| 1826 | sdk_version: "core_platform", |
| 1827 | apex_available: ["myapex"], |
| 1828 | } |
| 1829 | `, |
| 1830 | }, |
| 1831 | { |
| 1832 | name: "Updatable apex with stable dep", |
| 1833 | bp: ` |
| 1834 | apex { |
| 1835 | name: "myapex", |
| 1836 | java_libs: ["myjar"], |
| 1837 | key: "myapex.key", |
| 1838 | updatable: true, |
| 1839 | min_sdk_version: "29", |
| 1840 | } |
| 1841 | apex_key { |
| 1842 | name: "myapex.key", |
| 1843 | public_key: "testkey.avbpubkey", |
| 1844 | private_key: "testkey.pem", |
| 1845 | } |
| 1846 | java_library { |
| 1847 | name: "myjar", |
| 1848 | srcs: ["foo/bar/MyClass.java"], |
| 1849 | sdk_version: "current", |
| 1850 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1851 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1852 | } |
| 1853 | `, |
| 1854 | }, |
| 1855 | { |
| 1856 | name: "Updatable apex with non-stable dep", |
| 1857 | expectedError: "cannot depend on \"myjar\"", |
| 1858 | bp: ` |
| 1859 | apex { |
| 1860 | name: "myapex", |
| 1861 | java_libs: ["myjar"], |
| 1862 | key: "myapex.key", |
| 1863 | updatable: true, |
| 1864 | } |
| 1865 | apex_key { |
| 1866 | name: "myapex.key", |
| 1867 | public_key: "testkey.avbpubkey", |
| 1868 | private_key: "testkey.pem", |
| 1869 | } |
| 1870 | java_library { |
| 1871 | name: "myjar", |
| 1872 | srcs: ["foo/bar/MyClass.java"], |
| 1873 | sdk_version: "core_platform", |
| 1874 | apex_available: ["myapex"], |
| 1875 | } |
| 1876 | `, |
| 1877 | }, |
| 1878 | { |
| 1879 | name: "Updatable apex with non-stable transitive dep", |
| 1880 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against non-public Android API.", |
| 1881 | bp: ` |
| 1882 | apex { |
| 1883 | name: "myapex", |
| 1884 | java_libs: ["myjar"], |
| 1885 | key: "myapex.key", |
| 1886 | updatable: true, |
| 1887 | } |
| 1888 | apex_key { |
| 1889 | name: "myapex.key", |
| 1890 | public_key: "testkey.avbpubkey", |
| 1891 | private_key: "testkey.pem", |
| 1892 | } |
| 1893 | java_library { |
| 1894 | name: "myjar", |
| 1895 | srcs: ["foo/bar/MyClass.java"], |
| 1896 | sdk_version: "current", |
| 1897 | apex_available: ["myapex"], |
| 1898 | static_libs: ["transitive-jar"], |
| 1899 | } |
| 1900 | java_library { |
| 1901 | name: "transitive-jar", |
| 1902 | srcs: ["foo/bar/MyClass.java"], |
| 1903 | sdk_version: "core_platform", |
| 1904 | apex_available: ["myapex"], |
| 1905 | } |
| 1906 | `, |
| 1907 | }, |
| 1908 | } |
| 1909 | |
| 1910 | for _, test := range testCases { |
| 1911 | t.Run(test.name, func(t *testing.T) { |
| 1912 | if test.expectedError == "" { |
| 1913 | testApex(t, test.bp) |
| 1914 | } else { |
| 1915 | testApexError(t, test.expectedError, test.bp) |
| 1916 | } |
| 1917 | }) |
| 1918 | } |
| 1919 | } |
| 1920 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1921 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 1922 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 1923 | apex { |
| 1924 | name: "myapex", |
| 1925 | key: "myapex.key", |
| 1926 | native_shared_libs: ["mylib"], |
| 1927 | min_sdk_version: "29", |
| 1928 | } |
| 1929 | |
| 1930 | apex_key { |
| 1931 | name: "myapex.key", |
| 1932 | public_key: "testkey.avbpubkey", |
| 1933 | private_key: "testkey.pem", |
| 1934 | } |
| 1935 | |
| 1936 | cc_library { |
| 1937 | name: "mylib", |
| 1938 | srcs: ["mylib.cpp"], |
| 1939 | shared_libs: ["mylib2"], |
| 1940 | system_shared_libs: [], |
| 1941 | stl: "none", |
| 1942 | apex_available: [ |
| 1943 | "myapex", |
| 1944 | ], |
| 1945 | min_sdk_version: "29", |
| 1946 | } |
| 1947 | |
| 1948 | // indirect part of the apex |
| 1949 | cc_library { |
| 1950 | name: "mylib2", |
| 1951 | srcs: ["mylib.cpp"], |
| 1952 | system_shared_libs: [], |
| 1953 | stl: "none", |
| 1954 | apex_available: [ |
| 1955 | "myapex", |
| 1956 | ], |
| 1957 | min_sdk_version: "30", |
| 1958 | } |
| 1959 | `) |
| 1960 | } |
| 1961 | |
| 1962 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 1963 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 1964 | apex { |
| 1965 | name: "myapex", |
| 1966 | key: "myapex.key", |
| 1967 | apps: ["AppFoo"], |
| 1968 | min_sdk_version: "29", |
| 1969 | } |
| 1970 | |
| 1971 | apex_key { |
| 1972 | name: "myapex.key", |
| 1973 | public_key: "testkey.avbpubkey", |
| 1974 | private_key: "testkey.pem", |
| 1975 | } |
| 1976 | |
| 1977 | android_app { |
| 1978 | name: "AppFoo", |
| 1979 | srcs: ["foo/bar/MyClass.java"], |
| 1980 | sdk_version: "current", |
| 1981 | min_sdk_version: "29", |
| 1982 | system_modules: "none", |
| 1983 | stl: "none", |
| 1984 | static_libs: ["bar"], |
| 1985 | apex_available: [ "myapex" ], |
| 1986 | } |
| 1987 | |
| 1988 | java_library { |
| 1989 | name: "bar", |
| 1990 | sdk_version: "current", |
| 1991 | srcs: ["a.java"], |
| 1992 | apex_available: [ "myapex" ], |
| 1993 | } |
| 1994 | `) |
| 1995 | } |
| 1996 | |
| 1997 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
| 1998 | ctx, _ := testApex(t, ` |
| 1999 | apex { |
| 2000 | name: "myapex", |
| 2001 | key: "myapex.key", |
| 2002 | native_shared_libs: ["mylib"], |
| 2003 | min_sdk_version: "29", |
| 2004 | } |
| 2005 | |
| 2006 | apex_key { |
| 2007 | name: "myapex.key", |
| 2008 | public_key: "testkey.avbpubkey", |
| 2009 | private_key: "testkey.pem", |
| 2010 | } |
| 2011 | |
| 2012 | // mylib in myapex will link to mylib2#29 |
| 2013 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2014 | cc_library { |
| 2015 | name: "mylib", |
| 2016 | srcs: ["mylib.cpp"], |
| 2017 | shared_libs: ["mylib2"], |
| 2018 | system_shared_libs: [], |
| 2019 | stl: "none", |
| 2020 | apex_available: ["myapex", "otherapex"], |
| 2021 | min_sdk_version: "29", |
| 2022 | } |
| 2023 | |
| 2024 | cc_library { |
| 2025 | name: "mylib2", |
| 2026 | srcs: ["mylib.cpp"], |
| 2027 | system_shared_libs: [], |
| 2028 | stl: "none", |
| 2029 | apex_available: ["otherapex"], |
| 2030 | stubs: { versions: ["29", "30"] }, |
| 2031 | min_sdk_version: "30", |
| 2032 | } |
| 2033 | |
| 2034 | apex { |
| 2035 | name: "otherapex", |
| 2036 | key: "myapex.key", |
| 2037 | native_shared_libs: ["mylib", "mylib2"], |
| 2038 | min_sdk_version: "30", |
| 2039 | } |
| 2040 | `) |
| 2041 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2042 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2043 | libFlags := ld.Args["libFlags"] |
| 2044 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2045 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2046 | expectLink("mylib", "shared_apex29", "mylib2", "shared_29") |
| 2047 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2048 | } |
| 2049 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2050 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2051 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2052 | apex { |
| 2053 | name: "myapex", |
| 2054 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2055 | native_shared_libs: ["mylib"], |
| 2056 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2057 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2058 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | apex_key { |
| 2062 | name: "myapex.key", |
| 2063 | public_key: "testkey.avbpubkey", |
| 2064 | private_key: "testkey.pem", |
| 2065 | } |
| 2066 | |
| 2067 | prebuilt_etc { |
| 2068 | name: "myetc", |
| 2069 | src: "myprebuilt", |
| 2070 | sub_dir: "foo/bar", |
| 2071 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2072 | |
| 2073 | cc_library { |
| 2074 | name: "mylib", |
| 2075 | srcs: ["mylib.cpp"], |
| 2076 | relative_install_path: "foo/bar", |
| 2077 | system_shared_libs: [], |
| 2078 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2079 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | cc_binary { |
| 2083 | name: "mybin", |
| 2084 | srcs: ["mylib.cpp"], |
| 2085 | relative_install_path: "foo/bar", |
| 2086 | system_shared_libs: [], |
| 2087 | static_executable: true, |
| 2088 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2089 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2090 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2091 | `) |
| 2092 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2093 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2094 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2095 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2096 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2097 | ensureListContains(t, dirs, "etc") |
| 2098 | ensureListContains(t, dirs, "etc/foo") |
| 2099 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2100 | ensureListContains(t, dirs, "lib64") |
| 2101 | ensureListContains(t, dirs, "lib64/foo") |
| 2102 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2103 | ensureListContains(t, dirs, "lib") |
| 2104 | ensureListContains(t, dirs, "lib/foo") |
| 2105 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2106 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2107 | ensureListContains(t, dirs, "bin") |
| 2108 | ensureListContains(t, dirs, "bin/foo") |
| 2109 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2110 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2111 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2112 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 2113 | ctx, _ := testApex(t, ` |
| 2114 | apex { |
| 2115 | name: "myapex", |
| 2116 | key: "myapex.key", |
| 2117 | multilib: { |
| 2118 | both: { |
| 2119 | native_shared_libs: ["mylib"], |
| 2120 | binaries: ["mybin"], |
| 2121 | }, |
| 2122 | }, |
| 2123 | compile_multilib: "both", |
| 2124 | native_bridge_supported: true, |
| 2125 | } |
| 2126 | |
| 2127 | apex_key { |
| 2128 | name: "myapex.key", |
| 2129 | public_key: "testkey.avbpubkey", |
| 2130 | private_key: "testkey.pem", |
| 2131 | } |
| 2132 | |
| 2133 | cc_library { |
| 2134 | name: "mylib", |
| 2135 | relative_install_path: "foo/bar", |
| 2136 | system_shared_libs: [], |
| 2137 | stl: "none", |
| 2138 | apex_available: [ "myapex" ], |
| 2139 | native_bridge_supported: true, |
| 2140 | } |
| 2141 | |
| 2142 | cc_binary { |
| 2143 | name: "mybin", |
| 2144 | relative_install_path: "foo/bar", |
| 2145 | system_shared_libs: [], |
| 2146 | static_executable: true, |
| 2147 | stl: "none", |
| 2148 | apex_available: [ "myapex" ], |
| 2149 | native_bridge_supported: true, |
| 2150 | compile_multilib: "both", // default is "first" for binary |
| 2151 | multilib: { |
| 2152 | lib64: { |
| 2153 | suffix: "64", |
| 2154 | }, |
| 2155 | }, |
| 2156 | } |
| 2157 | `, withNativeBridgeEnabled) |
| 2158 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2159 | "bin/foo/bar/mybin", |
| 2160 | "bin/foo/bar/mybin64", |
| 2161 | "bin/arm/foo/bar/mybin", |
| 2162 | "bin/arm64/foo/bar/mybin64", |
| 2163 | "lib/foo/bar/mylib.so", |
| 2164 | "lib/arm/foo/bar/mylib.so", |
| 2165 | "lib64/foo/bar/mylib.so", |
| 2166 | "lib64/arm64/foo/bar/mylib.so", |
| 2167 | }) |
| 2168 | } |
| 2169 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2170 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2171 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2172 | apex { |
| 2173 | name: "myapex", |
| 2174 | key: "myapex.key", |
| 2175 | native_shared_libs: ["mylib"], |
| 2176 | use_vendor: true, |
| 2177 | } |
| 2178 | |
| 2179 | apex_key { |
| 2180 | name: "myapex.key", |
| 2181 | public_key: "testkey.avbpubkey", |
| 2182 | private_key: "testkey.pem", |
| 2183 | } |
| 2184 | |
| 2185 | cc_library { |
| 2186 | name: "mylib", |
| 2187 | srcs: ["mylib.cpp"], |
| 2188 | shared_libs: ["mylib2"], |
| 2189 | system_shared_libs: [], |
| 2190 | vendor_available: true, |
| 2191 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2192 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | cc_library { |
| 2196 | name: "mylib2", |
| 2197 | srcs: ["mylib.cpp"], |
| 2198 | system_shared_libs: [], |
| 2199 | vendor_available: true, |
| 2200 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2201 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2202 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2203 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2204 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2205 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2206 | |
| 2207 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2208 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2209 | for _, implicit := range i.Implicits { |
| 2210 | inputsList = append(inputsList, implicit.String()) |
| 2211 | } |
| 2212 | } |
| 2213 | inputsString := strings.Join(inputsList, " ") |
| 2214 | |
| 2215 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2216 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2217 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2218 | |
| 2219 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2220 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2221 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2222 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2223 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2224 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2225 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2226 | apex { |
| 2227 | name: "myapex", |
| 2228 | key: "myapex.key", |
| 2229 | use_vendor: true, |
| 2230 | } |
| 2231 | apex_key { |
| 2232 | name: "myapex.key", |
| 2233 | public_key: "testkey.avbpubkey", |
| 2234 | private_key: "testkey.pem", |
| 2235 | } |
| 2236 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2237 | setUseVendorAllowListForTest(config, []string{""}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2238 | }) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2239 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2240 | testApex(t, ` |
| 2241 | apex { |
| 2242 | name: "myapex", |
| 2243 | key: "myapex.key", |
| 2244 | use_vendor: true, |
| 2245 | } |
| 2246 | apex_key { |
| 2247 | name: "myapex.key", |
| 2248 | public_key: "testkey.avbpubkey", |
| 2249 | private_key: "testkey.pem", |
| 2250 | } |
| 2251 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2252 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2253 | }) |
| 2254 | } |
| 2255 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2256 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2257 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2258 | apex { |
| 2259 | name: "myapex", |
| 2260 | key: "myapex.key", |
| 2261 | native_shared_libs: ["mylib"], |
| 2262 | use_vendor: true, |
| 2263 | } |
| 2264 | |
| 2265 | apex_key { |
| 2266 | name: "myapex.key", |
| 2267 | public_key: "testkey.avbpubkey", |
| 2268 | private_key: "testkey.pem", |
| 2269 | } |
| 2270 | |
| 2271 | cc_library { |
| 2272 | name: "mylib", |
| 2273 | srcs: ["mylib.cpp"], |
| 2274 | system_shared_libs: [], |
| 2275 | stl: "none", |
| 2276 | } |
| 2277 | `) |
| 2278 | } |
| 2279 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2280 | func TestVendorApex(t *testing.T) { |
| 2281 | ctx, config := testApex(t, ` |
| 2282 | apex { |
| 2283 | name: "myapex", |
| 2284 | key: "myapex.key", |
| 2285 | binaries: ["mybin"], |
| 2286 | vendor: true, |
| 2287 | } |
| 2288 | apex_key { |
| 2289 | name: "myapex.key", |
| 2290 | public_key: "testkey.avbpubkey", |
| 2291 | private_key: "testkey.pem", |
| 2292 | } |
| 2293 | cc_binary { |
| 2294 | name: "mybin", |
| 2295 | vendor: true, |
| 2296 | shared_libs: ["libfoo"], |
| 2297 | } |
| 2298 | cc_library { |
| 2299 | name: "libfoo", |
| 2300 | proprietary: true, |
| 2301 | } |
| 2302 | `) |
| 2303 | |
| 2304 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2305 | "bin/mybin", |
| 2306 | "lib64/libfoo.so", |
| 2307 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2308 | "lib64/libc++.so", |
| 2309 | }) |
| 2310 | |
| 2311 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2312 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2313 | name := apexBundle.BaseModuleName() |
| 2314 | prefix := "TARGET_" |
| 2315 | var builder strings.Builder |
| 2316 | data.Custom(&builder, name, prefix, "", data) |
| 2317 | androidMk := builder.String() |
| 2318 | ensureContains(t, androidMk, `LOCAL_MODULE_PATH := /tmp/target/product/test_device/vendor/apex`) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2319 | |
| 2320 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2321 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2322 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2323 | } |
| 2324 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2325 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
| 2326 | ctx, _ := testApex(t, ` |
| 2327 | apex { |
| 2328 | name: "myapex", |
| 2329 | key: "myapex.key", |
| 2330 | binaries: ["mybin"], |
| 2331 | vendor: true, |
| 2332 | use_vndk_as_stable: true, |
| 2333 | } |
| 2334 | apex_key { |
| 2335 | name: "myapex.key", |
| 2336 | public_key: "testkey.avbpubkey", |
| 2337 | private_key: "testkey.pem", |
| 2338 | } |
| 2339 | cc_binary { |
| 2340 | name: "mybin", |
| 2341 | vendor: true, |
| 2342 | shared_libs: ["libvndk", "libvendor"], |
| 2343 | } |
| 2344 | cc_library { |
| 2345 | name: "libvndk", |
| 2346 | vndk: { |
| 2347 | enabled: true, |
| 2348 | }, |
| 2349 | vendor_available: true, |
| 2350 | } |
| 2351 | cc_library { |
| 2352 | name: "libvendor", |
| 2353 | vendor: true, |
| 2354 | } |
| 2355 | `) |
| 2356 | |
| 2357 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2358 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2359 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2360 | libs := names(ldRule.Args["libFlags"]) |
| 2361 | // VNDK libs(libvndk/libc++) as they are |
| 2362 | ensureListContains(t, libs, buildDir+"/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2363 | ensureListContains(t, libs, buildDir+"/.intermediates/libc++/"+vendorVariant+"_shared/libc++.so") |
| 2364 | // non-stable Vendor libs as APEX variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2365 | ensureListContains(t, libs, buildDir+"/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2366 | |
| 2367 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2368 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2369 | "bin/mybin", |
| 2370 | "lib64/libvendor.so", |
| 2371 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2372 | |
| 2373 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2374 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2375 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2376 | } |
| 2377 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2378 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2379 | testCases := []struct { |
| 2380 | name string |
| 2381 | additionalProp string |
| 2382 | }{ |
| 2383 | {"system apex with prebuilt_firmware", ""}, |
| 2384 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2385 | } |
| 2386 | for _, tc := range testCases { |
| 2387 | t.Run(tc.name, func(t *testing.T) { |
| 2388 | ctx, _ := testApex(t, ` |
| 2389 | apex { |
| 2390 | name: "myapex", |
| 2391 | key: "myapex.key", |
| 2392 | prebuilts: ["myfirmware"], |
| 2393 | `+tc.additionalProp+` |
| 2394 | } |
| 2395 | apex_key { |
| 2396 | name: "myapex.key", |
| 2397 | public_key: "testkey.avbpubkey", |
| 2398 | private_key: "testkey.pem", |
| 2399 | } |
| 2400 | prebuilt_firmware { |
| 2401 | name: "myfirmware", |
| 2402 | src: "myfirmware.bin", |
| 2403 | filename_from_src: true, |
| 2404 | `+tc.additionalProp+` |
| 2405 | } |
| 2406 | `) |
| 2407 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2408 | "etc/firmware/myfirmware.bin", |
| 2409 | }) |
| 2410 | }) |
| 2411 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2412 | } |
| 2413 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2414 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
| 2415 | ctx, config := testApex(t, ` |
| 2416 | apex { |
| 2417 | name: "myapex", |
| 2418 | key: "myapex.key", |
| 2419 | use_vendor: true, |
| 2420 | native_shared_libs: ["mylib"], |
| 2421 | } |
| 2422 | |
| 2423 | apex_key { |
| 2424 | name: "myapex.key", |
| 2425 | public_key: "testkey.avbpubkey", |
| 2426 | private_key: "testkey.pem", |
| 2427 | } |
| 2428 | |
| 2429 | cc_library { |
| 2430 | name: "mylib", |
| 2431 | vendor_available: true, |
| 2432 | apex_available: ["myapex"], |
| 2433 | } |
| 2434 | `, func(fs map[string][]byte, config android.Config) { |
| 2435 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
| 2436 | }) |
| 2437 | |
| 2438 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2439 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2440 | name := apexBundle.BaseModuleName() |
| 2441 | prefix := "TARGET_" |
| 2442 | var builder strings.Builder |
| 2443 | data.Custom(&builder, name, prefix, "", data) |
| 2444 | androidMk := builder.String() |
| 2445 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2446 | } |
| 2447 | |
| 2448 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
| 2449 | ctx, config := testApex(t, ` |
| 2450 | apex { |
| 2451 | name: "myapex", |
| 2452 | key: "myapex.key", |
| 2453 | vendor: true, |
| 2454 | native_shared_libs: ["mylib"], |
| 2455 | } |
| 2456 | |
| 2457 | apex_key { |
| 2458 | name: "myapex.key", |
| 2459 | public_key: "testkey.avbpubkey", |
| 2460 | private_key: "testkey.pem", |
| 2461 | } |
| 2462 | |
| 2463 | cc_library { |
| 2464 | name: "mylib", |
| 2465 | vendor_available: true, |
| 2466 | } |
| 2467 | `) |
| 2468 | |
| 2469 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2470 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2471 | name := apexBundle.BaseModuleName() |
| 2472 | prefix := "TARGET_" |
| 2473 | var builder strings.Builder |
| 2474 | data.Custom(&builder, name, prefix, "", data) |
| 2475 | androidMk := builder.String() |
| 2476 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2477 | } |
| 2478 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2479 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
| 2480 | ctx, config := testApex(t, ` |
| 2481 | apex { |
| 2482 | name: "myapex", |
| 2483 | key: "myapex.key", |
| 2484 | vintf_fragments: ["fragment.xml"], |
| 2485 | init_rc: ["init.rc"], |
| 2486 | } |
| 2487 | apex_key { |
| 2488 | name: "myapex.key", |
| 2489 | public_key: "testkey.avbpubkey", |
| 2490 | private_key: "testkey.pem", |
| 2491 | } |
| 2492 | cc_binary { |
| 2493 | name: "mybin", |
| 2494 | } |
| 2495 | `) |
| 2496 | |
| 2497 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2498 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2499 | name := apexBundle.BaseModuleName() |
| 2500 | prefix := "TARGET_" |
| 2501 | var builder strings.Builder |
| 2502 | data.Custom(&builder, name, prefix, "", data) |
| 2503 | androidMk := builder.String() |
| 2504 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2505 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2506 | } |
| 2507 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2508 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2509 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2510 | apex { |
| 2511 | name: "myapex", |
| 2512 | key: "myapex.key", |
| 2513 | native_shared_libs: ["mylib"], |
| 2514 | } |
| 2515 | |
| 2516 | apex_key { |
| 2517 | name: "myapex.key", |
| 2518 | public_key: "testkey.avbpubkey", |
| 2519 | private_key: "testkey.pem", |
| 2520 | } |
| 2521 | |
| 2522 | cc_library { |
| 2523 | name: "mylib", |
| 2524 | srcs: ["mylib.cpp"], |
| 2525 | system_shared_libs: [], |
| 2526 | stl: "none", |
| 2527 | stubs: { |
| 2528 | versions: ["1", "2", "3"], |
| 2529 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2530 | apex_available: [ |
| 2531 | "//apex_available:platform", |
| 2532 | "myapex", |
| 2533 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | cc_binary { |
| 2537 | name: "not_in_apex", |
| 2538 | srcs: ["mylib.cpp"], |
| 2539 | static_libs: ["mylib"], |
| 2540 | static_executable: true, |
| 2541 | system_shared_libs: [], |
| 2542 | stl: "none", |
| 2543 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2544 | `) |
| 2545 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2546 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2547 | |
| 2548 | // Ensure that not_in_apex is linking with the static variant of mylib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2549 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2550 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2551 | |
| 2552 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2553 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2554 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2555 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2556 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2557 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2558 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2559 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | cc_library { |
| 2563 | name: "mylib", |
| 2564 | srcs: ["mylib.cpp"], |
| 2565 | system_shared_libs: [], |
| 2566 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2567 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | apex_key { |
| 2571 | name: "myapex.key", |
| 2572 | public_key: "testkey.avbpubkey", |
| 2573 | private_key: "testkey.pem", |
| 2574 | } |
| 2575 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2576 | android_app_certificate { |
| 2577 | name: "myapex.certificate", |
| 2578 | certificate: "testkey", |
| 2579 | } |
| 2580 | |
| 2581 | android_app_certificate { |
| 2582 | name: "myapex.certificate.override", |
| 2583 | certificate: "testkey.override", |
| 2584 | } |
| 2585 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2586 | `) |
| 2587 | |
| 2588 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2589 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2590 | |
| 2591 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2592 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 2593 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2594 | } |
| 2595 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2596 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 2597 | "vendor/foo/devkeys/testkey.pem") |
| 2598 | } |
| 2599 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2600 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2601 | certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"] |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2602 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2603 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2604 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2605 | } |
| 2606 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2607 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2608 | func TestCertificate(t *testing.T) { |
| 2609 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 2610 | ctx, _ := testApex(t, ` |
| 2611 | apex { |
| 2612 | name: "myapex", |
| 2613 | key: "myapex.key", |
| 2614 | } |
| 2615 | apex_key { |
| 2616 | name: "myapex.key", |
| 2617 | public_key: "testkey.avbpubkey", |
| 2618 | private_key: "testkey.pem", |
| 2619 | }`) |
| 2620 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2621 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2622 | if actual := rule.Args["certificates"]; actual != expected { |
| 2623 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2624 | } |
| 2625 | }) |
| 2626 | t.Run("override when unspecified", func(t *testing.T) { |
| 2627 | ctx, _ := testApex(t, ` |
| 2628 | apex { |
| 2629 | name: "myapex_keytest", |
| 2630 | key: "myapex.key", |
| 2631 | file_contexts: ":myapex-file_contexts", |
| 2632 | } |
| 2633 | apex_key { |
| 2634 | name: "myapex.key", |
| 2635 | public_key: "testkey.avbpubkey", |
| 2636 | private_key: "testkey.pem", |
| 2637 | } |
| 2638 | android_app_certificate { |
| 2639 | name: "myapex.certificate.override", |
| 2640 | certificate: "testkey.override", |
| 2641 | }`) |
| 2642 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2643 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2644 | if actual := rule.Args["certificates"]; actual != expected { |
| 2645 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2646 | } |
| 2647 | }) |
| 2648 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 2649 | ctx, _ := testApex(t, ` |
| 2650 | apex { |
| 2651 | name: "myapex", |
| 2652 | key: "myapex.key", |
| 2653 | certificate: ":myapex.certificate", |
| 2654 | } |
| 2655 | apex_key { |
| 2656 | name: "myapex.key", |
| 2657 | public_key: "testkey.avbpubkey", |
| 2658 | private_key: "testkey.pem", |
| 2659 | } |
| 2660 | android_app_certificate { |
| 2661 | name: "myapex.certificate", |
| 2662 | certificate: "testkey", |
| 2663 | }`) |
| 2664 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2665 | expected := "testkey.x509.pem testkey.pk8" |
| 2666 | if actual := rule.Args["certificates"]; actual != expected { |
| 2667 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2668 | } |
| 2669 | }) |
| 2670 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 2671 | ctx, _ := testApex(t, ` |
| 2672 | apex { |
| 2673 | name: "myapex_keytest", |
| 2674 | key: "myapex.key", |
| 2675 | file_contexts: ":myapex-file_contexts", |
| 2676 | certificate: ":myapex.certificate", |
| 2677 | } |
| 2678 | apex_key { |
| 2679 | name: "myapex.key", |
| 2680 | public_key: "testkey.avbpubkey", |
| 2681 | private_key: "testkey.pem", |
| 2682 | } |
| 2683 | android_app_certificate { |
| 2684 | name: "myapex.certificate.override", |
| 2685 | certificate: "testkey.override", |
| 2686 | }`) |
| 2687 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2688 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2689 | if actual := rule.Args["certificates"]; actual != expected { |
| 2690 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2691 | } |
| 2692 | }) |
| 2693 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 2694 | ctx, _ := testApex(t, ` |
| 2695 | apex { |
| 2696 | name: "myapex", |
| 2697 | key: "myapex.key", |
| 2698 | certificate: "testkey", |
| 2699 | } |
| 2700 | apex_key { |
| 2701 | name: "myapex.key", |
| 2702 | public_key: "testkey.avbpubkey", |
| 2703 | private_key: "testkey.pem", |
| 2704 | }`) |
| 2705 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2706 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2707 | if actual := rule.Args["certificates"]; actual != expected { |
| 2708 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2709 | } |
| 2710 | }) |
| 2711 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 2712 | ctx, _ := testApex(t, ` |
| 2713 | apex { |
| 2714 | name: "myapex_keytest", |
| 2715 | key: "myapex.key", |
| 2716 | file_contexts: ":myapex-file_contexts", |
| 2717 | certificate: "testkey", |
| 2718 | } |
| 2719 | apex_key { |
| 2720 | name: "myapex.key", |
| 2721 | public_key: "testkey.avbpubkey", |
| 2722 | private_key: "testkey.pem", |
| 2723 | } |
| 2724 | android_app_certificate { |
| 2725 | name: "myapex.certificate.override", |
| 2726 | certificate: "testkey.override", |
| 2727 | }`) |
| 2728 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2729 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2730 | if actual := rule.Args["certificates"]; actual != expected { |
| 2731 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2732 | } |
| 2733 | }) |
| 2734 | } |
| 2735 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2736 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2737 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2738 | apex { |
| 2739 | name: "myapex", |
| 2740 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2741 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | apex { |
| 2745 | name: "otherapex", |
| 2746 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2747 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2748 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | apex_key { |
| 2752 | name: "myapex.key", |
| 2753 | public_key: "testkey.avbpubkey", |
| 2754 | private_key: "testkey.pem", |
| 2755 | } |
| 2756 | |
| 2757 | cc_library { |
| 2758 | name: "mylib", |
| 2759 | srcs: ["mylib.cpp"], |
| 2760 | system_shared_libs: [], |
| 2761 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2762 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2763 | "myapex", |
| 2764 | "otherapex", |
| 2765 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2766 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2767 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2768 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2769 | cc_library { |
| 2770 | name: "mylib2", |
| 2771 | srcs: ["mylib.cpp"], |
| 2772 | system_shared_libs: [], |
| 2773 | stl: "none", |
| 2774 | apex_available: [ |
| 2775 | "myapex", |
| 2776 | "otherapex", |
| 2777 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2778 | static_libs: ["mylib3"], |
| 2779 | recovery_available: true, |
| 2780 | min_sdk_version: "29", |
| 2781 | } |
| 2782 | cc_library { |
| 2783 | name: "mylib3", |
| 2784 | srcs: ["mylib.cpp"], |
| 2785 | system_shared_libs: [], |
| 2786 | stl: "none", |
| 2787 | apex_available: [ |
| 2788 | "myapex", |
| 2789 | "otherapex", |
| 2790 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2791 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2792 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2793 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2794 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2795 | `) |
| 2796 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2797 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2798 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 2799 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2800 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2801 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2802 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2803 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2804 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2805 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2806 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2807 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2808 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2809 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex29").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2810 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2811 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2812 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2813 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2814 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 2815 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 2816 | |
| 2817 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 2818 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2819 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2820 | |
| 2821 | // APEX variant has __ANDROID_APEX__ defined |
| 2822 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 2823 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2824 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2825 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 2826 | |
| 2827 | // APEX variant has __ANDROID_APEX__ defined |
| 2828 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 2829 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2830 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 2831 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 2832 | |
| 2833 | // recovery variant does not set __ANDROID_SDK_VERSION__ |
| 2834 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2835 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2836 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
| 2837 | |
| 2838 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 2839 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2840 | |
| 2841 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 2842 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 2843 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2844 | |
| 2845 | // APEX variant has __ANDROID_APEX__ defined |
| 2846 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 2847 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2848 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2849 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2850 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2851 | // APEX variant has __ANDROID_APEX__ defined |
| 2852 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 2853 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2854 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2855 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2856 | |
| 2857 | // recovery variant does not set __ANDROID_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2858 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2859 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 2860 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2861 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2862 | |
| 2863 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2864 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2865 | apex { |
| 2866 | name: "myapex", |
| 2867 | key: "myapex.key", |
| 2868 | native_shared_libs: ["mylib"], |
| 2869 | } |
| 2870 | |
| 2871 | apex_key { |
| 2872 | name: "myapex.key", |
| 2873 | public_key: "testkey.avbpubkey", |
| 2874 | private_key: "testkey.pem", |
| 2875 | } |
| 2876 | |
| 2877 | cc_library_headers { |
| 2878 | name: "mylib_headers", |
| 2879 | export_include_dirs: ["my_include"], |
| 2880 | system_shared_libs: [], |
| 2881 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 2882 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | cc_library { |
| 2886 | name: "mylib", |
| 2887 | srcs: ["mylib.cpp"], |
| 2888 | system_shared_libs: [], |
| 2889 | stl: "none", |
| 2890 | header_libs: ["mylib_headers"], |
| 2891 | export_header_lib_headers: ["mylib_headers"], |
| 2892 | stubs: { |
| 2893 | versions: ["1", "2", "3"], |
| 2894 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2895 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | cc_library { |
| 2899 | name: "otherlib", |
| 2900 | srcs: ["mylib.cpp"], |
| 2901 | system_shared_libs: [], |
| 2902 | stl: "none", |
| 2903 | shared_libs: ["mylib"], |
| 2904 | } |
| 2905 | `) |
| 2906 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2907 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2908 | |
| 2909 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 2910 | ensureContains(t, cFlags, "-Imy_include") |
| 2911 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2912 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2913 | type fileInApex struct { |
| 2914 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2915 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2916 | isLink bool |
| 2917 | } |
| 2918 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2919 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2920 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2921 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2922 | copyCmds := apexRule.Args["copy_commands"] |
| 2923 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2924 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2925 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 2926 | cmd = strings.TrimSpace(cmd) |
| 2927 | if cmd == "" { |
| 2928 | continue |
| 2929 | } |
| 2930 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2931 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2932 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2933 | switch terms[0] { |
| 2934 | case "mkdir": |
| 2935 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2936 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2937 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 2938 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2939 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2940 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2941 | isLink = false |
| 2942 | case "ln": |
| 2943 | if len(terms) != 3 && len(terms) != 4 { |
| 2944 | // ln LINK TARGET or ln -s LINK TARGET |
| 2945 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 2946 | } |
| 2947 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2948 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2949 | isLink = true |
| 2950 | default: |
| 2951 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 2952 | } |
| 2953 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2954 | index := strings.Index(dst, imageApexDir) |
| 2955 | if index == -1 { |
| 2956 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 2957 | } |
| 2958 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2959 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2960 | } |
| 2961 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2962 | return ret |
| 2963 | } |
| 2964 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2965 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 2966 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2967 | var failed bool |
| 2968 | var surplus []string |
| 2969 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2970 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2971 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2972 | for _, expected := range files { |
| 2973 | if matched, _ := path.Match(expected, file.path); matched { |
| 2974 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2975 | mactchFound = true |
| 2976 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2977 | } |
| 2978 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2979 | if !mactchFound { |
| 2980 | surplus = append(surplus, file.path) |
| 2981 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 2982 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2983 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2984 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2985 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2986 | t.Log("surplus files", surplus) |
| 2987 | failed = true |
| 2988 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2989 | |
| 2990 | if len(files) > len(filesMatched) { |
| 2991 | var missing []string |
| 2992 | for _, expected := range files { |
| 2993 | if !filesMatched[expected] { |
| 2994 | missing = append(missing, expected) |
| 2995 | } |
| 2996 | } |
| 2997 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2998 | t.Log("missing files", missing) |
| 2999 | failed = true |
| 3000 | } |
| 3001 | if failed { |
| 3002 | t.Fail() |
| 3003 | } |
| 3004 | } |
| 3005 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3006 | func TestVndkApexCurrent(t *testing.T) { |
| 3007 | ctx, _ := testApex(t, ` |
| 3008 | apex_vndk { |
| 3009 | name: "myapex", |
| 3010 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | apex_key { |
| 3014 | name: "myapex.key", |
| 3015 | public_key: "testkey.avbpubkey", |
| 3016 | private_key: "testkey.pem", |
| 3017 | } |
| 3018 | |
| 3019 | cc_library { |
| 3020 | name: "libvndk", |
| 3021 | srcs: ["mylib.cpp"], |
| 3022 | vendor_available: true, |
| 3023 | vndk: { |
| 3024 | enabled: true, |
| 3025 | }, |
| 3026 | system_shared_libs: [], |
| 3027 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3028 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | cc_library { |
| 3032 | name: "libvndksp", |
| 3033 | srcs: ["mylib.cpp"], |
| 3034 | vendor_available: true, |
| 3035 | vndk: { |
| 3036 | enabled: true, |
| 3037 | support_system_process: true, |
| 3038 | }, |
| 3039 | system_shared_libs: [], |
| 3040 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3041 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3042 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3043 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3044 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3045 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3046 | "lib/libvndk.so", |
| 3047 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3048 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3049 | "lib64/libvndk.so", |
| 3050 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3051 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3052 | "etc/llndk.libraries.VER.txt", |
| 3053 | "etc/vndkcore.libraries.VER.txt", |
| 3054 | "etc/vndksp.libraries.VER.txt", |
| 3055 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3056 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 3060 | ctx, _ := testApex(t, ` |
| 3061 | apex_vndk { |
| 3062 | name: "myapex", |
| 3063 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | apex_key { |
| 3067 | name: "myapex.key", |
| 3068 | public_key: "testkey.avbpubkey", |
| 3069 | private_key: "testkey.pem", |
| 3070 | } |
| 3071 | |
| 3072 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3073 | name: "libvndk", |
| 3074 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3075 | vendor_available: true, |
| 3076 | vndk: { |
| 3077 | enabled: true, |
| 3078 | }, |
| 3079 | system_shared_libs: [], |
| 3080 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3081 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3082 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3083 | |
| 3084 | cc_prebuilt_library_shared { |
| 3085 | name: "libvndk.arm", |
| 3086 | srcs: ["libvndk.arm.so"], |
| 3087 | vendor_available: true, |
| 3088 | vndk: { |
| 3089 | enabled: true, |
| 3090 | }, |
| 3091 | enabled: false, |
| 3092 | arch: { |
| 3093 | arm: { |
| 3094 | enabled: true, |
| 3095 | }, |
| 3096 | }, |
| 3097 | system_shared_libs: [], |
| 3098 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3099 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3100 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3101 | `+vndkLibrariesTxtFiles("current"), |
| 3102 | withFiles(map[string][]byte{ |
| 3103 | "libvndk.so": nil, |
| 3104 | "libvndk.arm.so": nil, |
| 3105 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3106 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3107 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3108 | "lib/libvndk.so", |
| 3109 | "lib/libvndk.arm.so", |
| 3110 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3111 | "lib/libc++.so", |
| 3112 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3113 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3114 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3115 | } |
| 3116 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3117 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3118 | for _, v := range vers { |
| 3119 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 3120 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3121 | result += ` |
| 3122 | vndk_libraries_txt { |
| 3123 | name: "` + txt + `.libraries.txt", |
| 3124 | } |
| 3125 | ` |
| 3126 | } |
| 3127 | } else { |
| 3128 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 3129 | result += ` |
| 3130 | prebuilt_etc { |
| 3131 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3132 | src: "dummy.txt", |
| 3133 | } |
| 3134 | ` |
| 3135 | } |
| 3136 | } |
| 3137 | } |
| 3138 | return |
| 3139 | } |
| 3140 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3141 | func TestVndkApexVersion(t *testing.T) { |
| 3142 | ctx, _ := testApex(t, ` |
| 3143 | apex_vndk { |
| 3144 | name: "myapex_v27", |
| 3145 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3146 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3147 | vndk_version: "27", |
| 3148 | } |
| 3149 | |
| 3150 | apex_key { |
| 3151 | name: "myapex.key", |
| 3152 | public_key: "testkey.avbpubkey", |
| 3153 | private_key: "testkey.pem", |
| 3154 | } |
| 3155 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3156 | vndk_prebuilt_shared { |
| 3157 | name: "libvndk27", |
| 3158 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3159 | vendor_available: true, |
| 3160 | vndk: { |
| 3161 | enabled: true, |
| 3162 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3163 | target_arch: "arm64", |
| 3164 | arch: { |
| 3165 | arm: { |
| 3166 | srcs: ["libvndk27_arm.so"], |
| 3167 | }, |
| 3168 | arm64: { |
| 3169 | srcs: ["libvndk27_arm64.so"], |
| 3170 | }, |
| 3171 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3172 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | vndk_prebuilt_shared { |
| 3176 | name: "libvndk27", |
| 3177 | version: "27", |
| 3178 | vendor_available: true, |
| 3179 | vndk: { |
| 3180 | enabled: true, |
| 3181 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3182 | target_arch: "x86_64", |
| 3183 | arch: { |
| 3184 | x86: { |
| 3185 | srcs: ["libvndk27_x86.so"], |
| 3186 | }, |
| 3187 | x86_64: { |
| 3188 | srcs: ["libvndk27_x86_64.so"], |
| 3189 | }, |
| 3190 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3191 | } |
| 3192 | `+vndkLibrariesTxtFiles("27"), |
| 3193 | withFiles(map[string][]byte{ |
| 3194 | "libvndk27_arm.so": nil, |
| 3195 | "libvndk27_arm64.so": nil, |
| 3196 | "libvndk27_x86.so": nil, |
| 3197 | "libvndk27_x86_64.so": nil, |
| 3198 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3199 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3200 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3201 | "lib/libvndk27_arm.so", |
| 3202 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3203 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3204 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 3208 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 3209 | apex_vndk { |
| 3210 | name: "myapex_v27", |
| 3211 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3212 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3213 | vndk_version: "27", |
| 3214 | } |
| 3215 | apex_vndk { |
| 3216 | name: "myapex_v27_other", |
| 3217 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3218 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3219 | vndk_version: "27", |
| 3220 | } |
| 3221 | |
| 3222 | apex_key { |
| 3223 | name: "myapex.key", |
| 3224 | public_key: "testkey.avbpubkey", |
| 3225 | private_key: "testkey.pem", |
| 3226 | } |
| 3227 | |
| 3228 | cc_library { |
| 3229 | name: "libvndk", |
| 3230 | srcs: ["mylib.cpp"], |
| 3231 | vendor_available: true, |
| 3232 | vndk: { |
| 3233 | enabled: true, |
| 3234 | }, |
| 3235 | system_shared_libs: [], |
| 3236 | stl: "none", |
| 3237 | } |
| 3238 | |
| 3239 | vndk_prebuilt_shared { |
| 3240 | name: "libvndk", |
| 3241 | version: "27", |
| 3242 | vendor_available: true, |
| 3243 | vndk: { |
| 3244 | enabled: true, |
| 3245 | }, |
| 3246 | srcs: ["libvndk.so"], |
| 3247 | } |
| 3248 | `, withFiles(map[string][]byte{ |
| 3249 | "libvndk.so": nil, |
| 3250 | })) |
| 3251 | } |
| 3252 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3253 | func TestVndkApexNameRule(t *testing.T) { |
| 3254 | ctx, _ := testApex(t, ` |
| 3255 | apex_vndk { |
| 3256 | name: "myapex", |
| 3257 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3258 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3259 | } |
| 3260 | apex_vndk { |
| 3261 | name: "myapex_v28", |
| 3262 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3263 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3264 | vndk_version: "28", |
| 3265 | } |
| 3266 | apex_key { |
| 3267 | name: "myapex.key", |
| 3268 | public_key: "testkey.avbpubkey", |
| 3269 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3270 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3271 | |
| 3272 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3273 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3274 | actual := proptools.String(bundle.properties.Apex_name) |
| 3275 | if !reflect.DeepEqual(actual, expected) { |
| 3276 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | assertApexName("com.android.vndk.vVER", "myapex") |
| 3281 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 3282 | } |
| 3283 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3284 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 3285 | ctx, _ := testApex(t, ` |
| 3286 | apex_vndk { |
| 3287 | name: "myapex", |
| 3288 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3289 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | apex_key { |
| 3293 | name: "myapex.key", |
| 3294 | public_key: "testkey.avbpubkey", |
| 3295 | private_key: "testkey.pem", |
| 3296 | } |
| 3297 | |
| 3298 | cc_library { |
| 3299 | name: "libvndk", |
| 3300 | srcs: ["mylib.cpp"], |
| 3301 | vendor_available: true, |
| 3302 | native_bridge_supported: true, |
| 3303 | host_supported: true, |
| 3304 | vndk: { |
| 3305 | enabled: true, |
| 3306 | }, |
| 3307 | system_shared_libs: [], |
| 3308 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3309 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3310 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3311 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3312 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3313 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3314 | "lib/libvndk.so", |
| 3315 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3316 | "lib/libc++.so", |
| 3317 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3318 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3319 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 3323 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 3324 | apex_vndk { |
| 3325 | name: "myapex", |
| 3326 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3327 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3328 | native_bridge_supported: true, |
| 3329 | } |
| 3330 | |
| 3331 | apex_key { |
| 3332 | name: "myapex.key", |
| 3333 | public_key: "testkey.avbpubkey", |
| 3334 | private_key: "testkey.pem", |
| 3335 | } |
| 3336 | |
| 3337 | cc_library { |
| 3338 | name: "libvndk", |
| 3339 | srcs: ["mylib.cpp"], |
| 3340 | vendor_available: true, |
| 3341 | native_bridge_supported: true, |
| 3342 | host_supported: true, |
| 3343 | vndk: { |
| 3344 | enabled: true, |
| 3345 | }, |
| 3346 | system_shared_libs: [], |
| 3347 | stl: "none", |
| 3348 | } |
| 3349 | `) |
| 3350 | } |
| 3351 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3352 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3353 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3354 | apex_vndk { |
| 3355 | name: "myapex_v27", |
| 3356 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3357 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3358 | vndk_version: "27", |
| 3359 | } |
| 3360 | |
| 3361 | apex_key { |
| 3362 | name: "myapex.key", |
| 3363 | public_key: "testkey.avbpubkey", |
| 3364 | private_key: "testkey.pem", |
| 3365 | } |
| 3366 | |
| 3367 | vndk_prebuilt_shared { |
| 3368 | name: "libvndk27", |
| 3369 | version: "27", |
| 3370 | target_arch: "arm", |
| 3371 | vendor_available: true, |
| 3372 | vndk: { |
| 3373 | enabled: true, |
| 3374 | }, |
| 3375 | arch: { |
| 3376 | arm: { |
| 3377 | srcs: ["libvndk27.so"], |
| 3378 | } |
| 3379 | }, |
| 3380 | } |
| 3381 | |
| 3382 | vndk_prebuilt_shared { |
| 3383 | name: "libvndk27", |
| 3384 | version: "27", |
| 3385 | target_arch: "arm", |
| 3386 | binder32bit: true, |
| 3387 | vendor_available: true, |
| 3388 | vndk: { |
| 3389 | enabled: true, |
| 3390 | }, |
| 3391 | arch: { |
| 3392 | arm: { |
| 3393 | srcs: ["libvndk27binder32.so"], |
| 3394 | } |
| 3395 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3396 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3397 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3398 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3399 | withFiles(map[string][]byte{ |
| 3400 | "libvndk27.so": nil, |
| 3401 | "libvndk27binder32.so": nil, |
| 3402 | }), |
| 3403 | withBinder32bit, |
| 3404 | withTargets(map[android.OsType][]android.Target{ |
| 3405 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3406 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3407 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3408 | }, |
| 3409 | }), |
| 3410 | ) |
| 3411 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3412 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3413 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3414 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3415 | }) |
| 3416 | } |
| 3417 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3418 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
| 3419 | ctx, _ := testApex(t, ` |
| 3420 | apex_vndk { |
| 3421 | name: "myapex", |
| 3422 | key: "myapex.key", |
| 3423 | file_contexts: ":myapex-file_contexts", |
| 3424 | } |
| 3425 | |
| 3426 | apex_key { |
| 3427 | name: "myapex.key", |
| 3428 | public_key: "testkey.avbpubkey", |
| 3429 | private_key: "testkey.pem", |
| 3430 | } |
| 3431 | |
| 3432 | cc_library { |
| 3433 | name: "libz", |
| 3434 | vendor_available: true, |
| 3435 | vndk: { |
| 3436 | enabled: true, |
| 3437 | }, |
| 3438 | stubs: { |
| 3439 | symbol_file: "libz.map.txt", |
| 3440 | versions: ["30"], |
| 3441 | } |
| 3442 | } |
| 3443 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3444 | "libz.map.txt": nil, |
| 3445 | })) |
| 3446 | |
| 3447 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_image").Rule("apexManifestRule") |
| 3448 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3449 | ensureListEmpty(t, provideNativeLibs) |
| 3450 | } |
| 3451 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3452 | func TestDependenciesInApexManifest(t *testing.T) { |
| 3453 | ctx, _ := testApex(t, ` |
| 3454 | apex { |
| 3455 | name: "myapex_nodep", |
| 3456 | key: "myapex.key", |
| 3457 | native_shared_libs: ["lib_nodep"], |
| 3458 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3459 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | apex { |
| 3463 | name: "myapex_dep", |
| 3464 | key: "myapex.key", |
| 3465 | native_shared_libs: ["lib_dep"], |
| 3466 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3467 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | apex { |
| 3471 | name: "myapex_provider", |
| 3472 | key: "myapex.key", |
| 3473 | native_shared_libs: ["libfoo"], |
| 3474 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3475 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | apex { |
| 3479 | name: "myapex_selfcontained", |
| 3480 | key: "myapex.key", |
| 3481 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3482 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3483 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | apex_key { |
| 3487 | name: "myapex.key", |
| 3488 | public_key: "testkey.avbpubkey", |
| 3489 | private_key: "testkey.pem", |
| 3490 | } |
| 3491 | |
| 3492 | cc_library { |
| 3493 | name: "lib_nodep", |
| 3494 | srcs: ["mylib.cpp"], |
| 3495 | system_shared_libs: [], |
| 3496 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3497 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | cc_library { |
| 3501 | name: "lib_dep", |
| 3502 | srcs: ["mylib.cpp"], |
| 3503 | shared_libs: ["libfoo"], |
| 3504 | system_shared_libs: [], |
| 3505 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3506 | apex_available: [ |
| 3507 | "myapex_dep", |
| 3508 | "myapex_provider", |
| 3509 | "myapex_selfcontained", |
| 3510 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | cc_library { |
| 3514 | name: "libfoo", |
| 3515 | srcs: ["mytest.cpp"], |
| 3516 | stubs: { |
| 3517 | versions: ["1"], |
| 3518 | }, |
| 3519 | system_shared_libs: [], |
| 3520 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3521 | apex_available: [ |
| 3522 | "myapex_provider", |
| 3523 | "myapex_selfcontained", |
| 3524 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3525 | } |
| 3526 | `) |
| 3527 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3528 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3529 | var provideNativeLibs, requireNativeLibs []string |
| 3530 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3531 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3532 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3533 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3534 | ensureListEmpty(t, provideNativeLibs) |
| 3535 | ensureListEmpty(t, requireNativeLibs) |
| 3536 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3537 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3538 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3539 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3540 | ensureListEmpty(t, provideNativeLibs) |
| 3541 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3542 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3543 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3544 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3545 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3546 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3547 | ensureListEmpty(t, requireNativeLibs) |
| 3548 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3549 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3550 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3551 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3552 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3553 | ensureListEmpty(t, requireNativeLibs) |
| 3554 | } |
| 3555 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3556 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3557 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3558 | apex { |
| 3559 | name: "myapex", |
| 3560 | key: "myapex.key", |
| 3561 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3562 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | apex_key { |
| 3566 | name: "myapex.key", |
| 3567 | public_key: "testkey.avbpubkey", |
| 3568 | private_key: "testkey.pem", |
| 3569 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3570 | |
| 3571 | cc_library { |
| 3572 | name: "mylib", |
| 3573 | srcs: ["mylib.cpp"], |
| 3574 | system_shared_libs: [], |
| 3575 | stl: "none", |
| 3576 | apex_available: [ |
| 3577 | "//apex_available:platform", |
| 3578 | "myapex", |
| 3579 | ], |
| 3580 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3581 | `) |
| 3582 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3583 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3584 | apexManifestRule := module.Rule("apexManifestRule") |
| 3585 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3586 | apexRule := module.Rule("apexRule") |
| 3587 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3588 | |
| 3589 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3590 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3591 | name := apexBundle.BaseModuleName() |
| 3592 | prefix := "TARGET_" |
| 3593 | var builder strings.Builder |
| 3594 | data.Custom(&builder, name, prefix, "", data) |
| 3595 | androidMk := builder.String() |
| 3596 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3597 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3598 | } |
| 3599 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3600 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3601 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3602 | apex { |
| 3603 | name: "myapex", |
| 3604 | key: "myapex.key", |
| 3605 | native_shared_libs: ["mylib_common"], |
| 3606 | } |
| 3607 | |
| 3608 | apex_key { |
| 3609 | name: "myapex.key", |
| 3610 | public_key: "testkey.avbpubkey", |
| 3611 | private_key: "testkey.pem", |
| 3612 | } |
| 3613 | |
| 3614 | cc_library { |
| 3615 | name: "mylib_common", |
| 3616 | srcs: ["mylib.cpp"], |
| 3617 | system_shared_libs: [], |
| 3618 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3619 | apex_available: [ |
| 3620 | "//apex_available:platform", |
| 3621 | "myapex", |
| 3622 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3623 | } |
| 3624 | `) |
| 3625 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3626 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3627 | apexRule := module.Rule("apexRule") |
| 3628 | copyCmds := apexRule.Args["copy_commands"] |
| 3629 | |
| 3630 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3631 | t.Log("Apex was a test apex!") |
| 3632 | t.Fail() |
| 3633 | } |
| 3634 | // Ensure that main rule creates an output |
| 3635 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3636 | |
| 3637 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3638 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3639 | |
| 3640 | // Ensure that both direct and indirect deps are copied into apex |
| 3641 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3642 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3643 | // Ensure that the platform variant ends with _shared |
| 3644 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3645 | |
| 3646 | if !android.InAnyApex("mylib_common") { |
| 3647 | t.Log("Found mylib_common not in any apex!") |
| 3648 | t.Fail() |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | func TestTestApex(t *testing.T) { |
| 3653 | if android.InAnyApex("mylib_common_test") { |
| 3654 | 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!") |
| 3655 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3656 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3657 | apex_test { |
| 3658 | name: "myapex", |
| 3659 | key: "myapex.key", |
| 3660 | native_shared_libs: ["mylib_common_test"], |
| 3661 | } |
| 3662 | |
| 3663 | apex_key { |
| 3664 | name: "myapex.key", |
| 3665 | public_key: "testkey.avbpubkey", |
| 3666 | private_key: "testkey.pem", |
| 3667 | } |
| 3668 | |
| 3669 | cc_library { |
| 3670 | name: "mylib_common_test", |
| 3671 | srcs: ["mylib.cpp"], |
| 3672 | system_shared_libs: [], |
| 3673 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3674 | // TODO: remove //apex_available:platform |
| 3675 | apex_available: [ |
| 3676 | "//apex_available:platform", |
| 3677 | "myapex", |
| 3678 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3679 | } |
| 3680 | `) |
| 3681 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3682 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3683 | apexRule := module.Rule("apexRule") |
| 3684 | copyCmds := apexRule.Args["copy_commands"] |
| 3685 | |
| 3686 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3687 | t.Log("Apex was not a test apex!") |
| 3688 | t.Fail() |
| 3689 | } |
| 3690 | // Ensure that main rule creates an output |
| 3691 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3692 | |
| 3693 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3694 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3695 | |
| 3696 | // Ensure that both direct and indirect deps are copied into apex |
| 3697 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3698 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3699 | // Ensure that the platform variant ends with _shared |
| 3700 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3701 | } |
| 3702 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3703 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3704 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3705 | apex { |
| 3706 | name: "myapex", |
| 3707 | key: "myapex.key", |
| 3708 | multilib: { |
| 3709 | first: { |
| 3710 | native_shared_libs: ["mylib_common"], |
| 3711 | } |
| 3712 | }, |
| 3713 | target: { |
| 3714 | android: { |
| 3715 | multilib: { |
| 3716 | first: { |
| 3717 | native_shared_libs: ["mylib"], |
| 3718 | } |
| 3719 | } |
| 3720 | }, |
| 3721 | host: { |
| 3722 | multilib: { |
| 3723 | first: { |
| 3724 | native_shared_libs: ["mylib2"], |
| 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | apex_key { |
| 3732 | name: "myapex.key", |
| 3733 | public_key: "testkey.avbpubkey", |
| 3734 | private_key: "testkey.pem", |
| 3735 | } |
| 3736 | |
| 3737 | cc_library { |
| 3738 | name: "mylib", |
| 3739 | srcs: ["mylib.cpp"], |
| 3740 | system_shared_libs: [], |
| 3741 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3742 | // TODO: remove //apex_available:platform |
| 3743 | apex_available: [ |
| 3744 | "//apex_available:platform", |
| 3745 | "myapex", |
| 3746 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | cc_library { |
| 3750 | name: "mylib_common", |
| 3751 | srcs: ["mylib.cpp"], |
| 3752 | system_shared_libs: [], |
| 3753 | stl: "none", |
| 3754 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3755 | // TODO: remove //apex_available:platform |
| 3756 | apex_available: [ |
| 3757 | "//apex_available:platform", |
| 3758 | "myapex", |
| 3759 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | cc_library { |
| 3763 | name: "mylib2", |
| 3764 | srcs: ["mylib.cpp"], |
| 3765 | system_shared_libs: [], |
| 3766 | stl: "none", |
| 3767 | compile_multilib: "first", |
| 3768 | } |
| 3769 | `) |
| 3770 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3771 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3772 | copyCmds := apexRule.Args["copy_commands"] |
| 3773 | |
| 3774 | // Ensure that main rule creates an output |
| 3775 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3776 | |
| 3777 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3778 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 3779 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 3780 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3781 | |
| 3782 | // Ensure that both direct and indirect deps are copied into apex |
| 3783 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3784 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3785 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3786 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3787 | // Ensure that the platform variant ends with _shared |
| 3788 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3789 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3790 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3791 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3792 | |
| 3793 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3794 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3795 | apex { |
| 3796 | name: "myapex", |
| 3797 | key: "myapex.key", |
| 3798 | binaries: ["myscript"], |
| 3799 | } |
| 3800 | |
| 3801 | apex_key { |
| 3802 | name: "myapex.key", |
| 3803 | public_key: "testkey.avbpubkey", |
| 3804 | private_key: "testkey.pem", |
| 3805 | } |
| 3806 | |
| 3807 | sh_binary { |
| 3808 | name: "myscript", |
| 3809 | src: "mylib.cpp", |
| 3810 | filename: "myscript.sh", |
| 3811 | sub_dir: "script", |
| 3812 | } |
| 3813 | `) |
| 3814 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3815 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3816 | copyCmds := apexRule.Args["copy_commands"] |
| 3817 | |
| 3818 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 3819 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3820 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3821 | func TestApexInVariousPartition(t *testing.T) { |
| 3822 | testcases := []struct { |
| 3823 | propName, parition, flattenedPartition string |
| 3824 | }{ |
| 3825 | {"", "system", "system_ext"}, |
| 3826 | {"product_specific: true", "product", "product"}, |
| 3827 | {"soc_specific: true", "vendor", "vendor"}, |
| 3828 | {"proprietary: true", "vendor", "vendor"}, |
| 3829 | {"vendor: true", "vendor", "vendor"}, |
| 3830 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 3831 | } |
| 3832 | for _, tc := range testcases { |
| 3833 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 3834 | ctx, _ := testApex(t, ` |
| 3835 | apex { |
| 3836 | name: "myapex", |
| 3837 | key: "myapex.key", |
| 3838 | `+tc.propName+` |
| 3839 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3840 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3841 | apex_key { |
| 3842 | name: "myapex.key", |
| 3843 | public_key: "testkey.avbpubkey", |
| 3844 | private_key: "testkey.pem", |
| 3845 | } |
| 3846 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3847 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3848 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3849 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 3850 | actual := apex.installDir.String() |
| 3851 | if actual != expected { |
| 3852 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 3853 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3854 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 3855 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 3856 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 3857 | actual = flattened.installDir.String() |
| 3858 | if actual != expected { |
| 3859 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 3860 | } |
| 3861 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3862 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3863 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3864 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3865 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3866 | ctx, _ := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3867 | apex { |
| 3868 | name: "myapex", |
| 3869 | key: "myapex.key", |
| 3870 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3871 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3872 | apex_key { |
| 3873 | name: "myapex.key", |
| 3874 | public_key: "testkey.avbpubkey", |
| 3875 | private_key: "testkey.pem", |
| 3876 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3877 | `) |
| 3878 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3879 | rule := module.Output("file_contexts") |
| 3880 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 3881 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3882 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3883 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3884 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3885 | apex { |
| 3886 | name: "myapex", |
| 3887 | key: "myapex.key", |
| 3888 | file_contexts: "my_own_file_contexts", |
| 3889 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3890 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3891 | apex_key { |
| 3892 | name: "myapex.key", |
| 3893 | public_key: "testkey.avbpubkey", |
| 3894 | private_key: "testkey.pem", |
| 3895 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3896 | `, withFiles(map[string][]byte{ |
| 3897 | "my_own_file_contexts": nil, |
| 3898 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3899 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3900 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3901 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3902 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3903 | apex { |
| 3904 | name: "myapex", |
| 3905 | key: "myapex.key", |
| 3906 | product_specific: true, |
| 3907 | file_contexts: "product_specific_file_contexts", |
| 3908 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3909 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3910 | apex_key { |
| 3911 | name: "myapex.key", |
| 3912 | public_key: "testkey.avbpubkey", |
| 3913 | private_key: "testkey.pem", |
| 3914 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3915 | `) |
| 3916 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3917 | ctx, _ := testApex(t, ` |
| 3918 | apex { |
| 3919 | name: "myapex", |
| 3920 | key: "myapex.key", |
| 3921 | product_specific: true, |
| 3922 | file_contexts: "product_specific_file_contexts", |
| 3923 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3924 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3925 | apex_key { |
| 3926 | name: "myapex.key", |
| 3927 | public_key: "testkey.avbpubkey", |
| 3928 | private_key: "testkey.pem", |
| 3929 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3930 | `, withFiles(map[string][]byte{ |
| 3931 | "product_specific_file_contexts": nil, |
| 3932 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3933 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3934 | rule := module.Output("file_contexts") |
| 3935 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 3936 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3937 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3938 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
| 3939 | ctx, _ := testApex(t, ` |
| 3940 | apex { |
| 3941 | name: "myapex", |
| 3942 | key: "myapex.key", |
| 3943 | product_specific: true, |
| 3944 | file_contexts: ":my-file-contexts", |
| 3945 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3946 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3947 | apex_key { |
| 3948 | name: "myapex.key", |
| 3949 | public_key: "testkey.avbpubkey", |
| 3950 | private_key: "testkey.pem", |
| 3951 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3952 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3953 | filegroup { |
| 3954 | name: "my-file-contexts", |
| 3955 | srcs: ["product_specific_file_contexts"], |
| 3956 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3957 | `, withFiles(map[string][]byte{ |
| 3958 | "product_specific_file_contexts": nil, |
| 3959 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 3960 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3961 | rule := module.Output("file_contexts") |
| 3962 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3963 | } |
| 3964 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3965 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3966 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 3967 | apex_key { |
| 3968 | name: "myapex.key", |
| 3969 | public_key: ":my.avbpubkey", |
| 3970 | private_key: ":my.pem", |
| 3971 | product_specific: true, |
| 3972 | } |
| 3973 | |
| 3974 | filegroup { |
| 3975 | name: "my.avbpubkey", |
| 3976 | srcs: ["testkey2.avbpubkey"], |
| 3977 | } |
| 3978 | |
| 3979 | filegroup { |
| 3980 | name: "my.pem", |
| 3981 | srcs: ["testkey2.pem"], |
| 3982 | } |
| 3983 | `) |
| 3984 | |
| 3985 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 3986 | expected_pubkey := "testkey2.avbpubkey" |
| 3987 | actual_pubkey := apex_key.public_key_file.String() |
| 3988 | if actual_pubkey != expected_pubkey { |
| 3989 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 3990 | } |
| 3991 | expected_privkey := "testkey2.pem" |
| 3992 | actual_privkey := apex_key.private_key_file.String() |
| 3993 | if actual_privkey != expected_privkey { |
| 3994 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 3995 | } |
| 3996 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 3997 | |
| 3998 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3999 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4000 | prebuilt_apex { |
| 4001 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4002 | arch: { |
| 4003 | arm64: { |
| 4004 | src: "myapex-arm64.apex", |
| 4005 | }, |
| 4006 | arm: { |
| 4007 | src: "myapex-arm.apex", |
| 4008 | }, |
| 4009 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4010 | } |
| 4011 | `) |
| 4012 | |
| 4013 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4014 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4015 | expectedInput := "myapex-arm64.apex" |
| 4016 | if prebuilt.inputApex.String() != expectedInput { |
| 4017 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4018 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4019 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4020 | |
| 4021 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4022 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4023 | prebuilt_apex { |
| 4024 | name: "myapex", |
| 4025 | src: "myapex-arm.apex", |
| 4026 | filename: "notmyapex.apex", |
| 4027 | } |
| 4028 | `) |
| 4029 | |
| 4030 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4031 | |
| 4032 | expected := "notmyapex.apex" |
| 4033 | if p.installFilename != expected { |
| 4034 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4035 | } |
| 4036 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4037 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4038 | func TestPrebuiltOverrides(t *testing.T) { |
| 4039 | ctx, config := testApex(t, ` |
| 4040 | prebuilt_apex { |
| 4041 | name: "myapex.prebuilt", |
| 4042 | src: "myapex-arm.apex", |
| 4043 | overrides: [ |
| 4044 | "myapex", |
| 4045 | ], |
| 4046 | } |
| 4047 | `) |
| 4048 | |
| 4049 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4050 | |
| 4051 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 4052 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4053 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4054 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4058 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4059 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4060 | apex_test { |
| 4061 | name: "myapex", |
| 4062 | key: "myapex.key", |
| 4063 | tests: [ |
| 4064 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4065 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4066 | ], |
| 4067 | } |
| 4068 | |
| 4069 | apex_key { |
| 4070 | name: "myapex.key", |
| 4071 | public_key: "testkey.avbpubkey", |
| 4072 | private_key: "testkey.pem", |
| 4073 | } |
| 4074 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4075 | filegroup { |
| 4076 | name: "fg", |
| 4077 | srcs: [ |
| 4078 | "baz", |
| 4079 | "bar/baz" |
| 4080 | ], |
| 4081 | } |
| 4082 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4083 | cc_test { |
| 4084 | name: "mytest", |
| 4085 | gtest: false, |
| 4086 | srcs: ["mytest.cpp"], |
| 4087 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4088 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4089 | system_shared_libs: [], |
| 4090 | static_executable: true, |
| 4091 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4092 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4093 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4094 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4095 | cc_library { |
| 4096 | name: "mylib", |
| 4097 | srcs: ["mylib.cpp"], |
| 4098 | system_shared_libs: [], |
| 4099 | stl: "none", |
| 4100 | } |
| 4101 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4102 | filegroup { |
| 4103 | name: "fg2", |
| 4104 | srcs: [ |
| 4105 | "testdata/baz" |
| 4106 | ], |
| 4107 | } |
| 4108 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4109 | cc_test { |
| 4110 | name: "mytests", |
| 4111 | gtest: false, |
| 4112 | srcs: [ |
| 4113 | "mytest1.cpp", |
| 4114 | "mytest2.cpp", |
| 4115 | "mytest3.cpp", |
| 4116 | ], |
| 4117 | test_per_src: true, |
| 4118 | relative_install_path: "test", |
| 4119 | system_shared_libs: [], |
| 4120 | static_executable: true, |
| 4121 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4122 | data: [ |
| 4123 | ":fg", |
| 4124 | ":fg2", |
| 4125 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4126 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4127 | `) |
| 4128 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4129 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4130 | copyCmds := apexRule.Args["copy_commands"] |
| 4131 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4132 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4133 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4134 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4135 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4136 | //Ensure that test data are copied into apex. |
| 4137 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4138 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4139 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4140 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4141 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4142 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4143 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4144 | |
| 4145 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4146 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 4147 | data := android.AndroidMkDataForTest(t, config, "", bundle) |
| 4148 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4149 | prefix := "TARGET_" |
| 4150 | var builder strings.Builder |
| 4151 | data.Custom(&builder, name, prefix, "", data) |
| 4152 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4153 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4154 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4155 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4156 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4157 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4158 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4159 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4160 | |
| 4161 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 4162 | data = android.AndroidMkDataForTest(t, config, "", flatBundle) |
| 4163 | data.Custom(&builder, name, prefix, "", data) |
| 4164 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4165 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 4166 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4169 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 4170 | ctx, config := testApex(t, ` |
| 4171 | apex { |
| 4172 | name: "myapex", |
| 4173 | key: "myapex.key", |
| 4174 | } |
| 4175 | apex_key { |
| 4176 | name: "myapex.key", |
| 4177 | public_key: "testkey.avbpubkey", |
| 4178 | private_key: "testkey.pem", |
| 4179 | } |
| 4180 | `, func(fs map[string][]byte, config android.Config) { |
| 4181 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 4182 | }) |
| 4183 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 4184 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4185 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 4186 | var builder strings.Builder |
| 4187 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 4188 | androidMk := builder.String() |
| 4189 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 4190 | } |
| 4191 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4192 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4193 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4194 | apex { |
| 4195 | name: "myapex", |
| 4196 | key: "myapex.key", |
| 4197 | native_shared_libs: ["mylib"], |
| 4198 | uses: ["commonapex"], |
| 4199 | } |
| 4200 | |
| 4201 | apex { |
| 4202 | name: "commonapex", |
| 4203 | key: "myapex.key", |
| 4204 | native_shared_libs: ["libcommon"], |
| 4205 | provide_cpp_shared_libs: true, |
| 4206 | } |
| 4207 | |
| 4208 | apex_key { |
| 4209 | name: "myapex.key", |
| 4210 | public_key: "testkey.avbpubkey", |
| 4211 | private_key: "testkey.pem", |
| 4212 | } |
| 4213 | |
| 4214 | cc_library { |
| 4215 | name: "mylib", |
| 4216 | srcs: ["mylib.cpp"], |
| 4217 | shared_libs: ["libcommon"], |
| 4218 | system_shared_libs: [], |
| 4219 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4220 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | cc_library { |
| 4224 | name: "libcommon", |
| 4225 | srcs: ["mylib_common.cpp"], |
| 4226 | system_shared_libs: [], |
| 4227 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4228 | // TODO: remove //apex_available:platform |
| 4229 | apex_available: [ |
| 4230 | "//apex_available:platform", |
| 4231 | "commonapex", |
| 4232 | "myapex", |
| 4233 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4234 | } |
| 4235 | `) |
| 4236 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4237 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4238 | apexRule1 := module1.Rule("apexRule") |
| 4239 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 4240 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4241 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4242 | apexRule2 := module2.Rule("apexRule") |
| 4243 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 4244 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4245 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 4246 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_apex10000") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4247 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 4248 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 4249 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 4250 | } |
| 4251 | |
| 4252 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 4253 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 4254 | apex { |
| 4255 | name: "myapex", |
| 4256 | key: "myapex.key", |
| 4257 | uses: ["commonapex"], |
| 4258 | } |
| 4259 | |
| 4260 | apex { |
| 4261 | name: "commonapex", |
| 4262 | key: "myapex.key", |
| 4263 | } |
| 4264 | |
| 4265 | apex_key { |
| 4266 | name: "myapex.key", |
| 4267 | public_key: "testkey.avbpubkey", |
| 4268 | private_key: "testkey.pem", |
| 4269 | } |
| 4270 | `) |
| 4271 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 4272 | apex { |
| 4273 | name: "myapex", |
| 4274 | key: "myapex.key", |
| 4275 | uses: ["commonapex"], |
| 4276 | } |
| 4277 | |
| 4278 | cc_library { |
| 4279 | name: "commonapex", |
| 4280 | system_shared_libs: [], |
| 4281 | stl: "none", |
| 4282 | } |
| 4283 | |
| 4284 | apex_key { |
| 4285 | name: "myapex.key", |
| 4286 | public_key: "testkey.avbpubkey", |
| 4287 | private_key: "testkey.pem", |
| 4288 | } |
| 4289 | `) |
| 4290 | } |
| 4291 | |
| 4292 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 4293 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 4294 | apex { |
| 4295 | name: "myapex", |
| 4296 | key: "myapex.key", |
| 4297 | use_vendor: true, |
| 4298 | uses: ["commonapex"], |
| 4299 | } |
| 4300 | |
| 4301 | apex { |
| 4302 | name: "commonapex", |
| 4303 | key: "myapex.key", |
| 4304 | provide_cpp_shared_libs: true, |
| 4305 | } |
| 4306 | |
| 4307 | apex_key { |
| 4308 | name: "myapex.key", |
| 4309 | public_key: "testkey.avbpubkey", |
| 4310 | private_key: "testkey.pem", |
| 4311 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 4312 | `, func(fs map[string][]byte, config android.Config) { |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 4313 | setUseVendorAllowListForTest(config, []string{"myapex"}) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 4314 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 4315 | } |
| 4316 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4317 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4318 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4319 | apex { |
| 4320 | name: "myapex", |
| 4321 | key: "myapex.key", |
| 4322 | native_shared_libs: ["libfoo"], |
| 4323 | } |
| 4324 | |
| 4325 | apex_key { |
| 4326 | name: "myapex.key", |
| 4327 | public_key: "testkey.avbpubkey", |
| 4328 | private_key: "testkey.pem", |
| 4329 | } |
| 4330 | |
| 4331 | cc_library { |
| 4332 | name: "libfoo", |
| 4333 | stl: "none", |
| 4334 | system_shared_libs: [], |
| 4335 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4336 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4337 | } |
| 4338 | `) |
| 4339 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4340 | apex { |
| 4341 | name: "myapex", |
| 4342 | key: "myapex.key", |
| 4343 | java_libs: ["myjar"], |
| 4344 | } |
| 4345 | |
| 4346 | apex_key { |
| 4347 | name: "myapex.key", |
| 4348 | public_key: "testkey.avbpubkey", |
| 4349 | private_key: "testkey.pem", |
| 4350 | } |
| 4351 | |
| 4352 | java_library { |
| 4353 | name: "myjar", |
| 4354 | srcs: ["foo/bar/MyClass.java"], |
| 4355 | sdk_version: "none", |
| 4356 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4357 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4358 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4359 | } |
| 4360 | `) |
| 4361 | } |
| 4362 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4363 | func TestApexWithApps(t *testing.T) { |
| 4364 | ctx, _ := testApex(t, ` |
| 4365 | apex { |
| 4366 | name: "myapex", |
| 4367 | key: "myapex.key", |
| 4368 | apps: [ |
| 4369 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4370 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4371 | ], |
| 4372 | } |
| 4373 | |
| 4374 | apex_key { |
| 4375 | name: "myapex.key", |
| 4376 | public_key: "testkey.avbpubkey", |
| 4377 | private_key: "testkey.pem", |
| 4378 | } |
| 4379 | |
| 4380 | android_app { |
| 4381 | name: "AppFoo", |
| 4382 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4383 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4384 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4385 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4386 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4387 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4388 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4389 | |
| 4390 | android_app { |
| 4391 | name: "AppFooPriv", |
| 4392 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4393 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4394 | system_modules: "none", |
| 4395 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4396 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4397 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4398 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4399 | |
| 4400 | cc_library_shared { |
| 4401 | name: "libjni", |
| 4402 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4403 | shared_libs: ["libfoo"], |
| 4404 | stl: "none", |
| 4405 | system_shared_libs: [], |
| 4406 | apex_available: [ "myapex" ], |
| 4407 | sdk_version: "current", |
| 4408 | } |
| 4409 | |
| 4410 | cc_library_shared { |
| 4411 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4412 | stl: "none", |
| 4413 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 4414 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 4415 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 4416 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4417 | `) |
| 4418 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4419 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4420 | apexRule := module.Rule("apexRule") |
| 4421 | copyCmds := apexRule.Args["copy_commands"] |
| 4422 | |
| 4423 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 4424 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4425 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4426 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4427 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4428 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4429 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 4430 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4431 | // JNI libraries including transitive deps are |
| 4432 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4433 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_apex10000").Module().(*cc.Module).OutputFile() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 4434 | // ... embedded inside APK (jnilibs.zip) |
| 4435 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 4436 | // ... and not directly inside the APEX |
| 4437 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 4438 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4439 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4440 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4441 | func TestApexWithAppImports(t *testing.T) { |
| 4442 | ctx, _ := testApex(t, ` |
| 4443 | apex { |
| 4444 | name: "myapex", |
| 4445 | key: "myapex.key", |
| 4446 | apps: [ |
| 4447 | "AppFooPrebuilt", |
| 4448 | "AppFooPrivPrebuilt", |
| 4449 | ], |
| 4450 | } |
| 4451 | |
| 4452 | apex_key { |
| 4453 | name: "myapex.key", |
| 4454 | public_key: "testkey.avbpubkey", |
| 4455 | private_key: "testkey.pem", |
| 4456 | } |
| 4457 | |
| 4458 | android_app_import { |
| 4459 | name: "AppFooPrebuilt", |
| 4460 | apk: "PrebuiltAppFoo.apk", |
| 4461 | presigned: true, |
| 4462 | dex_preopt: { |
| 4463 | enabled: false, |
| 4464 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4465 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | android_app_import { |
| 4469 | name: "AppFooPrivPrebuilt", |
| 4470 | apk: "PrebuiltAppFooPriv.apk", |
| 4471 | privileged: true, |
| 4472 | presigned: true, |
| 4473 | dex_preopt: { |
| 4474 | enabled: false, |
| 4475 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4476 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4477 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4478 | } |
| 4479 | `) |
| 4480 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4481 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 4482 | apexRule := module.Rule("apexRule") |
| 4483 | copyCmds := apexRule.Args["copy_commands"] |
| 4484 | |
| 4485 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4486 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 4487 | } |
| 4488 | |
| 4489 | func TestApexWithAppImportsPrefer(t *testing.T) { |
| 4490 | ctx, _ := testApex(t, ` |
| 4491 | apex { |
| 4492 | name: "myapex", |
| 4493 | key: "myapex.key", |
| 4494 | apps: [ |
| 4495 | "AppFoo", |
| 4496 | ], |
| 4497 | } |
| 4498 | |
| 4499 | apex_key { |
| 4500 | name: "myapex.key", |
| 4501 | public_key: "testkey.avbpubkey", |
| 4502 | private_key: "testkey.pem", |
| 4503 | } |
| 4504 | |
| 4505 | android_app { |
| 4506 | name: "AppFoo", |
| 4507 | srcs: ["foo/bar/MyClass.java"], |
| 4508 | sdk_version: "none", |
| 4509 | system_modules: "none", |
| 4510 | apex_available: [ "myapex" ], |
| 4511 | } |
| 4512 | |
| 4513 | android_app_import { |
| 4514 | name: "AppFoo", |
| 4515 | apk: "AppFooPrebuilt.apk", |
| 4516 | filename: "AppFooPrebuilt.apk", |
| 4517 | presigned: true, |
| 4518 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 4519 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4520 | } |
| 4521 | `, withFiles(map[string][]byte{ |
| 4522 | "AppFooPrebuilt.apk": nil, |
| 4523 | })) |
| 4524 | |
| 4525 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4526 | "app/AppFoo/AppFooPrebuilt.apk", |
| 4527 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4528 | } |
| 4529 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4530 | func TestApexWithTestHelperApp(t *testing.T) { |
| 4531 | ctx, _ := testApex(t, ` |
| 4532 | apex { |
| 4533 | name: "myapex", |
| 4534 | key: "myapex.key", |
| 4535 | apps: [ |
| 4536 | "TesterHelpAppFoo", |
| 4537 | ], |
| 4538 | } |
| 4539 | |
| 4540 | apex_key { |
| 4541 | name: "myapex.key", |
| 4542 | public_key: "testkey.avbpubkey", |
| 4543 | private_key: "testkey.pem", |
| 4544 | } |
| 4545 | |
| 4546 | android_test_helper_app { |
| 4547 | name: "TesterHelpAppFoo", |
| 4548 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4549 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | `) |
| 4553 | |
| 4554 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4555 | apexRule := module.Rule("apexRule") |
| 4556 | copyCmds := apexRule.Args["copy_commands"] |
| 4557 | |
| 4558 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 4559 | } |
| 4560 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4561 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 4562 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4563 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 4564 | apex { |
| 4565 | name: "myapex", |
| 4566 | key: "myapex.key", |
| 4567 | native_shared_libs: ["libfoo"], |
| 4568 | } |
| 4569 | |
| 4570 | apex_key { |
| 4571 | name: "myapex.key", |
| 4572 | public_key: "testkey.avbpubkey", |
| 4573 | private_key: "testkey.pem", |
| 4574 | } |
| 4575 | |
| 4576 | apex { |
| 4577 | name: "otherapex", |
| 4578 | key: "myapex.key", |
| 4579 | native_shared_libs: ["libfoo"], |
| 4580 | } |
| 4581 | |
| 4582 | cc_defaults { |
| 4583 | name: "libfoo-defaults", |
| 4584 | apex_available: ["otherapex"], |
| 4585 | } |
| 4586 | |
| 4587 | cc_library { |
| 4588 | name: "libfoo", |
| 4589 | defaults: ["libfoo-defaults"], |
| 4590 | stl: "none", |
| 4591 | system_shared_libs: [], |
| 4592 | }`) |
| 4593 | } |
| 4594 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4595 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4596 | // libfoo is not available to myapex, but only to otherapex |
| 4597 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 4598 | apex { |
| 4599 | name: "myapex", |
| 4600 | key: "myapex.key", |
| 4601 | native_shared_libs: ["libfoo"], |
| 4602 | } |
| 4603 | |
| 4604 | apex_key { |
| 4605 | name: "myapex.key", |
| 4606 | public_key: "testkey.avbpubkey", |
| 4607 | private_key: "testkey.pem", |
| 4608 | } |
| 4609 | |
| 4610 | apex { |
| 4611 | name: "otherapex", |
| 4612 | key: "otherapex.key", |
| 4613 | native_shared_libs: ["libfoo"], |
| 4614 | } |
| 4615 | |
| 4616 | apex_key { |
| 4617 | name: "otherapex.key", |
| 4618 | public_key: "testkey.avbpubkey", |
| 4619 | private_key: "testkey.pem", |
| 4620 | } |
| 4621 | |
| 4622 | cc_library { |
| 4623 | name: "libfoo", |
| 4624 | stl: "none", |
| 4625 | system_shared_libs: [], |
| 4626 | apex_available: ["otherapex"], |
| 4627 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4628 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4629 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4630 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4631 | // libbbaz is an indirect dep |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4632 | testApexError(t, `requires "libbaz" that is not available for the APEX. Dependency path: |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 4633 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4634 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 4635 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 4636 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 4637 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 4638 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4639 | apex { |
| 4640 | name: "myapex", |
| 4641 | key: "myapex.key", |
| 4642 | native_shared_libs: ["libfoo"], |
| 4643 | } |
| 4644 | |
| 4645 | apex_key { |
| 4646 | name: "myapex.key", |
| 4647 | public_key: "testkey.avbpubkey", |
| 4648 | private_key: "testkey.pem", |
| 4649 | } |
| 4650 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4651 | cc_library { |
| 4652 | name: "libfoo", |
| 4653 | stl: "none", |
| 4654 | shared_libs: ["libbar"], |
| 4655 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4656 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | cc_library { |
| 4660 | name: "libbar", |
| 4661 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4662 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4663 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4664 | apex_available: ["myapex"], |
| 4665 | } |
| 4666 | |
| 4667 | cc_library { |
| 4668 | name: "libbaz", |
| 4669 | stl: "none", |
| 4670 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4671 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4672 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4673 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4674 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4675 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 4676 | apex { |
| 4677 | name: "myapex", |
| 4678 | key: "myapex.key", |
| 4679 | native_shared_libs: ["libfoo"], |
| 4680 | } |
| 4681 | |
| 4682 | apex_key { |
| 4683 | name: "myapex.key", |
| 4684 | public_key: "testkey.avbpubkey", |
| 4685 | private_key: "testkey.pem", |
| 4686 | } |
| 4687 | |
| 4688 | cc_library { |
| 4689 | name: "libfoo", |
| 4690 | stl: "none", |
| 4691 | system_shared_libs: [], |
| 4692 | apex_available: ["otherapex"], |
| 4693 | }`) |
| 4694 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4695 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4696 | apex { |
| 4697 | name: "myapex", |
| 4698 | key: "myapex.key", |
| 4699 | native_shared_libs: ["libfoo", "libbar"], |
| 4700 | } |
| 4701 | |
| 4702 | apex_key { |
| 4703 | name: "myapex.key", |
| 4704 | public_key: "testkey.avbpubkey", |
| 4705 | private_key: "testkey.pem", |
| 4706 | } |
| 4707 | |
| 4708 | cc_library { |
| 4709 | name: "libfoo", |
| 4710 | stl: "none", |
| 4711 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4712 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4713 | apex_available: ["myapex"], |
| 4714 | } |
| 4715 | |
| 4716 | cc_library { |
| 4717 | name: "libbar", |
| 4718 | stl: "none", |
| 4719 | system_shared_libs: [], |
| 4720 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | cc_library { |
| 4724 | name: "libbaz", |
| 4725 | stl: "none", |
| 4726 | system_shared_libs: [], |
| 4727 | stubs: { |
| 4728 | versions: ["10", "20", "30"], |
| 4729 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4730 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4731 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4732 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4733 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4734 | ctx, _ := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4735 | apex { |
| 4736 | name: "myapex", |
| 4737 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4738 | native_shared_libs: ["libbar", "libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | apex_key { |
| 4742 | name: "myapex.key", |
| 4743 | public_key: "testkey.avbpubkey", |
| 4744 | private_key: "testkey.pem", |
| 4745 | } |
| 4746 | |
| 4747 | cc_library { |
| 4748 | name: "libfoo", |
| 4749 | stl: "none", |
| 4750 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4751 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4752 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | cc_library { |
| 4756 | name: "libfoo2", |
| 4757 | stl: "none", |
| 4758 | system_shared_libs: [], |
| 4759 | shared_libs: ["libbaz"], |
| 4760 | apex_available: ["//apex_available:platform"], |
| 4761 | } |
| 4762 | |
| 4763 | cc_library { |
| 4764 | name: "libbar", |
| 4765 | stl: "none", |
| 4766 | system_shared_libs: [], |
| 4767 | apex_available: ["myapex"], |
| 4768 | } |
| 4769 | |
| 4770 | cc_library { |
| 4771 | name: "libbaz", |
| 4772 | stl: "none", |
| 4773 | system_shared_libs: [], |
| 4774 | apex_available: ["myapex"], |
| 4775 | stubs: { |
| 4776 | versions: ["1"], |
| 4777 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4778 | }`) |
| 4779 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4780 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 4781 | // because it depends on libbar which isn't available to platform |
| 4782 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4783 | if libfoo.NotAvailableForPlatform() != true { |
| 4784 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 4785 | } |
| 4786 | |
| 4787 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 4788 | // stubs |
| 4789 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4790 | if libfoo2.NotAvailableForPlatform() == true { |
| 4791 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 4792 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4793 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4794 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 4795 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4796 | ctx, _ := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 4797 | apex { |
| 4798 | name: "myapex", |
| 4799 | key: "myapex.key", |
| 4800 | native_shared_libs: ["libfoo"], |
| 4801 | } |
| 4802 | |
| 4803 | apex_key { |
| 4804 | name: "myapex.key", |
| 4805 | public_key: "testkey.avbpubkey", |
| 4806 | private_key: "testkey.pem", |
| 4807 | } |
| 4808 | |
| 4809 | cc_library { |
| 4810 | name: "libfoo", |
| 4811 | stl: "none", |
| 4812 | system_shared_libs: [], |
| 4813 | apex_available: ["myapex"], |
| 4814 | static: { |
| 4815 | apex_available: ["//apex_available:platform"], |
| 4816 | }, |
| 4817 | }`) |
| 4818 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 4819 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 4820 | if libfooShared.NotAvailableForPlatform() != true { |
| 4821 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 4822 | } |
| 4823 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 4824 | if libfooStatic.NotAvailableForPlatform() != false { |
| 4825 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 4826 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 4827 | } |
| 4828 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4829 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4830 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4831 | apex { |
| 4832 | name: "myapex", |
| 4833 | key: "myapex.key", |
| 4834 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4835 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4836 | } |
| 4837 | |
| 4838 | override_apex { |
| 4839 | name: "override_myapex", |
| 4840 | base: "myapex", |
| 4841 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4842 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 4843 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 4844 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | apex_key { |
| 4848 | name: "myapex.key", |
| 4849 | public_key: "testkey.avbpubkey", |
| 4850 | private_key: "testkey.pem", |
| 4851 | } |
| 4852 | |
| 4853 | android_app { |
| 4854 | name: "app", |
| 4855 | srcs: ["foo/bar/MyClass.java"], |
| 4856 | package_name: "foo", |
| 4857 | sdk_version: "none", |
| 4858 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4859 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | override_android_app { |
| 4863 | name: "override_app", |
| 4864 | base: "app", |
| 4865 | package_name: "bar", |
| 4866 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4867 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4868 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 4869 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 4870 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 4871 | if originalVariant.GetOverriddenBy() != "" { |
| 4872 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 4873 | } |
| 4874 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 4875 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 4876 | } |
| 4877 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4878 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 4879 | apexRule := module.Rule("apexRule") |
| 4880 | copyCmds := apexRule.Args["copy_commands"] |
| 4881 | |
| 4882 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 4883 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4884 | |
| 4885 | apexBundle := module.Module().(*apexBundle) |
| 4886 | name := apexBundle.Name() |
| 4887 | if name != "override_myapex" { |
| 4888 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 4889 | } |
| 4890 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 4891 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 4892 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 4893 | } |
| 4894 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4895 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 4896 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 4897 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4898 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 4899 | var builder strings.Builder |
| 4900 | data.Custom(&builder, name, "TARGET_", "", data) |
| 4901 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 4902 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4903 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 4904 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 4905 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4906 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 4907 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 4908 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 4909 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 4910 | } |
| 4911 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4912 | func TestLegacyAndroid10Support(t *testing.T) { |
| 4913 | ctx, _ := testApex(t, ` |
| 4914 | apex { |
| 4915 | name: "myapex", |
| 4916 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4917 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 4918 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | apex_key { |
| 4922 | name: "myapex.key", |
| 4923 | public_key: "testkey.avbpubkey", |
| 4924 | private_key: "testkey.pem", |
| 4925 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4926 | |
| 4927 | cc_library { |
| 4928 | name: "mylib", |
| 4929 | srcs: ["mylib.cpp"], |
| 4930 | stl: "libc++", |
| 4931 | system_shared_libs: [], |
| 4932 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 4933 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4934 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4935 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4936 | |
| 4937 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4938 | args := module.Rule("apexRule").Args |
| 4939 | ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String()) |
Dario Freni | e354690 | 2020-01-14 23:50:25 +0000 | [diff] [blame] | 4940 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4941 | |
| 4942 | // The copies of the libraries in the apex should have one more dependency than |
| 4943 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 4944 | // the dependency names directly here but for some reason the names are blank in |
| 4945 | // this test. |
| 4946 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4947 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_apex29").Rule("ld").Implicits |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 4948 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 4949 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 4950 | t.Errorf("%q missing unwinder dep", lib) |
| 4951 | } |
| 4952 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4953 | } |
| 4954 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4955 | var filesForSdkLibrary = map[string][]byte{ |
| 4956 | "api/current.txt": nil, |
| 4957 | "api/removed.txt": nil, |
| 4958 | "api/system-current.txt": nil, |
| 4959 | "api/system-removed.txt": nil, |
| 4960 | "api/test-current.txt": nil, |
| 4961 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 4962 | |
| 4963 | // For java_sdk_library_import |
| 4964 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4965 | } |
| 4966 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4967 | func TestJavaSDKLibrary(t *testing.T) { |
| 4968 | ctx, _ := testApex(t, ` |
| 4969 | apex { |
| 4970 | name: "myapex", |
| 4971 | key: "myapex.key", |
| 4972 | java_libs: ["foo"], |
| 4973 | } |
| 4974 | |
| 4975 | apex_key { |
| 4976 | name: "myapex.key", |
| 4977 | public_key: "testkey.avbpubkey", |
| 4978 | private_key: "testkey.pem", |
| 4979 | } |
| 4980 | |
| 4981 | java_sdk_library { |
| 4982 | name: "foo", |
| 4983 | srcs: ["a.java"], |
| 4984 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4985 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4986 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4987 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4988 | |
| 4989 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4990 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4991 | "javalib/foo.jar", |
| 4992 | "etc/permissions/foo.xml", |
| 4993 | }) |
| 4994 | // Permission XML should point to the activated path of impl jar of java_sdk_library |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 4995 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 4996 | ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 4997 | } |
| 4998 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 4999 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
| 5000 | ctx, _ := testApex(t, ` |
| 5001 | apex { |
| 5002 | name: "myapex", |
| 5003 | key: "myapex.key", |
| 5004 | java_libs: ["foo", "bar"], |
| 5005 | } |
| 5006 | |
| 5007 | apex_key { |
| 5008 | name: "myapex.key", |
| 5009 | public_key: "testkey.avbpubkey", |
| 5010 | private_key: "testkey.pem", |
| 5011 | } |
| 5012 | |
| 5013 | java_sdk_library { |
| 5014 | name: "foo", |
| 5015 | srcs: ["a.java"], |
| 5016 | api_packages: ["foo"], |
| 5017 | apex_available: ["myapex"], |
| 5018 | sdk_version: "none", |
| 5019 | system_modules: "none", |
| 5020 | } |
| 5021 | |
| 5022 | java_library { |
| 5023 | name: "bar", |
| 5024 | srcs: ["a.java"], |
| 5025 | libs: ["foo"], |
| 5026 | apex_available: ["myapex"], |
| 5027 | sdk_version: "none", |
| 5028 | system_modules: "none", |
| 5029 | } |
| 5030 | `, withFiles(filesForSdkLibrary)) |
| 5031 | |
| 5032 | // java_sdk_library installs both impl jar and permission XML |
| 5033 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5034 | "javalib/bar.jar", |
| 5035 | "javalib/foo.jar", |
| 5036 | "etc/permissions/foo.xml", |
| 5037 | }) |
| 5038 | |
| 5039 | // The bar library should depend on the implementation jar. |
| 5040 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5041 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5042 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
| 5047 | ctx, _ := testApex(t, ` |
| 5048 | apex { |
| 5049 | name: "myapex", |
| 5050 | key: "myapex.key", |
| 5051 | java_libs: ["foo"], |
| 5052 | } |
| 5053 | |
| 5054 | apex_key { |
| 5055 | name: "myapex.key", |
| 5056 | public_key: "testkey.avbpubkey", |
| 5057 | private_key: "testkey.pem", |
| 5058 | } |
| 5059 | |
| 5060 | java_sdk_library { |
| 5061 | name: "foo", |
| 5062 | srcs: ["a.java"], |
| 5063 | api_packages: ["foo"], |
| 5064 | apex_available: ["myapex"], |
| 5065 | sdk_version: "none", |
| 5066 | system_modules: "none", |
| 5067 | } |
| 5068 | |
| 5069 | java_library { |
| 5070 | name: "bar", |
| 5071 | srcs: ["a.java"], |
| 5072 | libs: ["foo"], |
| 5073 | sdk_version: "none", |
| 5074 | system_modules: "none", |
| 5075 | } |
| 5076 | `, withFiles(filesForSdkLibrary)) |
| 5077 | |
| 5078 | // java_sdk_library installs both impl jar and permission XML |
| 5079 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5080 | "javalib/foo.jar", |
| 5081 | "etc/permissions/foo.xml", |
| 5082 | }) |
| 5083 | |
| 5084 | // The bar library should depend on the stubs jar. |
| 5085 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 5086 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5087 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5088 | } |
| 5089 | } |
| 5090 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5091 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
| 5092 | ctx, _ := testApex(t, ``, |
| 5093 | withFiles(map[string][]byte{ |
| 5094 | "apex/a.java": nil, |
| 5095 | "apex/apex_manifest.json": nil, |
| 5096 | "apex/Android.bp": []byte(` |
| 5097 | package { |
| 5098 | default_visibility: ["//visibility:private"], |
| 5099 | } |
| 5100 | |
| 5101 | apex { |
| 5102 | name: "myapex", |
| 5103 | key: "myapex.key", |
| 5104 | java_libs: ["foo", "bar"], |
| 5105 | } |
| 5106 | |
| 5107 | apex_key { |
| 5108 | name: "myapex.key", |
| 5109 | public_key: "testkey.avbpubkey", |
| 5110 | private_key: "testkey.pem", |
| 5111 | } |
| 5112 | |
| 5113 | java_library { |
| 5114 | name: "bar", |
| 5115 | srcs: ["a.java"], |
| 5116 | libs: ["foo"], |
| 5117 | apex_available: ["myapex"], |
| 5118 | sdk_version: "none", |
| 5119 | system_modules: "none", |
| 5120 | } |
| 5121 | `), |
| 5122 | "source/a.java": nil, |
| 5123 | "source/api/current.txt": nil, |
| 5124 | "source/api/removed.txt": nil, |
| 5125 | "source/Android.bp": []byte(` |
| 5126 | package { |
| 5127 | default_visibility: ["//visibility:private"], |
| 5128 | } |
| 5129 | |
| 5130 | java_sdk_library { |
| 5131 | name: "foo", |
| 5132 | visibility: ["//apex"], |
| 5133 | srcs: ["a.java"], |
| 5134 | api_packages: ["foo"], |
| 5135 | apex_available: ["myapex"], |
| 5136 | sdk_version: "none", |
| 5137 | system_modules: "none", |
| 5138 | public: { |
| 5139 | enabled: true, |
| 5140 | }, |
| 5141 | } |
| 5142 | `), |
| 5143 | "prebuilt/a.jar": nil, |
| 5144 | "prebuilt/Android.bp": []byte(` |
| 5145 | package { |
| 5146 | default_visibility: ["//visibility:private"], |
| 5147 | } |
| 5148 | |
| 5149 | java_sdk_library_import { |
| 5150 | name: "foo", |
| 5151 | visibility: ["//apex", "//source"], |
| 5152 | apex_available: ["myapex"], |
| 5153 | prefer: true, |
| 5154 | public: { |
| 5155 | jars: ["a.jar"], |
| 5156 | }, |
| 5157 | } |
| 5158 | `), |
| 5159 | }), |
| 5160 | ) |
| 5161 | |
| 5162 | // java_sdk_library installs both impl jar and permission XML |
| 5163 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5164 | "javalib/bar.jar", |
| 5165 | "javalib/foo.jar", |
| 5166 | "etc/permissions/foo.xml", |
| 5167 | }) |
| 5168 | |
| 5169 | // The bar library should depend on the implementation jar. |
| 5170 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
| 5171 | if expected, actual := `^-classpath /[^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 5172 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5177 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5178 | apex { |
| 5179 | name: "myapex", |
| 5180 | key: "myapex.key", |
| 5181 | java_libs: ["foo"], |
| 5182 | } |
| 5183 | |
| 5184 | apex_key { |
| 5185 | name: "myapex.key", |
| 5186 | public_key: "testkey.avbpubkey", |
| 5187 | private_key: "testkey.pem", |
| 5188 | } |
| 5189 | |
| 5190 | java_sdk_library_import { |
| 5191 | name: "foo", |
| 5192 | apex_available: ["myapex"], |
| 5193 | prefer: true, |
| 5194 | public: { |
| 5195 | jars: ["a.jar"], |
| 5196 | }, |
| 5197 | } |
| 5198 | |
| 5199 | `, withFiles(filesForSdkLibrary)) |
| 5200 | } |
| 5201 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5202 | func TestCompatConfig(t *testing.T) { |
| 5203 | ctx, _ := testApex(t, ` |
| 5204 | apex { |
| 5205 | name: "myapex", |
| 5206 | key: "myapex.key", |
| 5207 | prebuilts: ["myjar-platform-compat-config"], |
| 5208 | java_libs: ["myjar"], |
| 5209 | } |
| 5210 | |
| 5211 | apex_key { |
| 5212 | name: "myapex.key", |
| 5213 | public_key: "testkey.avbpubkey", |
| 5214 | private_key: "testkey.pem", |
| 5215 | } |
| 5216 | |
| 5217 | platform_compat_config { |
| 5218 | name: "myjar-platform-compat-config", |
| 5219 | src: ":myjar", |
| 5220 | } |
| 5221 | |
| 5222 | java_library { |
| 5223 | name: "myjar", |
| 5224 | srcs: ["foo/bar/MyClass.java"], |
| 5225 | sdk_version: "none", |
| 5226 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5227 | apex_available: [ "myapex" ], |
| 5228 | } |
| 5229 | `) |
| 5230 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5231 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5232 | "javalib/myjar.jar", |
| 5233 | }) |
| 5234 | } |
| 5235 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5236 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5237 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5238 | apex { |
| 5239 | name: "myapex", |
| 5240 | key: "myapex.key", |
| 5241 | java_libs: ["myjar"], |
| 5242 | } |
| 5243 | |
| 5244 | apex_key { |
| 5245 | name: "myapex.key", |
| 5246 | public_key: "testkey.avbpubkey", |
| 5247 | private_key: "testkey.pem", |
| 5248 | } |
| 5249 | |
| 5250 | java_library { |
| 5251 | name: "myjar", |
| 5252 | srcs: ["foo/bar/MyClass.java"], |
| 5253 | sdk_version: "none", |
| 5254 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5255 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5256 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5257 | } |
| 5258 | `) |
| 5259 | } |
| 5260 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5261 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 5262 | ctx, config := testApex(t, ` |
| 5263 | apex { |
| 5264 | name: "myapex", |
| 5265 | key: "myapex.key", |
| 5266 | native_shared_libs: ["mylib"], |
| 5267 | } |
| 5268 | |
| 5269 | apex_key { |
| 5270 | name: "myapex.key", |
| 5271 | public_key: "testkey.avbpubkey", |
| 5272 | private_key: "testkey.pem", |
| 5273 | } |
| 5274 | |
| 5275 | cc_library { |
| 5276 | name: "mylib", |
| 5277 | srcs: ["mylib.cpp"], |
| 5278 | system_shared_libs: [], |
| 5279 | stl: "none", |
| 5280 | required: ["a", "b"], |
| 5281 | host_required: ["c", "d"], |
| 5282 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5283 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5284 | } |
| 5285 | `) |
| 5286 | |
| 5287 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5288 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5289 | name := apexBundle.BaseModuleName() |
| 5290 | prefix := "TARGET_" |
| 5291 | var builder strings.Builder |
| 5292 | data.Custom(&builder, name, prefix, "", data) |
| 5293 | androidMk := builder.String() |
| 5294 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5295 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5296 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5297 | } |
| 5298 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5299 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5300 | bp := ` |
| 5301 | apex { |
| 5302 | name: "myapex", |
| 5303 | key: "myapex.key", |
| 5304 | native_shared_libs: ["mylib"], |
| 5305 | java_libs: ["myjar"], |
| 5306 | } |
| 5307 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5308 | apex { |
| 5309 | name: "myapex.updatable", |
| 5310 | key: "myapex.key", |
| 5311 | native_shared_libs: ["mylib"], |
| 5312 | java_libs: ["myjar"], |
| 5313 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5314 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5315 | } |
| 5316 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5317 | apex_key { |
| 5318 | name: "myapex.key", |
| 5319 | public_key: "testkey.avbpubkey", |
| 5320 | private_key: "testkey.pem", |
| 5321 | } |
| 5322 | |
| 5323 | cc_library { |
| 5324 | name: "mylib", |
| 5325 | srcs: ["mylib.cpp"], |
| 5326 | shared_libs: ["myotherlib"], |
| 5327 | system_shared_libs: [], |
| 5328 | stl: "none", |
| 5329 | apex_available: [ |
| 5330 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5331 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5332 | "//apex_available:platform", |
| 5333 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5334 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | cc_library { |
| 5338 | name: "myotherlib", |
| 5339 | srcs: ["mylib.cpp"], |
| 5340 | system_shared_libs: [], |
| 5341 | stl: "none", |
| 5342 | apex_available: [ |
| 5343 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5344 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5345 | "//apex_available:platform", |
| 5346 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5347 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | java_library { |
| 5351 | name: "myjar", |
| 5352 | srcs: ["foo/bar/MyClass.java"], |
| 5353 | sdk_version: "none", |
| 5354 | system_modules: "none", |
| 5355 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5356 | apex_available: [ |
| 5357 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5358 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5359 | "//apex_available:platform", |
| 5360 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5361 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | java_library { |
| 5365 | name: "myotherjar", |
| 5366 | srcs: ["foo/bar/MyClass.java"], |
| 5367 | sdk_version: "none", |
| 5368 | system_modules: "none", |
| 5369 | apex_available: [ |
| 5370 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5371 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5372 | "//apex_available:platform", |
| 5373 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5374 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5375 | } |
| 5376 | ` |
| 5377 | |
| 5378 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 5379 | for _, f := range files { |
| 5380 | if f.path == file { |
| 5381 | if f.isLink { |
| 5382 | t.Errorf("%q is not a real file", file) |
| 5383 | } |
| 5384 | return |
| 5385 | } |
| 5386 | } |
| 5387 | t.Errorf("%q is not found", file) |
| 5388 | } |
| 5389 | |
| 5390 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 5391 | for _, f := range files { |
| 5392 | if f.path == file { |
| 5393 | if !f.isLink { |
| 5394 | t.Errorf("%q is not a symlink", file) |
| 5395 | } |
| 5396 | return |
| 5397 | } |
| 5398 | } |
| 5399 | t.Errorf("%q is not found", file) |
| 5400 | } |
| 5401 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5402 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 5403 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5404 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5405 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5406 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5407 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5408 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5409 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5410 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5411 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5412 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5413 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 5414 | |
| 5415 | // For bundled build, symlink to the system for the non-updatable APEXes only |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5416 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5417 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5418 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5419 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5420 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 5421 | |
| 5422 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 5423 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 5424 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 5425 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5426 | } |
| 5427 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 5428 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
| 5429 | ctx, config := testApex(t, ` |
| 5430 | apex { |
| 5431 | name: "myapex", |
| 5432 | key: "myapex.key", |
| 5433 | native_shared_libs: ["mylib"], |
| 5434 | } |
| 5435 | |
| 5436 | apex_key { |
| 5437 | name: "myapex.key", |
| 5438 | public_key: "testkey.avbpubkey", |
| 5439 | private_key: "testkey.pem", |
| 5440 | } |
| 5441 | |
| 5442 | cc_library_shared { |
| 5443 | name: "mylib", |
| 5444 | srcs: ["mylib.cpp"], |
| 5445 | shared_libs: ["myotherlib"], |
| 5446 | system_shared_libs: [], |
| 5447 | stl: "none", |
| 5448 | apex_available: [ |
| 5449 | "myapex", |
| 5450 | "//apex_available:platform", |
| 5451 | ], |
| 5452 | } |
| 5453 | |
| 5454 | cc_prebuilt_library_shared { |
| 5455 | name: "myotherlib", |
| 5456 | srcs: ["prebuilt.so"], |
| 5457 | system_shared_libs: [], |
| 5458 | stl: "none", |
| 5459 | apex_available: [ |
| 5460 | "myapex", |
| 5461 | "//apex_available:platform", |
| 5462 | ], |
| 5463 | } |
| 5464 | `) |
| 5465 | |
| 5466 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 5467 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 5468 | var builder strings.Builder |
| 5469 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 5470 | androidMk := builder.String() |
| 5471 | // `myotherlib` is added to `myapex` as symlink |
| 5472 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 5473 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 5474 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 5475 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
| 5476 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex myotherlib apex_manifest.pb.myapex apex_pubkey.myapex\n") |
| 5477 | } |
| 5478 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 5479 | func TestApexWithJniLibs(t *testing.T) { |
| 5480 | ctx, _ := testApex(t, ` |
| 5481 | apex { |
| 5482 | name: "myapex", |
| 5483 | key: "myapex.key", |
| 5484 | jni_libs: ["mylib"], |
| 5485 | } |
| 5486 | |
| 5487 | apex_key { |
| 5488 | name: "myapex.key", |
| 5489 | public_key: "testkey.avbpubkey", |
| 5490 | private_key: "testkey.pem", |
| 5491 | } |
| 5492 | |
| 5493 | cc_library { |
| 5494 | name: "mylib", |
| 5495 | srcs: ["mylib.cpp"], |
| 5496 | shared_libs: ["mylib2"], |
| 5497 | system_shared_libs: [], |
| 5498 | stl: "none", |
| 5499 | apex_available: [ "myapex" ], |
| 5500 | } |
| 5501 | |
| 5502 | cc_library { |
| 5503 | name: "mylib2", |
| 5504 | srcs: ["mylib.cpp"], |
| 5505 | system_shared_libs: [], |
| 5506 | stl: "none", |
| 5507 | apex_available: [ "myapex" ], |
| 5508 | } |
| 5509 | `) |
| 5510 | |
| 5511 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 5512 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 5513 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 5514 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5515 | "lib64/mylib.so", |
| 5516 | "lib64/mylib2.so", |
| 5517 | }) |
| 5518 | } |
| 5519 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 5520 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
| 5521 | ctx, _ := testApex(t, ` |
| 5522 | apex { |
| 5523 | name: "myapex", |
| 5524 | key: "myapex.key", |
| 5525 | } |
| 5526 | apex_key { |
| 5527 | name: "myapex.key", |
| 5528 | public_key: "testkey.avbpubkey", |
| 5529 | private_key: "testkey.pem", |
| 5530 | } |
| 5531 | `, func(fs map[string][]byte, config android.Config) { |
| 5532 | delete(config.Targets, android.Android) |
| 5533 | config.AndroidCommonTarget = android.Target{} |
| 5534 | }) |
| 5535 | |
| 5536 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 5537 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 5538 | } |
| 5539 | } |
| 5540 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5541 | func TestAppBundle(t *testing.T) { |
| 5542 | ctx, _ := testApex(t, ` |
| 5543 | apex { |
| 5544 | name: "myapex", |
| 5545 | key: "myapex.key", |
| 5546 | apps: ["AppFoo"], |
| 5547 | } |
| 5548 | |
| 5549 | apex_key { |
| 5550 | name: "myapex.key", |
| 5551 | public_key: "testkey.avbpubkey", |
| 5552 | private_key: "testkey.pem", |
| 5553 | } |
| 5554 | |
| 5555 | android_app { |
| 5556 | name: "AppFoo", |
| 5557 | srcs: ["foo/bar/MyClass.java"], |
| 5558 | sdk_version: "none", |
| 5559 | system_modules: "none", |
| 5560 | apex_available: [ "myapex" ], |
| 5561 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5562 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5563 | |
| 5564 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 5565 | content := bundleConfigRule.Args["content"] |
| 5566 | |
| 5567 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 5568 | ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 5569 | } |
| 5570 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5571 | func TestAppSetBundle(t *testing.T) { |
| 5572 | ctx, _ := testApex(t, ` |
| 5573 | apex { |
| 5574 | name: "myapex", |
| 5575 | key: "myapex.key", |
| 5576 | apps: ["AppSet"], |
| 5577 | } |
| 5578 | |
| 5579 | apex_key { |
| 5580 | name: "myapex.key", |
| 5581 | public_key: "testkey.avbpubkey", |
| 5582 | private_key: "testkey.pem", |
| 5583 | } |
| 5584 | |
| 5585 | android_app_set { |
| 5586 | name: "AppSet", |
| 5587 | set: "AppSet.apks", |
| 5588 | }`) |
| 5589 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5590 | bundleConfigRule := mod.Description("Bundle Config") |
| 5591 | content := bundleConfigRule.Args["content"] |
| 5592 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 5593 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 5594 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 5595 | if len(copyCmds) != 3 { |
| 5596 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 5597 | } |
| 5598 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 5599 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 5600 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 5601 | } |
| 5602 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5603 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5604 | t.Helper() |
| 5605 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5606 | bp := ` |
| 5607 | java_library { |
| 5608 | name: "some-updatable-apex-lib", |
| 5609 | srcs: ["a.java"], |
| 5610 | sdk_version: "current", |
| 5611 | apex_available: [ |
| 5612 | "some-updatable-apex", |
| 5613 | ], |
| 5614 | } |
| 5615 | |
| 5616 | java_library { |
| 5617 | name: "some-non-updatable-apex-lib", |
| 5618 | srcs: ["a.java"], |
| 5619 | apex_available: [ |
| 5620 | "some-non-updatable-apex", |
| 5621 | ], |
| 5622 | } |
| 5623 | |
| 5624 | java_library { |
| 5625 | name: "some-platform-lib", |
| 5626 | srcs: ["a.java"], |
| 5627 | sdk_version: "current", |
| 5628 | installable: true, |
| 5629 | } |
| 5630 | |
| 5631 | java_library { |
| 5632 | name: "some-art-lib", |
| 5633 | srcs: ["a.java"], |
| 5634 | sdk_version: "current", |
| 5635 | apex_available: [ |
| 5636 | "com.android.art.something", |
| 5637 | ], |
| 5638 | hostdex: true, |
| 5639 | } |
| 5640 | |
| 5641 | apex { |
| 5642 | name: "some-updatable-apex", |
| 5643 | key: "some-updatable-apex.key", |
| 5644 | java_libs: ["some-updatable-apex-lib"], |
| 5645 | updatable: true, |
| 5646 | min_sdk_version: "current", |
| 5647 | } |
| 5648 | |
| 5649 | apex { |
| 5650 | name: "some-non-updatable-apex", |
| 5651 | key: "some-non-updatable-apex.key", |
| 5652 | java_libs: ["some-non-updatable-apex-lib"], |
| 5653 | } |
| 5654 | |
| 5655 | apex_key { |
| 5656 | name: "some-updatable-apex.key", |
| 5657 | } |
| 5658 | |
| 5659 | apex_key { |
| 5660 | name: "some-non-updatable-apex.key", |
| 5661 | } |
| 5662 | |
| 5663 | apex { |
| 5664 | name: "com.android.art.something", |
| 5665 | key: "com.android.art.something.key", |
| 5666 | java_libs: ["some-art-lib"], |
| 5667 | updatable: true, |
| 5668 | min_sdk_version: "current", |
| 5669 | } |
| 5670 | |
| 5671 | apex_key { |
| 5672 | name: "com.android.art.something.key", |
| 5673 | } |
| 5674 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5675 | filegroup { |
| 5676 | name: "some-updatable-apex-file_contexts", |
| 5677 | srcs: [ |
| 5678 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 5679 | ], |
| 5680 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5681 | |
| 5682 | filegroup { |
| 5683 | name: "some-non-updatable-apex-file_contexts", |
| 5684 | srcs: [ |
| 5685 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 5686 | ], |
| 5687 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5688 | ` |
| 5689 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 5690 | bp += java.GatherRequiredDepsForTest() |
| 5691 | bp += dexpreopt.BpToolModulesForTest() |
| 5692 | |
| 5693 | fs := map[string][]byte{ |
| 5694 | "a.java": nil, |
| 5695 | "a.jar": nil, |
| 5696 | "build/make/target/product/security": nil, |
| 5697 | "apex_manifest.json": nil, |
| 5698 | "AndroidManifest.xml": nil, |
| 5699 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5700 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5701 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 5702 | "framework/aidl/a.aidl": nil, |
| 5703 | } |
| 5704 | cc.GatherRequiredFilesForTest(fs) |
| 5705 | |
| 5706 | ctx := android.NewTestArchContext() |
| 5707 | ctx.RegisterModuleType("apex", BundleFactory) |
| 5708 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 5709 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 5710 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 5711 | android.RegisterPrebuiltMutators(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5712 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 5713 | java.RegisterJavaBuildComponents(ctx) |
| 5714 | java.RegisterSystemModulesBuildComponents(ctx) |
| 5715 | java.RegisterAppBuildComponents(ctx) |
| 5716 | java.RegisterDexpreoptBootJarsComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5717 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 5718 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 5719 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 5720 | |
| 5721 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 5722 | ctx.Register(config) |
| 5723 | |
| 5724 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 5725 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 5726 | pathCtx := android.PathContextForTesting(config) |
| 5727 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 5728 | transformDexpreoptConfig(dexpreoptConfig) |
| 5729 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 5730 | |
| 5731 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 5732 | android.FailIfErrored(t, errs) |
| 5733 | |
| 5734 | _, errs = ctx.PrepareBuildActions(config) |
| 5735 | if errmsg == "" { |
| 5736 | android.FailIfErrored(t, errs) |
| 5737 | } else if len(errs) > 0 { |
| 5738 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 5739 | return |
| 5740 | } else { |
| 5741 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 5742 | } |
| 5743 | } |
| 5744 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 5745 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 5746 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 5747 | apex { |
| 5748 | name: "myapex", |
| 5749 | key: "myapex.key", |
| 5750 | updatable: true, |
| 5751 | } |
| 5752 | |
| 5753 | apex_key { |
| 5754 | name: "myapex.key", |
| 5755 | public_key: "testkey.avbpubkey", |
| 5756 | private_key: "testkey.pem", |
| 5757 | } |
| 5758 | `) |
| 5759 | } |
| 5760 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5761 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5762 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5763 | var transform func(*dexpreopt.GlobalConfig) |
| 5764 | |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5765 | config := android.TestArchConfig(buildDir, nil, "", nil) |
| 5766 | ctx := android.PathContextForTesting(config) |
| 5767 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5768 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 5769 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5770 | config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"com.android.art.something:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5771 | } |
| 5772 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5773 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5774 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5775 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5776 | err = `module "some-art-lib" from updatable apexes \["com.android.art.something"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5777 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5778 | config.BootJars = android.CreateConfiguredJarList(ctx, []string{"com.android.art.something:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5779 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5780 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5781 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5782 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5783 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5784 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5785 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5786 | config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5787 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5788 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5789 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5790 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5791 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5792 | err = `module "some-non-updatable-apex-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5793 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5794 | config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5795 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5796 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5797 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5798 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5799 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5800 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5801 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5802 | config.BootJars = android.CreateConfiguredJarList(ctx, []string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5803 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5804 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5805 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5806 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5807 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 5808 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5809 | config.BootJars = android.CreateConfiguredJarList(ctx, []string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5810 | } |
| 5811 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5812 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 5813 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5814 | t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5815 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5816 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5817 | config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5818 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5819 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5820 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5821 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5822 | t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5823 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5824 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5825 | config.BootJars = android.CreateConfiguredJarList(ctx, []string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5826 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5827 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5828 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5829 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5830 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5831 | err = `module "some-platform-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5832 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5833 | config.ArtApexJars = android.CreateConfiguredJarList(ctx, []string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5834 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 5835 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5836 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5837 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5838 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 5839 | transform = func(config *dexpreopt.GlobalConfig) { |
Ulya Trafimovich | 249386a | 2020-07-01 14:31:13 +0100 | [diff] [blame] | 5840 | config.BootJars = android.CreateConfiguredJarList(ctx, []string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 5841 | } |
| 5842 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 5843 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 5844 | } |
| 5845 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 5846 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 5847 | t.Helper() |
| 5848 | android.ClearApexDependency() |
| 5849 | bp += ` |
| 5850 | apex_key { |
| 5851 | name: "myapex.key", |
| 5852 | public_key: "testkey.avbpubkey", |
| 5853 | private_key: "testkey.pem", |
| 5854 | }` |
| 5855 | fs := map[string][]byte{ |
| 5856 | "lib1/src/A.java": nil, |
| 5857 | "lib2/src/B.java": nil, |
| 5858 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 5859 | } |
| 5860 | |
| 5861 | ctx := android.NewTestArchContext() |
| 5862 | ctx.RegisterModuleType("apex", BundleFactory) |
| 5863 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 5864 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 5865 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 5866 | java.RegisterJavaBuildComponents(ctx) |
| 5867 | java.RegisterSystemModulesBuildComponents(ctx) |
| 5868 | java.RegisterDexpreoptBootJarsComponents(ctx) |
| 5869 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 5870 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 5871 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 5872 | ctx.PostDepsMutators(android.RegisterNeverallowMutator) |
| 5873 | |
| 5874 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 5875 | android.SetTestNeverallowRules(config, rules) |
| 5876 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 5877 | for _, apexBootJar := range apexBootJars { |
| 5878 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 5879 | } |
| 5880 | config.TestProductVariables.UpdatableBootJars = updatableBootJars |
| 5881 | |
| 5882 | ctx.Register(config) |
| 5883 | |
| 5884 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 5885 | android.FailIfErrored(t, errs) |
| 5886 | |
| 5887 | _, errs = ctx.PrepareBuildActions(config) |
| 5888 | if errmsg == "" { |
| 5889 | android.FailIfErrored(t, errs) |
| 5890 | } else if len(errs) > 0 { |
| 5891 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 5892 | return |
| 5893 | } else { |
| 5894 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 5895 | } |
| 5896 | } |
| 5897 | |
| 5898 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 5899 | testcases := []struct { |
| 5900 | name string |
| 5901 | expectedError string |
| 5902 | bp string |
| 5903 | bootJars []string |
| 5904 | modulesPackages map[string][]string |
| 5905 | }{ |
| 5906 | |
| 5907 | { |
| 5908 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 5909 | expectedError: "", |
| 5910 | bp: ` |
| 5911 | java_library { |
| 5912 | name: "bcp_lib1", |
| 5913 | srcs: ["lib1/src/*.java"], |
| 5914 | permitted_packages: ["foo.bar"], |
| 5915 | apex_available: ["myapex"], |
| 5916 | sdk_version: "none", |
| 5917 | system_modules: "none", |
| 5918 | } |
| 5919 | java_library { |
| 5920 | name: "nonbcp_lib2", |
| 5921 | srcs: ["lib2/src/*.java"], |
| 5922 | apex_available: ["myapex"], |
| 5923 | permitted_packages: ["a.b"], |
| 5924 | sdk_version: "none", |
| 5925 | system_modules: "none", |
| 5926 | } |
| 5927 | apex { |
| 5928 | name: "myapex", |
| 5929 | key: "myapex.key", |
| 5930 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
| 5931 | }`, |
| 5932 | bootJars: []string{"bcp_lib1"}, |
| 5933 | modulesPackages: map[string][]string{ |
| 5934 | "myapex": []string{ |
| 5935 | "foo.bar", |
| 5936 | }, |
| 5937 | }, |
| 5938 | }, |
| 5939 | { |
| 5940 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 5941 | expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar. Please jarjar or move code around.`, |
| 5942 | bp: ` |
| 5943 | java_library { |
| 5944 | name: "bcp_lib1", |
| 5945 | srcs: ["lib1/src/*.java"], |
| 5946 | apex_available: ["myapex"], |
| 5947 | permitted_packages: ["foo.bar"], |
| 5948 | sdk_version: "none", |
| 5949 | system_modules: "none", |
| 5950 | } |
| 5951 | java_library { |
| 5952 | name: "bcp_lib2", |
| 5953 | srcs: ["lib2/src/*.java"], |
| 5954 | apex_available: ["myapex"], |
| 5955 | permitted_packages: ["foo.bar", "bar.baz"], |
| 5956 | sdk_version: "none", |
| 5957 | system_modules: "none", |
| 5958 | } |
| 5959 | apex { |
| 5960 | name: "myapex", |
| 5961 | key: "myapex.key", |
| 5962 | java_libs: ["bcp_lib1", "bcp_lib2"], |
| 5963 | } |
| 5964 | `, |
| 5965 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 5966 | modulesPackages: map[string][]string{ |
| 5967 | "myapex": []string{ |
| 5968 | "foo.bar", |
| 5969 | }, |
| 5970 | }, |
| 5971 | }, |
| 5972 | } |
| 5973 | for _, tc := range testcases { |
| 5974 | t.Run(tc.name, func(t *testing.T) { |
| 5975 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 5976 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 5977 | }) |
| 5978 | } |
| 5979 | } |
| 5980 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 5981 | func TestTestFor(t *testing.T) { |
| 5982 | ctx, _ := testApex(t, ` |
| 5983 | apex { |
| 5984 | name: "myapex", |
| 5985 | key: "myapex.key", |
| 5986 | native_shared_libs: ["mylib", "myprivlib"], |
| 5987 | } |
| 5988 | |
| 5989 | apex_key { |
| 5990 | name: "myapex.key", |
| 5991 | public_key: "testkey.avbpubkey", |
| 5992 | private_key: "testkey.pem", |
| 5993 | } |
| 5994 | |
| 5995 | cc_library { |
| 5996 | name: "mylib", |
| 5997 | srcs: ["mylib.cpp"], |
| 5998 | system_shared_libs: [], |
| 5999 | stl: "none", |
| 6000 | stubs: { |
| 6001 | versions: ["1"], |
| 6002 | }, |
| 6003 | apex_available: ["myapex"], |
| 6004 | } |
| 6005 | |
| 6006 | cc_library { |
| 6007 | name: "myprivlib", |
| 6008 | srcs: ["mylib.cpp"], |
| 6009 | system_shared_libs: [], |
| 6010 | stl: "none", |
| 6011 | apex_available: ["myapex"], |
| 6012 | } |
| 6013 | |
| 6014 | |
| 6015 | cc_test { |
| 6016 | name: "mytest", |
| 6017 | gtest: false, |
| 6018 | srcs: ["mylib.cpp"], |
| 6019 | system_shared_libs: [], |
| 6020 | stl: "none", |
| 6021 | shared_libs: ["mylib", "myprivlib"], |
| 6022 | test_for: ["myapex"] |
| 6023 | } |
| 6024 | `) |
| 6025 | |
| 6026 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 6027 | // actual implementation of mylib instead of its stub. |
| 6028 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6029 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6030 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 6031 | } |
| 6032 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6033 | // TODO(jungjw): Move this to proptools |
| 6034 | func intPtr(i int) *int { |
| 6035 | return &i |
| 6036 | } |
| 6037 | |
| 6038 | func TestApexSet(t *testing.T) { |
| 6039 | ctx, config := testApex(t, ` |
| 6040 | apex_set { |
| 6041 | name: "myapex", |
| 6042 | set: "myapex.apks", |
| 6043 | filename: "foo_v2.apex", |
| 6044 | overrides: ["foo"], |
| 6045 | } |
| 6046 | `, func(fs map[string][]byte, config android.Config) { |
| 6047 | config.TestProductVariables.Platform_sdk_version = intPtr(30) |
Jaewoong Jung | 829b713 | 2020-06-10 12:23:32 -0700 | [diff] [blame] | 6048 | config.Targets[android.Android] = []android.Target{ |
| 6049 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 6050 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 6051 | } |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6052 | }) |
| 6053 | |
| 6054 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6055 | |
| 6056 | // Check extract_apks tool parameters. |
| 6057 | extractedApex := m.Output(buildDir + "/.intermediates/myapex/android_common/foo_v2.apex") |
| 6058 | actual := extractedApex.Args["abis"] |
| 6059 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 6060 | if actual != expected { |
| 6061 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6062 | } |
| 6063 | actual = extractedApex.Args["sdk-version"] |
| 6064 | expected = "30" |
| 6065 | if actual != expected { |
| 6066 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6067 | } |
| 6068 | |
| 6069 | a := m.Module().(*ApexSet) |
| 6070 | expectedOverrides := []string{"foo"} |
| 6071 | actualOverrides := android.AndroidMkEntriesForTest(t, config, "", a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
| 6072 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 6073 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 6074 | } |
| 6075 | } |
| 6076 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 6077 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 6078 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 6079 | apex { |
| 6080 | name: "myapex", |
| 6081 | key: "myapex.key", |
| 6082 | native_shared_libs: ["mylib"], |
| 6083 | } |
| 6084 | |
| 6085 | apex_key { |
| 6086 | name: "myapex.key", |
| 6087 | public_key: "testkey.avbpubkey", |
| 6088 | private_key: "testkey.pem", |
| 6089 | } |
| 6090 | |
| 6091 | cc_library { |
| 6092 | name: "mylib", |
| 6093 | srcs: ["mylib.cpp"], |
| 6094 | static_libs: ["otherlib"], |
| 6095 | system_shared_libs: [], |
| 6096 | stl: "none", |
| 6097 | apex_available: [ "myapex" ], |
| 6098 | } |
| 6099 | |
| 6100 | cc_library { |
| 6101 | name: "otherlib", |
| 6102 | srcs: ["mylib.cpp"], |
| 6103 | system_shared_libs: [], |
| 6104 | stl: "none", |
| 6105 | stubs: { |
| 6106 | versions: ["1", "2", "3"], |
| 6107 | }, |
| 6108 | apex_available: [ "myapex" ], |
| 6109 | } |
| 6110 | `) |
| 6111 | } |
| 6112 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6113 | func TestApexKeysTxt(t *testing.T) { |
| 6114 | ctx, _ := testApex(t, ` |
| 6115 | apex { |
| 6116 | name: "myapex", |
| 6117 | key: "myapex.key", |
| 6118 | } |
| 6119 | |
| 6120 | apex_key { |
| 6121 | name: "myapex.key", |
| 6122 | public_key: "testkey.avbpubkey", |
| 6123 | private_key: "testkey.pem", |
| 6124 | } |
| 6125 | |
| 6126 | prebuilt_apex { |
| 6127 | name: "myapex", |
| 6128 | prefer: true, |
| 6129 | arch: { |
| 6130 | arm64: { |
| 6131 | src: "myapex-arm64.apex", |
| 6132 | }, |
| 6133 | arm: { |
| 6134 | src: "myapex-arm.apex", |
| 6135 | }, |
| 6136 | }, |
| 6137 | } |
| 6138 | |
| 6139 | apex_set { |
| 6140 | name: "myapex_set", |
| 6141 | set: "myapex.apks", |
| 6142 | filename: "myapex_set.apex", |
| 6143 | overrides: ["myapex"], |
| 6144 | } |
| 6145 | `) |
| 6146 | |
| 6147 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 6148 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 6149 | ensureContains(t, content, `name="myapex_set.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 03a7f3e | 2020-06-18 19:34:42 +0900 | [diff] [blame] | 6150 | ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6151 | } |
| 6152 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 6153 | func TestAllowedFiles(t *testing.T) { |
| 6154 | ctx, _ := testApex(t, ` |
| 6155 | apex { |
| 6156 | name: "myapex", |
| 6157 | key: "myapex.key", |
| 6158 | apps: ["app"], |
| 6159 | allowed_files: "allowed.txt", |
| 6160 | } |
| 6161 | |
| 6162 | apex_key { |
| 6163 | name: "myapex.key", |
| 6164 | public_key: "testkey.avbpubkey", |
| 6165 | private_key: "testkey.pem", |
| 6166 | } |
| 6167 | |
| 6168 | android_app { |
| 6169 | name: "app", |
| 6170 | srcs: ["foo/bar/MyClass.java"], |
| 6171 | package_name: "foo", |
| 6172 | sdk_version: "none", |
| 6173 | system_modules: "none", |
| 6174 | apex_available: [ "myapex" ], |
| 6175 | } |
| 6176 | `, withFiles(map[string][]byte{ |
| 6177 | "sub/Android.bp": []byte(` |
| 6178 | override_apex { |
| 6179 | name: "override_myapex", |
| 6180 | base: "myapex", |
| 6181 | apps: ["override_app"], |
| 6182 | allowed_files: ":allowed", |
| 6183 | } |
| 6184 | // Overridable "path" property should be referenced indirectly |
| 6185 | filegroup { |
| 6186 | name: "allowed", |
| 6187 | srcs: ["allowed.txt"], |
| 6188 | } |
| 6189 | override_android_app { |
| 6190 | name: "override_app", |
| 6191 | base: "app", |
| 6192 | package_name: "bar", |
| 6193 | } |
| 6194 | `), |
| 6195 | })) |
| 6196 | |
| 6197 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 6198 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 6199 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6200 | } |
| 6201 | |
| 6202 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 6203 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 6204 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 6205 | } |
| 6206 | } |
| 6207 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6208 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
| 6209 | _, _ = testApex(t, ` |
| 6210 | apex { |
| 6211 | name: "myapex", |
| 6212 | key: "myapex.key", |
| 6213 | native_shared_libs: ["mylib"], |
| 6214 | } |
| 6215 | |
| 6216 | apex_key { |
| 6217 | name: "myapex.key", |
| 6218 | public_key: "testkey.avbpubkey", |
| 6219 | private_key: "testkey.pem", |
| 6220 | } |
| 6221 | |
| 6222 | cc_library { |
| 6223 | name: "mylib", |
| 6224 | srcs: ["mylib.cpp"], |
| 6225 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6226 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6227 | }, |
| 6228 | apex_available: ["myapex"], |
| 6229 | } |
| 6230 | |
| 6231 | cc_prebuilt_library_shared { |
| 6232 | name: "mylib", |
| 6233 | prefer: false, |
| 6234 | srcs: ["prebuilt.so"], |
| 6235 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 6236 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 6237 | }, |
| 6238 | apex_available: ["myapex"], |
| 6239 | } |
| 6240 | `) |
| 6241 | } |
| 6242 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 6243 | func TestMain(m *testing.M) { |
| 6244 | run := func() int { |
| 6245 | setUp() |
| 6246 | defer tearDown() |
| 6247 | |
| 6248 | return m.Run() |
| 6249 | } |
| 6250 | |
| 6251 | os.Exit(run()) |
| 6252 | } |