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" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 20 | "reflect" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 21 | "strings" |
| 22 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 23 | |
| 24 | "github.com/google/blueprint/proptools" |
| 25 | |
| 26 | "android/soong/android" |
| 27 | "android/soong/cc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 28 | "android/soong/java" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 29 | ) |
| 30 | |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 31 | var buildDir string |
| 32 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 33 | // names returns name list from white space separated string |
| 34 | func names(s string) (ns []string) { |
| 35 | for _, n := range strings.Split(s, " ") { |
| 36 | if len(n) > 0 { |
| 37 | ns = append(ns, n) |
| 38 | } |
| 39 | } |
| 40 | return |
| 41 | } |
| 42 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 43 | func testApexError(t *testing.T, pattern, bp string) { |
| 44 | ctx, config := testApexContext(t, bp) |
| 45 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 46 | if len(errs) > 0 { |
| 47 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 48 | return |
| 49 | } |
| 50 | _, errs = ctx.PrepareBuildActions(config) |
| 51 | if len(errs) > 0 { |
| 52 | android.FailIfNoMatchingErrors(t, pattern, errs) |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
| 57 | } |
| 58 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 59 | func testApex(t *testing.T, bp string) (*android.TestContext, android.Config) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 60 | ctx, config := testApexContext(t, bp) |
| 61 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 62 | android.FailIfErrored(t, errs) |
| 63 | _, errs = ctx.PrepareBuildActions(config) |
| 64 | android.FailIfErrored(t, errs) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 65 | return ctx, config |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | func testApexContext(t *testing.T, bp string) (*android.TestContext, android.Config) { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 69 | config := android.TestArchConfig(buildDir, nil) |
| 70 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
| 71 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 72 | config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 73 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 74 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 75 | |
| 76 | ctx := android.NewTestArchContext() |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 77 | ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory)) |
| 78 | ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 79 | ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory)) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 80 | ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 81 | ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory)) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 82 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 83 | |
| 84 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 85 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 86 | ctx.BottomUp("apex", apexMutator) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 87 | ctx.BottomUp("apex_uses", apexUsesMutator) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 88 | ctx.TopDown("prebuilt_select", android.PrebuiltSelectModuleMutator).Parallel() |
| 89 | ctx.BottomUp("prebuilt_postdeps", android.PrebuiltPostDepsMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 90 | }) |
| 91 | |
| 92 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) |
| 93 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 94 | ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory)) |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 95 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 96 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 97 | ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory)) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 98 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 99 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 100 | ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 101 | ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory)) |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 102 | ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory)) |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 103 | ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 104 | ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 105 | ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory)) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame^] | 106 | ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory)) |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 107 | |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 108 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 109 | ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel() |
| 110 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 111 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 112 | ctx.BottomUp("image", cc.ImageMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 113 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 114 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 115 | ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 116 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 117 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 118 | }) |
| 119 | |
| 120 | ctx.Register() |
| 121 | |
| 122 | bp = bp + ` |
| 123 | toolchain_library { |
| 124 | name: "libcompiler_rt-extras", |
| 125 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 126 | vendor_available: true, |
| 127 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | toolchain_library { |
| 131 | name: "libatomic", |
| 132 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 133 | vendor_available: true, |
| 134 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | toolchain_library { |
| 138 | name: "libgcc", |
| 139 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 140 | vendor_available: true, |
| 141 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | toolchain_library { |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 145 | name: "libgcc_stripped", |
| 146 | src: "", |
| 147 | vendor_available: true, |
| 148 | recovery_available: true, |
| 149 | } |
| 150 | |
| 151 | toolchain_library { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 152 | name: "libclang_rt.builtins-aarch64-android", |
| 153 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 154 | vendor_available: true, |
| 155 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | toolchain_library { |
| 159 | name: "libclang_rt.builtins-arm-android", |
| 160 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 161 | vendor_available: true, |
| 162 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | cc_object { |
| 166 | name: "crtbegin_so", |
| 167 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 168 | vendor_available: true, |
| 169 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | cc_object { |
| 173 | name: "crtend_so", |
| 174 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 175 | vendor_available: true, |
| 176 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 177 | } |
| 178 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 179 | cc_object { |
| 180 | name: "crtbegin_static", |
| 181 | stl: "none", |
| 182 | } |
| 183 | |
| 184 | cc_object { |
| 185 | name: "crtend_android", |
| 186 | stl: "none", |
| 187 | } |
| 188 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 189 | llndk_library { |
| 190 | name: "libc", |
| 191 | symbol_file: "", |
| 192 | } |
| 193 | |
| 194 | llndk_library { |
| 195 | name: "libm", |
| 196 | symbol_file: "", |
| 197 | } |
| 198 | |
| 199 | llndk_library { |
| 200 | name: "libdl", |
| 201 | symbol_file: "", |
| 202 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 203 | ` |
| 204 | |
| 205 | ctx.MockFileSystem(map[string][]byte{ |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 206 | "Android.bp": []byte(bp), |
Dan Willemsen | 412160e | 2019-04-09 21:36:26 -0700 | [diff] [blame] | 207 | "build/make/target/product/security": nil, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 208 | "apex_manifest.json": nil, |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 209 | "AndroidManifest.xml": nil, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 210 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 211 | "system/sepolicy/apex/myapex_keytest-file_contexts": nil, |
| 212 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 213 | "system/sepolicy/apex/commonapex-file_contexts": nil, |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame^] | 214 | "mylib.cpp": nil, |
| 215 | "mylib_common.cpp": nil, |
| 216 | "mytest.cpp": nil, |
| 217 | "mytest1.cpp": nil, |
| 218 | "mytest2.cpp": nil, |
| 219 | "mytest3.cpp": nil, |
| 220 | "myprebuilt": nil, |
| 221 | "my_include": nil, |
| 222 | "foo/bar/MyClass.java": nil, |
| 223 | "prebuilt.jar": nil, |
| 224 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 225 | "vendor/foo/devkeys/test.pk8": nil, |
| 226 | "testkey.x509.pem": nil, |
| 227 | "testkey.pk8": nil, |
| 228 | "testkey.override.x509.pem": nil, |
| 229 | "testkey.override.pk8": nil, |
| 230 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 231 | "vendor/foo/devkeys/testkey.pem": nil, |
| 232 | "NOTICE": nil, |
| 233 | "custom_notice": nil, |
| 234 | "testkey2.avbpubkey": nil, |
| 235 | "testkey2.pem": nil, |
| 236 | "myapex-arm64.apex": nil, |
| 237 | "myapex-arm.apex": nil, |
| 238 | "frameworks/base/api/current.txt": nil, |
| 239 | "build/make/core/proguard.flags": nil, |
| 240 | "build/make/core/proguard_basic_keeps.flags": nil, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 241 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 242 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 243 | return ctx, config |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 244 | } |
| 245 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 246 | func setUp() { |
| 247 | var err error |
| 248 | buildDir, err = ioutil.TempDir("", "soong_apex_test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 249 | if err != nil { |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 250 | panic(err) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 251 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 252 | } |
| 253 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 254 | func tearDown() { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 255 | os.RemoveAll(buildDir) |
| 256 | } |
| 257 | |
| 258 | // ensure that 'result' contains 'expected' |
| 259 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 260 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 261 | if !strings.Contains(result, expected) { |
| 262 | t.Errorf("%q is not found in %q", expected, result) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // ensures that 'result' does not contain 'notExpected' |
| 267 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 268 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 269 | if strings.Contains(result, notExpected) { |
| 270 | t.Errorf("%q is found in %q", notExpected, result) |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 275 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 276 | if !android.InList(expected, result) { |
| 277 | t.Errorf("%q is not found in %v", expected, result) |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 282 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 283 | if android.InList(notExpected, result) { |
| 284 | t.Errorf("%q is found in %v", notExpected, result) |
| 285 | } |
| 286 | } |
| 287 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 288 | func ensureListEmpty(t *testing.T, result []string) { |
| 289 | t.Helper() |
| 290 | if len(result) > 0 { |
| 291 | t.Errorf("%q is expected to be empty", result) |
| 292 | } |
| 293 | } |
| 294 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 295 | // Minimal test |
| 296 | func TestBasicApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 297 | ctx, _ := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 298 | apex_defaults { |
| 299 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 300 | manifest: ":myapex.manifest", |
| 301 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 302 | key: "myapex.key", |
| 303 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 304 | multilib: { |
| 305 | both: { |
| 306 | binaries: ["foo",], |
| 307 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 308 | }, |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 309 | java_libs: ["myjar", "myprebuiltjar"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 310 | } |
| 311 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 312 | apex { |
| 313 | name: "myapex", |
| 314 | defaults: ["myapex-defaults"], |
| 315 | } |
| 316 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 317 | apex_key { |
| 318 | name: "myapex.key", |
| 319 | public_key: "testkey.avbpubkey", |
| 320 | private_key: "testkey.pem", |
| 321 | } |
| 322 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 323 | filegroup { |
| 324 | name: "myapex.manifest", |
| 325 | srcs: ["apex_manifest.json"], |
| 326 | } |
| 327 | |
| 328 | filegroup { |
| 329 | name: "myapex.androidmanifest", |
| 330 | srcs: ["AndroidManifest.xml"], |
| 331 | } |
| 332 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 333 | cc_library { |
| 334 | name: "mylib", |
| 335 | srcs: ["mylib.cpp"], |
| 336 | shared_libs: ["mylib2"], |
| 337 | system_shared_libs: [], |
| 338 | stl: "none", |
| 339 | } |
| 340 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 341 | cc_binary { |
| 342 | name: "foo", |
| 343 | srcs: ["mylib.cpp"], |
| 344 | compile_multilib: "both", |
| 345 | multilib: { |
| 346 | lib32: { |
| 347 | suffix: "32", |
| 348 | }, |
| 349 | lib64: { |
| 350 | suffix: "64", |
| 351 | }, |
| 352 | }, |
| 353 | symlinks: ["foo_link_"], |
| 354 | symlink_preferred_arch: true, |
| 355 | system_shared_libs: [], |
| 356 | static_executable: true, |
| 357 | stl: "none", |
| 358 | } |
| 359 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 360 | cc_library { |
| 361 | name: "mylib2", |
| 362 | srcs: ["mylib.cpp"], |
| 363 | system_shared_libs: [], |
| 364 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 365 | notice: "custom_notice", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 366 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 367 | |
| 368 | java_library { |
| 369 | name: "myjar", |
| 370 | srcs: ["foo/bar/MyClass.java"], |
| 371 | sdk_version: "none", |
| 372 | system_modules: "none", |
| 373 | compile_dex: true, |
| 374 | static_libs: ["myotherjar"], |
| 375 | } |
| 376 | |
| 377 | java_library { |
| 378 | name: "myotherjar", |
| 379 | srcs: ["foo/bar/MyClass.java"], |
| 380 | sdk_version: "none", |
| 381 | system_modules: "none", |
| 382 | compile_dex: true, |
| 383 | } |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 384 | |
| 385 | java_import { |
| 386 | name: "myprebuiltjar", |
| 387 | jars: ["prebuilt.jar"], |
| 388 | installable: true, |
| 389 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 390 | `) |
| 391 | |
| 392 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 393 | |
| 394 | optFlags := apexRule.Args["opt_flags"] |
| 395 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 396 | // Ensure that the NOTICE output is being packaged as an asset. |
| 397 | ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex/NOTICE") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 398 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 399 | copyCmds := apexRule.Args["copy_commands"] |
| 400 | |
| 401 | // Ensure that main rule creates an output |
| 402 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 403 | |
| 404 | // Ensure that apex variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 405 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 406 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex") |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 407 | ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 408 | |
| 409 | // Ensure that apex variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 410 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 411 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 412 | |
| 413 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 414 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 415 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 416 | ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar") |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 417 | ensureContains(t, copyCmds, "image.apex/javalib/myprebuiltjar.jar") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 418 | // .. but not for java libs |
| 419 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 420 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 421 | // Ensure that the platform variant ends with _core_shared or _common |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 422 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 423 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 424 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 425 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 9e6c242 | 2019-08-09 20:39:45 +0900 | [diff] [blame] | 426 | ensureListContains(t, ctx.ModuleVariantsForTests("myprebuiltjar"), "android_common") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 427 | |
| 428 | // Ensure that all symlinks are present. |
| 429 | found_foo_link_64 := false |
| 430 | found_foo := false |
| 431 | for _, cmd := range strings.Split(copyCmds, " && ") { |
| 432 | if strings.HasPrefix(cmd, "ln -s foo64") { |
| 433 | if strings.HasSuffix(cmd, "bin/foo") { |
| 434 | found_foo = true |
| 435 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 436 | found_foo_link_64 = true |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | good := found_foo && found_foo_link_64 |
| 441 | if !good { |
| 442 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 443 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 444 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 445 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("mergeNoticesRule") |
| 446 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 447 | if len(noticeInputs) != 2 { |
| 448 | t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs)) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 449 | } |
| 450 | ensureListContains(t, noticeInputs, "NOTICE") |
| 451 | ensureListContains(t, noticeInputs, "custom_notice") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | func TestBasicZipApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 455 | ctx, _ := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 456 | apex { |
| 457 | name: "myapex", |
| 458 | key: "myapex.key", |
| 459 | payload_type: "zip", |
| 460 | native_shared_libs: ["mylib"], |
| 461 | } |
| 462 | |
| 463 | apex_key { |
| 464 | name: "myapex.key", |
| 465 | public_key: "testkey.avbpubkey", |
| 466 | private_key: "testkey.pem", |
| 467 | } |
| 468 | |
| 469 | cc_library { |
| 470 | name: "mylib", |
| 471 | srcs: ["mylib.cpp"], |
| 472 | shared_libs: ["mylib2"], |
| 473 | system_shared_libs: [], |
| 474 | stl: "none", |
| 475 | } |
| 476 | |
| 477 | cc_library { |
| 478 | name: "mylib2", |
| 479 | srcs: ["mylib.cpp"], |
| 480 | system_shared_libs: [], |
| 481 | stl: "none", |
| 482 | } |
| 483 | `) |
| 484 | |
| 485 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule") |
| 486 | copyCmds := zipApexRule.Args["copy_commands"] |
| 487 | |
| 488 | // Ensure that main rule creates an output |
| 489 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 490 | |
| 491 | // Ensure that APEX variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 492 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 493 | |
| 494 | // Ensure that APEX variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 495 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 496 | |
| 497 | // Ensure that both direct and indirect deps are copied into apex |
| 498 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 499 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | func TestApexWithStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 503 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 504 | apex { |
| 505 | name: "myapex", |
| 506 | key: "myapex.key", |
| 507 | native_shared_libs: ["mylib", "mylib3"], |
| 508 | } |
| 509 | |
| 510 | apex_key { |
| 511 | name: "myapex.key", |
| 512 | public_key: "testkey.avbpubkey", |
| 513 | private_key: "testkey.pem", |
| 514 | } |
| 515 | |
| 516 | cc_library { |
| 517 | name: "mylib", |
| 518 | srcs: ["mylib.cpp"], |
| 519 | shared_libs: ["mylib2", "mylib3"], |
| 520 | system_shared_libs: [], |
| 521 | stl: "none", |
| 522 | } |
| 523 | |
| 524 | cc_library { |
| 525 | name: "mylib2", |
| 526 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 527 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 528 | system_shared_libs: [], |
| 529 | stl: "none", |
| 530 | stubs: { |
| 531 | versions: ["1", "2", "3"], |
| 532 | }, |
| 533 | } |
| 534 | |
| 535 | cc_library { |
| 536 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 537 | srcs: ["mylib.cpp"], |
| 538 | shared_libs: ["mylib4"], |
| 539 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 540 | stl: "none", |
| 541 | stubs: { |
| 542 | versions: ["10", "11", "12"], |
| 543 | }, |
| 544 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 545 | |
| 546 | cc_library { |
| 547 | name: "mylib4", |
| 548 | srcs: ["mylib.cpp"], |
| 549 | system_shared_libs: [], |
| 550 | stl: "none", |
| 551 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 552 | `) |
| 553 | |
| 554 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 555 | copyCmds := apexRule.Args["copy_commands"] |
| 556 | |
| 557 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 558 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 559 | |
| 560 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 561 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 562 | |
| 563 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 564 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 565 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 566 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 567 | |
| 568 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 569 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 570 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 571 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 572 | |
| 573 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 574 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 575 | // .. and not linking to the stubs variant of mylib3 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 576 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 577 | |
| 578 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 579 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 580 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 581 | |
| 582 | // Ensure that genstub is invoked with --apex |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 583 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"]) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 584 | } |
| 585 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 586 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 587 | ctx, _ := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 588 | apex { |
| 589 | name: "myapex", |
| 590 | key: "myapex.key", |
| 591 | native_shared_libs: ["mylib"], |
| 592 | } |
| 593 | |
| 594 | apex_key { |
| 595 | name: "myapex.key", |
| 596 | public_key: "testkey.avbpubkey", |
| 597 | private_key: "testkey.pem", |
| 598 | } |
| 599 | |
| 600 | cc_library { |
| 601 | name: "mylib", |
| 602 | srcs: ["mylib.cpp"], |
| 603 | shared_libs: ["libfoo#10"], |
| 604 | system_shared_libs: [], |
| 605 | stl: "none", |
| 606 | } |
| 607 | |
| 608 | cc_library { |
| 609 | name: "libfoo", |
| 610 | srcs: ["mylib.cpp"], |
| 611 | shared_libs: ["libbar"], |
| 612 | system_shared_libs: [], |
| 613 | stl: "none", |
| 614 | stubs: { |
| 615 | versions: ["10", "20", "30"], |
| 616 | }, |
| 617 | } |
| 618 | |
| 619 | cc_library { |
| 620 | name: "libbar", |
| 621 | srcs: ["mylib.cpp"], |
| 622 | system_shared_libs: [], |
| 623 | stl: "none", |
| 624 | } |
| 625 | |
| 626 | `) |
| 627 | |
| 628 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 629 | copyCmds := apexRule.Args["copy_commands"] |
| 630 | |
| 631 | // Ensure that direct non-stubs dep is always included |
| 632 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 633 | |
| 634 | // Ensure that indirect stubs dep is not included |
| 635 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 636 | |
| 637 | // Ensure that dependency of stubs is not included |
| 638 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 639 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 640 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 641 | |
| 642 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 643 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 644 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 645 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 646 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 647 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 648 | |
| 649 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 650 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
| 651 | } |
| 652 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 653 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 654 | /* |
| 655 | myapex |
| 656 | | |
| 657 | v (runtime_libs) |
| 658 | mylib ------+------> libfoo [provides stub] |
| 659 | | |
| 660 | `------> libbar |
| 661 | */ |
| 662 | ctx, _ := testApex(t, ` |
| 663 | apex { |
| 664 | name: "myapex", |
| 665 | key: "myapex.key", |
| 666 | native_shared_libs: ["mylib"], |
| 667 | } |
| 668 | |
| 669 | apex_key { |
| 670 | name: "myapex.key", |
| 671 | public_key: "testkey.avbpubkey", |
| 672 | private_key: "testkey.pem", |
| 673 | } |
| 674 | |
| 675 | cc_library { |
| 676 | name: "mylib", |
| 677 | srcs: ["mylib.cpp"], |
| 678 | runtime_libs: ["libfoo", "libbar"], |
| 679 | system_shared_libs: [], |
| 680 | stl: "none", |
| 681 | } |
| 682 | |
| 683 | cc_library { |
| 684 | name: "libfoo", |
| 685 | srcs: ["mylib.cpp"], |
| 686 | system_shared_libs: [], |
| 687 | stl: "none", |
| 688 | stubs: { |
| 689 | versions: ["10", "20", "30"], |
| 690 | }, |
| 691 | } |
| 692 | |
| 693 | cc_library { |
| 694 | name: "libbar", |
| 695 | srcs: ["mylib.cpp"], |
| 696 | system_shared_libs: [], |
| 697 | stl: "none", |
| 698 | } |
| 699 | |
| 700 | `) |
| 701 | |
| 702 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 703 | copyCmds := apexRule.Args["copy_commands"] |
| 704 | |
| 705 | // Ensure that direct non-stubs dep is always included |
| 706 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 707 | |
| 708 | // Ensure that indirect stubs dep is not included |
| 709 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 710 | |
| 711 | // Ensure that runtime_libs dep in included |
| 712 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 713 | |
| 714 | injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency") |
| 715 | ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"])) |
| 716 | ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libfoo.so") |
| 717 | |
| 718 | } |
| 719 | |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 720 | func TestApexDependencyToLLNDK(t *testing.T) { |
| 721 | ctx, _ := testApex(t, ` |
| 722 | apex { |
| 723 | name: "myapex", |
| 724 | key: "myapex.key", |
| 725 | use_vendor: true, |
| 726 | native_shared_libs: ["mylib"], |
| 727 | } |
| 728 | |
| 729 | apex_key { |
| 730 | name: "myapex.key", |
| 731 | public_key: "testkey.avbpubkey", |
| 732 | private_key: "testkey.pem", |
| 733 | } |
| 734 | |
| 735 | cc_library { |
| 736 | name: "mylib", |
| 737 | srcs: ["mylib.cpp"], |
| 738 | vendor_available: true, |
| 739 | shared_libs: ["libbar"], |
| 740 | system_shared_libs: [], |
| 741 | stl: "none", |
| 742 | } |
| 743 | |
| 744 | cc_library { |
| 745 | name: "libbar", |
| 746 | srcs: ["mylib.cpp"], |
| 747 | system_shared_libs: [], |
| 748 | stl: "none", |
| 749 | } |
| 750 | |
| 751 | llndk_library { |
| 752 | name: "libbar", |
| 753 | symbol_file: "", |
| 754 | } |
| 755 | |
| 756 | `) |
| 757 | |
| 758 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 759 | copyCmds := apexRule.Args["copy_commands"] |
| 760 | |
| 761 | // Ensure that LLNDK dep is not included |
| 762 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 763 | |
| 764 | injectRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("injectApexDependency") |
| 765 | ensureListEmpty(t, names(injectRule.Args["provideNativeLibs"])) |
| 766 | |
| 767 | // Ensure that LLNDK dep is required |
| 768 | ensureListContains(t, names(injectRule.Args["requireNativeLibs"]), "libbar.so") |
| 769 | |
| 770 | } |
| 771 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 772 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 773 | ctx, _ := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 774 | apex { |
| 775 | name: "myapex", |
| 776 | key: "myapex.key", |
| 777 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 778 | } |
| 779 | |
| 780 | apex_key { |
| 781 | name: "myapex.key", |
| 782 | public_key: "testkey.avbpubkey", |
| 783 | private_key: "testkey.pem", |
| 784 | } |
| 785 | |
| 786 | cc_library { |
| 787 | name: "mylib", |
| 788 | srcs: ["mylib.cpp"], |
| 789 | shared_libs: ["libdl#27"], |
| 790 | stl: "none", |
| 791 | } |
| 792 | |
| 793 | cc_library_shared { |
| 794 | name: "mylib_shared", |
| 795 | srcs: ["mylib.cpp"], |
| 796 | shared_libs: ["libdl#27"], |
| 797 | stl: "none", |
| 798 | } |
| 799 | |
| 800 | cc_library { |
| 801 | name: "libc", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 802 | no_libcrt: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 803 | nocrt: true, |
| 804 | system_shared_libs: [], |
| 805 | stl: "none", |
| 806 | stubs: { |
| 807 | versions: ["27", "28", "29"], |
| 808 | }, |
| 809 | } |
| 810 | |
| 811 | cc_library { |
| 812 | name: "libm", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 813 | no_libcrt: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 814 | nocrt: true, |
| 815 | system_shared_libs: [], |
| 816 | stl: "none", |
| 817 | stubs: { |
| 818 | versions: ["27", "28", "29"], |
| 819 | }, |
| 820 | } |
| 821 | |
| 822 | cc_library { |
| 823 | name: "libdl", |
Yi Kong | e7fe991 | 2019-06-02 00:53:50 -0700 | [diff] [blame] | 824 | no_libcrt: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 825 | nocrt: true, |
| 826 | system_shared_libs: [], |
| 827 | stl: "none", |
| 828 | stubs: { |
| 829 | versions: ["27", "28", "29"], |
| 830 | }, |
| 831 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 832 | |
| 833 | cc_library { |
| 834 | name: "libBootstrap", |
| 835 | srcs: ["mylib.cpp"], |
| 836 | stl: "none", |
| 837 | bootstrap: true, |
| 838 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 839 | `) |
| 840 | |
| 841 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 842 | copyCmds := apexRule.Args["copy_commands"] |
| 843 | |
| 844 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 845 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 846 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 847 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 848 | |
| 849 | // 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] | 850 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 851 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 852 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| 853 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 854 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 855 | |
| 856 | // For dependency to libc |
| 857 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 858 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 859 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 860 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 861 | // ... Cflags from stub is correctly exported to mylib |
| 862 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 863 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 864 | |
| 865 | // For dependency to libm |
| 866 | // Ensure that mylib is linking with the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 867 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 868 | // ... and not linking to the stub variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 869 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 870 | // ... and is not compiling with the stub |
| 871 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 872 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 873 | |
| 874 | // For dependency to libdl |
| 875 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 876 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 877 | // ... and not linking to the other versions of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 878 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so") |
| 879 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 880 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 881 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 882 | // ... Cflags from stub is correctly exported to mylib |
| 883 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 884 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 885 | |
| 886 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
| 887 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"] |
| 888 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so") |
| 889 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so") |
| 890 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 891 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 892 | |
| 893 | func TestFilesInSubDir(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 894 | ctx, _ := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 895 | apex { |
| 896 | name: "myapex", |
| 897 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 898 | native_shared_libs: ["mylib"], |
| 899 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 900 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 901 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | apex_key { |
| 905 | name: "myapex.key", |
| 906 | public_key: "testkey.avbpubkey", |
| 907 | private_key: "testkey.pem", |
| 908 | } |
| 909 | |
| 910 | prebuilt_etc { |
| 911 | name: "myetc", |
| 912 | src: "myprebuilt", |
| 913 | sub_dir: "foo/bar", |
| 914 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 915 | |
| 916 | cc_library { |
| 917 | name: "mylib", |
| 918 | srcs: ["mylib.cpp"], |
| 919 | relative_install_path: "foo/bar", |
| 920 | system_shared_libs: [], |
| 921 | stl: "none", |
| 922 | } |
| 923 | |
| 924 | cc_binary { |
| 925 | name: "mybin", |
| 926 | srcs: ["mylib.cpp"], |
| 927 | relative_install_path: "foo/bar", |
| 928 | system_shared_libs: [], |
| 929 | static_executable: true, |
| 930 | stl: "none", |
| 931 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 932 | `) |
| 933 | |
| 934 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig") |
| 935 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 936 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 937 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 938 | ensureListContains(t, dirs, "etc") |
| 939 | ensureListContains(t, dirs, "etc/foo") |
| 940 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 941 | ensureListContains(t, dirs, "lib64") |
| 942 | ensureListContains(t, dirs, "lib64/foo") |
| 943 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 944 | ensureListContains(t, dirs, "lib") |
| 945 | ensureListContains(t, dirs, "lib/foo") |
| 946 | ensureListContains(t, dirs, "lib/foo/bar") |
| 947 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 948 | ensureListContains(t, dirs, "bin") |
| 949 | ensureListContains(t, dirs, "bin/foo") |
| 950 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 951 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 952 | |
| 953 | func TestUseVendor(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 954 | ctx, _ := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 955 | apex { |
| 956 | name: "myapex", |
| 957 | key: "myapex.key", |
| 958 | native_shared_libs: ["mylib"], |
| 959 | use_vendor: true, |
| 960 | } |
| 961 | |
| 962 | apex_key { |
| 963 | name: "myapex.key", |
| 964 | public_key: "testkey.avbpubkey", |
| 965 | private_key: "testkey.pem", |
| 966 | } |
| 967 | |
| 968 | cc_library { |
| 969 | name: "mylib", |
| 970 | srcs: ["mylib.cpp"], |
| 971 | shared_libs: ["mylib2"], |
| 972 | system_shared_libs: [], |
| 973 | vendor_available: true, |
| 974 | stl: "none", |
| 975 | } |
| 976 | |
| 977 | cc_library { |
| 978 | name: "mylib2", |
| 979 | srcs: ["mylib.cpp"], |
| 980 | system_shared_libs: [], |
| 981 | vendor_available: true, |
| 982 | stl: "none", |
| 983 | } |
| 984 | `) |
| 985 | |
| 986 | inputsList := []string{} |
| 987 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() { |
| 988 | for _, implicit := range i.Implicits { |
| 989 | inputsList = append(inputsList, implicit.String()) |
| 990 | } |
| 991 | } |
| 992 | inputsString := strings.Join(inputsList, " ") |
| 993 | |
| 994 | // ensure that the apex includes vendor variants of the direct and indirect deps |
| 995 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so") |
| 996 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so") |
| 997 | |
| 998 | // ensure that the apex does not include core variants |
| 999 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so") |
| 1000 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
| 1001 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1002 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1003 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 1004 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 1005 | apex { |
| 1006 | name: "myapex", |
| 1007 | key: "myapex.key", |
| 1008 | native_shared_libs: ["mylib"], |
| 1009 | use_vendor: true, |
| 1010 | } |
| 1011 | |
| 1012 | apex_key { |
| 1013 | name: "myapex.key", |
| 1014 | public_key: "testkey.avbpubkey", |
| 1015 | private_key: "testkey.pem", |
| 1016 | } |
| 1017 | |
| 1018 | cc_library { |
| 1019 | name: "mylib", |
| 1020 | srcs: ["mylib.cpp"], |
| 1021 | system_shared_libs: [], |
| 1022 | stl: "none", |
| 1023 | } |
| 1024 | `) |
| 1025 | } |
| 1026 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1027 | func TestStaticLinking(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1028 | ctx, _ := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1029 | apex { |
| 1030 | name: "myapex", |
| 1031 | key: "myapex.key", |
| 1032 | native_shared_libs: ["mylib"], |
| 1033 | } |
| 1034 | |
| 1035 | apex_key { |
| 1036 | name: "myapex.key", |
| 1037 | public_key: "testkey.avbpubkey", |
| 1038 | private_key: "testkey.pem", |
| 1039 | } |
| 1040 | |
| 1041 | cc_library { |
| 1042 | name: "mylib", |
| 1043 | srcs: ["mylib.cpp"], |
| 1044 | system_shared_libs: [], |
| 1045 | stl: "none", |
| 1046 | stubs: { |
| 1047 | versions: ["1", "2", "3"], |
| 1048 | }, |
| 1049 | } |
| 1050 | |
| 1051 | cc_binary { |
| 1052 | name: "not_in_apex", |
| 1053 | srcs: ["mylib.cpp"], |
| 1054 | static_libs: ["mylib"], |
| 1055 | static_executable: true, |
| 1056 | system_shared_libs: [], |
| 1057 | stl: "none", |
| 1058 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1059 | `) |
| 1060 | |
| 1061 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"] |
| 1062 | |
| 1063 | // Ensure that not_in_apex is linking with the static variant of mylib |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 1064 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1065 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1066 | |
| 1067 | func TestKeys(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1068 | ctx, _ := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1069 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1070 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1071 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1072 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1073 | native_shared_libs: ["mylib"], |
| 1074 | } |
| 1075 | |
| 1076 | cc_library { |
| 1077 | name: "mylib", |
| 1078 | srcs: ["mylib.cpp"], |
| 1079 | system_shared_libs: [], |
| 1080 | stl: "none", |
| 1081 | } |
| 1082 | |
| 1083 | apex_key { |
| 1084 | name: "myapex.key", |
| 1085 | public_key: "testkey.avbpubkey", |
| 1086 | private_key: "testkey.pem", |
| 1087 | } |
| 1088 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1089 | android_app_certificate { |
| 1090 | name: "myapex.certificate", |
| 1091 | certificate: "testkey", |
| 1092 | } |
| 1093 | |
| 1094 | android_app_certificate { |
| 1095 | name: "myapex.certificate.override", |
| 1096 | certificate: "testkey.override", |
| 1097 | } |
| 1098 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1099 | `) |
| 1100 | |
| 1101 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1102 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1103 | |
| 1104 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 1105 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 1106 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 1107 | } |
| 1108 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 1109 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 1110 | "vendor/foo/devkeys/testkey.pem") |
| 1111 | } |
| 1112 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1113 | // check the APK certs. It should be overridden to myapex.certificate.override |
| 1114 | certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"] |
| 1115 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1116 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 1117 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 1118 | } |
| 1119 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1120 | |
| 1121 | func TestMacro(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1122 | ctx, _ := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 1123 | apex { |
| 1124 | name: "myapex", |
| 1125 | key: "myapex.key", |
| 1126 | native_shared_libs: ["mylib"], |
| 1127 | } |
| 1128 | |
| 1129 | apex { |
| 1130 | name: "otherapex", |
| 1131 | key: "myapex.key", |
| 1132 | native_shared_libs: ["mylib"], |
| 1133 | } |
| 1134 | |
| 1135 | apex_key { |
| 1136 | name: "myapex.key", |
| 1137 | public_key: "testkey.avbpubkey", |
| 1138 | private_key: "testkey.pem", |
| 1139 | } |
| 1140 | |
| 1141 | cc_library { |
| 1142 | name: "mylib", |
| 1143 | srcs: ["mylib.cpp"], |
| 1144 | system_shared_libs: [], |
| 1145 | stl: "none", |
| 1146 | } |
| 1147 | `) |
| 1148 | |
| 1149 | // non-APEX variant does not have __ANDROID__APEX__ defined |
| 1150 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 1151 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 1152 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 1153 | |
| 1154 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 1155 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 1156 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 1157 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 1158 | |
| 1159 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 1160 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"] |
| 1161 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 1162 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 1163 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1164 | |
| 1165 | func TestHeaderLibsDependency(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1166 | ctx, _ := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1167 | apex { |
| 1168 | name: "myapex", |
| 1169 | key: "myapex.key", |
| 1170 | native_shared_libs: ["mylib"], |
| 1171 | } |
| 1172 | |
| 1173 | apex_key { |
| 1174 | name: "myapex.key", |
| 1175 | public_key: "testkey.avbpubkey", |
| 1176 | private_key: "testkey.pem", |
| 1177 | } |
| 1178 | |
| 1179 | cc_library_headers { |
| 1180 | name: "mylib_headers", |
| 1181 | export_include_dirs: ["my_include"], |
| 1182 | system_shared_libs: [], |
| 1183 | stl: "none", |
| 1184 | } |
| 1185 | |
| 1186 | cc_library { |
| 1187 | name: "mylib", |
| 1188 | srcs: ["mylib.cpp"], |
| 1189 | system_shared_libs: [], |
| 1190 | stl: "none", |
| 1191 | header_libs: ["mylib_headers"], |
| 1192 | export_header_lib_headers: ["mylib_headers"], |
| 1193 | stubs: { |
| 1194 | versions: ["1", "2", "3"], |
| 1195 | }, |
| 1196 | } |
| 1197 | |
| 1198 | cc_library { |
| 1199 | name: "otherlib", |
| 1200 | srcs: ["mylib.cpp"], |
| 1201 | system_shared_libs: [], |
| 1202 | stl: "none", |
| 1203 | shared_libs: ["mylib"], |
| 1204 | } |
| 1205 | `) |
| 1206 | |
| 1207 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 1208 | |
| 1209 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 1210 | ensureContains(t, cFlags, "-Imy_include") |
| 1211 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1212 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1213 | func TestDependenciesInApexManifest(t *testing.T) { |
| 1214 | ctx, _ := testApex(t, ` |
| 1215 | apex { |
| 1216 | name: "myapex_nodep", |
| 1217 | key: "myapex.key", |
| 1218 | native_shared_libs: ["lib_nodep"], |
| 1219 | compile_multilib: "both", |
| 1220 | file_contexts: "myapex", |
| 1221 | } |
| 1222 | |
| 1223 | apex { |
| 1224 | name: "myapex_dep", |
| 1225 | key: "myapex.key", |
| 1226 | native_shared_libs: ["lib_dep"], |
| 1227 | compile_multilib: "both", |
| 1228 | file_contexts: "myapex", |
| 1229 | } |
| 1230 | |
| 1231 | apex { |
| 1232 | name: "myapex_provider", |
| 1233 | key: "myapex.key", |
| 1234 | native_shared_libs: ["libfoo"], |
| 1235 | compile_multilib: "both", |
| 1236 | file_contexts: "myapex", |
| 1237 | } |
| 1238 | |
| 1239 | apex { |
| 1240 | name: "myapex_selfcontained", |
| 1241 | key: "myapex.key", |
| 1242 | native_shared_libs: ["lib_dep", "libfoo"], |
| 1243 | compile_multilib: "both", |
| 1244 | file_contexts: "myapex", |
| 1245 | } |
| 1246 | |
| 1247 | apex_key { |
| 1248 | name: "myapex.key", |
| 1249 | public_key: "testkey.avbpubkey", |
| 1250 | private_key: "testkey.pem", |
| 1251 | } |
| 1252 | |
| 1253 | cc_library { |
| 1254 | name: "lib_nodep", |
| 1255 | srcs: ["mylib.cpp"], |
| 1256 | system_shared_libs: [], |
| 1257 | stl: "none", |
| 1258 | } |
| 1259 | |
| 1260 | cc_library { |
| 1261 | name: "lib_dep", |
| 1262 | srcs: ["mylib.cpp"], |
| 1263 | shared_libs: ["libfoo"], |
| 1264 | system_shared_libs: [], |
| 1265 | stl: "none", |
| 1266 | } |
| 1267 | |
| 1268 | cc_library { |
| 1269 | name: "libfoo", |
| 1270 | srcs: ["mytest.cpp"], |
| 1271 | stubs: { |
| 1272 | versions: ["1"], |
| 1273 | }, |
| 1274 | system_shared_libs: [], |
| 1275 | stl: "none", |
| 1276 | } |
| 1277 | `) |
| 1278 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 1279 | var injectRule android.TestingBuildParams |
| 1280 | var provideNativeLibs, requireNativeLibs []string |
| 1281 | |
| 1282 | injectRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep").Rule("injectApexDependency") |
| 1283 | provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) |
| 1284 | requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) |
| 1285 | ensureListEmpty(t, provideNativeLibs) |
| 1286 | ensureListEmpty(t, requireNativeLibs) |
| 1287 | |
| 1288 | injectRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep").Rule("injectApexDependency") |
| 1289 | provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) |
| 1290 | requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) |
| 1291 | ensureListEmpty(t, provideNativeLibs) |
| 1292 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 1293 | |
| 1294 | injectRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider").Rule("injectApexDependency") |
| 1295 | provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) |
| 1296 | requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) |
| 1297 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 1298 | ensureListEmpty(t, requireNativeLibs) |
| 1299 | |
| 1300 | injectRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained").Rule("injectApexDependency") |
| 1301 | provideNativeLibs = names(injectRule.Args["provideNativeLibs"]) |
| 1302 | requireNativeLibs = names(injectRule.Args["requireNativeLibs"]) |
| 1303 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 1304 | ensureListEmpty(t, requireNativeLibs) |
| 1305 | } |
| 1306 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1307 | func TestNonTestApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1308 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1309 | apex { |
| 1310 | name: "myapex", |
| 1311 | key: "myapex.key", |
| 1312 | native_shared_libs: ["mylib_common"], |
| 1313 | } |
| 1314 | |
| 1315 | apex_key { |
| 1316 | name: "myapex.key", |
| 1317 | public_key: "testkey.avbpubkey", |
| 1318 | private_key: "testkey.pem", |
| 1319 | } |
| 1320 | |
| 1321 | cc_library { |
| 1322 | name: "mylib_common", |
| 1323 | srcs: ["mylib.cpp"], |
| 1324 | system_shared_libs: [], |
| 1325 | stl: "none", |
| 1326 | } |
| 1327 | `) |
| 1328 | |
| 1329 | module := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 1330 | apexRule := module.Rule("apexRule") |
| 1331 | copyCmds := apexRule.Args["copy_commands"] |
| 1332 | |
| 1333 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 1334 | t.Log("Apex was a test apex!") |
| 1335 | t.Fail() |
| 1336 | } |
| 1337 | // Ensure that main rule creates an output |
| 1338 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 1339 | |
| 1340 | // Ensure that apex variant is created for the direct dep |
| 1341 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex") |
| 1342 | |
| 1343 | // Ensure that both direct and indirect deps are copied into apex |
| 1344 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 1345 | |
| 1346 | // Ensure that the platform variant ends with _core_shared |
| 1347 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared") |
| 1348 | |
| 1349 | if !android.InAnyApex("mylib_common") { |
| 1350 | t.Log("Found mylib_common not in any apex!") |
| 1351 | t.Fail() |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | func TestTestApex(t *testing.T) { |
| 1356 | if android.InAnyApex("mylib_common_test") { |
| 1357 | 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!") |
| 1358 | } |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1359 | ctx, _ := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 1360 | apex_test { |
| 1361 | name: "myapex", |
| 1362 | key: "myapex.key", |
| 1363 | native_shared_libs: ["mylib_common_test"], |
| 1364 | } |
| 1365 | |
| 1366 | apex_key { |
| 1367 | name: "myapex.key", |
| 1368 | public_key: "testkey.avbpubkey", |
| 1369 | private_key: "testkey.pem", |
| 1370 | } |
| 1371 | |
| 1372 | cc_library { |
| 1373 | name: "mylib_common_test", |
| 1374 | srcs: ["mylib.cpp"], |
| 1375 | system_shared_libs: [], |
| 1376 | stl: "none", |
| 1377 | } |
| 1378 | `) |
| 1379 | |
| 1380 | module := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 1381 | apexRule := module.Rule("apexRule") |
| 1382 | copyCmds := apexRule.Args["copy_commands"] |
| 1383 | |
| 1384 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 1385 | t.Log("Apex was not a test apex!") |
| 1386 | t.Fail() |
| 1387 | } |
| 1388 | // Ensure that main rule creates an output |
| 1389 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 1390 | |
| 1391 | // Ensure that apex variant is created for the direct dep |
| 1392 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex") |
| 1393 | |
| 1394 | // Ensure that both direct and indirect deps are copied into apex |
| 1395 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 1396 | |
| 1397 | // Ensure that the platform variant ends with _core_shared |
| 1398 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared") |
| 1399 | |
| 1400 | if android.InAnyApex("mylib_common_test") { |
| 1401 | t.Log("Found mylib_common_test in some apex!") |
| 1402 | t.Fail() |
| 1403 | } |
| 1404 | } |
| 1405 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1406 | func TestApexWithTarget(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1407 | ctx, _ := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 1408 | apex { |
| 1409 | name: "myapex", |
| 1410 | key: "myapex.key", |
| 1411 | multilib: { |
| 1412 | first: { |
| 1413 | native_shared_libs: ["mylib_common"], |
| 1414 | } |
| 1415 | }, |
| 1416 | target: { |
| 1417 | android: { |
| 1418 | multilib: { |
| 1419 | first: { |
| 1420 | native_shared_libs: ["mylib"], |
| 1421 | } |
| 1422 | } |
| 1423 | }, |
| 1424 | host: { |
| 1425 | multilib: { |
| 1426 | first: { |
| 1427 | native_shared_libs: ["mylib2"], |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | apex_key { |
| 1435 | name: "myapex.key", |
| 1436 | public_key: "testkey.avbpubkey", |
| 1437 | private_key: "testkey.pem", |
| 1438 | } |
| 1439 | |
| 1440 | cc_library { |
| 1441 | name: "mylib", |
| 1442 | srcs: ["mylib.cpp"], |
| 1443 | system_shared_libs: [], |
| 1444 | stl: "none", |
| 1445 | } |
| 1446 | |
| 1447 | cc_library { |
| 1448 | name: "mylib_common", |
| 1449 | srcs: ["mylib.cpp"], |
| 1450 | system_shared_libs: [], |
| 1451 | stl: "none", |
| 1452 | compile_multilib: "first", |
| 1453 | } |
| 1454 | |
| 1455 | cc_library { |
| 1456 | name: "mylib2", |
| 1457 | srcs: ["mylib.cpp"], |
| 1458 | system_shared_libs: [], |
| 1459 | stl: "none", |
| 1460 | compile_multilib: "first", |
| 1461 | } |
| 1462 | `) |
| 1463 | |
| 1464 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1465 | copyCmds := apexRule.Args["copy_commands"] |
| 1466 | |
| 1467 | // Ensure that main rule creates an output |
| 1468 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 1469 | |
| 1470 | // Ensure that apex variant is created for the direct dep |
| 1471 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| 1472 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex") |
| 1473 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
| 1474 | |
| 1475 | // Ensure that both direct and indirect deps are copied into apex |
| 1476 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1477 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 1478 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1479 | |
| 1480 | // Ensure that the platform variant ends with _core_shared |
| 1481 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 1482 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared") |
| 1483 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
| 1484 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1485 | |
| 1486 | func TestApexWithShBinary(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1487 | ctx, _ := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 1488 | apex { |
| 1489 | name: "myapex", |
| 1490 | key: "myapex.key", |
| 1491 | binaries: ["myscript"], |
| 1492 | } |
| 1493 | |
| 1494 | apex_key { |
| 1495 | name: "myapex.key", |
| 1496 | public_key: "testkey.avbpubkey", |
| 1497 | private_key: "testkey.pem", |
| 1498 | } |
| 1499 | |
| 1500 | sh_binary { |
| 1501 | name: "myscript", |
| 1502 | src: "mylib.cpp", |
| 1503 | filename: "myscript.sh", |
| 1504 | sub_dir: "script", |
| 1505 | } |
| 1506 | `) |
| 1507 | |
| 1508 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1509 | copyCmds := apexRule.Args["copy_commands"] |
| 1510 | |
| 1511 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 1512 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1513 | |
| 1514 | func TestApexInProductPartition(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1515 | ctx, _ := testApex(t, ` |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1516 | apex { |
| 1517 | name: "myapex", |
| 1518 | key: "myapex.key", |
| 1519 | native_shared_libs: ["mylib"], |
| 1520 | product_specific: true, |
| 1521 | } |
| 1522 | |
| 1523 | apex_key { |
| 1524 | name: "myapex.key", |
| 1525 | public_key: "testkey.avbpubkey", |
| 1526 | private_key: "testkey.pem", |
| 1527 | product_specific: true, |
| 1528 | } |
| 1529 | |
| 1530 | cc_library { |
| 1531 | name: "mylib", |
| 1532 | srcs: ["mylib.cpp"], |
| 1533 | system_shared_libs: [], |
| 1534 | stl: "none", |
| 1535 | } |
| 1536 | `) |
| 1537 | |
| 1538 | apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle) |
| 1539 | expected := "target/product/test_device/product/apex" |
| 1540 | actual := apex.installDir.RelPathString() |
| 1541 | if actual != expected { |
| 1542 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 1543 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 1544 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 1545 | |
| 1546 | func TestApexKeyFromOtherModule(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1547 | ctx, _ := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 1548 | apex_key { |
| 1549 | name: "myapex.key", |
| 1550 | public_key: ":my.avbpubkey", |
| 1551 | private_key: ":my.pem", |
| 1552 | product_specific: true, |
| 1553 | } |
| 1554 | |
| 1555 | filegroup { |
| 1556 | name: "my.avbpubkey", |
| 1557 | srcs: ["testkey2.avbpubkey"], |
| 1558 | } |
| 1559 | |
| 1560 | filegroup { |
| 1561 | name: "my.pem", |
| 1562 | srcs: ["testkey2.pem"], |
| 1563 | } |
| 1564 | `) |
| 1565 | |
| 1566 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 1567 | expected_pubkey := "testkey2.avbpubkey" |
| 1568 | actual_pubkey := apex_key.public_key_file.String() |
| 1569 | if actual_pubkey != expected_pubkey { |
| 1570 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 1571 | } |
| 1572 | expected_privkey := "testkey2.pem" |
| 1573 | actual_privkey := apex_key.private_key_file.String() |
| 1574 | if actual_privkey != expected_privkey { |
| 1575 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 1576 | } |
| 1577 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1578 | |
| 1579 | func TestPrebuilt(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1580 | ctx, _ := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1581 | prebuilt_apex { |
| 1582 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1583 | arch: { |
| 1584 | arm64: { |
| 1585 | src: "myapex-arm64.apex", |
| 1586 | }, |
| 1587 | arm: { |
| 1588 | src: "myapex-arm.apex", |
| 1589 | }, |
| 1590 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | `) |
| 1593 | |
| 1594 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 1595 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 1596 | expectedInput := "myapex-arm64.apex" |
| 1597 | if prebuilt.inputApex.String() != expectedInput { |
| 1598 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 1599 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 1600 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1601 | |
| 1602 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1603 | ctx, _ := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 1604 | prebuilt_apex { |
| 1605 | name: "myapex", |
| 1606 | src: "myapex-arm.apex", |
| 1607 | filename: "notmyapex.apex", |
| 1608 | } |
| 1609 | `) |
| 1610 | |
| 1611 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 1612 | |
| 1613 | expected := "notmyapex.apex" |
| 1614 | if p.installFilename != expected { |
| 1615 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 1616 | } |
| 1617 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 1618 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1619 | func TestPrebuiltOverrides(t *testing.T) { |
| 1620 | ctx, config := testApex(t, ` |
| 1621 | prebuilt_apex { |
| 1622 | name: "myapex.prebuilt", |
| 1623 | src: "myapex-arm.apex", |
| 1624 | overrides: [ |
| 1625 | "myapex", |
| 1626 | ], |
| 1627 | } |
| 1628 | `) |
| 1629 | |
| 1630 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 1631 | |
| 1632 | expected := []string{"myapex"} |
| 1633 | actual := android.AndroidMkEntriesForTest(t, config, "", p).EntryMap["LOCAL_OVERRIDES_PACKAGES"] |
| 1634 | if !reflect.DeepEqual(actual, expected) { |
| 1635 | t.Errorf("Incorrect LOCAL_OVERRIDES_PACKAGES value '%s', expected '%s'", actual, expected) |
| 1636 | } |
| 1637 | } |
| 1638 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1639 | func TestApexWithTests(t *testing.T) { |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1640 | ctx, config := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1641 | apex_test { |
| 1642 | name: "myapex", |
| 1643 | key: "myapex.key", |
| 1644 | tests: [ |
| 1645 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1646 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1647 | ], |
| 1648 | } |
| 1649 | |
| 1650 | apex_key { |
| 1651 | name: "myapex.key", |
| 1652 | public_key: "testkey.avbpubkey", |
| 1653 | private_key: "testkey.pem", |
| 1654 | } |
| 1655 | |
| 1656 | cc_test { |
| 1657 | name: "mytest", |
| 1658 | gtest: false, |
| 1659 | srcs: ["mytest.cpp"], |
| 1660 | relative_install_path: "test", |
| 1661 | system_shared_libs: [], |
| 1662 | static_executable: true, |
| 1663 | stl: "none", |
| 1664 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1665 | |
| 1666 | cc_test { |
| 1667 | name: "mytests", |
| 1668 | gtest: false, |
| 1669 | srcs: [ |
| 1670 | "mytest1.cpp", |
| 1671 | "mytest2.cpp", |
| 1672 | "mytest3.cpp", |
| 1673 | ], |
| 1674 | test_per_src: true, |
| 1675 | relative_install_path: "test", |
| 1676 | system_shared_libs: [], |
| 1677 | static_executable: true, |
| 1678 | stl: "none", |
| 1679 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1680 | `) |
| 1681 | |
| 1682 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1683 | copyCmds := apexRule.Args["copy_commands"] |
| 1684 | |
| 1685 | // Ensure that test dep is copied into apex. |
| 1686 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1687 | |
| 1688 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 1689 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 1690 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 1691 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1692 | |
| 1693 | // Ensure the module is correctly translated. |
| 1694 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle) |
| 1695 | data := android.AndroidMkDataForTest(t, config, "", apexBundle) |
| 1696 | name := apexBundle.BaseModuleName() |
| 1697 | prefix := "TARGET_" |
| 1698 | var builder strings.Builder |
| 1699 | data.Custom(&builder, name, prefix, "", data) |
| 1700 | androidMk := builder.String() |
| 1701 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest\n") |
| 1702 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest1\n") |
| 1703 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest2\n") |
| 1704 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex.mytest3\n") |
| 1705 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_manifest.json\n") |
| 1706 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex.apex_pubkey\n") |
| 1707 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1710 | func TestApexUsesOtherApex(t *testing.T) { |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 1711 | ctx, _ := testApex(t, ` |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 1712 | apex { |
| 1713 | name: "myapex", |
| 1714 | key: "myapex.key", |
| 1715 | native_shared_libs: ["mylib"], |
| 1716 | uses: ["commonapex"], |
| 1717 | } |
| 1718 | |
| 1719 | apex { |
| 1720 | name: "commonapex", |
| 1721 | key: "myapex.key", |
| 1722 | native_shared_libs: ["libcommon"], |
| 1723 | provide_cpp_shared_libs: true, |
| 1724 | } |
| 1725 | |
| 1726 | apex_key { |
| 1727 | name: "myapex.key", |
| 1728 | public_key: "testkey.avbpubkey", |
| 1729 | private_key: "testkey.pem", |
| 1730 | } |
| 1731 | |
| 1732 | cc_library { |
| 1733 | name: "mylib", |
| 1734 | srcs: ["mylib.cpp"], |
| 1735 | shared_libs: ["libcommon"], |
| 1736 | system_shared_libs: [], |
| 1737 | stl: "none", |
| 1738 | } |
| 1739 | |
| 1740 | cc_library { |
| 1741 | name: "libcommon", |
| 1742 | srcs: ["mylib_common.cpp"], |
| 1743 | system_shared_libs: [], |
| 1744 | stl: "none", |
| 1745 | } |
| 1746 | `) |
| 1747 | |
| 1748 | module1 := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 1749 | apexRule1 := module1.Rule("apexRule") |
| 1750 | copyCmds1 := apexRule1.Args["copy_commands"] |
| 1751 | |
| 1752 | module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex") |
| 1753 | apexRule2 := module2.Rule("apexRule") |
| 1754 | copyCmds2 := apexRule2.Args["copy_commands"] |
| 1755 | |
| 1756 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| 1757 | ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_core_shared_commonapex") |
| 1758 | ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so") |
| 1759 | ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so") |
| 1760 | ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so") |
| 1761 | } |
| 1762 | |
| 1763 | func TestApexUsesFailsIfNotProvided(t *testing.T) { |
| 1764 | testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, ` |
| 1765 | apex { |
| 1766 | name: "myapex", |
| 1767 | key: "myapex.key", |
| 1768 | uses: ["commonapex"], |
| 1769 | } |
| 1770 | |
| 1771 | apex { |
| 1772 | name: "commonapex", |
| 1773 | key: "myapex.key", |
| 1774 | } |
| 1775 | |
| 1776 | apex_key { |
| 1777 | name: "myapex.key", |
| 1778 | public_key: "testkey.avbpubkey", |
| 1779 | private_key: "testkey.pem", |
| 1780 | } |
| 1781 | `) |
| 1782 | testApexError(t, `uses: "commonapex" is not a provider`, ` |
| 1783 | apex { |
| 1784 | name: "myapex", |
| 1785 | key: "myapex.key", |
| 1786 | uses: ["commonapex"], |
| 1787 | } |
| 1788 | |
| 1789 | cc_library { |
| 1790 | name: "commonapex", |
| 1791 | system_shared_libs: [], |
| 1792 | stl: "none", |
| 1793 | } |
| 1794 | |
| 1795 | apex_key { |
| 1796 | name: "myapex.key", |
| 1797 | public_key: "testkey.avbpubkey", |
| 1798 | private_key: "testkey.pem", |
| 1799 | } |
| 1800 | `) |
| 1801 | } |
| 1802 | |
| 1803 | func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) { |
| 1804 | testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, ` |
| 1805 | apex { |
| 1806 | name: "myapex", |
| 1807 | key: "myapex.key", |
| 1808 | use_vendor: true, |
| 1809 | uses: ["commonapex"], |
| 1810 | } |
| 1811 | |
| 1812 | apex { |
| 1813 | name: "commonapex", |
| 1814 | key: "myapex.key", |
| 1815 | provide_cpp_shared_libs: true, |
| 1816 | } |
| 1817 | |
| 1818 | apex_key { |
| 1819 | name: "myapex.key", |
| 1820 | public_key: "testkey.avbpubkey", |
| 1821 | private_key: "testkey.pem", |
| 1822 | } |
| 1823 | `) |
| 1824 | } |
| 1825 | |
Jiyong Park | 4f7dd9b | 2019-08-12 10:37:49 +0900 | [diff] [blame] | 1826 | func TestApexUsesFailsIfUseNoApex(t *testing.T) { |
| 1827 | testApexError(t, `tries to include no_apex module mylib2`, ` |
| 1828 | apex { |
| 1829 | name: "commonapex", |
| 1830 | key: "myapex.key", |
| 1831 | native_shared_libs: ["mylib"], |
| 1832 | } |
| 1833 | |
| 1834 | apex_key { |
| 1835 | name: "myapex.key", |
| 1836 | public_key: "testkey.avbpubkey", |
| 1837 | private_key: "testkey.pem", |
| 1838 | } |
| 1839 | |
| 1840 | cc_library { |
| 1841 | name: "mylib", |
| 1842 | srcs: ["mylib.cpp"], |
| 1843 | shared_libs: ["mylib2"], |
| 1844 | system_shared_libs: [], |
| 1845 | stl: "none", |
| 1846 | } |
| 1847 | |
| 1848 | cc_library { |
| 1849 | name: "mylib2", |
| 1850 | srcs: ["mylib.cpp"], |
| 1851 | system_shared_libs: [], |
| 1852 | stl: "none", |
| 1853 | no_apex: true, |
| 1854 | } |
| 1855 | `) |
| 1856 | |
Sundong Ahn | 2db7f46 | 2019-08-27 18:53:12 +0900 | [diff] [blame] | 1857 | testApexError(t, `tries to include no_apex module mylib2`, ` |
| 1858 | apex { |
| 1859 | name: "commonapex", |
| 1860 | key: "myapex.key", |
| 1861 | native_shared_libs: ["mylib"], |
| 1862 | } |
| 1863 | |
| 1864 | apex_key { |
| 1865 | name: "myapex.key", |
| 1866 | public_key: "testkey.avbpubkey", |
| 1867 | private_key: "testkey.pem", |
| 1868 | } |
| 1869 | |
| 1870 | cc_library { |
| 1871 | name: "mylib", |
| 1872 | srcs: ["mylib.cpp"], |
| 1873 | static_libs: ["mylib2"], |
| 1874 | system_shared_libs: [], |
| 1875 | stl: "none", |
| 1876 | } |
| 1877 | |
| 1878 | cc_library { |
| 1879 | name: "mylib2", |
| 1880 | srcs: ["mylib.cpp"], |
| 1881 | system_shared_libs: [], |
| 1882 | stl: "none", |
| 1883 | no_apex: true, |
| 1884 | } |
| 1885 | `) |
| 1886 | |
Jiyong Park | 4f7dd9b | 2019-08-12 10:37:49 +0900 | [diff] [blame] | 1887 | ctx, _ := testApex(t, ` |
| 1888 | apex { |
| 1889 | name: "myapex", |
| 1890 | key: "myapex.key", |
| 1891 | native_shared_libs: ["mylib"], |
| 1892 | } |
| 1893 | |
| 1894 | apex_key { |
| 1895 | name: "myapex.key", |
| 1896 | public_key: "testkey.avbpubkey", |
| 1897 | private_key: "testkey.pem", |
| 1898 | } |
| 1899 | |
| 1900 | cc_library { |
| 1901 | name: "mylib", |
| 1902 | srcs: ["mylib.cpp"], |
| 1903 | shared_libs: ["mylib2"], |
| 1904 | system_shared_libs: [], |
| 1905 | stl: "none", |
| 1906 | } |
| 1907 | |
| 1908 | cc_library { |
| 1909 | name: "mylib2", |
| 1910 | srcs: ["mylib.cpp"], |
| 1911 | shared_libs: ["mylib3"], |
| 1912 | system_shared_libs: [], |
| 1913 | stl: "none", |
| 1914 | stubs: { |
| 1915 | versions: ["1", "2", "3"], |
| 1916 | }, |
| 1917 | } |
| 1918 | |
| 1919 | cc_library { |
| 1920 | name: "mylib3", |
| 1921 | srcs: ["mylib.cpp"], |
| 1922 | system_shared_libs: [], |
| 1923 | stl: "none", |
| 1924 | no_apex: true, |
| 1925 | } |
| 1926 | `) |
| 1927 | |
| 1928 | module := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 1929 | apexRule := module.Rule("apexRule") |
| 1930 | copyCmds := apexRule.Args["copy_commands"] |
| 1931 | |
| 1932 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1933 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1934 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 1935 | |
| 1936 | } |
| 1937 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 1938 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 1939 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 1940 | apex { |
| 1941 | name: "myapex", |
| 1942 | key: "myapex.key", |
| 1943 | native_shared_libs: ["libfoo"], |
| 1944 | } |
| 1945 | |
| 1946 | apex_key { |
| 1947 | name: "myapex.key", |
| 1948 | public_key: "testkey.avbpubkey", |
| 1949 | private_key: "testkey.pem", |
| 1950 | } |
| 1951 | |
| 1952 | cc_library { |
| 1953 | name: "libfoo", |
| 1954 | stl: "none", |
| 1955 | system_shared_libs: [], |
| 1956 | enabled: false, |
| 1957 | } |
| 1958 | `) |
| 1959 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 1960 | apex { |
| 1961 | name: "myapex", |
| 1962 | key: "myapex.key", |
| 1963 | java_libs: ["myjar"], |
| 1964 | } |
| 1965 | |
| 1966 | apex_key { |
| 1967 | name: "myapex.key", |
| 1968 | public_key: "testkey.avbpubkey", |
| 1969 | private_key: "testkey.pem", |
| 1970 | } |
| 1971 | |
| 1972 | java_library { |
| 1973 | name: "myjar", |
| 1974 | srcs: ["foo/bar/MyClass.java"], |
| 1975 | sdk_version: "none", |
| 1976 | system_modules: "none", |
| 1977 | compile_dex: true, |
| 1978 | enabled: false, |
| 1979 | } |
| 1980 | `) |
| 1981 | } |
| 1982 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame^] | 1983 | func TestApexWithApps(t *testing.T) { |
| 1984 | ctx, _ := testApex(t, ` |
| 1985 | apex { |
| 1986 | name: "myapex", |
| 1987 | key: "myapex.key", |
| 1988 | apps: [ |
| 1989 | "AppFoo", |
| 1990 | ], |
| 1991 | } |
| 1992 | |
| 1993 | apex_key { |
| 1994 | name: "myapex.key", |
| 1995 | public_key: "testkey.avbpubkey", |
| 1996 | private_key: "testkey.pem", |
| 1997 | } |
| 1998 | |
| 1999 | android_app { |
| 2000 | name: "AppFoo", |
| 2001 | srcs: ["foo/bar/MyClass.java"], |
| 2002 | sdk_version: "none", |
| 2003 | system_modules: "none", |
| 2004 | } |
| 2005 | `) |
| 2006 | |
| 2007 | module := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 2008 | apexRule := module.Rule("apexRule") |
| 2009 | copyCmds := apexRule.Args["copy_commands"] |
| 2010 | |
| 2011 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
| 2012 | |
| 2013 | } |
| 2014 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 2015 | func TestMain(m *testing.M) { |
| 2016 | run := func() int { |
| 2017 | setUp() |
| 2018 | defer tearDown() |
| 2019 | |
| 2020 | return m.Run() |
| 2021 | } |
| 2022 | |
| 2023 | os.Exit(run()) |
| 2024 | } |