blob: 0a4e16d9d74da604f121be12ad49fa2ad9144422 [file] [log] [blame]
Paul Duffina80fdec2019-12-03 15:25:00 +00001// Copyright (C) 2019 The Android Open Source Project
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 sdk
16
17import (
18 "testing"
19
Paul Duffinb0cbec32020-02-25 19:26:33 +000020 "android/soong/android"
Paul Duffina80fdec2019-12-03 15:25:00 +000021 "android/soong/cc"
22)
23
Paul Duffind835daa2019-11-30 17:49:09 +000024func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
25 t.Helper()
26
27 fs := map[string][]byte{
Paul Duffin9b358d72020-03-02 10:16:35 +000028 "Test.cpp": nil,
29 "include/Test.h": nil,
30 "include-android/AndroidTest.h": nil,
31 "include-host/HostTest.h": nil,
32 "arm64/include/Arm64Test.h": nil,
33 "libfoo.so": nil,
34 "aidl/foo/bar/Test.aidl": nil,
Paul Duffind835daa2019-11-30 17:49:09 +000035 }
36 return testSdkWithFs(t, bp, fs)
37}
38
Paul Duffina80fdec2019-12-03 15:25:00 +000039// Contains tests for SDK members provided by the cc package.
40
41func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000042 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000043 sdk {
44 name: "mysdk",
45 native_shared_libs: ["sdkmember"],
46 }
47
48 cc_library_shared {
49 name: "sdkmember",
50 srcs: ["Test.cpp"],
51 system_shared_libs: [],
52 stl: "none",
53 }
54 `)
55
Colin Cross7113d202019-11-20 16:39:12 -080056 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
57 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
Paul Duffina80fdec2019-12-03 15:25:00 +000058
59 var inputs []string
Paul Duffinb0cbec32020-02-25 19:26:33 +000060 buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
Paul Duffina80fdec2019-12-03 15:25:00 +000061 for _, bp := range buildParams {
62 if bp.Input != nil {
63 inputs = append(inputs, bp.Input.String())
64 }
65 }
66
67 // ensure that both 32/64 outputs are inputs of the sdk snapshot
68 ensureListContains(t, inputs, armOutput.String())
69 ensureListContains(t, inputs, arm64Output.String())
70}
71
72func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000073 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000074 sdk {
75 name: "mysdk",
76 native_shared_libs: ["sdkmember"],
77 }
78
Paul Duffina0843f62019-12-13 19:50:38 +000079 cc_library_shared {
80 name: "sdkmember",
Colin Crossf9aabd72020-02-15 11:29:50 -080081 system_shared_libs: [],
Paul Duffina0843f62019-12-13 19:50:38 +000082 }
83
Paul Duffina80fdec2019-12-03 15:25:00 +000084 sdk_snapshot {
85 name: "mysdk@1",
86 native_shared_libs: ["sdkmember_mysdk_1"],
87 }
88
89 sdk_snapshot {
90 name: "mysdk@2",
91 native_shared_libs: ["sdkmember_mysdk_2"],
92 }
93
94 cc_prebuilt_library_shared {
95 name: "sdkmember",
96 srcs: ["libfoo.so"],
97 prefer: false,
98 system_shared_libs: [],
99 stl: "none",
100 }
101
102 cc_prebuilt_library_shared {
103 name: "sdkmember_mysdk_1",
104 sdk_member_name: "sdkmember",
105 srcs: ["libfoo.so"],
106 system_shared_libs: [],
107 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000108 // TODO: remove //apex_available:platform
109 apex_available: [
110 "//apex_available:platform",
111 "myapex",
112 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000113 }
114
115 cc_prebuilt_library_shared {
116 name: "sdkmember_mysdk_2",
117 sdk_member_name: "sdkmember",
118 srcs: ["libfoo.so"],
119 system_shared_libs: [],
120 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000121 // TODO: remove //apex_available:platform
122 apex_available: [
123 "//apex_available:platform",
124 "myapex2",
125 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000126 }
127
128 cc_library_shared {
129 name: "mycpplib",
130 srcs: ["Test.cpp"],
131 shared_libs: ["sdkmember"],
132 system_shared_libs: [],
133 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 apex_available: [
135 "myapex",
136 "myapex2",
137 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000138 }
139
140 apex {
141 name: "myapex",
142 native_shared_libs: ["mycpplib"],
143 uses_sdks: ["mysdk@1"],
144 key: "myapex.key",
145 certificate: ":myapex.cert",
146 }
147
148 apex {
149 name: "myapex2",
150 native_shared_libs: ["mycpplib"],
151 uses_sdks: ["mysdk@2"],
152 key: "myapex.key",
153 certificate: ":myapex.cert",
154 }
155 `)
156
Colin Cross7113d202019-11-20 16:39:12 -0800157 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_myapex").Rule("toc").Output
158 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_myapex2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000159
Colin Cross7113d202019-11-20 16:39:12 -0800160 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
161 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000162
163 // Depending on the uses_sdks value, different libs are linked
164 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
165 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
166}
167
Paul Duffina0843f62019-12-13 19:50:38 +0000168// Make sure the sdk can use host specific cc libraries static/shared and both.
169func TestHostSdkWithCc(t *testing.T) {
170 testSdkWithCc(t, `
171 sdk {
172 name: "mysdk",
173 device_supported: false,
174 host_supported: true,
175 native_shared_libs: ["sdkshared"],
176 native_static_libs: ["sdkstatic"],
177 }
178
179 cc_library_host_shared {
180 name: "sdkshared",
181 system_shared_libs: [],
182 stl: "none",
183 }
184
185 cc_library_host_static {
186 name: "sdkstatic",
187 system_shared_libs: [],
188 stl: "none",
189 }
190 `)
191}
192
193// Make sure the sdk can use cc libraries static/shared and both.
194func TestSdkWithCc(t *testing.T) {
195 testSdkWithCc(t, `
196 sdk {
197 name: "mysdk",
198 native_shared_libs: ["sdkshared", "sdkboth1"],
199 native_static_libs: ["sdkstatic", "sdkboth2"],
200 }
201
202 cc_library_shared {
203 name: "sdkshared",
204 system_shared_libs: [],
205 stl: "none",
206 }
207
208 cc_library_static {
209 name: "sdkstatic",
210 system_shared_libs: [],
211 stl: "none",
212 }
213
214 cc_library {
215 name: "sdkboth1",
216 system_shared_libs: [],
217 stl: "none",
218 }
219
220 cc_library {
221 name: "sdkboth2",
222 system_shared_libs: [],
223 stl: "none",
224 }
225 `)
226}
227
Paul Duffinc62a5102019-12-11 18:34:15 +0000228func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
229 result := testSdkWithCc(t, `
230 sdk {
231 name: "mysdk",
232 native_shared_libs: ["mynativelib1", "mynativelib2"],
233 }
234
235 cc_library_shared {
236 name: "mynativelib1",
237 srcs: [
238 "Test.cpp",
239 ],
240 export_include_dirs: ["include"],
241 system_shared_libs: [],
242 stl: "none",
243 }
244
245 cc_library_shared {
246 name: "mynativelib2",
247 srcs: [
248 "Test.cpp",
249 ],
250 export_include_dirs: ["include"],
251 system_shared_libs: [],
252 stl: "none",
253 }
254 `)
255
Paul Duffinb0cbec32020-02-25 19:26:33 +0000256 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000257 checkAllCopyRules(`
258include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800259.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
260.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
261.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
262.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000263`),
264 )
265}
266
Paul Duffina7cd8c82019-12-11 20:00:57 +0000267// Verify that when the shared library has some common and some arch specific properties that the generated
268// snapshot is optimized properly.
269func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
270 result := testSdkWithCc(t, `
271 sdk {
272 name: "mysdk",
273 native_shared_libs: ["mynativelib"],
274 }
275
276 cc_library_shared {
277 name: "mynativelib",
278 srcs: [
279 "Test.cpp",
280 "aidl/foo/bar/Test.aidl",
281 ],
282 export_include_dirs: ["include"],
283 arch: {
284 arm64: {
285 export_system_include_dirs: ["arm64/include"],
286 },
287 },
288 system_shared_libs: [],
289 stl: "none",
290 }
291 `)
292
Paul Duffinb0cbec32020-02-25 19:26:33 +0000293 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000294 checkAndroidBpContents(`
295// This is auto-generated. DO NOT EDIT.
296
297cc_prebuilt_library_shared {
298 name: "mysdk_mynativelib@current",
299 sdk_member_name: "mynativelib",
Paul Duffinf51768a2020-03-04 14:52:46 +0000300 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000301 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000302 export_include_dirs: ["include/include"],
303 arch: {
304 arm64: {
305 srcs: ["arm64/lib/mynativelib.so"],
306 export_system_include_dirs: ["arm64/include/arm64/include"],
307 },
308 arm: {
309 srcs: ["arm/lib/mynativelib.so"],
310 },
311 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000312}
313
314cc_prebuilt_library_shared {
315 name: "mynativelib",
316 prefer: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000317 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000318 export_include_dirs: ["include/include"],
319 arch: {
320 arm64: {
321 srcs: ["arm64/lib/mynativelib.so"],
322 export_system_include_dirs: ["arm64/include/arm64/include"],
323 },
324 arm: {
325 srcs: ["arm/lib/mynativelib.so"],
326 },
327 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000328}
329
330sdk_snapshot {
331 name: "mysdk@current",
332 native_shared_libs: ["mysdk_mynativelib@current"],
333}
334`),
335 checkAllCopyRules(`
336include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800337.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000338arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800339.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000340 )
341}
342
Paul Duffin25ce04b2020-01-16 11:47:25 +0000343func TestSnapshotWithCcBinary(t *testing.T) {
344 result := testSdkWithCc(t, `
345 module_exports {
346 name: "mymodule_exports",
347 native_binaries: ["mynativebinary"],
348 }
349
350 cc_binary {
351 name: "mynativebinary",
352 srcs: [
353 "Test.cpp",
354 ],
355 compile_multilib: "both",
356 system_shared_libs: [],
357 stl: "none",
358 }
359 `)
360
Paul Duffinb0cbec32020-02-25 19:26:33 +0000361 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000362 checkAndroidBpContents(`
363// This is auto-generated. DO NOT EDIT.
364
365cc_prebuilt_binary {
366 name: "mymodule_exports_mynativebinary@current",
367 sdk_member_name: "mynativebinary",
Paul Duffinf51768a2020-03-04 14:52:46 +0000368 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000369 compile_multilib: "both",
370 arch: {
371 arm64: {
372 srcs: ["arm64/bin/mynativebinary"],
373 },
374 arm: {
375 srcs: ["arm/bin/mynativebinary"],
376 },
377 },
378}
379
380cc_prebuilt_binary {
381 name: "mynativebinary",
382 prefer: false,
383 compile_multilib: "both",
384 arch: {
385 arm64: {
386 srcs: ["arm64/bin/mynativebinary"],
387 },
388 arm: {
389 srcs: ["arm/bin/mynativebinary"],
390 },
391 },
392}
393
394module_exports_snapshot {
395 name: "mymodule_exports@current",
396 native_binaries: ["mymodule_exports_mynativebinary@current"],
397}
398`),
399 checkAllCopyRules(`
400.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
401.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
402`),
403 )
404}
405
Paul Duffin9b358d72020-03-02 10:16:35 +0000406func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
407 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
408 SkipIfNotLinux(t)
409
410 result := testSdkWithCc(t, `
411 module_exports {
412 name: "myexports",
413 device_supported: false,
414 host_supported: true,
415 native_binaries: ["mynativebinary"],
416 target: {
417 windows: {
418 enabled: true,
419 },
420 },
421 }
422
423 cc_binary {
424 name: "mynativebinary",
425 device_supported: false,
426 host_supported: true,
427 srcs: [
428 "Test.cpp",
429 ],
430 compile_multilib: "both",
431 system_shared_libs: [],
432 stl: "none",
433 target: {
434 windows: {
435 enabled: true,
436 },
437 },
438 }
439 `)
440
441 result.CheckSnapshot("myexports", "",
442 checkAndroidBpContents(`
443// This is auto-generated. DO NOT EDIT.
444
445cc_prebuilt_binary {
446 name: "myexports_mynativebinary@current",
447 sdk_member_name: "mynativebinary",
448 device_supported: false,
449 host_supported: true,
Paul Duffinf51768a2020-03-04 14:52:46 +0000450 installable: false,
Paul Duffin9b358d72020-03-02 10:16:35 +0000451 target: {
452 linux_glibc: {
453 compile_multilib: "both",
454 },
455 linux_glibc_x86_64: {
456 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
457 },
458 linux_glibc_x86: {
459 srcs: ["linux_glibc/x86/bin/mynativebinary"],
460 },
461 windows: {
462 compile_multilib: "64",
463 },
464 windows_x86_64: {
465 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
466 },
467 },
468}
469
470cc_prebuilt_binary {
471 name: "mynativebinary",
472 prefer: false,
473 device_supported: false,
474 host_supported: true,
475 target: {
476 linux_glibc: {
477 compile_multilib: "both",
478 },
479 linux_glibc_x86_64: {
480 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
481 },
482 linux_glibc_x86: {
483 srcs: ["linux_glibc/x86/bin/mynativebinary"],
484 },
485 windows: {
486 compile_multilib: "64",
487 },
488 windows_x86_64: {
489 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
490 },
491 },
492}
493
494module_exports_snapshot {
495 name: "myexports@current",
496 device_supported: false,
497 host_supported: true,
498 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin2b5887a2020-03-20 17:50:07 +0000499 target: {
500 windows: {
501 compile_multilib: "64",
502 },
503 },
Paul Duffin9b358d72020-03-02 10:16:35 +0000504}
505`),
506 checkAllCopyRules(`
507.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
508.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
509.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
510`),
511 )
512}
513
Paul Duffin9ab556f2019-12-11 18:42:17 +0000514func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000515 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000516 sdk {
517 name: "mysdk",
518 native_shared_libs: ["mynativelib"],
519 }
520
521 cc_library_shared {
522 name: "mynativelib",
523 srcs: [
524 "Test.cpp",
525 "aidl/foo/bar/Test.aidl",
526 ],
Paul Duffin3a6c0952020-03-04 14:22:45 +0000527 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000528 export_include_dirs: ["include"],
529 aidl: {
530 export_aidl_headers: true,
531 },
532 system_shared_libs: [],
533 stl: "none",
534 }
535 `)
536
Paul Duffinb0cbec32020-02-25 19:26:33 +0000537 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000538 checkAndroidBpContents(`
539// This is auto-generated. DO NOT EDIT.
540
541cc_prebuilt_library_shared {
542 name: "mysdk_mynativelib@current",
543 sdk_member_name: "mynativelib",
Paul Duffin3a6c0952020-03-04 14:22:45 +0000544 apex_available: [
545 "apex1",
546 "apex2",
547 ],
Paul Duffinf51768a2020-03-04 14:52:46 +0000548 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000549 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000550 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000551 arch: {
552 arm64: {
553 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000554 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000555 },
556 arm: {
557 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000558 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000559 },
560 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000561}
562
563cc_prebuilt_library_shared {
564 name: "mynativelib",
565 prefer: false,
Paul Duffin3a6c0952020-03-04 14:22:45 +0000566 apex_available: [
567 "apex1",
568 "apex2",
569 ],
Paul Duffin2bdbe832020-03-11 18:42:08 +0000570 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000571 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000572 arch: {
573 arm64: {
574 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000575 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000576 },
577 arm: {
578 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000579 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000580 },
581 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000582}
583
584sdk_snapshot {
585 name: "mysdk@current",
586 native_shared_libs: ["mysdk_mynativelib@current"],
587}
588`),
589 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000590include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800591.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
592.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
593.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
594.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
595.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
596.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
597.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
598.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000599`),
600 )
601}
602
Paul Duffin206433a2020-03-06 12:30:43 +0000603func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
604 result := testSdkWithCc(t, `
605 sdk {
606 name: "mysdk",
607 native_shared_libs: [
608 "mynativelib",
609 "myothernativelib",
610 "mysystemnativelib",
611 ],
612 }
613
614 cc_library {
615 name: "mysystemnativelib",
616 srcs: [
617 "Test.cpp",
618 ],
619 system_shared_libs: [],
620 stl: "none",
621 }
622
623 cc_library_shared {
624 name: "myothernativelib",
625 srcs: [
626 "Test.cpp",
627 ],
628 system_shared_libs: [
629 // A reference to a library that is not an sdk member. Uses libm as that
630 // is in the default set of modules available to this test and so is available
631 // both here and also when the generated Android.bp file is tested in
632 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
633 // handles references to modules that are not sdk members.
634 "libm",
635 ],
636 stl: "none",
637 }
638
639 cc_library {
640 name: "mynativelib",
641 srcs: [
642 "Test.cpp",
643 ],
644 shared_libs: [
645 // A reference to another sdk member.
646 "myothernativelib",
647 ],
648 target: {
649 android: {
650 shared: {
651 shared_libs: [
652 // A reference to a library that is not an sdk member. The libc library
653 // is used here to check that the shared_libs property is handled correctly
654 // in a similar way to how libm is used to check system_shared_libs above.
655 "libc",
656 ],
657 },
658 },
659 },
660 system_shared_libs: [],
661 stl: "none",
662 }
663 `)
664
665 result.CheckSnapshot("mysdk", "",
666 checkAndroidBpContents(`
667// This is auto-generated. DO NOT EDIT.
668
669cc_prebuilt_library_shared {
670 name: "mysdk_mynativelib@current",
671 sdk_member_name: "mynativelib",
672 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000673 stl: "none",
Paul Duffin206433a2020-03-06 12:30:43 +0000674 shared_libs: [
675 "mysdk_myothernativelib@current",
676 "libc",
677 ],
678 arch: {
679 arm64: {
680 srcs: ["arm64/lib/mynativelib.so"],
681 },
682 arm: {
683 srcs: ["arm/lib/mynativelib.so"],
684 },
685 },
Paul Duffin206433a2020-03-06 12:30:43 +0000686}
687
688cc_prebuilt_library_shared {
689 name: "mynativelib",
690 prefer: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000691 stl: "none",
Paul Duffin206433a2020-03-06 12:30:43 +0000692 shared_libs: [
693 "myothernativelib",
694 "libc",
695 ],
696 arch: {
697 arm64: {
698 srcs: ["arm64/lib/mynativelib.so"],
699 },
700 arm: {
701 srcs: ["arm/lib/mynativelib.so"],
702 },
703 },
Paul Duffin206433a2020-03-06 12:30:43 +0000704}
705
706cc_prebuilt_library_shared {
707 name: "mysdk_myothernativelib@current",
708 sdk_member_name: "myothernativelib",
709 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000710 stl: "none",
Paul Duffin206433a2020-03-06 12:30:43 +0000711 system_shared_libs: ["libm"],
712 arch: {
713 arm64: {
714 srcs: ["arm64/lib/myothernativelib.so"],
715 },
716 arm: {
717 srcs: ["arm/lib/myothernativelib.so"],
718 },
719 },
Paul Duffin206433a2020-03-06 12:30:43 +0000720}
721
722cc_prebuilt_library_shared {
723 name: "myothernativelib",
724 prefer: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000725 stl: "none",
Paul Duffin206433a2020-03-06 12:30:43 +0000726 system_shared_libs: ["libm"],
727 arch: {
728 arm64: {
729 srcs: ["arm64/lib/myothernativelib.so"],
730 },
731 arm: {
732 srcs: ["arm/lib/myothernativelib.so"],
733 },
734 },
Paul Duffin206433a2020-03-06 12:30:43 +0000735}
736
737cc_prebuilt_library_shared {
738 name: "mysdk_mysystemnativelib@current",
739 sdk_member_name: "mysystemnativelib",
740 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000741 stl: "none",
Paul Duffin206433a2020-03-06 12:30:43 +0000742 arch: {
743 arm64: {
744 srcs: ["arm64/lib/mysystemnativelib.so"],
745 },
746 arm: {
747 srcs: ["arm/lib/mysystemnativelib.so"],
748 },
749 },
Paul Duffin206433a2020-03-06 12:30:43 +0000750}
751
752cc_prebuilt_library_shared {
753 name: "mysystemnativelib",
754 prefer: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000755 stl: "none",
Paul Duffin206433a2020-03-06 12:30:43 +0000756 arch: {
757 arm64: {
758 srcs: ["arm64/lib/mysystemnativelib.so"],
759 },
760 arm: {
761 srcs: ["arm/lib/mysystemnativelib.so"],
762 },
763 },
Paul Duffin206433a2020-03-06 12:30:43 +0000764}
765
766sdk_snapshot {
767 name: "mysdk@current",
768 native_shared_libs: [
769 "mysdk_mynativelib@current",
770 "mysdk_myothernativelib@current",
771 "mysdk_mysystemnativelib@current",
772 ],
773}
774`),
775 checkAllCopyRules(`
776.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
777.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
778.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
779.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
780.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
781.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
782`),
783 )
784}
785
Paul Duffin9ab556f2019-12-11 18:42:17 +0000786func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000787 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
788 SkipIfNotLinux(t)
789
Paul Duffind835daa2019-11-30 17:49:09 +0000790 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000791 sdk {
792 name: "mysdk",
793 device_supported: false,
794 host_supported: true,
795 native_shared_libs: ["mynativelib"],
796 }
797
798 cc_library_shared {
799 name: "mynativelib",
800 device_supported: false,
801 host_supported: true,
802 srcs: [
803 "Test.cpp",
804 "aidl/foo/bar/Test.aidl",
805 ],
806 export_include_dirs: ["include"],
807 aidl: {
808 export_aidl_headers: true,
809 },
810 system_shared_libs: [],
811 stl: "none",
Paul Duffin8fa6acf2020-03-05 14:09:58 +0000812 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +0000813 }
814 `)
815
Paul Duffinb0cbec32020-02-25 19:26:33 +0000816 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000817 checkAndroidBpContents(`
818// This is auto-generated. DO NOT EDIT.
819
820cc_prebuilt_library_shared {
821 name: "mysdk_mynativelib@current",
822 sdk_member_name: "mynativelib",
823 device_supported: false,
824 host_supported: true,
Paul Duffinf51768a2020-03-04 14:52:46 +0000825 installable: false,
Paul Duffin8fa6acf2020-03-05 14:09:58 +0000826 sdk_version: "minimum",
Paul Duffin2bdbe832020-03-11 18:42:08 +0000827 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000828 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000829 arch: {
830 x86_64: {
831 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000832 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000833 },
834 x86: {
835 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000836 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000837 },
838 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000839}
840
841cc_prebuilt_library_shared {
842 name: "mynativelib",
843 prefer: false,
844 device_supported: false,
845 host_supported: true,
Paul Duffin8fa6acf2020-03-05 14:09:58 +0000846 sdk_version: "minimum",
Paul Duffin2bdbe832020-03-11 18:42:08 +0000847 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000848 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000849 arch: {
850 x86_64: {
851 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000852 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000853 },
854 x86: {
855 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000856 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000857 },
858 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000859}
860
861sdk_snapshot {
862 name: "mysdk@current",
863 device_supported: false,
864 host_supported: true,
865 native_shared_libs: ["mysdk_mynativelib@current"],
866}
867`),
868 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000869include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000870.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000871.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
872.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
873.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
874.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000875.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
876.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
877.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
878`),
879 )
880}
Paul Duffin9ab556f2019-12-11 18:42:17 +0000881
Paul Duffin9b358d72020-03-02 10:16:35 +0000882func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
883 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
884 SkipIfNotLinux(t)
885
886 result := testSdkWithCc(t, `
887 sdk {
888 name: "mysdk",
889 device_supported: false,
890 host_supported: true,
891 native_shared_libs: ["mynativelib"],
892 target: {
893 windows: {
894 enabled: true,
895 },
896 },
897 }
898
899 cc_library_shared {
900 name: "mynativelib",
901 device_supported: false,
902 host_supported: true,
903 srcs: [
904 "Test.cpp",
905 ],
906 system_shared_libs: [],
907 stl: "none",
908 target: {
909 windows: {
910 enabled: true,
911 },
912 },
913 }
914 `)
915
916 result.CheckSnapshot("mysdk", "",
917 checkAndroidBpContents(`
918// This is auto-generated. DO NOT EDIT.
919
920cc_prebuilt_library_shared {
921 name: "mysdk_mynativelib@current",
922 sdk_member_name: "mynativelib",
923 device_supported: false,
924 host_supported: true,
Paul Duffinf51768a2020-03-04 14:52:46 +0000925 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000926 stl: "none",
Paul Duffin9b358d72020-03-02 10:16:35 +0000927 target: {
928 linux_glibc_x86_64: {
929 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
930 },
931 linux_glibc_x86: {
932 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
933 },
934 windows_x86_64: {
935 srcs: ["windows/x86_64/lib/mynativelib.dll"],
936 },
937 },
Paul Duffin9b358d72020-03-02 10:16:35 +0000938}
939
940cc_prebuilt_library_shared {
941 name: "mynativelib",
942 prefer: false,
943 device_supported: false,
944 host_supported: true,
Paul Duffin2bdbe832020-03-11 18:42:08 +0000945 stl: "none",
Paul Duffin9b358d72020-03-02 10:16:35 +0000946 target: {
947 linux_glibc_x86_64: {
948 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
949 },
950 linux_glibc_x86: {
951 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
952 },
953 windows_x86_64: {
954 srcs: ["windows/x86_64/lib/mynativelib.dll"],
955 },
956 },
Paul Duffin9b358d72020-03-02 10:16:35 +0000957}
958
959sdk_snapshot {
960 name: "mysdk@current",
961 device_supported: false,
962 host_supported: true,
963 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin2b5887a2020-03-20 17:50:07 +0000964 target: {
965 windows: {
966 compile_multilib: "64",
967 },
968 },
Paul Duffin9b358d72020-03-02 10:16:35 +0000969}
970`),
971 checkAllCopyRules(`
972.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
973.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
974.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
975`),
976 )
977}
978
Paul Duffin9ab556f2019-12-11 18:42:17 +0000979func TestSnapshotWithCcStaticLibrary(t *testing.T) {
980 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +0000981 module_exports {
982 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000983 native_static_libs: ["mynativelib"],
984 }
985
986 cc_library_static {
987 name: "mynativelib",
988 srcs: [
989 "Test.cpp",
990 "aidl/foo/bar/Test.aidl",
991 ],
992 export_include_dirs: ["include"],
993 aidl: {
994 export_aidl_headers: true,
995 },
996 system_shared_libs: [],
997 stl: "none",
998 }
999 `)
1000
Paul Duffinb0cbec32020-02-25 19:26:33 +00001001 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001002 checkAndroidBpContents(`
1003// This is auto-generated. DO NOT EDIT.
1004
1005cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001006 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001007 sdk_member_name: "mynativelib",
Paul Duffinf51768a2020-03-04 14:52:46 +00001008 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001009 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001010 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001011 arch: {
1012 arm64: {
1013 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001014 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001015 },
1016 arm: {
1017 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001018 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001019 },
1020 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001021}
1022
1023cc_prebuilt_library_static {
1024 name: "mynativelib",
1025 prefer: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001026 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001027 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001028 arch: {
1029 arm64: {
1030 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001031 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001032 },
1033 arm: {
1034 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001035 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001036 },
1037 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001038}
1039
Paul Duffine6029182019-12-16 17:43:48 +00001040module_exports_snapshot {
1041 name: "myexports@current",
1042 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001043}
1044`),
1045 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001046include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001047.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1048.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1049.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1050.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1051.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1052.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1053.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1054.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001055`),
1056 )
1057}
1058
1059func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1060 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1061 SkipIfNotLinux(t)
1062
1063 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001064 module_exports {
1065 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001066 device_supported: false,
1067 host_supported: true,
1068 native_static_libs: ["mynativelib"],
1069 }
1070
1071 cc_library_static {
1072 name: "mynativelib",
1073 device_supported: false,
1074 host_supported: true,
1075 srcs: [
1076 "Test.cpp",
1077 "aidl/foo/bar/Test.aidl",
1078 ],
1079 export_include_dirs: ["include"],
1080 aidl: {
1081 export_aidl_headers: true,
1082 },
1083 system_shared_libs: [],
1084 stl: "none",
1085 }
1086 `)
1087
Paul Duffinb0cbec32020-02-25 19:26:33 +00001088 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001089 checkAndroidBpContents(`
1090// This is auto-generated. DO NOT EDIT.
1091
1092cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001093 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001094 sdk_member_name: "mynativelib",
1095 device_supported: false,
1096 host_supported: true,
Paul Duffinf51768a2020-03-04 14:52:46 +00001097 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001098 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001099 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001100 arch: {
1101 x86_64: {
1102 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001103 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001104 },
1105 x86: {
1106 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001107 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001108 },
1109 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001110}
1111
1112cc_prebuilt_library_static {
1113 name: "mynativelib",
1114 prefer: false,
1115 device_supported: false,
1116 host_supported: true,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001117 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001118 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001119 arch: {
1120 x86_64: {
1121 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001122 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001123 },
1124 x86: {
1125 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001126 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001127 },
1128 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001129}
1130
Paul Duffine6029182019-12-16 17:43:48 +00001131module_exports_snapshot {
1132 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001133 device_supported: false,
1134 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001135 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001136}
1137`),
1138 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001139include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001140.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001141.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1142.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1143.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1144.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001145.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1146.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1147.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1148`),
1149 )
1150}
Paul Duffinac897cf2020-02-19 16:19:27 +00001151
Paul Duffin6cb8f172020-03-12 10:24:35 +00001152func TestSnapshotWithCcLibrary(t *testing.T) {
1153 result := testSdkWithCc(t, `
1154 module_exports {
1155 name: "myexports",
1156 native_libs: ["mynativelib"],
1157 }
1158
1159 cc_library {
1160 name: "mynativelib",
1161 srcs: [
1162 "Test.cpp",
1163 ],
1164 export_include_dirs: ["include"],
1165 system_shared_libs: [],
1166 stl: "none",
1167 }
1168 `)
1169
1170 result.CheckSnapshot("myexports", "",
1171 checkAndroidBpContents(`
1172// This is auto-generated. DO NOT EDIT.
1173
1174cc_prebuilt_library {
1175 name: "myexports_mynativelib@current",
1176 sdk_member_name: "mynativelib",
1177 installable: false,
1178 stl: "none",
1179 export_include_dirs: ["include/include"],
1180 arch: {
1181 arm64: {
1182 static: {
1183 srcs: ["arm64/lib/mynativelib.a"],
1184 },
1185 shared: {
1186 srcs: ["arm64/lib/mynativelib.so"],
1187 },
1188 },
1189 arm: {
1190 static: {
1191 srcs: ["arm/lib/mynativelib.a"],
1192 },
1193 shared: {
1194 srcs: ["arm/lib/mynativelib.so"],
1195 },
1196 },
1197 },
1198}
1199
1200cc_prebuilt_library {
1201 name: "mynativelib",
1202 prefer: false,
1203 stl: "none",
1204 export_include_dirs: ["include/include"],
1205 arch: {
1206 arm64: {
1207 static: {
1208 srcs: ["arm64/lib/mynativelib.a"],
1209 },
1210 shared: {
1211 srcs: ["arm64/lib/mynativelib.so"],
1212 },
1213 },
1214 arm: {
1215 static: {
1216 srcs: ["arm/lib/mynativelib.a"],
1217 },
1218 shared: {
1219 srcs: ["arm/lib/mynativelib.so"],
1220 },
1221 },
1222 },
1223}
1224
1225module_exports_snapshot {
1226 name: "myexports@current",
1227 native_libs: ["myexports_mynativelib@current"],
1228}
1229`),
1230 checkAllCopyRules(`
1231include/Test.h -> include/include/Test.h
1232.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1233.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1234.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1235.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1236 )
1237}
1238
Paul Duffinac897cf2020-02-19 16:19:27 +00001239func TestHostSnapshotWithMultiLib64(t *testing.T) {
1240 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1241 SkipIfNotLinux(t)
1242
1243 result := testSdkWithCc(t, `
1244 module_exports {
1245 name: "myexports",
1246 device_supported: false,
1247 host_supported: true,
1248 target: {
1249 host: {
1250 compile_multilib: "64",
1251 },
1252 },
1253 native_static_libs: ["mynativelib"],
1254 }
1255
1256 cc_library_static {
1257 name: "mynativelib",
1258 device_supported: false,
1259 host_supported: true,
1260 srcs: [
1261 "Test.cpp",
1262 "aidl/foo/bar/Test.aidl",
1263 ],
1264 export_include_dirs: ["include"],
1265 aidl: {
1266 export_aidl_headers: true,
1267 },
1268 system_shared_libs: [],
1269 stl: "none",
1270 }
1271 `)
1272
Paul Duffinb0cbec32020-02-25 19:26:33 +00001273 result.CheckSnapshot("myexports", "",
Paul Duffinac897cf2020-02-19 16:19:27 +00001274 checkAndroidBpContents(`
1275// This is auto-generated. DO NOT EDIT.
1276
1277cc_prebuilt_library_static {
1278 name: "myexports_mynativelib@current",
1279 sdk_member_name: "mynativelib",
1280 device_supported: false,
1281 host_supported: true,
Paul Duffinf51768a2020-03-04 14:52:46 +00001282 installable: false,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001283 stl: "none",
Paul Duffinac897cf2020-02-19 16:19:27 +00001284 export_include_dirs: ["include/include"],
1285 arch: {
1286 x86_64: {
1287 srcs: ["x86_64/lib/mynativelib.a"],
1288 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1289 },
1290 },
Paul Duffinac897cf2020-02-19 16:19:27 +00001291}
1292
1293cc_prebuilt_library_static {
1294 name: "mynativelib",
1295 prefer: false,
1296 device_supported: false,
1297 host_supported: true,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001298 stl: "none",
Paul Duffinac897cf2020-02-19 16:19:27 +00001299 export_include_dirs: ["include/include"],
1300 arch: {
1301 x86_64: {
1302 srcs: ["x86_64/lib/mynativelib.a"],
1303 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1304 },
1305 },
Paul Duffinac897cf2020-02-19 16:19:27 +00001306}
1307
1308module_exports_snapshot {
1309 name: "myexports@current",
1310 device_supported: false,
1311 host_supported: true,
Paul Duffin35dbafc2020-03-11 18:17:42 +00001312 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffinac897cf2020-02-19 16:19:27 +00001313 target: {
Paul Duffin2b5887a2020-03-20 17:50:07 +00001314 linux_glibc: {
Paul Duffinac897cf2020-02-19 16:19:27 +00001315 compile_multilib: "64",
1316 },
1317 },
Paul Duffinac897cf2020-02-19 16:19:27 +00001318}`),
1319 checkAllCopyRules(`
1320include/Test.h -> include/include/Test.h
1321.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1322.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1323.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1324.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1325`),
1326 )
1327}
Paul Duffin132e66f2020-02-21 16:29:57 +00001328
1329func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1330 result := testSdkWithCc(t, `
1331 sdk {
1332 name: "mysdk",
1333 native_header_libs: ["mynativeheaders"],
1334 }
1335
1336 cc_library_headers {
1337 name: "mynativeheaders",
1338 export_include_dirs: ["include"],
1339 system_shared_libs: [],
1340 stl: "none",
1341 }
1342 `)
1343
Paul Duffinb0cbec32020-02-25 19:26:33 +00001344 result.CheckSnapshot("mysdk", "",
Paul Duffin132e66f2020-02-21 16:29:57 +00001345 checkAndroidBpContents(`
1346// This is auto-generated. DO NOT EDIT.
1347
1348cc_prebuilt_library_headers {
1349 name: "mysdk_mynativeheaders@current",
1350 sdk_member_name: "mynativeheaders",
Paul Duffin132e66f2020-02-21 16:29:57 +00001351 stl: "none",
Paul Duffin2bdbe832020-03-11 18:42:08 +00001352 export_include_dirs: ["include/include"],
Paul Duffin132e66f2020-02-21 16:29:57 +00001353}
1354
1355cc_prebuilt_library_headers {
1356 name: "mynativeheaders",
1357 prefer: false,
Paul Duffin132e66f2020-02-21 16:29:57 +00001358 stl: "none",
Paul Duffin2bdbe832020-03-11 18:42:08 +00001359 export_include_dirs: ["include/include"],
Paul Duffin132e66f2020-02-21 16:29:57 +00001360}
1361
1362sdk_snapshot {
1363 name: "mysdk@current",
1364 native_header_libs: ["mysdk_mynativeheaders@current"],
1365}
1366`),
1367 checkAllCopyRules(`
1368include/Test.h -> include/include/Test.h
1369`),
1370 )
1371}
1372
1373func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1374 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1375 SkipIfNotLinux(t)
1376
1377 result := testSdkWithCc(t, `
1378 sdk {
1379 name: "mysdk",
1380 device_supported: false,
1381 host_supported: true,
1382 native_header_libs: ["mynativeheaders"],
1383 }
1384
1385 cc_library_headers {
1386 name: "mynativeheaders",
1387 device_supported: false,
1388 host_supported: true,
1389 export_include_dirs: ["include"],
1390 system_shared_libs: [],
1391 stl: "none",
1392 }
1393 `)
1394
Paul Duffinb0cbec32020-02-25 19:26:33 +00001395 result.CheckSnapshot("mysdk", "",
Paul Duffin132e66f2020-02-21 16:29:57 +00001396 checkAndroidBpContents(`
1397// This is auto-generated. DO NOT EDIT.
1398
1399cc_prebuilt_library_headers {
1400 name: "mysdk_mynativeheaders@current",
1401 sdk_member_name: "mynativeheaders",
1402 device_supported: false,
1403 host_supported: true,
Paul Duffin132e66f2020-02-21 16:29:57 +00001404 stl: "none",
Paul Duffin2bdbe832020-03-11 18:42:08 +00001405 export_include_dirs: ["include/include"],
Paul Duffin132e66f2020-02-21 16:29:57 +00001406}
1407
1408cc_prebuilt_library_headers {
1409 name: "mynativeheaders",
1410 prefer: false,
1411 device_supported: false,
1412 host_supported: true,
Paul Duffin132e66f2020-02-21 16:29:57 +00001413 stl: "none",
Paul Duffin2bdbe832020-03-11 18:42:08 +00001414 export_include_dirs: ["include/include"],
Paul Duffin132e66f2020-02-21 16:29:57 +00001415}
1416
1417sdk_snapshot {
1418 name: "mysdk@current",
1419 device_supported: false,
1420 host_supported: true,
1421 native_header_libs: ["mysdk_mynativeheaders@current"],
1422}
1423`),
1424 checkAllCopyRules(`
1425include/Test.h -> include/include/Test.h
1426`),
1427 )
1428}
Paul Duffin9b358d72020-03-02 10:16:35 +00001429
1430func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1431 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1432 SkipIfNotLinux(t)
1433
1434 result := testSdkWithCc(t, `
1435 sdk {
1436 name: "mysdk",
1437 host_supported: true,
1438 native_header_libs: ["mynativeheaders"],
1439 }
1440
1441 cc_library_headers {
1442 name: "mynativeheaders",
1443 host_supported: true,
1444 system_shared_libs: [],
1445 stl: "none",
1446 export_system_include_dirs: ["include"],
1447 target: {
1448 android: {
1449 export_include_dirs: ["include-android"],
1450 },
1451 host: {
1452 export_include_dirs: ["include-host"],
1453 },
1454 },
1455 }
1456 `)
1457
1458 result.CheckSnapshot("mysdk", "",
1459 checkAndroidBpContents(`
1460// This is auto-generated. DO NOT EDIT.
1461
1462cc_prebuilt_library_headers {
1463 name: "mysdk_mynativeheaders@current",
1464 sdk_member_name: "mynativeheaders",
1465 host_supported: true,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001466 stl: "none",
Paul Duffin9b358d72020-03-02 10:16:35 +00001467 export_system_include_dirs: ["include/include"],
1468 target: {
1469 android: {
1470 export_include_dirs: ["include/include-android"],
1471 },
1472 linux_glibc: {
1473 export_include_dirs: ["include/include-host"],
1474 },
1475 },
Paul Duffin9b358d72020-03-02 10:16:35 +00001476}
1477
1478cc_prebuilt_library_headers {
1479 name: "mynativeheaders",
1480 prefer: false,
1481 host_supported: true,
Paul Duffin2bdbe832020-03-11 18:42:08 +00001482 stl: "none",
Paul Duffin9b358d72020-03-02 10:16:35 +00001483 export_system_include_dirs: ["include/include"],
1484 target: {
1485 android: {
1486 export_include_dirs: ["include/include-android"],
1487 },
1488 linux_glibc: {
1489 export_include_dirs: ["include/include-host"],
1490 },
1491 },
Paul Duffin9b358d72020-03-02 10:16:35 +00001492}
1493
1494sdk_snapshot {
1495 name: "mysdk@current",
1496 host_supported: true,
1497 native_header_libs: ["mysdk_mynativeheaders@current"],
1498}
1499`),
1500 checkAllCopyRules(`
1501include/Test.h -> include/include/Test.h
1502include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1503include-host/HostTest.h -> include/include-host/HostTest.h
1504`),
1505 )
1506}