blob: ecb1da0a0723c167c446dd8306b1366fdcbf8c37 [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
20 "android/soong/cc"
21)
22
Paul Duffind835daa2019-11-30 17:49:09 +000023func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
24 t.Helper()
25
26 fs := map[string][]byte{
Paul Duffina7cd8c82019-12-11 20:00:57 +000027 "Test.cpp": nil,
28 "include/Test.h": nil,
29 "arm64/include/Arm64Test.h": nil,
30 "libfoo.so": nil,
31 "aidl/foo/bar/Test.aidl": nil,
Paul Duffind835daa2019-11-30 17:49:09 +000032 }
33 return testSdkWithFs(t, bp, fs)
34}
35
Paul Duffina80fdec2019-12-03 15:25:00 +000036// Contains tests for SDK members provided by the cc package.
37
38func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000039 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000040 sdk {
41 name: "mysdk",
42 native_shared_libs: ["sdkmember"],
43 }
44
45 cc_library_shared {
46 name: "sdkmember",
47 srcs: ["Test.cpp"],
48 system_shared_libs: [],
49 stl: "none",
50 }
51 `)
52
Colin Cross7113d202019-11-20 16:39:12 -080053 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
54 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
Paul Duffina80fdec2019-12-03 15:25:00 +000055
56 var inputs []string
57 buildParams := result.Module("mysdk", "android_common").BuildParamsForTests()
58 for _, bp := range buildParams {
59 if bp.Input != nil {
60 inputs = append(inputs, bp.Input.String())
61 }
62 }
63
64 // ensure that both 32/64 outputs are inputs of the sdk snapshot
65 ensureListContains(t, inputs, armOutput.String())
66 ensureListContains(t, inputs, arm64Output.String())
67}
68
69func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000070 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000071 sdk {
72 name: "mysdk",
73 native_shared_libs: ["sdkmember"],
74 }
75
Paul Duffina0843f62019-12-13 19:50:38 +000076 cc_library_shared {
77 name: "sdkmember",
Colin Crossf9aabd72020-02-15 11:29:50 -080078 system_shared_libs: [],
Paul Duffina0843f62019-12-13 19:50:38 +000079 }
80
Paul Duffina80fdec2019-12-03 15:25:00 +000081 sdk_snapshot {
82 name: "mysdk@1",
83 native_shared_libs: ["sdkmember_mysdk_1"],
84 }
85
86 sdk_snapshot {
87 name: "mysdk@2",
88 native_shared_libs: ["sdkmember_mysdk_2"],
89 }
90
91 cc_prebuilt_library_shared {
92 name: "sdkmember",
93 srcs: ["libfoo.so"],
94 prefer: false,
95 system_shared_libs: [],
96 stl: "none",
97 }
98
99 cc_prebuilt_library_shared {
100 name: "sdkmember_mysdk_1",
101 sdk_member_name: "sdkmember",
102 srcs: ["libfoo.so"],
103 system_shared_libs: [],
104 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000105 // TODO: remove //apex_available:platform
106 apex_available: [
107 "//apex_available:platform",
108 "myapex",
109 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000110 }
111
112 cc_prebuilt_library_shared {
113 name: "sdkmember_mysdk_2",
114 sdk_member_name: "sdkmember",
115 srcs: ["libfoo.so"],
116 system_shared_libs: [],
117 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000118 // TODO: remove //apex_available:platform
119 apex_available: [
120 "//apex_available:platform",
121 "myapex2",
122 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000123 }
124
125 cc_library_shared {
126 name: "mycpplib",
127 srcs: ["Test.cpp"],
128 shared_libs: ["sdkmember"],
129 system_shared_libs: [],
130 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000131 apex_available: [
132 "myapex",
133 "myapex2",
134 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000135 }
136
137 apex {
138 name: "myapex",
139 native_shared_libs: ["mycpplib"],
140 uses_sdks: ["mysdk@1"],
141 key: "myapex.key",
142 certificate: ":myapex.cert",
143 }
144
145 apex {
146 name: "myapex2",
147 native_shared_libs: ["mycpplib"],
148 uses_sdks: ["mysdk@2"],
149 key: "myapex.key",
150 certificate: ":myapex.cert",
151 }
152 `)
153
Colin Cross7113d202019-11-20 16:39:12 -0800154 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_myapex").Rule("toc").Output
155 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_myapex2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000156
Colin Cross7113d202019-11-20 16:39:12 -0800157 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
158 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000159
160 // Depending on the uses_sdks value, different libs are linked
161 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
162 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
163}
164
Paul Duffina0843f62019-12-13 19:50:38 +0000165// Make sure the sdk can use host specific cc libraries static/shared and both.
166func TestHostSdkWithCc(t *testing.T) {
167 testSdkWithCc(t, `
168 sdk {
169 name: "mysdk",
170 device_supported: false,
171 host_supported: true,
172 native_shared_libs: ["sdkshared"],
173 native_static_libs: ["sdkstatic"],
174 }
175
176 cc_library_host_shared {
177 name: "sdkshared",
178 system_shared_libs: [],
179 stl: "none",
180 }
181
182 cc_library_host_static {
183 name: "sdkstatic",
184 system_shared_libs: [],
185 stl: "none",
186 }
187 `)
188}
189
190// Make sure the sdk can use cc libraries static/shared and both.
191func TestSdkWithCc(t *testing.T) {
192 testSdkWithCc(t, `
193 sdk {
194 name: "mysdk",
195 native_shared_libs: ["sdkshared", "sdkboth1"],
196 native_static_libs: ["sdkstatic", "sdkboth2"],
197 }
198
199 cc_library_shared {
200 name: "sdkshared",
201 system_shared_libs: [],
202 stl: "none",
203 }
204
205 cc_library_static {
206 name: "sdkstatic",
207 system_shared_libs: [],
208 stl: "none",
209 }
210
211 cc_library {
212 name: "sdkboth1",
213 system_shared_libs: [],
214 stl: "none",
215 }
216
217 cc_library {
218 name: "sdkboth2",
219 system_shared_libs: [],
220 stl: "none",
221 }
222 `)
223}
224
Paul Duffinc62a5102019-12-11 18:34:15 +0000225func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
226 result := testSdkWithCc(t, `
227 sdk {
228 name: "mysdk",
229 native_shared_libs: ["mynativelib1", "mynativelib2"],
230 }
231
232 cc_library_shared {
233 name: "mynativelib1",
234 srcs: [
235 "Test.cpp",
236 ],
237 export_include_dirs: ["include"],
238 system_shared_libs: [],
239 stl: "none",
240 }
241
242 cc_library_shared {
243 name: "mynativelib2",
244 srcs: [
245 "Test.cpp",
246 ],
247 export_include_dirs: ["include"],
248 system_shared_libs: [],
249 stl: "none",
250 }
251 `)
252
253 result.CheckSnapshot("mysdk", "android_common", "",
254 checkAllCopyRules(`
255include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800256.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
257.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
258.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
259.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000260`),
261 )
262}
263
Paul Duffina7cd8c82019-12-11 20:00:57 +0000264// Verify that when the shared library has some common and some arch specific properties that the generated
265// snapshot is optimized properly.
266func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
267 result := testSdkWithCc(t, `
268 sdk {
269 name: "mysdk",
270 native_shared_libs: ["mynativelib"],
271 }
272
273 cc_library_shared {
274 name: "mynativelib",
275 srcs: [
276 "Test.cpp",
277 "aidl/foo/bar/Test.aidl",
278 ],
279 export_include_dirs: ["include"],
280 arch: {
281 arm64: {
282 export_system_include_dirs: ["arm64/include"],
283 },
284 },
285 system_shared_libs: [],
286 stl: "none",
287 }
288 `)
289
290 result.CheckSnapshot("mysdk", "android_common", "",
291 checkAndroidBpContents(`
292// This is auto-generated. DO NOT EDIT.
293
294cc_prebuilt_library_shared {
295 name: "mysdk_mynativelib@current",
296 sdk_member_name: "mynativelib",
297 export_include_dirs: ["include/include"],
298 arch: {
299 arm64: {
300 srcs: ["arm64/lib/mynativelib.so"],
301 export_system_include_dirs: ["arm64/include/arm64/include"],
302 },
303 arm: {
304 srcs: ["arm/lib/mynativelib.so"],
305 },
306 },
307 stl: "none",
308 system_shared_libs: [],
309}
310
311cc_prebuilt_library_shared {
312 name: "mynativelib",
313 prefer: false,
314 export_include_dirs: ["include/include"],
315 arch: {
316 arm64: {
317 srcs: ["arm64/lib/mynativelib.so"],
318 export_system_include_dirs: ["arm64/include/arm64/include"],
319 },
320 arm: {
321 srcs: ["arm/lib/mynativelib.so"],
322 },
323 },
324 stl: "none",
325 system_shared_libs: [],
326}
327
328sdk_snapshot {
329 name: "mysdk@current",
330 native_shared_libs: ["mysdk_mynativelib@current"],
331}
332`),
333 checkAllCopyRules(`
334include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800335.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000336arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800337.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000338 )
339}
340
Paul Duffin25ce04b2020-01-16 11:47:25 +0000341func TestSnapshotWithCcBinary(t *testing.T) {
342 result := testSdkWithCc(t, `
343 module_exports {
344 name: "mymodule_exports",
345 native_binaries: ["mynativebinary"],
346 }
347
348 cc_binary {
349 name: "mynativebinary",
350 srcs: [
351 "Test.cpp",
352 ],
353 compile_multilib: "both",
354 system_shared_libs: [],
355 stl: "none",
356 }
357 `)
358
359 result.CheckSnapshot("mymodule_exports", "android_common", "",
360 checkAndroidBpContents(`
361// This is auto-generated. DO NOT EDIT.
362
363cc_prebuilt_binary {
364 name: "mymodule_exports_mynativebinary@current",
365 sdk_member_name: "mynativebinary",
366 compile_multilib: "both",
367 arch: {
368 arm64: {
369 srcs: ["arm64/bin/mynativebinary"],
370 },
371 arm: {
372 srcs: ["arm/bin/mynativebinary"],
373 },
374 },
375}
376
377cc_prebuilt_binary {
378 name: "mynativebinary",
379 prefer: false,
380 compile_multilib: "both",
381 arch: {
382 arm64: {
383 srcs: ["arm64/bin/mynativebinary"],
384 },
385 arm: {
386 srcs: ["arm/bin/mynativebinary"],
387 },
388 },
389}
390
391module_exports_snapshot {
392 name: "mymodule_exports@current",
393 native_binaries: ["mymodule_exports_mynativebinary@current"],
394}
395`),
396 checkAllCopyRules(`
397.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
398.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
399`),
400 )
401}
402
Paul Duffin9ab556f2019-12-11 18:42:17 +0000403func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000404 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000405 sdk {
406 name: "mysdk",
407 native_shared_libs: ["mynativelib"],
408 }
409
410 cc_library_shared {
411 name: "mynativelib",
412 srcs: [
413 "Test.cpp",
414 "aidl/foo/bar/Test.aidl",
415 ],
416 export_include_dirs: ["include"],
417 aidl: {
418 export_aidl_headers: true,
419 },
420 system_shared_libs: [],
421 stl: "none",
422 }
423 `)
424
Paul Duffin593b3c92019-12-05 14:31:48 +0000425 result.CheckSnapshot("mysdk", "android_common", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000426 checkAndroidBpContents(`
427// This is auto-generated. DO NOT EDIT.
428
429cc_prebuilt_library_shared {
430 name: "mysdk_mynativelib@current",
431 sdk_member_name: "mynativelib",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000432 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000433 arch: {
434 arm64: {
435 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000436 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000437 },
438 arm: {
439 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000440 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000441 },
442 },
443 stl: "none",
444 system_shared_libs: [],
445}
446
447cc_prebuilt_library_shared {
448 name: "mynativelib",
449 prefer: false,
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000450 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000451 arch: {
452 arm64: {
453 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000454 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000455 },
456 arm: {
457 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000458 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000459 },
460 },
461 stl: "none",
462 system_shared_libs: [],
463}
464
465sdk_snapshot {
466 name: "mysdk@current",
467 native_shared_libs: ["mysdk_mynativelib@current"],
468}
469`),
470 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000471include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800472.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
473.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
474.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
475.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
476.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
477.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
478.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
479.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 +0000480`),
481 )
482}
483
Paul Duffin9ab556f2019-12-11 18:42:17 +0000484func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000485 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
486 SkipIfNotLinux(t)
487
Paul Duffind835daa2019-11-30 17:49:09 +0000488 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000489 sdk {
490 name: "mysdk",
491 device_supported: false,
492 host_supported: true,
493 native_shared_libs: ["mynativelib"],
494 }
495
496 cc_library_shared {
497 name: "mynativelib",
498 device_supported: false,
499 host_supported: true,
500 srcs: [
501 "Test.cpp",
502 "aidl/foo/bar/Test.aidl",
503 ],
504 export_include_dirs: ["include"],
505 aidl: {
506 export_aidl_headers: true,
507 },
508 system_shared_libs: [],
509 stl: "none",
510 }
511 `)
512
Paul Duffin593b3c92019-12-05 14:31:48 +0000513 result.CheckSnapshot("mysdk", "linux_glibc_common", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000514 checkAndroidBpContents(`
515// This is auto-generated. DO NOT EDIT.
516
517cc_prebuilt_library_shared {
518 name: "mysdk_mynativelib@current",
519 sdk_member_name: "mynativelib",
520 device_supported: false,
521 host_supported: true,
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000522 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000523 arch: {
524 x86_64: {
525 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000526 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000527 },
528 x86: {
529 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000530 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000531 },
532 },
533 stl: "none",
534 system_shared_libs: [],
535}
536
537cc_prebuilt_library_shared {
538 name: "mynativelib",
539 prefer: false,
540 device_supported: false,
541 host_supported: true,
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000542 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000543 arch: {
544 x86_64: {
545 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000546 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000547 },
548 x86: {
549 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000550 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000551 },
552 },
553 stl: "none",
554 system_shared_libs: [],
555}
556
557sdk_snapshot {
558 name: "mysdk@current",
559 device_supported: false,
560 host_supported: true,
561 native_shared_libs: ["mysdk_mynativelib@current"],
562}
563`),
564 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000565include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000566.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000567.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
568.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
569.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
570.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000571.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
572.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
573.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
574`),
575 )
576}
Paul Duffin9ab556f2019-12-11 18:42:17 +0000577
578func TestSnapshotWithCcStaticLibrary(t *testing.T) {
579 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +0000580 module_exports {
581 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000582 native_static_libs: ["mynativelib"],
583 }
584
585 cc_library_static {
586 name: "mynativelib",
587 srcs: [
588 "Test.cpp",
589 "aidl/foo/bar/Test.aidl",
590 ],
591 export_include_dirs: ["include"],
592 aidl: {
593 export_aidl_headers: true,
594 },
595 system_shared_libs: [],
596 stl: "none",
597 }
598 `)
599
Paul Duffine6029182019-12-16 17:43:48 +0000600 result.CheckSnapshot("myexports", "android_common", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000601 checkAndroidBpContents(`
602// This is auto-generated. DO NOT EDIT.
603
604cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +0000605 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000606 sdk_member_name: "mynativelib",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000607 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000608 arch: {
609 arm64: {
610 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000611 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000612 },
613 arm: {
614 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000615 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000616 },
617 },
618 stl: "none",
619 system_shared_libs: [],
620}
621
622cc_prebuilt_library_static {
623 name: "mynativelib",
624 prefer: false,
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000625 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000626 arch: {
627 arm64: {
628 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000629 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000630 },
631 arm: {
632 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000633 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000634 },
635 },
636 stl: "none",
637 system_shared_libs: [],
638}
639
Paul Duffine6029182019-12-16 17:43:48 +0000640module_exports_snapshot {
641 name: "myexports@current",
642 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000643}
644`),
645 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000646include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800647.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
648.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
649.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
650.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
651.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
652.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
653.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
654.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 +0000655`),
656 )
657}
658
659func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
660 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
661 SkipIfNotLinux(t)
662
663 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +0000664 module_exports {
665 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000666 device_supported: false,
667 host_supported: true,
668 native_static_libs: ["mynativelib"],
669 }
670
671 cc_library_static {
672 name: "mynativelib",
673 device_supported: false,
674 host_supported: true,
675 srcs: [
676 "Test.cpp",
677 "aidl/foo/bar/Test.aidl",
678 ],
679 export_include_dirs: ["include"],
680 aidl: {
681 export_aidl_headers: true,
682 },
683 system_shared_libs: [],
684 stl: "none",
685 }
686 `)
687
Paul Duffine6029182019-12-16 17:43:48 +0000688 result.CheckSnapshot("myexports", "linux_glibc_common", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000689 checkAndroidBpContents(`
690// This is auto-generated. DO NOT EDIT.
691
692cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +0000693 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000694 sdk_member_name: "mynativelib",
695 device_supported: false,
696 host_supported: true,
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000697 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000698 arch: {
699 x86_64: {
700 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000701 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000702 },
703 x86: {
704 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000705 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000706 },
707 },
708 stl: "none",
709 system_shared_libs: [],
710}
711
712cc_prebuilt_library_static {
713 name: "mynativelib",
714 prefer: false,
715 device_supported: false,
716 host_supported: true,
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000717 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000718 arch: {
719 x86_64: {
720 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000721 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000722 },
723 x86: {
724 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000725 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000726 },
727 },
728 stl: "none",
729 system_shared_libs: [],
730}
731
Paul Duffine6029182019-12-16 17:43:48 +0000732module_exports_snapshot {
733 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000734 device_supported: false,
735 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +0000736 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +0000737}
738`),
739 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000740include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +0000741.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +0000742.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
743.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
744.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
745.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +0000746.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
747.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
748.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
749`),
750 )
751}
Paul Duffin13ad94f2020-02-19 16:19:27 +0000752
753func TestHostSnapshotWithMultiLib64(t *testing.T) {
754 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
755 SkipIfNotLinux(t)
756
757 result := testSdkWithCc(t, `
758 module_exports {
759 name: "myexports",
760 device_supported: false,
761 host_supported: true,
762 target: {
763 host: {
764 compile_multilib: "64",
765 },
766 },
767 native_static_libs: ["mynativelib"],
768 }
769
770 cc_library_static {
771 name: "mynativelib",
772 device_supported: false,
773 host_supported: true,
774 srcs: [
775 "Test.cpp",
776 "aidl/foo/bar/Test.aidl",
777 ],
778 export_include_dirs: ["include"],
779 aidl: {
780 export_aidl_headers: true,
781 },
782 system_shared_libs: [],
783 stl: "none",
784 }
785 `)
786
787 result.CheckSnapshot("myexports", "linux_glibc_common", "",
788 checkAndroidBpContents(`
789// This is auto-generated. DO NOT EDIT.
790
791cc_prebuilt_library_static {
792 name: "myexports_mynativelib@current",
793 sdk_member_name: "mynativelib",
794 device_supported: false,
795 host_supported: true,
796 export_include_dirs: ["include/include"],
797 arch: {
798 x86_64: {
799 srcs: ["x86_64/lib/mynativelib.a"],
800 export_include_dirs: ["x86_64/include_gen/mynativelib"],
801 },
802 },
803 stl: "none",
804 system_shared_libs: [],
805}
806
807cc_prebuilt_library_static {
808 name: "mynativelib",
809 prefer: false,
810 device_supported: false,
811 host_supported: true,
812 export_include_dirs: ["include/include"],
813 arch: {
814 x86_64: {
815 srcs: ["x86_64/lib/mynativelib.a"],
816 export_include_dirs: ["x86_64/include_gen/mynativelib"],
817 },
818 },
819 stl: "none",
820 system_shared_libs: [],
821}
822
823module_exports_snapshot {
824 name: "myexports@current",
825 device_supported: false,
826 host_supported: true,
827 target: {
828 host: {
829 compile_multilib: "64",
830 },
831 },
832 native_static_libs: ["myexports_mynativelib@current"],
833}`),
834 checkAllCopyRules(`
835include/Test.h -> include/include/Test.h
836.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
837.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
838.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
839.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
840`),
841 )
842}
Paul Duffin91756d22020-02-21 16:29:57 +0000843
844func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
845 result := testSdkWithCc(t, `
846 sdk {
847 name: "mysdk",
848 native_header_libs: ["mynativeheaders"],
849 }
850
851 cc_library_headers {
852 name: "mynativeheaders",
853 export_include_dirs: ["include"],
854 system_shared_libs: [],
855 stl: "none",
856 }
857 `)
858
859 result.CheckSnapshot("mysdk", "android_common", "",
860 checkAndroidBpContents(`
861// This is auto-generated. DO NOT EDIT.
862
863cc_prebuilt_library_headers {
864 name: "mysdk_mynativeheaders@current",
865 sdk_member_name: "mynativeheaders",
866 export_include_dirs: ["include/include"],
867 stl: "none",
868 system_shared_libs: [],
869}
870
871cc_prebuilt_library_headers {
872 name: "mynativeheaders",
873 prefer: false,
874 export_include_dirs: ["include/include"],
875 stl: "none",
876 system_shared_libs: [],
877}
878
879sdk_snapshot {
880 name: "mysdk@current",
881 native_header_libs: ["mysdk_mynativeheaders@current"],
882}
883`),
884 checkAllCopyRules(`
885include/Test.h -> include/include/Test.h
886`),
887 )
888}
889
890func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
891 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
892 SkipIfNotLinux(t)
893
894 result := testSdkWithCc(t, `
895 sdk {
896 name: "mysdk",
897 device_supported: false,
898 host_supported: true,
899 native_header_libs: ["mynativeheaders"],
900 }
901
902 cc_library_headers {
903 name: "mynativeheaders",
904 device_supported: false,
905 host_supported: true,
906 export_include_dirs: ["include"],
907 system_shared_libs: [],
908 stl: "none",
909 }
910 `)
911
912 result.CheckSnapshot("mysdk", "linux_glibc_common", "",
913 checkAndroidBpContents(`
914// This is auto-generated. DO NOT EDIT.
915
916cc_prebuilt_library_headers {
917 name: "mysdk_mynativeheaders@current",
918 sdk_member_name: "mynativeheaders",
919 device_supported: false,
920 host_supported: true,
921 export_include_dirs: ["include/include"],
922 stl: "none",
923 system_shared_libs: [],
924}
925
926cc_prebuilt_library_headers {
927 name: "mynativeheaders",
928 prefer: false,
929 device_supported: false,
930 host_supported: true,
931 export_include_dirs: ["include/include"],
932 stl: "none",
933 system_shared_libs: [],
934}
935
936sdk_snapshot {
937 name: "mysdk@current",
938 device_supported: false,
939 host_supported: true,
940 native_header_libs: ["mysdk_mynativeheaders@current"],
941}
942`),
943 checkAllCopyRules(`
944include/Test.h -> include/include/Test.h
945`),
946 )
947}