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