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" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 23 | "strings" |
| 24 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 25 | |
| 26 | "github.com/google/blueprint/proptools" |
| 27 | |
| 28 | "android/soong/android" |
| 29 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame^] | 30 | "android/soong/dexpreopt" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 31 | "android/soong/java" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 34 | var buildDir string |
| 35 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 36 | // names returns name list from white space separated string |
| 37 | func names(s string) (ns []string) { |
| 38 | for _, n := range strings.Split(s, " ") { |
| 39 | if len(n) > 0 { |
| 40 | ns = append(ns, n) |
| 41 | } |
| 42 | } |
| 43 | return |
| 44 | } |
| 45 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 46 | func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { |
| 47 | t.Helper() |
| 48 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 49 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 50 | if len(errs) > 0 { |
| 51 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 52 | return |
| 53 | } |
| 54 | _, errs = ctx.PrepareBuildActions(config) |
| 55 | if len(errs) > 0 { |
| 56 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 61 | } |
| 62 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 63 | func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
| 64 | t.Helper() |
| 65 | ctx, config := testApexContext(t, bp, handlers...) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 66 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 67 | android.FailIfErrored(t, errs) |
| 68 | _, errs = ctx.PrepareBuildActions(config) |
| 69 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 70 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 71 | } |
| 72 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 73 | type testCustomizer func(fs map[string][]byte, config android.Config) |
| 74 | |
| 75 | func withFiles(files map[string][]byte) testCustomizer { |
| 76 | return func(fs map[string][]byte, config android.Config) { |
| 77 | for k, v := range files { |
| 78 | fs[k] = v |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func withTargets(targets map[android.OsType][]android.Target) testCustomizer { |
| 84 | return func(fs map[string][]byte, config android.Config) { |
| 85 | for k, v := range targets { |
| 86 | config.Targets[k] = v |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 91 | // withNativeBridgeTargets sets configuration with targets including: |
| 92 | // - X86_64 (primary) |
| 93 | // - X86 (secondary) |
| 94 | // - Arm64 on X86_64 (native bridge) |
| 95 | // - Arm on X86 (native bridge) |
| 96 | func withNativeBridgeEnabled(fs map[string][]byte, config android.Config) { |
| 97 | config.Targets[android.Android] = []android.Target{ |
| 98 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 99 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 100 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 101 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 102 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 103 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 104 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 105 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 106 | } |
| 107 | } |
| 108 | |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 109 | func withManifestPackageNameOverrides(specs []string) testCustomizer { |
| 110 | return func(fs map[string][]byte, config android.Config) { |
| 111 | config.TestProductVariables.ManifestPackageNameOverrides = specs |
| 112 | } |
| 113 | } |
| 114 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 115 | func withBinder32bit(fs map[string][]byte, config android.Config) { |
| 116 | config.TestProductVariables.Binder32bit = proptools.BoolPtr(true) |
| 117 | } |
| 118 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 119 | func withUnbundledBuild(fs map[string][]byte, config android.Config) { |
| 120 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 121 | } |
| 122 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 123 | func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) { |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 124 | android.ClearApexDependency() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 125 | |
| 126 | bp = bp + ` |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 127 | filegroup { |
| 128 | name: "myapex-file_contexts", |
| 129 | srcs: [ |
| 130 | "system/sepolicy/apex/myapex-file_contexts", |
| 131 | ], |
| 132 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 133 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 134 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 135 | bp = bp + cc.GatherRequiredDepsForTest(android.Android) |
| 136 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 137 | bp = bp + java.GatherRequiredDepsForTest() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 138 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 139 | fs := map[string][]byte{ |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 140 | "a.java": nil, |
| 141 | "PrebuiltAppFoo.apk": nil, |
| 142 | "PrebuiltAppFooPriv.apk": nil, |
| 143 | "build/make/target/product/security": nil, |
| 144 | "apex_manifest.json": nil, |
| 145 | "AndroidManifest.xml": nil, |
| 146 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 147 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 148 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 149 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 150 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
| 151 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 152 | "mylib.cpp": nil, |
| 153 | "mylib_common.cpp": nil, |
| 154 | "mytest.cpp": nil, |
| 155 | "mytest1.cpp": nil, |
| 156 | "mytest2.cpp": nil, |
| 157 | "mytest3.cpp": nil, |
| 158 | "myprebuilt": nil, |
| 159 | "my_include": nil, |
| 160 | "foo/bar/MyClass.java": nil, |
| 161 | "prebuilt.jar": nil, |
| 162 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 163 | "vendor/foo/devkeys/test.pk8": nil, |
| 164 | "testkey.x509.pem": nil, |
| 165 | "testkey.pk8": nil, |
| 166 | "testkey.override.x509.pem": nil, |
| 167 | "testkey.override.pk8": nil, |
| 168 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 169 | "vendor/foo/devkeys/testkey.pem": nil, |
| 170 | "NOTICE": nil, |
| 171 | "custom_notice": nil, |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 172 | "custom_notice_for_static_lib": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 173 | "testkey2.avbpubkey": nil, |
| 174 | "testkey2.pem": nil, |
| 175 | "myapex-arm64.apex": nil, |
| 176 | "myapex-arm.apex": nil, |
| 177 | "frameworks/base/api/current.txt": nil, |
| 178 | "framework/aidl/a.aidl": nil, |
| 179 | "build/make/core/proguard.flags": nil, |
| 180 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 181 | "dummy.txt": nil, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 182 | } |
| 183 | |
Colin Cross | f9aabd7 | 2020-02-15 11:29:50 -0800 | [diff] [blame] | 184 | cc.GatherRequiredFilesForTest(fs) |
| 185 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 186 | for _, handler := range handlers { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 187 | // The fs now needs to be populated before creating the config, call handlers twice |
| 188 | // for now, once to get any fs changes, and later after the config was created to |
| 189 | // set product variables or targets. |
| 190 | tempConfig := android.TestArchConfig(buildDir, nil, bp, fs) |
| 191 | handler(fs, tempConfig) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 192 | } |
| 193 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 194 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 195 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 196 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 197 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 198 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 199 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
| 200 | config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") |
| 201 | |
| 202 | for _, handler := range handlers { |
| 203 | // The fs now needs to be populated before creating the config, call handlers twice |
| 204 | // for now, earlier to get any fs changes, and now after the config was created to |
| 205 | // set product variables or targets. |
| 206 | tempFS := map[string][]byte{} |
| 207 | handler(tempFS, config) |
| 208 | } |
| 209 | |
| 210 | ctx := android.NewTestArchContext() |
| 211 | ctx.RegisterModuleType("apex", BundleFactory) |
| 212 | ctx.RegisterModuleType("apex_test", testApexBundleFactory) |
| 213 | ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) |
| 214 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 215 | ctx.RegisterModuleType("apex_defaults", defaultsFactory) |
| 216 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
| 217 | ctx.RegisterModuleType("override_apex", overrideApexFactory) |
| 218 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 219 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 220 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 221 | |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 222 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 223 | ctx.RegisterModuleType("cc_test", cc.TestFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 224 | ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) |
| 225 | ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 226 | ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory) |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 227 | ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 228 | ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 229 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 230 | java.RegisterJavaBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 231 | java.RegisterSystemModulesBuildComponents(ctx) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 232 | java.RegisterAppBuildComponents(ctx) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 233 | ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 234 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 235 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 236 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 237 | |
| 238 | ctx.Register(config) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 239 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 240 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 241 | } |
| 242 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 243 | func setUp() { |
| 244 | var err error |
| 245 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 246 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 247 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 248 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 249 | } |
| 250 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 251 | func tearDown() { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 252 | os.RemoveAll(buildDir) |
| 253 | } |
| 254 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 255 | // ensure that 'result' equals 'expected' |
| 256 | func ensureEquals(t *testing.T, result string, expected string) { |
| 257 | t.Helper() |
| 258 | if result != expected { |
| 259 | t.Errorf("%q != %q", expected, result) |
| 260 | } |
| 261 | } |
| 262 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 263 | // ensure that 'result' contains 'expected' |
| 264 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 265 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 266 | if !strings.Contains(result, expected) { |
| 267 | t.Errorf("%q is not found in %q", expected, result) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // ensures that 'result' does not contain 'notExpected' |
| 272 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 273 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 274 | if strings.Contains(result, notExpected) { |
| 275 | t.Errorf("%q is found in %q", notExpected, result) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 280 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 281 | if !android.InList(expected, result) { |
| 282 | t.Errorf("%q is not found in %v", expected, result) |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 287 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 288 | if android.InList(notExpected, result) { |
| 289 | t.Errorf("%q is found in %v", notExpected, result) |
| 290 | } |
| 291 | } |
| 292 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 293 | func ensureListEmpty(t *testing.T, result []string) { |
| 294 | t.Helper() |
| 295 | if len(result) > 0 { |
| 296 | t.Errorf("%q is expected to be empty", result) |
| 297 | } |
| 298 | } |
| 299 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 300 | // Minimal test |
| 301 | func TestBasicApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 302 | ctx, _ := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 303 | apex_defaults { |
| 304 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 305 | manifest: ":myapex.manifest", |
| 306 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 307 | key: "myapex.key", |
| 308 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 309 | multilib: { |
| 310 | both: { |
| 311 | binaries: ["foo",], |
| 312 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 313 | }, |
Jooyung Han | 5a80d9f | 2019-12-23 15:38:34 +0900 | [diff] [blame] | 314 | java_libs: ["myjar"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 315 | } |
| 316 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 317 | apex { |
| 318 | name: "myapex", |
| 319 | defaults: ["myapex-defaults"], |
| 320 | } |
| 321 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 322 | apex_key { |
| 323 | name: "myapex.key", |
| 324 | public_key: "testkey.avbpubkey", |
| 325 | private_key: "testkey.pem", |
| 326 | } |
| 327 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 328 | filegroup { |
| 329 | name: "myapex.manifest", |
| 330 | srcs: ["apex_manifest.json"], |
| 331 | } |
| 332 | |
| 333 | filegroup { |
| 334 | name: "myapex.androidmanifest", |
| 335 | srcs: ["AndroidManifest.xml"], |
| 336 | } |
| 337 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 338 | cc_library { |
| 339 | name: "mylib", |
| 340 | srcs: ["mylib.cpp"], |
| 341 | shared_libs: ["mylib2"], |
| 342 | system_shared_libs: [], |
| 343 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 344 | // TODO: remove //apex_available:platform |
| 345 | apex_available: [ |
| 346 | "//apex_available:platform", |
| 347 | "myapex", |
| 348 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 349 | } |
| 350 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 351 | cc_binary { |
| 352 | name: "foo", |
| 353 | srcs: ["mylib.cpp"], |
| 354 | compile_multilib: "both", |
| 355 | multilib: { |
| 356 | lib32: { |
| 357 | suffix: "32", |
| 358 | }, |
| 359 | lib64: { |
| 360 | suffix: "64", |
| 361 | }, |
| 362 | }, |
| 363 | symlinks: ["foo_link_"], |
| 364 | symlink_preferred_arch: true, |
| 365 | system_shared_libs: [], |
| 366 | static_executable: true, |
| 367 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 368 | apex_available: [ "myapex" ], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 371 | cc_library { |
| 372 | name: "mylib2", |
| 373 | srcs: ["mylib.cpp"], |
| 374 | system_shared_libs: [], |
| 375 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 376 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 377 | static_libs: ["libstatic"], |
| 378 | // TODO: remove //apex_available:platform |
| 379 | apex_available: [ |
| 380 | "//apex_available:platform", |
| 381 | "myapex", |
| 382 | ], |
| 383 | } |
| 384 | |
| 385 | cc_library_static { |
| 386 | name: "libstatic", |
| 387 | srcs: ["mylib.cpp"], |
| 388 | system_shared_libs: [], |
| 389 | stl: "none", |
| 390 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 391 | // TODO: remove //apex_available:platform |
| 392 | apex_available: [ |
| 393 | "//apex_available:platform", |
| 394 | "myapex", |
| 395 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 396 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 397 | |
| 398 | java_library { |
| 399 | name: "myjar", |
| 400 | srcs: ["foo/bar/MyClass.java"], |
| 401 | sdk_version: "none", |
| 402 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 403 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 404 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 405 | // TODO: remove //apex_available:platform |
| 406 | apex_available: [ |
| 407 | "//apex_available:platform", |
| 408 | "myapex", |
| 409 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | java_library { |
| 413 | name: "myotherjar", |
| 414 | srcs: ["foo/bar/MyClass.java"], |
| 415 | sdk_version: "none", |
| 416 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 417 | // TODO: remove //apex_available:platform |
| 418 | apex_available: [ |
| 419 | "//apex_available:platform", |
| 420 | "myapex", |
| 421 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 422 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 423 | |
| 424 | java_library { |
| 425 | name: "mysharedjar", |
| 426 | srcs: ["foo/bar/MyClass.java"], |
| 427 | sdk_version: "none", |
| 428 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 429 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 430 | `) |
| 431 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 432 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 433 | |
| 434 | optFlags := apexRule.Args["opt_flags"] |
| 435 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 436 | // Ensure that the NOTICE output is being packaged as an asset. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 437 | 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] | 438 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 439 | copyCmds := apexRule.Args["copy_commands"] |
| 440 | |
| 441 | // Ensure that main rule creates an output |
| 442 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 443 | |
| 444 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 445 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 446 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 447 | |
| 448 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 449 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 450 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 451 | |
| 452 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 453 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 454 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 455 | ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar") |
| 456 | // .. but not for java libs |
| 457 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 458 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 459 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 460 | // Ensure that the platform variant ends with _shared or _common |
| 461 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 462 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 463 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 464 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 465 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 466 | |
| 467 | // Ensure that dynamic dependency to java libs are not included |
| 468 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 469 | |
| 470 | // Ensure that all symlinks are present. |
| 471 | found_foo_link_64 := false |
| 472 | found_foo := false |
| 473 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 474 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 475 | if strings.HasSuffix(cmd, "bin/foo") { |
| 476 | found_foo = true |
| 477 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 478 | found_foo_link_64 = true |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | good := found_foo && found_foo_link_64 |
| 483 | if !good { |
| 484 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 485 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 486 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 487 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 488 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 489 | if len(noticeInputs) != 3 { |
| 490 | 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] | 491 | } |
| 492 | ensureListContains(t, noticeInputs, "NOTICE") |
| 493 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 494 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 495 | |
| 496 | depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 497 | ensureListContains(t, depsInfo, "myjar <- myapex") |
| 498 | ensureListContains(t, depsInfo, "mylib <- myapex") |
| 499 | ensureListContains(t, depsInfo, "mylib2 <- mylib") |
| 500 | ensureListContains(t, depsInfo, "myotherjar <- myjar") |
| 501 | ensureListContains(t, depsInfo, "mysharedjar (external) <- myjar") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 504 | func TestDefaults(t *testing.T) { |
| 505 | ctx, _ := testApex(t, ` |
| 506 | apex_defaults { |
| 507 | name: "myapex-defaults", |
| 508 | key: "myapex.key", |
| 509 | prebuilts: ["myetc"], |
| 510 | native_shared_libs: ["mylib"], |
| 511 | java_libs: ["myjar"], |
| 512 | apps: ["AppFoo"], |
| 513 | } |
| 514 | |
| 515 | prebuilt_etc { |
| 516 | name: "myetc", |
| 517 | src: "myprebuilt", |
| 518 | } |
| 519 | |
| 520 | apex { |
| 521 | name: "myapex", |
| 522 | defaults: ["myapex-defaults"], |
| 523 | } |
| 524 | |
| 525 | apex_key { |
| 526 | name: "myapex.key", |
| 527 | public_key: "testkey.avbpubkey", |
| 528 | private_key: "testkey.pem", |
| 529 | } |
| 530 | |
| 531 | cc_library { |
| 532 | name: "mylib", |
| 533 | system_shared_libs: [], |
| 534 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 535 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | java_library { |
| 539 | name: "myjar", |
| 540 | srcs: ["foo/bar/MyClass.java"], |
| 541 | sdk_version: "none", |
| 542 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 543 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | android_app { |
| 547 | name: "AppFoo", |
| 548 | srcs: ["foo/bar/MyClass.java"], |
| 549 | sdk_version: "none", |
| 550 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 551 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 552 | } |
| 553 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 554 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 555 | "etc/myetc", |
| 556 | "javalib/myjar.jar", |
| 557 | "lib64/mylib.so", |
| 558 | "app/AppFoo/AppFoo.apk", |
| 559 | }) |
| 560 | } |
| 561 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 562 | func TestApexManifest(t *testing.T) { |
| 563 | ctx, _ := testApex(t, ` |
| 564 | apex { |
| 565 | name: "myapex", |
| 566 | key: "myapex.key", |
| 567 | } |
| 568 | |
| 569 | apex_key { |
| 570 | name: "myapex.key", |
| 571 | public_key: "testkey.avbpubkey", |
| 572 | private_key: "testkey.pem", |
| 573 | } |
| 574 | `) |
| 575 | |
| 576 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 577 | args := module.Rule("apexRule").Args |
| 578 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 579 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 580 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 581 | } |
| 582 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 583 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 584 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 585 | apex { |
| 586 | name: "myapex", |
| 587 | key: "myapex.key", |
| 588 | payload_type: "zip", |
| 589 | native_shared_libs: ["mylib"], |
| 590 | } |
| 591 | |
| 592 | apex_key { |
| 593 | name: "myapex.key", |
| 594 | public_key: "testkey.avbpubkey", |
| 595 | private_key: "testkey.pem", |
| 596 | } |
| 597 | |
| 598 | cc_library { |
| 599 | name: "mylib", |
| 600 | srcs: ["mylib.cpp"], |
| 601 | shared_libs: ["mylib2"], |
| 602 | system_shared_libs: [], |
| 603 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 604 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | cc_library { |
| 608 | name: "mylib2", |
| 609 | srcs: ["mylib.cpp"], |
| 610 | system_shared_libs: [], |
| 611 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 612 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 613 | } |
| 614 | `) |
| 615 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 616 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 617 | copyCmds := zipApexRule.Args["copy_commands"] |
| 618 | |
| 619 | // Ensure that main rule creates an output |
| 620 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 621 | |
| 622 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 623 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 624 | |
| 625 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 626 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 627 | |
| 628 | // Ensure that both direct and indirect deps are copied into apex |
| 629 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 630 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 634 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 635 | apex { |
| 636 | name: "myapex", |
| 637 | key: "myapex.key", |
| 638 | native_shared_libs: ["mylib", "mylib3"], |
| 639 | } |
| 640 | |
| 641 | apex_key { |
| 642 | name: "myapex.key", |
| 643 | public_key: "testkey.avbpubkey", |
| 644 | private_key: "testkey.pem", |
| 645 | } |
| 646 | |
| 647 | cc_library { |
| 648 | name: "mylib", |
| 649 | srcs: ["mylib.cpp"], |
| 650 | shared_libs: ["mylib2", "mylib3"], |
| 651 | system_shared_libs: [], |
| 652 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 653 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | cc_library { |
| 657 | name: "mylib2", |
| 658 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 659 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 660 | system_shared_libs: [], |
| 661 | stl: "none", |
| 662 | stubs: { |
| 663 | versions: ["1", "2", "3"], |
| 664 | }, |
| 665 | } |
| 666 | |
| 667 | cc_library { |
| 668 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 669 | srcs: ["mylib.cpp"], |
| 670 | shared_libs: ["mylib4"], |
| 671 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 672 | stl: "none", |
| 673 | stubs: { |
| 674 | versions: ["10", "11", "12"], |
| 675 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 676 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 677 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 678 | |
| 679 | cc_library { |
| 680 | name: "mylib4", |
| 681 | srcs: ["mylib.cpp"], |
| 682 | system_shared_libs: [], |
| 683 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 684 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 685 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 686 | `) |
| 687 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 688 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 689 | copyCmds := apexRule.Args["copy_commands"] |
| 690 | |
| 691 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 692 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 693 | |
| 694 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 695 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 696 | |
| 697 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 698 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 699 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 700 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 701 | |
| 702 | // 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] | 703 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 704 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 705 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 706 | |
| 707 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 708 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 709 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 710 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 711 | |
| 712 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 713 | 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] | 714 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 715 | |
| 716 | // Ensure that genstub is invoked with --apex |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 717 | 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] | 718 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 719 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 720 | "lib64/mylib.so", |
| 721 | "lib64/mylib3.so", |
| 722 | "lib64/mylib4.so", |
| 723 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 724 | } |
| 725 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 726 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 727 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 728 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 729 | name: "myapex2", |
| 730 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 731 | native_shared_libs: ["mylib"], |
| 732 | } |
| 733 | |
| 734 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 735 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 736 | public_key: "testkey.avbpubkey", |
| 737 | private_key: "testkey.pem", |
| 738 | } |
| 739 | |
| 740 | cc_library { |
| 741 | name: "mylib", |
| 742 | srcs: ["mylib.cpp"], |
| 743 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 744 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 745 | system_shared_libs: [], |
| 746 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 747 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | cc_library { |
| 751 | name: "libfoo", |
| 752 | srcs: ["mylib.cpp"], |
| 753 | shared_libs: ["libbar"], |
| 754 | system_shared_libs: [], |
| 755 | stl: "none", |
| 756 | stubs: { |
| 757 | versions: ["10", "20", "30"], |
| 758 | }, |
| 759 | } |
| 760 | |
| 761 | cc_library { |
| 762 | name: "libbar", |
| 763 | srcs: ["mylib.cpp"], |
| 764 | system_shared_libs: [], |
| 765 | stl: "none", |
| 766 | } |
| 767 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 768 | cc_library_static { |
| 769 | name: "libbaz", |
| 770 | srcs: ["mylib.cpp"], |
| 771 | system_shared_libs: [], |
| 772 | stl: "none", |
| 773 | apex_available: [ "myapex2" ], |
| 774 | } |
| 775 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 776 | `) |
| 777 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 778 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 779 | copyCmds := apexRule.Args["copy_commands"] |
| 780 | |
| 781 | // Ensure that direct non-stubs dep is always included |
| 782 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 783 | |
| 784 | // Ensure that indirect stubs dep is not included |
| 785 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 786 | |
| 787 | // Ensure that dependency of stubs is not included |
| 788 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 789 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 790 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 791 | |
| 792 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 793 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 794 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 795 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 796 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 797 | 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] | 798 | |
| 799 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 800 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 801 | |
| 802 | depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 803 | |
| 804 | ensureListContains(t, depsInfo, "mylib <- myapex2") |
| 805 | ensureListContains(t, depsInfo, "libbaz <- mylib") |
| 806 | ensureListContains(t, depsInfo, "libfoo (external) <- mylib") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 807 | } |
| 808 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 809 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 810 | /* |
| 811 | myapex |
| 812 | | |
| 813 | v (runtime_libs) |
| 814 | mylib ------+------> libfoo [provides stub] |
| 815 | | |
| 816 | `------> libbar |
| 817 | */ |
| 818 | ctx, _ := testApex(t, ` |
| 819 | apex { |
| 820 | name: "myapex", |
| 821 | key: "myapex.key", |
| 822 | native_shared_libs: ["mylib"], |
| 823 | } |
| 824 | |
| 825 | apex_key { |
| 826 | name: "myapex.key", |
| 827 | public_key: "testkey.avbpubkey", |
| 828 | private_key: "testkey.pem", |
| 829 | } |
| 830 | |
| 831 | cc_library { |
| 832 | name: "mylib", |
| 833 | srcs: ["mylib.cpp"], |
| 834 | runtime_libs: ["libfoo", "libbar"], |
| 835 | system_shared_libs: [], |
| 836 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 837 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | cc_library { |
| 841 | name: "libfoo", |
| 842 | srcs: ["mylib.cpp"], |
| 843 | system_shared_libs: [], |
| 844 | stl: "none", |
| 845 | stubs: { |
| 846 | versions: ["10", "20", "30"], |
| 847 | }, |
| 848 | } |
| 849 | |
| 850 | cc_library { |
| 851 | name: "libbar", |
| 852 | srcs: ["mylib.cpp"], |
| 853 | system_shared_libs: [], |
| 854 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 855 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | `) |
| 859 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 860 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 861 | copyCmds := apexRule.Args["copy_commands"] |
| 862 | |
| 863 | // Ensure that direct non-stubs dep is always included |
| 864 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 865 | |
| 866 | // Ensure that indirect stubs dep is not included |
| 867 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 868 | |
| 869 | // Ensure that runtime_libs dep in included |
| 870 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 871 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 872 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 873 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 874 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 875 | |
| 876 | } |
| 877 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 878 | func TestApexDependencyToLLNDK(t *testing.T) { |
| 879 | ctx, _ := testApex(t, ` |
| 880 | apex { |
| 881 | name: "myapex", |
| 882 | key: "myapex.key", |
| 883 | use_vendor: true, |
| 884 | native_shared_libs: ["mylib"], |
| 885 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 886 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 887 | apex_key { |
| 888 | name: "myapex.key", |
| 889 | public_key: "testkey.avbpubkey", |
| 890 | private_key: "testkey.pem", |
| 891 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 892 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 893 | cc_library { |
| 894 | name: "mylib", |
| 895 | srcs: ["mylib.cpp"], |
| 896 | vendor_available: true, |
| 897 | shared_libs: ["libbar"], |
| 898 | system_shared_libs: [], |
| 899 | stl: "none", |
| 900 | apex_available: [ "myapex" ], |
| 901 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 902 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 903 | cc_library { |
| 904 | name: "libbar", |
| 905 | srcs: ["mylib.cpp"], |
| 906 | system_shared_libs: [], |
| 907 | stl: "none", |
| 908 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 909 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 910 | llndk_library { |
| 911 | name: "libbar", |
| 912 | symbol_file: "", |
| 913 | } |
| 914 | `, func(fs map[string][]byte, config android.Config) { |
| 915 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 916 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 917 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 918 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 919 | copyCmds := apexRule.Args["copy_commands"] |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 920 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 921 | // Ensure that LLNDK dep is not included |
| 922 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 923 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 924 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 925 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 926 | |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 927 | // Ensure that LLNDK dep is required |
| 928 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
| 929 | |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 930 | } |
| 931 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 932 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 933 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 934 | apex { |
| 935 | name: "myapex", |
| 936 | key: "myapex.key", |
| 937 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 938 | } |
| 939 | |
| 940 | apex_key { |
| 941 | name: "myapex.key", |
| 942 | public_key: "testkey.avbpubkey", |
| 943 | private_key: "testkey.pem", |
| 944 | } |
| 945 | |
| 946 | cc_library { |
| 947 | name: "mylib", |
| 948 | srcs: ["mylib.cpp"], |
| 949 | shared_libs: ["libdl#27"], |
| 950 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 951 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | cc_library_shared { |
| 955 | name: "mylib_shared", |
| 956 | srcs: ["mylib.cpp"], |
| 957 | shared_libs: ["libdl#27"], |
| 958 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 959 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 963 | name: "libBootstrap", |
| 964 | srcs: ["mylib.cpp"], |
| 965 | stl: "none", |
| 966 | bootstrap: true, |
| 967 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 968 | `) |
| 969 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 970 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 971 | copyCmds := apexRule.Args["copy_commands"] |
| 972 | |
| 973 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 974 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 975 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 976 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 977 | |
| 978 | // 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] | 979 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 980 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 981 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 982 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 983 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 984 | |
| 985 | // For dependency to libc |
| 986 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 987 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 988 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 989 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 990 | // ... Cflags from stub is correctly exported to mylib |
| 991 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 992 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 993 | |
| 994 | // For dependency to libm |
| 995 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 996 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 997 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 998 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 999 | // ... and is not compiling with the stub |
| 1000 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1001 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1002 | |
| 1003 | // For dependency to libdl |
| 1004 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1005 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1006 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1007 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1008 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1009 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1010 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1011 | // ... Cflags from stub is correctly exported to mylib |
| 1012 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1013 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1014 | |
| 1015 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1016 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1017 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1018 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1019 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1020 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1021 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1022 | func TestApexUseStubsAccordingToMinSdkVersionInUnbundledBuild(t *testing.T) { |
| 1023 | // there are three links between liba --> libz |
| 1024 | // 1) myapex -> libx -> liba -> libz : this should be #2 link, but fallback to #1 |
| 1025 | // 2) otherapex -> liby -> liba -> libz : this should be #3 link |
| 1026 | // 3) (platform) -> liba -> libz : this should be non-stub link |
| 1027 | ctx, _ := testApex(t, ` |
| 1028 | apex { |
| 1029 | name: "myapex", |
| 1030 | key: "myapex.key", |
| 1031 | native_shared_libs: ["libx"], |
| 1032 | min_sdk_version: "2", |
| 1033 | } |
| 1034 | |
| 1035 | apex { |
| 1036 | name: "otherapex", |
| 1037 | key: "myapex.key", |
| 1038 | native_shared_libs: ["liby"], |
| 1039 | min_sdk_version: "3", |
| 1040 | } |
| 1041 | |
| 1042 | apex_key { |
| 1043 | name: "myapex.key", |
| 1044 | public_key: "testkey.avbpubkey", |
| 1045 | private_key: "testkey.pem", |
| 1046 | } |
| 1047 | |
| 1048 | cc_library { |
| 1049 | name: "libx", |
| 1050 | shared_libs: ["liba"], |
| 1051 | system_shared_libs: [], |
| 1052 | stl: "none", |
| 1053 | apex_available: [ "myapex" ], |
| 1054 | } |
| 1055 | |
| 1056 | cc_library { |
| 1057 | name: "liby", |
| 1058 | shared_libs: ["liba"], |
| 1059 | system_shared_libs: [], |
| 1060 | stl: "none", |
| 1061 | apex_available: [ "otherapex" ], |
| 1062 | } |
| 1063 | |
| 1064 | cc_library { |
| 1065 | name: "liba", |
| 1066 | shared_libs: ["libz"], |
| 1067 | system_shared_libs: [], |
| 1068 | stl: "none", |
| 1069 | apex_available: [ |
| 1070 | "//apex_available:anyapex", |
| 1071 | "//apex_available:platform", |
| 1072 | ], |
| 1073 | } |
| 1074 | |
| 1075 | cc_library { |
| 1076 | name: "libz", |
| 1077 | system_shared_libs: [], |
| 1078 | stl: "none", |
| 1079 | stubs: { |
| 1080 | versions: ["1", "3"], |
| 1081 | }, |
| 1082 | } |
| 1083 | `, withUnbundledBuild) |
| 1084 | |
| 1085 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1086 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1087 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1088 | } |
| 1089 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1090 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1091 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1092 | } |
| 1093 | // platform liba is linked to non-stub version |
| 1094 | expectLink("liba", "shared", "libz", "shared") |
| 1095 | // liba in myapex is linked to #1 |
| 1096 | expectLink("liba", "shared_myapex", "libz", "shared_1") |
| 1097 | expectNoLink("liba", "shared_myapex", "libz", "shared_3") |
| 1098 | expectNoLink("liba", "shared_myapex", "libz", "shared") |
| 1099 | // liba in otherapex is linked to #3 |
| 1100 | expectLink("liba", "shared_otherapex", "libz", "shared_3") |
| 1101 | expectNoLink("liba", "shared_otherapex", "libz", "shared_1") |
| 1102 | expectNoLink("liba", "shared_otherapex", "libz", "shared") |
| 1103 | } |
| 1104 | |
| 1105 | func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) { |
| 1106 | ctx, _ := testApex(t, ` |
| 1107 | apex { |
| 1108 | name: "myapex", |
| 1109 | key: "myapex.key", |
| 1110 | native_shared_libs: ["libx"], |
| 1111 | } |
| 1112 | |
| 1113 | apex_key { |
| 1114 | name: "myapex.key", |
| 1115 | public_key: "testkey.avbpubkey", |
| 1116 | private_key: "testkey.pem", |
| 1117 | } |
| 1118 | |
| 1119 | cc_library { |
| 1120 | name: "libx", |
| 1121 | shared_libs: ["libz"], |
| 1122 | system_shared_libs: [], |
| 1123 | stl: "none", |
| 1124 | apex_available: [ "myapex" ], |
| 1125 | } |
| 1126 | |
| 1127 | cc_library { |
| 1128 | name: "libz", |
| 1129 | system_shared_libs: [], |
| 1130 | stl: "none", |
| 1131 | stubs: { |
| 1132 | versions: ["1", "2"], |
| 1133 | }, |
| 1134 | } |
| 1135 | `) |
| 1136 | |
| 1137 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1138 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1139 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1140 | } |
| 1141 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1142 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1143 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1144 | } |
| 1145 | expectLink("libx", "shared_myapex", "libz", "shared_2") |
| 1146 | expectNoLink("libx", "shared_myapex", "libz", "shared_1") |
| 1147 | expectNoLink("libx", "shared_myapex", "libz", "shared") |
| 1148 | } |
| 1149 | |
| 1150 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
| 1151 | ctx, _ := testApex(t, ` |
| 1152 | apex { |
| 1153 | name: "myapex", |
| 1154 | key: "myapex.key", |
| 1155 | native_shared_libs: ["libx"], |
| 1156 | } |
| 1157 | |
| 1158 | apex_key { |
| 1159 | name: "myapex.key", |
| 1160 | public_key: "testkey.avbpubkey", |
| 1161 | private_key: "testkey.pem", |
| 1162 | } |
| 1163 | |
| 1164 | cc_library { |
| 1165 | name: "libx", |
| 1166 | system_shared_libs: [], |
| 1167 | stl: "none", |
| 1168 | apex_available: [ "myapex" ], |
| 1169 | stubs: { |
| 1170 | versions: ["1", "2"], |
| 1171 | }, |
| 1172 | } |
| 1173 | |
| 1174 | cc_library { |
| 1175 | name: "libz", |
| 1176 | shared_libs: ["libx"], |
| 1177 | system_shared_libs: [], |
| 1178 | stl: "none", |
| 1179 | } |
| 1180 | `) |
| 1181 | |
| 1182 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1183 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1184 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1185 | } |
| 1186 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1187 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1188 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1189 | } |
| 1190 | expectLink("libz", "shared", "libx", "shared_2") |
| 1191 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1192 | expectNoLink("libz", "shared", "libz", "shared") |
| 1193 | } |
| 1194 | |
| 1195 | func TestQApexesUseLatestStubsInBundledBuilds(t *testing.T) { |
| 1196 | ctx, _ := testApex(t, ` |
| 1197 | apex { |
| 1198 | name: "myapex", |
| 1199 | key: "myapex.key", |
| 1200 | native_shared_libs: ["libx"], |
| 1201 | min_sdk_version: "29", |
| 1202 | } |
| 1203 | |
| 1204 | apex_key { |
| 1205 | name: "myapex.key", |
| 1206 | public_key: "testkey.avbpubkey", |
| 1207 | private_key: "testkey.pem", |
| 1208 | } |
| 1209 | |
| 1210 | cc_library { |
| 1211 | name: "libx", |
| 1212 | shared_libs: ["libbar"], |
| 1213 | apex_available: [ "myapex" ], |
| 1214 | } |
| 1215 | |
| 1216 | cc_library { |
| 1217 | name: "libbar", |
| 1218 | stubs: { |
| 1219 | versions: ["29", "30"], |
| 1220 | }, |
| 1221 | } |
| 1222 | `) |
| 1223 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1224 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1225 | libFlags := ld.Args["libFlags"] |
| 1226 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1227 | } |
| 1228 | expectLink("libx", "shared_myapex", "libbar", "shared_30") |
| 1229 | } |
| 1230 | |
| 1231 | func TestQTargetApexUseStaticUnwinder(t *testing.T) { |
| 1232 | ctx, _ := testApex(t, ` |
| 1233 | apex { |
| 1234 | name: "myapex", |
| 1235 | key: "myapex.key", |
| 1236 | native_shared_libs: ["libx"], |
| 1237 | min_sdk_version: "29", |
| 1238 | } |
| 1239 | |
| 1240 | apex_key { |
| 1241 | name: "myapex.key", |
| 1242 | public_key: "testkey.avbpubkey", |
| 1243 | private_key: "testkey.pem", |
| 1244 | } |
| 1245 | |
| 1246 | cc_library { |
| 1247 | name: "libx", |
| 1248 | apex_available: [ "myapex" ], |
| 1249 | } |
| 1250 | |
| 1251 | `, withUnbundledBuild) |
| 1252 | |
| 1253 | // ensure apex variant of c++ is linked with static unwinder |
| 1254 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module) |
| 1255 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
| 1256 | // note that platform variant is not. |
| 1257 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 1258 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libgcc_stripped") |
Jooyung Han | bacf34d | 2020-03-21 13:58:19 +0000 | [diff] [blame] | 1259 | |
| 1260 | libFlags := ctx.ModuleForTests("libx", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"] |
| 1261 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_myapex/libc++.so") |
| 1262 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_29/libc.so") // min_sdk_version applied |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | func TestInvalidMinSdkVersion(t *testing.T) { |
| 1266 | testApexError(t, `"libz" .*: min_sdk_version is set 29.*`, ` |
| 1267 | apex { |
| 1268 | name: "myapex", |
| 1269 | key: "myapex.key", |
| 1270 | native_shared_libs: ["libx"], |
| 1271 | min_sdk_version: "29", |
| 1272 | } |
| 1273 | |
| 1274 | apex_key { |
| 1275 | name: "myapex.key", |
| 1276 | public_key: "testkey.avbpubkey", |
| 1277 | private_key: "testkey.pem", |
| 1278 | } |
| 1279 | |
| 1280 | cc_library { |
| 1281 | name: "libx", |
| 1282 | shared_libs: ["libz"], |
| 1283 | system_shared_libs: [], |
| 1284 | stl: "none", |
| 1285 | apex_available: [ "myapex" ], |
| 1286 | } |
| 1287 | |
| 1288 | cc_library { |
| 1289 | name: "libz", |
| 1290 | system_shared_libs: [], |
| 1291 | stl: "none", |
| 1292 | stubs: { |
| 1293 | versions: ["30"], |
| 1294 | }, |
| 1295 | } |
| 1296 | `, withUnbundledBuild) |
| 1297 | |
| 1298 | testApexError(t, `"myapex" .*: min_sdk_version: should be .*`, ` |
| 1299 | apex { |
| 1300 | name: "myapex", |
| 1301 | key: "myapex.key", |
| 1302 | min_sdk_version: "R", |
| 1303 | } |
| 1304 | |
| 1305 | apex_key { |
| 1306 | name: "myapex.key", |
| 1307 | public_key: "testkey.avbpubkey", |
| 1308 | private_key: "testkey.pem", |
| 1309 | } |
| 1310 | `) |
| 1311 | } |
| 1312 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1313 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1314 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1315 | apex { |
| 1316 | name: "myapex", |
| 1317 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1318 | native_shared_libs: ["mylib"], |
| 1319 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1320 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1321 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | apex_key { |
| 1325 | name: "myapex.key", |
| 1326 | public_key: "testkey.avbpubkey", |
| 1327 | private_key: "testkey.pem", |
| 1328 | } |
| 1329 | |
| 1330 | prebuilt_etc { |
| 1331 | name: "myetc", |
| 1332 | src: "myprebuilt", |
| 1333 | sub_dir: "foo/bar", |
| 1334 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1335 | |
| 1336 | cc_library { |
| 1337 | name: "mylib", |
| 1338 | srcs: ["mylib.cpp"], |
| 1339 | relative_install_path: "foo/bar", |
| 1340 | system_shared_libs: [], |
| 1341 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1342 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | cc_binary { |
| 1346 | name: "mybin", |
| 1347 | srcs: ["mylib.cpp"], |
| 1348 | relative_install_path: "foo/bar", |
| 1349 | system_shared_libs: [], |
| 1350 | static_executable: true, |
| 1351 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1352 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1353 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1354 | `) |
| 1355 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1356 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1357 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 1358 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1359 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1360 | ensureListContains(t, dirs, "etc") |
| 1361 | ensureListContains(t, dirs, "etc/foo") |
| 1362 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 1363 | ensureListContains(t, dirs, "lib64") |
| 1364 | ensureListContains(t, dirs, "lib64/foo") |
| 1365 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 1366 | ensureListContains(t, dirs, "lib") |
| 1367 | ensureListContains(t, dirs, "lib/foo") |
| 1368 | ensureListContains(t, dirs, "lib/foo/bar") |
| 1369 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 1370 | ensureListContains(t, dirs, "bin") |
| 1371 | ensureListContains(t, dirs, "bin/foo") |
| 1372 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1373 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1374 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 1375 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
| 1376 | ctx, _ := testApex(t, ` |
| 1377 | apex { |
| 1378 | name: "myapex", |
| 1379 | key: "myapex.key", |
| 1380 | multilib: { |
| 1381 | both: { |
| 1382 | native_shared_libs: ["mylib"], |
| 1383 | binaries: ["mybin"], |
| 1384 | }, |
| 1385 | }, |
| 1386 | compile_multilib: "both", |
| 1387 | native_bridge_supported: true, |
| 1388 | } |
| 1389 | |
| 1390 | apex_key { |
| 1391 | name: "myapex.key", |
| 1392 | public_key: "testkey.avbpubkey", |
| 1393 | private_key: "testkey.pem", |
| 1394 | } |
| 1395 | |
| 1396 | cc_library { |
| 1397 | name: "mylib", |
| 1398 | relative_install_path: "foo/bar", |
| 1399 | system_shared_libs: [], |
| 1400 | stl: "none", |
| 1401 | apex_available: [ "myapex" ], |
| 1402 | native_bridge_supported: true, |
| 1403 | } |
| 1404 | |
| 1405 | cc_binary { |
| 1406 | name: "mybin", |
| 1407 | relative_install_path: "foo/bar", |
| 1408 | system_shared_libs: [], |
| 1409 | static_executable: true, |
| 1410 | stl: "none", |
| 1411 | apex_available: [ "myapex" ], |
| 1412 | native_bridge_supported: true, |
| 1413 | compile_multilib: "both", // default is "first" for binary |
| 1414 | multilib: { |
| 1415 | lib64: { |
| 1416 | suffix: "64", |
| 1417 | }, |
| 1418 | }, |
| 1419 | } |
| 1420 | `, withNativeBridgeEnabled) |
| 1421 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1422 | "bin/foo/bar/mybin", |
| 1423 | "bin/foo/bar/mybin64", |
| 1424 | "bin/arm/foo/bar/mybin", |
| 1425 | "bin/arm64/foo/bar/mybin64", |
| 1426 | "lib/foo/bar/mylib.so", |
| 1427 | "lib/arm/foo/bar/mylib.so", |
| 1428 | "lib64/foo/bar/mylib.so", |
| 1429 | "lib64/arm64/foo/bar/mylib.so", |
| 1430 | }) |
| 1431 | } |
| 1432 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1433 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1434 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1435 | apex { |
| 1436 | name: "myapex", |
| 1437 | key: "myapex.key", |
| 1438 | native_shared_libs: ["mylib"], |
| 1439 | use_vendor: true, |
| 1440 | } |
| 1441 | |
| 1442 | apex_key { |
| 1443 | name: "myapex.key", |
| 1444 | public_key: "testkey.avbpubkey", |
| 1445 | private_key: "testkey.pem", |
| 1446 | } |
| 1447 | |
| 1448 | cc_library { |
| 1449 | name: "mylib", |
| 1450 | srcs: ["mylib.cpp"], |
| 1451 | shared_libs: ["mylib2"], |
| 1452 | system_shared_libs: [], |
| 1453 | vendor_available: true, |
| 1454 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1455 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | cc_library { |
| 1459 | name: "mylib2", |
| 1460 | srcs: ["mylib.cpp"], |
| 1461 | system_shared_libs: [], |
| 1462 | vendor_available: true, |
| 1463 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1464 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1465 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1466 | `, func(fs map[string][]byte, config android.Config) { |
| 1467 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1468 | }) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1469 | |
| 1470 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1471 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1472 | for _, implicit := range i.Implicits { |
| 1473 | inputsList = append(inputsList, implicit.String()) |
| 1474 | } |
| 1475 | } |
| 1476 | inputsString := strings.Join(inputsList, " ") |
| 1477 | |
| 1478 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 1479 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so") |
| 1480 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1481 | |
| 1482 | // ensure that the apex does not include core variants |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1483 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so") |
| 1484 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1485 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1486 | |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 1487 | func TestUseVendorRestriction(t *testing.T) { |
| 1488 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 1489 | apex { |
| 1490 | name: "myapex", |
| 1491 | key: "myapex.key", |
| 1492 | use_vendor: true, |
| 1493 | } |
| 1494 | apex_key { |
| 1495 | name: "myapex.key", |
| 1496 | public_key: "testkey.avbpubkey", |
| 1497 | private_key: "testkey.pem", |
| 1498 | } |
| 1499 | `, func(fs map[string][]byte, config android.Config) { |
| 1500 | setUseVendorWhitelistForTest(config, []string{""}) |
| 1501 | }) |
| 1502 | // no error with whitelist |
| 1503 | testApex(t, ` |
| 1504 | apex { |
| 1505 | name: "myapex", |
| 1506 | key: "myapex.key", |
| 1507 | use_vendor: true, |
| 1508 | } |
| 1509 | apex_key { |
| 1510 | name: "myapex.key", |
| 1511 | public_key: "testkey.avbpubkey", |
| 1512 | private_key: "testkey.pem", |
| 1513 | } |
| 1514 | `, func(fs map[string][]byte, config android.Config) { |
| 1515 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 1516 | }) |
| 1517 | } |
| 1518 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1519 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 1520 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 1521 | apex { |
| 1522 | name: "myapex", |
| 1523 | key: "myapex.key", |
| 1524 | native_shared_libs: ["mylib"], |
| 1525 | use_vendor: true, |
| 1526 | } |
| 1527 | |
| 1528 | apex_key { |
| 1529 | name: "myapex.key", |
| 1530 | public_key: "testkey.avbpubkey", |
| 1531 | private_key: "testkey.pem", |
| 1532 | } |
| 1533 | |
| 1534 | cc_library { |
| 1535 | name: "mylib", |
| 1536 | srcs: ["mylib.cpp"], |
| 1537 | system_shared_libs: [], |
| 1538 | stl: "none", |
| 1539 | } |
| 1540 | `) |
| 1541 | } |
| 1542 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1543 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1544 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1545 | apex { |
| 1546 | name: "myapex", |
| 1547 | key: "myapex.key", |
| 1548 | native_shared_libs: ["mylib"], |
| 1549 | } |
| 1550 | |
| 1551 | apex_key { |
| 1552 | name: "myapex.key", |
| 1553 | public_key: "testkey.avbpubkey", |
| 1554 | private_key: "testkey.pem", |
| 1555 | } |
| 1556 | |
| 1557 | cc_library { |
| 1558 | name: "mylib", |
| 1559 | srcs: ["mylib.cpp"], |
| 1560 | system_shared_libs: [], |
| 1561 | stl: "none", |
| 1562 | stubs: { |
| 1563 | versions: ["1", "2", "3"], |
| 1564 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1565 | apex_available: [ |
| 1566 | "//apex_available:platform", |
| 1567 | "myapex", |
| 1568 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | cc_binary { |
| 1572 | name: "not_in_apex", |
| 1573 | srcs: ["mylib.cpp"], |
| 1574 | static_libs: ["mylib"], |
| 1575 | static_executable: true, |
| 1576 | system_shared_libs: [], |
| 1577 | stl: "none", |
| 1578 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1579 | `) |
| 1580 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1581 | 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] | 1582 | |
| 1583 | // 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] | 1584 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1585 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1586 | |
| 1587 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1588 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1589 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1590 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1591 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1592 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1593 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 1594 | file_contexts: ":myapex-file_contexts", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | cc_library { |
| 1598 | name: "mylib", |
| 1599 | srcs: ["mylib.cpp"], |
| 1600 | system_shared_libs: [], |
| 1601 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1602 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | apex_key { |
| 1606 | name: "myapex.key", |
| 1607 | public_key: "testkey.avbpubkey", |
| 1608 | private_key: "testkey.pem", |
| 1609 | } |
| 1610 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1611 | android_app_certificate { |
| 1612 | name: "myapex.certificate", |
| 1613 | certificate: "testkey", |
| 1614 | } |
| 1615 | |
| 1616 | android_app_certificate { |
| 1617 | name: "myapex.certificate.override", |
| 1618 | certificate: "testkey.override", |
| 1619 | } |
| 1620 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1621 | `) |
| 1622 | |
| 1623 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1624 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1625 | |
| 1626 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 1627 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 1628 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 1629 | } |
| 1630 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 1631 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 1632 | "vendor/foo/devkeys/testkey.pem") |
| 1633 | } |
| 1634 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1635 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1636 | 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] | 1637 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1638 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1639 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1640 | } |
| 1641 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1642 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 1643 | func TestCertificate(t *testing.T) { |
| 1644 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
| 1645 | ctx, _ := testApex(t, ` |
| 1646 | apex { |
| 1647 | name: "myapex", |
| 1648 | key: "myapex.key", |
| 1649 | } |
| 1650 | apex_key { |
| 1651 | name: "myapex.key", |
| 1652 | public_key: "testkey.avbpubkey", |
| 1653 | private_key: "testkey.pem", |
| 1654 | }`) |
| 1655 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1656 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 1657 | if actual := rule.Args["certificates"]; actual != expected { |
| 1658 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1659 | } |
| 1660 | }) |
| 1661 | t.Run("override when unspecified", func(t *testing.T) { |
| 1662 | ctx, _ := testApex(t, ` |
| 1663 | apex { |
| 1664 | name: "myapex_keytest", |
| 1665 | key: "myapex.key", |
| 1666 | file_contexts: ":myapex-file_contexts", |
| 1667 | } |
| 1668 | apex_key { |
| 1669 | name: "myapex.key", |
| 1670 | public_key: "testkey.avbpubkey", |
| 1671 | private_key: "testkey.pem", |
| 1672 | } |
| 1673 | android_app_certificate { |
| 1674 | name: "myapex.certificate.override", |
| 1675 | certificate: "testkey.override", |
| 1676 | }`) |
| 1677 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1678 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1679 | if actual := rule.Args["certificates"]; actual != expected { |
| 1680 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1681 | } |
| 1682 | }) |
| 1683 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
| 1684 | ctx, _ := testApex(t, ` |
| 1685 | apex { |
| 1686 | name: "myapex", |
| 1687 | key: "myapex.key", |
| 1688 | certificate: ":myapex.certificate", |
| 1689 | } |
| 1690 | apex_key { |
| 1691 | name: "myapex.key", |
| 1692 | public_key: "testkey.avbpubkey", |
| 1693 | private_key: "testkey.pem", |
| 1694 | } |
| 1695 | android_app_certificate { |
| 1696 | name: "myapex.certificate", |
| 1697 | certificate: "testkey", |
| 1698 | }`) |
| 1699 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1700 | expected := "testkey.x509.pem testkey.pk8" |
| 1701 | if actual := rule.Args["certificates"]; actual != expected { |
| 1702 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1703 | } |
| 1704 | }) |
| 1705 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
| 1706 | ctx, _ := testApex(t, ` |
| 1707 | apex { |
| 1708 | name: "myapex_keytest", |
| 1709 | key: "myapex.key", |
| 1710 | file_contexts: ":myapex-file_contexts", |
| 1711 | certificate: ":myapex.certificate", |
| 1712 | } |
| 1713 | apex_key { |
| 1714 | name: "myapex.key", |
| 1715 | public_key: "testkey.avbpubkey", |
| 1716 | private_key: "testkey.pem", |
| 1717 | } |
| 1718 | android_app_certificate { |
| 1719 | name: "myapex.certificate.override", |
| 1720 | certificate: "testkey.override", |
| 1721 | }`) |
| 1722 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1723 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1724 | if actual := rule.Args["certificates"]; actual != expected { |
| 1725 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1726 | } |
| 1727 | }) |
| 1728 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
| 1729 | ctx, _ := testApex(t, ` |
| 1730 | apex { |
| 1731 | name: "myapex", |
| 1732 | key: "myapex.key", |
| 1733 | certificate: "testkey", |
| 1734 | } |
| 1735 | apex_key { |
| 1736 | name: "myapex.key", |
| 1737 | public_key: "testkey.avbpubkey", |
| 1738 | private_key: "testkey.pem", |
| 1739 | }`) |
| 1740 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 1741 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 1742 | if actual := rule.Args["certificates"]; actual != expected { |
| 1743 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1744 | } |
| 1745 | }) |
| 1746 | t.Run("override when specified as <name>", func(t *testing.T) { |
| 1747 | ctx, _ := testApex(t, ` |
| 1748 | apex { |
| 1749 | name: "myapex_keytest", |
| 1750 | key: "myapex.key", |
| 1751 | file_contexts: ":myapex-file_contexts", |
| 1752 | certificate: "testkey", |
| 1753 | } |
| 1754 | apex_key { |
| 1755 | name: "myapex.key", |
| 1756 | public_key: "testkey.avbpubkey", |
| 1757 | private_key: "testkey.pem", |
| 1758 | } |
| 1759 | android_app_certificate { |
| 1760 | name: "myapex.certificate.override", |
| 1761 | certificate: "testkey.override", |
| 1762 | }`) |
| 1763 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 1764 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 1765 | if actual := rule.Args["certificates"]; actual != expected { |
| 1766 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 1767 | } |
| 1768 | }) |
| 1769 | } |
| 1770 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1771 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1772 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1773 | apex { |
| 1774 | name: "myapex", |
| 1775 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1776 | native_shared_libs: ["mylib", "mylib2"], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | apex { |
| 1780 | name: "otherapex", |
| 1781 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1782 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1783 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | apex_key { |
| 1787 | name: "myapex.key", |
| 1788 | public_key: "testkey.avbpubkey", |
| 1789 | private_key: "testkey.pem", |
| 1790 | } |
| 1791 | |
| 1792 | cc_library { |
| 1793 | name: "mylib", |
| 1794 | srcs: ["mylib.cpp"], |
| 1795 | system_shared_libs: [], |
| 1796 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1797 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1798 | "myapex", |
| 1799 | "otherapex", |
| 1800 | ], |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1801 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1802 | cc_library { |
| 1803 | name: "mylib2", |
| 1804 | srcs: ["mylib.cpp"], |
| 1805 | system_shared_libs: [], |
| 1806 | stl: "none", |
| 1807 | apex_available: [ |
| 1808 | "myapex", |
| 1809 | "otherapex", |
| 1810 | ], |
| 1811 | use_apex_name_macro: true, |
| 1812 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1813 | `) |
| 1814 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1815 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1816 | 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] | 1817 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1818 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1819 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1820 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1821 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 1822 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1823 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1824 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1825 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1826 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1827 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 1828 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1829 | ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1830 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1831 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1832 | // When cc_library sets use_apex_name_macro: true |
| 1833 | // apex variants define additional macro to distinguish which apex variant it is built for |
| 1834 | |
| 1835 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 1836 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1837 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 1838 | |
| 1839 | // APEX variant has __ANDROID_APEX__ defined |
| 1840 | 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] | 1841 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1842 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1843 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1844 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 1845 | // APEX variant has __ANDROID_APEX__ defined |
| 1846 | 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] | 1847 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 1848 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 1849 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1850 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1851 | |
| 1852 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1853 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1854 | apex { |
| 1855 | name: "myapex", |
| 1856 | key: "myapex.key", |
| 1857 | native_shared_libs: ["mylib"], |
| 1858 | } |
| 1859 | |
| 1860 | apex_key { |
| 1861 | name: "myapex.key", |
| 1862 | public_key: "testkey.avbpubkey", |
| 1863 | private_key: "testkey.pem", |
| 1864 | } |
| 1865 | |
| 1866 | cc_library_headers { |
| 1867 | name: "mylib_headers", |
| 1868 | export_include_dirs: ["my_include"], |
| 1869 | system_shared_libs: [], |
| 1870 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 1871 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | cc_library { |
| 1875 | name: "mylib", |
| 1876 | srcs: ["mylib.cpp"], |
| 1877 | system_shared_libs: [], |
| 1878 | stl: "none", |
| 1879 | header_libs: ["mylib_headers"], |
| 1880 | export_header_lib_headers: ["mylib_headers"], |
| 1881 | stubs: { |
| 1882 | versions: ["1", "2", "3"], |
| 1883 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1884 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | cc_library { |
| 1888 | name: "otherlib", |
| 1889 | srcs: ["mylib.cpp"], |
| 1890 | system_shared_libs: [], |
| 1891 | stl: "none", |
| 1892 | shared_libs: ["mylib"], |
| 1893 | } |
| 1894 | `) |
| 1895 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1896 | 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] | 1897 | |
| 1898 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 1899 | ensureContains(t, cFlags, "-Imy_include") |
| 1900 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1901 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1902 | type fileInApex struct { |
| 1903 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1904 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1905 | isLink bool |
| 1906 | } |
| 1907 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1908 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1909 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1910 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1911 | copyCmds := apexRule.Args["copy_commands"] |
| 1912 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1913 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1914 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 1915 | cmd = strings.TrimSpace(cmd) |
| 1916 | if cmd == "" { |
| 1917 | continue |
| 1918 | } |
| 1919 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1920 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1921 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1922 | switch terms[0] { |
| 1923 | case "mkdir": |
| 1924 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1925 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1926 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 1927 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1928 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1929 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1930 | isLink = false |
| 1931 | case "ln": |
| 1932 | if len(terms) != 3 && len(terms) != 4 { |
| 1933 | // ln LINK TARGET or ln -s LINK TARGET |
| 1934 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 1935 | } |
| 1936 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1937 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1938 | isLink = true |
| 1939 | default: |
| 1940 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 1941 | } |
| 1942 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1943 | index := strings.Index(dst, imageApexDir) |
| 1944 | if index == -1 { |
| 1945 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 1946 | } |
| 1947 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1948 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1949 | } |
| 1950 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1951 | return ret |
| 1952 | } |
| 1953 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1954 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 1955 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1956 | var failed bool |
| 1957 | var surplus []string |
| 1958 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 1959 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 1960 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1961 | for _, expected := range files { |
| 1962 | if matched, _ := path.Match(expected, file.path); matched { |
| 1963 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 1964 | mactchFound = true |
| 1965 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1966 | } |
| 1967 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 1968 | if !mactchFound { |
| 1969 | surplus = append(surplus, file.path) |
| 1970 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 1971 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1972 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1973 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1974 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1975 | t.Log("surplus files", surplus) |
| 1976 | failed = true |
| 1977 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 1978 | |
| 1979 | if len(files) > len(filesMatched) { |
| 1980 | var missing []string |
| 1981 | for _, expected := range files { |
| 1982 | if !filesMatched[expected] { |
| 1983 | missing = append(missing, expected) |
| 1984 | } |
| 1985 | } |
| 1986 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 1987 | t.Log("missing files", missing) |
| 1988 | failed = true |
| 1989 | } |
| 1990 | if failed { |
| 1991 | t.Fail() |
| 1992 | } |
| 1993 | } |
| 1994 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 1995 | func TestVndkApexCurrent(t *testing.T) { |
| 1996 | ctx, _ := testApex(t, ` |
| 1997 | apex_vndk { |
| 1998 | name: "myapex", |
| 1999 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | apex_key { |
| 2003 | name: "myapex.key", |
| 2004 | public_key: "testkey.avbpubkey", |
| 2005 | private_key: "testkey.pem", |
| 2006 | } |
| 2007 | |
| 2008 | cc_library { |
| 2009 | name: "libvndk", |
| 2010 | srcs: ["mylib.cpp"], |
| 2011 | vendor_available: true, |
| 2012 | vndk: { |
| 2013 | enabled: true, |
| 2014 | }, |
| 2015 | system_shared_libs: [], |
| 2016 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2017 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | cc_library { |
| 2021 | name: "libvndksp", |
| 2022 | srcs: ["mylib.cpp"], |
| 2023 | vendor_available: true, |
| 2024 | vndk: { |
| 2025 | enabled: true, |
| 2026 | support_system_process: true, |
| 2027 | }, |
| 2028 | system_shared_libs: [], |
| 2029 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2030 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2031 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2032 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2033 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2034 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2035 | "lib/libvndk.so", |
| 2036 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2037 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2038 | "lib64/libvndk.so", |
| 2039 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2040 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2041 | "etc/llndk.libraries.VER.txt", |
| 2042 | "etc/vndkcore.libraries.VER.txt", |
| 2043 | "etc/vndksp.libraries.VER.txt", |
| 2044 | "etc/vndkprivate.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2045 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | func TestVndkApexWithPrebuilt(t *testing.T) { |
| 2049 | ctx, _ := testApex(t, ` |
| 2050 | apex_vndk { |
| 2051 | name: "myapex", |
| 2052 | key: "myapex.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | apex_key { |
| 2056 | name: "myapex.key", |
| 2057 | public_key: "testkey.avbpubkey", |
| 2058 | private_key: "testkey.pem", |
| 2059 | } |
| 2060 | |
| 2061 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2062 | name: "libvndk", |
| 2063 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2064 | vendor_available: true, |
| 2065 | vndk: { |
| 2066 | enabled: true, |
| 2067 | }, |
| 2068 | system_shared_libs: [], |
| 2069 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2070 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2071 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2072 | |
| 2073 | cc_prebuilt_library_shared { |
| 2074 | name: "libvndk.arm", |
| 2075 | srcs: ["libvndk.arm.so"], |
| 2076 | vendor_available: true, |
| 2077 | vndk: { |
| 2078 | enabled: true, |
| 2079 | }, |
| 2080 | enabled: false, |
| 2081 | arch: { |
| 2082 | arm: { |
| 2083 | enabled: true, |
| 2084 | }, |
| 2085 | }, |
| 2086 | system_shared_libs: [], |
| 2087 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2088 | apex_available: [ "myapex" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2089 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2090 | `+vndkLibrariesTxtFiles("current"), |
| 2091 | withFiles(map[string][]byte{ |
| 2092 | "libvndk.so": nil, |
| 2093 | "libvndk.arm.so": nil, |
| 2094 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2095 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2096 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2097 | "lib/libvndk.so", |
| 2098 | "lib/libvndk.arm.so", |
| 2099 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2100 | "lib/libc++.so", |
| 2101 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2102 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2103 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2104 | } |
| 2105 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2106 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 2107 | for _, v := range vers { |
| 2108 | if v == "current" { |
Kiyoung Kim | e1aa8ea | 2019-12-30 11:12:55 +0900 | [diff] [blame] | 2109 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2110 | result += ` |
| 2111 | vndk_libraries_txt { |
| 2112 | name: "` + txt + `.libraries.txt", |
| 2113 | } |
| 2114 | ` |
| 2115 | } |
| 2116 | } else { |
| 2117 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} { |
| 2118 | result += ` |
| 2119 | prebuilt_etc { |
| 2120 | name: "` + txt + `.libraries.` + v + `.txt", |
| 2121 | src: "dummy.txt", |
| 2122 | } |
| 2123 | ` |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | return |
| 2128 | } |
| 2129 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2130 | func TestVndkApexVersion(t *testing.T) { |
| 2131 | ctx, _ := testApex(t, ` |
| 2132 | apex_vndk { |
| 2133 | name: "myapex_v27", |
| 2134 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2135 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2136 | vndk_version: "27", |
| 2137 | } |
| 2138 | |
| 2139 | apex_key { |
| 2140 | name: "myapex.key", |
| 2141 | public_key: "testkey.avbpubkey", |
| 2142 | private_key: "testkey.pem", |
| 2143 | } |
| 2144 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2145 | vndk_prebuilt_shared { |
| 2146 | name: "libvndk27", |
| 2147 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2148 | vendor_available: true, |
| 2149 | vndk: { |
| 2150 | enabled: true, |
| 2151 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2152 | target_arch: "arm64", |
| 2153 | arch: { |
| 2154 | arm: { |
| 2155 | srcs: ["libvndk27_arm.so"], |
| 2156 | }, |
| 2157 | arm64: { |
| 2158 | srcs: ["libvndk27_arm64.so"], |
| 2159 | }, |
| 2160 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2161 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | vndk_prebuilt_shared { |
| 2165 | name: "libvndk27", |
| 2166 | version: "27", |
| 2167 | vendor_available: true, |
| 2168 | vndk: { |
| 2169 | enabled: true, |
| 2170 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2171 | target_arch: "x86_64", |
| 2172 | arch: { |
| 2173 | x86: { |
| 2174 | srcs: ["libvndk27_x86.so"], |
| 2175 | }, |
| 2176 | x86_64: { |
| 2177 | srcs: ["libvndk27_x86_64.so"], |
| 2178 | }, |
| 2179 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2180 | } |
| 2181 | `+vndkLibrariesTxtFiles("27"), |
| 2182 | withFiles(map[string][]byte{ |
| 2183 | "libvndk27_arm.so": nil, |
| 2184 | "libvndk27_arm64.so": nil, |
| 2185 | "libvndk27_x86.so": nil, |
| 2186 | "libvndk27_x86_64.so": nil, |
| 2187 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2188 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2189 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2190 | "lib/libvndk27_arm.so", |
| 2191 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2192 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2193 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { |
| 2197 | testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, ` |
| 2198 | apex_vndk { |
| 2199 | name: "myapex_v27", |
| 2200 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2201 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2202 | vndk_version: "27", |
| 2203 | } |
| 2204 | apex_vndk { |
| 2205 | name: "myapex_v27_other", |
| 2206 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2207 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2208 | vndk_version: "27", |
| 2209 | } |
| 2210 | |
| 2211 | apex_key { |
| 2212 | name: "myapex.key", |
| 2213 | public_key: "testkey.avbpubkey", |
| 2214 | private_key: "testkey.pem", |
| 2215 | } |
| 2216 | |
| 2217 | cc_library { |
| 2218 | name: "libvndk", |
| 2219 | srcs: ["mylib.cpp"], |
| 2220 | vendor_available: true, |
| 2221 | vndk: { |
| 2222 | enabled: true, |
| 2223 | }, |
| 2224 | system_shared_libs: [], |
| 2225 | stl: "none", |
| 2226 | } |
| 2227 | |
| 2228 | vndk_prebuilt_shared { |
| 2229 | name: "libvndk", |
| 2230 | version: "27", |
| 2231 | vendor_available: true, |
| 2232 | vndk: { |
| 2233 | enabled: true, |
| 2234 | }, |
| 2235 | srcs: ["libvndk.so"], |
| 2236 | } |
| 2237 | `, withFiles(map[string][]byte{ |
| 2238 | "libvndk.so": nil, |
| 2239 | })) |
| 2240 | } |
| 2241 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2242 | func TestVndkApexNameRule(t *testing.T) { |
| 2243 | ctx, _ := testApex(t, ` |
| 2244 | apex_vndk { |
| 2245 | name: "myapex", |
| 2246 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2247 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2248 | } |
| 2249 | apex_vndk { |
| 2250 | name: "myapex_v28", |
| 2251 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2252 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2253 | vndk_version: "28", |
| 2254 | } |
| 2255 | apex_key { |
| 2256 | name: "myapex.key", |
| 2257 | public_key: "testkey.avbpubkey", |
| 2258 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2259 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2260 | |
| 2261 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2262 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 2263 | actual := proptools.String(bundle.properties.Apex_name) |
| 2264 | if !reflect.DeepEqual(actual, expected) { |
| 2265 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | assertApexName("com.android.vndk.vVER", "myapex") |
| 2270 | assertApexName("com.android.vndk.v28", "myapex_v28") |
| 2271 | } |
| 2272 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2273 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
| 2274 | ctx, _ := testApex(t, ` |
| 2275 | apex_vndk { |
| 2276 | name: "myapex", |
| 2277 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2278 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | apex_key { |
| 2282 | name: "myapex.key", |
| 2283 | public_key: "testkey.avbpubkey", |
| 2284 | private_key: "testkey.pem", |
| 2285 | } |
| 2286 | |
| 2287 | cc_library { |
| 2288 | name: "libvndk", |
| 2289 | srcs: ["mylib.cpp"], |
| 2290 | vendor_available: true, |
| 2291 | native_bridge_supported: true, |
| 2292 | host_supported: true, |
| 2293 | vndk: { |
| 2294 | enabled: true, |
| 2295 | }, |
| 2296 | system_shared_libs: [], |
| 2297 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2298 | apex_available: [ "myapex" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2299 | } |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2300 | `+vndkLibrariesTxtFiles("current"), withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2301 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2302 | ensureExactContents(t, ctx, "myapex", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2303 | "lib/libvndk.so", |
| 2304 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 2305 | "lib/libc++.so", |
| 2306 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2307 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2308 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
| 2312 | testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
| 2313 | apex_vndk { |
| 2314 | name: "myapex", |
| 2315 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2316 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 2317 | native_bridge_supported: true, |
| 2318 | } |
| 2319 | |
| 2320 | apex_key { |
| 2321 | name: "myapex.key", |
| 2322 | public_key: "testkey.avbpubkey", |
| 2323 | private_key: "testkey.pem", |
| 2324 | } |
| 2325 | |
| 2326 | cc_library { |
| 2327 | name: "libvndk", |
| 2328 | srcs: ["mylib.cpp"], |
| 2329 | vendor_available: true, |
| 2330 | native_bridge_supported: true, |
| 2331 | host_supported: true, |
| 2332 | vndk: { |
| 2333 | enabled: true, |
| 2334 | }, |
| 2335 | system_shared_libs: [], |
| 2336 | stl: "none", |
| 2337 | } |
| 2338 | `) |
| 2339 | } |
| 2340 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2341 | func TestVndkApexWithBinder32(t *testing.T) { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2342 | ctx, _ := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2343 | apex_vndk { |
| 2344 | name: "myapex_v27", |
| 2345 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2346 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2347 | vndk_version: "27", |
| 2348 | } |
| 2349 | |
| 2350 | apex_key { |
| 2351 | name: "myapex.key", |
| 2352 | public_key: "testkey.avbpubkey", |
| 2353 | private_key: "testkey.pem", |
| 2354 | } |
| 2355 | |
| 2356 | vndk_prebuilt_shared { |
| 2357 | name: "libvndk27", |
| 2358 | version: "27", |
| 2359 | target_arch: "arm", |
| 2360 | vendor_available: true, |
| 2361 | vndk: { |
| 2362 | enabled: true, |
| 2363 | }, |
| 2364 | arch: { |
| 2365 | arm: { |
| 2366 | srcs: ["libvndk27.so"], |
| 2367 | } |
| 2368 | }, |
| 2369 | } |
| 2370 | |
| 2371 | vndk_prebuilt_shared { |
| 2372 | name: "libvndk27", |
| 2373 | version: "27", |
| 2374 | target_arch: "arm", |
| 2375 | binder32bit: true, |
| 2376 | vendor_available: true, |
| 2377 | vndk: { |
| 2378 | enabled: true, |
| 2379 | }, |
| 2380 | arch: { |
| 2381 | arm: { |
| 2382 | srcs: ["libvndk27binder32.so"], |
| 2383 | } |
| 2384 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2385 | apex_available: [ "myapex_v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2386 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2387 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2388 | withFiles(map[string][]byte{ |
| 2389 | "libvndk27.so": nil, |
| 2390 | "libvndk27binder32.so": nil, |
| 2391 | }), |
| 2392 | withBinder32bit, |
| 2393 | withTargets(map[android.OsType][]android.Target{ |
| 2394 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2395 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 2396 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2397 | }, |
| 2398 | }), |
| 2399 | ) |
| 2400 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 2401 | ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2402 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 2403 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 2404 | }) |
| 2405 | } |
| 2406 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2407 | func TestDependenciesInApexManifest(t *testing.T) { |
| 2408 | ctx, _ := testApex(t, ` |
| 2409 | apex { |
| 2410 | name: "myapex_nodep", |
| 2411 | key: "myapex.key", |
| 2412 | native_shared_libs: ["lib_nodep"], |
| 2413 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2414 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | apex { |
| 2418 | name: "myapex_dep", |
| 2419 | key: "myapex.key", |
| 2420 | native_shared_libs: ["lib_dep"], |
| 2421 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2422 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | apex { |
| 2426 | name: "myapex_provider", |
| 2427 | key: "myapex.key", |
| 2428 | native_shared_libs: ["libfoo"], |
| 2429 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2430 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | apex { |
| 2434 | name: "myapex_selfcontained", |
| 2435 | key: "myapex.key", |
| 2436 | native_shared_libs: ["lib_dep", "libfoo"], |
| 2437 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2438 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | apex_key { |
| 2442 | name: "myapex.key", |
| 2443 | public_key: "testkey.avbpubkey", |
| 2444 | private_key: "testkey.pem", |
| 2445 | } |
| 2446 | |
| 2447 | cc_library { |
| 2448 | name: "lib_nodep", |
| 2449 | srcs: ["mylib.cpp"], |
| 2450 | system_shared_libs: [], |
| 2451 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2452 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | cc_library { |
| 2456 | name: "lib_dep", |
| 2457 | srcs: ["mylib.cpp"], |
| 2458 | shared_libs: ["libfoo"], |
| 2459 | system_shared_libs: [], |
| 2460 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2461 | apex_available: [ |
| 2462 | "myapex_dep", |
| 2463 | "myapex_provider", |
| 2464 | "myapex_selfcontained", |
| 2465 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | cc_library { |
| 2469 | name: "libfoo", |
| 2470 | srcs: ["mytest.cpp"], |
| 2471 | stubs: { |
| 2472 | versions: ["1"], |
| 2473 | }, |
| 2474 | system_shared_libs: [], |
| 2475 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2476 | apex_available: [ |
| 2477 | "myapex_provider", |
| 2478 | "myapex_selfcontained", |
| 2479 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2480 | } |
| 2481 | `) |
| 2482 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2483 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2484 | var provideNativeLibs, requireNativeLibs []string |
| 2485 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2486 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2487 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2488 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2489 | ensureListEmpty(t, provideNativeLibs) |
| 2490 | ensureListEmpty(t, requireNativeLibs) |
| 2491 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2492 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2493 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2494 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2495 | ensureListEmpty(t, provideNativeLibs) |
| 2496 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 2497 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2498 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2499 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2500 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2501 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2502 | ensureListEmpty(t, requireNativeLibs) |
| 2503 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2504 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2505 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 2506 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 2507 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 2508 | ensureListEmpty(t, requireNativeLibs) |
| 2509 | } |
| 2510 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2511 | func TestApexName(t *testing.T) { |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2512 | ctx, config := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2513 | apex { |
| 2514 | name: "myapex", |
| 2515 | key: "myapex.key", |
| 2516 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2517 | native_shared_libs: ["mylib"], |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | apex_key { |
| 2521 | name: "myapex.key", |
| 2522 | public_key: "testkey.avbpubkey", |
| 2523 | private_key: "testkey.pem", |
| 2524 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2525 | |
| 2526 | cc_library { |
| 2527 | name: "mylib", |
| 2528 | srcs: ["mylib.cpp"], |
| 2529 | system_shared_libs: [], |
| 2530 | stl: "none", |
| 2531 | apex_available: [ |
| 2532 | "//apex_available:platform", |
| 2533 | "myapex", |
| 2534 | ], |
| 2535 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2536 | `) |
| 2537 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2538 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2539 | apexManifestRule := module.Rule("apexManifestRule") |
| 2540 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 2541 | apexRule := module.Rule("apexRule") |
| 2542 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 2543 | |
| 2544 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2545 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 2546 | name := apexBundle.BaseModuleName() |
| 2547 | prefix := "TARGET_" |
| 2548 | var builder strings.Builder |
| 2549 | data.Custom(&builder, name, prefix, "", data) |
| 2550 | androidMk := builder.String() |
| 2551 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 2552 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 2553 | } |
| 2554 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2555 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2556 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2557 | apex { |
| 2558 | name: "myapex", |
| 2559 | key: "myapex.key", |
| 2560 | native_shared_libs: ["mylib_common"], |
| 2561 | } |
| 2562 | |
| 2563 | apex_key { |
| 2564 | name: "myapex.key", |
| 2565 | public_key: "testkey.avbpubkey", |
| 2566 | private_key: "testkey.pem", |
| 2567 | } |
| 2568 | |
| 2569 | cc_library { |
| 2570 | name: "mylib_common", |
| 2571 | srcs: ["mylib.cpp"], |
| 2572 | system_shared_libs: [], |
| 2573 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2574 | apex_available: [ |
| 2575 | "//apex_available:platform", |
| 2576 | "myapex", |
| 2577 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2578 | } |
| 2579 | `) |
| 2580 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2581 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2582 | apexRule := module.Rule("apexRule") |
| 2583 | copyCmds := apexRule.Args["copy_commands"] |
| 2584 | |
| 2585 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 2586 | t.Log("Apex was a test apex!") |
| 2587 | t.Fail() |
| 2588 | } |
| 2589 | // Ensure that main rule creates an output |
| 2590 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2591 | |
| 2592 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2593 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2594 | |
| 2595 | // Ensure that both direct and indirect deps are copied into apex |
| 2596 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2597 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2598 | // Ensure that the platform variant ends with _shared |
| 2599 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2600 | |
| 2601 | if !android.InAnyApex("mylib_common") { |
| 2602 | t.Log("Found mylib_common not in any apex!") |
| 2603 | t.Fail() |
| 2604 | } |
| 2605 | } |
| 2606 | |
| 2607 | func TestTestApex(t *testing.T) { |
| 2608 | if android.InAnyApex("mylib_common_test") { |
| 2609 | 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!") |
| 2610 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2611 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2612 | apex_test { |
| 2613 | name: "myapex", |
| 2614 | key: "myapex.key", |
| 2615 | native_shared_libs: ["mylib_common_test"], |
| 2616 | } |
| 2617 | |
| 2618 | apex_key { |
| 2619 | name: "myapex.key", |
| 2620 | public_key: "testkey.avbpubkey", |
| 2621 | private_key: "testkey.pem", |
| 2622 | } |
| 2623 | |
| 2624 | cc_library { |
| 2625 | name: "mylib_common_test", |
| 2626 | srcs: ["mylib.cpp"], |
| 2627 | system_shared_libs: [], |
| 2628 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2629 | // TODO: remove //apex_available:platform |
| 2630 | apex_available: [ |
| 2631 | "//apex_available:platform", |
| 2632 | "myapex", |
| 2633 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2634 | } |
| 2635 | `) |
| 2636 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2637 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2638 | apexRule := module.Rule("apexRule") |
| 2639 | copyCmds := apexRule.Args["copy_commands"] |
| 2640 | |
| 2641 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 2642 | t.Log("Apex was not a test apex!") |
| 2643 | t.Fail() |
| 2644 | } |
| 2645 | // Ensure that main rule creates an output |
| 2646 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2647 | |
| 2648 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2649 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2650 | |
| 2651 | // Ensure that both direct and indirect deps are copied into apex |
| 2652 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 2653 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2654 | // Ensure that the platform variant ends with _shared |
| 2655 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 2656 | } |
| 2657 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2658 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2659 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2660 | apex { |
| 2661 | name: "myapex", |
| 2662 | key: "myapex.key", |
| 2663 | multilib: { |
| 2664 | first: { |
| 2665 | native_shared_libs: ["mylib_common"], |
| 2666 | } |
| 2667 | }, |
| 2668 | target: { |
| 2669 | android: { |
| 2670 | multilib: { |
| 2671 | first: { |
| 2672 | native_shared_libs: ["mylib"], |
| 2673 | } |
| 2674 | } |
| 2675 | }, |
| 2676 | host: { |
| 2677 | multilib: { |
| 2678 | first: { |
| 2679 | native_shared_libs: ["mylib2"], |
| 2680 | } |
| 2681 | } |
| 2682 | } |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | apex_key { |
| 2687 | name: "myapex.key", |
| 2688 | public_key: "testkey.avbpubkey", |
| 2689 | private_key: "testkey.pem", |
| 2690 | } |
| 2691 | |
| 2692 | cc_library { |
| 2693 | name: "mylib", |
| 2694 | srcs: ["mylib.cpp"], |
| 2695 | system_shared_libs: [], |
| 2696 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2697 | // TODO: remove //apex_available:platform |
| 2698 | apex_available: [ |
| 2699 | "//apex_available:platform", |
| 2700 | "myapex", |
| 2701 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | cc_library { |
| 2705 | name: "mylib_common", |
| 2706 | srcs: ["mylib.cpp"], |
| 2707 | system_shared_libs: [], |
| 2708 | stl: "none", |
| 2709 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2710 | // TODO: remove //apex_available:platform |
| 2711 | apex_available: [ |
| 2712 | "//apex_available:platform", |
| 2713 | "myapex", |
| 2714 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | cc_library { |
| 2718 | name: "mylib2", |
| 2719 | srcs: ["mylib.cpp"], |
| 2720 | system_shared_libs: [], |
| 2721 | stl: "none", |
| 2722 | compile_multilib: "first", |
| 2723 | } |
| 2724 | `) |
| 2725 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2726 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2727 | copyCmds := apexRule.Args["copy_commands"] |
| 2728 | |
| 2729 | // Ensure that main rule creates an output |
| 2730 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 2731 | |
| 2732 | // Ensure that apex variant is created for the direct dep |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2733 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 2734 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex") |
| 2735 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2736 | |
| 2737 | // Ensure that both direct and indirect deps are copied into apex |
| 2738 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 2739 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 2740 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 2741 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2742 | // Ensure that the platform variant ends with _shared |
| 2743 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 2744 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 2745 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 2746 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2747 | |
| 2748 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2749 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2750 | apex { |
| 2751 | name: "myapex", |
| 2752 | key: "myapex.key", |
| 2753 | binaries: ["myscript"], |
| 2754 | } |
| 2755 | |
| 2756 | apex_key { |
| 2757 | name: "myapex.key", |
| 2758 | public_key: "testkey.avbpubkey", |
| 2759 | private_key: "testkey.pem", |
| 2760 | } |
| 2761 | |
| 2762 | sh_binary { |
| 2763 | name: "myscript", |
| 2764 | src: "mylib.cpp", |
| 2765 | filename: "myscript.sh", |
| 2766 | sub_dir: "script", |
| 2767 | } |
| 2768 | `) |
| 2769 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2770 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 2771 | copyCmds := apexRule.Args["copy_commands"] |
| 2772 | |
| 2773 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 2774 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2775 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2776 | func TestApexInVariousPartition(t *testing.T) { |
| 2777 | testcases := []struct { |
| 2778 | propName, parition, flattenedPartition string |
| 2779 | }{ |
| 2780 | {"", "system", "system_ext"}, |
| 2781 | {"product_specific: true", "product", "product"}, |
| 2782 | {"soc_specific: true", "vendor", "vendor"}, |
| 2783 | {"proprietary: true", "vendor", "vendor"}, |
| 2784 | {"vendor: true", "vendor", "vendor"}, |
| 2785 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 2786 | } |
| 2787 | for _, tc := range testcases { |
| 2788 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
| 2789 | ctx, _ := testApex(t, ` |
| 2790 | apex { |
| 2791 | name: "myapex", |
| 2792 | key: "myapex.key", |
| 2793 | `+tc.propName+` |
| 2794 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2795 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2796 | apex_key { |
| 2797 | name: "myapex.key", |
| 2798 | public_key: "testkey.avbpubkey", |
| 2799 | private_key: "testkey.pem", |
| 2800 | } |
| 2801 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2802 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2803 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2804 | expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" |
| 2805 | actual := apex.installDir.String() |
| 2806 | if actual != expected { |
| 2807 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2808 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2809 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 2810 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 2811 | expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 2812 | actual = flattened.installDir.String() |
| 2813 | if actual != expected { |
| 2814 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 2815 | } |
| 2816 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2817 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2818 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2819 | |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2820 | func TestFileContexts(t *testing.T) { |
| 2821 | ctx, _ := testApex(t, ` |
| 2822 | apex { |
| 2823 | name: "myapex", |
| 2824 | key: "myapex.key", |
| 2825 | } |
| 2826 | |
| 2827 | apex_key { |
| 2828 | name: "myapex.key", |
| 2829 | public_key: "testkey.avbpubkey", |
| 2830 | private_key: "testkey.pem", |
| 2831 | } |
| 2832 | `) |
| 2833 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2834 | apexRule := module.Rule("apexRule") |
| 2835 | actual := apexRule.Args["file_contexts"] |
| 2836 | expected := "system/sepolicy/apex/myapex-file_contexts" |
| 2837 | if actual != expected { |
| 2838 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2839 | } |
| 2840 | |
| 2841 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
| 2842 | apex { |
| 2843 | name: "myapex", |
| 2844 | key: "myapex.key", |
| 2845 | file_contexts: "my_own_file_contexts", |
| 2846 | } |
| 2847 | |
| 2848 | apex_key { |
| 2849 | name: "myapex.key", |
| 2850 | public_key: "testkey.avbpubkey", |
| 2851 | private_key: "testkey.pem", |
| 2852 | } |
| 2853 | `, withFiles(map[string][]byte{ |
| 2854 | "my_own_file_contexts": nil, |
| 2855 | })) |
| 2856 | |
| 2857 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
| 2858 | apex { |
| 2859 | name: "myapex", |
| 2860 | key: "myapex.key", |
| 2861 | product_specific: true, |
| 2862 | file_contexts: "product_specific_file_contexts", |
| 2863 | } |
| 2864 | |
| 2865 | apex_key { |
| 2866 | name: "myapex.key", |
| 2867 | public_key: "testkey.avbpubkey", |
| 2868 | private_key: "testkey.pem", |
| 2869 | } |
| 2870 | `) |
| 2871 | |
| 2872 | ctx, _ = testApex(t, ` |
| 2873 | apex { |
| 2874 | name: "myapex", |
| 2875 | key: "myapex.key", |
| 2876 | product_specific: true, |
| 2877 | file_contexts: "product_specific_file_contexts", |
| 2878 | } |
| 2879 | |
| 2880 | apex_key { |
| 2881 | name: "myapex.key", |
| 2882 | public_key: "testkey.avbpubkey", |
| 2883 | private_key: "testkey.pem", |
| 2884 | } |
| 2885 | `, withFiles(map[string][]byte{ |
| 2886 | "product_specific_file_contexts": nil, |
| 2887 | })) |
| 2888 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2889 | apexRule = module.Rule("apexRule") |
| 2890 | actual = apexRule.Args["file_contexts"] |
| 2891 | expected = "product_specific_file_contexts" |
| 2892 | if actual != expected { |
| 2893 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2894 | } |
| 2895 | |
| 2896 | ctx, _ = testApex(t, ` |
| 2897 | apex { |
| 2898 | name: "myapex", |
| 2899 | key: "myapex.key", |
| 2900 | product_specific: true, |
| 2901 | file_contexts: ":my-file-contexts", |
| 2902 | } |
| 2903 | |
| 2904 | apex_key { |
| 2905 | name: "myapex.key", |
| 2906 | public_key: "testkey.avbpubkey", |
| 2907 | private_key: "testkey.pem", |
| 2908 | } |
| 2909 | |
| 2910 | filegroup { |
| 2911 | name: "my-file-contexts", |
| 2912 | srcs: ["product_specific_file_contexts"], |
| 2913 | } |
| 2914 | `, withFiles(map[string][]byte{ |
| 2915 | "product_specific_file_contexts": nil, |
| 2916 | })) |
| 2917 | module = ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 2918 | apexRule = module.Rule("apexRule") |
| 2919 | actual = apexRule.Args["file_contexts"] |
| 2920 | expected = "product_specific_file_contexts" |
| 2921 | if actual != expected { |
| 2922 | t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) |
| 2923 | } |
| 2924 | } |
| 2925 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2926 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2927 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 2928 | apex_key { |
| 2929 | name: "myapex.key", |
| 2930 | public_key: ":my.avbpubkey", |
| 2931 | private_key: ":my.pem", |
| 2932 | product_specific: true, |
| 2933 | } |
| 2934 | |
| 2935 | filegroup { |
| 2936 | name: "my.avbpubkey", |
| 2937 | srcs: ["testkey2.avbpubkey"], |
| 2938 | } |
| 2939 | |
| 2940 | filegroup { |
| 2941 | name: "my.pem", |
| 2942 | srcs: ["testkey2.pem"], |
| 2943 | } |
| 2944 | `) |
| 2945 | |
| 2946 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 2947 | expected_pubkey := "testkey2.avbpubkey" |
| 2948 | actual_pubkey := apex_key.public_key_file.String() |
| 2949 | if actual_pubkey != expected_pubkey { |
| 2950 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 2951 | } |
| 2952 | expected_privkey := "testkey2.pem" |
| 2953 | actual_privkey := apex_key.private_key_file.String() |
| 2954 | if actual_privkey != expected_privkey { |
| 2955 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 2956 | } |
| 2957 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2958 | |
| 2959 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2960 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2961 | prebuilt_apex { |
| 2962 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2963 | arch: { |
| 2964 | arm64: { |
| 2965 | src: "myapex-arm64.apex", |
| 2966 | }, |
| 2967 | arm: { |
| 2968 | src: "myapex-arm.apex", |
| 2969 | }, |
| 2970 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2971 | } |
| 2972 | `) |
| 2973 | |
| 2974 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 2975 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 2976 | expectedInput := "myapex-arm64.apex" |
| 2977 | if prebuilt.inputApex.String() != expectedInput { |
| 2978 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 2979 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 2980 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2981 | |
| 2982 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2983 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 2984 | prebuilt_apex { |
| 2985 | name: "myapex", |
| 2986 | src: "myapex-arm.apex", |
| 2987 | filename: "notmyapex.apex", |
| 2988 | } |
| 2989 | `) |
| 2990 | |
| 2991 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 2992 | |
| 2993 | expected := "notmyapex.apex" |
| 2994 | if p.installFilename != expected { |
| 2995 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 2996 | } |
| 2997 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 2998 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 2999 | func TestPrebuiltOverrides(t *testing.T) { |
| 3000 | ctx, config := testApex(t, ` |
| 3001 | prebuilt_apex { |
| 3002 | name: "myapex.prebuilt", |
| 3003 | src: "myapex-arm.apex", |
| 3004 | overrides: [ |
| 3005 | "myapex", |
| 3006 | ], |
| 3007 | } |
| 3008 | `) |
| 3009 | |
| 3010 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 3011 | |
| 3012 | expected := []string{"myapex"} |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 3013 | actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3014 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 3015 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3016 | } |
| 3017 | } |
| 3018 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3019 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3020 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3021 | apex_test { |
| 3022 | name: "myapex", |
| 3023 | key: "myapex.key", |
| 3024 | tests: [ |
| 3025 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3026 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3027 | ], |
| 3028 | } |
| 3029 | |
| 3030 | apex_key { |
| 3031 | name: "myapex.key", |
| 3032 | public_key: "testkey.avbpubkey", |
| 3033 | private_key: "testkey.pem", |
| 3034 | } |
| 3035 | |
| 3036 | cc_test { |
| 3037 | name: "mytest", |
| 3038 | gtest: false, |
| 3039 | srcs: ["mytest.cpp"], |
| 3040 | relative_install_path: "test", |
| 3041 | system_shared_libs: [], |
| 3042 | static_executable: true, |
| 3043 | stl: "none", |
| 3044 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3045 | |
| 3046 | cc_test { |
| 3047 | name: "mytests", |
| 3048 | gtest: false, |
| 3049 | srcs: [ |
| 3050 | "mytest1.cpp", |
| 3051 | "mytest2.cpp", |
| 3052 | "mytest3.cpp", |
| 3053 | ], |
| 3054 | test_per_src: true, |
| 3055 | relative_install_path: "test", |
| 3056 | system_shared_libs: [], |
| 3057 | static_executable: true, |
| 3058 | stl: "none", |
| 3059 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3060 | `) |
| 3061 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3062 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3063 | copyCmds := apexRule.Args["copy_commands"] |
| 3064 | |
| 3065 | // Ensure that test dep is copied into apex. |
| 3066 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 3067 | |
| 3068 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 3069 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 3070 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 3071 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3072 | |
| 3073 | // Ensure the module is correctly translated. |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3074 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3075 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3076 | name := apexBundle.BaseModuleName() |
| 3077 | prefix := "TARGET_" |
| 3078 | var builder strings.Builder |
| 3079 | data.Custom(&builder, name, prefix, "", data) |
| 3080 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3081 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 3082 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 3083 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 3084 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3085 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3086 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3087 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3090 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
| 3091 | ctx, config := testApex(t, ` |
| 3092 | apex { |
| 3093 | name: "myapex", |
| 3094 | key: "myapex.key", |
| 3095 | } |
| 3096 | apex_key { |
| 3097 | name: "myapex.key", |
| 3098 | public_key: "testkey.avbpubkey", |
| 3099 | private_key: "testkey.pem", |
| 3100 | } |
| 3101 | `, func(fs map[string][]byte, config android.Config) { |
| 3102 | config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 3103 | }) |
| 3104 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 3105 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 3106 | mk := android.AndroidMkDataForTest(t, config, "", ab) |
| 3107 | var builder strings.Builder |
| 3108 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 3109 | androidMk := builder.String() |
| 3110 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 3111 | } |
| 3112 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3113 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 3114 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3115 | apex { |
| 3116 | name: "myapex", |
| 3117 | key: "myapex.key", |
| 3118 | native_shared_libs: ["mylib"], |
| 3119 | uses: ["commonapex"], |
| 3120 | } |
| 3121 | |
| 3122 | apex { |
| 3123 | name: "commonapex", |
| 3124 | key: "myapex.key", |
| 3125 | native_shared_libs: ["libcommon"], |
| 3126 | provide_cpp_shared_libs: true, |
| 3127 | } |
| 3128 | |
| 3129 | apex_key { |
| 3130 | name: "myapex.key", |
| 3131 | public_key: "testkey.avbpubkey", |
| 3132 | private_key: "testkey.pem", |
| 3133 | } |
| 3134 | |
| 3135 | cc_library { |
| 3136 | name: "mylib", |
| 3137 | srcs: ["mylib.cpp"], |
| 3138 | shared_libs: ["libcommon"], |
| 3139 | system_shared_libs: [], |
| 3140 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3141 | apex_available: [ "myapex" ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | cc_library { |
| 3145 | name: "libcommon", |
| 3146 | srcs: ["mylib_common.cpp"], |
| 3147 | system_shared_libs: [], |
| 3148 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3149 | // TODO: remove //apex_available:platform |
| 3150 | apex_available: [ |
| 3151 | "//apex_available:platform", |
| 3152 | "commonapex", |
| 3153 | "myapex", |
| 3154 | ], |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3155 | } |
| 3156 | `) |
| 3157 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3158 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3159 | apexRule1 := module1.Rule("apexRule") |
| 3160 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 3161 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3162 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3163 | apexRule2 := module2.Rule("apexRule") |
| 3164 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 3165 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3166 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex") |
| 3167 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex") |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3168 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 3169 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 3170 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 3171 | } |
| 3172 | |
| 3173 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 3174 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 3175 | apex { |
| 3176 | name: "myapex", |
| 3177 | key: "myapex.key", |
| 3178 | uses: ["commonapex"], |
| 3179 | } |
| 3180 | |
| 3181 | apex { |
| 3182 | name: "commonapex", |
| 3183 | key: "myapex.key", |
| 3184 | } |
| 3185 | |
| 3186 | apex_key { |
| 3187 | name: "myapex.key", |
| 3188 | public_key: "testkey.avbpubkey", |
| 3189 | private_key: "testkey.pem", |
| 3190 | } |
| 3191 | `) |
| 3192 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 3193 | apex { |
| 3194 | name: "myapex", |
| 3195 | key: "myapex.key", |
| 3196 | uses: ["commonapex"], |
| 3197 | } |
| 3198 | |
| 3199 | cc_library { |
| 3200 | name: "commonapex", |
| 3201 | system_shared_libs: [], |
| 3202 | stl: "none", |
| 3203 | } |
| 3204 | |
| 3205 | apex_key { |
| 3206 | name: "myapex.key", |
| 3207 | public_key: "testkey.avbpubkey", |
| 3208 | private_key: "testkey.pem", |
| 3209 | } |
| 3210 | `) |
| 3211 | } |
| 3212 | |
| 3213 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 3214 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 3215 | apex { |
| 3216 | name: "myapex", |
| 3217 | key: "myapex.key", |
| 3218 | use_vendor: true, |
| 3219 | uses: ["commonapex"], |
| 3220 | } |
| 3221 | |
| 3222 | apex { |
| 3223 | name: "commonapex", |
| 3224 | key: "myapex.key", |
| 3225 | provide_cpp_shared_libs: true, |
| 3226 | } |
| 3227 | |
| 3228 | apex_key { |
| 3229 | name: "myapex.key", |
| 3230 | public_key: "testkey.avbpubkey", |
| 3231 | private_key: "testkey.pem", |
| 3232 | } |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 3233 | `, func(fs map[string][]byte, config android.Config) { |
| 3234 | setUseVendorWhitelistForTest(config, []string{"myapex"}) |
| 3235 | }) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 3236 | } |
| 3237 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3238 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 3239 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 3240 | apex { |
| 3241 | name: "myapex", |
| 3242 | key: "myapex.key", |
| 3243 | native_shared_libs: ["libfoo"], |
| 3244 | } |
| 3245 | |
| 3246 | apex_key { |
| 3247 | name: "myapex.key", |
| 3248 | public_key: "testkey.avbpubkey", |
| 3249 | private_key: "testkey.pem", |
| 3250 | } |
| 3251 | |
| 3252 | cc_library { |
| 3253 | name: "libfoo", |
| 3254 | stl: "none", |
| 3255 | system_shared_libs: [], |
| 3256 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3257 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3258 | } |
| 3259 | `) |
| 3260 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 3261 | apex { |
| 3262 | name: "myapex", |
| 3263 | key: "myapex.key", |
| 3264 | java_libs: ["myjar"], |
| 3265 | } |
| 3266 | |
| 3267 | apex_key { |
| 3268 | name: "myapex.key", |
| 3269 | public_key: "testkey.avbpubkey", |
| 3270 | private_key: "testkey.pem", |
| 3271 | } |
| 3272 | |
| 3273 | java_library { |
| 3274 | name: "myjar", |
| 3275 | srcs: ["foo/bar/MyClass.java"], |
| 3276 | sdk_version: "none", |
| 3277 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3278 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3279 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 3280 | } |
| 3281 | `) |
| 3282 | } |
| 3283 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3284 | func TestApexWithApps(t *testing.T) { |
| 3285 | ctx, _ := testApex(t, ` |
| 3286 | apex { |
| 3287 | name: "myapex", |
| 3288 | key: "myapex.key", |
| 3289 | apps: [ |
| 3290 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3291 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3292 | ], |
| 3293 | } |
| 3294 | |
| 3295 | apex_key { |
| 3296 | name: "myapex.key", |
| 3297 | public_key: "testkey.avbpubkey", |
| 3298 | private_key: "testkey.pem", |
| 3299 | } |
| 3300 | |
| 3301 | android_app { |
| 3302 | name: "AppFoo", |
| 3303 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3304 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3305 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3306 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3307 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3308 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3309 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3310 | |
| 3311 | android_app { |
| 3312 | name: "AppFooPriv", |
| 3313 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3314 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3315 | system_modules: "none", |
| 3316 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3317 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3318 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3319 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3320 | |
| 3321 | cc_library_shared { |
| 3322 | name: "libjni", |
| 3323 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3324 | shared_libs: ["libfoo"], |
| 3325 | stl: "none", |
| 3326 | system_shared_libs: [], |
| 3327 | apex_available: [ "myapex" ], |
| 3328 | sdk_version: "current", |
| 3329 | } |
| 3330 | |
| 3331 | cc_library_shared { |
| 3332 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3333 | stl: "none", |
| 3334 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3335 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 3336 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 3337 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3338 | `) |
| 3339 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3340 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3341 | apexRule := module.Rule("apexRule") |
| 3342 | copyCmds := apexRule.Args["copy_commands"] |
| 3343 | |
| 3344 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 3345 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3346 | |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3347 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Description("zip jni libs") |
| 3348 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3349 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3350 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 3351 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 3352 | // JNI libraries including transitive deps are |
| 3353 | for _, jni := range []string{"libjni", "libfoo"} { |
| 3354 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile() |
| 3355 | // ... embedded inside APK (jnilibs.zip) |
| 3356 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 3357 | // ... and not directly inside the APEX |
| 3358 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 3359 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3360 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3361 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3362 | func TestApexWithAppImports(t *testing.T) { |
| 3363 | ctx, _ := testApex(t, ` |
| 3364 | apex { |
| 3365 | name: "myapex", |
| 3366 | key: "myapex.key", |
| 3367 | apps: [ |
| 3368 | "AppFooPrebuilt", |
| 3369 | "AppFooPrivPrebuilt", |
| 3370 | ], |
| 3371 | } |
| 3372 | |
| 3373 | apex_key { |
| 3374 | name: "myapex.key", |
| 3375 | public_key: "testkey.avbpubkey", |
| 3376 | private_key: "testkey.pem", |
| 3377 | } |
| 3378 | |
| 3379 | android_app_import { |
| 3380 | name: "AppFooPrebuilt", |
| 3381 | apk: "PrebuiltAppFoo.apk", |
| 3382 | presigned: true, |
| 3383 | dex_preopt: { |
| 3384 | enabled: false, |
| 3385 | }, |
| 3386 | } |
| 3387 | |
| 3388 | android_app_import { |
| 3389 | name: "AppFooPrivPrebuilt", |
| 3390 | apk: "PrebuiltAppFooPriv.apk", |
| 3391 | privileged: true, |
| 3392 | presigned: true, |
| 3393 | dex_preopt: { |
| 3394 | enabled: false, |
| 3395 | }, |
| 3396 | } |
| 3397 | `) |
| 3398 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3399 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 3400 | apexRule := module.Rule("apexRule") |
| 3401 | copyCmds := apexRule.Args["copy_commands"] |
| 3402 | |
| 3403 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
| 3404 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 3405 | } |
| 3406 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3407 | func TestApexWithTestHelperApp(t *testing.T) { |
| 3408 | ctx, _ := testApex(t, ` |
| 3409 | apex { |
| 3410 | name: "myapex", |
| 3411 | key: "myapex.key", |
| 3412 | apps: [ |
| 3413 | "TesterHelpAppFoo", |
| 3414 | ], |
| 3415 | } |
| 3416 | |
| 3417 | apex_key { |
| 3418 | name: "myapex.key", |
| 3419 | public_key: "testkey.avbpubkey", |
| 3420 | private_key: "testkey.pem", |
| 3421 | } |
| 3422 | |
| 3423 | android_test_helper_app { |
| 3424 | name: "TesterHelpAppFoo", |
| 3425 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3426 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | `) |
| 3430 | |
| 3431 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3432 | apexRule := module.Rule("apexRule") |
| 3433 | copyCmds := apexRule.Args["copy_commands"] |
| 3434 | |
| 3435 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 3436 | } |
| 3437 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3438 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 3439 | // libfoo's apex_available comes from cc_defaults |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3440 | testApexError(t, `requires "libfoo" that is not available for the APEX`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 3441 | apex { |
| 3442 | name: "myapex", |
| 3443 | key: "myapex.key", |
| 3444 | native_shared_libs: ["libfoo"], |
| 3445 | } |
| 3446 | |
| 3447 | apex_key { |
| 3448 | name: "myapex.key", |
| 3449 | public_key: "testkey.avbpubkey", |
| 3450 | private_key: "testkey.pem", |
| 3451 | } |
| 3452 | |
| 3453 | apex { |
| 3454 | name: "otherapex", |
| 3455 | key: "myapex.key", |
| 3456 | native_shared_libs: ["libfoo"], |
| 3457 | } |
| 3458 | |
| 3459 | cc_defaults { |
| 3460 | name: "libfoo-defaults", |
| 3461 | apex_available: ["otherapex"], |
| 3462 | } |
| 3463 | |
| 3464 | cc_library { |
| 3465 | name: "libfoo", |
| 3466 | defaults: ["libfoo-defaults"], |
| 3467 | stl: "none", |
| 3468 | system_shared_libs: [], |
| 3469 | }`) |
| 3470 | } |
| 3471 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3472 | func TestApexAvailable(t *testing.T) { |
| 3473 | // libfoo is not available to myapex, but only to otherapex |
| 3474 | testApexError(t, "requires \"libfoo\" that is not available for the APEX", ` |
| 3475 | apex { |
| 3476 | name: "myapex", |
| 3477 | key: "myapex.key", |
| 3478 | native_shared_libs: ["libfoo"], |
| 3479 | } |
| 3480 | |
| 3481 | apex_key { |
| 3482 | name: "myapex.key", |
| 3483 | public_key: "testkey.avbpubkey", |
| 3484 | private_key: "testkey.pem", |
| 3485 | } |
| 3486 | |
| 3487 | apex { |
| 3488 | name: "otherapex", |
| 3489 | key: "otherapex.key", |
| 3490 | native_shared_libs: ["libfoo"], |
| 3491 | } |
| 3492 | |
| 3493 | apex_key { |
| 3494 | name: "otherapex.key", |
| 3495 | public_key: "testkey.avbpubkey", |
| 3496 | private_key: "testkey.pem", |
| 3497 | } |
| 3498 | |
| 3499 | cc_library { |
| 3500 | name: "libfoo", |
| 3501 | stl: "none", |
| 3502 | system_shared_libs: [], |
| 3503 | apex_available: ["otherapex"], |
| 3504 | }`) |
| 3505 | |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3506 | // libbbaz is an indirect dep |
| 3507 | testApexError(t, "requires \"libbaz\" that is not available for the APEX", ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3508 | apex { |
| 3509 | name: "myapex", |
| 3510 | key: "myapex.key", |
| 3511 | native_shared_libs: ["libfoo"], |
| 3512 | } |
| 3513 | |
| 3514 | apex_key { |
| 3515 | name: "myapex.key", |
| 3516 | public_key: "testkey.avbpubkey", |
| 3517 | private_key: "testkey.pem", |
| 3518 | } |
| 3519 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3520 | cc_library { |
| 3521 | name: "libfoo", |
| 3522 | stl: "none", |
| 3523 | shared_libs: ["libbar"], |
| 3524 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3525 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | cc_library { |
| 3529 | name: "libbar", |
| 3530 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3531 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3532 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3533 | apex_available: ["myapex"], |
| 3534 | } |
| 3535 | |
| 3536 | cc_library { |
| 3537 | name: "libbaz", |
| 3538 | stl: "none", |
| 3539 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3540 | }`) |
| 3541 | |
| 3542 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 3543 | apex { |
| 3544 | name: "myapex", |
| 3545 | key: "myapex.key", |
| 3546 | native_shared_libs: ["libfoo"], |
| 3547 | } |
| 3548 | |
| 3549 | apex_key { |
| 3550 | name: "myapex.key", |
| 3551 | public_key: "testkey.avbpubkey", |
| 3552 | private_key: "testkey.pem", |
| 3553 | } |
| 3554 | |
| 3555 | cc_library { |
| 3556 | name: "libfoo", |
| 3557 | stl: "none", |
| 3558 | system_shared_libs: [], |
| 3559 | apex_available: ["otherapex"], |
| 3560 | }`) |
| 3561 | |
| 3562 | ctx, _ := testApex(t, ` |
| 3563 | apex { |
| 3564 | name: "myapex", |
| 3565 | key: "myapex.key", |
| 3566 | native_shared_libs: ["libfoo", "libbar"], |
| 3567 | } |
| 3568 | |
| 3569 | apex_key { |
| 3570 | name: "myapex.key", |
| 3571 | public_key: "testkey.avbpubkey", |
| 3572 | private_key: "testkey.pem", |
| 3573 | } |
| 3574 | |
| 3575 | cc_library { |
| 3576 | name: "libfoo", |
| 3577 | stl: "none", |
| 3578 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 3579 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3580 | apex_available: ["myapex"], |
| 3581 | } |
| 3582 | |
| 3583 | cc_library { |
| 3584 | name: "libbar", |
| 3585 | stl: "none", |
| 3586 | system_shared_libs: [], |
| 3587 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | cc_library { |
| 3591 | name: "libbaz", |
| 3592 | stl: "none", |
| 3593 | system_shared_libs: [], |
| 3594 | stubs: { |
| 3595 | versions: ["10", "20", "30"], |
| 3596 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3597 | }`) |
| 3598 | |
| 3599 | // check that libfoo and libbar are created only for myapex, but not for the platform |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3600 | // TODO(jiyong) the checks for the platform variant are removed because we now create |
| 3601 | // the platform variant regardless of the apex_availability. Instead, we will make sure that |
| 3602 | // the platform variants are not used from other platform modules. When that is done, |
| 3603 | // these checks will be replaced by expecting a specific error message that will be |
| 3604 | // emitted when the platform variant is used. |
| 3605 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3606 | // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
| 3607 | // ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex") |
| 3608 | // ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared") |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3609 | |
| 3610 | ctx, _ = testApex(t, ` |
| 3611 | apex { |
| 3612 | name: "myapex", |
| 3613 | key: "myapex.key", |
| 3614 | } |
| 3615 | |
| 3616 | apex_key { |
| 3617 | name: "myapex.key", |
| 3618 | public_key: "testkey.avbpubkey", |
| 3619 | private_key: "testkey.pem", |
| 3620 | } |
| 3621 | |
| 3622 | cc_library { |
| 3623 | name: "libfoo", |
| 3624 | stl: "none", |
| 3625 | system_shared_libs: [], |
| 3626 | apex_available: ["//apex_available:platform"], |
| 3627 | }`) |
| 3628 | |
| 3629 | // check that libfoo is created only for the platform |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3630 | ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3631 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3632 | |
| 3633 | ctx, _ = testApex(t, ` |
| 3634 | apex { |
| 3635 | name: "myapex", |
| 3636 | key: "myapex.key", |
| 3637 | native_shared_libs: ["libfoo"], |
| 3638 | } |
| 3639 | |
| 3640 | apex_key { |
| 3641 | name: "myapex.key", |
| 3642 | public_key: "testkey.avbpubkey", |
| 3643 | private_key: "testkey.pem", |
| 3644 | } |
| 3645 | |
| 3646 | cc_library { |
| 3647 | name: "libfoo", |
| 3648 | stl: "none", |
| 3649 | system_shared_libs: [], |
| 3650 | apex_available: ["myapex"], |
| 3651 | static: { |
| 3652 | apex_available: ["//apex_available:platform"], |
| 3653 | }, |
| 3654 | }`) |
| 3655 | |
| 3656 | // shared variant of libfoo is only available to myapex |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3657 | // TODO(jiyong) the checks for the platform variant are removed because we now create |
| 3658 | // the platform variant regardless of the apex_availability. Instead, we will make sure that |
| 3659 | // the platform variants are not used from other platform modules. When that is done, |
| 3660 | // these checks will be replaced by expecting a specific error message that will be |
| 3661 | // emitted when the platform variant is used. |
| 3662 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex") |
| 3663 | // ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared") |
| 3664 | // // but the static variant is available to both myapex and the platform |
| 3665 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex") |
| 3666 | // ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static") |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 3667 | } |
| 3668 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3669 | func TestOverrideApex(t *testing.T) { |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3670 | ctx, config := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3671 | apex { |
| 3672 | name: "myapex", |
| 3673 | key: "myapex.key", |
| 3674 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3675 | overrides: ["oldapex"], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | override_apex { |
| 3679 | name: "override_myapex", |
| 3680 | base: "myapex", |
| 3681 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3682 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3683 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 3684 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | apex_key { |
| 3688 | name: "myapex.key", |
| 3689 | public_key: "testkey.avbpubkey", |
| 3690 | private_key: "testkey.pem", |
| 3691 | } |
| 3692 | |
| 3693 | android_app { |
| 3694 | name: "app", |
| 3695 | srcs: ["foo/bar/MyClass.java"], |
| 3696 | package_name: "foo", |
| 3697 | sdk_version: "none", |
| 3698 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3699 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | override_android_app { |
| 3703 | name: "override_app", |
| 3704 | base: "app", |
| 3705 | package_name: "bar", |
| 3706 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3707 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3708 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 3709 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 3710 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 3711 | if originalVariant.GetOverriddenBy() != "" { |
| 3712 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 3713 | } |
| 3714 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 3715 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 3716 | } |
| 3717 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3718 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 3719 | apexRule := module.Rule("apexRule") |
| 3720 | copyCmds := apexRule.Args["copy_commands"] |
| 3721 | |
| 3722 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
| 3723 | ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3724 | |
| 3725 | apexBundle := module.Module().(*apexBundle) |
| 3726 | name := apexBundle.Name() |
| 3727 | if name != "override_myapex" { |
| 3728 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 3729 | } |
| 3730 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 3731 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 3732 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 3733 | } |
| 3734 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3735 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 3736 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 3737 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3738 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3739 | var builder strings.Builder |
| 3740 | data.Custom(&builder, name, "TARGET_", "", data) |
| 3741 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3742 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3743 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 3744 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 3745 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3746 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 3747 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 3748 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 3749 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 3750 | } |
| 3751 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3752 | func TestLegacyAndroid10Support(t *testing.T) { |
| 3753 | ctx, _ := testApex(t, ` |
| 3754 | apex { |
| 3755 | name: "myapex", |
| 3756 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3757 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 3758 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | apex_key { |
| 3762 | name: "myapex.key", |
| 3763 | public_key: "testkey.avbpubkey", |
| 3764 | private_key: "testkey.pem", |
| 3765 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3766 | |
| 3767 | cc_library { |
| 3768 | name: "mylib", |
| 3769 | srcs: ["mylib.cpp"], |
| 3770 | stl: "libc++", |
| 3771 | system_shared_libs: [], |
| 3772 | apex_available: [ "myapex" ], |
| 3773 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3774 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3775 | |
| 3776 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 3777 | args := module.Rule("apexRule").Args |
| 3778 | 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] | 3779 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 3780 | |
| 3781 | // The copies of the libraries in the apex should have one more dependency than |
| 3782 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 3783 | // the dependency names directly here but for some reason the names are blank in |
| 3784 | // this test. |
| 3785 | for _, lib := range []string{"libc++", "mylib"} { |
| 3786 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_myapex").Rule("ld").Implicits |
| 3787 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 3788 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 3789 | t.Errorf("%q missing unwinder dep", lib) |
| 3790 | } |
| 3791 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 3792 | } |
| 3793 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3794 | func TestJavaSDKLibrary(t *testing.T) { |
| 3795 | ctx, _ := testApex(t, ` |
| 3796 | apex { |
| 3797 | name: "myapex", |
| 3798 | key: "myapex.key", |
| 3799 | java_libs: ["foo"], |
| 3800 | } |
| 3801 | |
| 3802 | apex_key { |
| 3803 | name: "myapex.key", |
| 3804 | public_key: "testkey.avbpubkey", |
| 3805 | private_key: "testkey.pem", |
| 3806 | } |
| 3807 | |
| 3808 | java_sdk_library { |
| 3809 | name: "foo", |
| 3810 | srcs: ["a.java"], |
| 3811 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3812 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3813 | } |
| 3814 | `, withFiles(map[string][]byte{ |
| 3815 | "api/current.txt": nil, |
| 3816 | "api/removed.txt": nil, |
| 3817 | "api/system-current.txt": nil, |
| 3818 | "api/system-removed.txt": nil, |
| 3819 | "api/test-current.txt": nil, |
| 3820 | "api/test-removed.txt": nil, |
| 3821 | })) |
| 3822 | |
| 3823 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3824 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 3825 | "javalib/foo.jar", |
| 3826 | "etc/permissions/foo.xml", |
| 3827 | }) |
| 3828 | // 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] | 3829 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 3830 | 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] | 3831 | } |
| 3832 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 3833 | func TestCompatConfig(t *testing.T) { |
| 3834 | ctx, _ := testApex(t, ` |
| 3835 | apex { |
| 3836 | name: "myapex", |
| 3837 | key: "myapex.key", |
| 3838 | prebuilts: ["myjar-platform-compat-config"], |
| 3839 | java_libs: ["myjar"], |
| 3840 | } |
| 3841 | |
| 3842 | apex_key { |
| 3843 | name: "myapex.key", |
| 3844 | public_key: "testkey.avbpubkey", |
| 3845 | private_key: "testkey.pem", |
| 3846 | } |
| 3847 | |
| 3848 | platform_compat_config { |
| 3849 | name: "myjar-platform-compat-config", |
| 3850 | src: ":myjar", |
| 3851 | } |
| 3852 | |
| 3853 | java_library { |
| 3854 | name: "myjar", |
| 3855 | srcs: ["foo/bar/MyClass.java"], |
| 3856 | sdk_version: "none", |
| 3857 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 3858 | apex_available: [ "myapex" ], |
| 3859 | } |
| 3860 | `) |
| 3861 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 3862 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 3863 | "javalib/myjar.jar", |
| 3864 | }) |
| 3865 | } |
| 3866 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 3867 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 3868 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 3869 | apex { |
| 3870 | name: "myapex", |
| 3871 | key: "myapex.key", |
| 3872 | java_libs: ["myjar"], |
| 3873 | } |
| 3874 | |
| 3875 | apex_key { |
| 3876 | name: "myapex.key", |
| 3877 | public_key: "testkey.avbpubkey", |
| 3878 | private_key: "testkey.pem", |
| 3879 | } |
| 3880 | |
| 3881 | java_library { |
| 3882 | name: "myjar", |
| 3883 | srcs: ["foo/bar/MyClass.java"], |
| 3884 | sdk_version: "none", |
| 3885 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 3886 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 3887 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 3888 | } |
| 3889 | `) |
| 3890 | } |
| 3891 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 3892 | func TestCarryRequiredModuleNames(t *testing.T) { |
| 3893 | ctx, config := testApex(t, ` |
| 3894 | apex { |
| 3895 | name: "myapex", |
| 3896 | key: "myapex.key", |
| 3897 | native_shared_libs: ["mylib"], |
| 3898 | } |
| 3899 | |
| 3900 | apex_key { |
| 3901 | name: "myapex.key", |
| 3902 | public_key: "testkey.avbpubkey", |
| 3903 | private_key: "testkey.pem", |
| 3904 | } |
| 3905 | |
| 3906 | cc_library { |
| 3907 | name: "mylib", |
| 3908 | srcs: ["mylib.cpp"], |
| 3909 | system_shared_libs: [], |
| 3910 | stl: "none", |
| 3911 | required: ["a", "b"], |
| 3912 | host_required: ["c", "d"], |
| 3913 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3914 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 3915 | } |
| 3916 | `) |
| 3917 | |
| 3918 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 3919 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 3920 | name := apexBundle.BaseModuleName() |
| 3921 | prefix := "TARGET_" |
| 3922 | var builder strings.Builder |
| 3923 | data.Custom(&builder, name, prefix, "", data) |
| 3924 | androidMk := builder.String() |
| 3925 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 3926 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 3927 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 3928 | } |
| 3929 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3930 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 3931 | bp := ` |
| 3932 | apex { |
| 3933 | name: "myapex", |
| 3934 | key: "myapex.key", |
| 3935 | native_shared_libs: ["mylib"], |
| 3936 | java_libs: ["myjar"], |
| 3937 | } |
| 3938 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3939 | apex { |
| 3940 | name: "myapex.updatable", |
| 3941 | key: "myapex.key", |
| 3942 | native_shared_libs: ["mylib"], |
| 3943 | java_libs: ["myjar"], |
| 3944 | updatable: true, |
| 3945 | } |
| 3946 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3947 | apex_key { |
| 3948 | name: "myapex.key", |
| 3949 | public_key: "testkey.avbpubkey", |
| 3950 | private_key: "testkey.pem", |
| 3951 | } |
| 3952 | |
| 3953 | cc_library { |
| 3954 | name: "mylib", |
| 3955 | srcs: ["mylib.cpp"], |
| 3956 | shared_libs: ["myotherlib"], |
| 3957 | system_shared_libs: [], |
| 3958 | stl: "none", |
| 3959 | apex_available: [ |
| 3960 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3961 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3962 | "//apex_available:platform", |
| 3963 | ], |
| 3964 | } |
| 3965 | |
| 3966 | cc_library { |
| 3967 | name: "myotherlib", |
| 3968 | srcs: ["mylib.cpp"], |
| 3969 | system_shared_libs: [], |
| 3970 | stl: "none", |
| 3971 | apex_available: [ |
| 3972 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3973 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3974 | "//apex_available:platform", |
| 3975 | ], |
| 3976 | } |
| 3977 | |
| 3978 | java_library { |
| 3979 | name: "myjar", |
| 3980 | srcs: ["foo/bar/MyClass.java"], |
| 3981 | sdk_version: "none", |
| 3982 | system_modules: "none", |
| 3983 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3984 | apex_available: [ |
| 3985 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3986 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3987 | "//apex_available:platform", |
| 3988 | ], |
| 3989 | } |
| 3990 | |
| 3991 | java_library { |
| 3992 | name: "myotherjar", |
| 3993 | srcs: ["foo/bar/MyClass.java"], |
| 3994 | sdk_version: "none", |
| 3995 | system_modules: "none", |
| 3996 | apex_available: [ |
| 3997 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 3998 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3999 | "//apex_available:platform", |
| 4000 | ], |
| 4001 | } |
| 4002 | ` |
| 4003 | |
| 4004 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 4005 | for _, f := range files { |
| 4006 | if f.path == file { |
| 4007 | if f.isLink { |
| 4008 | t.Errorf("%q is not a real file", file) |
| 4009 | } |
| 4010 | return |
| 4011 | } |
| 4012 | } |
| 4013 | t.Errorf("%q is not found", file) |
| 4014 | } |
| 4015 | |
| 4016 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 4017 | for _, f := range files { |
| 4018 | if f.path == file { |
| 4019 | if !f.isLink { |
| 4020 | t.Errorf("%q is not a symlink", file) |
| 4021 | } |
| 4022 | return |
| 4023 | } |
| 4024 | } |
| 4025 | t.Errorf("%q is not found", file) |
| 4026 | } |
| 4027 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4028 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 4029 | // is updatable or not |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4030 | ctx, _ := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4031 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4032 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4033 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4034 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 4035 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4036 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 4037 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4038 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4039 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 4040 | |
| 4041 | // 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] | 4042 | ctx, _ = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 4043 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4044 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4045 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4046 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 4047 | |
| 4048 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 4049 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 4050 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 4051 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 4052 | } |
| 4053 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 4054 | func TestApexWithJniLibs(t *testing.T) { |
| 4055 | ctx, _ := testApex(t, ` |
| 4056 | apex { |
| 4057 | name: "myapex", |
| 4058 | key: "myapex.key", |
| 4059 | jni_libs: ["mylib"], |
| 4060 | } |
| 4061 | |
| 4062 | apex_key { |
| 4063 | name: "myapex.key", |
| 4064 | public_key: "testkey.avbpubkey", |
| 4065 | private_key: "testkey.pem", |
| 4066 | } |
| 4067 | |
| 4068 | cc_library { |
| 4069 | name: "mylib", |
| 4070 | srcs: ["mylib.cpp"], |
| 4071 | shared_libs: ["mylib2"], |
| 4072 | system_shared_libs: [], |
| 4073 | stl: "none", |
| 4074 | apex_available: [ "myapex" ], |
| 4075 | } |
| 4076 | |
| 4077 | cc_library { |
| 4078 | name: "mylib2", |
| 4079 | srcs: ["mylib.cpp"], |
| 4080 | system_shared_libs: [], |
| 4081 | stl: "none", |
| 4082 | apex_available: [ "myapex" ], |
| 4083 | } |
| 4084 | `) |
| 4085 | |
| 4086 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 4087 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 4088 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 4089 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 4090 | "lib64/mylib.so", |
| 4091 | "lib64/mylib2.so", |
| 4092 | }) |
| 4093 | } |
| 4094 | |
| 4095 | func TestApexWithJniLibs_Errors(t *testing.T) { |
| 4096 | testApexError(t, `jni_libs: "xxx" is not a cc_library`, ` |
| 4097 | apex { |
| 4098 | name: "myapex", |
| 4099 | key: "myapex.key", |
| 4100 | jni_libs: ["xxx"], |
| 4101 | } |
| 4102 | |
| 4103 | apex_key { |
| 4104 | name: "myapex.key", |
| 4105 | public_key: "testkey.avbpubkey", |
| 4106 | private_key: "testkey.pem", |
| 4107 | } |
| 4108 | |
| 4109 | prebuilt_etc { |
| 4110 | name: "xxx", |
| 4111 | src: "xxx", |
| 4112 | } |
| 4113 | `, withFiles(map[string][]byte{ |
| 4114 | "xxx": nil, |
| 4115 | })) |
| 4116 | } |
| 4117 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4118 | func TestAppBundle(t *testing.T) { |
| 4119 | ctx, _ := testApex(t, ` |
| 4120 | apex { |
| 4121 | name: "myapex", |
| 4122 | key: "myapex.key", |
| 4123 | apps: ["AppFoo"], |
| 4124 | } |
| 4125 | |
| 4126 | apex_key { |
| 4127 | name: "myapex.key", |
| 4128 | public_key: "testkey.avbpubkey", |
| 4129 | private_key: "testkey.pem", |
| 4130 | } |
| 4131 | |
| 4132 | android_app { |
| 4133 | name: "AppFoo", |
| 4134 | srcs: ["foo/bar/MyClass.java"], |
| 4135 | sdk_version: "none", |
| 4136 | system_modules: "none", |
| 4137 | apex_available: [ "myapex" ], |
| 4138 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 4139 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 4140 | |
| 4141 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config") |
| 4142 | content := bundleConfigRule.Args["content"] |
| 4143 | |
| 4144 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 4145 | 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] | 4146 | } |
| 4147 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame^] | 4148 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg, bp string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
| 4149 | t.Helper() |
| 4150 | |
| 4151 | bp = bp + ` |
| 4152 | filegroup { |
| 4153 | name: "some-updatable-apex-file_contexts", |
| 4154 | srcs: [ |
| 4155 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 4156 | ], |
| 4157 | } |
| 4158 | ` |
| 4159 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 4160 | bp += java.GatherRequiredDepsForTest() |
| 4161 | bp += dexpreopt.BpToolModulesForTest() |
| 4162 | |
| 4163 | fs := map[string][]byte{ |
| 4164 | "a.java": nil, |
| 4165 | "a.jar": nil, |
| 4166 | "build/make/target/product/security": nil, |
| 4167 | "apex_manifest.json": nil, |
| 4168 | "AndroidManifest.xml": nil, |
| 4169 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 4170 | "system/sepolicy/apex/com.android.art.something-file_contexts": nil, |
| 4171 | "framework/aidl/a.aidl": nil, |
| 4172 | } |
| 4173 | cc.GatherRequiredFilesForTest(fs) |
| 4174 | |
| 4175 | ctx := android.NewTestArchContext() |
| 4176 | ctx.RegisterModuleType("apex", BundleFactory) |
| 4177 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 4178 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 4179 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
| 4180 | java.RegisterJavaBuildComponents(ctx) |
| 4181 | java.RegisterSystemModulesBuildComponents(ctx) |
| 4182 | java.RegisterAppBuildComponents(ctx) |
| 4183 | java.RegisterDexpreoptBootJarsComponents(ctx) |
| 4184 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 4185 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 4186 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 4187 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 4188 | |
| 4189 | config := android.TestArchConfig(buildDir, nil, bp, fs) |
| 4190 | ctx.Register(config) |
| 4191 | |
| 4192 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 4193 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 4194 | pathCtx := android.PathContextForTesting(config) |
| 4195 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 4196 | transformDexpreoptConfig(dexpreoptConfig) |
| 4197 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 4198 | |
| 4199 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 4200 | android.FailIfErrored(t, errs) |
| 4201 | |
| 4202 | _, errs = ctx.PrepareBuildActions(config) |
| 4203 | if errmsg == "" { |
| 4204 | android.FailIfErrored(t, errs) |
| 4205 | } else if len(errs) > 0 { |
| 4206 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 4207 | return |
| 4208 | } else { |
| 4209 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
| 4214 | bp := ` |
| 4215 | java_library { |
| 4216 | name: "some-updatable-apex-lib", |
| 4217 | srcs: ["a.java"], |
| 4218 | apex_available: [ |
| 4219 | "some-updatable-apex", |
| 4220 | ], |
| 4221 | } |
| 4222 | |
| 4223 | java_library { |
| 4224 | name: "some-platform-lib", |
| 4225 | srcs: ["a.java"], |
| 4226 | installable: true, |
| 4227 | } |
| 4228 | |
| 4229 | java_library { |
| 4230 | name: "some-art-lib", |
| 4231 | srcs: ["a.java"], |
| 4232 | apex_available: [ |
| 4233 | "com.android.art.something", |
| 4234 | ], |
| 4235 | hostdex: true, |
| 4236 | } |
| 4237 | |
| 4238 | apex { |
| 4239 | name: "some-updatable-apex", |
| 4240 | key: "some-updatable-apex.key", |
| 4241 | java_libs: ["some-updatable-apex-lib"], |
| 4242 | } |
| 4243 | |
| 4244 | apex_key { |
| 4245 | name: "some-updatable-apex.key", |
| 4246 | } |
| 4247 | |
| 4248 | apex { |
| 4249 | name: "com.android.art.something", |
| 4250 | key: "com.android.art.something.key", |
| 4251 | java_libs: ["some-art-lib"], |
| 4252 | } |
| 4253 | |
| 4254 | apex_key { |
| 4255 | name: "com.android.art.something.key", |
| 4256 | } |
| 4257 | ` |
| 4258 | |
| 4259 | var error string |
| 4260 | var transform func(*dexpreopt.GlobalConfig) |
| 4261 | |
| 4262 | // updatable jar from ART apex in the ART boot image => ok |
| 4263 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4264 | config.ArtApexJars = []string{"some-art-lib"} |
| 4265 | } |
| 4266 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4267 | |
| 4268 | // updatable jar from ART apex in the framework boot image => error |
| 4269 | error = "module 'some-art-lib' from updatable apex 'com.android.art.something' is not allowed in the framework boot image" |
| 4270 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4271 | config.BootJars = []string{"some-art-lib"} |
| 4272 | } |
| 4273 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4274 | |
| 4275 | // updatable jar from some other apex in the ART boot image => error |
| 4276 | error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the ART boot image" |
| 4277 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4278 | config.ArtApexJars = []string{"some-updatable-apex-lib"} |
| 4279 | } |
| 4280 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4281 | |
| 4282 | // updatable jar from some other apex in the framework boot image => error |
| 4283 | error = "module 'some-updatable-apex-lib' from updatable apex 'some-updatable-apex' is not allowed in the framework boot image" |
| 4284 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4285 | config.BootJars = []string{"some-updatable-apex-lib"} |
| 4286 | } |
| 4287 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4288 | |
| 4289 | // nonexistent jar in the ART boot image => error |
| 4290 | error = "failed to find a dex jar path for module 'nonexistent'" |
| 4291 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4292 | config.ArtApexJars = []string{"nonexistent"} |
| 4293 | } |
| 4294 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4295 | |
| 4296 | // nonexistent jar in the framework boot image => error |
| 4297 | error = "failed to find a dex jar path for module 'nonexistent'" |
| 4298 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4299 | config.BootJars = []string{"nonexistent"} |
| 4300 | } |
| 4301 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4302 | |
| 4303 | // platform jar in the ART boot image => error |
| 4304 | error = "module 'some-platform-lib' is part of the platform and not allowed in the ART boot image" |
| 4305 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4306 | config.ArtApexJars = []string{"some-platform-lib"} |
| 4307 | } |
| 4308 | testNoUpdatableJarsInBootImage(t, error, bp, transform) |
| 4309 | |
| 4310 | // platform jar in the framework boot image => ok |
| 4311 | transform = func(config *dexpreopt.GlobalConfig) { |
| 4312 | config.BootJars = []string{"some-platform-lib"} |
| 4313 | } |
| 4314 | testNoUpdatableJarsInBootImage(t, "", bp, transform) |
| 4315 | } |
| 4316 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4317 | func TestMain(m *testing.M) { |
| 4318 | run := func() int { |
| 4319 | setUp() |
| 4320 | defer tearDown() |
| 4321 | |
| 4322 | return m.Run() |
| 4323 | } |
| 4324 | |
| 4325 | os.Exit(run()) |
| 4326 | } |