blob: b7dd7fb5f6481dbe02396e35073e2f05d97b2483 [file] [log] [blame]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001// 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
15package apex
16
17import (
Jiyong Park25fc6a92018-11-18 18:02:45 +090018 "io/ioutil"
19 "os"
Jooyung Han39edb6c2019-11-06 16:53:07 +090020 "path"
Jaewoong Jung22f7d182019-07-16 18:25:41 -070021 "reflect"
Jooyung Han31c470b2019-10-18 16:26:59 +090022 "sort"
Jiyong Park25fc6a92018-11-18 18:02:45 +090023 "strings"
24 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090025
26 "github.com/google/blueprint/proptools"
27
28 "android/soong/android"
29 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090030 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090031)
32
Jaewoong Jung14f5ff62019-06-18 13:09:13 -070033var buildDir string
34
Jooyung Hand3639552019-08-09 12:57:43 +090035// names returns name list from white space separated string
36func names(s string) (ns []string) {
37 for _, n := range strings.Split(s, " ") {
38 if len(n) > 0 {
39 ns = append(ns, n)
40 }
41 }
42 return
43}
44
Jooyung Han344d5432019-08-23 11:17:39 +090045func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) {
46 t.Helper()
47 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090048 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
49 if len(errs) > 0 {
50 android.FailIfNoMatchingErrors(t, pattern, errs)
51 return
52 }
53 _, errs = ctx.PrepareBuildActions(config)
54 if len(errs) > 0 {
55 android.FailIfNoMatchingErrors(t, pattern, errs)
56 return
57 }
58
59 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
60}
61
Jooyung Han344d5432019-08-23 11:17:39 +090062func testApex(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
63 t.Helper()
64 ctx, config := testApexContext(t, bp, handlers...)
Jooyung Han5c998b92019-06-27 11:30:33 +090065 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
66 android.FailIfErrored(t, errs)
67 _, errs = ctx.PrepareBuildActions(config)
68 android.FailIfErrored(t, errs)
Jaewoong Jung22f7d182019-07-16 18:25:41 -070069 return ctx, config
Jooyung Han5c998b92019-06-27 11:30:33 +090070}
71
Jooyung Han344d5432019-08-23 11:17:39 +090072type testCustomizer func(fs map[string][]byte, config android.Config)
73
74func withFiles(files map[string][]byte) testCustomizer {
75 return func(fs map[string][]byte, config android.Config) {
76 for k, v := range files {
77 fs[k] = v
78 }
79 }
80}
81
82func withTargets(targets map[android.OsType][]android.Target) testCustomizer {
83 return func(fs map[string][]byte, config android.Config) {
84 for k, v := range targets {
85 config.Targets[k] = v
86 }
87 }
88}
89
Jooyung Han31c470b2019-10-18 16:26:59 +090090func withBinder32bit(fs map[string][]byte, config android.Config) {
91 config.TestProductVariables.Binder32bit = proptools.BoolPtr(true)
92}
93
Jiyong Park7cd10e32020-01-14 09:22:18 +090094func withUnbundledBuild(fs map[string][]byte, config android.Config) {
95 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
96}
97
Jooyung Han344d5432019-08-23 11:17:39 +090098func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*android.TestContext, android.Config) {
Jooyung Han671f1ce2019-12-17 12:47:13 +090099 android.ClearApexDependency()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900100
101 bp = bp + `
102 toolchain_library {
103 name: "libcompiler_rt-extras",
104 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900105 vendor_available: true,
106 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900107 }
108
109 toolchain_library {
110 name: "libatomic",
111 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900112 vendor_available: true,
113 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900114 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900115 }
116
117 toolchain_library {
118 name: "libgcc",
119 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900120 vendor_available: true,
121 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900122 }
123
124 toolchain_library {
Yi Kongacee27c2019-03-29 20:05:14 -0700125 name: "libgcc_stripped",
126 src: "",
127 vendor_available: true,
128 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900129 native_bridge_supported: true,
Yi Kongacee27c2019-03-29 20:05:14 -0700130 }
131
132 toolchain_library {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 name: "libclang_rt.builtins-aarch64-android",
134 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900135 vendor_available: true,
136 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900137 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900138 }
139
140 toolchain_library {
141 name: "libclang_rt.builtins-arm-android",
142 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900143 vendor_available: true,
144 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900145 native_bridge_supported: true,
146 }
147
148 toolchain_library {
149 name: "libclang_rt.builtins-x86_64-android",
150 src: "",
151 vendor_available: true,
152 recovery_available: true,
153 native_bridge_supported: true,
154 }
155
156 toolchain_library {
157 name: "libclang_rt.builtins-i686-android",
158 src: "",
159 vendor_available: true,
160 recovery_available: true,
161 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900162 }
163
164 cc_object {
165 name: "crtbegin_so",
166 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900167 vendor_available: true,
168 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900169 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900170 }
171
172 cc_object {
173 name: "crtend_so",
174 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900175 vendor_available: true,
176 recovery_available: true,
Jooyung Han344d5432019-08-23 11:17:39 +0900177 native_bridge_supported: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900178 }
179
Alex Light3d673592019-01-18 14:37:31 -0800180 cc_object {
181 name: "crtbegin_static",
182 stl: "none",
183 }
184
185 cc_object {
186 name: "crtend_android",
187 stl: "none",
188 }
189
Jiyong Parkda6eb592018-12-19 17:12:36 +0900190 llndk_library {
191 name: "libc",
192 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900193 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900194 }
195
196 llndk_library {
197 name: "libm",
198 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900199 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900200 }
201
202 llndk_library {
203 name: "libdl",
204 symbol_file: "",
Jooyung Han344d5432019-08-23 11:17:39 +0900205 native_bridge_supported: true,
Jiyong Parkda6eb592018-12-19 17:12:36 +0900206 }
Jooyung Han54aca7b2019-11-20 02:26:02 +0900207
208 filegroup {
209 name: "myapex-file_contexts",
210 srcs: [
211 "system/sepolicy/apex/myapex-file_contexts",
212 ],
213 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900214 `
Colin Cross98be1bb2019-12-13 20:41:13 -0800215
Dario Frenicde2a032019-10-27 00:29:22 +0100216 bp = bp + java.GatherRequiredDepsForTest()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900217
Jooyung Han344d5432019-08-23 11:17:39 +0900218 fs := map[string][]byte{
Jooyung Han54aca7b2019-11-20 02:26:02 +0900219 "a.java": nil,
220 "PrebuiltAppFoo.apk": nil,
221 "PrebuiltAppFooPriv.apk": nil,
222 "build/make/target/product/security": nil,
223 "apex_manifest.json": nil,
224 "AndroidManifest.xml": nil,
225 "system/sepolicy/apex/myapex-file_contexts": nil,
Jiyong Park83dc74b2020-01-14 18:38:44 +0900226 "system/sepolicy/apex/myapex2-file_contexts": nil,
Jooyung Han54aca7b2019-11-20 02:26:02 +0900227 "system/sepolicy/apex/otherapex-file_contexts": nil,
228 "system/sepolicy/apex/commonapex-file_contexts": nil,
229 "system/sepolicy/apex/com.android.vndk-file_contexts": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -0800230 "mylib.cpp": nil,
231 "mylib_common.cpp": nil,
232 "mytest.cpp": nil,
233 "mytest1.cpp": nil,
234 "mytest2.cpp": nil,
235 "mytest3.cpp": nil,
236 "myprebuilt": nil,
237 "my_include": nil,
238 "foo/bar/MyClass.java": nil,
239 "prebuilt.jar": nil,
240 "vendor/foo/devkeys/test.x509.pem": nil,
241 "vendor/foo/devkeys/test.pk8": nil,
242 "testkey.x509.pem": nil,
243 "testkey.pk8": nil,
244 "testkey.override.x509.pem": nil,
245 "testkey.override.pk8": nil,
246 "vendor/foo/devkeys/testkey.avbpubkey": nil,
247 "vendor/foo/devkeys/testkey.pem": nil,
248 "NOTICE": nil,
249 "custom_notice": nil,
250 "testkey2.avbpubkey": nil,
251 "testkey2.pem": nil,
252 "myapex-arm64.apex": nil,
253 "myapex-arm.apex": nil,
254 "frameworks/base/api/current.txt": nil,
255 "framework/aidl/a.aidl": nil,
256 "build/make/core/proguard.flags": nil,
257 "build/make/core/proguard_basic_keeps.flags": nil,
258 "dummy.txt": nil,
Jooyung Han344d5432019-08-23 11:17:39 +0900259 }
260
261 for _, handler := range handlers {
Colin Cross98be1bb2019-12-13 20:41:13 -0800262 // The fs now needs to be populated before creating the config, call handlers twice
263 // for now, once to get any fs changes, and later after the config was created to
264 // set product variables or targets.
265 tempConfig := android.TestArchConfig(buildDir, nil, bp, fs)
266 handler(fs, tempConfig)
Jooyung Han344d5432019-08-23 11:17:39 +0900267 }
268
Colin Cross98be1bb2019-12-13 20:41:13 -0800269 config := android.TestArchConfig(buildDir, nil, bp, fs)
270 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
271 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
272 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
273 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q")
274 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false)
275 config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
276
277 for _, handler := range handlers {
278 // The fs now needs to be populated before creating the config, call handlers twice
279 // for now, earlier to get any fs changes, and now after the config was created to
280 // set product variables or targets.
281 tempFS := map[string][]byte{}
282 handler(tempFS, config)
283 }
284
285 ctx := android.NewTestArchContext()
286 ctx.RegisterModuleType("apex", BundleFactory)
287 ctx.RegisterModuleType("apex_test", testApexBundleFactory)
288 ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
289 ctx.RegisterModuleType("apex_key", ApexKeyFactory)
290 ctx.RegisterModuleType("apex_defaults", defaultsFactory)
291 ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
292 ctx.RegisterModuleType("override_apex", overrideApexFactory)
293
Jooyung Hana57af4a2020-01-23 05:36:59 +0000294 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
295 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
296
Paul Duffin77980a82019-12-19 16:01:36 +0000297 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross98be1bb2019-12-13 20:41:13 -0800298 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800299 ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
300 ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800301 ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
302 ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800303 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000304 java.RegisterJavaBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000305 java.RegisterSystemModulesBuildComponents(ctx)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000306 java.RegisterAppBuildComponents(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900307 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800308
Colin Cross98be1bb2019-12-13 20:41:13 -0800309 ctx.PreDepsMutators(RegisterPreDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800310 ctx.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800311
312 ctx.Register(config)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900313
Jooyung Han5c998b92019-06-27 11:30:33 +0900314 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900315}
316
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700317func setUp() {
318 var err error
319 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900320 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700321 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900322 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900323}
324
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700325func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900326 os.RemoveAll(buildDir)
327}
328
329// ensure that 'result' contains 'expected'
330func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900331 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900332 if !strings.Contains(result, expected) {
333 t.Errorf("%q is not found in %q", expected, result)
334 }
335}
336
337// ensures that 'result' does not contain 'notExpected'
338func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900339 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900340 if strings.Contains(result, notExpected) {
341 t.Errorf("%q is found in %q", notExpected, result)
342 }
343}
344
345func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900346 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900347 if !android.InList(expected, result) {
348 t.Errorf("%q is not found in %v", expected, result)
349 }
350}
351
352func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900353 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900354 if android.InList(notExpected, result) {
355 t.Errorf("%q is found in %v", notExpected, result)
356 }
357}
358
Jooyung Hane1633032019-08-01 17:41:43 +0900359func ensureListEmpty(t *testing.T, result []string) {
360 t.Helper()
361 if len(result) > 0 {
362 t.Errorf("%q is expected to be empty", result)
363 }
364}
365
Jiyong Park25fc6a92018-11-18 18:02:45 +0900366// Minimal test
367func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700368 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900369 apex_defaults {
370 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900371 manifest: ":myapex.manifest",
372 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900373 key: "myapex.key",
374 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800375 multilib: {
376 both: {
377 binaries: ["foo",],
378 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900379 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900380 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900381 }
382
Jiyong Park30ca9372019-02-07 16:27:23 +0900383 apex {
384 name: "myapex",
385 defaults: ["myapex-defaults"],
386 }
387
Jiyong Park25fc6a92018-11-18 18:02:45 +0900388 apex_key {
389 name: "myapex.key",
390 public_key: "testkey.avbpubkey",
391 private_key: "testkey.pem",
392 }
393
Jiyong Park809bb722019-02-13 21:33:49 +0900394 filegroup {
395 name: "myapex.manifest",
396 srcs: ["apex_manifest.json"],
397 }
398
399 filegroup {
400 name: "myapex.androidmanifest",
401 srcs: ["AndroidManifest.xml"],
402 }
403
Jiyong Park25fc6a92018-11-18 18:02:45 +0900404 cc_library {
405 name: "mylib",
406 srcs: ["mylib.cpp"],
407 shared_libs: ["mylib2"],
408 system_shared_libs: [],
409 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000410 // TODO: remove //apex_available:platform
411 apex_available: [
412 "//apex_available:platform",
413 "myapex",
414 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900415 }
416
Alex Light3d673592019-01-18 14:37:31 -0800417 cc_binary {
418 name: "foo",
419 srcs: ["mylib.cpp"],
420 compile_multilib: "both",
421 multilib: {
422 lib32: {
423 suffix: "32",
424 },
425 lib64: {
426 suffix: "64",
427 },
428 },
429 symlinks: ["foo_link_"],
430 symlink_preferred_arch: true,
431 system_shared_libs: [],
432 static_executable: true,
433 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000434 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800435 }
436
Jiyong Park25fc6a92018-11-18 18:02:45 +0900437 cc_library {
438 name: "mylib2",
439 srcs: ["mylib.cpp"],
440 system_shared_libs: [],
441 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900442 notice: "custom_notice",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000443 // TODO: remove //apex_available:platform
444 apex_available: [
445 "//apex_available:platform",
446 "myapex",
447 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900448 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900449
450 java_library {
451 name: "myjar",
452 srcs: ["foo/bar/MyClass.java"],
453 sdk_version: "none",
454 system_modules: "none",
455 compile_dex: true,
456 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900457 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000458 // TODO: remove //apex_available:platform
459 apex_available: [
460 "//apex_available:platform",
461 "myapex",
462 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900463 }
464
465 java_library {
466 name: "myotherjar",
467 srcs: ["foo/bar/MyClass.java"],
468 sdk_version: "none",
469 system_modules: "none",
470 compile_dex: true,
471 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900472
473 java_library {
474 name: "mysharedjar",
475 srcs: ["foo/bar/MyClass.java"],
476 sdk_version: "none",
477 system_modules: "none",
478 compile_dex: true,
479 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900480 `)
481
Sundong Ahnabb64432019-10-22 13:58:29 +0900482 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900483
484 optFlags := apexRule.Args["opt_flags"]
485 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700486 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900487 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900488
Jiyong Park25fc6a92018-11-18 18:02:45 +0900489 copyCmds := apexRule.Args["copy_commands"]
490
491 // Ensure that main rule creates an output
492 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
493
494 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800495 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900496 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900497
498 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800499 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900500 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900501
502 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800503 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
504 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900505 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
506 // .. but not for java libs
507 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900508 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800509
Colin Cross7113d202019-11-20 16:39:12 -0800510 // Ensure that the platform variant ends with _shared or _common
511 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
512 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900513 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
514 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900515 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
516
517 // Ensure that dynamic dependency to java libs are not included
518 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800519
520 // Ensure that all symlinks are present.
521 found_foo_link_64 := false
522 found_foo := false
523 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900524 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800525 if strings.HasSuffix(cmd, "bin/foo") {
526 found_foo = true
527 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
528 found_foo_link_64 = true
529 }
530 }
531 }
532 good := found_foo && found_foo_link_64
533 if !good {
534 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
535 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900536
Sundong Ahnabb64432019-10-22 13:58:29 +0900537 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700538 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700539 if len(noticeInputs) != 2 {
540 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900541 }
542 ensureListContains(t, noticeInputs, "NOTICE")
543 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900544
545 depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n")
546 ensureListContains(t, depsInfo, "internal myjar")
547 ensureListContains(t, depsInfo, "internal mylib")
548 ensureListContains(t, depsInfo, "internal mylib2")
549 ensureListContains(t, depsInfo, "internal myotherjar")
Alex Light5098a612018-11-29 17:12:15 -0800550}
551
Jooyung Hanf21c7972019-12-16 22:32:06 +0900552func TestDefaults(t *testing.T) {
553 ctx, _ := testApex(t, `
554 apex_defaults {
555 name: "myapex-defaults",
556 key: "myapex.key",
557 prebuilts: ["myetc"],
558 native_shared_libs: ["mylib"],
559 java_libs: ["myjar"],
560 apps: ["AppFoo"],
561 }
562
563 prebuilt_etc {
564 name: "myetc",
565 src: "myprebuilt",
566 }
567
568 apex {
569 name: "myapex",
570 defaults: ["myapex-defaults"],
571 }
572
573 apex_key {
574 name: "myapex.key",
575 public_key: "testkey.avbpubkey",
576 private_key: "testkey.pem",
577 }
578
579 cc_library {
580 name: "mylib",
581 system_shared_libs: [],
582 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000583 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900584 }
585
586 java_library {
587 name: "myjar",
588 srcs: ["foo/bar/MyClass.java"],
589 sdk_version: "none",
590 system_modules: "none",
591 compile_dex: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000592 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900593 }
594
595 android_app {
596 name: "AppFoo",
597 srcs: ["foo/bar/MyClass.java"],
598 sdk_version: "none",
599 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000600 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900601 }
602 `)
Jooyung Hana57af4a2020-01-23 05:36:59 +0000603 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900604 "etc/myetc",
605 "javalib/myjar.jar",
606 "lib64/mylib.so",
607 "app/AppFoo/AppFoo.apk",
608 })
609}
610
Jooyung Han01a3ee22019-11-02 02:52:25 +0900611func TestApexManifest(t *testing.T) {
612 ctx, _ := testApex(t, `
613 apex {
614 name: "myapex",
615 key: "myapex.key",
616 }
617
618 apex_key {
619 name: "myapex.key",
620 public_key: "testkey.avbpubkey",
621 private_key: "testkey.pem",
622 }
623 `)
624
625 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900626 args := module.Rule("apexRule").Args
627 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
628 t.Error("manifest should be apex_manifest.pb, but " + manifest)
629 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900630}
631
Alex Light5098a612018-11-29 17:12:15 -0800632func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700633 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800634 apex {
635 name: "myapex",
636 key: "myapex.key",
637 payload_type: "zip",
638 native_shared_libs: ["mylib"],
639 }
640
641 apex_key {
642 name: "myapex.key",
643 public_key: "testkey.avbpubkey",
644 private_key: "testkey.pem",
645 }
646
647 cc_library {
648 name: "mylib",
649 srcs: ["mylib.cpp"],
650 shared_libs: ["mylib2"],
651 system_shared_libs: [],
652 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000653 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800654 }
655
656 cc_library {
657 name: "mylib2",
658 srcs: ["mylib.cpp"],
659 system_shared_libs: [],
660 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000661 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800662 }
663 `)
664
Sundong Ahnabb64432019-10-22 13:58:29 +0900665 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800666 copyCmds := zipApexRule.Args["copy_commands"]
667
668 // Ensure that main rule creates an output
669 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
670
671 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800672 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800673
674 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800675 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800676
677 // Ensure that both direct and indirect deps are copied into apex
678 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
679 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900680}
681
682func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700683 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900684 apex {
685 name: "myapex",
686 key: "myapex.key",
687 native_shared_libs: ["mylib", "mylib3"],
688 }
689
690 apex_key {
691 name: "myapex.key",
692 public_key: "testkey.avbpubkey",
693 private_key: "testkey.pem",
694 }
695
696 cc_library {
697 name: "mylib",
698 srcs: ["mylib.cpp"],
699 shared_libs: ["mylib2", "mylib3"],
700 system_shared_libs: [],
701 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000702 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900703 }
704
705 cc_library {
706 name: "mylib2",
707 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900708 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900709 system_shared_libs: [],
710 stl: "none",
711 stubs: {
712 versions: ["1", "2", "3"],
713 },
714 }
715
716 cc_library {
717 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900718 srcs: ["mylib.cpp"],
719 shared_libs: ["mylib4"],
720 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900721 stl: "none",
722 stubs: {
723 versions: ["10", "11", "12"],
724 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000725 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900726 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900727
728 cc_library {
729 name: "mylib4",
730 srcs: ["mylib.cpp"],
731 system_shared_libs: [],
732 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000733 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900734 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900735 `)
736
Sundong Ahnabb64432019-10-22 13:58:29 +0900737 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900738 copyCmds := apexRule.Args["copy_commands"]
739
740 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800741 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900742
743 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800744 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900745
746 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800747 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900748
Colin Cross7113d202019-11-20 16:39:12 -0800749 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900750
751 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900752 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900753 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900754 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900755
756 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Colin Cross7113d202019-11-20 16:39:12 -0800757 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900758 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800759 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900760
761 // Ensure that stubs libs are built without -include flags
Colin Cross7113d202019-11-20 16:39:12 -0800762 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900763 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900764
765 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900766 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900767
Jooyung Hana57af4a2020-01-23 05:36:59 +0000768 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900769 "lib64/mylib.so",
770 "lib64/mylib3.so",
771 "lib64/mylib4.so",
772 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900773}
774
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900775func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700776 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900777 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900778 name: "myapex2",
779 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900780 native_shared_libs: ["mylib"],
781 }
782
783 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900784 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900785 public_key: "testkey.avbpubkey",
786 private_key: "testkey.pem",
787 }
788
789 cc_library {
790 name: "mylib",
791 srcs: ["mylib.cpp"],
792 shared_libs: ["libfoo#10"],
793 system_shared_libs: [],
794 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000795 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900796 }
797
798 cc_library {
799 name: "libfoo",
800 srcs: ["mylib.cpp"],
801 shared_libs: ["libbar"],
802 system_shared_libs: [],
803 stl: "none",
804 stubs: {
805 versions: ["10", "20", "30"],
806 },
807 }
808
809 cc_library {
810 name: "libbar",
811 srcs: ["mylib.cpp"],
812 system_shared_libs: [],
813 stl: "none",
814 }
815
816 `)
817
Jiyong Park83dc74b2020-01-14 18:38:44 +0900818 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900819 copyCmds := apexRule.Args["copy_commands"]
820
821 // Ensure that direct non-stubs dep is always included
822 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
823
824 // Ensure that indirect stubs dep is not included
825 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
826
827 // Ensure that dependency of stubs is not included
828 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
829
Jiyong Park83dc74b2020-01-14 18:38:44 +0900830 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900831
832 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900833 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900834 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900835 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900836
Jiyong Park3ff16992019-12-27 14:11:47 +0900837 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900838
839 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
840 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900841
842 depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n")
843 ensureListContains(t, depsInfo, "internal mylib")
844 ensureListContains(t, depsInfo, "external libfoo")
845 ensureListNotContains(t, depsInfo, "internal libfoo")
846 ensureListNotContains(t, depsInfo, "external mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900847}
848
Jooyung Hand3639552019-08-09 12:57:43 +0900849func TestApexWithRuntimeLibsDependency(t *testing.T) {
850 /*
851 myapex
852 |
853 v (runtime_libs)
854 mylib ------+------> libfoo [provides stub]
855 |
856 `------> libbar
857 */
858 ctx, _ := testApex(t, `
859 apex {
860 name: "myapex",
861 key: "myapex.key",
862 native_shared_libs: ["mylib"],
863 }
864
865 apex_key {
866 name: "myapex.key",
867 public_key: "testkey.avbpubkey",
868 private_key: "testkey.pem",
869 }
870
871 cc_library {
872 name: "mylib",
873 srcs: ["mylib.cpp"],
874 runtime_libs: ["libfoo", "libbar"],
875 system_shared_libs: [],
876 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000877 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900878 }
879
880 cc_library {
881 name: "libfoo",
882 srcs: ["mylib.cpp"],
883 system_shared_libs: [],
884 stl: "none",
885 stubs: {
886 versions: ["10", "20", "30"],
887 },
888 }
889
890 cc_library {
891 name: "libbar",
892 srcs: ["mylib.cpp"],
893 system_shared_libs: [],
894 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000895 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900896 }
897
898 `)
899
Sundong Ahnabb64432019-10-22 13:58:29 +0900900 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900901 copyCmds := apexRule.Args["copy_commands"]
902
903 // Ensure that direct non-stubs dep is always included
904 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
905
906 // Ensure that indirect stubs dep is not included
907 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
908
909 // Ensure that runtime_libs dep in included
910 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
911
Sundong Ahnabb64432019-10-22 13:58:29 +0900912 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900913 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
914 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900915
916}
917
Jooyung Han9c80bae2019-08-20 17:30:57 +0900918func TestApexDependencyToLLNDK(t *testing.T) {
919 ctx, _ := testApex(t, `
920 apex {
921 name: "myapex",
922 key: "myapex.key",
923 use_vendor: true,
924 native_shared_libs: ["mylib"],
925 }
926
927 apex_key {
928 name: "myapex.key",
929 public_key: "testkey.avbpubkey",
930 private_key: "testkey.pem",
931 }
932
933 cc_library {
934 name: "mylib",
935 srcs: ["mylib.cpp"],
936 vendor_available: true,
937 shared_libs: ["libbar"],
938 system_shared_libs: [],
939 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000940 apex_available: [ "myapex" ],
Jooyung Han9c80bae2019-08-20 17:30:57 +0900941 }
942
943 cc_library {
944 name: "libbar",
945 srcs: ["mylib.cpp"],
946 system_shared_libs: [],
947 stl: "none",
948 }
949
950 llndk_library {
951 name: "libbar",
952 symbol_file: "",
953 }
Jooyung Handc782442019-11-01 03:14:38 +0900954 `, func(fs map[string][]byte, config android.Config) {
955 setUseVendorWhitelistForTest(config, []string{"myapex"})
956 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900957
Sundong Ahnabb64432019-10-22 13:58:29 +0900958 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900959 copyCmds := apexRule.Args["copy_commands"]
960
961 // Ensure that LLNDK dep is not included
962 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
963
Sundong Ahnabb64432019-10-22 13:58:29 +0900964 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900965 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900966
967 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900968 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900969
970}
971
Jiyong Park25fc6a92018-11-18 18:02:45 +0900972func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700973 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900974 apex {
975 name: "myapex",
976 key: "myapex.key",
977 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
978 }
979
980 apex_key {
981 name: "myapex.key",
982 public_key: "testkey.avbpubkey",
983 private_key: "testkey.pem",
984 }
985
986 cc_library {
987 name: "mylib",
988 srcs: ["mylib.cpp"],
989 shared_libs: ["libdl#27"],
990 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000991 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900992 }
993
994 cc_library_shared {
995 name: "mylib_shared",
996 srcs: ["mylib.cpp"],
997 shared_libs: ["libdl#27"],
998 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000999 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001000 }
1001
1002 cc_library {
1003 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -07001004 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001005 nocrt: true,
1006 system_shared_libs: [],
1007 stl: "none",
1008 stubs: {
1009 versions: ["27", "28", "29"],
1010 },
1011 }
1012
1013 cc_library {
1014 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -07001015 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001016 nocrt: true,
1017 system_shared_libs: [],
1018 stl: "none",
1019 stubs: {
1020 versions: ["27", "28", "29"],
1021 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001022 apex_available: [
1023 "//apex_available:platform",
1024 "myapex"
1025 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001026 }
1027
1028 cc_library {
1029 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -07001030 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001031 nocrt: true,
1032 system_shared_libs: [],
1033 stl: "none",
1034 stubs: {
1035 versions: ["27", "28", "29"],
1036 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001037 apex_available: [
1038 "//apex_available:platform",
1039 "myapex"
1040 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001041 }
Jiyong Parkb0788572018-12-20 22:10:17 +09001042
1043 cc_library {
1044 name: "libBootstrap",
1045 srcs: ["mylib.cpp"],
1046 stl: "none",
1047 bootstrap: true,
1048 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001049 `)
1050
Sundong Ahnabb64432019-10-22 13:58:29 +09001051 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001052 copyCmds := apexRule.Args["copy_commands"]
1053
1054 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -08001055 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +09001056 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
1057 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001058
1059 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001060 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001061
Colin Cross7113d202019-11-20 16:39:12 -08001062 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1063 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1064 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001065
1066 // For dependency to libc
1067 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001068 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001069 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001070 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001071 // ... Cflags from stub is correctly exported to mylib
1072 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
1073 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
1074
1075 // For dependency to libm
1076 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001077 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001078 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001079 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001080 // ... and is not compiling with the stub
1081 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
1082 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
1083
1084 // For dependency to libdl
1085 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001086 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001087 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001088 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
1089 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001090 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001091 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001092 // ... Cflags from stub is correctly exported to mylib
1093 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
1094 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +09001095
1096 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -08001097 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
1098 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
1099 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
1100 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001101}
Jiyong Park7c2ee712018-12-07 00:42:25 +09001102
1103func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001104 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001105 apex {
1106 name: "myapex",
1107 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001108 native_shared_libs: ["mylib"],
1109 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001110 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001111 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001112 }
1113
1114 apex_key {
1115 name: "myapex.key",
1116 public_key: "testkey.avbpubkey",
1117 private_key: "testkey.pem",
1118 }
1119
1120 prebuilt_etc {
1121 name: "myetc",
1122 src: "myprebuilt",
1123 sub_dir: "foo/bar",
1124 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001125
1126 cc_library {
1127 name: "mylib",
1128 srcs: ["mylib.cpp"],
1129 relative_install_path: "foo/bar",
1130 system_shared_libs: [],
1131 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001132 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001133 }
1134
1135 cc_binary {
1136 name: "mybin",
1137 srcs: ["mylib.cpp"],
1138 relative_install_path: "foo/bar",
1139 system_shared_libs: [],
1140 static_executable: true,
1141 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001142 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001143 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001144 `)
1145
Sundong Ahnabb64432019-10-22 13:58:29 +09001146 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001147 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1148
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001149 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001150 ensureListContains(t, dirs, "etc")
1151 ensureListContains(t, dirs, "etc/foo")
1152 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001153 ensureListContains(t, dirs, "lib64")
1154 ensureListContains(t, dirs, "lib64/foo")
1155 ensureListContains(t, dirs, "lib64/foo/bar")
1156 ensureListContains(t, dirs, "lib")
1157 ensureListContains(t, dirs, "lib/foo")
1158 ensureListContains(t, dirs, "lib/foo/bar")
1159
Jiyong Parkbd13e442019-03-15 18:10:35 +09001160 ensureListContains(t, dirs, "bin")
1161 ensureListContains(t, dirs, "bin/foo")
1162 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001163}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001164
1165func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001166 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001167 apex {
1168 name: "myapex",
1169 key: "myapex.key",
1170 native_shared_libs: ["mylib"],
1171 use_vendor: true,
1172 }
1173
1174 apex_key {
1175 name: "myapex.key",
1176 public_key: "testkey.avbpubkey",
1177 private_key: "testkey.pem",
1178 }
1179
1180 cc_library {
1181 name: "mylib",
1182 srcs: ["mylib.cpp"],
1183 shared_libs: ["mylib2"],
1184 system_shared_libs: [],
1185 vendor_available: true,
1186 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001187 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001188 }
1189
1190 cc_library {
1191 name: "mylib2",
1192 srcs: ["mylib.cpp"],
1193 system_shared_libs: [],
1194 vendor_available: true,
1195 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001196 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001197 }
Jooyung Handc782442019-11-01 03:14:38 +09001198 `, func(fs map[string][]byte, config android.Config) {
1199 setUseVendorWhitelistForTest(config, []string{"myapex"})
1200 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001201
1202 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001203 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001204 for _, implicit := range i.Implicits {
1205 inputsList = append(inputsList, implicit.String())
1206 }
1207 }
1208 inputsString := strings.Join(inputsList, " ")
1209
1210 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001211 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1212 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001213
1214 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001215 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1216 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001217}
Jiyong Park16e91a02018-12-20 18:18:08 +09001218
Jooyung Handc782442019-11-01 03:14:38 +09001219func TestUseVendorRestriction(t *testing.T) {
1220 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1221 apex {
1222 name: "myapex",
1223 key: "myapex.key",
1224 use_vendor: true,
1225 }
1226 apex_key {
1227 name: "myapex.key",
1228 public_key: "testkey.avbpubkey",
1229 private_key: "testkey.pem",
1230 }
1231 `, func(fs map[string][]byte, config android.Config) {
1232 setUseVendorWhitelistForTest(config, []string{""})
1233 })
1234 // no error with whitelist
1235 testApex(t, `
1236 apex {
1237 name: "myapex",
1238 key: "myapex.key",
1239 use_vendor: true,
1240 }
1241 apex_key {
1242 name: "myapex.key",
1243 public_key: "testkey.avbpubkey",
1244 private_key: "testkey.pem",
1245 }
1246 `, func(fs map[string][]byte, config android.Config) {
1247 setUseVendorWhitelistForTest(config, []string{"myapex"})
1248 })
1249}
1250
Jooyung Han5c998b92019-06-27 11:30:33 +09001251func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1252 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1253 apex {
1254 name: "myapex",
1255 key: "myapex.key",
1256 native_shared_libs: ["mylib"],
1257 use_vendor: true,
1258 }
1259
1260 apex_key {
1261 name: "myapex.key",
1262 public_key: "testkey.avbpubkey",
1263 private_key: "testkey.pem",
1264 }
1265
1266 cc_library {
1267 name: "mylib",
1268 srcs: ["mylib.cpp"],
1269 system_shared_libs: [],
1270 stl: "none",
1271 }
1272 `)
1273}
1274
Jiyong Park16e91a02018-12-20 18:18:08 +09001275func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001276 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001277 apex {
1278 name: "myapex",
1279 key: "myapex.key",
1280 native_shared_libs: ["mylib"],
1281 }
1282
1283 apex_key {
1284 name: "myapex.key",
1285 public_key: "testkey.avbpubkey",
1286 private_key: "testkey.pem",
1287 }
1288
1289 cc_library {
1290 name: "mylib",
1291 srcs: ["mylib.cpp"],
1292 system_shared_libs: [],
1293 stl: "none",
1294 stubs: {
1295 versions: ["1", "2", "3"],
1296 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001297 apex_available: [
1298 "//apex_available:platform",
1299 "myapex",
1300 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001301 }
1302
1303 cc_binary {
1304 name: "not_in_apex",
1305 srcs: ["mylib.cpp"],
1306 static_libs: ["mylib"],
1307 static_executable: true,
1308 system_shared_libs: [],
1309 stl: "none",
1310 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001311 `)
1312
Colin Cross7113d202019-11-20 16:39:12 -08001313 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001314
1315 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001316 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001317}
Jiyong Park9335a262018-12-24 11:31:58 +09001318
1319func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001320 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001321 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001322 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001323 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001324 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001325 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001326 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001327 }
1328
1329 cc_library {
1330 name: "mylib",
1331 srcs: ["mylib.cpp"],
1332 system_shared_libs: [],
1333 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001334 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001335 }
1336
1337 apex_key {
1338 name: "myapex.key",
1339 public_key: "testkey.avbpubkey",
1340 private_key: "testkey.pem",
1341 }
1342
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001343 android_app_certificate {
1344 name: "myapex.certificate",
1345 certificate: "testkey",
1346 }
1347
1348 android_app_certificate {
1349 name: "myapex.certificate.override",
1350 certificate: "testkey.override",
1351 }
1352
Jiyong Park9335a262018-12-24 11:31:58 +09001353 `)
1354
1355 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001356 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001357
1358 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1359 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1360 "vendor/foo/devkeys/testkey.avbpubkey")
1361 }
1362 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1363 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1364 "vendor/foo/devkeys/testkey.pem")
1365 }
1366
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001367 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001368 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001369 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001370 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001371 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001372 }
1373}
Jiyong Park58e364a2019-01-19 19:24:06 +09001374
Jooyung Hanf121a652019-12-17 14:30:11 +09001375func TestCertificate(t *testing.T) {
1376 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1377 ctx, _ := testApex(t, `
1378 apex {
1379 name: "myapex",
1380 key: "myapex.key",
1381 }
1382 apex_key {
1383 name: "myapex.key",
1384 public_key: "testkey.avbpubkey",
1385 private_key: "testkey.pem",
1386 }`)
1387 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1388 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1389 if actual := rule.Args["certificates"]; actual != expected {
1390 t.Errorf("certificates should be %q, not %q", expected, actual)
1391 }
1392 })
1393 t.Run("override when unspecified", func(t *testing.T) {
1394 ctx, _ := testApex(t, `
1395 apex {
1396 name: "myapex_keytest",
1397 key: "myapex.key",
1398 file_contexts: ":myapex-file_contexts",
1399 }
1400 apex_key {
1401 name: "myapex.key",
1402 public_key: "testkey.avbpubkey",
1403 private_key: "testkey.pem",
1404 }
1405 android_app_certificate {
1406 name: "myapex.certificate.override",
1407 certificate: "testkey.override",
1408 }`)
1409 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1410 expected := "testkey.override.x509.pem testkey.override.pk8"
1411 if actual := rule.Args["certificates"]; actual != expected {
1412 t.Errorf("certificates should be %q, not %q", expected, actual)
1413 }
1414 })
1415 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1416 ctx, _ := testApex(t, `
1417 apex {
1418 name: "myapex",
1419 key: "myapex.key",
1420 certificate: ":myapex.certificate",
1421 }
1422 apex_key {
1423 name: "myapex.key",
1424 public_key: "testkey.avbpubkey",
1425 private_key: "testkey.pem",
1426 }
1427 android_app_certificate {
1428 name: "myapex.certificate",
1429 certificate: "testkey",
1430 }`)
1431 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1432 expected := "testkey.x509.pem testkey.pk8"
1433 if actual := rule.Args["certificates"]; actual != expected {
1434 t.Errorf("certificates should be %q, not %q", expected, actual)
1435 }
1436 })
1437 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1438 ctx, _ := testApex(t, `
1439 apex {
1440 name: "myapex_keytest",
1441 key: "myapex.key",
1442 file_contexts: ":myapex-file_contexts",
1443 certificate: ":myapex.certificate",
1444 }
1445 apex_key {
1446 name: "myapex.key",
1447 public_key: "testkey.avbpubkey",
1448 private_key: "testkey.pem",
1449 }
1450 android_app_certificate {
1451 name: "myapex.certificate.override",
1452 certificate: "testkey.override",
1453 }`)
1454 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1455 expected := "testkey.override.x509.pem testkey.override.pk8"
1456 if actual := rule.Args["certificates"]; actual != expected {
1457 t.Errorf("certificates should be %q, not %q", expected, actual)
1458 }
1459 })
1460 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1461 ctx, _ := testApex(t, `
1462 apex {
1463 name: "myapex",
1464 key: "myapex.key",
1465 certificate: "testkey",
1466 }
1467 apex_key {
1468 name: "myapex.key",
1469 public_key: "testkey.avbpubkey",
1470 private_key: "testkey.pem",
1471 }`)
1472 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1473 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1474 if actual := rule.Args["certificates"]; actual != expected {
1475 t.Errorf("certificates should be %q, not %q", expected, actual)
1476 }
1477 })
1478 t.Run("override when specified as <name>", func(t *testing.T) {
1479 ctx, _ := testApex(t, `
1480 apex {
1481 name: "myapex_keytest",
1482 key: "myapex.key",
1483 file_contexts: ":myapex-file_contexts",
1484 certificate: "testkey",
1485 }
1486 apex_key {
1487 name: "myapex.key",
1488 public_key: "testkey.avbpubkey",
1489 private_key: "testkey.pem",
1490 }
1491 android_app_certificate {
1492 name: "myapex.certificate.override",
1493 certificate: "testkey.override",
1494 }`)
1495 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1496 expected := "testkey.override.x509.pem testkey.override.pk8"
1497 if actual := rule.Args["certificates"]; actual != expected {
1498 t.Errorf("certificates should be %q, not %q", expected, actual)
1499 }
1500 })
1501}
1502
Jiyong Park58e364a2019-01-19 19:24:06 +09001503func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001504 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001505 apex {
1506 name: "myapex",
1507 key: "myapex.key",
1508 native_shared_libs: ["mylib"],
1509 }
1510
1511 apex {
1512 name: "otherapex",
1513 key: "myapex.key",
1514 native_shared_libs: ["mylib"],
1515 }
1516
1517 apex_key {
1518 name: "myapex.key",
1519 public_key: "testkey.avbpubkey",
1520 private_key: "testkey.pem",
1521 }
1522
1523 cc_library {
1524 name: "mylib",
1525 srcs: ["mylib.cpp"],
1526 system_shared_libs: [],
1527 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001528 // TODO: remove //apex_available:platform
1529 apex_available: [
1530 "//apex_available:platform",
1531 "myapex",
1532 "otherapex",
1533 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001534 }
1535 `)
1536
Jooyung Han6b8459b2019-10-30 08:29:25 +09001537 // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001538 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001539 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001540 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1541 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001542
Jooyung Han6b8459b2019-10-30 08:29:25 +09001543 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001544 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001545 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001546 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1547 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001548
Jooyung Han6b8459b2019-10-30 08:29:25 +09001549 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001550 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001551 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001552 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1553 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001554}
Jiyong Park7e636d02019-01-28 16:16:54 +09001555
1556func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001557 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001558 apex {
1559 name: "myapex",
1560 key: "myapex.key",
1561 native_shared_libs: ["mylib"],
1562 }
1563
1564 apex_key {
1565 name: "myapex.key",
1566 public_key: "testkey.avbpubkey",
1567 private_key: "testkey.pem",
1568 }
1569
1570 cc_library_headers {
1571 name: "mylib_headers",
1572 export_include_dirs: ["my_include"],
1573 system_shared_libs: [],
1574 stl: "none",
1575 }
1576
1577 cc_library {
1578 name: "mylib",
1579 srcs: ["mylib.cpp"],
1580 system_shared_libs: [],
1581 stl: "none",
1582 header_libs: ["mylib_headers"],
1583 export_header_lib_headers: ["mylib_headers"],
1584 stubs: {
1585 versions: ["1", "2", "3"],
1586 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001587 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001588 }
1589
1590 cc_library {
1591 name: "otherlib",
1592 srcs: ["mylib.cpp"],
1593 system_shared_libs: [],
1594 stl: "none",
1595 shared_libs: ["mylib"],
1596 }
1597 `)
1598
Colin Cross7113d202019-11-20 16:39:12 -08001599 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001600
1601 // Ensure that the include path of the header lib is exported to 'otherlib'
1602 ensureContains(t, cFlags, "-Imy_include")
1603}
Alex Light9670d332019-01-29 18:07:33 -08001604
Jiyong Park7cd10e32020-01-14 09:22:18 +09001605type fileInApex struct {
1606 path string // path in apex
Jooyung Hana57af4a2020-01-23 05:36:59 +00001607 src string // src path
Jiyong Park7cd10e32020-01-14 09:22:18 +09001608 isLink bool
1609}
1610
Jooyung Hana57af4a2020-01-23 05:36:59 +00001611func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001612 t.Helper()
Jooyung Hana57af4a2020-01-23 05:36:59 +00001613 apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001614 copyCmds := apexRule.Args["copy_commands"]
1615 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001616 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001617 for _, cmd := range strings.Split(copyCmds, "&&") {
1618 cmd = strings.TrimSpace(cmd)
1619 if cmd == "" {
1620 continue
1621 }
1622 terms := strings.Split(cmd, " ")
Jooyung Hana57af4a2020-01-23 05:36:59 +00001623 var dst, src string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001624 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001625 switch terms[0] {
1626 case "mkdir":
1627 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001628 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001629 t.Fatal("copyCmds contains invalid cp command", cmd)
1630 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001631 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001632 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001633 isLink = false
1634 case "ln":
1635 if len(terms) != 3 && len(terms) != 4 {
1636 // ln LINK TARGET or ln -s LINK TARGET
1637 t.Fatal("copyCmds contains invalid ln command", cmd)
1638 }
1639 dst = terms[len(terms)-1]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001640 src = terms[len(terms)-2]
Jiyong Park7cd10e32020-01-14 09:22:18 +09001641 isLink = true
1642 default:
1643 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1644 }
1645 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001646 index := strings.Index(dst, imageApexDir)
1647 if index == -1 {
1648 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1649 }
1650 dstFile := dst[index+len(imageApexDir):]
Jooyung Hana57af4a2020-01-23 05:36:59 +00001651 ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001652 }
1653 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001654 return ret
1655}
1656
Jooyung Hana57af4a2020-01-23 05:36:59 +00001657func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) {
1658 t.Helper()
Jiyong Park7cd10e32020-01-14 09:22:18 +09001659 var failed bool
1660 var surplus []string
1661 filesMatched := make(map[string]bool)
Jooyung Hana57af4a2020-01-23 05:36:59 +00001662 for _, file := range getFiles(t, ctx, moduleName, variant) {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001663 for _, expected := range files {
1664 if matched, _ := path.Match(expected, file.path); matched {
1665 filesMatched[expected] = true
1666 return
1667 }
1668 }
1669 surplus = append(surplus, file.path)
1670 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001671
Jooyung Han31c470b2019-10-18 16:26:59 +09001672 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001673 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001674 t.Log("surplus files", surplus)
1675 failed = true
1676 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001677
1678 if len(files) > len(filesMatched) {
1679 var missing []string
1680 for _, expected := range files {
1681 if !filesMatched[expected] {
1682 missing = append(missing, expected)
1683 }
1684 }
1685 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001686 t.Log("missing files", missing)
1687 failed = true
1688 }
1689 if failed {
1690 t.Fail()
1691 }
1692}
1693
Jooyung Han344d5432019-08-23 11:17:39 +09001694func TestVndkApexCurrent(t *testing.T) {
1695 ctx, _ := testApex(t, `
1696 apex_vndk {
1697 name: "myapex",
1698 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001699 }
1700
1701 apex_key {
1702 name: "myapex.key",
1703 public_key: "testkey.avbpubkey",
1704 private_key: "testkey.pem",
1705 }
1706
1707 cc_library {
1708 name: "libvndk",
1709 srcs: ["mylib.cpp"],
1710 vendor_available: true,
1711 vndk: {
1712 enabled: true,
1713 },
1714 system_shared_libs: [],
1715 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001716 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001717 }
1718
1719 cc_library {
1720 name: "libvndksp",
1721 srcs: ["mylib.cpp"],
1722 vendor_available: true,
1723 vndk: {
1724 enabled: true,
1725 support_system_process: true,
1726 },
1727 system_shared_libs: [],
1728 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001729 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001730 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001731 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001732
Jooyung Hana57af4a2020-01-23 05:36:59 +00001733 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001734 "lib/libvndk.so",
1735 "lib/libvndksp.so",
1736 "lib64/libvndk.so",
1737 "lib64/libvndksp.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001738 "etc/llndk.libraries.VER.txt",
1739 "etc/vndkcore.libraries.VER.txt",
1740 "etc/vndksp.libraries.VER.txt",
1741 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001742 })
Jooyung Han344d5432019-08-23 11:17:39 +09001743}
1744
1745func TestVndkApexWithPrebuilt(t *testing.T) {
1746 ctx, _ := testApex(t, `
1747 apex_vndk {
1748 name: "myapex",
1749 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001750 }
1751
1752 apex_key {
1753 name: "myapex.key",
1754 public_key: "testkey.avbpubkey",
1755 private_key: "testkey.pem",
1756 }
1757
1758 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001759 name: "libvndk",
1760 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001761 vendor_available: true,
1762 vndk: {
1763 enabled: true,
1764 },
1765 system_shared_libs: [],
1766 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001767 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001768 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001769
1770 cc_prebuilt_library_shared {
1771 name: "libvndk.arm",
1772 srcs: ["libvndk.arm.so"],
1773 vendor_available: true,
1774 vndk: {
1775 enabled: true,
1776 },
1777 enabled: false,
1778 arch: {
1779 arm: {
1780 enabled: true,
1781 },
1782 },
1783 system_shared_libs: [],
1784 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001785 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09001786 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001787 `+vndkLibrariesTxtFiles("current"),
1788 withFiles(map[string][]byte{
1789 "libvndk.so": nil,
1790 "libvndk.arm.so": nil,
1791 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001792
Jooyung Hana57af4a2020-01-23 05:36:59 +00001793 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001794 "lib/libvndk.so",
1795 "lib/libvndk.arm.so",
1796 "lib64/libvndk.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001797 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09001798 })
Jooyung Han344d5432019-08-23 11:17:39 +09001799}
1800
Jooyung Han39edb6c2019-11-06 16:53:07 +09001801func vndkLibrariesTxtFiles(vers ...string) (result string) {
1802 for _, v := range vers {
1803 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09001804 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001805 result += `
1806 vndk_libraries_txt {
1807 name: "` + txt + `.libraries.txt",
1808 }
1809 `
1810 }
1811 } else {
1812 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
1813 result += `
1814 prebuilt_etc {
1815 name: "` + txt + `.libraries.` + v + `.txt",
1816 src: "dummy.txt",
1817 }
1818 `
1819 }
1820 }
1821 }
1822 return
1823}
1824
Jooyung Han344d5432019-08-23 11:17:39 +09001825func TestVndkApexVersion(t *testing.T) {
1826 ctx, _ := testApex(t, `
1827 apex_vndk {
1828 name: "myapex_v27",
1829 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001830 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001831 vndk_version: "27",
1832 }
1833
1834 apex_key {
1835 name: "myapex.key",
1836 public_key: "testkey.avbpubkey",
1837 private_key: "testkey.pem",
1838 }
1839
Jooyung Han31c470b2019-10-18 16:26:59 +09001840 vndk_prebuilt_shared {
1841 name: "libvndk27",
1842 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001843 vendor_available: true,
1844 vndk: {
1845 enabled: true,
1846 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001847 target_arch: "arm64",
1848 arch: {
1849 arm: {
1850 srcs: ["libvndk27_arm.so"],
1851 },
1852 arm64: {
1853 srcs: ["libvndk27_arm64.so"],
1854 },
1855 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001856 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001857 }
1858
1859 vndk_prebuilt_shared {
1860 name: "libvndk27",
1861 version: "27",
1862 vendor_available: true,
1863 vndk: {
1864 enabled: true,
1865 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001866 target_arch: "x86_64",
1867 arch: {
1868 x86: {
1869 srcs: ["libvndk27_x86.so"],
1870 },
1871 x86_64: {
1872 srcs: ["libvndk27_x86_64.so"],
1873 },
1874 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09001875 }
1876 `+vndkLibrariesTxtFiles("27"),
1877 withFiles(map[string][]byte{
1878 "libvndk27_arm.so": nil,
1879 "libvndk27_arm64.so": nil,
1880 "libvndk27_x86.so": nil,
1881 "libvndk27_x86_64.so": nil,
1882 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001883
Jooyung Hana57af4a2020-01-23 05:36:59 +00001884 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001885 "lib/libvndk27_arm.so",
1886 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001887 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09001888 })
Jooyung Han344d5432019-08-23 11:17:39 +09001889}
1890
1891func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1892 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1893 apex_vndk {
1894 name: "myapex_v27",
1895 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001896 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001897 vndk_version: "27",
1898 }
1899 apex_vndk {
1900 name: "myapex_v27_other",
1901 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001902 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001903 vndk_version: "27",
1904 }
1905
1906 apex_key {
1907 name: "myapex.key",
1908 public_key: "testkey.avbpubkey",
1909 private_key: "testkey.pem",
1910 }
1911
1912 cc_library {
1913 name: "libvndk",
1914 srcs: ["mylib.cpp"],
1915 vendor_available: true,
1916 vndk: {
1917 enabled: true,
1918 },
1919 system_shared_libs: [],
1920 stl: "none",
1921 }
1922
1923 vndk_prebuilt_shared {
1924 name: "libvndk",
1925 version: "27",
1926 vendor_available: true,
1927 vndk: {
1928 enabled: true,
1929 },
1930 srcs: ["libvndk.so"],
1931 }
1932 `, withFiles(map[string][]byte{
1933 "libvndk.so": nil,
1934 }))
1935}
1936
Jooyung Han90eee022019-10-01 20:02:42 +09001937func TestVndkApexNameRule(t *testing.T) {
1938 ctx, _ := testApex(t, `
1939 apex_vndk {
1940 name: "myapex",
1941 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001942 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09001943 }
1944 apex_vndk {
1945 name: "myapex_v28",
1946 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001947 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09001948 vndk_version: "28",
1949 }
1950 apex_key {
1951 name: "myapex.key",
1952 public_key: "testkey.avbpubkey",
1953 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001954 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09001955
1956 assertApexName := func(expected, moduleName string) {
Jooyung Hana57af4a2020-01-23 05:36:59 +00001957 bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09001958 actual := proptools.String(bundle.properties.Apex_name)
1959 if !reflect.DeepEqual(actual, expected) {
1960 t.Errorf("Got '%v', expected '%v'", actual, expected)
1961 }
1962 }
1963
1964 assertApexName("com.android.vndk.vVER", "myapex")
1965 assertApexName("com.android.vndk.v28", "myapex_v28")
1966}
1967
Jooyung Han344d5432019-08-23 11:17:39 +09001968func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1969 ctx, _ := testApex(t, `
1970 apex_vndk {
1971 name: "myapex",
1972 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001973 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001974 }
1975
1976 apex_key {
1977 name: "myapex.key",
1978 public_key: "testkey.avbpubkey",
1979 private_key: "testkey.pem",
1980 }
1981
1982 cc_library {
1983 name: "libvndk",
1984 srcs: ["mylib.cpp"],
1985 vendor_available: true,
1986 native_bridge_supported: true,
1987 host_supported: true,
1988 vndk: {
1989 enabled: true,
1990 },
1991 system_shared_libs: [],
1992 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001993 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001994 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001995 `+vndkLibrariesTxtFiles("current"),
1996 withTargets(map[android.OsType][]android.Target{
1997 android.Android: []android.Target{
1998 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1999 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2000 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
2001 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
2002 },
2003 }))
Jooyung Han344d5432019-08-23 11:17:39 +09002004
Jooyung Hana57af4a2020-01-23 05:36:59 +00002005 ensureExactContents(t, ctx, "myapex", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002006 "lib/libvndk.so",
2007 "lib64/libvndk.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002008 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002009 })
Jooyung Han344d5432019-08-23 11:17:39 +09002010}
2011
2012func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2013 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2014 apex_vndk {
2015 name: "myapex",
2016 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002017 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002018 native_bridge_supported: true,
2019 }
2020
2021 apex_key {
2022 name: "myapex.key",
2023 public_key: "testkey.avbpubkey",
2024 private_key: "testkey.pem",
2025 }
2026
2027 cc_library {
2028 name: "libvndk",
2029 srcs: ["mylib.cpp"],
2030 vendor_available: true,
2031 native_bridge_supported: true,
2032 host_supported: true,
2033 vndk: {
2034 enabled: true,
2035 },
2036 system_shared_libs: [],
2037 stl: "none",
2038 }
2039 `)
2040}
2041
Jooyung Han31c470b2019-10-18 16:26:59 +09002042func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002043 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002044 apex_vndk {
2045 name: "myapex_v27",
2046 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002047 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002048 vndk_version: "27",
2049 }
2050
2051 apex_key {
2052 name: "myapex.key",
2053 public_key: "testkey.avbpubkey",
2054 private_key: "testkey.pem",
2055 }
2056
2057 vndk_prebuilt_shared {
2058 name: "libvndk27",
2059 version: "27",
2060 target_arch: "arm",
2061 vendor_available: true,
2062 vndk: {
2063 enabled: true,
2064 },
2065 arch: {
2066 arm: {
2067 srcs: ["libvndk27.so"],
2068 }
2069 },
2070 }
2071
2072 vndk_prebuilt_shared {
2073 name: "libvndk27",
2074 version: "27",
2075 target_arch: "arm",
2076 binder32bit: true,
2077 vendor_available: true,
2078 vndk: {
2079 enabled: true,
2080 },
2081 arch: {
2082 arm: {
2083 srcs: ["libvndk27binder32.so"],
2084 }
2085 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002086 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002087 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002088 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002089 withFiles(map[string][]byte{
2090 "libvndk27.so": nil,
2091 "libvndk27binder32.so": nil,
2092 }),
2093 withBinder32bit,
2094 withTargets(map[android.OsType][]android.Target{
2095 android.Android: []android.Target{
2096 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2097 },
2098 }),
2099 )
2100
Jooyung Hana57af4a2020-01-23 05:36:59 +00002101 ensureExactContents(t, ctx, "myapex_v27", "android_common_image", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002102 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002103 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002104 })
2105}
2106
Jooyung Hane1633032019-08-01 17:41:43 +09002107func TestDependenciesInApexManifest(t *testing.T) {
2108 ctx, _ := testApex(t, `
2109 apex {
2110 name: "myapex_nodep",
2111 key: "myapex.key",
2112 native_shared_libs: ["lib_nodep"],
2113 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002114 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002115 }
2116
2117 apex {
2118 name: "myapex_dep",
2119 key: "myapex.key",
2120 native_shared_libs: ["lib_dep"],
2121 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002122 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002123 }
2124
2125 apex {
2126 name: "myapex_provider",
2127 key: "myapex.key",
2128 native_shared_libs: ["libfoo"],
2129 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002130 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002131 }
2132
2133 apex {
2134 name: "myapex_selfcontained",
2135 key: "myapex.key",
2136 native_shared_libs: ["lib_dep", "libfoo"],
2137 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002138 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002139 }
2140
2141 apex_key {
2142 name: "myapex.key",
2143 public_key: "testkey.avbpubkey",
2144 private_key: "testkey.pem",
2145 }
2146
2147 cc_library {
2148 name: "lib_nodep",
2149 srcs: ["mylib.cpp"],
2150 system_shared_libs: [],
2151 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002152 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002153 }
2154
2155 cc_library {
2156 name: "lib_dep",
2157 srcs: ["mylib.cpp"],
2158 shared_libs: ["libfoo"],
2159 system_shared_libs: [],
2160 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002161 apex_available: [
2162 "myapex_dep",
2163 "myapex_provider",
2164 "myapex_selfcontained",
2165 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002166 }
2167
2168 cc_library {
2169 name: "libfoo",
2170 srcs: ["mytest.cpp"],
2171 stubs: {
2172 versions: ["1"],
2173 },
2174 system_shared_libs: [],
2175 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002176 apex_available: [
2177 "myapex_provider",
2178 "myapex_selfcontained",
2179 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002180 }
2181 `)
2182
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002183 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002184 var provideNativeLibs, requireNativeLibs []string
2185
Sundong Ahnabb64432019-10-22 13:58:29 +09002186 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002187 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2188 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002189 ensureListEmpty(t, provideNativeLibs)
2190 ensureListEmpty(t, requireNativeLibs)
2191
Sundong Ahnabb64432019-10-22 13:58:29 +09002192 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002193 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2194 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002195 ensureListEmpty(t, provideNativeLibs)
2196 ensureListContains(t, requireNativeLibs, "libfoo.so")
2197
Sundong Ahnabb64432019-10-22 13:58:29 +09002198 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002199 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2200 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002201 ensureListContains(t, provideNativeLibs, "libfoo.so")
2202 ensureListEmpty(t, requireNativeLibs)
2203
Sundong Ahnabb64432019-10-22 13:58:29 +09002204 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002205 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2206 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002207 ensureListContains(t, provideNativeLibs, "libfoo.so")
2208 ensureListEmpty(t, requireNativeLibs)
2209}
2210
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002211func TestApexName(t *testing.T) {
2212 ctx, _ := testApex(t, `
2213 apex {
2214 name: "myapex",
2215 key: "myapex.key",
2216 apex_name: "com.android.myapex",
2217 }
2218
2219 apex_key {
2220 name: "myapex.key",
2221 public_key: "testkey.avbpubkey",
2222 private_key: "testkey.pem",
2223 }
2224 `)
2225
Sundong Ahnabb64432019-10-22 13:58:29 +09002226 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002227 apexManifestRule := module.Rule("apexManifestRule")
2228 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2229 apexRule := module.Rule("apexRule")
2230 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
2231}
2232
Alex Light0851b882019-02-07 13:20:53 -08002233func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002234 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002235 apex {
2236 name: "myapex",
2237 key: "myapex.key",
2238 native_shared_libs: ["mylib_common"],
2239 }
2240
2241 apex_key {
2242 name: "myapex.key",
2243 public_key: "testkey.avbpubkey",
2244 private_key: "testkey.pem",
2245 }
2246
2247 cc_library {
2248 name: "mylib_common",
2249 srcs: ["mylib.cpp"],
2250 system_shared_libs: [],
2251 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002252 apex_available: [
2253 "//apex_available:platform",
2254 "myapex",
2255 ],
Alex Light0851b882019-02-07 13:20:53 -08002256 }
2257 `)
2258
Sundong Ahnabb64432019-10-22 13:58:29 +09002259 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002260 apexRule := module.Rule("apexRule")
2261 copyCmds := apexRule.Args["copy_commands"]
2262
2263 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2264 t.Log("Apex was a test apex!")
2265 t.Fail()
2266 }
2267 // Ensure that main rule creates an output
2268 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2269
2270 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002271 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002272
2273 // Ensure that both direct and indirect deps are copied into apex
2274 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2275
Colin Cross7113d202019-11-20 16:39:12 -08002276 // Ensure that the platform variant ends with _shared
2277 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002278
2279 if !android.InAnyApex("mylib_common") {
2280 t.Log("Found mylib_common not in any apex!")
2281 t.Fail()
2282 }
2283}
2284
2285func TestTestApex(t *testing.T) {
2286 if android.InAnyApex("mylib_common_test") {
2287 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!")
2288 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002289 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002290 apex_test {
2291 name: "myapex",
2292 key: "myapex.key",
2293 native_shared_libs: ["mylib_common_test"],
2294 }
2295
2296 apex_key {
2297 name: "myapex.key",
2298 public_key: "testkey.avbpubkey",
2299 private_key: "testkey.pem",
2300 }
2301
2302 cc_library {
2303 name: "mylib_common_test",
2304 srcs: ["mylib.cpp"],
2305 system_shared_libs: [],
2306 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002307 // TODO: remove //apex_available:platform
2308 apex_available: [
2309 "//apex_available:platform",
2310 "myapex",
2311 ],
Alex Light0851b882019-02-07 13:20:53 -08002312 }
2313 `)
2314
Sundong Ahnabb64432019-10-22 13:58:29 +09002315 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002316 apexRule := module.Rule("apexRule")
2317 copyCmds := apexRule.Args["copy_commands"]
2318
2319 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2320 t.Log("Apex was not a test apex!")
2321 t.Fail()
2322 }
2323 // Ensure that main rule creates an output
2324 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2325
2326 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002327 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002328
2329 // Ensure that both direct and indirect deps are copied into apex
2330 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2331
Colin Cross7113d202019-11-20 16:39:12 -08002332 // Ensure that the platform variant ends with _shared
2333 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002334
2335 if android.InAnyApex("mylib_common_test") {
2336 t.Log("Found mylib_common_test in some apex!")
2337 t.Fail()
2338 }
2339}
2340
Alex Light9670d332019-01-29 18:07:33 -08002341func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002342 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002343 apex {
2344 name: "myapex",
2345 key: "myapex.key",
2346 multilib: {
2347 first: {
2348 native_shared_libs: ["mylib_common"],
2349 }
2350 },
2351 target: {
2352 android: {
2353 multilib: {
2354 first: {
2355 native_shared_libs: ["mylib"],
2356 }
2357 }
2358 },
2359 host: {
2360 multilib: {
2361 first: {
2362 native_shared_libs: ["mylib2"],
2363 }
2364 }
2365 }
2366 }
2367 }
2368
2369 apex_key {
2370 name: "myapex.key",
2371 public_key: "testkey.avbpubkey",
2372 private_key: "testkey.pem",
2373 }
2374
2375 cc_library {
2376 name: "mylib",
2377 srcs: ["mylib.cpp"],
2378 system_shared_libs: [],
2379 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002380 // TODO: remove //apex_available:platform
2381 apex_available: [
2382 "//apex_available:platform",
2383 "myapex",
2384 ],
Alex Light9670d332019-01-29 18:07:33 -08002385 }
2386
2387 cc_library {
2388 name: "mylib_common",
2389 srcs: ["mylib.cpp"],
2390 system_shared_libs: [],
2391 stl: "none",
2392 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002393 // TODO: remove //apex_available:platform
2394 apex_available: [
2395 "//apex_available:platform",
2396 "myapex",
2397 ],
Alex Light9670d332019-01-29 18:07:33 -08002398 }
2399
2400 cc_library {
2401 name: "mylib2",
2402 srcs: ["mylib.cpp"],
2403 system_shared_libs: [],
2404 stl: "none",
2405 compile_multilib: "first",
2406 }
2407 `)
2408
Sundong Ahnabb64432019-10-22 13:58:29 +09002409 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002410 copyCmds := apexRule.Args["copy_commands"]
2411
2412 // Ensure that main rule creates an output
2413 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2414
2415 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002416 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2417 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2418 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002419
2420 // Ensure that both direct and indirect deps are copied into apex
2421 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2422 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2423 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2424
Colin Cross7113d202019-11-20 16:39:12 -08002425 // Ensure that the platform variant ends with _shared
2426 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2427 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2428 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002429}
Jiyong Park04480cf2019-02-06 00:16:29 +09002430
2431func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002432 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002433 apex {
2434 name: "myapex",
2435 key: "myapex.key",
2436 binaries: ["myscript"],
2437 }
2438
2439 apex_key {
2440 name: "myapex.key",
2441 public_key: "testkey.avbpubkey",
2442 private_key: "testkey.pem",
2443 }
2444
2445 sh_binary {
2446 name: "myscript",
2447 src: "mylib.cpp",
2448 filename: "myscript.sh",
2449 sub_dir: "script",
2450 }
2451 `)
2452
Sundong Ahnabb64432019-10-22 13:58:29 +09002453 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002454 copyCmds := apexRule.Args["copy_commands"]
2455
2456 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2457}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002458
Jooyung Han91df2082019-11-20 01:49:42 +09002459func TestApexInVariousPartition(t *testing.T) {
2460 testcases := []struct {
2461 propName, parition, flattenedPartition string
2462 }{
2463 {"", "system", "system_ext"},
2464 {"product_specific: true", "product", "product"},
2465 {"soc_specific: true", "vendor", "vendor"},
2466 {"proprietary: true", "vendor", "vendor"},
2467 {"vendor: true", "vendor", "vendor"},
2468 {"system_ext_specific: true", "system_ext", "system_ext"},
2469 }
2470 for _, tc := range testcases {
2471 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2472 ctx, _ := testApex(t, `
2473 apex {
2474 name: "myapex",
2475 key: "myapex.key",
2476 `+tc.propName+`
2477 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002478
Jooyung Han91df2082019-11-20 01:49:42 +09002479 apex_key {
2480 name: "myapex.key",
2481 public_key: "testkey.avbpubkey",
2482 private_key: "testkey.pem",
2483 }
2484 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002485
Jooyung Han91df2082019-11-20 01:49:42 +09002486 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2487 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2488 actual := apex.installDir.String()
2489 if actual != expected {
2490 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2491 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002492
Jooyung Han91df2082019-11-20 01:49:42 +09002493 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2494 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2495 actual = flattened.installDir.String()
2496 if actual != expected {
2497 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2498 }
2499 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002500 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002501}
Jiyong Park67882562019-03-21 01:11:21 +09002502
Jooyung Han54aca7b2019-11-20 02:26:02 +09002503func TestFileContexts(t *testing.T) {
2504 ctx, _ := testApex(t, `
2505 apex {
2506 name: "myapex",
2507 key: "myapex.key",
2508 }
2509
2510 apex_key {
2511 name: "myapex.key",
2512 public_key: "testkey.avbpubkey",
2513 private_key: "testkey.pem",
2514 }
2515 `)
2516 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2517 apexRule := module.Rule("apexRule")
2518 actual := apexRule.Args["file_contexts"]
2519 expected := "system/sepolicy/apex/myapex-file_contexts"
2520 if actual != expected {
2521 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2522 }
2523
2524 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2525 apex {
2526 name: "myapex",
2527 key: "myapex.key",
2528 file_contexts: "my_own_file_contexts",
2529 }
2530
2531 apex_key {
2532 name: "myapex.key",
2533 public_key: "testkey.avbpubkey",
2534 private_key: "testkey.pem",
2535 }
2536 `, withFiles(map[string][]byte{
2537 "my_own_file_contexts": nil,
2538 }))
2539
2540 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2541 apex {
2542 name: "myapex",
2543 key: "myapex.key",
2544 product_specific: true,
2545 file_contexts: "product_specific_file_contexts",
2546 }
2547
2548 apex_key {
2549 name: "myapex.key",
2550 public_key: "testkey.avbpubkey",
2551 private_key: "testkey.pem",
2552 }
2553 `)
2554
2555 ctx, _ = testApex(t, `
2556 apex {
2557 name: "myapex",
2558 key: "myapex.key",
2559 product_specific: true,
2560 file_contexts: "product_specific_file_contexts",
2561 }
2562
2563 apex_key {
2564 name: "myapex.key",
2565 public_key: "testkey.avbpubkey",
2566 private_key: "testkey.pem",
2567 }
2568 `, withFiles(map[string][]byte{
2569 "product_specific_file_contexts": nil,
2570 }))
2571 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2572 apexRule = module.Rule("apexRule")
2573 actual = apexRule.Args["file_contexts"]
2574 expected = "product_specific_file_contexts"
2575 if actual != expected {
2576 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2577 }
2578
2579 ctx, _ = testApex(t, `
2580 apex {
2581 name: "myapex",
2582 key: "myapex.key",
2583 product_specific: true,
2584 file_contexts: ":my-file-contexts",
2585 }
2586
2587 apex_key {
2588 name: "myapex.key",
2589 public_key: "testkey.avbpubkey",
2590 private_key: "testkey.pem",
2591 }
2592
2593 filegroup {
2594 name: "my-file-contexts",
2595 srcs: ["product_specific_file_contexts"],
2596 }
2597 `, withFiles(map[string][]byte{
2598 "product_specific_file_contexts": nil,
2599 }))
2600 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2601 apexRule = module.Rule("apexRule")
2602 actual = apexRule.Args["file_contexts"]
2603 expected = "product_specific_file_contexts"
2604 if actual != expected {
2605 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2606 }
2607}
2608
Jiyong Park67882562019-03-21 01:11:21 +09002609func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002610 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002611 apex_key {
2612 name: "myapex.key",
2613 public_key: ":my.avbpubkey",
2614 private_key: ":my.pem",
2615 product_specific: true,
2616 }
2617
2618 filegroup {
2619 name: "my.avbpubkey",
2620 srcs: ["testkey2.avbpubkey"],
2621 }
2622
2623 filegroup {
2624 name: "my.pem",
2625 srcs: ["testkey2.pem"],
2626 }
2627 `)
2628
2629 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2630 expected_pubkey := "testkey2.avbpubkey"
2631 actual_pubkey := apex_key.public_key_file.String()
2632 if actual_pubkey != expected_pubkey {
2633 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2634 }
2635 expected_privkey := "testkey2.pem"
2636 actual_privkey := apex_key.private_key_file.String()
2637 if actual_privkey != expected_privkey {
2638 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2639 }
2640}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002641
2642func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002643 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002644 prebuilt_apex {
2645 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002646 arch: {
2647 arm64: {
2648 src: "myapex-arm64.apex",
2649 },
2650 arm: {
2651 src: "myapex-arm.apex",
2652 },
2653 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002654 }
2655 `)
2656
2657 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2658
Jiyong Parkc95714e2019-03-29 14:23:10 +09002659 expectedInput := "myapex-arm64.apex"
2660 if prebuilt.inputApex.String() != expectedInput {
2661 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2662 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002663}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002664
2665func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002666 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002667 prebuilt_apex {
2668 name: "myapex",
2669 src: "myapex-arm.apex",
2670 filename: "notmyapex.apex",
2671 }
2672 `)
2673
2674 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2675
2676 expected := "notmyapex.apex"
2677 if p.installFilename != expected {
2678 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2679 }
2680}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002681
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002682func TestPrebuiltOverrides(t *testing.T) {
2683 ctx, config := testApex(t, `
2684 prebuilt_apex {
2685 name: "myapex.prebuilt",
2686 src: "myapex-arm.apex",
2687 overrides: [
2688 "myapex",
2689 ],
2690 }
2691 `)
2692
2693 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2694
2695 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002696 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002697 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002698 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002699 }
2700}
2701
Roland Levillain630846d2019-06-26 12:48:34 +01002702func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002703 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002704 apex_test {
2705 name: "myapex",
2706 key: "myapex.key",
2707 tests: [
2708 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002709 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002710 ],
2711 }
2712
2713 apex_key {
2714 name: "myapex.key",
2715 public_key: "testkey.avbpubkey",
2716 private_key: "testkey.pem",
2717 }
2718
2719 cc_test {
2720 name: "mytest",
2721 gtest: false,
2722 srcs: ["mytest.cpp"],
2723 relative_install_path: "test",
2724 system_shared_libs: [],
2725 static_executable: true,
2726 stl: "none",
2727 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002728
2729 cc_test {
2730 name: "mytests",
2731 gtest: false,
2732 srcs: [
2733 "mytest1.cpp",
2734 "mytest2.cpp",
2735 "mytest3.cpp",
2736 ],
2737 test_per_src: true,
2738 relative_install_path: "test",
2739 system_shared_libs: [],
2740 static_executable: true,
2741 stl: "none",
2742 }
Roland Levillain630846d2019-06-26 12:48:34 +01002743 `)
2744
Sundong Ahnabb64432019-10-22 13:58:29 +09002745 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002746 copyCmds := apexRule.Args["copy_commands"]
2747
2748 // Ensure that test dep is copied into apex.
2749 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002750
2751 // Ensure that test deps built with `test_per_src` are copied into apex.
2752 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2753 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2754 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002755
2756 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002757 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002758 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2759 name := apexBundle.BaseModuleName()
2760 prefix := "TARGET_"
2761 var builder strings.Builder
2762 data.Custom(&builder, name, prefix, "", data)
2763 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002764 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2765 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2766 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2767 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09002768 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09002769 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002770 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002771}
2772
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002773func TestInstallExtraFlattenedApexes(t *testing.T) {
2774 ctx, config := testApex(t, `
2775 apex {
2776 name: "myapex",
2777 key: "myapex.key",
2778 }
2779 apex_key {
2780 name: "myapex.key",
2781 public_key: "testkey.avbpubkey",
2782 private_key: "testkey.pem",
2783 }
2784 `, func(fs map[string][]byte, config android.Config) {
2785 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
2786 })
2787 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09002788 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002789 mk := android.AndroidMkDataForTest(t, config, "", ab)
2790 var builder strings.Builder
2791 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
2792 androidMk := builder.String()
2793 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
2794}
2795
Jooyung Han5c998b92019-06-27 11:30:33 +09002796func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002797 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002798 apex {
2799 name: "myapex",
2800 key: "myapex.key",
2801 native_shared_libs: ["mylib"],
2802 uses: ["commonapex"],
2803 }
2804
2805 apex {
2806 name: "commonapex",
2807 key: "myapex.key",
2808 native_shared_libs: ["libcommon"],
2809 provide_cpp_shared_libs: true,
2810 }
2811
2812 apex_key {
2813 name: "myapex.key",
2814 public_key: "testkey.avbpubkey",
2815 private_key: "testkey.pem",
2816 }
2817
2818 cc_library {
2819 name: "mylib",
2820 srcs: ["mylib.cpp"],
2821 shared_libs: ["libcommon"],
2822 system_shared_libs: [],
2823 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002824 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09002825 }
2826
2827 cc_library {
2828 name: "libcommon",
2829 srcs: ["mylib_common.cpp"],
2830 system_shared_libs: [],
2831 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002832 // TODO: remove //apex_available:platform
2833 apex_available: [
2834 "//apex_available:platform",
2835 "commonapex",
2836 "myapex",
2837 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09002838 }
2839 `)
2840
Sundong Ahnabb64432019-10-22 13:58:29 +09002841 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002842 apexRule1 := module1.Rule("apexRule")
2843 copyCmds1 := apexRule1.Args["copy_commands"]
2844
Sundong Ahnabb64432019-10-22 13:58:29 +09002845 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002846 apexRule2 := module2.Rule("apexRule")
2847 copyCmds2 := apexRule2.Args["copy_commands"]
2848
Colin Cross7113d202019-11-20 16:39:12 -08002849 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2850 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09002851 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2852 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2853 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2854}
2855
2856func TestApexUsesFailsIfNotProvided(t *testing.T) {
2857 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2858 apex {
2859 name: "myapex",
2860 key: "myapex.key",
2861 uses: ["commonapex"],
2862 }
2863
2864 apex {
2865 name: "commonapex",
2866 key: "myapex.key",
2867 }
2868
2869 apex_key {
2870 name: "myapex.key",
2871 public_key: "testkey.avbpubkey",
2872 private_key: "testkey.pem",
2873 }
2874 `)
2875 testApexError(t, `uses: "commonapex" is not a provider`, `
2876 apex {
2877 name: "myapex",
2878 key: "myapex.key",
2879 uses: ["commonapex"],
2880 }
2881
2882 cc_library {
2883 name: "commonapex",
2884 system_shared_libs: [],
2885 stl: "none",
2886 }
2887
2888 apex_key {
2889 name: "myapex.key",
2890 public_key: "testkey.avbpubkey",
2891 private_key: "testkey.pem",
2892 }
2893 `)
2894}
2895
2896func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2897 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2898 apex {
2899 name: "myapex",
2900 key: "myapex.key",
2901 use_vendor: true,
2902 uses: ["commonapex"],
2903 }
2904
2905 apex {
2906 name: "commonapex",
2907 key: "myapex.key",
2908 provide_cpp_shared_libs: true,
2909 }
2910
2911 apex_key {
2912 name: "myapex.key",
2913 public_key: "testkey.avbpubkey",
2914 private_key: "testkey.pem",
2915 }
Jooyung Handc782442019-11-01 03:14:38 +09002916 `, func(fs map[string][]byte, config android.Config) {
2917 setUseVendorWhitelistForTest(config, []string{"myapex"})
2918 })
Jooyung Han5c998b92019-06-27 11:30:33 +09002919}
2920
Jooyung Hand48f3c32019-08-23 11:18:57 +09002921func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2922 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2923 apex {
2924 name: "myapex",
2925 key: "myapex.key",
2926 native_shared_libs: ["libfoo"],
2927 }
2928
2929 apex_key {
2930 name: "myapex.key",
2931 public_key: "testkey.avbpubkey",
2932 private_key: "testkey.pem",
2933 }
2934
2935 cc_library {
2936 name: "libfoo",
2937 stl: "none",
2938 system_shared_libs: [],
2939 enabled: false,
2940 }
2941 `)
2942 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2943 apex {
2944 name: "myapex",
2945 key: "myapex.key",
2946 java_libs: ["myjar"],
2947 }
2948
2949 apex_key {
2950 name: "myapex.key",
2951 public_key: "testkey.avbpubkey",
2952 private_key: "testkey.pem",
2953 }
2954
2955 java_library {
2956 name: "myjar",
2957 srcs: ["foo/bar/MyClass.java"],
2958 sdk_version: "none",
2959 system_modules: "none",
2960 compile_dex: true,
2961 enabled: false,
2962 }
2963 `)
2964}
2965
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002966func TestApexWithApps(t *testing.T) {
2967 ctx, _ := testApex(t, `
2968 apex {
2969 name: "myapex",
2970 key: "myapex.key",
2971 apps: [
2972 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002973 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002974 ],
2975 }
2976
2977 apex_key {
2978 name: "myapex.key",
2979 public_key: "testkey.avbpubkey",
2980 private_key: "testkey.pem",
2981 }
2982
2983 android_app {
2984 name: "AppFoo",
2985 srcs: ["foo/bar/MyClass.java"],
2986 sdk_version: "none",
2987 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09002988 jni_libs: ["libjni"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002989 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002990 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002991
2992 android_app {
2993 name: "AppFooPriv",
2994 srcs: ["foo/bar/MyClass.java"],
2995 sdk_version: "none",
2996 system_modules: "none",
2997 privileged: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002998 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09002999 }
Jiyong Park8be103b2019-11-08 15:53:48 +09003000
3001 cc_library_shared {
3002 name: "libjni",
3003 srcs: ["mylib.cpp"],
3004 stl: "none",
3005 system_shared_libs: [],
3006 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003007 `)
3008
Sundong Ahnabb64432019-10-22 13:58:29 +09003009 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003010 apexRule := module.Rule("apexRule")
3011 copyCmds := apexRule.Args["copy_commands"]
3012
3013 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003014 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003015
3016 // JNI libraries are embedded inside APK
3017 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Rule("zip")
Colin Cross7113d202019-11-20 16:39:12 -08003018 libjniOutput := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
Jiyong Park52cd06f2019-11-11 10:14:32 +09003019 ensureListContains(t, appZipRule.Implicits.Strings(), libjniOutput.String())
3020 // ... uncompressed
3021 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
3022 t.Errorf("jni lib is not uncompressed for AppFoo")
3023 }
3024 // ... and not directly inside the APEX
3025 ensureNotContains(t, copyCmds, "image.apex/lib64/libjni.so")
Dario Frenicde2a032019-10-27 00:29:22 +01003026}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003027
Dario Frenicde2a032019-10-27 00:29:22 +01003028func TestApexWithAppImports(t *testing.T) {
3029 ctx, _ := testApex(t, `
3030 apex {
3031 name: "myapex",
3032 key: "myapex.key",
3033 apps: [
3034 "AppFooPrebuilt",
3035 "AppFooPrivPrebuilt",
3036 ],
3037 }
3038
3039 apex_key {
3040 name: "myapex.key",
3041 public_key: "testkey.avbpubkey",
3042 private_key: "testkey.pem",
3043 }
3044
3045 android_app_import {
3046 name: "AppFooPrebuilt",
3047 apk: "PrebuiltAppFoo.apk",
3048 presigned: true,
3049 dex_preopt: {
3050 enabled: false,
3051 },
3052 }
3053
3054 android_app_import {
3055 name: "AppFooPrivPrebuilt",
3056 apk: "PrebuiltAppFooPriv.apk",
3057 privileged: true,
3058 presigned: true,
3059 dex_preopt: {
3060 enabled: false,
3061 },
3062 }
3063 `)
3064
Sundong Ahnabb64432019-10-22 13:58:29 +09003065 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003066 apexRule := module.Rule("apexRule")
3067 copyCmds := apexRule.Args["copy_commands"]
3068
3069 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3070 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003071}
3072
Dario Freni6f3937c2019-12-20 22:58:03 +00003073func TestApexWithTestHelperApp(t *testing.T) {
3074 ctx, _ := testApex(t, `
3075 apex {
3076 name: "myapex",
3077 key: "myapex.key",
3078 apps: [
3079 "TesterHelpAppFoo",
3080 ],
3081 }
3082
3083 apex_key {
3084 name: "myapex.key",
3085 public_key: "testkey.avbpubkey",
3086 private_key: "testkey.pem",
3087 }
3088
3089 android_test_helper_app {
3090 name: "TesterHelpAppFoo",
3091 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003092 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003093 }
3094
3095 `)
3096
3097 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3098 apexRule := module.Rule("apexRule")
3099 copyCmds := apexRule.Args["copy_commands"]
3100
3101 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3102}
3103
Jooyung Han18020ea2019-11-13 10:50:48 +09003104func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3105 // libfoo's apex_available comes from cc_defaults
3106 testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, `
3107 apex {
3108 name: "myapex",
3109 key: "myapex.key",
3110 native_shared_libs: ["libfoo"],
3111 }
3112
3113 apex_key {
3114 name: "myapex.key",
3115 public_key: "testkey.avbpubkey",
3116 private_key: "testkey.pem",
3117 }
3118
3119 apex {
3120 name: "otherapex",
3121 key: "myapex.key",
3122 native_shared_libs: ["libfoo"],
3123 }
3124
3125 cc_defaults {
3126 name: "libfoo-defaults",
3127 apex_available: ["otherapex"],
3128 }
3129
3130 cc_library {
3131 name: "libfoo",
3132 defaults: ["libfoo-defaults"],
3133 stl: "none",
3134 system_shared_libs: [],
3135 }`)
3136}
3137
Jiyong Park127b40b2019-09-30 16:04:35 +09003138func TestApexAvailable(t *testing.T) {
3139 // libfoo is not available to myapex, but only to otherapex
3140 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3141 apex {
3142 name: "myapex",
3143 key: "myapex.key",
3144 native_shared_libs: ["libfoo"],
3145 }
3146
3147 apex_key {
3148 name: "myapex.key",
3149 public_key: "testkey.avbpubkey",
3150 private_key: "testkey.pem",
3151 }
3152
3153 apex {
3154 name: "otherapex",
3155 key: "otherapex.key",
3156 native_shared_libs: ["libfoo"],
3157 }
3158
3159 apex_key {
3160 name: "otherapex.key",
3161 public_key: "testkey.avbpubkey",
3162 private_key: "testkey.pem",
3163 }
3164
3165 cc_library {
3166 name: "libfoo",
3167 stl: "none",
3168 system_shared_libs: [],
3169 apex_available: ["otherapex"],
3170 }`)
3171
3172 // libbar is an indirect dep
3173 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
3174 apex {
3175 name: "myapex",
3176 key: "myapex.key",
3177 native_shared_libs: ["libfoo"],
3178 }
3179
3180 apex_key {
3181 name: "myapex.key",
3182 public_key: "testkey.avbpubkey",
3183 private_key: "testkey.pem",
3184 }
3185
3186 apex {
3187 name: "otherapex",
3188 key: "otherapex.key",
3189 native_shared_libs: ["libfoo"],
3190 }
3191
3192 apex_key {
3193 name: "otherapex.key",
3194 public_key: "testkey.avbpubkey",
3195 private_key: "testkey.pem",
3196 }
3197
3198 cc_library {
3199 name: "libfoo",
3200 stl: "none",
3201 shared_libs: ["libbar"],
3202 system_shared_libs: [],
3203 apex_available: ["myapex", "otherapex"],
3204 }
3205
3206 cc_library {
3207 name: "libbar",
3208 stl: "none",
3209 system_shared_libs: [],
3210 apex_available: ["otherapex"],
3211 }`)
3212
3213 testApexError(t, "\"otherapex\" is not a valid module name", `
3214 apex {
3215 name: "myapex",
3216 key: "myapex.key",
3217 native_shared_libs: ["libfoo"],
3218 }
3219
3220 apex_key {
3221 name: "myapex.key",
3222 public_key: "testkey.avbpubkey",
3223 private_key: "testkey.pem",
3224 }
3225
3226 cc_library {
3227 name: "libfoo",
3228 stl: "none",
3229 system_shared_libs: [],
3230 apex_available: ["otherapex"],
3231 }`)
3232
3233 ctx, _ := testApex(t, `
3234 apex {
3235 name: "myapex",
3236 key: "myapex.key",
3237 native_shared_libs: ["libfoo", "libbar"],
3238 }
3239
3240 apex_key {
3241 name: "myapex.key",
3242 public_key: "testkey.avbpubkey",
3243 private_key: "testkey.pem",
3244 }
3245
3246 cc_library {
3247 name: "libfoo",
3248 stl: "none",
3249 system_shared_libs: [],
3250 apex_available: ["myapex"],
3251 }
3252
3253 cc_library {
3254 name: "libbar",
3255 stl: "none",
3256 system_shared_libs: [],
3257 apex_available: ["//apex_available:anyapex"],
3258 }`)
3259
3260 // check that libfoo and libbar are created only for myapex, but not for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003261 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3262 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3263 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3264 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003265
3266 ctx, _ = testApex(t, `
3267 apex {
3268 name: "myapex",
3269 key: "myapex.key",
3270 }
3271
3272 apex_key {
3273 name: "myapex.key",
3274 public_key: "testkey.avbpubkey",
3275 private_key: "testkey.pem",
3276 }
3277
3278 cc_library {
3279 name: "libfoo",
3280 stl: "none",
3281 system_shared_libs: [],
3282 apex_available: ["//apex_available:platform"],
3283 }`)
3284
3285 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003286 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3287 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003288
3289 ctx, _ = testApex(t, `
3290 apex {
3291 name: "myapex",
3292 key: "myapex.key",
3293 native_shared_libs: ["libfoo"],
3294 }
3295
3296 apex_key {
3297 name: "myapex.key",
3298 public_key: "testkey.avbpubkey",
3299 private_key: "testkey.pem",
3300 }
3301
3302 cc_library {
3303 name: "libfoo",
3304 stl: "none",
3305 system_shared_libs: [],
3306 apex_available: ["myapex"],
3307 static: {
3308 apex_available: ["//apex_available:platform"],
3309 },
3310 }`)
3311
3312 // shared variant of libfoo is only available to myapex
Colin Cross7113d202019-11-20 16:39:12 -08003313 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3314 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003315 // but the static variant is available to both myapex and the platform
Colin Cross7113d202019-11-20 16:39:12 -08003316 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3317 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003318}
3319
Jiyong Park5d790c32019-11-15 18:40:32 +09003320func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003321 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003322 apex {
3323 name: "myapex",
3324 key: "myapex.key",
3325 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003326 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003327 }
3328
3329 override_apex {
3330 name: "override_myapex",
3331 base: "myapex",
3332 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003333 overrides: ["unknownapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003334 }
3335
3336 apex_key {
3337 name: "myapex.key",
3338 public_key: "testkey.avbpubkey",
3339 private_key: "testkey.pem",
3340 }
3341
3342 android_app {
3343 name: "app",
3344 srcs: ["foo/bar/MyClass.java"],
3345 package_name: "foo",
3346 sdk_version: "none",
3347 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003348 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003349 }
3350
3351 override_android_app {
3352 name: "override_app",
3353 base: "app",
3354 package_name: "bar",
3355 }
3356 `)
3357
Jiyong Park317645e2019-12-05 13:20:58 +09003358 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3359 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3360 if originalVariant.GetOverriddenBy() != "" {
3361 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3362 }
3363 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3364 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3365 }
3366
Jiyong Park5d790c32019-11-15 18:40:32 +09003367 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3368 apexRule := module.Rule("apexRule")
3369 copyCmds := apexRule.Args["copy_commands"]
3370
3371 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3372 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003373
3374 apexBundle := module.Module().(*apexBundle)
3375 name := apexBundle.Name()
3376 if name != "override_myapex" {
3377 t.Errorf("name should be \"override_myapex\", but was %q", name)
3378 }
3379
3380 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3381 var builder strings.Builder
3382 data.Custom(&builder, name, "TARGET_", "", data)
3383 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003384 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003385 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3386 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003387 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003388 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003389 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003390 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3391 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003392}
3393
Jooyung Han214bf372019-11-12 13:03:50 +09003394func TestLegacyAndroid10Support(t *testing.T) {
3395 ctx, _ := testApex(t, `
3396 apex {
3397 name: "myapex",
3398 key: "myapex.key",
3399 legacy_android10_support: true,
3400 }
3401
3402 apex_key {
3403 name: "myapex.key",
3404 public_key: "testkey.avbpubkey",
3405 private_key: "testkey.pem",
3406 }
3407 `)
3408
3409 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3410 args := module.Rule("apexRule").Args
3411 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003412 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Jooyung Han214bf372019-11-12 13:03:50 +09003413}
3414
Jooyung Han58f26ab2019-12-18 15:34:32 +09003415func TestJavaSDKLibrary(t *testing.T) {
3416 ctx, _ := testApex(t, `
3417 apex {
3418 name: "myapex",
3419 key: "myapex.key",
3420 java_libs: ["foo"],
3421 }
3422
3423 apex_key {
3424 name: "myapex.key",
3425 public_key: "testkey.avbpubkey",
3426 private_key: "testkey.pem",
3427 }
3428
3429 java_sdk_library {
3430 name: "foo",
3431 srcs: ["a.java"],
3432 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003433 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003434 }
3435 `, withFiles(map[string][]byte{
3436 "api/current.txt": nil,
3437 "api/removed.txt": nil,
3438 "api/system-current.txt": nil,
3439 "api/system-removed.txt": nil,
3440 "api/test-current.txt": nil,
3441 "api/test-removed.txt": nil,
3442 }))
3443
3444 // java_sdk_library installs both impl jar and permission XML
Jooyung Hana57af4a2020-01-23 05:36:59 +00003445 ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003446 "javalib/foo.jar",
3447 "etc/permissions/foo.xml",
3448 })
3449 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jooyung Han624058e2019-12-24 18:38:06 +09003450 xml := ctx.ModuleForTests("foo", "android_common_myapex").Output("foo.xml")
3451 ensureContains(t, xml.Args["content"], `<library name="foo" file="/apex/myapex/javalib/foo.jar"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003452}
3453
Jiyong Park479321d2019-12-16 11:47:12 +09003454func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3455 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3456 apex {
3457 name: "myapex",
3458 key: "myapex.key",
3459 java_libs: ["myjar"],
3460 }
3461
3462 apex_key {
3463 name: "myapex.key",
3464 public_key: "testkey.avbpubkey",
3465 private_key: "testkey.pem",
3466 }
3467
3468 java_library {
3469 name: "myjar",
3470 srcs: ["foo/bar/MyClass.java"],
3471 sdk_version: "none",
3472 system_modules: "none",
3473 }
3474 `)
3475}
3476
Jiyong Park7afd1072019-12-30 16:56:33 +09003477func TestCarryRequiredModuleNames(t *testing.T) {
3478 ctx, config := testApex(t, `
3479 apex {
3480 name: "myapex",
3481 key: "myapex.key",
3482 native_shared_libs: ["mylib"],
3483 }
3484
3485 apex_key {
3486 name: "myapex.key",
3487 public_key: "testkey.avbpubkey",
3488 private_key: "testkey.pem",
3489 }
3490
3491 cc_library {
3492 name: "mylib",
3493 srcs: ["mylib.cpp"],
3494 system_shared_libs: [],
3495 stl: "none",
3496 required: ["a", "b"],
3497 host_required: ["c", "d"],
3498 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003499 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003500 }
3501 `)
3502
3503 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3504 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3505 name := apexBundle.BaseModuleName()
3506 prefix := "TARGET_"
3507 var builder strings.Builder
3508 data.Custom(&builder, name, prefix, "", data)
3509 androidMk := builder.String()
3510 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3511 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3512 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3513}
3514
Jiyong Park7cd10e32020-01-14 09:22:18 +09003515func TestSymlinksFromApexToSystem(t *testing.T) {
3516 bp := `
3517 apex {
3518 name: "myapex",
3519 key: "myapex.key",
3520 native_shared_libs: ["mylib"],
3521 java_libs: ["myjar"],
3522 }
3523
3524 apex_key {
3525 name: "myapex.key",
3526 public_key: "testkey.avbpubkey",
3527 private_key: "testkey.pem",
3528 }
3529
3530 cc_library {
3531 name: "mylib",
3532 srcs: ["mylib.cpp"],
3533 shared_libs: ["myotherlib"],
3534 system_shared_libs: [],
3535 stl: "none",
3536 apex_available: [
3537 "myapex",
3538 "//apex_available:platform",
3539 ],
3540 }
3541
3542 cc_library {
3543 name: "myotherlib",
3544 srcs: ["mylib.cpp"],
3545 system_shared_libs: [],
3546 stl: "none",
3547 apex_available: [
3548 "myapex",
3549 "//apex_available:platform",
3550 ],
3551 }
3552
3553 java_library {
3554 name: "myjar",
3555 srcs: ["foo/bar/MyClass.java"],
3556 sdk_version: "none",
3557 system_modules: "none",
3558 libs: ["myotherjar"],
3559 compile_dex: true,
3560 apex_available: [
3561 "myapex",
3562 "//apex_available:platform",
3563 ],
3564 }
3565
3566 java_library {
3567 name: "myotherjar",
3568 srcs: ["foo/bar/MyClass.java"],
3569 sdk_version: "none",
3570 system_modules: "none",
3571 apex_available: [
3572 "myapex",
3573 "//apex_available:platform",
3574 ],
3575 }
3576 `
3577
3578 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3579 for _, f := range files {
3580 if f.path == file {
3581 if f.isLink {
3582 t.Errorf("%q is not a real file", file)
3583 }
3584 return
3585 }
3586 }
3587 t.Errorf("%q is not found", file)
3588 }
3589
3590 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3591 for _, f := range files {
3592 if f.path == file {
3593 if !f.isLink {
3594 t.Errorf("%q is not a symlink", file)
3595 }
3596 return
3597 }
3598 }
3599 t.Errorf("%q is not found", file)
3600 }
3601
3602 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003603 files := getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003604 ensureRealfileExists(t, files, "javalib/myjar.jar")
3605 ensureRealfileExists(t, files, "lib64/mylib.so")
3606 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3607
3608 ctx, _ = testApex(t, bp)
Jooyung Hana57af4a2020-01-23 05:36:59 +00003609 files = getFiles(t, ctx, "myapex", "android_common_myapex_image")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003610 ensureRealfileExists(t, files, "javalib/myjar.jar")
3611 ensureRealfileExists(t, files, "lib64/mylib.so")
3612 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
3613}
3614
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07003615func TestMain(m *testing.M) {
3616 run := func() int {
3617 setUp()
3618 defer tearDown()
3619
3620 return m.Run()
3621 }
3622
3623 os.Exit(run())
3624}