blob: 66f07259023d689dea0e9e18ca2019d920acdbac [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 Park809bb722019-02-13 21:33:49 +090056 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090057 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090058 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090059 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090060 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090061 ctx.BottomUp("version", cc.VersionMutator).Parallel()
62 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
63 })
64
65 ctx.Register()
66
67 bp = bp + `
68 toolchain_library {
69 name: "libcompiler_rt-extras",
70 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090071 vendor_available: true,
72 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090073 }
74
75 toolchain_library {
76 name: "libatomic",
77 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090078 vendor_available: true,
79 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090080 }
81
82 toolchain_library {
83 name: "libgcc",
84 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090085 vendor_available: true,
86 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090087 }
88
89 toolchain_library {
90 name: "libclang_rt.builtins-aarch64-android",
91 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090092 vendor_available: true,
93 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090094 }
95
96 toolchain_library {
97 name: "libclang_rt.builtins-arm-android",
98 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090099 vendor_available: true,
100 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900101 }
102
103 cc_object {
104 name: "crtbegin_so",
105 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900106 vendor_available: true,
107 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900108 }
109
110 cc_object {
111 name: "crtend_so",
112 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900113 vendor_available: true,
114 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900115 }
116
Alex Light3d673592019-01-18 14:37:31 -0800117 cc_object {
118 name: "crtbegin_static",
119 stl: "none",
120 }
121
122 cc_object {
123 name: "crtend_android",
124 stl: "none",
125 }
126
Jiyong Parkda6eb592018-12-19 17:12:36 +0900127 llndk_library {
128 name: "libc",
129 symbol_file: "",
130 }
131
132 llndk_library {
133 name: "libm",
134 symbol_file: "",
135 }
136
137 llndk_library {
138 name: "libdl",
139 symbol_file: "",
140 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900141 `
142
143 ctx.MockFileSystem(map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900144 "Android.bp": []byte(bp),
145 "build/target/product/security": nil,
146 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900147 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900148 "system/sepolicy/apex/myapex-file_contexts": nil,
149 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
150 "system/sepolicy/apex/otherapex-file_contexts": nil,
151 "mylib.cpp": nil,
152 "myprebuilt": nil,
153 "my_include": nil,
154 "vendor/foo/devkeys/test.x509.pem": nil,
155 "vendor/foo/devkeys/test.pk8": nil,
156 "testkey.x509.pem": nil,
157 "testkey.pk8": nil,
158 "testkey.override.x509.pem": nil,
159 "testkey.override.pk8": nil,
160 "vendor/foo/devkeys/testkey.avbpubkey": nil,
161 "vendor/foo/devkeys/testkey.pem": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900162 })
163 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
164 android.FailIfErrored(t, errs)
165 _, errs = ctx.PrepareBuildActions(config)
166 android.FailIfErrored(t, errs)
167
168 return ctx
169}
170
171func setup(t *testing.T) (config android.Config, buildDir string) {
172 buildDir, err := ioutil.TempDir("", "soong_apex_test")
173 if err != nil {
174 t.Fatal(err)
175 }
176
177 config = android.TestArchConfig(buildDir, nil)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900178 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Park9335a262018-12-24 11:31:58 +0900179 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900180 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
Jiyong Park25fc6a92018-11-18 18:02:45 +0900181 return
182}
183
184func teardown(buildDir string) {
185 os.RemoveAll(buildDir)
186}
187
188// ensure that 'result' contains 'expected'
189func ensureContains(t *testing.T, result string, expected string) {
190 if !strings.Contains(result, expected) {
191 t.Errorf("%q is not found in %q", expected, result)
192 }
193}
194
195// ensures that 'result' does not contain 'notExpected'
196func ensureNotContains(t *testing.T, result string, notExpected string) {
197 if strings.Contains(result, notExpected) {
198 t.Errorf("%q is found in %q", notExpected, result)
199 }
200}
201
202func ensureListContains(t *testing.T, result []string, expected string) {
203 if !android.InList(expected, result) {
204 t.Errorf("%q is not found in %v", expected, result)
205 }
206}
207
208func ensureListNotContains(t *testing.T, result []string, notExpected string) {
209 if android.InList(notExpected, result) {
210 t.Errorf("%q is found in %v", notExpected, result)
211 }
212}
213
214// Minimal test
215func TestBasicApex(t *testing.T) {
216 ctx := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900217 apex_defaults {
218 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900219 manifest: ":myapex.manifest",
220 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900221 key: "myapex.key",
222 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800223 multilib: {
224 both: {
225 binaries: ["foo",],
226 }
227 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900228 }
229
Jiyong Park30ca9372019-02-07 16:27:23 +0900230 apex {
231 name: "myapex",
232 defaults: ["myapex-defaults"],
233 }
234
Jiyong Park25fc6a92018-11-18 18:02:45 +0900235 apex_key {
236 name: "myapex.key",
237 public_key: "testkey.avbpubkey",
238 private_key: "testkey.pem",
239 }
240
Jiyong Park809bb722019-02-13 21:33:49 +0900241 filegroup {
242 name: "myapex.manifest",
243 srcs: ["apex_manifest.json"],
244 }
245
246 filegroup {
247 name: "myapex.androidmanifest",
248 srcs: ["AndroidManifest.xml"],
249 }
250
Jiyong Park25fc6a92018-11-18 18:02:45 +0900251 cc_library {
252 name: "mylib",
253 srcs: ["mylib.cpp"],
254 shared_libs: ["mylib2"],
255 system_shared_libs: [],
256 stl: "none",
257 }
258
Alex Light3d673592019-01-18 14:37:31 -0800259 cc_binary {
260 name: "foo",
261 srcs: ["mylib.cpp"],
262 compile_multilib: "both",
263 multilib: {
264 lib32: {
265 suffix: "32",
266 },
267 lib64: {
268 suffix: "64",
269 },
270 },
271 symlinks: ["foo_link_"],
272 symlink_preferred_arch: true,
273 system_shared_libs: [],
274 static_executable: true,
275 stl: "none",
276 }
277
Jiyong Park25fc6a92018-11-18 18:02:45 +0900278 cc_library {
279 name: "mylib2",
280 srcs: ["mylib.cpp"],
281 system_shared_libs: [],
282 stl: "none",
283 }
284 `)
285
286 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
287 copyCmds := apexRule.Args["copy_commands"]
288
289 // Ensure that main rule creates an output
290 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
291
292 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900293 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900294
295 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900296 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900297
298 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800299 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
300 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Logan Chien3aeedc92018-12-26 15:32:21 +0800301
302 // Ensure that the platform variant ends with _core_shared
303 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
304 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Alex Light3d673592019-01-18 14:37:31 -0800305
306 // Ensure that all symlinks are present.
307 found_foo_link_64 := false
308 found_foo := false
309 for _, cmd := range strings.Split(copyCmds, " && ") {
310 if strings.HasPrefix(cmd, "ln -s foo64") {
311 if strings.HasSuffix(cmd, "bin/foo") {
312 found_foo = true
313 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
314 found_foo_link_64 = true
315 }
316 }
317 }
318 good := found_foo && found_foo_link_64
319 if !good {
320 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
321 }
Alex Light5098a612018-11-29 17:12:15 -0800322}
323
324func TestBasicZipApex(t *testing.T) {
325 ctx := testApex(t, `
326 apex {
327 name: "myapex",
328 key: "myapex.key",
329 payload_type: "zip",
330 native_shared_libs: ["mylib"],
331 }
332
333 apex_key {
334 name: "myapex.key",
335 public_key: "testkey.avbpubkey",
336 private_key: "testkey.pem",
337 }
338
339 cc_library {
340 name: "mylib",
341 srcs: ["mylib.cpp"],
342 shared_libs: ["mylib2"],
343 system_shared_libs: [],
344 stl: "none",
345 }
346
347 cc_library {
348 name: "mylib2",
349 srcs: ["mylib.cpp"],
350 system_shared_libs: [],
351 stl: "none",
352 }
353 `)
354
355 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
356 copyCmds := zipApexRule.Args["copy_commands"]
357
358 // Ensure that main rule creates an output
359 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
360
361 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900362 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800363
364 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900365 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800366
367 // Ensure that both direct and indirect deps are copied into apex
368 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
369 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900370}
371
372func TestApexWithStubs(t *testing.T) {
373 ctx := testApex(t, `
374 apex {
375 name: "myapex",
376 key: "myapex.key",
377 native_shared_libs: ["mylib", "mylib3"],
378 }
379
380 apex_key {
381 name: "myapex.key",
382 public_key: "testkey.avbpubkey",
383 private_key: "testkey.pem",
384 }
385
386 cc_library {
387 name: "mylib",
388 srcs: ["mylib.cpp"],
389 shared_libs: ["mylib2", "mylib3"],
390 system_shared_libs: [],
391 stl: "none",
392 }
393
394 cc_library {
395 name: "mylib2",
396 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900397 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900398 system_shared_libs: [],
399 stl: "none",
400 stubs: {
401 versions: ["1", "2", "3"],
402 },
403 }
404
405 cc_library {
406 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900407 srcs: ["mylib.cpp"],
408 shared_libs: ["mylib4"],
409 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900410 stl: "none",
411 stubs: {
412 versions: ["10", "11", "12"],
413 },
414 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900415
416 cc_library {
417 name: "mylib4",
418 srcs: ["mylib.cpp"],
419 system_shared_libs: [],
420 stl: "none",
421 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900422 `)
423
424 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
425 copyCmds := apexRule.Args["copy_commands"]
426
427 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800428 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900429
430 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800431 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900432
433 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800434 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900435
Jiyong Parkda6eb592018-12-19 17:12:36 +0900436 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900437
438 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900439 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900440 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900441 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900442
443 // 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 +0900444 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900445 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900446 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900447
448 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900449 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900450 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900451
452 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900453 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 +0900454}
455
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900456func TestApexWithExplicitStubsDependency(t *testing.T) {
457 ctx := testApex(t, `
458 apex {
459 name: "myapex",
460 key: "myapex.key",
461 native_shared_libs: ["mylib"],
462 }
463
464 apex_key {
465 name: "myapex.key",
466 public_key: "testkey.avbpubkey",
467 private_key: "testkey.pem",
468 }
469
470 cc_library {
471 name: "mylib",
472 srcs: ["mylib.cpp"],
473 shared_libs: ["libfoo#10"],
474 system_shared_libs: [],
475 stl: "none",
476 }
477
478 cc_library {
479 name: "libfoo",
480 srcs: ["mylib.cpp"],
481 shared_libs: ["libbar"],
482 system_shared_libs: [],
483 stl: "none",
484 stubs: {
485 versions: ["10", "20", "30"],
486 },
487 }
488
489 cc_library {
490 name: "libbar",
491 srcs: ["mylib.cpp"],
492 system_shared_libs: [],
493 stl: "none",
494 }
495
496 `)
497
498 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
499 copyCmds := apexRule.Args["copy_commands"]
500
501 // Ensure that direct non-stubs dep is always included
502 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
503
504 // Ensure that indirect stubs dep is not included
505 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
506
507 // Ensure that dependency of stubs is not included
508 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
509
Jiyong Parkda6eb592018-12-19 17:12:36 +0900510 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900511
512 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900513 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900514 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900515 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900516
Jiyong Parkda6eb592018-12-19 17:12:36 +0900517 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900518
519 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
520 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
521}
522
Jiyong Park25fc6a92018-11-18 18:02:45 +0900523func TestApexWithSystemLibsStubs(t *testing.T) {
524 ctx := testApex(t, `
525 apex {
526 name: "myapex",
527 key: "myapex.key",
528 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
529 }
530
531 apex_key {
532 name: "myapex.key",
533 public_key: "testkey.avbpubkey",
534 private_key: "testkey.pem",
535 }
536
537 cc_library {
538 name: "mylib",
539 srcs: ["mylib.cpp"],
540 shared_libs: ["libdl#27"],
541 stl: "none",
542 }
543
544 cc_library_shared {
545 name: "mylib_shared",
546 srcs: ["mylib.cpp"],
547 shared_libs: ["libdl#27"],
548 stl: "none",
549 }
550
551 cc_library {
552 name: "libc",
553 no_libgcc: true,
554 nocrt: true,
555 system_shared_libs: [],
556 stl: "none",
557 stubs: {
558 versions: ["27", "28", "29"],
559 },
560 }
561
562 cc_library {
563 name: "libm",
564 no_libgcc: true,
565 nocrt: true,
566 system_shared_libs: [],
567 stl: "none",
568 stubs: {
569 versions: ["27", "28", "29"],
570 },
571 }
572
573 cc_library {
574 name: "libdl",
575 no_libgcc: true,
576 nocrt: true,
577 system_shared_libs: [],
578 stl: "none",
579 stubs: {
580 versions: ["27", "28", "29"],
581 },
582 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900583
584 cc_library {
585 name: "libBootstrap",
586 srcs: ["mylib.cpp"],
587 stl: "none",
588 bootstrap: true,
589 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900590 `)
591
592 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
593 copyCmds := apexRule.Args["copy_commands"]
594
595 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800596 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900597 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
598 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900599
600 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900601 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900602
Jiyong Parkda6eb592018-12-19 17:12:36 +0900603 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
604 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
605 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900606
607 // For dependency to libc
608 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900609 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900610 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900611 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900612 // ... Cflags from stub is correctly exported to mylib
613 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
614 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
615
616 // For dependency to libm
617 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900618 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900619 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900620 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900621 // ... and is not compiling with the stub
622 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
623 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
624
625 // For dependency to libdl
626 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900627 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900628 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900629 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
630 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900631 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900632 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900633 // ... Cflags from stub is correctly exported to mylib
634 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
635 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900636
637 // Ensure that libBootstrap is depending on the platform variant of bionic libs
638 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
639 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
640 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
641 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900642}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900643
644func TestFilesInSubDir(t *testing.T) {
645 ctx := testApex(t, `
646 apex {
647 name: "myapex",
648 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900649 native_shared_libs: ["mylib"],
650 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900651 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900652 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900653 }
654
655 apex_key {
656 name: "myapex.key",
657 public_key: "testkey.avbpubkey",
658 private_key: "testkey.pem",
659 }
660
661 prebuilt_etc {
662 name: "myetc",
663 src: "myprebuilt",
664 sub_dir: "foo/bar",
665 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900666
667 cc_library {
668 name: "mylib",
669 srcs: ["mylib.cpp"],
670 relative_install_path: "foo/bar",
671 system_shared_libs: [],
672 stl: "none",
673 }
674
675 cc_binary {
676 name: "mybin",
677 srcs: ["mylib.cpp"],
678 relative_install_path: "foo/bar",
679 system_shared_libs: [],
680 static_executable: true,
681 stl: "none",
682 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900683 `)
684
685 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
686 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
687
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900688 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900689 ensureListContains(t, dirs, "etc")
690 ensureListContains(t, dirs, "etc/foo")
691 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900692 ensureListContains(t, dirs, "lib64")
693 ensureListContains(t, dirs, "lib64/foo")
694 ensureListContains(t, dirs, "lib64/foo/bar")
695 ensureListContains(t, dirs, "lib")
696 ensureListContains(t, dirs, "lib/foo")
697 ensureListContains(t, dirs, "lib/foo/bar")
698
699 // TODO(b/123721777) respect relative path for binaries
700 // ensureListContains(t, dirs, "bin")
701 // ensureListContains(t, dirs, "bin/foo")
702 // ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +0900703}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900704
705func TestUseVendor(t *testing.T) {
706 ctx := testApex(t, `
707 apex {
708 name: "myapex",
709 key: "myapex.key",
710 native_shared_libs: ["mylib"],
711 use_vendor: true,
712 }
713
714 apex_key {
715 name: "myapex.key",
716 public_key: "testkey.avbpubkey",
717 private_key: "testkey.pem",
718 }
719
720 cc_library {
721 name: "mylib",
722 srcs: ["mylib.cpp"],
723 shared_libs: ["mylib2"],
724 system_shared_libs: [],
725 vendor_available: true,
726 stl: "none",
727 }
728
729 cc_library {
730 name: "mylib2",
731 srcs: ["mylib.cpp"],
732 system_shared_libs: [],
733 vendor_available: true,
734 stl: "none",
735 }
736 `)
737
738 inputsList := []string{}
739 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
740 for _, implicit := range i.Implicits {
741 inputsList = append(inputsList, implicit.String())
742 }
743 }
744 inputsString := strings.Join(inputsList, " ")
745
746 // ensure that the apex includes vendor variants of the direct and indirect deps
747 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
748 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
749
750 // ensure that the apex does not include core variants
751 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
752 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
753}
Jiyong Park16e91a02018-12-20 18:18:08 +0900754
755func TestStaticLinking(t *testing.T) {
756 ctx := testApex(t, `
757 apex {
758 name: "myapex",
759 key: "myapex.key",
760 native_shared_libs: ["mylib"],
761 }
762
763 apex_key {
764 name: "myapex.key",
765 public_key: "testkey.avbpubkey",
766 private_key: "testkey.pem",
767 }
768
769 cc_library {
770 name: "mylib",
771 srcs: ["mylib.cpp"],
772 system_shared_libs: [],
773 stl: "none",
774 stubs: {
775 versions: ["1", "2", "3"],
776 },
777 }
778
779 cc_binary {
780 name: "not_in_apex",
781 srcs: ["mylib.cpp"],
782 static_libs: ["mylib"],
783 static_executable: true,
784 system_shared_libs: [],
785 stl: "none",
786 }
Jiyong Park16e91a02018-12-20 18:18:08 +0900787 `)
788
789 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
790
791 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800792 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900793}
Jiyong Park9335a262018-12-24 11:31:58 +0900794
795func TestKeys(t *testing.T) {
796 ctx := testApex(t, `
797 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900798 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +0900799 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900800 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +0900801 native_shared_libs: ["mylib"],
802 }
803
804 cc_library {
805 name: "mylib",
806 srcs: ["mylib.cpp"],
807 system_shared_libs: [],
808 stl: "none",
809 }
810
811 apex_key {
812 name: "myapex.key",
813 public_key: "testkey.avbpubkey",
814 private_key: "testkey.pem",
815 }
816
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900817 android_app_certificate {
818 name: "myapex.certificate",
819 certificate: "testkey",
820 }
821
822 android_app_certificate {
823 name: "myapex.certificate.override",
824 certificate: "testkey.override",
825 }
826
Jiyong Park9335a262018-12-24 11:31:58 +0900827 `)
828
829 // check the APEX keys
830 keys := ctx.ModuleForTests("myapex.key", "").Module().(*apexKey)
831
832 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
833 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
834 "vendor/foo/devkeys/testkey.avbpubkey")
835 }
836 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
837 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
838 "vendor/foo/devkeys/testkey.pem")
839 }
840
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900841 // check the APK certs. It should be overridden to myapex.certificate.override
842 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
843 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +0900844 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900845 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +0900846 }
847}
Jiyong Park58e364a2019-01-19 19:24:06 +0900848
849func TestMacro(t *testing.T) {
850 ctx := testApex(t, `
851 apex {
852 name: "myapex",
853 key: "myapex.key",
854 native_shared_libs: ["mylib"],
855 }
856
857 apex {
858 name: "otherapex",
859 key: "myapex.key",
860 native_shared_libs: ["mylib"],
861 }
862
863 apex_key {
864 name: "myapex.key",
865 public_key: "testkey.avbpubkey",
866 private_key: "testkey.pem",
867 }
868
869 cc_library {
870 name: "mylib",
871 srcs: ["mylib.cpp"],
872 system_shared_libs: [],
873 stl: "none",
874 }
875 `)
876
877 // non-APEX variant does not have __ANDROID__APEX__ defined
878 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
879 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
880 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
881
882 // APEX variant has __ANDROID_APEX__=<apexname> defined
883 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
884 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
885 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
886
887 // APEX variant has __ANDROID_APEX__=<apexname> defined
888 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
889 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
890 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
891}
Jiyong Park7e636d02019-01-28 16:16:54 +0900892
893func TestHeaderLibsDependency(t *testing.T) {
894 ctx := testApex(t, `
895 apex {
896 name: "myapex",
897 key: "myapex.key",
898 native_shared_libs: ["mylib"],
899 }
900
901 apex_key {
902 name: "myapex.key",
903 public_key: "testkey.avbpubkey",
904 private_key: "testkey.pem",
905 }
906
907 cc_library_headers {
908 name: "mylib_headers",
909 export_include_dirs: ["my_include"],
910 system_shared_libs: [],
911 stl: "none",
912 }
913
914 cc_library {
915 name: "mylib",
916 srcs: ["mylib.cpp"],
917 system_shared_libs: [],
918 stl: "none",
919 header_libs: ["mylib_headers"],
920 export_header_lib_headers: ["mylib_headers"],
921 stubs: {
922 versions: ["1", "2", "3"],
923 },
924 }
925
926 cc_library {
927 name: "otherlib",
928 srcs: ["mylib.cpp"],
929 system_shared_libs: [],
930 stl: "none",
931 shared_libs: ["mylib"],
932 }
933 `)
934
935 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
936
937 // Ensure that the include path of the header lib is exported to 'otherlib'
938 ensureContains(t, cFlags, "-Imy_include")
939}
Alex Light9670d332019-01-29 18:07:33 -0800940
Alex Light0851b882019-02-07 13:20:53 -0800941func TestNonTestApex(t *testing.T) {
942 ctx := testApex(t, `
943 apex {
944 name: "myapex",
945 key: "myapex.key",
946 native_shared_libs: ["mylib_common"],
947 }
948
949 apex_key {
950 name: "myapex.key",
951 public_key: "testkey.avbpubkey",
952 private_key: "testkey.pem",
953 }
954
955 cc_library {
956 name: "mylib_common",
957 srcs: ["mylib.cpp"],
958 system_shared_libs: [],
959 stl: "none",
960 }
961 `)
962
963 module := ctx.ModuleForTests("myapex", "android_common_myapex")
964 apexRule := module.Rule("apexRule")
965 copyCmds := apexRule.Args["copy_commands"]
966
967 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
968 t.Log("Apex was a test apex!")
969 t.Fail()
970 }
971 // Ensure that main rule creates an output
972 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
973
974 // Ensure that apex variant is created for the direct dep
975 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
976
977 // Ensure that both direct and indirect deps are copied into apex
978 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
979
980 // Ensure that the platform variant ends with _core_shared
981 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
982
983 if !android.InAnyApex("mylib_common") {
984 t.Log("Found mylib_common not in any apex!")
985 t.Fail()
986 }
987}
988
989func TestTestApex(t *testing.T) {
990 if android.InAnyApex("mylib_common_test") {
991 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!")
992 }
993 ctx := testApex(t, `
994 apex_test {
995 name: "myapex",
996 key: "myapex.key",
997 native_shared_libs: ["mylib_common_test"],
998 }
999
1000 apex_key {
1001 name: "myapex.key",
1002 public_key: "testkey.avbpubkey",
1003 private_key: "testkey.pem",
1004 }
1005
1006 cc_library {
1007 name: "mylib_common_test",
1008 srcs: ["mylib.cpp"],
1009 system_shared_libs: [],
1010 stl: "none",
1011 }
1012 `)
1013
1014 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1015 apexRule := module.Rule("apexRule")
1016 copyCmds := apexRule.Args["copy_commands"]
1017
1018 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1019 t.Log("Apex was not a test apex!")
1020 t.Fail()
1021 }
1022 // Ensure that main rule creates an output
1023 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1024
1025 // Ensure that apex variant is created for the direct dep
1026 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1027
1028 // Ensure that both direct and indirect deps are copied into apex
1029 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1030
1031 // Ensure that the platform variant ends with _core_shared
1032 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1033
1034 if android.InAnyApex("mylib_common_test") {
1035 t.Log("Found mylib_common_test in some apex!")
1036 t.Fail()
1037 }
1038}
1039
Alex Light9670d332019-01-29 18:07:33 -08001040func TestApexWithTarget(t *testing.T) {
1041 ctx := testApex(t, `
1042 apex {
1043 name: "myapex",
1044 key: "myapex.key",
1045 multilib: {
1046 first: {
1047 native_shared_libs: ["mylib_common"],
1048 }
1049 },
1050 target: {
1051 android: {
1052 multilib: {
1053 first: {
1054 native_shared_libs: ["mylib"],
1055 }
1056 }
1057 },
1058 host: {
1059 multilib: {
1060 first: {
1061 native_shared_libs: ["mylib2"],
1062 }
1063 }
1064 }
1065 }
1066 }
1067
1068 apex_key {
1069 name: "myapex.key",
1070 public_key: "testkey.avbpubkey",
1071 private_key: "testkey.pem",
1072 }
1073
1074 cc_library {
1075 name: "mylib",
1076 srcs: ["mylib.cpp"],
1077 system_shared_libs: [],
1078 stl: "none",
1079 }
1080
1081 cc_library {
1082 name: "mylib_common",
1083 srcs: ["mylib.cpp"],
1084 system_shared_libs: [],
1085 stl: "none",
1086 compile_multilib: "first",
1087 }
1088
1089 cc_library {
1090 name: "mylib2",
1091 srcs: ["mylib.cpp"],
1092 system_shared_libs: [],
1093 stl: "none",
1094 compile_multilib: "first",
1095 }
1096 `)
1097
1098 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1099 copyCmds := apexRule.Args["copy_commands"]
1100
1101 // Ensure that main rule creates an output
1102 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1103
1104 // Ensure that apex variant is created for the direct dep
1105 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1106 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1107 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1108
1109 // Ensure that both direct and indirect deps are copied into apex
1110 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1111 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1112 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1113
1114 // Ensure that the platform variant ends with _core_shared
1115 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1116 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1117 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1118}
Jiyong Park04480cf2019-02-06 00:16:29 +09001119
1120func TestApexWithShBinary(t *testing.T) {
1121 ctx := testApex(t, `
1122 apex {
1123 name: "myapex",
1124 key: "myapex.key",
1125 binaries: ["myscript"],
1126 }
1127
1128 apex_key {
1129 name: "myapex.key",
1130 public_key: "testkey.avbpubkey",
1131 private_key: "testkey.pem",
1132 }
1133
1134 sh_binary {
1135 name: "myscript",
1136 src: "mylib.cpp",
1137 filename: "myscript.sh",
1138 sub_dir: "script",
1139 }
1140 `)
1141
1142 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1143 copyCmds := apexRule.Args["copy_commands"]
1144
1145 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1146}