blob: 13ddb55dbf8947a5353ba6dd3ae32ac6bbb6eec5 [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"
20 "strings"
21 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090022
23 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
26 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090027 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090028)
29
30func testApex(t *testing.T, bp string) *android.TestContext {
31 config, buildDir := setup(t)
32 defer teardown(buildDir)
33
34 ctx := android.NewTestArchContext()
Alex Light0851b882019-02-07 13:20:53 -080035 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
36 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090037 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +090038 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
39 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jiyong Park25fc6a92018-11-18 18:02:45 +090040
41 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
42 ctx.TopDown("apex_deps", apexDepsMutator)
43 ctx.BottomUp("apex", apexMutator)
44 })
45
46 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
47 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +090048 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +090049 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090051 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090052 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +090053 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +090054 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +090055 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090056 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090057 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090058 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090059 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090060 ctx.BottomUp("version", cc.VersionMutator).Parallel()
61 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
62 })
63
64 ctx.Register()
65
66 bp = bp + `
67 toolchain_library {
68 name: "libcompiler_rt-extras",
69 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090070 vendor_available: true,
71 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090072 }
73
74 toolchain_library {
75 name: "libatomic",
76 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090077 vendor_available: true,
78 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090079 }
80
81 toolchain_library {
82 name: "libgcc",
83 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090084 vendor_available: true,
85 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090086 }
87
88 toolchain_library {
89 name: "libclang_rt.builtins-aarch64-android",
90 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090091 vendor_available: true,
92 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090093 }
94
95 toolchain_library {
96 name: "libclang_rt.builtins-arm-android",
97 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090098 vendor_available: true,
99 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900100 }
101
102 cc_object {
103 name: "crtbegin_so",
104 stl: "none",
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 cc_object {
110 name: "crtend_so",
111 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900112 vendor_available: true,
113 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900114 }
115
Alex Light3d673592019-01-18 14:37:31 -0800116 cc_object {
117 name: "crtbegin_static",
118 stl: "none",
119 }
120
121 cc_object {
122 name: "crtend_android",
123 stl: "none",
124 }
125
Jiyong Parkda6eb592018-12-19 17:12:36 +0900126 llndk_library {
127 name: "libc",
128 symbol_file: "",
129 }
130
131 llndk_library {
132 name: "libm",
133 symbol_file: "",
134 }
135
136 llndk_library {
137 name: "libdl",
138 symbol_file: "",
139 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900140 `
141
142 ctx.MockFileSystem(map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900143 "Android.bp": []byte(bp),
144 "build/target/product/security": nil,
145 "apex_manifest.json": nil,
146 "system/sepolicy/apex/myapex-file_contexts": nil,
147 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
148 "system/sepolicy/apex/otherapex-file_contexts": nil,
149 "mylib.cpp": nil,
150 "myprebuilt": nil,
151 "my_include": nil,
152 "vendor/foo/devkeys/test.x509.pem": nil,
153 "vendor/foo/devkeys/test.pk8": nil,
154 "testkey.x509.pem": nil,
155 "testkey.pk8": nil,
156 "testkey.override.x509.pem": nil,
157 "testkey.override.pk8": nil,
158 "vendor/foo/devkeys/testkey.avbpubkey": nil,
159 "vendor/foo/devkeys/testkey.pem": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900160 })
161 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
162 android.FailIfErrored(t, errs)
163 _, errs = ctx.PrepareBuildActions(config)
164 android.FailIfErrored(t, errs)
165
166 return ctx
167}
168
169func setup(t *testing.T) (config android.Config, buildDir string) {
170 buildDir, err := ioutil.TempDir("", "soong_apex_test")
171 if err != nil {
172 t.Fatal(err)
173 }
174
175 config = android.TestArchConfig(buildDir, nil)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900176 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Park9335a262018-12-24 11:31:58 +0900177 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900178 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
Jiyong Park25fc6a92018-11-18 18:02:45 +0900179 return
180}
181
182func teardown(buildDir string) {
183 os.RemoveAll(buildDir)
184}
185
186// ensure that 'result' contains 'expected'
187func ensureContains(t *testing.T, result string, expected string) {
188 if !strings.Contains(result, expected) {
189 t.Errorf("%q is not found in %q", expected, result)
190 }
191}
192
193// ensures that 'result' does not contain 'notExpected'
194func ensureNotContains(t *testing.T, result string, notExpected string) {
195 if strings.Contains(result, notExpected) {
196 t.Errorf("%q is found in %q", notExpected, result)
197 }
198}
199
200func ensureListContains(t *testing.T, result []string, expected string) {
201 if !android.InList(expected, result) {
202 t.Errorf("%q is not found in %v", expected, result)
203 }
204}
205
206func ensureListNotContains(t *testing.T, result []string, notExpected string) {
207 if android.InList(notExpected, result) {
208 t.Errorf("%q is found in %v", notExpected, result)
209 }
210}
211
212// Minimal test
213func TestBasicApex(t *testing.T) {
214 ctx := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900215 apex_defaults {
216 name: "myapex-defaults",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900217 key: "myapex.key",
218 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800219 multilib: {
220 both: {
221 binaries: ["foo",],
222 }
223 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900224 }
225
Jiyong Park30ca9372019-02-07 16:27:23 +0900226 apex {
227 name: "myapex",
228 defaults: ["myapex-defaults"],
229 }
230
Jiyong Park25fc6a92018-11-18 18:02:45 +0900231 apex_key {
232 name: "myapex.key",
233 public_key: "testkey.avbpubkey",
234 private_key: "testkey.pem",
235 }
236
237 cc_library {
238 name: "mylib",
239 srcs: ["mylib.cpp"],
240 shared_libs: ["mylib2"],
241 system_shared_libs: [],
242 stl: "none",
243 }
244
Alex Light3d673592019-01-18 14:37:31 -0800245 cc_binary {
246 name: "foo",
247 srcs: ["mylib.cpp"],
248 compile_multilib: "both",
249 multilib: {
250 lib32: {
251 suffix: "32",
252 },
253 lib64: {
254 suffix: "64",
255 },
256 },
257 symlinks: ["foo_link_"],
258 symlink_preferred_arch: true,
259 system_shared_libs: [],
260 static_executable: true,
261 stl: "none",
262 }
263
Jiyong Park25fc6a92018-11-18 18:02:45 +0900264 cc_library {
265 name: "mylib2",
266 srcs: ["mylib.cpp"],
267 system_shared_libs: [],
268 stl: "none",
269 }
270 `)
271
272 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
273 copyCmds := apexRule.Args["copy_commands"]
274
275 // Ensure that main rule creates an output
276 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
277
278 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900279 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900280
281 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900282 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900283
284 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800285 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
286 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Logan Chien3aeedc92018-12-26 15:32:21 +0800287
288 // Ensure that the platform variant ends with _core_shared
289 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
290 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Alex Light3d673592019-01-18 14:37:31 -0800291
292 // Ensure that all symlinks are present.
293 found_foo_link_64 := false
294 found_foo := false
295 for _, cmd := range strings.Split(copyCmds, " && ") {
296 if strings.HasPrefix(cmd, "ln -s foo64") {
297 if strings.HasSuffix(cmd, "bin/foo") {
298 found_foo = true
299 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
300 found_foo_link_64 = true
301 }
302 }
303 }
304 good := found_foo && found_foo_link_64
305 if !good {
306 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
307 }
Alex Light5098a612018-11-29 17:12:15 -0800308}
309
310func TestBasicZipApex(t *testing.T) {
311 ctx := testApex(t, `
312 apex {
313 name: "myapex",
314 key: "myapex.key",
315 payload_type: "zip",
316 native_shared_libs: ["mylib"],
317 }
318
319 apex_key {
320 name: "myapex.key",
321 public_key: "testkey.avbpubkey",
322 private_key: "testkey.pem",
323 }
324
325 cc_library {
326 name: "mylib",
327 srcs: ["mylib.cpp"],
328 shared_libs: ["mylib2"],
329 system_shared_libs: [],
330 stl: "none",
331 }
332
333 cc_library {
334 name: "mylib2",
335 srcs: ["mylib.cpp"],
336 system_shared_libs: [],
337 stl: "none",
338 }
339 `)
340
341 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
342 copyCmds := zipApexRule.Args["copy_commands"]
343
344 // Ensure that main rule creates an output
345 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
346
347 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900348 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800349
350 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900351 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800352
353 // Ensure that both direct and indirect deps are copied into apex
354 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
355 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900356}
357
358func TestApexWithStubs(t *testing.T) {
359 ctx := testApex(t, `
360 apex {
361 name: "myapex",
362 key: "myapex.key",
363 native_shared_libs: ["mylib", "mylib3"],
364 }
365
366 apex_key {
367 name: "myapex.key",
368 public_key: "testkey.avbpubkey",
369 private_key: "testkey.pem",
370 }
371
372 cc_library {
373 name: "mylib",
374 srcs: ["mylib.cpp"],
375 shared_libs: ["mylib2", "mylib3"],
376 system_shared_libs: [],
377 stl: "none",
378 }
379
380 cc_library {
381 name: "mylib2",
382 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900383 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900384 system_shared_libs: [],
385 stl: "none",
386 stubs: {
387 versions: ["1", "2", "3"],
388 },
389 }
390
391 cc_library {
392 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900393 srcs: ["mylib.cpp"],
394 shared_libs: ["mylib4"],
395 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900396 stl: "none",
397 stubs: {
398 versions: ["10", "11", "12"],
399 },
400 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900401
402 cc_library {
403 name: "mylib4",
404 srcs: ["mylib.cpp"],
405 system_shared_libs: [],
406 stl: "none",
407 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900408 `)
409
410 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
411 copyCmds := apexRule.Args["copy_commands"]
412
413 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800414 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900415
416 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800417 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900418
419 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800420 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900421
Jiyong Parkda6eb592018-12-19 17:12:36 +0900422 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900423
424 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900425 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900426 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900427 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900428
429 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900430 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900431 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900432 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900433
434 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900435 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900436 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900437
438 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900439 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"])
Jiyong Park25fc6a92018-11-18 18:02:45 +0900440}
441
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900442func TestApexWithExplicitStubsDependency(t *testing.T) {
443 ctx := testApex(t, `
444 apex {
445 name: "myapex",
446 key: "myapex.key",
447 native_shared_libs: ["mylib"],
448 }
449
450 apex_key {
451 name: "myapex.key",
452 public_key: "testkey.avbpubkey",
453 private_key: "testkey.pem",
454 }
455
456 cc_library {
457 name: "mylib",
458 srcs: ["mylib.cpp"],
459 shared_libs: ["libfoo#10"],
460 system_shared_libs: [],
461 stl: "none",
462 }
463
464 cc_library {
465 name: "libfoo",
466 srcs: ["mylib.cpp"],
467 shared_libs: ["libbar"],
468 system_shared_libs: [],
469 stl: "none",
470 stubs: {
471 versions: ["10", "20", "30"],
472 },
473 }
474
475 cc_library {
476 name: "libbar",
477 srcs: ["mylib.cpp"],
478 system_shared_libs: [],
479 stl: "none",
480 }
481
482 `)
483
484 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
485 copyCmds := apexRule.Args["copy_commands"]
486
487 // Ensure that direct non-stubs dep is always included
488 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
489
490 // Ensure that indirect stubs dep is not included
491 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
492
493 // Ensure that dependency of stubs is not included
494 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
495
Jiyong Parkda6eb592018-12-19 17:12:36 +0900496 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900497
498 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900499 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900500 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900501 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900502
Jiyong Parkda6eb592018-12-19 17:12:36 +0900503 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900504
505 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
506 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
507}
508
Jiyong Park25fc6a92018-11-18 18:02:45 +0900509func TestApexWithSystemLibsStubs(t *testing.T) {
510 ctx := testApex(t, `
511 apex {
512 name: "myapex",
513 key: "myapex.key",
514 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
515 }
516
517 apex_key {
518 name: "myapex.key",
519 public_key: "testkey.avbpubkey",
520 private_key: "testkey.pem",
521 }
522
523 cc_library {
524 name: "mylib",
525 srcs: ["mylib.cpp"],
526 shared_libs: ["libdl#27"],
527 stl: "none",
528 }
529
530 cc_library_shared {
531 name: "mylib_shared",
532 srcs: ["mylib.cpp"],
533 shared_libs: ["libdl#27"],
534 stl: "none",
535 }
536
537 cc_library {
538 name: "libc",
539 no_libgcc: true,
540 nocrt: true,
541 system_shared_libs: [],
542 stl: "none",
543 stubs: {
544 versions: ["27", "28", "29"],
545 },
546 }
547
548 cc_library {
549 name: "libm",
550 no_libgcc: true,
551 nocrt: true,
552 system_shared_libs: [],
553 stl: "none",
554 stubs: {
555 versions: ["27", "28", "29"],
556 },
557 }
558
559 cc_library {
560 name: "libdl",
561 no_libgcc: true,
562 nocrt: true,
563 system_shared_libs: [],
564 stl: "none",
565 stubs: {
566 versions: ["27", "28", "29"],
567 },
568 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900569
570 cc_library {
571 name: "libBootstrap",
572 srcs: ["mylib.cpp"],
573 stl: "none",
574 bootstrap: true,
575 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900576 `)
577
578 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
579 copyCmds := apexRule.Args["copy_commands"]
580
581 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800582 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900583 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
584 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900585
586 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900587 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900588
Jiyong Parkda6eb592018-12-19 17:12:36 +0900589 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
590 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
591 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900592
593 // For dependency to libc
594 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900595 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900596 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900597 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900598 // ... Cflags from stub is correctly exported to mylib
599 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
600 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
601
602 // For dependency to libm
603 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900604 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900605 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900606 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900607 // ... and is not compiling with the stub
608 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
609 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
610
611 // For dependency to libdl
612 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900613 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900614 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900615 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
616 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900617 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900618 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900619 // ... Cflags from stub is correctly exported to mylib
620 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
621 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900622
623 // Ensure that libBootstrap is depending on the platform variant of bionic libs
624 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
625 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
626 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
627 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900628}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900629
630func TestFilesInSubDir(t *testing.T) {
631 ctx := testApex(t, `
632 apex {
633 name: "myapex",
634 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900635 native_shared_libs: ["mylib"],
636 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900637 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900638 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900639 }
640
641 apex_key {
642 name: "myapex.key",
643 public_key: "testkey.avbpubkey",
644 private_key: "testkey.pem",
645 }
646
647 prebuilt_etc {
648 name: "myetc",
649 src: "myprebuilt",
650 sub_dir: "foo/bar",
651 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900652
653 cc_library {
654 name: "mylib",
655 srcs: ["mylib.cpp"],
656 relative_install_path: "foo/bar",
657 system_shared_libs: [],
658 stl: "none",
659 }
660
661 cc_binary {
662 name: "mybin",
663 srcs: ["mylib.cpp"],
664 relative_install_path: "foo/bar",
665 system_shared_libs: [],
666 static_executable: true,
667 stl: "none",
668 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900669 `)
670
671 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
672 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
673
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900674 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900675 ensureListContains(t, dirs, "etc")
676 ensureListContains(t, dirs, "etc/foo")
677 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900678 ensureListContains(t, dirs, "lib64")
679 ensureListContains(t, dirs, "lib64/foo")
680 ensureListContains(t, dirs, "lib64/foo/bar")
681 ensureListContains(t, dirs, "lib")
682 ensureListContains(t, dirs, "lib/foo")
683 ensureListContains(t, dirs, "lib/foo/bar")
684
685 // TODO(b/123721777) respect relative path for binaries
686 // ensureListContains(t, dirs, "bin")
687 // ensureListContains(t, dirs, "bin/foo")
688 // ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +0900689}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900690
691func TestUseVendor(t *testing.T) {
692 ctx := testApex(t, `
693 apex {
694 name: "myapex",
695 key: "myapex.key",
696 native_shared_libs: ["mylib"],
697 use_vendor: true,
698 }
699
700 apex_key {
701 name: "myapex.key",
702 public_key: "testkey.avbpubkey",
703 private_key: "testkey.pem",
704 }
705
706 cc_library {
707 name: "mylib",
708 srcs: ["mylib.cpp"],
709 shared_libs: ["mylib2"],
710 system_shared_libs: [],
711 vendor_available: true,
712 stl: "none",
713 }
714
715 cc_library {
716 name: "mylib2",
717 srcs: ["mylib.cpp"],
718 system_shared_libs: [],
719 vendor_available: true,
720 stl: "none",
721 }
722 `)
723
724 inputsList := []string{}
725 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
726 for _, implicit := range i.Implicits {
727 inputsList = append(inputsList, implicit.String())
728 }
729 }
730 inputsString := strings.Join(inputsList, " ")
731
732 // ensure that the apex includes vendor variants of the direct and indirect deps
733 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
734 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
735
736 // ensure that the apex does not include core variants
737 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
738 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
739}
Jiyong Park16e91a02018-12-20 18:18:08 +0900740
741func TestStaticLinking(t *testing.T) {
742 ctx := testApex(t, `
743 apex {
744 name: "myapex",
745 key: "myapex.key",
746 native_shared_libs: ["mylib"],
747 }
748
749 apex_key {
750 name: "myapex.key",
751 public_key: "testkey.avbpubkey",
752 private_key: "testkey.pem",
753 }
754
755 cc_library {
756 name: "mylib",
757 srcs: ["mylib.cpp"],
758 system_shared_libs: [],
759 stl: "none",
760 stubs: {
761 versions: ["1", "2", "3"],
762 },
763 }
764
765 cc_binary {
766 name: "not_in_apex",
767 srcs: ["mylib.cpp"],
768 static_libs: ["mylib"],
769 static_executable: true,
770 system_shared_libs: [],
771 stl: "none",
772 }
Jiyong Park16e91a02018-12-20 18:18:08 +0900773 `)
774
775 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
776
777 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800778 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900779}
Jiyong Park9335a262018-12-24 11:31:58 +0900780
781func TestKeys(t *testing.T) {
782 ctx := testApex(t, `
783 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900784 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +0900785 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900786 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +0900787 native_shared_libs: ["mylib"],
788 }
789
790 cc_library {
791 name: "mylib",
792 srcs: ["mylib.cpp"],
793 system_shared_libs: [],
794 stl: "none",
795 }
796
797 apex_key {
798 name: "myapex.key",
799 public_key: "testkey.avbpubkey",
800 private_key: "testkey.pem",
801 }
802
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900803 android_app_certificate {
804 name: "myapex.certificate",
805 certificate: "testkey",
806 }
807
808 android_app_certificate {
809 name: "myapex.certificate.override",
810 certificate: "testkey.override",
811 }
812
Jiyong Park9335a262018-12-24 11:31:58 +0900813 `)
814
815 // check the APEX keys
816 keys := ctx.ModuleForTests("myapex.key", "").Module().(*apexKey)
817
818 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
819 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
820 "vendor/foo/devkeys/testkey.avbpubkey")
821 }
822 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
823 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
824 "vendor/foo/devkeys/testkey.pem")
825 }
826
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900827 // check the APK certs. It should be overridden to myapex.certificate.override
828 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
829 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +0900830 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900831 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +0900832 }
833}
Jiyong Park58e364a2019-01-19 19:24:06 +0900834
835func TestMacro(t *testing.T) {
836 ctx := testApex(t, `
837 apex {
838 name: "myapex",
839 key: "myapex.key",
840 native_shared_libs: ["mylib"],
841 }
842
843 apex {
844 name: "otherapex",
845 key: "myapex.key",
846 native_shared_libs: ["mylib"],
847 }
848
849 apex_key {
850 name: "myapex.key",
851 public_key: "testkey.avbpubkey",
852 private_key: "testkey.pem",
853 }
854
855 cc_library {
856 name: "mylib",
857 srcs: ["mylib.cpp"],
858 system_shared_libs: [],
859 stl: "none",
860 }
861 `)
862
863 // non-APEX variant does not have __ANDROID__APEX__ defined
864 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
865 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
866 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
867
868 // APEX variant has __ANDROID_APEX__=<apexname> defined
869 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
870 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
871 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
872
873 // APEX variant has __ANDROID_APEX__=<apexname> defined
874 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
875 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
876 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
877}
Jiyong Park7e636d02019-01-28 16:16:54 +0900878
879func TestHeaderLibsDependency(t *testing.T) {
880 ctx := testApex(t, `
881 apex {
882 name: "myapex",
883 key: "myapex.key",
884 native_shared_libs: ["mylib"],
885 }
886
887 apex_key {
888 name: "myapex.key",
889 public_key: "testkey.avbpubkey",
890 private_key: "testkey.pem",
891 }
892
893 cc_library_headers {
894 name: "mylib_headers",
895 export_include_dirs: ["my_include"],
896 system_shared_libs: [],
897 stl: "none",
898 }
899
900 cc_library {
901 name: "mylib",
902 srcs: ["mylib.cpp"],
903 system_shared_libs: [],
904 stl: "none",
905 header_libs: ["mylib_headers"],
906 export_header_lib_headers: ["mylib_headers"],
907 stubs: {
908 versions: ["1", "2", "3"],
909 },
910 }
911
912 cc_library {
913 name: "otherlib",
914 srcs: ["mylib.cpp"],
915 system_shared_libs: [],
916 stl: "none",
917 shared_libs: ["mylib"],
918 }
919 `)
920
921 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
922
923 // Ensure that the include path of the header lib is exported to 'otherlib'
924 ensureContains(t, cFlags, "-Imy_include")
925}
Alex Light9670d332019-01-29 18:07:33 -0800926
Alex Light0851b882019-02-07 13:20:53 -0800927func TestNonTestApex(t *testing.T) {
928 ctx := testApex(t, `
929 apex {
930 name: "myapex",
931 key: "myapex.key",
932 native_shared_libs: ["mylib_common"],
933 }
934
935 apex_key {
936 name: "myapex.key",
937 public_key: "testkey.avbpubkey",
938 private_key: "testkey.pem",
939 }
940
941 cc_library {
942 name: "mylib_common",
943 srcs: ["mylib.cpp"],
944 system_shared_libs: [],
945 stl: "none",
946 }
947 `)
948
949 module := ctx.ModuleForTests("myapex", "android_common_myapex")
950 apexRule := module.Rule("apexRule")
951 copyCmds := apexRule.Args["copy_commands"]
952
953 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
954 t.Log("Apex was a test apex!")
955 t.Fail()
956 }
957 // Ensure that main rule creates an output
958 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
959
960 // Ensure that apex variant is created for the direct dep
961 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
962
963 // Ensure that both direct and indirect deps are copied into apex
964 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
965
966 // Ensure that the platform variant ends with _core_shared
967 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
968
969 if !android.InAnyApex("mylib_common") {
970 t.Log("Found mylib_common not in any apex!")
971 t.Fail()
972 }
973}
974
975func TestTestApex(t *testing.T) {
976 if android.InAnyApex("mylib_common_test") {
977 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!")
978 }
979 ctx := testApex(t, `
980 apex_test {
981 name: "myapex",
982 key: "myapex.key",
983 native_shared_libs: ["mylib_common_test"],
984 }
985
986 apex_key {
987 name: "myapex.key",
988 public_key: "testkey.avbpubkey",
989 private_key: "testkey.pem",
990 }
991
992 cc_library {
993 name: "mylib_common_test",
994 srcs: ["mylib.cpp"],
995 system_shared_libs: [],
996 stl: "none",
997 }
998 `)
999
1000 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1001 apexRule := module.Rule("apexRule")
1002 copyCmds := apexRule.Args["copy_commands"]
1003
1004 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1005 t.Log("Apex was not a test apex!")
1006 t.Fail()
1007 }
1008 // Ensure that main rule creates an output
1009 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1010
1011 // Ensure that apex variant is created for the direct dep
1012 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1013
1014 // Ensure that both direct and indirect deps are copied into apex
1015 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1016
1017 // Ensure that the platform variant ends with _core_shared
1018 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1019
1020 if android.InAnyApex("mylib_common_test") {
1021 t.Log("Found mylib_common_test in some apex!")
1022 t.Fail()
1023 }
1024}
1025
Alex Light9670d332019-01-29 18:07:33 -08001026func TestApexWithTarget(t *testing.T) {
1027 ctx := testApex(t, `
1028 apex {
1029 name: "myapex",
1030 key: "myapex.key",
1031 multilib: {
1032 first: {
1033 native_shared_libs: ["mylib_common"],
1034 }
1035 },
1036 target: {
1037 android: {
1038 multilib: {
1039 first: {
1040 native_shared_libs: ["mylib"],
1041 }
1042 }
1043 },
1044 host: {
1045 multilib: {
1046 first: {
1047 native_shared_libs: ["mylib2"],
1048 }
1049 }
1050 }
1051 }
1052 }
1053
1054 apex_key {
1055 name: "myapex.key",
1056 public_key: "testkey.avbpubkey",
1057 private_key: "testkey.pem",
1058 }
1059
1060 cc_library {
1061 name: "mylib",
1062 srcs: ["mylib.cpp"],
1063 system_shared_libs: [],
1064 stl: "none",
1065 }
1066
1067 cc_library {
1068 name: "mylib_common",
1069 srcs: ["mylib.cpp"],
1070 system_shared_libs: [],
1071 stl: "none",
1072 compile_multilib: "first",
1073 }
1074
1075 cc_library {
1076 name: "mylib2",
1077 srcs: ["mylib.cpp"],
1078 system_shared_libs: [],
1079 stl: "none",
1080 compile_multilib: "first",
1081 }
1082 `)
1083
1084 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1085 copyCmds := apexRule.Args["copy_commands"]
1086
1087 // Ensure that main rule creates an output
1088 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1089
1090 // Ensure that apex variant is created for the direct dep
1091 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1092 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1093 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1094
1095 // Ensure that both direct and indirect deps are copied into apex
1096 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1097 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1098 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1099
1100 // Ensure that the platform variant ends with _core_shared
1101 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1102 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1103 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1104}
Jiyong Park04480cf2019-02-06 00:16:29 +09001105
1106func TestApexWithShBinary(t *testing.T) {
1107 ctx := testApex(t, `
1108 apex {
1109 name: "myapex",
1110 key: "myapex.key",
1111 binaries: ["myscript"],
1112 }
1113
1114 apex_key {
1115 name: "myapex.key",
1116 public_key: "testkey.avbpubkey",
1117 private_key: "testkey.pem",
1118 }
1119
1120 sh_binary {
1121 name: "myscript",
1122 src: "mylib.cpp",
1123 filename: "myscript.sh",
1124 sub_dir: "script",
1125 }
1126 `)
1127
1128 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1129 copyCmds := apexRule.Args["copy_commands"]
1130
1131 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1132}