blob: 1a9b95cea0514959a032cdeb5810a3eb410c4bcd [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
Paul Duffin77980a82019-12-19 16:01:36 +0000294 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross98be1bb2019-12-13 20:41:13 -0800295 ctx.RegisterModuleType("cc_test", cc.TestFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800296 ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory)
297 ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800298 ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory)
299 ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800300 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000301 java.RegisterJavaBuildComponents(ctx)
Paul Duffin43dc1cc2019-12-19 11:18:54 +0000302 java.RegisterSystemModulesBuildComponents(ctx)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000303 java.RegisterAppBuildComponents(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900304 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -0800305
Jooyung Han5df3b112020-01-23 05:10:16 +0000306 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800307 ctx.PreDepsMutators(RegisterPreDepsMutators)
Jooyung Han5df3b112020-01-23 05:10:16 +0000308 ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800309 ctx.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross98be1bb2019-12-13 20:41:13 -0800310
311 ctx.Register(config)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900312
Jooyung Han5c998b92019-06-27 11:30:33 +0900313 return ctx, config
Jiyong Park25fc6a92018-11-18 18:02:45 +0900314}
315
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700316func setUp() {
317 var err error
318 buildDir, err = ioutil.TempDir("", "soong_apex_test")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900319 if err != nil {
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700320 panic(err)
Jiyong Park25fc6a92018-11-18 18:02:45 +0900321 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900322}
323
Jaewoong Jungc1001ec2019-06-25 11:20:53 -0700324func tearDown() {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900325 os.RemoveAll(buildDir)
326}
327
328// ensure that 'result' contains 'expected'
329func ensureContains(t *testing.T, result string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900330 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900331 if !strings.Contains(result, expected) {
332 t.Errorf("%q is not found in %q", expected, result)
333 }
334}
335
336// ensures that 'result' does not contain 'notExpected'
337func ensureNotContains(t *testing.T, result string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900338 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900339 if strings.Contains(result, notExpected) {
340 t.Errorf("%q is found in %q", notExpected, result)
341 }
342}
343
344func ensureListContains(t *testing.T, result []string, expected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900345 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900346 if !android.InList(expected, result) {
347 t.Errorf("%q is not found in %v", expected, result)
348 }
349}
350
351func ensureListNotContains(t *testing.T, result []string, notExpected string) {
Jooyung Han5c998b92019-06-27 11:30:33 +0900352 t.Helper()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900353 if android.InList(notExpected, result) {
354 t.Errorf("%q is found in %v", notExpected, result)
355 }
356}
357
Jooyung Hane1633032019-08-01 17:41:43 +0900358func ensureListEmpty(t *testing.T, result []string) {
359 t.Helper()
360 if len(result) > 0 {
361 t.Errorf("%q is expected to be empty", result)
362 }
363}
364
Jiyong Park25fc6a92018-11-18 18:02:45 +0900365// Minimal test
366func TestBasicApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700367 ctx, _ := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900368 apex_defaults {
369 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900370 manifest: ":myapex.manifest",
371 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900372 key: "myapex.key",
373 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800374 multilib: {
375 both: {
376 binaries: ["foo",],
377 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900378 },
Jooyung Han5a80d9f2019-12-23 15:38:34 +0900379 java_libs: ["myjar"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900380 }
381
Jiyong Park30ca9372019-02-07 16:27:23 +0900382 apex {
383 name: "myapex",
384 defaults: ["myapex-defaults"],
385 }
386
Jiyong Park25fc6a92018-11-18 18:02:45 +0900387 apex_key {
388 name: "myapex.key",
389 public_key: "testkey.avbpubkey",
390 private_key: "testkey.pem",
391 }
392
Jiyong Park809bb722019-02-13 21:33:49 +0900393 filegroup {
394 name: "myapex.manifest",
395 srcs: ["apex_manifest.json"],
396 }
397
398 filegroup {
399 name: "myapex.androidmanifest",
400 srcs: ["AndroidManifest.xml"],
401 }
402
Jiyong Park25fc6a92018-11-18 18:02:45 +0900403 cc_library {
404 name: "mylib",
405 srcs: ["mylib.cpp"],
406 shared_libs: ["mylib2"],
407 system_shared_libs: [],
408 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000409 // TODO: remove //apex_available:platform
410 apex_available: [
411 "//apex_available:platform",
412 "myapex",
413 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900414 }
415
Alex Light3d673592019-01-18 14:37:31 -0800416 cc_binary {
417 name: "foo",
418 srcs: ["mylib.cpp"],
419 compile_multilib: "both",
420 multilib: {
421 lib32: {
422 suffix: "32",
423 },
424 lib64: {
425 suffix: "64",
426 },
427 },
428 symlinks: ["foo_link_"],
429 symlink_preferred_arch: true,
430 system_shared_libs: [],
431 static_executable: true,
432 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000433 apex_available: [ "myapex" ],
Alex Light3d673592019-01-18 14:37:31 -0800434 }
435
Jiyong Park25fc6a92018-11-18 18:02:45 +0900436 cc_library {
437 name: "mylib2",
438 srcs: ["mylib.cpp"],
439 system_shared_libs: [],
440 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900441 notice: "custom_notice",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000442 // TODO: remove //apex_available:platform
443 apex_available: [
444 "//apex_available:platform",
445 "myapex",
446 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900447 }
Jiyong Park7f7766d2019-07-25 22:02:35 +0900448
449 java_library {
450 name: "myjar",
451 srcs: ["foo/bar/MyClass.java"],
452 sdk_version: "none",
453 system_modules: "none",
454 compile_dex: true,
455 static_libs: ["myotherjar"],
Jiyong Park3ff16992019-12-27 14:11:47 +0900456 libs: ["mysharedjar"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000457 // TODO: remove //apex_available:platform
458 apex_available: [
459 "//apex_available:platform",
460 "myapex",
461 ],
Jiyong Park7f7766d2019-07-25 22:02:35 +0900462 }
463
464 java_library {
465 name: "myotherjar",
466 srcs: ["foo/bar/MyClass.java"],
467 sdk_version: "none",
468 system_modules: "none",
469 compile_dex: true,
470 }
Jiyong Park3ff16992019-12-27 14:11:47 +0900471
472 java_library {
473 name: "mysharedjar",
474 srcs: ["foo/bar/MyClass.java"],
475 sdk_version: "none",
476 system_modules: "none",
477 compile_dex: true,
478 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900479 `)
480
Sundong Ahnabb64432019-10-22 13:58:29 +0900481 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900482
483 optFlags := apexRule.Args["opt_flags"]
484 ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey")
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700485 // Ensure that the NOTICE output is being packaged as an asset.
Sundong Ahnabb64432019-10-22 13:58:29 +0900486 ensureContains(t, optFlags, "--assets_dir "+buildDir+"/.intermediates/myapex/android_common_myapex_image/NOTICE")
Jiyong Park42cca6c2019-04-01 11:15:50 +0900487
Jiyong Park25fc6a92018-11-18 18:02:45 +0900488 copyCmds := apexRule.Args["copy_commands"]
489
490 // Ensure that main rule creates an output
491 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
492
493 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800494 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900495 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900496
497 // Ensure that apex variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800498 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900499 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900500
501 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800502 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
503 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900504 ensureContains(t, copyCmds, "image.apex/javalib/myjar.jar")
505 // .. but not for java libs
506 ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar")
Jiyong Park3ff16992019-12-27 14:11:47 +0900507 ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar")
Logan Chien3aeedc92018-12-26 15:32:21 +0800508
Colin Cross7113d202019-11-20 16:39:12 -0800509 // Ensure that the platform variant ends with _shared or _common
510 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
511 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Jiyong Park7f7766d2019-07-25 22:02:35 +0900512 ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common")
513 ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common")
Jiyong Park3ff16992019-12-27 14:11:47 +0900514 ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common")
515
516 // Ensure that dynamic dependency to java libs are not included
517 ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex")
Alex Light3d673592019-01-18 14:37:31 -0800518
519 // Ensure that all symlinks are present.
520 found_foo_link_64 := false
521 found_foo := false
522 for _, cmd := range strings.Split(copyCmds, " && ") {
Jiyong Park7cd10e32020-01-14 09:22:18 +0900523 if strings.HasPrefix(cmd, "ln -sfn foo64") {
Alex Light3d673592019-01-18 14:37:31 -0800524 if strings.HasSuffix(cmd, "bin/foo") {
525 found_foo = true
526 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
527 found_foo_link_64 = true
528 }
529 }
530 }
531 good := found_foo && found_foo_link_64
532 if !good {
533 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
534 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900535
Sundong Ahnabb64432019-10-22 13:58:29 +0900536 mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule")
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700537 noticeInputs := mergeNoticesRule.Inputs.Strings()
Jaewoong Jung14f5ff62019-06-18 13:09:13 -0700538 if len(noticeInputs) != 2 {
539 t.Errorf("number of input notice files: expected = 2, actual = %q", len(noticeInputs))
Jiyong Park52818fc2019-03-18 12:01:38 +0900540 }
541 ensureListContains(t, noticeInputs, "NOTICE")
542 ensureListContains(t, noticeInputs, "custom_notice")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900543
544 depsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("myapex-deps-info.txt").Args["content"], "\\n")
545 ensureListContains(t, depsInfo, "internal myjar")
546 ensureListContains(t, depsInfo, "internal mylib")
547 ensureListContains(t, depsInfo, "internal mylib2")
548 ensureListContains(t, depsInfo, "internal myotherjar")
Alex Light5098a612018-11-29 17:12:15 -0800549}
550
Jooyung Hanf21c7972019-12-16 22:32:06 +0900551func TestDefaults(t *testing.T) {
552 ctx, _ := testApex(t, `
553 apex_defaults {
554 name: "myapex-defaults",
555 key: "myapex.key",
556 prebuilts: ["myetc"],
557 native_shared_libs: ["mylib"],
558 java_libs: ["myjar"],
559 apps: ["AppFoo"],
560 }
561
562 prebuilt_etc {
563 name: "myetc",
564 src: "myprebuilt",
565 }
566
567 apex {
568 name: "myapex",
569 defaults: ["myapex-defaults"],
570 }
571
572 apex_key {
573 name: "myapex.key",
574 public_key: "testkey.avbpubkey",
575 private_key: "testkey.pem",
576 }
577
578 cc_library {
579 name: "mylib",
580 system_shared_libs: [],
581 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000582 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900583 }
584
585 java_library {
586 name: "myjar",
587 srcs: ["foo/bar/MyClass.java"],
588 sdk_version: "none",
589 system_modules: "none",
590 compile_dex: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000591 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900592 }
593
594 android_app {
595 name: "AppFoo",
596 srcs: ["foo/bar/MyClass.java"],
597 sdk_version: "none",
598 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000599 apex_available: [ "myapex" ],
Jooyung Hanf21c7972019-12-16 22:32:06 +0900600 }
601 `)
Jooyung Han5df3b112020-01-23 05:10:16 +0000602 ensureExactContents(t, ctx, "myapex", []string{
Jooyung Hanf21c7972019-12-16 22:32:06 +0900603 "etc/myetc",
604 "javalib/myjar.jar",
605 "lib64/mylib.so",
606 "app/AppFoo/AppFoo.apk",
607 })
608}
609
Jooyung Han01a3ee22019-11-02 02:52:25 +0900610func TestApexManifest(t *testing.T) {
611 ctx, _ := testApex(t, `
612 apex {
613 name: "myapex",
614 key: "myapex.key",
615 }
616
617 apex_key {
618 name: "myapex.key",
619 public_key: "testkey.avbpubkey",
620 private_key: "testkey.pem",
621 }
622 `)
623
624 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han214bf372019-11-12 13:03:50 +0900625 args := module.Rule("apexRule").Args
626 if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() {
627 t.Error("manifest should be apex_manifest.pb, but " + manifest)
628 }
Jooyung Han01a3ee22019-11-02 02:52:25 +0900629}
630
Alex Light5098a612018-11-29 17:12:15 -0800631func TestBasicZipApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700632 ctx, _ := testApex(t, `
Alex Light5098a612018-11-29 17:12:15 -0800633 apex {
634 name: "myapex",
635 key: "myapex.key",
636 payload_type: "zip",
637 native_shared_libs: ["mylib"],
638 }
639
640 apex_key {
641 name: "myapex.key",
642 public_key: "testkey.avbpubkey",
643 private_key: "testkey.pem",
644 }
645
646 cc_library {
647 name: "mylib",
648 srcs: ["mylib.cpp"],
649 shared_libs: ["mylib2"],
650 system_shared_libs: [],
651 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000652 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800653 }
654
655 cc_library {
656 name: "mylib2",
657 srcs: ["mylib.cpp"],
658 system_shared_libs: [],
659 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000660 apex_available: [ "myapex" ],
Alex Light5098a612018-11-29 17:12:15 -0800661 }
662 `)
663
Sundong Ahnabb64432019-10-22 13:58:29 +0900664 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule")
Alex Light5098a612018-11-29 17:12:15 -0800665 copyCmds := zipApexRule.Args["copy_commands"]
666
667 // Ensure that main rule creates an output
668 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
669
670 // Ensure that APEX variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -0800671 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800672
673 // Ensure that APEX variant is created for the indirect dep
Colin Cross7113d202019-11-20 16:39:12 -0800674 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800675
676 // Ensure that both direct and indirect deps are copied into apex
677 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
678 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900679}
680
681func TestApexWithStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700682 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900683 apex {
684 name: "myapex",
685 key: "myapex.key",
686 native_shared_libs: ["mylib", "mylib3"],
687 }
688
689 apex_key {
690 name: "myapex.key",
691 public_key: "testkey.avbpubkey",
692 private_key: "testkey.pem",
693 }
694
695 cc_library {
696 name: "mylib",
697 srcs: ["mylib.cpp"],
698 shared_libs: ["mylib2", "mylib3"],
699 system_shared_libs: [],
700 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000701 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900702 }
703
704 cc_library {
705 name: "mylib2",
706 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900707 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900708 system_shared_libs: [],
709 stl: "none",
710 stubs: {
711 versions: ["1", "2", "3"],
712 },
713 }
714
715 cc_library {
716 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900717 srcs: ["mylib.cpp"],
718 shared_libs: ["mylib4"],
719 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900720 stl: "none",
721 stubs: {
722 versions: ["10", "11", "12"],
723 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000724 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900725 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900726
727 cc_library {
728 name: "mylib4",
729 srcs: ["mylib.cpp"],
730 system_shared_libs: [],
731 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000732 apex_available: [ "myapex" ],
Jiyong Park28d395a2018-12-07 22:42:47 +0900733 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900734 `)
735
Sundong Ahnabb64432019-10-22 13:58:29 +0900736 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900737 copyCmds := apexRule.Args["copy_commands"]
738
739 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800740 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900741
742 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800743 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900744
745 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800746 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900747
Colin Cross7113d202019-11-20 16:39:12 -0800748 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900749
750 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900751 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900752 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Park3ff16992019-12-27 14:11:47 +0900753 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900754
755 // 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 -0800756 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900757 // .. and not linking to the stubs variant of mylib3
Colin Cross7113d202019-11-20 16:39:12 -0800758 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900759
760 // Ensure that stubs libs are built without -include flags
Colin Cross7113d202019-11-20 16:39:12 -0800761 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900762 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900763
764 // Ensure that genstub is invoked with --apex
Jiyong Park3ff16992019-12-27 14:11:47 +0900765 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
Jooyung Han671f1ce2019-12-17 12:47:13 +0900766
Jooyung Han5df3b112020-01-23 05:10:16 +0000767 ensureExactContents(t, ctx, "myapex", []string{
Jooyung Han671f1ce2019-12-17 12:47:13 +0900768 "lib64/mylib.so",
769 "lib64/mylib3.so",
770 "lib64/mylib4.so",
771 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900772}
773
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900774func TestApexWithExplicitStubsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700775 ctx, _ := testApex(t, `
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900776 apex {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900777 name: "myapex2",
778 key: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900779 native_shared_libs: ["mylib"],
780 }
781
782 apex_key {
Jiyong Park83dc74b2020-01-14 18:38:44 +0900783 name: "myapex2.key",
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900784 public_key: "testkey.avbpubkey",
785 private_key: "testkey.pem",
786 }
787
788 cc_library {
789 name: "mylib",
790 srcs: ["mylib.cpp"],
791 shared_libs: ["libfoo#10"],
792 system_shared_libs: [],
793 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000794 apex_available: [ "myapex2" ],
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900795 }
796
797 cc_library {
798 name: "libfoo",
799 srcs: ["mylib.cpp"],
800 shared_libs: ["libbar"],
801 system_shared_libs: [],
802 stl: "none",
803 stubs: {
804 versions: ["10", "20", "30"],
805 },
806 }
807
808 cc_library {
809 name: "libbar",
810 srcs: ["mylib.cpp"],
811 system_shared_libs: [],
812 stl: "none",
813 }
814
815 `)
816
Jiyong Park83dc74b2020-01-14 18:38:44 +0900817 apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900818 copyCmds := apexRule.Args["copy_commands"]
819
820 // Ensure that direct non-stubs dep is always included
821 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
822
823 // Ensure that indirect stubs dep is not included
824 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
825
826 // Ensure that dependency of stubs is not included
827 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
828
Jiyong Park83dc74b2020-01-14 18:38:44 +0900829 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex2").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900830
831 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900832 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900833 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Park3ff16992019-12-27 14:11:47 +0900834 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900835
Jiyong Park3ff16992019-12-27 14:11:47 +0900836 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900837
838 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
839 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
Jiyong Park83dc74b2020-01-14 18:38:44 +0900840
841 depsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("myapex2-deps-info.txt").Args["content"], "\\n")
842 ensureListContains(t, depsInfo, "internal mylib")
843 ensureListContains(t, depsInfo, "external libfoo")
844 ensureListNotContains(t, depsInfo, "internal libfoo")
845 ensureListNotContains(t, depsInfo, "external mylib")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900846}
847
Jooyung Hand3639552019-08-09 12:57:43 +0900848func TestApexWithRuntimeLibsDependency(t *testing.T) {
849 /*
850 myapex
851 |
852 v (runtime_libs)
853 mylib ------+------> libfoo [provides stub]
854 |
855 `------> libbar
856 */
857 ctx, _ := testApex(t, `
858 apex {
859 name: "myapex",
860 key: "myapex.key",
861 native_shared_libs: ["mylib"],
862 }
863
864 apex_key {
865 name: "myapex.key",
866 public_key: "testkey.avbpubkey",
867 private_key: "testkey.pem",
868 }
869
870 cc_library {
871 name: "mylib",
872 srcs: ["mylib.cpp"],
873 runtime_libs: ["libfoo", "libbar"],
874 system_shared_libs: [],
875 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000876 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900877 }
878
879 cc_library {
880 name: "libfoo",
881 srcs: ["mylib.cpp"],
882 system_shared_libs: [],
883 stl: "none",
884 stubs: {
885 versions: ["10", "20", "30"],
886 },
887 }
888
889 cc_library {
890 name: "libbar",
891 srcs: ["mylib.cpp"],
892 system_shared_libs: [],
893 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000894 apex_available: [ "myapex" ],
Jooyung Hand3639552019-08-09 12:57:43 +0900895 }
896
897 `)
898
Sundong Ahnabb64432019-10-22 13:58:29 +0900899 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Hand3639552019-08-09 12:57:43 +0900900 copyCmds := apexRule.Args["copy_commands"]
901
902 // Ensure that direct non-stubs dep is always included
903 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
904
905 // Ensure that indirect stubs dep is not included
906 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
907
908 // Ensure that runtime_libs dep in included
909 ensureContains(t, copyCmds, "image.apex/lib64/libbar.so")
910
Sundong Ahnabb64432019-10-22 13:58:29 +0900911 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900912 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
913 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so")
Jooyung Hand3639552019-08-09 12:57:43 +0900914
915}
916
Jooyung Han9c80bae2019-08-20 17:30:57 +0900917func TestApexDependencyToLLNDK(t *testing.T) {
918 ctx, _ := testApex(t, `
919 apex {
920 name: "myapex",
921 key: "myapex.key",
922 use_vendor: true,
923 native_shared_libs: ["mylib"],
924 }
925
926 apex_key {
927 name: "myapex.key",
928 public_key: "testkey.avbpubkey",
929 private_key: "testkey.pem",
930 }
931
932 cc_library {
933 name: "mylib",
934 srcs: ["mylib.cpp"],
935 vendor_available: true,
936 shared_libs: ["libbar"],
937 system_shared_libs: [],
938 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000939 apex_available: [ "myapex" ],
Jooyung Han9c80bae2019-08-20 17:30:57 +0900940 }
941
942 cc_library {
943 name: "libbar",
944 srcs: ["mylib.cpp"],
945 system_shared_libs: [],
946 stl: "none",
947 }
948
949 llndk_library {
950 name: "libbar",
951 symbol_file: "",
952 }
Jooyung Handc782442019-11-01 03:14:38 +0900953 `, func(fs map[string][]byte, config android.Config) {
954 setUseVendorWhitelistForTest(config, []string{"myapex"})
955 })
Jooyung Han9c80bae2019-08-20 17:30:57 +0900956
Sundong Ahnabb64432019-10-22 13:58:29 +0900957 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900958 copyCmds := apexRule.Args["copy_commands"]
959
960 // Ensure that LLNDK dep is not included
961 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
962
Sundong Ahnabb64432019-10-22 13:58:29 +0900963 apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900964 ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"]))
Jooyung Han9c80bae2019-08-20 17:30:57 +0900965
966 // Ensure that LLNDK dep is required
Jooyung Hand15aa1f2019-09-27 00:38:03 +0900967 ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so")
Jooyung Han9c80bae2019-08-20 17:30:57 +0900968
969}
970
Jiyong Park25fc6a92018-11-18 18:02:45 +0900971func TestApexWithSystemLibsStubs(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -0700972 ctx, _ := testApex(t, `
Jiyong Park25fc6a92018-11-18 18:02:45 +0900973 apex {
974 name: "myapex",
975 key: "myapex.key",
976 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
977 }
978
979 apex_key {
980 name: "myapex.key",
981 public_key: "testkey.avbpubkey",
982 private_key: "testkey.pem",
983 }
984
985 cc_library {
986 name: "mylib",
987 srcs: ["mylib.cpp"],
988 shared_libs: ["libdl#27"],
989 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000990 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900991 }
992
993 cc_library_shared {
994 name: "mylib_shared",
995 srcs: ["mylib.cpp"],
996 shared_libs: ["libdl#27"],
997 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000998 apex_available: [ "myapex" ],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900999 }
1000
1001 cc_library {
1002 name: "libc",
Yi Konge7fe9912019-06-02 00:53:50 -07001003 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001004 nocrt: true,
1005 system_shared_libs: [],
1006 stl: "none",
1007 stubs: {
1008 versions: ["27", "28", "29"],
1009 },
1010 }
1011
1012 cc_library {
1013 name: "libm",
Yi Konge7fe9912019-06-02 00:53:50 -07001014 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001015 nocrt: true,
1016 system_shared_libs: [],
1017 stl: "none",
1018 stubs: {
1019 versions: ["27", "28", "29"],
1020 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001021 apex_available: [
1022 "//apex_available:platform",
1023 "myapex"
1024 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001025 }
1026
1027 cc_library {
1028 name: "libdl",
Yi Konge7fe9912019-06-02 00:53:50 -07001029 no_libcrt: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001030 nocrt: true,
1031 system_shared_libs: [],
1032 stl: "none",
1033 stubs: {
1034 versions: ["27", "28", "29"],
1035 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001036 apex_available: [
1037 "//apex_available:platform",
1038 "myapex"
1039 ],
Jiyong Park25fc6a92018-11-18 18:02:45 +09001040 }
Jiyong Parkb0788572018-12-20 22:10:17 +09001041
1042 cc_library {
1043 name: "libBootstrap",
1044 srcs: ["mylib.cpp"],
1045 stl: "none",
1046 bootstrap: true,
1047 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001048 `)
1049
Sundong Ahnabb64432019-10-22 13:58:29 +09001050 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001051 copyCmds := apexRule.Args["copy_commands"]
1052
1053 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -08001054 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +09001055 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
1056 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001057
1058 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001059 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001060
Colin Cross7113d202019-11-20 16:39:12 -08001061 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_myapex").Rule("ld").Args["libFlags"]
1062 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
1063 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +09001064
1065 // For dependency to libc
1066 // Ensure that mylib is linking with the latest version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001067 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001068 // ... and not linking to the non-stub (impl) variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001069 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001070 // ... Cflags from stub is correctly exported to mylib
1071 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
1072 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
1073
1074 // For dependency to libm
1075 // Ensure that mylib is linking with the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001076 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001077 // ... and not linking to the stub variant
Jiyong Park3ff16992019-12-27 14:11:47 +09001078 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001079 // ... and is not compiling with the stub
1080 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
1081 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
1082
1083 // For dependency to libdl
1084 // Ensure that mylib is linking with the specified version of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001085 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001086 // ... and not linking to the other versions of stubs
Jiyong Park3ff16992019-12-27 14:11:47 +09001087 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so")
1088 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001089 // ... and not linking to the non-stub (impl) variant
Colin Cross7113d202019-11-20 16:39:12 -08001090 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001091 // ... Cflags from stub is correctly exported to mylib
1092 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
1093 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +09001094
1095 // Ensure that libBootstrap is depending on the platform variant of bionic libs
Colin Cross7113d202019-11-20 16:39:12 -08001096 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"]
1097 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so")
1098 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so")
1099 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +09001100}
Jiyong Park7c2ee712018-12-07 00:42:25 +09001101
1102func TestFilesInSubDir(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001103 ctx, _ := testApex(t, `
Jiyong Park7c2ee712018-12-07 00:42:25 +09001104 apex {
1105 name: "myapex",
1106 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001107 native_shared_libs: ["mylib"],
1108 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +09001109 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001110 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +09001111 }
1112
1113 apex_key {
1114 name: "myapex.key",
1115 public_key: "testkey.avbpubkey",
1116 private_key: "testkey.pem",
1117 }
1118
1119 prebuilt_etc {
1120 name: "myetc",
1121 src: "myprebuilt",
1122 sub_dir: "foo/bar",
1123 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001124
1125 cc_library {
1126 name: "mylib",
1127 srcs: ["mylib.cpp"],
1128 relative_install_path: "foo/bar",
1129 system_shared_libs: [],
1130 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001131 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001132 }
1133
1134 cc_binary {
1135 name: "mybin",
1136 srcs: ["mylib.cpp"],
1137 relative_install_path: "foo/bar",
1138 system_shared_libs: [],
1139 static_executable: true,
1140 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001141 apex_available: [ "myapex" ],
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001142 }
Jiyong Park7c2ee712018-12-07 00:42:25 +09001143 `)
1144
Sundong Ahnabb64432019-10-22 13:58:29 +09001145 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001146 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
1147
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001148 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +09001149 ensureListContains(t, dirs, "etc")
1150 ensureListContains(t, dirs, "etc/foo")
1151 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001152 ensureListContains(t, dirs, "lib64")
1153 ensureListContains(t, dirs, "lib64/foo")
1154 ensureListContains(t, dirs, "lib64/foo/bar")
1155 ensureListContains(t, dirs, "lib")
1156 ensureListContains(t, dirs, "lib/foo")
1157 ensureListContains(t, dirs, "lib/foo/bar")
1158
Jiyong Parkbd13e442019-03-15 18:10:35 +09001159 ensureListContains(t, dirs, "bin")
1160 ensureListContains(t, dirs, "bin/foo")
1161 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +09001162}
Jiyong Parkda6eb592018-12-19 17:12:36 +09001163
1164func TestUseVendor(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001165 ctx, _ := testApex(t, `
Jiyong Parkda6eb592018-12-19 17:12:36 +09001166 apex {
1167 name: "myapex",
1168 key: "myapex.key",
1169 native_shared_libs: ["mylib"],
1170 use_vendor: true,
1171 }
1172
1173 apex_key {
1174 name: "myapex.key",
1175 public_key: "testkey.avbpubkey",
1176 private_key: "testkey.pem",
1177 }
1178
1179 cc_library {
1180 name: "mylib",
1181 srcs: ["mylib.cpp"],
1182 shared_libs: ["mylib2"],
1183 system_shared_libs: [],
1184 vendor_available: true,
1185 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001186 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001187 }
1188
1189 cc_library {
1190 name: "mylib2",
1191 srcs: ["mylib.cpp"],
1192 system_shared_libs: [],
1193 vendor_available: true,
1194 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001195 apex_available: [ "myapex" ],
Jiyong Parkda6eb592018-12-19 17:12:36 +09001196 }
Jooyung Handc782442019-11-01 03:14:38 +09001197 `, func(fs map[string][]byte, config android.Config) {
1198 setUseVendorWhitelistForTest(config, []string{"myapex"})
1199 })
Jiyong Parkda6eb592018-12-19 17:12:36 +09001200
1201 inputsList := []string{}
Sundong Ahnabb64432019-10-22 13:58:29 +09001202 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() {
Jiyong Parkda6eb592018-12-19 17:12:36 +09001203 for _, implicit := range i.Implicits {
1204 inputsList = append(inputsList, implicit.String())
1205 }
1206 }
1207 inputsString := strings.Join(inputsList, " ")
1208
1209 // ensure that the apex includes vendor variants of the direct and indirect deps
Colin Crossfb0c16e2019-11-20 17:12:35 -08001210 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib.so")
1211 ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001212
1213 // ensure that the apex does not include core variants
Colin Cross7113d202019-11-20 16:39:12 -08001214 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib.so")
1215 ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_myapex/mylib2.so")
Jiyong Parkda6eb592018-12-19 17:12:36 +09001216}
Jiyong Park16e91a02018-12-20 18:18:08 +09001217
Jooyung Handc782442019-11-01 03:14:38 +09001218func TestUseVendorRestriction(t *testing.T) {
1219 testApexError(t, `module "myapex" .*: use_vendor: not allowed`, `
1220 apex {
1221 name: "myapex",
1222 key: "myapex.key",
1223 use_vendor: true,
1224 }
1225 apex_key {
1226 name: "myapex.key",
1227 public_key: "testkey.avbpubkey",
1228 private_key: "testkey.pem",
1229 }
1230 `, func(fs map[string][]byte, config android.Config) {
1231 setUseVendorWhitelistForTest(config, []string{""})
1232 })
1233 // no error with whitelist
1234 testApex(t, `
1235 apex {
1236 name: "myapex",
1237 key: "myapex.key",
1238 use_vendor: true,
1239 }
1240 apex_key {
1241 name: "myapex.key",
1242 public_key: "testkey.avbpubkey",
1243 private_key: "testkey.pem",
1244 }
1245 `, func(fs map[string][]byte, config android.Config) {
1246 setUseVendorWhitelistForTest(config, []string{"myapex"})
1247 })
1248}
1249
Jooyung Han5c998b92019-06-27 11:30:33 +09001250func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) {
1251 testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, `
1252 apex {
1253 name: "myapex",
1254 key: "myapex.key",
1255 native_shared_libs: ["mylib"],
1256 use_vendor: true,
1257 }
1258
1259 apex_key {
1260 name: "myapex.key",
1261 public_key: "testkey.avbpubkey",
1262 private_key: "testkey.pem",
1263 }
1264
1265 cc_library {
1266 name: "mylib",
1267 srcs: ["mylib.cpp"],
1268 system_shared_libs: [],
1269 stl: "none",
1270 }
1271 `)
1272}
1273
Jiyong Park16e91a02018-12-20 18:18:08 +09001274func TestStaticLinking(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001275 ctx, _ := testApex(t, `
Jiyong Park16e91a02018-12-20 18:18:08 +09001276 apex {
1277 name: "myapex",
1278 key: "myapex.key",
1279 native_shared_libs: ["mylib"],
1280 }
1281
1282 apex_key {
1283 name: "myapex.key",
1284 public_key: "testkey.avbpubkey",
1285 private_key: "testkey.pem",
1286 }
1287
1288 cc_library {
1289 name: "mylib",
1290 srcs: ["mylib.cpp"],
1291 system_shared_libs: [],
1292 stl: "none",
1293 stubs: {
1294 versions: ["1", "2", "3"],
1295 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001296 apex_available: [
1297 "//apex_available:platform",
1298 "myapex",
1299 ],
Jiyong Park16e91a02018-12-20 18:18:08 +09001300 }
1301
1302 cc_binary {
1303 name: "not_in_apex",
1304 srcs: ["mylib.cpp"],
1305 static_libs: ["mylib"],
1306 static_executable: true,
1307 system_shared_libs: [],
1308 stl: "none",
1309 }
Jiyong Park16e91a02018-12-20 18:18:08 +09001310 `)
1311
Colin Cross7113d202019-11-20 16:39:12 -08001312 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
Jiyong Park16e91a02018-12-20 18:18:08 +09001313
1314 // Ensure that not_in_apex is linking with the static variant of mylib
Colin Cross7113d202019-11-20 16:39:12 -08001315 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +09001316}
Jiyong Park9335a262018-12-24 11:31:58 +09001317
1318func TestKeys(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001319 ctx, _ := testApex(t, `
Jiyong Park9335a262018-12-24 11:31:58 +09001320 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001321 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +09001322 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001323 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +09001324 native_shared_libs: ["mylib"],
Jooyung Han54aca7b2019-11-20 02:26:02 +09001325 file_contexts: ":myapex-file_contexts",
Jiyong Park9335a262018-12-24 11:31:58 +09001326 }
1327
1328 cc_library {
1329 name: "mylib",
1330 srcs: ["mylib.cpp"],
1331 system_shared_libs: [],
1332 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001333 apex_available: [ "myapex_keytest" ],
Jiyong Park9335a262018-12-24 11:31:58 +09001334 }
1335
1336 apex_key {
1337 name: "myapex.key",
1338 public_key: "testkey.avbpubkey",
1339 private_key: "testkey.pem",
1340 }
1341
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001342 android_app_certificate {
1343 name: "myapex.certificate",
1344 certificate: "testkey",
1345 }
1346
1347 android_app_certificate {
1348 name: "myapex.certificate.override",
1349 certificate: "testkey.override",
1350 }
1351
Jiyong Park9335a262018-12-24 11:31:58 +09001352 `)
1353
1354 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001355 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +09001356
1357 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
1358 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
1359 "vendor/foo/devkeys/testkey.avbpubkey")
1360 }
1361 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
1362 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
1363 "vendor/foo/devkeys/testkey.pem")
1364 }
1365
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001366 // check the APK certs. It should be overridden to myapex.certificate.override
Sundong Ahnabb64432019-10-22 13:58:29 +09001367 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"]
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001368 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +09001369 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +09001370 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +09001371 }
1372}
Jiyong Park58e364a2019-01-19 19:24:06 +09001373
Jooyung Hanf121a652019-12-17 14:30:11 +09001374func TestCertificate(t *testing.T) {
1375 t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) {
1376 ctx, _ := testApex(t, `
1377 apex {
1378 name: "myapex",
1379 key: "myapex.key",
1380 }
1381 apex_key {
1382 name: "myapex.key",
1383 public_key: "testkey.avbpubkey",
1384 private_key: "testkey.pem",
1385 }`)
1386 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1387 expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8"
1388 if actual := rule.Args["certificates"]; actual != expected {
1389 t.Errorf("certificates should be %q, not %q", expected, actual)
1390 }
1391 })
1392 t.Run("override when unspecified", func(t *testing.T) {
1393 ctx, _ := testApex(t, `
1394 apex {
1395 name: "myapex_keytest",
1396 key: "myapex.key",
1397 file_contexts: ":myapex-file_contexts",
1398 }
1399 apex_key {
1400 name: "myapex.key",
1401 public_key: "testkey.avbpubkey",
1402 private_key: "testkey.pem",
1403 }
1404 android_app_certificate {
1405 name: "myapex.certificate.override",
1406 certificate: "testkey.override",
1407 }`)
1408 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1409 expected := "testkey.override.x509.pem testkey.override.pk8"
1410 if actual := rule.Args["certificates"]; actual != expected {
1411 t.Errorf("certificates should be %q, not %q", expected, actual)
1412 }
1413 })
1414 t.Run("if specified as :module, it respects the prop", func(t *testing.T) {
1415 ctx, _ := testApex(t, `
1416 apex {
1417 name: "myapex",
1418 key: "myapex.key",
1419 certificate: ":myapex.certificate",
1420 }
1421 apex_key {
1422 name: "myapex.key",
1423 public_key: "testkey.avbpubkey",
1424 private_key: "testkey.pem",
1425 }
1426 android_app_certificate {
1427 name: "myapex.certificate",
1428 certificate: "testkey",
1429 }`)
1430 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1431 expected := "testkey.x509.pem testkey.pk8"
1432 if actual := rule.Args["certificates"]; actual != expected {
1433 t.Errorf("certificates should be %q, not %q", expected, actual)
1434 }
1435 })
1436 t.Run("override when specifiec as <:module>", func(t *testing.T) {
1437 ctx, _ := testApex(t, `
1438 apex {
1439 name: "myapex_keytest",
1440 key: "myapex.key",
1441 file_contexts: ":myapex-file_contexts",
1442 certificate: ":myapex.certificate",
1443 }
1444 apex_key {
1445 name: "myapex.key",
1446 public_key: "testkey.avbpubkey",
1447 private_key: "testkey.pem",
1448 }
1449 android_app_certificate {
1450 name: "myapex.certificate.override",
1451 certificate: "testkey.override",
1452 }`)
1453 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1454 expected := "testkey.override.x509.pem testkey.override.pk8"
1455 if actual := rule.Args["certificates"]; actual != expected {
1456 t.Errorf("certificates should be %q, not %q", expected, actual)
1457 }
1458 })
1459 t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) {
1460 ctx, _ := testApex(t, `
1461 apex {
1462 name: "myapex",
1463 key: "myapex.key",
1464 certificate: "testkey",
1465 }
1466 apex_key {
1467 name: "myapex.key",
1468 public_key: "testkey.avbpubkey",
1469 private_key: "testkey.pem",
1470 }`)
1471 rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk")
1472 expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8"
1473 if actual := rule.Args["certificates"]; actual != expected {
1474 t.Errorf("certificates should be %q, not %q", expected, actual)
1475 }
1476 })
1477 t.Run("override when specified as <name>", func(t *testing.T) {
1478 ctx, _ := testApex(t, `
1479 apex {
1480 name: "myapex_keytest",
1481 key: "myapex.key",
1482 file_contexts: ":myapex-file_contexts",
1483 certificate: "testkey",
1484 }
1485 apex_key {
1486 name: "myapex.key",
1487 public_key: "testkey.avbpubkey",
1488 private_key: "testkey.pem",
1489 }
1490 android_app_certificate {
1491 name: "myapex.certificate.override",
1492 certificate: "testkey.override",
1493 }`)
1494 rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk")
1495 expected := "testkey.override.x509.pem testkey.override.pk8"
1496 if actual := rule.Args["certificates"]; actual != expected {
1497 t.Errorf("certificates should be %q, not %q", expected, actual)
1498 }
1499 })
1500}
1501
Jiyong Park58e364a2019-01-19 19:24:06 +09001502func TestMacro(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001503 ctx, _ := testApex(t, `
Jiyong Park58e364a2019-01-19 19:24:06 +09001504 apex {
1505 name: "myapex",
1506 key: "myapex.key",
1507 native_shared_libs: ["mylib"],
1508 }
1509
1510 apex {
1511 name: "otherapex",
1512 key: "myapex.key",
1513 native_shared_libs: ["mylib"],
1514 }
1515
1516 apex_key {
1517 name: "myapex.key",
1518 public_key: "testkey.avbpubkey",
1519 private_key: "testkey.pem",
1520 }
1521
1522 cc_library {
1523 name: "mylib",
1524 srcs: ["mylib.cpp"],
1525 system_shared_libs: [],
1526 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001527 // TODO: remove //apex_available:platform
1528 apex_available: [
1529 "//apex_available:platform",
1530 "myapex",
1531 "otherapex",
1532 ],
Jiyong Park58e364a2019-01-19 19:24:06 +09001533 }
1534 `)
1535
Jooyung Han6b8459b2019-10-30 08:29:25 +09001536 // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001537 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001538 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001539 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1540 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001541
Jooyung Han6b8459b2019-10-30 08:29:25 +09001542 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001543 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001544 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001545 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1546 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001547
Jooyung Han6b8459b2019-10-30 08:29:25 +09001548 // APEX variant has __ANDROID_APEX(_NAME)__ defined
Colin Cross7113d202019-11-20 16:39:12 -08001549 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"]
Jooyung Han6b8459b2019-10-30 08:29:25 +09001550 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
Jooyung Han77988572019-10-18 16:26:16 +09001551 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
1552 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
Jiyong Park58e364a2019-01-19 19:24:06 +09001553}
Jiyong Park7e636d02019-01-28 16:16:54 +09001554
1555func TestHeaderLibsDependency(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07001556 ctx, _ := testApex(t, `
Jiyong Park7e636d02019-01-28 16:16:54 +09001557 apex {
1558 name: "myapex",
1559 key: "myapex.key",
1560 native_shared_libs: ["mylib"],
1561 }
1562
1563 apex_key {
1564 name: "myapex.key",
1565 public_key: "testkey.avbpubkey",
1566 private_key: "testkey.pem",
1567 }
1568
1569 cc_library_headers {
1570 name: "mylib_headers",
1571 export_include_dirs: ["my_include"],
1572 system_shared_libs: [],
1573 stl: "none",
1574 }
1575
1576 cc_library {
1577 name: "mylib",
1578 srcs: ["mylib.cpp"],
1579 system_shared_libs: [],
1580 stl: "none",
1581 header_libs: ["mylib_headers"],
1582 export_header_lib_headers: ["mylib_headers"],
1583 stubs: {
1584 versions: ["1", "2", "3"],
1585 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001586 apex_available: [ "myapex" ],
Jiyong Park7e636d02019-01-28 16:16:54 +09001587 }
1588
1589 cc_library {
1590 name: "otherlib",
1591 srcs: ["mylib.cpp"],
1592 system_shared_libs: [],
1593 stl: "none",
1594 shared_libs: ["mylib"],
1595 }
1596 `)
1597
Colin Cross7113d202019-11-20 16:39:12 -08001598 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
Jiyong Park7e636d02019-01-28 16:16:54 +09001599
1600 // Ensure that the include path of the header lib is exported to 'otherlib'
1601 ensureContains(t, cFlags, "-Imy_include")
1602}
Alex Light9670d332019-01-29 18:07:33 -08001603
Jiyong Park7cd10e32020-01-14 09:22:18 +09001604type fileInApex struct {
1605 path string // path in apex
1606 isLink bool
1607}
1608
Jooyung Han5df3b112020-01-23 05:10:16 +00001609func getFiles(t *testing.T, ctx *android.TestContext, moduleName string) []fileInApex {
Jooyung Han31c470b2019-10-18 16:26:59 +09001610 t.Helper()
Jooyung Han5df3b112020-01-23 05:10:16 +00001611 apexRule := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Rule("apexRule")
Jooyung Han31c470b2019-10-18 16:26:59 +09001612 copyCmds := apexRule.Args["copy_commands"]
1613 imageApexDir := "/image.apex/"
Jiyong Park7cd10e32020-01-14 09:22:18 +09001614 var ret []fileInApex
Jooyung Han31c470b2019-10-18 16:26:59 +09001615 for _, cmd := range strings.Split(copyCmds, "&&") {
1616 cmd = strings.TrimSpace(cmd)
1617 if cmd == "" {
1618 continue
1619 }
1620 terms := strings.Split(cmd, " ")
Jooyung Han5df3b112020-01-23 05:10:16 +00001621 var dst string
Jiyong Park7cd10e32020-01-14 09:22:18 +09001622 var isLink bool
Jooyung Han31c470b2019-10-18 16:26:59 +09001623 switch terms[0] {
1624 case "mkdir":
1625 case "cp":
Jiyong Park7cd10e32020-01-14 09:22:18 +09001626 if len(terms) != 3 && len(terms) != 4 {
Jooyung Han31c470b2019-10-18 16:26:59 +09001627 t.Fatal("copyCmds contains invalid cp command", cmd)
1628 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001629 dst = terms[len(terms)-1]
1630 isLink = false
1631 case "ln":
1632 if len(terms) != 3 && len(terms) != 4 {
1633 // ln LINK TARGET or ln -s LINK TARGET
1634 t.Fatal("copyCmds contains invalid ln command", cmd)
1635 }
1636 dst = terms[len(terms)-1]
1637 isLink = true
1638 default:
1639 t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd)
1640 }
1641 if dst != "" {
Jooyung Han31c470b2019-10-18 16:26:59 +09001642 index := strings.Index(dst, imageApexDir)
1643 if index == -1 {
1644 t.Fatal("copyCmds should copy a file to image.apex/", cmd)
1645 }
1646 dstFile := dst[index+len(imageApexDir):]
Jooyung Han5df3b112020-01-23 05:10:16 +00001647 ret = append(ret, fileInApex{path: dstFile, isLink: isLink})
Jooyung Han31c470b2019-10-18 16:26:59 +09001648 }
1649 }
Jiyong Park7cd10e32020-01-14 09:22:18 +09001650 return ret
1651}
1652
Jooyung Han5df3b112020-01-23 05:10:16 +00001653func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName string, files []string) {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001654 var failed bool
1655 var surplus []string
1656 filesMatched := make(map[string]bool)
Jooyung Han5df3b112020-01-23 05:10:16 +00001657 for _, file := range getFiles(t, ctx, moduleName) {
Jiyong Park7cd10e32020-01-14 09:22:18 +09001658 for _, expected := range files {
1659 if matched, _ := path.Match(expected, file.path); matched {
1660 filesMatched[expected] = true
1661 return
1662 }
1663 }
1664 surplus = append(surplus, file.path)
1665 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001666
Jooyung Han31c470b2019-10-18 16:26:59 +09001667 if len(surplus) > 0 {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001668 sort.Strings(surplus)
Jooyung Han31c470b2019-10-18 16:26:59 +09001669 t.Log("surplus files", surplus)
1670 failed = true
1671 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001672
1673 if len(files) > len(filesMatched) {
1674 var missing []string
1675 for _, expected := range files {
1676 if !filesMatched[expected] {
1677 missing = append(missing, expected)
1678 }
1679 }
1680 sort.Strings(missing)
Jooyung Han31c470b2019-10-18 16:26:59 +09001681 t.Log("missing files", missing)
1682 failed = true
1683 }
1684 if failed {
1685 t.Fail()
1686 }
1687}
1688
Jooyung Han344d5432019-08-23 11:17:39 +09001689func TestVndkApexCurrent(t *testing.T) {
1690 ctx, _ := testApex(t, `
1691 apex_vndk {
1692 name: "myapex",
1693 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001694 }
1695
1696 apex_key {
1697 name: "myapex.key",
1698 public_key: "testkey.avbpubkey",
1699 private_key: "testkey.pem",
1700 }
1701
1702 cc_library {
1703 name: "libvndk",
1704 srcs: ["mylib.cpp"],
1705 vendor_available: true,
1706 vndk: {
1707 enabled: true,
1708 },
1709 system_shared_libs: [],
1710 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001711 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001712 }
1713
1714 cc_library {
1715 name: "libvndksp",
1716 srcs: ["mylib.cpp"],
1717 vendor_available: true,
1718 vndk: {
1719 enabled: true,
1720 support_system_process: true,
1721 },
1722 system_shared_libs: [],
1723 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001724 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001725 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001726 `+vndkLibrariesTxtFiles("current"))
Jooyung Han344d5432019-08-23 11:17:39 +09001727
Jooyung Han5df3b112020-01-23 05:10:16 +00001728 ensureExactContents(t, ctx, "myapex", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001729 "lib/libvndk.so",
1730 "lib/libvndksp.so",
1731 "lib64/libvndk.so",
1732 "lib64/libvndksp.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001733 "etc/llndk.libraries.VER.txt",
1734 "etc/vndkcore.libraries.VER.txt",
1735 "etc/vndksp.libraries.VER.txt",
1736 "etc/vndkprivate.libraries.VER.txt",
Jooyung Han31c470b2019-10-18 16:26:59 +09001737 })
Jooyung Han344d5432019-08-23 11:17:39 +09001738}
1739
1740func TestVndkApexWithPrebuilt(t *testing.T) {
1741 ctx, _ := testApex(t, `
1742 apex_vndk {
1743 name: "myapex",
1744 key: "myapex.key",
Jooyung Han344d5432019-08-23 11:17:39 +09001745 }
1746
1747 apex_key {
1748 name: "myapex.key",
1749 public_key: "testkey.avbpubkey",
1750 private_key: "testkey.pem",
1751 }
1752
1753 cc_prebuilt_library_shared {
Jooyung Han31c470b2019-10-18 16:26:59 +09001754 name: "libvndk",
1755 srcs: ["libvndk.so"],
Jooyung Han344d5432019-08-23 11:17:39 +09001756 vendor_available: true,
1757 vndk: {
1758 enabled: true,
1759 },
1760 system_shared_libs: [],
1761 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001762 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001763 }
Jooyung Han31c470b2019-10-18 16:26:59 +09001764
1765 cc_prebuilt_library_shared {
1766 name: "libvndk.arm",
1767 srcs: ["libvndk.arm.so"],
1768 vendor_available: true,
1769 vndk: {
1770 enabled: true,
1771 },
1772 enabled: false,
1773 arch: {
1774 arm: {
1775 enabled: true,
1776 },
1777 },
1778 system_shared_libs: [],
1779 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001780 apex_available: [ "myapex" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09001781 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001782 `+vndkLibrariesTxtFiles("current"),
1783 withFiles(map[string][]byte{
1784 "libvndk.so": nil,
1785 "libvndk.arm.so": nil,
1786 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001787
Jooyung Han5df3b112020-01-23 05:10:16 +00001788 ensureExactContents(t, ctx, "myapex", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001789 "lib/libvndk.so",
1790 "lib/libvndk.arm.so",
1791 "lib64/libvndk.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001792 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09001793 })
Jooyung Han344d5432019-08-23 11:17:39 +09001794}
1795
Jooyung Han39edb6c2019-11-06 16:53:07 +09001796func vndkLibrariesTxtFiles(vers ...string) (result string) {
1797 for _, v := range vers {
1798 if v == "current" {
Kiyoung Kime1aa8ea2019-12-30 11:12:55 +09001799 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
Jooyung Han39edb6c2019-11-06 16:53:07 +09001800 result += `
1801 vndk_libraries_txt {
1802 name: "` + txt + `.libraries.txt",
1803 }
1804 `
1805 }
1806 } else {
1807 for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate"} {
1808 result += `
1809 prebuilt_etc {
1810 name: "` + txt + `.libraries.` + v + `.txt",
1811 src: "dummy.txt",
1812 }
1813 `
1814 }
1815 }
1816 }
1817 return
1818}
1819
Jooyung Han344d5432019-08-23 11:17:39 +09001820func TestVndkApexVersion(t *testing.T) {
1821 ctx, _ := testApex(t, `
1822 apex_vndk {
1823 name: "myapex_v27",
1824 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001825 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001826 vndk_version: "27",
1827 }
1828
1829 apex_key {
1830 name: "myapex.key",
1831 public_key: "testkey.avbpubkey",
1832 private_key: "testkey.pem",
1833 }
1834
Jooyung Han31c470b2019-10-18 16:26:59 +09001835 vndk_prebuilt_shared {
1836 name: "libvndk27",
1837 version: "27",
Jooyung Han344d5432019-08-23 11:17:39 +09001838 vendor_available: true,
1839 vndk: {
1840 enabled: true,
1841 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001842 target_arch: "arm64",
1843 arch: {
1844 arm: {
1845 srcs: ["libvndk27_arm.so"],
1846 },
1847 arm64: {
1848 srcs: ["libvndk27_arm64.so"],
1849 },
1850 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001851 apex_available: [ "myapex_v27" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001852 }
1853
1854 vndk_prebuilt_shared {
1855 name: "libvndk27",
1856 version: "27",
1857 vendor_available: true,
1858 vndk: {
1859 enabled: true,
1860 },
Jooyung Han31c470b2019-10-18 16:26:59 +09001861 target_arch: "x86_64",
1862 arch: {
1863 x86: {
1864 srcs: ["libvndk27_x86.so"],
1865 },
1866 x86_64: {
1867 srcs: ["libvndk27_x86_64.so"],
1868 },
1869 },
Jooyung Han39edb6c2019-11-06 16:53:07 +09001870 }
1871 `+vndkLibrariesTxtFiles("27"),
1872 withFiles(map[string][]byte{
1873 "libvndk27_arm.so": nil,
1874 "libvndk27_arm64.so": nil,
1875 "libvndk27_x86.so": nil,
1876 "libvndk27_x86_64.so": nil,
1877 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001878
Jooyung Han5df3b112020-01-23 05:10:16 +00001879 ensureExactContents(t, ctx, "myapex_v27", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09001880 "lib/libvndk27_arm.so",
1881 "lib64/libvndk27_arm64.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001882 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09001883 })
Jooyung Han344d5432019-08-23 11:17:39 +09001884}
1885
1886func TestVndkApexErrorWithDuplicateVersion(t *testing.T) {
1887 testApexError(t, `module "myapex_v27.*" .*: vndk_version: 27 is already defined in "myapex_v27.*"`, `
1888 apex_vndk {
1889 name: "myapex_v27",
1890 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001891 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001892 vndk_version: "27",
1893 }
1894 apex_vndk {
1895 name: "myapex_v27_other",
1896 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001897 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001898 vndk_version: "27",
1899 }
1900
1901 apex_key {
1902 name: "myapex.key",
1903 public_key: "testkey.avbpubkey",
1904 private_key: "testkey.pem",
1905 }
1906
1907 cc_library {
1908 name: "libvndk",
1909 srcs: ["mylib.cpp"],
1910 vendor_available: true,
1911 vndk: {
1912 enabled: true,
1913 },
1914 system_shared_libs: [],
1915 stl: "none",
1916 }
1917
1918 vndk_prebuilt_shared {
1919 name: "libvndk",
1920 version: "27",
1921 vendor_available: true,
1922 vndk: {
1923 enabled: true,
1924 },
1925 srcs: ["libvndk.so"],
1926 }
1927 `, withFiles(map[string][]byte{
1928 "libvndk.so": nil,
1929 }))
1930}
1931
Jooyung Han90eee022019-10-01 20:02:42 +09001932func TestVndkApexNameRule(t *testing.T) {
1933 ctx, _ := testApex(t, `
1934 apex_vndk {
1935 name: "myapex",
1936 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001937 file_contexts: ":myapex-file_contexts",
Jooyung Han90eee022019-10-01 20:02:42 +09001938 }
1939 apex_vndk {
1940 name: "myapex_v28",
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 vndk_version: "28",
1944 }
1945 apex_key {
1946 name: "myapex.key",
1947 public_key: "testkey.avbpubkey",
1948 private_key: "testkey.pem",
Jooyung Han39edb6c2019-11-06 16:53:07 +09001949 }`+vndkLibrariesTxtFiles("28", "current"))
Jooyung Han90eee022019-10-01 20:02:42 +09001950
1951 assertApexName := func(expected, moduleName string) {
Jooyung Han5df3b112020-01-23 05:10:16 +00001952 bundle := ctx.ModuleForTests(moduleName, "android_common_"+moduleName+"_image").Module().(*apexBundle)
Jooyung Han90eee022019-10-01 20:02:42 +09001953 actual := proptools.String(bundle.properties.Apex_name)
1954 if !reflect.DeepEqual(actual, expected) {
1955 t.Errorf("Got '%v', expected '%v'", actual, expected)
1956 }
1957 }
1958
1959 assertApexName("com.android.vndk.vVER", "myapex")
1960 assertApexName("com.android.vndk.v28", "myapex_v28")
1961}
1962
Jooyung Han344d5432019-08-23 11:17:39 +09001963func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) {
1964 ctx, _ := testApex(t, `
1965 apex_vndk {
1966 name: "myapex",
1967 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09001968 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09001969 }
1970
1971 apex_key {
1972 name: "myapex.key",
1973 public_key: "testkey.avbpubkey",
1974 private_key: "testkey.pem",
1975 }
1976
1977 cc_library {
1978 name: "libvndk",
1979 srcs: ["mylib.cpp"],
1980 vendor_available: true,
1981 native_bridge_supported: true,
1982 host_supported: true,
1983 vndk: {
1984 enabled: true,
1985 },
1986 system_shared_libs: [],
1987 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00001988 apex_available: [ "myapex" ],
Jooyung Han344d5432019-08-23 11:17:39 +09001989 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09001990 `+vndkLibrariesTxtFiles("current"),
1991 withTargets(map[android.OsType][]android.Target{
1992 android.Android: []android.Target{
1993 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1994 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
1995 {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"},
1996 {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"},
1997 },
1998 }))
Jooyung Han344d5432019-08-23 11:17:39 +09001999
Jooyung Han5df3b112020-01-23 05:10:16 +00002000 ensureExactContents(t, ctx, "myapex", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002001 "lib/libvndk.so",
2002 "lib64/libvndk.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002003 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002004 })
Jooyung Han344d5432019-08-23 11:17:39 +09002005}
2006
2007func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) {
2008 testApexError(t, `module "myapex" .*: native_bridge_supported: .* doesn't support native bridge binary`, `
2009 apex_vndk {
2010 name: "myapex",
2011 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002012 file_contexts: ":myapex-file_contexts",
Jooyung Han344d5432019-08-23 11:17:39 +09002013 native_bridge_supported: true,
2014 }
2015
2016 apex_key {
2017 name: "myapex.key",
2018 public_key: "testkey.avbpubkey",
2019 private_key: "testkey.pem",
2020 }
2021
2022 cc_library {
2023 name: "libvndk",
2024 srcs: ["mylib.cpp"],
2025 vendor_available: true,
2026 native_bridge_supported: true,
2027 host_supported: true,
2028 vndk: {
2029 enabled: true,
2030 },
2031 system_shared_libs: [],
2032 stl: "none",
2033 }
2034 `)
2035}
2036
Jooyung Han31c470b2019-10-18 16:26:59 +09002037func TestVndkApexWithBinder32(t *testing.T) {
Jooyung Han39edb6c2019-11-06 16:53:07 +09002038 ctx, _ := testApex(t, `
Jooyung Han31c470b2019-10-18 16:26:59 +09002039 apex_vndk {
2040 name: "myapex_v27",
2041 key: "myapex.key",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002042 file_contexts: ":myapex-file_contexts",
Jooyung Han31c470b2019-10-18 16:26:59 +09002043 vndk_version: "27",
2044 }
2045
2046 apex_key {
2047 name: "myapex.key",
2048 public_key: "testkey.avbpubkey",
2049 private_key: "testkey.pem",
2050 }
2051
2052 vndk_prebuilt_shared {
2053 name: "libvndk27",
2054 version: "27",
2055 target_arch: "arm",
2056 vendor_available: true,
2057 vndk: {
2058 enabled: true,
2059 },
2060 arch: {
2061 arm: {
2062 srcs: ["libvndk27.so"],
2063 }
2064 },
2065 }
2066
2067 vndk_prebuilt_shared {
2068 name: "libvndk27",
2069 version: "27",
2070 target_arch: "arm",
2071 binder32bit: true,
2072 vendor_available: true,
2073 vndk: {
2074 enabled: true,
2075 },
2076 arch: {
2077 arm: {
2078 srcs: ["libvndk27binder32.so"],
2079 }
2080 },
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002081 apex_available: [ "myapex_v27" ],
Jooyung Han31c470b2019-10-18 16:26:59 +09002082 }
Jooyung Han39edb6c2019-11-06 16:53:07 +09002083 `+vndkLibrariesTxtFiles("27"),
Jooyung Han31c470b2019-10-18 16:26:59 +09002084 withFiles(map[string][]byte{
2085 "libvndk27.so": nil,
2086 "libvndk27binder32.so": nil,
2087 }),
2088 withBinder32bit,
2089 withTargets(map[android.OsType][]android.Target{
2090 android.Android: []android.Target{
2091 {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""},
2092 },
2093 }),
2094 )
2095
Jooyung Han5df3b112020-01-23 05:10:16 +00002096 ensureExactContents(t, ctx, "myapex_v27", []string{
Jooyung Han31c470b2019-10-18 16:26:59 +09002097 "lib/libvndk27binder32.so",
Jooyung Han39edb6c2019-11-06 16:53:07 +09002098 "etc/*",
Jooyung Han31c470b2019-10-18 16:26:59 +09002099 })
2100}
2101
Jooyung Hane1633032019-08-01 17:41:43 +09002102func TestDependenciesInApexManifest(t *testing.T) {
2103 ctx, _ := testApex(t, `
2104 apex {
2105 name: "myapex_nodep",
2106 key: "myapex.key",
2107 native_shared_libs: ["lib_nodep"],
2108 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002109 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002110 }
2111
2112 apex {
2113 name: "myapex_dep",
2114 key: "myapex.key",
2115 native_shared_libs: ["lib_dep"],
2116 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002117 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002118 }
2119
2120 apex {
2121 name: "myapex_provider",
2122 key: "myapex.key",
2123 native_shared_libs: ["libfoo"],
2124 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002125 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002126 }
2127
2128 apex {
2129 name: "myapex_selfcontained",
2130 key: "myapex.key",
2131 native_shared_libs: ["lib_dep", "libfoo"],
2132 compile_multilib: "both",
Jooyung Han54aca7b2019-11-20 02:26:02 +09002133 file_contexts: ":myapex-file_contexts",
Jooyung Hane1633032019-08-01 17:41:43 +09002134 }
2135
2136 apex_key {
2137 name: "myapex.key",
2138 public_key: "testkey.avbpubkey",
2139 private_key: "testkey.pem",
2140 }
2141
2142 cc_library {
2143 name: "lib_nodep",
2144 srcs: ["mylib.cpp"],
2145 system_shared_libs: [],
2146 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002147 apex_available: [ "myapex_nodep" ],
Jooyung Hane1633032019-08-01 17:41:43 +09002148 }
2149
2150 cc_library {
2151 name: "lib_dep",
2152 srcs: ["mylib.cpp"],
2153 shared_libs: ["libfoo"],
2154 system_shared_libs: [],
2155 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002156 apex_available: [
2157 "myapex_dep",
2158 "myapex_provider",
2159 "myapex_selfcontained",
2160 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002161 }
2162
2163 cc_library {
2164 name: "libfoo",
2165 srcs: ["mytest.cpp"],
2166 stubs: {
2167 versions: ["1"],
2168 },
2169 system_shared_libs: [],
2170 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002171 apex_available: [
2172 "myapex_provider",
2173 "myapex_selfcontained",
2174 ],
Jooyung Hane1633032019-08-01 17:41:43 +09002175 }
2176 `)
2177
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002178 var apexManifestRule android.TestingBuildParams
Jooyung Hane1633032019-08-01 17:41:43 +09002179 var provideNativeLibs, requireNativeLibs []string
2180
Sundong Ahnabb64432019-10-22 13:58:29 +09002181 apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002182 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2183 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002184 ensureListEmpty(t, provideNativeLibs)
2185 ensureListEmpty(t, requireNativeLibs)
2186
Sundong Ahnabb64432019-10-22 13:58:29 +09002187 apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002188 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2189 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002190 ensureListEmpty(t, provideNativeLibs)
2191 ensureListContains(t, requireNativeLibs, "libfoo.so")
2192
Sundong Ahnabb64432019-10-22 13:58:29 +09002193 apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002194 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2195 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002196 ensureListContains(t, provideNativeLibs, "libfoo.so")
2197 ensureListEmpty(t, requireNativeLibs)
2198
Sundong Ahnabb64432019-10-22 13:58:29 +09002199 apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002200 provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"])
2201 requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"])
Jooyung Hane1633032019-08-01 17:41:43 +09002202 ensureListContains(t, provideNativeLibs, "libfoo.so")
2203 ensureListEmpty(t, requireNativeLibs)
2204}
2205
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002206func TestApexName(t *testing.T) {
2207 ctx, _ := testApex(t, `
2208 apex {
2209 name: "myapex",
2210 key: "myapex.key",
2211 apex_name: "com.android.myapex",
2212 }
2213
2214 apex_key {
2215 name: "myapex.key",
2216 public_key: "testkey.avbpubkey",
2217 private_key: "testkey.pem",
2218 }
2219 `)
2220
Sundong Ahnabb64432019-10-22 13:58:29 +09002221 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Hand15aa1f2019-09-27 00:38:03 +09002222 apexManifestRule := module.Rule("apexManifestRule")
2223 ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex")
2224 apexRule := module.Rule("apexRule")
2225 ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname")
2226}
2227
Alex Light0851b882019-02-07 13:20:53 -08002228func TestNonTestApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002229 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002230 apex {
2231 name: "myapex",
2232 key: "myapex.key",
2233 native_shared_libs: ["mylib_common"],
2234 }
2235
2236 apex_key {
2237 name: "myapex.key",
2238 public_key: "testkey.avbpubkey",
2239 private_key: "testkey.pem",
2240 }
2241
2242 cc_library {
2243 name: "mylib_common",
2244 srcs: ["mylib.cpp"],
2245 system_shared_libs: [],
2246 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002247 apex_available: [
2248 "//apex_available:platform",
2249 "myapex",
2250 ],
Alex Light0851b882019-02-07 13:20:53 -08002251 }
2252 `)
2253
Sundong Ahnabb64432019-10-22 13:58:29 +09002254 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002255 apexRule := module.Rule("apexRule")
2256 copyCmds := apexRule.Args["copy_commands"]
2257
2258 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
2259 t.Log("Apex was a test apex!")
2260 t.Fail()
2261 }
2262 // Ensure that main rule creates an output
2263 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2264
2265 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002266 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002267
2268 // Ensure that both direct and indirect deps are copied into apex
2269 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2270
Colin Cross7113d202019-11-20 16:39:12 -08002271 // Ensure that the platform variant ends with _shared
2272 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002273
2274 if !android.InAnyApex("mylib_common") {
2275 t.Log("Found mylib_common not in any apex!")
2276 t.Fail()
2277 }
2278}
2279
2280func TestTestApex(t *testing.T) {
2281 if android.InAnyApex("mylib_common_test") {
2282 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!")
2283 }
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002284 ctx, _ := testApex(t, `
Alex Light0851b882019-02-07 13:20:53 -08002285 apex_test {
2286 name: "myapex",
2287 key: "myapex.key",
2288 native_shared_libs: ["mylib_common_test"],
2289 }
2290
2291 apex_key {
2292 name: "myapex.key",
2293 public_key: "testkey.avbpubkey",
2294 private_key: "testkey.pem",
2295 }
2296
2297 cc_library {
2298 name: "mylib_common_test",
2299 srcs: ["mylib.cpp"],
2300 system_shared_libs: [],
2301 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002302 // TODO: remove //apex_available:platform
2303 apex_available: [
2304 "//apex_available:platform",
2305 "myapex",
2306 ],
Alex Light0851b882019-02-07 13:20:53 -08002307 }
2308 `)
2309
Sundong Ahnabb64432019-10-22 13:58:29 +09002310 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Alex Light0851b882019-02-07 13:20:53 -08002311 apexRule := module.Rule("apexRule")
2312 copyCmds := apexRule.Args["copy_commands"]
2313
2314 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
2315 t.Log("Apex was not a test apex!")
2316 t.Fail()
2317 }
2318 // Ensure that main rule creates an output
2319 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2320
2321 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002322 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_myapex")
Alex Light0851b882019-02-07 13:20:53 -08002323
2324 // Ensure that both direct and indirect deps are copied into apex
2325 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
2326
Colin Cross7113d202019-11-20 16:39:12 -08002327 // Ensure that the platform variant ends with _shared
2328 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared")
Alex Light0851b882019-02-07 13:20:53 -08002329
2330 if android.InAnyApex("mylib_common_test") {
2331 t.Log("Found mylib_common_test in some apex!")
2332 t.Fail()
2333 }
2334}
2335
Alex Light9670d332019-01-29 18:07:33 -08002336func TestApexWithTarget(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002337 ctx, _ := testApex(t, `
Alex Light9670d332019-01-29 18:07:33 -08002338 apex {
2339 name: "myapex",
2340 key: "myapex.key",
2341 multilib: {
2342 first: {
2343 native_shared_libs: ["mylib_common"],
2344 }
2345 },
2346 target: {
2347 android: {
2348 multilib: {
2349 first: {
2350 native_shared_libs: ["mylib"],
2351 }
2352 }
2353 },
2354 host: {
2355 multilib: {
2356 first: {
2357 native_shared_libs: ["mylib2"],
2358 }
2359 }
2360 }
2361 }
2362 }
2363
2364 apex_key {
2365 name: "myapex.key",
2366 public_key: "testkey.avbpubkey",
2367 private_key: "testkey.pem",
2368 }
2369
2370 cc_library {
2371 name: "mylib",
2372 srcs: ["mylib.cpp"],
2373 system_shared_libs: [],
2374 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002375 // TODO: remove //apex_available:platform
2376 apex_available: [
2377 "//apex_available:platform",
2378 "myapex",
2379 ],
Alex Light9670d332019-01-29 18:07:33 -08002380 }
2381
2382 cc_library {
2383 name: "mylib_common",
2384 srcs: ["mylib.cpp"],
2385 system_shared_libs: [],
2386 stl: "none",
2387 compile_multilib: "first",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002388 // TODO: remove //apex_available:platform
2389 apex_available: [
2390 "//apex_available:platform",
2391 "myapex",
2392 ],
Alex Light9670d332019-01-29 18:07:33 -08002393 }
2394
2395 cc_library {
2396 name: "mylib2",
2397 srcs: ["mylib.cpp"],
2398 system_shared_libs: [],
2399 stl: "none",
2400 compile_multilib: "first",
2401 }
2402 `)
2403
Sundong Ahnabb64432019-10-22 13:58:29 +09002404 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Alex Light9670d332019-01-29 18:07:33 -08002405 copyCmds := apexRule.Args["copy_commands"]
2406
2407 // Ensure that main rule creates an output
2408 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
2409
2410 // Ensure that apex variant is created for the direct dep
Colin Cross7113d202019-11-20 16:39:12 -08002411 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2412 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_myapex")
2413 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_myapex")
Alex Light9670d332019-01-29 18:07:33 -08002414
2415 // Ensure that both direct and indirect deps are copied into apex
2416 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
2417 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
2418 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
2419
Colin Cross7113d202019-11-20 16:39:12 -08002420 // Ensure that the platform variant ends with _shared
2421 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared")
2422 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared")
2423 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared")
Alex Light9670d332019-01-29 18:07:33 -08002424}
Jiyong Park04480cf2019-02-06 00:16:29 +09002425
2426func TestApexWithShBinary(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002427 ctx, _ := testApex(t, `
Jiyong Park04480cf2019-02-06 00:16:29 +09002428 apex {
2429 name: "myapex",
2430 key: "myapex.key",
2431 binaries: ["myscript"],
2432 }
2433
2434 apex_key {
2435 name: "myapex.key",
2436 public_key: "testkey.avbpubkey",
2437 private_key: "testkey.pem",
2438 }
2439
2440 sh_binary {
2441 name: "myscript",
2442 src: "mylib.cpp",
2443 filename: "myscript.sh",
2444 sub_dir: "script",
2445 }
2446 `)
2447
Sundong Ahnabb64432019-10-22 13:58:29 +09002448 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Jiyong Park04480cf2019-02-06 00:16:29 +09002449 copyCmds := apexRule.Args["copy_commands"]
2450
2451 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
2452}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002453
Jooyung Han91df2082019-11-20 01:49:42 +09002454func TestApexInVariousPartition(t *testing.T) {
2455 testcases := []struct {
2456 propName, parition, flattenedPartition string
2457 }{
2458 {"", "system", "system_ext"},
2459 {"product_specific: true", "product", "product"},
2460 {"soc_specific: true", "vendor", "vendor"},
2461 {"proprietary: true", "vendor", "vendor"},
2462 {"vendor: true", "vendor", "vendor"},
2463 {"system_ext_specific: true", "system_ext", "system_ext"},
2464 }
2465 for _, tc := range testcases {
2466 t.Run(tc.propName+":"+tc.parition, func(t *testing.T) {
2467 ctx, _ := testApex(t, `
2468 apex {
2469 name: "myapex",
2470 key: "myapex.key",
2471 `+tc.propName+`
2472 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002473
Jooyung Han91df2082019-11-20 01:49:42 +09002474 apex_key {
2475 name: "myapex.key",
2476 public_key: "testkey.avbpubkey",
2477 private_key: "testkey.pem",
2478 }
2479 `)
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002480
Jooyung Han91df2082019-11-20 01:49:42 +09002481 apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
2482 expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex"
2483 actual := apex.installDir.String()
2484 if actual != expected {
2485 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2486 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002487
Jooyung Han91df2082019-11-20 01:49:42 +09002488 flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle)
2489 expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex"
2490 actual = flattened.installDir.String()
2491 if actual != expected {
2492 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
2493 }
2494 })
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002495 }
Jiyong Parkd1e293d2019-03-15 02:13:21 +09002496}
Jiyong Park67882562019-03-21 01:11:21 +09002497
Jooyung Han54aca7b2019-11-20 02:26:02 +09002498func TestFileContexts(t *testing.T) {
2499 ctx, _ := testApex(t, `
2500 apex {
2501 name: "myapex",
2502 key: "myapex.key",
2503 }
2504
2505 apex_key {
2506 name: "myapex.key",
2507 public_key: "testkey.avbpubkey",
2508 private_key: "testkey.pem",
2509 }
2510 `)
2511 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
2512 apexRule := module.Rule("apexRule")
2513 actual := apexRule.Args["file_contexts"]
2514 expected := "system/sepolicy/apex/myapex-file_contexts"
2515 if actual != expected {
2516 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2517 }
2518
2519 testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, `
2520 apex {
2521 name: "myapex",
2522 key: "myapex.key",
2523 file_contexts: "my_own_file_contexts",
2524 }
2525
2526 apex_key {
2527 name: "myapex.key",
2528 public_key: "testkey.avbpubkey",
2529 private_key: "testkey.pem",
2530 }
2531 `, withFiles(map[string][]byte{
2532 "my_own_file_contexts": nil,
2533 }))
2534
2535 testApexError(t, `"myapex" .*: file_contexts: cannot find`, `
2536 apex {
2537 name: "myapex",
2538 key: "myapex.key",
2539 product_specific: true,
2540 file_contexts: "product_specific_file_contexts",
2541 }
2542
2543 apex_key {
2544 name: "myapex.key",
2545 public_key: "testkey.avbpubkey",
2546 private_key: "testkey.pem",
2547 }
2548 `)
2549
2550 ctx, _ = testApex(t, `
2551 apex {
2552 name: "myapex",
2553 key: "myapex.key",
2554 product_specific: true,
2555 file_contexts: "product_specific_file_contexts",
2556 }
2557
2558 apex_key {
2559 name: "myapex.key",
2560 public_key: "testkey.avbpubkey",
2561 private_key: "testkey.pem",
2562 }
2563 `, withFiles(map[string][]byte{
2564 "product_specific_file_contexts": nil,
2565 }))
2566 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2567 apexRule = module.Rule("apexRule")
2568 actual = apexRule.Args["file_contexts"]
2569 expected = "product_specific_file_contexts"
2570 if actual != expected {
2571 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2572 }
2573
2574 ctx, _ = testApex(t, `
2575 apex {
2576 name: "myapex",
2577 key: "myapex.key",
2578 product_specific: true,
2579 file_contexts: ":my-file-contexts",
2580 }
2581
2582 apex_key {
2583 name: "myapex.key",
2584 public_key: "testkey.avbpubkey",
2585 private_key: "testkey.pem",
2586 }
2587
2588 filegroup {
2589 name: "my-file-contexts",
2590 srcs: ["product_specific_file_contexts"],
2591 }
2592 `, withFiles(map[string][]byte{
2593 "product_specific_file_contexts": nil,
2594 }))
2595 module = ctx.ModuleForTests("myapex", "android_common_myapex_image")
2596 apexRule = module.Rule("apexRule")
2597 actual = apexRule.Args["file_contexts"]
2598 expected = "product_specific_file_contexts"
2599 if actual != expected {
2600 t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual)
2601 }
2602}
2603
Jiyong Park67882562019-03-21 01:11:21 +09002604func TestApexKeyFromOtherModule(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002605 ctx, _ := testApex(t, `
Jiyong Park67882562019-03-21 01:11:21 +09002606 apex_key {
2607 name: "myapex.key",
2608 public_key: ":my.avbpubkey",
2609 private_key: ":my.pem",
2610 product_specific: true,
2611 }
2612
2613 filegroup {
2614 name: "my.avbpubkey",
2615 srcs: ["testkey2.avbpubkey"],
2616 }
2617
2618 filegroup {
2619 name: "my.pem",
2620 srcs: ["testkey2.pem"],
2621 }
2622 `)
2623
2624 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
2625 expected_pubkey := "testkey2.avbpubkey"
2626 actual_pubkey := apex_key.public_key_file.String()
2627 if actual_pubkey != expected_pubkey {
2628 t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey)
2629 }
2630 expected_privkey := "testkey2.pem"
2631 actual_privkey := apex_key.private_key_file.String()
2632 if actual_privkey != expected_privkey {
2633 t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey)
2634 }
2635}
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002636
2637func TestPrebuilt(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002638 ctx, _ := testApex(t, `
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002639 prebuilt_apex {
2640 name: "myapex",
Jiyong Parkc95714e2019-03-29 14:23:10 +09002641 arch: {
2642 arm64: {
2643 src: "myapex-arm64.apex",
2644 },
2645 arm: {
2646 src: "myapex-arm.apex",
2647 },
2648 },
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002649 }
2650 `)
2651
2652 prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2653
Jiyong Parkc95714e2019-03-29 14:23:10 +09002654 expectedInput := "myapex-arm64.apex"
2655 if prebuilt.inputApex.String() != expectedInput {
2656 t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String())
2657 }
Jaewoong Jung939ebd52019-03-26 15:07:36 -07002658}
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002659
2660func TestPrebuiltFilenameOverride(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002661 ctx, _ := testApex(t, `
Nikita Ioffe7a41ebd2019-04-04 18:09:48 +01002662 prebuilt_apex {
2663 name: "myapex",
2664 src: "myapex-arm.apex",
2665 filename: "notmyapex.apex",
2666 }
2667 `)
2668
2669 p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt)
2670
2671 expected := "notmyapex.apex"
2672 if p.installFilename != expected {
2673 t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename)
2674 }
2675}
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07002676
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002677func TestPrebuiltOverrides(t *testing.T) {
2678 ctx, config := testApex(t, `
2679 prebuilt_apex {
2680 name: "myapex.prebuilt",
2681 src: "myapex-arm.apex",
2682 overrides: [
2683 "myapex",
2684 ],
2685 }
2686 `)
2687
2688 p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt)
2689
2690 expected := []string{"myapex"}
Jiyong Park0b0e1b92019-12-03 13:24:29 +09002691 actual := android.AndroidMkEntriesForTest(t, config, "", p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002692 if !reflect.DeepEqual(actual, expected) {
Jiyong Parkb0a012c2019-11-14 17:17:03 +09002693 t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected)
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002694 }
2695}
2696
Roland Levillain630846d2019-06-26 12:48:34 +01002697func TestApexWithTests(t *testing.T) {
Roland Levillainf89cd092019-07-29 16:22:59 +01002698 ctx, config := testApex(t, `
Roland Levillain630846d2019-06-26 12:48:34 +01002699 apex_test {
2700 name: "myapex",
2701 key: "myapex.key",
2702 tests: [
2703 "mytest",
Roland Levillain9b5fde92019-06-28 15:41:19 +01002704 "mytests",
Roland Levillain630846d2019-06-26 12:48:34 +01002705 ],
2706 }
2707
2708 apex_key {
2709 name: "myapex.key",
2710 public_key: "testkey.avbpubkey",
2711 private_key: "testkey.pem",
2712 }
2713
2714 cc_test {
2715 name: "mytest",
2716 gtest: false,
2717 srcs: ["mytest.cpp"],
2718 relative_install_path: "test",
2719 system_shared_libs: [],
2720 static_executable: true,
2721 stl: "none",
2722 }
Roland Levillain9b5fde92019-06-28 15:41:19 +01002723
2724 cc_test {
2725 name: "mytests",
2726 gtest: false,
2727 srcs: [
2728 "mytest1.cpp",
2729 "mytest2.cpp",
2730 "mytest3.cpp",
2731 ],
2732 test_per_src: true,
2733 relative_install_path: "test",
2734 system_shared_libs: [],
2735 static_executable: true,
2736 stl: "none",
2737 }
Roland Levillain630846d2019-06-26 12:48:34 +01002738 `)
2739
Sundong Ahnabb64432019-10-22 13:58:29 +09002740 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule")
Roland Levillain630846d2019-06-26 12:48:34 +01002741 copyCmds := apexRule.Args["copy_commands"]
2742
2743 // Ensure that test dep is copied into apex.
2744 ensureContains(t, copyCmds, "image.apex/bin/test/mytest")
Roland Levillain9b5fde92019-06-28 15:41:19 +01002745
2746 // Ensure that test deps built with `test_per_src` are copied into apex.
2747 ensureContains(t, copyCmds, "image.apex/bin/test/mytest1")
2748 ensureContains(t, copyCmds, "image.apex/bin/test/mytest2")
2749 ensureContains(t, copyCmds, "image.apex/bin/test/mytest3")
Roland Levillainf89cd092019-07-29 16:22:59 +01002750
2751 // Ensure the module is correctly translated.
Sundong Ahnabb64432019-10-22 13:58:29 +09002752 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Roland Levillainf89cd092019-07-29 16:22:59 +01002753 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
2754 name := apexBundle.BaseModuleName()
2755 prefix := "TARGET_"
2756 var builder strings.Builder
2757 data.Custom(&builder, name, prefix, "", data)
2758 androidMk := builder.String()
Jooyung Han31c470b2019-10-18 16:26:59 +09002759 ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n")
2760 ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n")
2761 ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n")
2762 ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n")
Jooyung Han214bf372019-11-12 13:03:50 +09002763 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n")
Jooyung Han31c470b2019-10-18 16:26:59 +09002764 ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n")
Roland Levillainf89cd092019-07-29 16:22:59 +01002765 ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n")
Roland Levillain630846d2019-06-26 12:48:34 +01002766}
2767
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002768func TestInstallExtraFlattenedApexes(t *testing.T) {
2769 ctx, config := testApex(t, `
2770 apex {
2771 name: "myapex",
2772 key: "myapex.key",
2773 }
2774 apex_key {
2775 name: "myapex.key",
2776 public_key: "testkey.avbpubkey",
2777 private_key: "testkey.pem",
2778 }
2779 `, func(fs map[string][]byte, config android.Config) {
2780 config.TestProductVariables.InstallExtraFlattenedApexes = proptools.BoolPtr(true)
2781 })
2782 ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
Jiyong Park83dc74b2020-01-14 18:38:44 +09002783 ensureListContains(t, ab.requiredDeps, "myapex.flattened")
Jooyung Han3ab2c3e2019-12-05 16:27:44 +09002784 mk := android.AndroidMkDataForTest(t, config, "", ab)
2785 var builder strings.Builder
2786 mk.Custom(&builder, ab.Name(), "TARGET_", "", mk)
2787 androidMk := builder.String()
2788 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened")
2789}
2790
Jooyung Han5c998b92019-06-27 11:30:33 +09002791func TestApexUsesOtherApex(t *testing.T) {
Jaewoong Jung22f7d182019-07-16 18:25:41 -07002792 ctx, _ := testApex(t, `
Jooyung Han5c998b92019-06-27 11:30:33 +09002793 apex {
2794 name: "myapex",
2795 key: "myapex.key",
2796 native_shared_libs: ["mylib"],
2797 uses: ["commonapex"],
2798 }
2799
2800 apex {
2801 name: "commonapex",
2802 key: "myapex.key",
2803 native_shared_libs: ["libcommon"],
2804 provide_cpp_shared_libs: true,
2805 }
2806
2807 apex_key {
2808 name: "myapex.key",
2809 public_key: "testkey.avbpubkey",
2810 private_key: "testkey.pem",
2811 }
2812
2813 cc_library {
2814 name: "mylib",
2815 srcs: ["mylib.cpp"],
2816 shared_libs: ["libcommon"],
2817 system_shared_libs: [],
2818 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002819 apex_available: [ "myapex" ],
Jooyung Han5c998b92019-06-27 11:30:33 +09002820 }
2821
2822 cc_library {
2823 name: "libcommon",
2824 srcs: ["mylib_common.cpp"],
2825 system_shared_libs: [],
2826 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002827 // TODO: remove //apex_available:platform
2828 apex_available: [
2829 "//apex_available:platform",
2830 "commonapex",
2831 "myapex",
2832 ],
Jooyung Han5c998b92019-06-27 11:30:33 +09002833 }
2834 `)
2835
Sundong Ahnabb64432019-10-22 13:58:29 +09002836 module1 := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002837 apexRule1 := module1.Rule("apexRule")
2838 copyCmds1 := apexRule1.Args["copy_commands"]
2839
Sundong Ahnabb64432019-10-22 13:58:29 +09002840 module2 := ctx.ModuleForTests("commonapex", "android_common_commonapex_image")
Jooyung Han5c998b92019-06-27 11:30:33 +09002841 apexRule2 := module2.Rule("apexRule")
2842 copyCmds2 := apexRule2.Args["copy_commands"]
2843
Colin Cross7113d202019-11-20 16:39:12 -08002844 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_myapex")
2845 ensureListContains(t, ctx.ModuleVariantsForTests("libcommon"), "android_arm64_armv8-a_shared_commonapex")
Jooyung Han5c998b92019-06-27 11:30:33 +09002846 ensureContains(t, copyCmds1, "image.apex/lib64/mylib.so")
2847 ensureContains(t, copyCmds2, "image.apex/lib64/libcommon.so")
2848 ensureNotContains(t, copyCmds1, "image.apex/lib64/libcommon.so")
2849}
2850
2851func TestApexUsesFailsIfNotProvided(t *testing.T) {
2852 testApexError(t, `uses: "commonapex" does not provide native_shared_libs`, `
2853 apex {
2854 name: "myapex",
2855 key: "myapex.key",
2856 uses: ["commonapex"],
2857 }
2858
2859 apex {
2860 name: "commonapex",
2861 key: "myapex.key",
2862 }
2863
2864 apex_key {
2865 name: "myapex.key",
2866 public_key: "testkey.avbpubkey",
2867 private_key: "testkey.pem",
2868 }
2869 `)
2870 testApexError(t, `uses: "commonapex" is not a provider`, `
2871 apex {
2872 name: "myapex",
2873 key: "myapex.key",
2874 uses: ["commonapex"],
2875 }
2876
2877 cc_library {
2878 name: "commonapex",
2879 system_shared_libs: [],
2880 stl: "none",
2881 }
2882
2883 apex_key {
2884 name: "myapex.key",
2885 public_key: "testkey.avbpubkey",
2886 private_key: "testkey.pem",
2887 }
2888 `)
2889}
2890
2891func TestApexUsesFailsIfUseVenderMismatch(t *testing.T) {
2892 testApexError(t, `use_vendor: "commonapex" has different value of use_vendor`, `
2893 apex {
2894 name: "myapex",
2895 key: "myapex.key",
2896 use_vendor: true,
2897 uses: ["commonapex"],
2898 }
2899
2900 apex {
2901 name: "commonapex",
2902 key: "myapex.key",
2903 provide_cpp_shared_libs: true,
2904 }
2905
2906 apex_key {
2907 name: "myapex.key",
2908 public_key: "testkey.avbpubkey",
2909 private_key: "testkey.pem",
2910 }
Jooyung Handc782442019-11-01 03:14:38 +09002911 `, func(fs map[string][]byte, config android.Config) {
2912 setUseVendorWhitelistForTest(config, []string{"myapex"})
2913 })
Jooyung Han5c998b92019-06-27 11:30:33 +09002914}
2915
Jooyung Hand48f3c32019-08-23 11:18:57 +09002916func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
2917 testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
2918 apex {
2919 name: "myapex",
2920 key: "myapex.key",
2921 native_shared_libs: ["libfoo"],
2922 }
2923
2924 apex_key {
2925 name: "myapex.key",
2926 public_key: "testkey.avbpubkey",
2927 private_key: "testkey.pem",
2928 }
2929
2930 cc_library {
2931 name: "libfoo",
2932 stl: "none",
2933 system_shared_libs: [],
2934 enabled: false,
2935 }
2936 `)
2937 testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
2938 apex {
2939 name: "myapex",
2940 key: "myapex.key",
2941 java_libs: ["myjar"],
2942 }
2943
2944 apex_key {
2945 name: "myapex.key",
2946 public_key: "testkey.avbpubkey",
2947 private_key: "testkey.pem",
2948 }
2949
2950 java_library {
2951 name: "myjar",
2952 srcs: ["foo/bar/MyClass.java"],
2953 sdk_version: "none",
2954 system_modules: "none",
2955 compile_dex: true,
2956 enabled: false,
2957 }
2958 `)
2959}
2960
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002961func TestApexWithApps(t *testing.T) {
2962 ctx, _ := testApex(t, `
2963 apex {
2964 name: "myapex",
2965 key: "myapex.key",
2966 apps: [
2967 "AppFoo",
Jiyong Parkf7487312019-10-17 12:54:30 +09002968 "AppFooPriv",
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002969 ],
2970 }
2971
2972 apex_key {
2973 name: "myapex.key",
2974 public_key: "testkey.avbpubkey",
2975 private_key: "testkey.pem",
2976 }
2977
2978 android_app {
2979 name: "AppFoo",
2980 srcs: ["foo/bar/MyClass.java"],
2981 sdk_version: "none",
2982 system_modules: "none",
Jiyong Park8be103b2019-11-08 15:53:48 +09002983 jni_libs: ["libjni"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002984 apex_available: [ "myapex" ],
Sundong Ahne1f05aa2019-08-27 13:55:42 +09002985 }
Jiyong Parkf7487312019-10-17 12:54:30 +09002986
2987 android_app {
2988 name: "AppFooPriv",
2989 srcs: ["foo/bar/MyClass.java"],
2990 sdk_version: "none",
2991 system_modules: "none",
2992 privileged: true,
Anton Hanssoneec79eb2020-01-10 15:12:39 +00002993 apex_available: [ "myapex" ],
Jiyong Parkf7487312019-10-17 12:54:30 +09002994 }
Jiyong Park8be103b2019-11-08 15:53:48 +09002995
2996 cc_library_shared {
2997 name: "libjni",
2998 srcs: ["mylib.cpp"],
2999 stl: "none",
3000 system_shared_libs: [],
3001 }
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003002 `)
3003
Sundong Ahnabb64432019-10-22 13:58:29 +09003004 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003005 apexRule := module.Rule("apexRule")
3006 copyCmds := apexRule.Args["copy_commands"]
3007
3008 ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
Jiyong Parkf7487312019-10-17 12:54:30 +09003009 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk")
Jiyong Park52cd06f2019-11-11 10:14:32 +09003010
3011 // JNI libraries are embedded inside APK
3012 appZipRule := ctx.ModuleForTests("AppFoo", "android_common_myapex").Rule("zip")
Colin Cross7113d202019-11-20 16:39:12 -08003013 libjniOutput := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared_myapex").Module().(*cc.Module).OutputFile()
Jiyong Park52cd06f2019-11-11 10:14:32 +09003014 ensureListContains(t, appZipRule.Implicits.Strings(), libjniOutput.String())
3015 // ... uncompressed
3016 if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") {
3017 t.Errorf("jni lib is not uncompressed for AppFoo")
3018 }
3019 // ... and not directly inside the APEX
3020 ensureNotContains(t, copyCmds, "image.apex/lib64/libjni.so")
Dario Frenicde2a032019-10-27 00:29:22 +01003021}
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003022
Dario Frenicde2a032019-10-27 00:29:22 +01003023func TestApexWithAppImports(t *testing.T) {
3024 ctx, _ := testApex(t, `
3025 apex {
3026 name: "myapex",
3027 key: "myapex.key",
3028 apps: [
3029 "AppFooPrebuilt",
3030 "AppFooPrivPrebuilt",
3031 ],
3032 }
3033
3034 apex_key {
3035 name: "myapex.key",
3036 public_key: "testkey.avbpubkey",
3037 private_key: "testkey.pem",
3038 }
3039
3040 android_app_import {
3041 name: "AppFooPrebuilt",
3042 apk: "PrebuiltAppFoo.apk",
3043 presigned: true,
3044 dex_preopt: {
3045 enabled: false,
3046 },
3047 }
3048
3049 android_app_import {
3050 name: "AppFooPrivPrebuilt",
3051 apk: "PrebuiltAppFooPriv.apk",
3052 privileged: true,
3053 presigned: true,
3054 dex_preopt: {
3055 enabled: false,
3056 },
3057 }
3058 `)
3059
Sundong Ahnabb64432019-10-22 13:58:29 +09003060 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
Dario Frenicde2a032019-10-27 00:29:22 +01003061 apexRule := module.Rule("apexRule")
3062 copyCmds := apexRule.Args["copy_commands"]
3063
3064 ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk")
3065 ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
Sundong Ahne1f05aa2019-08-27 13:55:42 +09003066}
3067
Dario Freni6f3937c2019-12-20 22:58:03 +00003068func TestApexWithTestHelperApp(t *testing.T) {
3069 ctx, _ := testApex(t, `
3070 apex {
3071 name: "myapex",
3072 key: "myapex.key",
3073 apps: [
3074 "TesterHelpAppFoo",
3075 ],
3076 }
3077
3078 apex_key {
3079 name: "myapex.key",
3080 public_key: "testkey.avbpubkey",
3081 private_key: "testkey.pem",
3082 }
3083
3084 android_test_helper_app {
3085 name: "TesterHelpAppFoo",
3086 srcs: ["foo/bar/MyClass.java"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003087 apex_available: [ "myapex" ],
Dario Freni6f3937c2019-12-20 22:58:03 +00003088 }
3089
3090 `)
3091
3092 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3093 apexRule := module.Rule("apexRule")
3094 copyCmds := apexRule.Args["copy_commands"]
3095
3096 ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk")
3097}
3098
Jooyung Han18020ea2019-11-13 10:50:48 +09003099func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
3100 // libfoo's apex_available comes from cc_defaults
3101 testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, `
3102 apex {
3103 name: "myapex",
3104 key: "myapex.key",
3105 native_shared_libs: ["libfoo"],
3106 }
3107
3108 apex_key {
3109 name: "myapex.key",
3110 public_key: "testkey.avbpubkey",
3111 private_key: "testkey.pem",
3112 }
3113
3114 apex {
3115 name: "otherapex",
3116 key: "myapex.key",
3117 native_shared_libs: ["libfoo"],
3118 }
3119
3120 cc_defaults {
3121 name: "libfoo-defaults",
3122 apex_available: ["otherapex"],
3123 }
3124
3125 cc_library {
3126 name: "libfoo",
3127 defaults: ["libfoo-defaults"],
3128 stl: "none",
3129 system_shared_libs: [],
3130 }`)
3131}
3132
Jiyong Park127b40b2019-09-30 16:04:35 +09003133func TestApexAvailable(t *testing.T) {
3134 // libfoo is not available to myapex, but only to otherapex
3135 testApexError(t, "requires \"libfoo\" that is not available for the APEX", `
3136 apex {
3137 name: "myapex",
3138 key: "myapex.key",
3139 native_shared_libs: ["libfoo"],
3140 }
3141
3142 apex_key {
3143 name: "myapex.key",
3144 public_key: "testkey.avbpubkey",
3145 private_key: "testkey.pem",
3146 }
3147
3148 apex {
3149 name: "otherapex",
3150 key: "otherapex.key",
3151 native_shared_libs: ["libfoo"],
3152 }
3153
3154 apex_key {
3155 name: "otherapex.key",
3156 public_key: "testkey.avbpubkey",
3157 private_key: "testkey.pem",
3158 }
3159
3160 cc_library {
3161 name: "libfoo",
3162 stl: "none",
3163 system_shared_libs: [],
3164 apex_available: ["otherapex"],
3165 }`)
3166
3167 // libbar is an indirect dep
3168 testApexError(t, "requires \"libbar\" that is not available for the APEX", `
3169 apex {
3170 name: "myapex",
3171 key: "myapex.key",
3172 native_shared_libs: ["libfoo"],
3173 }
3174
3175 apex_key {
3176 name: "myapex.key",
3177 public_key: "testkey.avbpubkey",
3178 private_key: "testkey.pem",
3179 }
3180
3181 apex {
3182 name: "otherapex",
3183 key: "otherapex.key",
3184 native_shared_libs: ["libfoo"],
3185 }
3186
3187 apex_key {
3188 name: "otherapex.key",
3189 public_key: "testkey.avbpubkey",
3190 private_key: "testkey.pem",
3191 }
3192
3193 cc_library {
3194 name: "libfoo",
3195 stl: "none",
3196 shared_libs: ["libbar"],
3197 system_shared_libs: [],
3198 apex_available: ["myapex", "otherapex"],
3199 }
3200
3201 cc_library {
3202 name: "libbar",
3203 stl: "none",
3204 system_shared_libs: [],
3205 apex_available: ["otherapex"],
3206 }`)
3207
3208 testApexError(t, "\"otherapex\" is not a valid module name", `
3209 apex {
3210 name: "myapex",
3211 key: "myapex.key",
3212 native_shared_libs: ["libfoo"],
3213 }
3214
3215 apex_key {
3216 name: "myapex.key",
3217 public_key: "testkey.avbpubkey",
3218 private_key: "testkey.pem",
3219 }
3220
3221 cc_library {
3222 name: "libfoo",
3223 stl: "none",
3224 system_shared_libs: [],
3225 apex_available: ["otherapex"],
3226 }`)
3227
3228 ctx, _ := testApex(t, `
3229 apex {
3230 name: "myapex",
3231 key: "myapex.key",
3232 native_shared_libs: ["libfoo", "libbar"],
3233 }
3234
3235 apex_key {
3236 name: "myapex.key",
3237 public_key: "testkey.avbpubkey",
3238 private_key: "testkey.pem",
3239 }
3240
3241 cc_library {
3242 name: "libfoo",
3243 stl: "none",
3244 system_shared_libs: [],
3245 apex_available: ["myapex"],
3246 }
3247
3248 cc_library {
3249 name: "libbar",
3250 stl: "none",
3251 system_shared_libs: [],
3252 apex_available: ["//apex_available:anyapex"],
3253 }`)
3254
3255 // check that libfoo and libbar are created only for myapex, but not for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003256 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3257 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
3258 ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_myapex")
3259 ensureListNotContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared")
Jiyong Park127b40b2019-09-30 16:04:35 +09003260
3261 ctx, _ = testApex(t, `
3262 apex {
3263 name: "myapex",
3264 key: "myapex.key",
3265 }
3266
3267 apex_key {
3268 name: "myapex.key",
3269 public_key: "testkey.avbpubkey",
3270 private_key: "testkey.pem",
3271 }
3272
3273 cc_library {
3274 name: "libfoo",
3275 stl: "none",
3276 system_shared_libs: [],
3277 apex_available: ["//apex_available:platform"],
3278 }`)
3279
3280 // check that libfoo is created only for the platform
Colin Cross7113d202019-11-20 16:39:12 -08003281 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3282 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003283
3284 ctx, _ = testApex(t, `
3285 apex {
3286 name: "myapex",
3287 key: "myapex.key",
3288 native_shared_libs: ["libfoo"],
3289 }
3290
3291 apex_key {
3292 name: "myapex.key",
3293 public_key: "testkey.avbpubkey",
3294 private_key: "testkey.pem",
3295 }
3296
3297 cc_library {
3298 name: "libfoo",
3299 stl: "none",
3300 system_shared_libs: [],
3301 apex_available: ["myapex"],
3302 static: {
3303 apex_available: ["//apex_available:platform"],
3304 },
3305 }`)
3306
3307 // shared variant of libfoo is only available to myapex
Colin Cross7113d202019-11-20 16:39:12 -08003308 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared_myapex")
3309 ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_shared")
Jiyong Parka90ca002019-10-07 15:47:24 +09003310 // but the static variant is available to both myapex and the platform
Colin Cross7113d202019-11-20 16:39:12 -08003311 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static_myapex")
3312 ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_static")
Jiyong Park127b40b2019-09-30 16:04:35 +09003313}
3314
Jiyong Park5d790c32019-11-15 18:40:32 +09003315func TestOverrideApex(t *testing.T) {
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003316 ctx, config := testApex(t, `
Jiyong Park5d790c32019-11-15 18:40:32 +09003317 apex {
3318 name: "myapex",
3319 key: "myapex.key",
3320 apps: ["app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003321 overrides: ["oldapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003322 }
3323
3324 override_apex {
3325 name: "override_myapex",
3326 base: "myapex",
3327 apps: ["override_app"],
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003328 overrides: ["unknownapex"],
Jiyong Park5d790c32019-11-15 18:40:32 +09003329 }
3330
3331 apex_key {
3332 name: "myapex.key",
3333 public_key: "testkey.avbpubkey",
3334 private_key: "testkey.pem",
3335 }
3336
3337 android_app {
3338 name: "app",
3339 srcs: ["foo/bar/MyClass.java"],
3340 package_name: "foo",
3341 sdk_version: "none",
3342 system_modules: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003343 apex_available: [ "myapex" ],
Jiyong Park5d790c32019-11-15 18:40:32 +09003344 }
3345
3346 override_android_app {
3347 name: "override_app",
3348 base: "app",
3349 package_name: "bar",
3350 }
3351 `)
3352
Jiyong Park317645e2019-12-05 13:20:58 +09003353 originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule)
3354 overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule)
3355 if originalVariant.GetOverriddenBy() != "" {
3356 t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy())
3357 }
3358 if overriddenVariant.GetOverriddenBy() != "override_myapex" {
3359 t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy())
3360 }
3361
Jiyong Park5d790c32019-11-15 18:40:32 +09003362 module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image")
3363 apexRule := module.Rule("apexRule")
3364 copyCmds := apexRule.Args["copy_commands"]
3365
3366 ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk")
3367 ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003368
3369 apexBundle := module.Module().(*apexBundle)
3370 name := apexBundle.Name()
3371 if name != "override_myapex" {
3372 t.Errorf("name should be \"override_myapex\", but was %q", name)
3373 }
3374
3375 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3376 var builder strings.Builder
3377 data.Custom(&builder, name, "TARGET_", "", data)
3378 androidMk := builder.String()
Jiyong Parkf653b052019-11-18 15:39:01 +09003379 ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003380 ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex")
3381 ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex")
Jaewoong Jung7abcf8e2019-12-19 17:32:06 -08003382 ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003383 ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex")
Jiyong Parkf653b052019-11-18 15:39:01 +09003384 ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex")
Jaewoong Jung1670ca02019-11-22 14:50:42 -08003385 ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex")
3386 ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex")
Jiyong Park5d790c32019-11-15 18:40:32 +09003387}
3388
Jooyung Han214bf372019-11-12 13:03:50 +09003389func TestLegacyAndroid10Support(t *testing.T) {
3390 ctx, _ := testApex(t, `
3391 apex {
3392 name: "myapex",
3393 key: "myapex.key",
3394 legacy_android10_support: true,
3395 }
3396
3397 apex_key {
3398 name: "myapex.key",
3399 public_key: "testkey.avbpubkey",
3400 private_key: "testkey.pem",
3401 }
3402 `)
3403
3404 module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
3405 args := module.Rule("apexRule").Args
3406 ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String())
Dario Frenie3546902020-01-14 23:50:25 +00003407 ensureNotContains(t, args["opt_flags"], "--no_hashtree")
Jooyung Han214bf372019-11-12 13:03:50 +09003408}
3409
Jooyung Han58f26ab2019-12-18 15:34:32 +09003410func TestJavaSDKLibrary(t *testing.T) {
3411 ctx, _ := testApex(t, `
3412 apex {
3413 name: "myapex",
3414 key: "myapex.key",
3415 java_libs: ["foo"],
3416 }
3417
3418 apex_key {
3419 name: "myapex.key",
3420 public_key: "testkey.avbpubkey",
3421 private_key: "testkey.pem",
3422 }
3423
3424 java_sdk_library {
3425 name: "foo",
3426 srcs: ["a.java"],
3427 api_packages: ["foo"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003428 apex_available: [ "myapex" ],
Jooyung Han58f26ab2019-12-18 15:34:32 +09003429 }
3430 `, withFiles(map[string][]byte{
3431 "api/current.txt": nil,
3432 "api/removed.txt": nil,
3433 "api/system-current.txt": nil,
3434 "api/system-removed.txt": nil,
3435 "api/test-current.txt": nil,
3436 "api/test-removed.txt": nil,
3437 }))
3438
3439 // java_sdk_library installs both impl jar and permission XML
Jooyung Han5df3b112020-01-23 05:10:16 +00003440 ensureExactContents(t, ctx, "myapex", []string{
Jooyung Han58f26ab2019-12-18 15:34:32 +09003441 "javalib/foo.jar",
3442 "etc/permissions/foo.xml",
3443 })
3444 // Permission XML should point to the activated path of impl jar of java_sdk_library
Jooyung Han624058e2019-12-24 18:38:06 +09003445 xml := ctx.ModuleForTests("foo", "android_common_myapex").Output("foo.xml")
3446 ensureContains(t, xml.Args["content"], `<library name="foo" file="/apex/myapex/javalib/foo.jar"`)
Jooyung Han58f26ab2019-12-18 15:34:32 +09003447}
3448
Jiyong Park479321d2019-12-16 11:47:12 +09003449func TestRejectNonInstallableJavaLibrary(t *testing.T) {
3450 testApexError(t, `"myjar" is not configured to be compiled into dex`, `
3451 apex {
3452 name: "myapex",
3453 key: "myapex.key",
3454 java_libs: ["myjar"],
3455 }
3456
3457 apex_key {
3458 name: "myapex.key",
3459 public_key: "testkey.avbpubkey",
3460 private_key: "testkey.pem",
3461 }
3462
3463 java_library {
3464 name: "myjar",
3465 srcs: ["foo/bar/MyClass.java"],
3466 sdk_version: "none",
3467 system_modules: "none",
3468 }
3469 `)
3470}
3471
Jiyong Park7afd1072019-12-30 16:56:33 +09003472func TestCarryRequiredModuleNames(t *testing.T) {
3473 ctx, config := testApex(t, `
3474 apex {
3475 name: "myapex",
3476 key: "myapex.key",
3477 native_shared_libs: ["mylib"],
3478 }
3479
3480 apex_key {
3481 name: "myapex.key",
3482 public_key: "testkey.avbpubkey",
3483 private_key: "testkey.pem",
3484 }
3485
3486 cc_library {
3487 name: "mylib",
3488 srcs: ["mylib.cpp"],
3489 system_shared_libs: [],
3490 stl: "none",
3491 required: ["a", "b"],
3492 host_required: ["c", "d"],
3493 target_required: ["e", "f"],
Anton Hanssoneec79eb2020-01-10 15:12:39 +00003494 apex_available: [ "myapex" ],
Jiyong Park7afd1072019-12-30 16:56:33 +09003495 }
3496 `)
3497
3498 apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle)
3499 data := android.AndroidMkDataForTest(t, config, "", apexBundle)
3500 name := apexBundle.BaseModuleName()
3501 prefix := "TARGET_"
3502 var builder strings.Builder
3503 data.Custom(&builder, name, prefix, "", data)
3504 androidMk := builder.String()
3505 ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n")
3506 ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n")
3507 ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n")
3508}
3509
Jiyong Park7cd10e32020-01-14 09:22:18 +09003510func TestSymlinksFromApexToSystem(t *testing.T) {
3511 bp := `
3512 apex {
3513 name: "myapex",
3514 key: "myapex.key",
3515 native_shared_libs: ["mylib"],
3516 java_libs: ["myjar"],
3517 }
3518
3519 apex_key {
3520 name: "myapex.key",
3521 public_key: "testkey.avbpubkey",
3522 private_key: "testkey.pem",
3523 }
3524
3525 cc_library {
3526 name: "mylib",
3527 srcs: ["mylib.cpp"],
3528 shared_libs: ["myotherlib"],
3529 system_shared_libs: [],
3530 stl: "none",
3531 apex_available: [
3532 "myapex",
3533 "//apex_available:platform",
3534 ],
3535 }
3536
3537 cc_library {
3538 name: "myotherlib",
3539 srcs: ["mylib.cpp"],
3540 system_shared_libs: [],
3541 stl: "none",
3542 apex_available: [
3543 "myapex",
3544 "//apex_available:platform",
3545 ],
3546 }
3547
3548 java_library {
3549 name: "myjar",
3550 srcs: ["foo/bar/MyClass.java"],
3551 sdk_version: "none",
3552 system_modules: "none",
3553 libs: ["myotherjar"],
3554 compile_dex: true,
3555 apex_available: [
3556 "myapex",
3557 "//apex_available:platform",
3558 ],
3559 }
3560
3561 java_library {
3562 name: "myotherjar",
3563 srcs: ["foo/bar/MyClass.java"],
3564 sdk_version: "none",
3565 system_modules: "none",
3566 apex_available: [
3567 "myapex",
3568 "//apex_available:platform",
3569 ],
3570 }
3571 `
3572
3573 ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) {
3574 for _, f := range files {
3575 if f.path == file {
3576 if f.isLink {
3577 t.Errorf("%q is not a real file", file)
3578 }
3579 return
3580 }
3581 }
3582 t.Errorf("%q is not found", file)
3583 }
3584
3585 ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) {
3586 for _, f := range files {
3587 if f.path == file {
3588 if !f.isLink {
3589 t.Errorf("%q is not a symlink", file)
3590 }
3591 return
3592 }
3593 }
3594 t.Errorf("%q is not found", file)
3595 }
3596
3597 ctx, _ := testApex(t, bp, withUnbundledBuild)
Jooyung Han5df3b112020-01-23 05:10:16 +00003598 files := getFiles(t, ctx, "myapex")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003599 ensureRealfileExists(t, files, "javalib/myjar.jar")
3600 ensureRealfileExists(t, files, "lib64/mylib.so")
3601 ensureRealfileExists(t, files, "lib64/myotherlib.so")
3602
3603 ctx, _ = testApex(t, bp)
Jooyung Han5df3b112020-01-23 05:10:16 +00003604 files = getFiles(t, ctx, "myapex")
Jiyong Park7cd10e32020-01-14 09:22:18 +09003605 ensureRealfileExists(t, files, "javalib/myjar.jar")
3606 ensureRealfileExists(t, files, "lib64/mylib.so")
3607 ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink
3608}
3609
Jaewoong Jungc1001ec2019-06-25 11:20:53 -07003610func TestMain(m *testing.M) {
3611 run := func() int {
3612 setUp()
3613 defer tearDown()
3614
3615 return m.Run()
3616 }
3617
3618 os.Exit(run())
3619}