blob: 0811ef5301abad3ce7ce566fff69b120f4c279c0 [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 Duffin1356d8c2020-02-25 19:26:33 +000020 "android/soong/android"
Paul Duffina80fdec2019-12-03 15:25:00 +000021 "android/soong/cc"
22)
23
Martin Stjernholm7feceb22020-07-11 04:33:29 +010024var ccTestFs = map[string][]byte{
25 "Test.cpp": nil,
26 "include/Test.h": nil,
27 "include-android/AndroidTest.h": nil,
28 "include-host/HostTest.h": nil,
29 "arm64/include/Arm64Test.h": nil,
30 "libfoo.so": nil,
31 "aidl/foo/bar/Test.aidl": nil,
32 "some/where/stubslib.map.txt": nil,
33}
34
Paul Duffind835daa2019-11-30 17:49:09 +000035func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
36 t.Helper()
Martin Stjernholm7feceb22020-07-11 04:33:29 +010037 return testSdkWithFs(t, bp, ccTestFs)
Paul Duffind835daa2019-11-30 17:49:09 +000038}
39
Paul Duffina80fdec2019-12-03 15:25:00 +000040// Contains tests for SDK members provided by the cc package.
41
Martin Stjernholmcaa47d72020-07-11 04:52:24 +010042func TestSingleDeviceOsAssumption(t *testing.T) {
43 // Mock a module with DeviceSupported() == true.
44 s := &sdk{}
45 android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon)
46
47 osTypes := s.getPossibleOsTypes()
48 if len(osTypes) != 1 {
49 // The snapshot generation assumes there is a single device OS. If more are
50 // added it might need to disable them by default, like it does for host
51 // OS'es.
52 t.Errorf("expected a single device OS, got %v", osTypes)
53 }
54}
55
Paul Duffina80fdec2019-12-03 15:25:00 +000056func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000057 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000058 sdk {
59 name: "mysdk",
60 native_shared_libs: ["sdkmember"],
61 }
62
63 cc_library_shared {
64 name: "sdkmember",
65 srcs: ["Test.cpp"],
Paul Duffina80fdec2019-12-03 15:25:00 +000066 stl: "none",
67 }
68 `)
69
Colin Cross7113d202019-11-20 16:39:12 -080070 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
71 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
Paul Duffina80fdec2019-12-03 15:25:00 +000072
73 var inputs []string
Paul Duffin1356d8c2020-02-25 19:26:33 +000074 buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
Paul Duffina80fdec2019-12-03 15:25:00 +000075 for _, bp := range buildParams {
76 if bp.Input != nil {
77 inputs = append(inputs, bp.Input.String())
78 }
79 }
80
81 // ensure that both 32/64 outputs are inputs of the sdk snapshot
82 ensureListContains(t, inputs, armOutput.String())
83 ensureListContains(t, inputs, arm64Output.String())
84}
85
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010086func TestSdkCompileMultilibOverride(t *testing.T) {
87 result := testSdkWithCc(t, `
88 sdk {
89 name: "mysdk",
Martin Stjernholm89238f42020-07-10 00:14:03 +010090 host_supported: true,
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010091 native_shared_libs: ["sdkmember"],
92 compile_multilib: "64",
93 }
94
95 cc_library_shared {
96 name: "sdkmember",
Martin Stjernholm89238f42020-07-10 00:14:03 +010097 host_supported: true,
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010098 srcs: ["Test.cpp"],
99 stl: "none",
100 compile_multilib: "64",
101 }
102 `)
103
104 result.CheckSnapshot("mysdk", "",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100105 checkAndroidBpContents(`
106// This is auto-generated. DO NOT EDIT.
107
108cc_prebuilt_library_shared {
109 name: "mysdk_sdkmember@current",
110 sdk_member_name: "sdkmember",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100111 host_supported: true,
112 installable: false,
113 stl: "none",
114 compile_multilib: "64",
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100115 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100116 host: {
117 enabled: false,
118 },
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100119 android_arm64: {
120 srcs: ["android/arm64/lib/sdkmember.so"],
121 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100122 linux_glibc: {
123 enabled: true,
124 },
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100125 linux_glibc_x86_64: {
126 srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
Martin Stjernholm89238f42020-07-10 00:14:03 +0100127 },
128 },
129}
130
131cc_prebuilt_library_shared {
132 name: "sdkmember",
133 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +0100134 host_supported: true,
135 stl: "none",
136 compile_multilib: "64",
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100137 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100138 host: {
139 enabled: false,
140 },
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100141 android_arm64: {
142 srcs: ["android/arm64/lib/sdkmember.so"],
143 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100144 linux_glibc: {
145 enabled: true,
146 },
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100147 linux_glibc_x86_64: {
148 srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
Martin Stjernholm89238f42020-07-10 00:14:03 +0100149 },
150 },
151}
152
153sdk_snapshot {
154 name: "mysdk@current",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100155 host_supported: true,
156 native_shared_libs: ["mysdk_sdkmember@current"],
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100157 compile_multilib: "64",
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100158 target: {
159 host: {
160 enabled: false,
161 },
162 linux_glibc: {
163 enabled: true,
164 },
165 },
Martin Stjernholm89238f42020-07-10 00:14:03 +0100166}
167`),
Martin Stjernholm26ab8e82020-06-30 20:34:00 +0100168 checkAllCopyRules(`
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +0100169.intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so
170.intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> linux_glibc/x86_64/lib/sdkmember.so
Martin Stjernholm26ab8e82020-06-30 20:34:00 +0100171`))
172}
173
Paul Duffina80fdec2019-12-03 15:25:00 +0000174func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000175 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000176 sdk {
177 name: "mysdk",
178 native_shared_libs: ["sdkmember"],
179 }
180
Paul Duffina0843f62019-12-13 19:50:38 +0000181 cc_library_shared {
182 name: "sdkmember",
Colin Crossf9aabd72020-02-15 11:29:50 -0800183 system_shared_libs: [],
Martin Stjernholmcc776012020-07-07 03:22:21 +0100184 stl: "none",
185 apex_available: ["mysdkapex"],
Paul Duffina0843f62019-12-13 19:50:38 +0000186 }
187
Paul Duffina80fdec2019-12-03 15:25:00 +0000188 sdk_snapshot {
189 name: "mysdk@1",
190 native_shared_libs: ["sdkmember_mysdk_1"],
191 }
192
193 sdk_snapshot {
194 name: "mysdk@2",
195 native_shared_libs: ["sdkmember_mysdk_2"],
196 }
197
198 cc_prebuilt_library_shared {
199 name: "sdkmember",
200 srcs: ["libfoo.so"],
201 prefer: false,
202 system_shared_libs: [],
203 stl: "none",
204 }
205
206 cc_prebuilt_library_shared {
207 name: "sdkmember_mysdk_1",
208 sdk_member_name: "sdkmember",
209 srcs: ["libfoo.so"],
210 system_shared_libs: [],
211 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000212 // TODO: remove //apex_available:platform
213 apex_available: [
214 "//apex_available:platform",
215 "myapex",
216 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000217 }
218
219 cc_prebuilt_library_shared {
220 name: "sdkmember_mysdk_2",
221 sdk_member_name: "sdkmember",
222 srcs: ["libfoo.so"],
223 system_shared_libs: [],
224 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000225 // TODO: remove //apex_available:platform
226 apex_available: [
227 "//apex_available:platform",
228 "myapex2",
229 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000230 }
231
232 cc_library_shared {
233 name: "mycpplib",
234 srcs: ["Test.cpp"],
235 shared_libs: ["sdkmember"],
236 system_shared_libs: [],
237 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000238 apex_available: [
239 "myapex",
240 "myapex2",
241 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000242 }
243
244 apex {
245 name: "myapex",
246 native_shared_libs: ["mycpplib"],
247 uses_sdks: ["mysdk@1"],
248 key: "myapex.key",
249 certificate: ":myapex.cert",
250 }
251
252 apex {
253 name: "myapex2",
254 native_shared_libs: ["mycpplib"],
255 uses_sdks: ["mysdk@2"],
256 key: "myapex.key",
257 certificate: ":myapex.cert",
258 }
Martin Stjernholmcc776012020-07-07 03:22:21 +0100259
260 apex {
261 name: "mysdkapex",
262 native_shared_libs: ["sdkmember"],
263 key: "myapex.key",
264 certificate: ":myapex.cert",
265 }
Paul Duffina80fdec2019-12-03 15:25:00 +0000266 `)
267
Colin Crossaede88c2020-08-11 12:17:01 -0700268 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_apex10000_mysdk_1").Rule("toc").Output
269 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_apex10000_mysdk_2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000270
Colin Crossaede88c2020-08-11 12:17:01 -0700271 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_apex10000_mysdk_1")
272 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_apex10000_mysdk_2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000273
274 // Depending on the uses_sdks value, different libs are linked
275 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
276 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
277}
278
Paul Duffina0843f62019-12-13 19:50:38 +0000279// Make sure the sdk can use host specific cc libraries static/shared and both.
280func TestHostSdkWithCc(t *testing.T) {
281 testSdkWithCc(t, `
282 sdk {
283 name: "mysdk",
284 device_supported: false,
285 host_supported: true,
286 native_shared_libs: ["sdkshared"],
287 native_static_libs: ["sdkstatic"],
288 }
289
290 cc_library_host_shared {
291 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000292 stl: "none",
293 }
294
295 cc_library_host_static {
296 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000297 stl: "none",
298 }
299 `)
300}
301
302// Make sure the sdk can use cc libraries static/shared and both.
303func TestSdkWithCc(t *testing.T) {
304 testSdkWithCc(t, `
305 sdk {
306 name: "mysdk",
307 native_shared_libs: ["sdkshared", "sdkboth1"],
308 native_static_libs: ["sdkstatic", "sdkboth2"],
309 }
310
311 cc_library_shared {
312 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000313 stl: "none",
314 }
315
316 cc_library_static {
317 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000318 stl: "none",
319 }
320
321 cc_library {
322 name: "sdkboth1",
Paul Duffina0843f62019-12-13 19:50:38 +0000323 stl: "none",
324 }
325
326 cc_library {
327 name: "sdkboth2",
Paul Duffina0843f62019-12-13 19:50:38 +0000328 stl: "none",
329 }
330 `)
331}
332
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000333func TestSnapshotWithObject(t *testing.T) {
334 result := testSdkWithCc(t, `
335 sdk {
336 name: "mysdk",
337 native_objects: ["crtobj"],
338 }
339
340 cc_object {
341 name: "crtobj",
342 stl: "none",
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100343 sanitize: {
344 never: true,
345 },
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000346 }
347 `)
348
349 result.CheckSnapshot("mysdk", "",
350 checkAndroidBpContents(`
351// This is auto-generated. DO NOT EDIT.
352
353cc_prebuilt_object {
354 name: "mysdk_crtobj@current",
355 sdk_member_name: "crtobj",
356 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100357 compile_multilib: "both",
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100358 sanitize: {
359 never: true,
360 },
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000361 arch: {
362 arm64: {
363 srcs: ["arm64/lib/crtobj.o"],
364 },
365 arm: {
366 srcs: ["arm/lib/crtobj.o"],
367 },
368 },
369}
370
371cc_prebuilt_object {
372 name: "crtobj",
373 prefer: false,
374 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100375 compile_multilib: "both",
Martin Stjernholmfbb486f2020-08-21 18:43:51 +0100376 sanitize: {
377 never: true,
378 },
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000379 arch: {
380 arm64: {
381 srcs: ["arm64/lib/crtobj.o"],
382 },
383 arm: {
384 srcs: ["arm/lib/crtobj.o"],
385 },
386 },
387}
388
389sdk_snapshot {
390 name: "mysdk@current",
391 native_objects: ["mysdk_crtobj@current"],
392}
393`),
394 checkAllCopyRules(`
395.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
396.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
397`),
398 )
399}
400
Paul Duffinc62a5102019-12-11 18:34:15 +0000401func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
402 result := testSdkWithCc(t, `
403 sdk {
404 name: "mysdk",
405 native_shared_libs: ["mynativelib1", "mynativelib2"],
406 }
407
408 cc_library_shared {
409 name: "mynativelib1",
410 srcs: [
411 "Test.cpp",
412 ],
413 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000414 stl: "none",
415 }
416
417 cc_library_shared {
418 name: "mynativelib2",
419 srcs: [
420 "Test.cpp",
421 ],
422 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000423 stl: "none",
424 }
425 `)
426
Paul Duffin1356d8c2020-02-25 19:26:33 +0000427 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000428 checkAllCopyRules(`
429include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800430.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
431.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
432.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
433.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000434`),
435 )
436}
437
Paul Duffina7cd8c82019-12-11 20:00:57 +0000438// Verify that when the shared library has some common and some arch specific properties that the generated
439// snapshot is optimized properly.
440func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
441 result := testSdkWithCc(t, `
442 sdk {
443 name: "mysdk",
444 native_shared_libs: ["mynativelib"],
445 }
446
447 cc_library_shared {
448 name: "mynativelib",
449 srcs: [
450 "Test.cpp",
451 "aidl/foo/bar/Test.aidl",
452 ],
453 export_include_dirs: ["include"],
454 arch: {
455 arm64: {
456 export_system_include_dirs: ["arm64/include"],
457 },
458 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000459 stl: "none",
460 }
461 `)
462
Paul Duffin1356d8c2020-02-25 19:26:33 +0000463 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000464 checkAndroidBpContents(`
465// This is auto-generated. DO NOT EDIT.
466
467cc_prebuilt_library_shared {
468 name: "mysdk_mynativelib@current",
469 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000470 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000471 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100472 compile_multilib: "both",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000473 export_include_dirs: ["include/include"],
474 arch: {
475 arm64: {
476 srcs: ["arm64/lib/mynativelib.so"],
477 export_system_include_dirs: ["arm64/include/arm64/include"],
478 },
479 arm: {
480 srcs: ["arm/lib/mynativelib.so"],
481 },
482 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000483}
484
485cc_prebuilt_library_shared {
486 name: "mynativelib",
487 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000488 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100489 compile_multilib: "both",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000490 export_include_dirs: ["include/include"],
491 arch: {
492 arm64: {
493 srcs: ["arm64/lib/mynativelib.so"],
494 export_system_include_dirs: ["arm64/include/arm64/include"],
495 },
496 arm: {
497 srcs: ["arm/lib/mynativelib.so"],
498 },
499 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000500}
501
502sdk_snapshot {
503 name: "mysdk@current",
504 native_shared_libs: ["mysdk_mynativelib@current"],
505}
506`),
507 checkAllCopyRules(`
508include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800509.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000510arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800511.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000512 )
513}
514
Paul Duffin25ce04b2020-01-16 11:47:25 +0000515func TestSnapshotWithCcBinary(t *testing.T) {
516 result := testSdkWithCc(t, `
517 module_exports {
518 name: "mymodule_exports",
519 native_binaries: ["mynativebinary"],
520 }
521
522 cc_binary {
523 name: "mynativebinary",
524 srcs: [
525 "Test.cpp",
526 ],
527 compile_multilib: "both",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000528 }
529 `)
530
Paul Duffin1356d8c2020-02-25 19:26:33 +0000531 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000532 checkAndroidBpContents(`
533// This is auto-generated. DO NOT EDIT.
534
535cc_prebuilt_binary {
536 name: "mymodule_exports_mynativebinary@current",
537 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000538 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000539 compile_multilib: "both",
540 arch: {
541 arm64: {
542 srcs: ["arm64/bin/mynativebinary"],
543 },
544 arm: {
545 srcs: ["arm/bin/mynativebinary"],
546 },
547 },
548}
549
550cc_prebuilt_binary {
551 name: "mynativebinary",
552 prefer: false,
553 compile_multilib: "both",
554 arch: {
555 arm64: {
556 srcs: ["arm64/bin/mynativebinary"],
557 },
558 arm: {
559 srcs: ["arm/bin/mynativebinary"],
560 },
561 },
562}
563
564module_exports_snapshot {
565 name: "mymodule_exports@current",
566 native_binaries: ["mymodule_exports_mynativebinary@current"],
567}
568`),
569 checkAllCopyRules(`
570.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
571.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
572`),
573 )
574}
575
Paul Duffina04c1072020-03-02 10:16:35 +0000576func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +0000577 result := testSdkWithCc(t, `
578 module_exports {
579 name: "myexports",
580 device_supported: false,
581 host_supported: true,
582 native_binaries: ["mynativebinary"],
583 target: {
584 windows: {
585 enabled: true,
586 },
587 },
588 }
589
590 cc_binary {
591 name: "mynativebinary",
592 device_supported: false,
593 host_supported: true,
594 srcs: [
595 "Test.cpp",
596 ],
597 compile_multilib: "both",
Paul Duffina04c1072020-03-02 10:16:35 +0000598 stl: "none",
599 target: {
600 windows: {
601 enabled: true,
602 },
603 },
604 }
605 `)
606
607 result.CheckSnapshot("myexports", "",
608 checkAndroidBpContents(`
609// This is auto-generated. DO NOT EDIT.
610
611cc_prebuilt_binary {
612 name: "myexports_mynativebinary@current",
613 sdk_member_name: "mynativebinary",
614 device_supported: false,
615 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000616 installable: false,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100617 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000618 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100619 host: {
620 enabled: false,
621 },
Paul Duffina04c1072020-03-02 10:16:35 +0000622 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100623 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000624 compile_multilib: "both",
625 },
626 linux_glibc_x86_64: {
627 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
628 },
629 linux_glibc_x86: {
630 srcs: ["linux_glibc/x86/bin/mynativebinary"],
631 },
632 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100633 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000634 compile_multilib: "64",
635 },
636 windows_x86_64: {
637 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
638 },
639 },
640}
641
642cc_prebuilt_binary {
643 name: "mynativebinary",
644 prefer: false,
645 device_supported: false,
646 host_supported: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100647 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000648 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100649 host: {
650 enabled: false,
651 },
Paul Duffina04c1072020-03-02 10:16:35 +0000652 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100653 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000654 compile_multilib: "both",
655 },
656 linux_glibc_x86_64: {
657 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
658 },
659 linux_glibc_x86: {
660 srcs: ["linux_glibc/x86/bin/mynativebinary"],
661 },
662 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100663 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000664 compile_multilib: "64",
665 },
666 windows_x86_64: {
667 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
668 },
669 },
670}
671
672module_exports_snapshot {
673 name: "myexports@current",
674 device_supported: false,
675 host_supported: true,
676 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000677 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100678 host: {
679 enabled: false,
680 },
681 linux_glibc: {
682 enabled: true,
683 },
Paul Duffin6a7e9532020-03-20 17:50:07 +0000684 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100685 enabled: true,
Paul Duffin6a7e9532020-03-20 17:50:07 +0000686 compile_multilib: "64",
687 },
688 },
Paul Duffina04c1072020-03-02 10:16:35 +0000689}
690`),
691 checkAllCopyRules(`
692.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
693.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
694.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
695`),
696 )
697}
698
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100699func TestSnapshotWithSingleHostOsType(t *testing.T) {
700 ctx, config := testSdkContext(`
701 cc_defaults {
702 name: "mydefaults",
703 device_supported: false,
704 host_supported: true,
705 compile_multilib: "64",
706 target: {
707 host: {
708 enabled: false,
709 },
710 linux_bionic: {
711 enabled: true,
712 },
713 },
714 }
715
716 module_exports {
717 name: "myexports",
718 defaults: ["mydefaults"],
719 native_shared_libs: ["mynativelib"],
720 native_binaries: ["mynativebinary"],
721 compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults.
722 }
723
724 cc_library {
725 name: "mynativelib",
726 defaults: ["mydefaults"],
727 srcs: [
728 "Test.cpp",
729 ],
730 stl: "none",
731 }
732
733 cc_binary {
734 name: "mynativebinary",
735 defaults: ["mydefaults"],
736 srcs: [
737 "Test.cpp",
738 ],
739 stl: "none",
740 }
741 `, ccTestFs, []android.OsType{android.LinuxBionic})
742
743 result := runTests(t, ctx, config)
744
745 result.CheckSnapshot("myexports", "",
746 checkAndroidBpContents(`
747// This is auto-generated. DO NOT EDIT.
748
749cc_prebuilt_binary {
750 name: "myexports_mynativebinary@current",
751 sdk_member_name: "mynativebinary",
752 device_supported: false,
753 host_supported: true,
754 installable: false,
755 stl: "none",
756 compile_multilib: "64",
757 target: {
758 host: {
759 enabled: false,
760 },
761 linux_bionic: {
762 enabled: true,
763 },
764 linux_bionic_x86_64: {
765 srcs: ["x86_64/bin/mynativebinary"],
766 },
767 },
768}
769
770cc_prebuilt_binary {
771 name: "mynativebinary",
772 prefer: false,
773 device_supported: false,
774 host_supported: true,
775 stl: "none",
776 compile_multilib: "64",
777 target: {
778 host: {
779 enabled: false,
780 },
781 linux_bionic: {
782 enabled: true,
783 },
784 linux_bionic_x86_64: {
785 srcs: ["x86_64/bin/mynativebinary"],
786 },
787 },
788}
789
790cc_prebuilt_library_shared {
791 name: "myexports_mynativelib@current",
792 sdk_member_name: "mynativelib",
793 device_supported: false,
794 host_supported: true,
795 installable: false,
796 stl: "none",
797 compile_multilib: "64",
798 target: {
799 host: {
800 enabled: false,
801 },
802 linux_bionic: {
803 enabled: true,
804 },
805 linux_bionic_x86_64: {
806 srcs: ["x86_64/lib/mynativelib.so"],
807 },
808 },
809}
810
811cc_prebuilt_library_shared {
812 name: "mynativelib",
813 prefer: false,
814 device_supported: false,
815 host_supported: true,
816 stl: "none",
817 compile_multilib: "64",
818 target: {
819 host: {
820 enabled: false,
821 },
822 linux_bionic: {
823 enabled: true,
824 },
825 linux_bionic_x86_64: {
826 srcs: ["x86_64/lib/mynativelib.so"],
827 },
828 },
829}
830
831module_exports_snapshot {
832 name: "myexports@current",
833 device_supported: false,
834 host_supported: true,
835 native_binaries: ["myexports_mynativebinary@current"],
836 native_shared_libs: ["myexports_mynativelib@current"],
837 compile_multilib: "64",
838 target: {
839 host: {
840 enabled: false,
841 },
842 linux_bionic: {
843 enabled: true,
844 },
845 },
846}
847`),
848 checkAllCopyRules(`
849.intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary
850.intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
851`),
852 )
853}
854
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100855// Test that we support the necessary flags for the linker binary, which is
856// special in several ways.
857func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100858 result := testSdkWithCc(t, `
859 module_exports {
860 name: "mymodule_exports",
861 host_supported: true,
862 device_supported: false,
863 native_binaries: ["linker"],
864 }
865
866 cc_binary {
867 name: "linker",
868 host_supported: true,
869 static_executable: true,
870 nocrt: true,
871 stl: "none",
872 srcs: [
873 "Test.cpp",
874 ],
875 compile_multilib: "both",
876 }
877 `)
878
879 result.CheckSnapshot("mymodule_exports", "",
880 checkAndroidBpContents(`
881// This is auto-generated. DO NOT EDIT.
882
883cc_prebuilt_binary {
884 name: "mymodule_exports_linker@current",
885 sdk_member_name: "linker",
886 device_supported: false,
887 host_supported: true,
888 installable: false,
889 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100890 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100891 static_executable: true,
892 nocrt: true,
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100893 target: {
894 host: {
895 enabled: false,
896 },
897 linux_glibc: {
898 enabled: true,
899 },
900 linux_glibc_x86_64: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100901 srcs: ["x86_64/bin/linker"],
902 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100903 linux_glibc_x86: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100904 srcs: ["x86/bin/linker"],
905 },
906 },
907}
908
909cc_prebuilt_binary {
910 name: "linker",
911 prefer: false,
912 device_supported: false,
913 host_supported: true,
914 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100915 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100916 static_executable: true,
917 nocrt: true,
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100918 target: {
919 host: {
920 enabled: false,
921 },
922 linux_glibc: {
923 enabled: true,
924 },
925 linux_glibc_x86_64: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100926 srcs: ["x86_64/bin/linker"],
927 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100928 linux_glibc_x86: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100929 srcs: ["x86/bin/linker"],
930 },
931 },
932}
933
934module_exports_snapshot {
935 name: "mymodule_exports@current",
936 device_supported: false,
937 host_supported: true,
938 native_binaries: ["mymodule_exports_linker@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100939 target: {
940 host: {
941 enabled: false,
942 },
943 linux_glibc: {
944 enabled: true,
945 },
946 },
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100947}
948`),
949 checkAllCopyRules(`
950.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
951.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
952`),
953 )
954}
955
Paul Duffin9ab556f2019-12-11 18:42:17 +0000956func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000957 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000958 sdk {
959 name: "mysdk",
960 native_shared_libs: ["mynativelib"],
961 }
962
963 cc_library_shared {
964 name: "mynativelib",
965 srcs: [
966 "Test.cpp",
967 "aidl/foo/bar/Test.aidl",
968 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000969 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000970 export_include_dirs: ["include"],
971 aidl: {
972 export_aidl_headers: true,
973 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000974 stl: "none",
975 }
976 `)
977
Paul Duffin1356d8c2020-02-25 19:26:33 +0000978 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000979 checkAndroidBpContents(`
980// This is auto-generated. DO NOT EDIT.
981
982cc_prebuilt_library_shared {
983 name: "mysdk_mynativelib@current",
984 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000985 apex_available: [
986 "apex1",
987 "apex2",
988 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000989 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000990 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100991 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000992 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000993 arch: {
994 arm64: {
995 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000996 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000997 },
998 arm: {
999 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001000 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001001 },
1002 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001003}
1004
1005cc_prebuilt_library_shared {
1006 name: "mynativelib",
1007 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +00001008 apex_available: [
1009 "apex1",
1010 "apex2",
1011 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +00001012 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001013 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001014 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001015 arch: {
1016 arm64: {
1017 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001018 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001019 },
1020 arm: {
1021 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001022 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001023 },
1024 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001025}
1026
1027sdk_snapshot {
1028 name: "mysdk@current",
1029 native_shared_libs: ["mysdk_mynativelib@current"],
1030}
1031`),
1032 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001033include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001034.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1035.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1036.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1037.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1038.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1039.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1040.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1041.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 +00001042`),
1043 )
1044}
1045
Paul Duffin13f02712020-03-06 12:30:43 +00001046func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
1047 result := testSdkWithCc(t, `
1048 sdk {
1049 name: "mysdk",
1050 native_shared_libs: [
1051 "mynativelib",
1052 "myothernativelib",
1053 "mysystemnativelib",
1054 ],
1055 }
1056
1057 cc_library {
1058 name: "mysystemnativelib",
1059 srcs: [
1060 "Test.cpp",
1061 ],
Paul Duffin13f02712020-03-06 12:30:43 +00001062 stl: "none",
1063 }
1064
1065 cc_library_shared {
1066 name: "myothernativelib",
1067 srcs: [
1068 "Test.cpp",
1069 ],
1070 system_shared_libs: [
1071 // A reference to a library that is not an sdk member. Uses libm as that
1072 // is in the default set of modules available to this test and so is available
1073 // both here and also when the generated Android.bp file is tested in
1074 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
1075 // handles references to modules that are not sdk members.
1076 "libm",
1077 ],
1078 stl: "none",
1079 }
1080
1081 cc_library {
1082 name: "mynativelib",
1083 srcs: [
1084 "Test.cpp",
1085 ],
1086 shared_libs: [
1087 // A reference to another sdk member.
1088 "myothernativelib",
1089 ],
1090 target: {
1091 android: {
1092 shared: {
1093 shared_libs: [
1094 // A reference to a library that is not an sdk member. The libc library
1095 // is used here to check that the shared_libs property is handled correctly
1096 // in a similar way to how libm is used to check system_shared_libs above.
1097 "libc",
1098 ],
1099 },
1100 },
1101 },
Paul Duffin13f02712020-03-06 12:30:43 +00001102 stl: "none",
1103 }
1104 `)
1105
1106 result.CheckSnapshot("mysdk", "",
1107 checkAndroidBpContents(`
1108// This is auto-generated. DO NOT EDIT.
1109
1110cc_prebuilt_library_shared {
1111 name: "mysdk_mynativelib@current",
1112 sdk_member_name: "mynativelib",
1113 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001114 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001115 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001116 shared_libs: [
1117 "mysdk_myothernativelib@current",
1118 "libc",
1119 ],
1120 arch: {
1121 arm64: {
1122 srcs: ["arm64/lib/mynativelib.so"],
1123 },
1124 arm: {
1125 srcs: ["arm/lib/mynativelib.so"],
1126 },
1127 },
Paul Duffin13f02712020-03-06 12:30:43 +00001128}
1129
1130cc_prebuilt_library_shared {
1131 name: "mynativelib",
1132 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001133 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001134 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001135 shared_libs: [
1136 "myothernativelib",
1137 "libc",
1138 ],
1139 arch: {
1140 arm64: {
1141 srcs: ["arm64/lib/mynativelib.so"],
1142 },
1143 arm: {
1144 srcs: ["arm/lib/mynativelib.so"],
1145 },
1146 },
Paul Duffin13f02712020-03-06 12:30:43 +00001147}
1148
1149cc_prebuilt_library_shared {
1150 name: "mysdk_myothernativelib@current",
1151 sdk_member_name: "myothernativelib",
1152 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001153 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001154 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001155 system_shared_libs: ["libm"],
1156 arch: {
1157 arm64: {
1158 srcs: ["arm64/lib/myothernativelib.so"],
1159 },
1160 arm: {
1161 srcs: ["arm/lib/myothernativelib.so"],
1162 },
1163 },
Paul Duffin13f02712020-03-06 12:30:43 +00001164}
1165
1166cc_prebuilt_library_shared {
1167 name: "myothernativelib",
1168 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001169 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001170 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001171 system_shared_libs: ["libm"],
1172 arch: {
1173 arm64: {
1174 srcs: ["arm64/lib/myothernativelib.so"],
1175 },
1176 arm: {
1177 srcs: ["arm/lib/myothernativelib.so"],
1178 },
1179 },
Paul Duffin13f02712020-03-06 12:30:43 +00001180}
1181
1182cc_prebuilt_library_shared {
1183 name: "mysdk_mysystemnativelib@current",
1184 sdk_member_name: "mysystemnativelib",
1185 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001186 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001187 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001188 arch: {
1189 arm64: {
1190 srcs: ["arm64/lib/mysystemnativelib.so"],
1191 },
1192 arm: {
1193 srcs: ["arm/lib/mysystemnativelib.so"],
1194 },
1195 },
Paul Duffin13f02712020-03-06 12:30:43 +00001196}
1197
1198cc_prebuilt_library_shared {
1199 name: "mysystemnativelib",
1200 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001201 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001202 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001203 arch: {
1204 arm64: {
1205 srcs: ["arm64/lib/mysystemnativelib.so"],
1206 },
1207 arm: {
1208 srcs: ["arm/lib/mysystemnativelib.so"],
1209 },
1210 },
Paul Duffin13f02712020-03-06 12:30:43 +00001211}
1212
1213sdk_snapshot {
1214 name: "mysdk@current",
1215 native_shared_libs: [
1216 "mysdk_mynativelib@current",
1217 "mysdk_myothernativelib@current",
1218 "mysdk_mysystemnativelib@current",
1219 ],
1220}
1221`),
1222 checkAllCopyRules(`
1223.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1224.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1225.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
1226.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
1227.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
1228.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
1229`),
1230 )
1231}
1232
Paul Duffin9ab556f2019-12-11 18:42:17 +00001233func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +00001234 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +00001235 sdk {
1236 name: "mysdk",
1237 device_supported: false,
1238 host_supported: true,
1239 native_shared_libs: ["mynativelib"],
1240 }
1241
1242 cc_library_shared {
1243 name: "mynativelib",
1244 device_supported: false,
1245 host_supported: true,
1246 srcs: [
1247 "Test.cpp",
1248 "aidl/foo/bar/Test.aidl",
1249 ],
1250 export_include_dirs: ["include"],
1251 aidl: {
1252 export_aidl_headers: true,
1253 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001254 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +00001255 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +00001256 }
1257 `)
1258
Paul Duffin1356d8c2020-02-25 19:26:33 +00001259 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +00001260 checkAndroidBpContents(`
1261// This is auto-generated. DO NOT EDIT.
1262
1263cc_prebuilt_library_shared {
1264 name: "mysdk_mynativelib@current",
1265 sdk_member_name: "mynativelib",
1266 device_supported: false,
1267 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001268 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +00001269 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001270 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001271 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001272 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001273 target: {
1274 host: {
1275 enabled: false,
1276 },
1277 linux_glibc: {
1278 enabled: true,
1279 },
1280 linux_glibc_x86_64: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001281 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001282 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001283 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001284 linux_glibc_x86: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001285 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001286 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001287 },
1288 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001289}
1290
1291cc_prebuilt_library_shared {
1292 name: "mynativelib",
1293 prefer: false,
1294 device_supported: false,
1295 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +00001296 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001297 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001298 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001299 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001300 target: {
1301 host: {
1302 enabled: false,
1303 },
1304 linux_glibc: {
1305 enabled: true,
1306 },
1307 linux_glibc_x86_64: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001308 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001309 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001310 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001311 linux_glibc_x86: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001312 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001313 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001314 },
1315 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001316}
1317
1318sdk_snapshot {
1319 name: "mysdk@current",
1320 device_supported: false,
1321 host_supported: true,
1322 native_shared_libs: ["mysdk_mynativelib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001323 target: {
1324 host: {
1325 enabled: false,
1326 },
1327 linux_glibc: {
1328 enabled: true,
1329 },
1330 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001331}
1332`),
1333 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001334include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +00001335.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001336.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1337.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1338.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1339.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001340.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1341.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1342.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1343`),
1344 )
1345}
Paul Duffin9ab556f2019-12-11 18:42:17 +00001346
Paul Duffina04c1072020-03-02 10:16:35 +00001347func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001348 result := testSdkWithCc(t, `
1349 sdk {
1350 name: "mysdk",
1351 device_supported: false,
1352 host_supported: true,
1353 native_shared_libs: ["mynativelib"],
1354 target: {
1355 windows: {
1356 enabled: true,
1357 },
1358 },
1359 }
1360
1361 cc_library_shared {
1362 name: "mynativelib",
1363 device_supported: false,
1364 host_supported: true,
1365 srcs: [
1366 "Test.cpp",
1367 ],
Paul Duffina04c1072020-03-02 10:16:35 +00001368 stl: "none",
1369 target: {
1370 windows: {
1371 enabled: true,
1372 },
1373 },
1374 }
1375 `)
1376
1377 result.CheckSnapshot("mysdk", "",
1378 checkAndroidBpContents(`
1379// This is auto-generated. DO NOT EDIT.
1380
1381cc_prebuilt_library_shared {
1382 name: "mysdk_mynativelib@current",
1383 sdk_member_name: "mynativelib",
1384 device_supported: false,
1385 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001386 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001387 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001388 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001389 host: {
1390 enabled: false,
1391 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001392 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001393 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001394 compile_multilib: "both",
1395 },
Paul Duffina04c1072020-03-02 10:16:35 +00001396 linux_glibc_x86_64: {
1397 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1398 },
1399 linux_glibc_x86: {
1400 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1401 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001402 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001403 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001404 compile_multilib: "64",
1405 },
Paul Duffina04c1072020-03-02 10:16:35 +00001406 windows_x86_64: {
1407 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1408 },
1409 },
Paul Duffina04c1072020-03-02 10:16:35 +00001410}
1411
1412cc_prebuilt_library_shared {
1413 name: "mynativelib",
1414 prefer: false,
1415 device_supported: false,
1416 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001417 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001418 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001419 host: {
1420 enabled: false,
1421 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001422 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001423 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001424 compile_multilib: "both",
1425 },
Paul Duffina04c1072020-03-02 10:16:35 +00001426 linux_glibc_x86_64: {
1427 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1428 },
1429 linux_glibc_x86: {
1430 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1431 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001432 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001433 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001434 compile_multilib: "64",
1435 },
Paul Duffina04c1072020-03-02 10:16:35 +00001436 windows_x86_64: {
1437 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1438 },
1439 },
Paul Duffina04c1072020-03-02 10:16:35 +00001440}
1441
1442sdk_snapshot {
1443 name: "mysdk@current",
1444 device_supported: false,
1445 host_supported: true,
1446 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001447 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001448 host: {
1449 enabled: false,
1450 },
1451 linux_glibc: {
1452 enabled: true,
1453 },
Paul Duffin6a7e9532020-03-20 17:50:07 +00001454 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001455 enabled: true,
Paul Duffin6a7e9532020-03-20 17:50:07 +00001456 compile_multilib: "64",
1457 },
1458 },
Paul Duffina04c1072020-03-02 10:16:35 +00001459}
1460`),
1461 checkAllCopyRules(`
1462.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1463.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1464.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1465`),
1466 )
1467}
1468
Paul Duffin9ab556f2019-12-11 18:42:17 +00001469func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1470 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001471 module_exports {
1472 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001473 native_static_libs: ["mynativelib"],
1474 }
1475
1476 cc_library_static {
1477 name: "mynativelib",
1478 srcs: [
1479 "Test.cpp",
1480 "aidl/foo/bar/Test.aidl",
1481 ],
1482 export_include_dirs: ["include"],
1483 aidl: {
1484 export_aidl_headers: true,
1485 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001486 stl: "none",
1487 }
1488 `)
1489
Paul Duffin1356d8c2020-02-25 19:26:33 +00001490 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001491 checkAndroidBpContents(`
1492// This is auto-generated. DO NOT EDIT.
1493
1494cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001495 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001496 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001497 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001498 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001499 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001500 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001501 arch: {
1502 arm64: {
1503 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001504 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001505 },
1506 arm: {
1507 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001508 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001509 },
1510 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001511}
1512
1513cc_prebuilt_library_static {
1514 name: "mynativelib",
1515 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001516 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001517 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001518 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001519 arch: {
1520 arm64: {
1521 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001522 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001523 },
1524 arm: {
1525 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001526 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001527 },
1528 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001529}
1530
Paul Duffine6029182019-12-16 17:43:48 +00001531module_exports_snapshot {
1532 name: "myexports@current",
1533 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001534}
1535`),
1536 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001537include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001538.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1539.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1540.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1541.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1542.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1543.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1544.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1545.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 +00001546`),
1547 )
1548}
1549
1550func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001551 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001552 module_exports {
1553 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001554 device_supported: false,
1555 host_supported: true,
1556 native_static_libs: ["mynativelib"],
1557 }
1558
1559 cc_library_static {
1560 name: "mynativelib",
1561 device_supported: false,
1562 host_supported: true,
1563 srcs: [
1564 "Test.cpp",
1565 "aidl/foo/bar/Test.aidl",
1566 ],
1567 export_include_dirs: ["include"],
1568 aidl: {
1569 export_aidl_headers: true,
1570 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001571 stl: "none",
1572 }
1573 `)
1574
Paul Duffin1356d8c2020-02-25 19:26:33 +00001575 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001576 checkAndroidBpContents(`
1577// This is auto-generated. DO NOT EDIT.
1578
1579cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001580 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001581 sdk_member_name: "mynativelib",
1582 device_supported: false,
1583 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001584 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001585 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001586 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001587 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001588 target: {
1589 host: {
1590 enabled: false,
1591 },
1592 linux_glibc: {
1593 enabled: true,
1594 },
1595 linux_glibc_x86_64: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001596 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001597 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001598 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001599 linux_glibc_x86: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001600 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001601 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001602 },
1603 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001604}
1605
1606cc_prebuilt_library_static {
1607 name: "mynativelib",
1608 prefer: false,
1609 device_supported: false,
1610 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001611 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001612 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001613 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001614 target: {
1615 host: {
1616 enabled: false,
1617 },
1618 linux_glibc: {
1619 enabled: true,
1620 },
1621 linux_glibc_x86_64: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001622 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001623 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001624 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001625 linux_glibc_x86: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001626 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001627 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001628 },
1629 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001630}
1631
Paul Duffine6029182019-12-16 17:43:48 +00001632module_exports_snapshot {
1633 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001634 device_supported: false,
1635 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001636 native_static_libs: ["myexports_mynativelib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001637 target: {
1638 host: {
1639 enabled: false,
1640 },
1641 linux_glibc: {
1642 enabled: true,
1643 },
1644 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001645}
1646`),
1647 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001648include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001649.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001650.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1651.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1652.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1653.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001654.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1655.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1656.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1657`),
1658 )
1659}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001660
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001661func TestSnapshotWithCcLibrary(t *testing.T) {
1662 result := testSdkWithCc(t, `
1663 module_exports {
1664 name: "myexports",
1665 native_libs: ["mynativelib"],
1666 }
1667
1668 cc_library {
1669 name: "mynativelib",
1670 srcs: [
1671 "Test.cpp",
1672 ],
1673 export_include_dirs: ["include"],
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001674 stl: "none",
Paul Duffind1edbd42020-08-13 19:45:31 +01001675 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001676 }
1677 `)
1678
1679 result.CheckSnapshot("myexports", "",
1680 checkAndroidBpContents(`
1681// This is auto-generated. DO NOT EDIT.
1682
1683cc_prebuilt_library {
1684 name: "myexports_mynativelib@current",
1685 sdk_member_name: "mynativelib",
1686 installable: false,
Paul Duffind1edbd42020-08-13 19:45:31 +01001687 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001688 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001689 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001690 export_include_dirs: ["include/include"],
1691 arch: {
1692 arm64: {
1693 static: {
1694 srcs: ["arm64/lib/mynativelib.a"],
1695 },
1696 shared: {
1697 srcs: ["arm64/lib/mynativelib.so"],
1698 },
1699 },
1700 arm: {
1701 static: {
1702 srcs: ["arm/lib/mynativelib.a"],
1703 },
1704 shared: {
1705 srcs: ["arm/lib/mynativelib.so"],
1706 },
1707 },
1708 },
1709}
1710
1711cc_prebuilt_library {
1712 name: "mynativelib",
1713 prefer: false,
Paul Duffind1edbd42020-08-13 19:45:31 +01001714 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001715 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001716 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001717 export_include_dirs: ["include/include"],
1718 arch: {
1719 arm64: {
1720 static: {
1721 srcs: ["arm64/lib/mynativelib.a"],
1722 },
1723 shared: {
1724 srcs: ["arm64/lib/mynativelib.so"],
1725 },
1726 },
1727 arm: {
1728 static: {
1729 srcs: ["arm/lib/mynativelib.a"],
1730 },
1731 shared: {
1732 srcs: ["arm/lib/mynativelib.so"],
1733 },
1734 },
1735 },
1736}
1737
1738module_exports_snapshot {
1739 name: "myexports@current",
1740 native_libs: ["myexports_mynativelib@current"],
1741}
1742`),
1743 checkAllCopyRules(`
1744include/Test.h -> include/include/Test.h
1745.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1746.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1747.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1748.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1749 )
1750}
1751
Paul Duffin13ad94f2020-02-19 16:19:27 +00001752func TestHostSnapshotWithMultiLib64(t *testing.T) {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001753 result := testSdkWithCc(t, `
1754 module_exports {
1755 name: "myexports",
1756 device_supported: false,
1757 host_supported: true,
1758 target: {
1759 host: {
1760 compile_multilib: "64",
1761 },
1762 },
1763 native_static_libs: ["mynativelib"],
1764 }
1765
1766 cc_library_static {
1767 name: "mynativelib",
1768 device_supported: false,
1769 host_supported: true,
1770 srcs: [
1771 "Test.cpp",
1772 "aidl/foo/bar/Test.aidl",
1773 ],
1774 export_include_dirs: ["include"],
1775 aidl: {
1776 export_aidl_headers: true,
1777 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001778 stl: "none",
1779 }
1780 `)
1781
Paul Duffin1356d8c2020-02-25 19:26:33 +00001782 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001783 checkAndroidBpContents(`
1784// This is auto-generated. DO NOT EDIT.
1785
1786cc_prebuilt_library_static {
1787 name: "myexports_mynativelib@current",
1788 sdk_member_name: "mynativelib",
1789 device_supported: false,
1790 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001791 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001792 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001793 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001794 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001795 target: {
1796 host: {
1797 enabled: false,
1798 },
1799 linux_glibc: {
1800 enabled: true,
1801 },
1802 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001803 srcs: ["x86_64/lib/mynativelib.a"],
1804 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1805 },
1806 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001807}
1808
1809cc_prebuilt_library_static {
1810 name: "mynativelib",
1811 prefer: false,
1812 device_supported: false,
1813 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001814 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001815 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001816 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001817 target: {
1818 host: {
1819 enabled: false,
1820 },
1821 linux_glibc: {
1822 enabled: true,
1823 },
1824 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001825 srcs: ["x86_64/lib/mynativelib.a"],
1826 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1827 },
1828 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001829}
1830
1831module_exports_snapshot {
1832 name: "myexports@current",
1833 device_supported: false,
1834 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001835 native_static_libs: ["myexports_mynativelib@current"],
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +01001836 compile_multilib: "64",
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001837 target: {
1838 host: {
1839 enabled: false,
1840 },
1841 linux_glibc: {
1842 enabled: true,
1843 },
1844 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001845}`),
1846 checkAllCopyRules(`
1847include/Test.h -> include/include/Test.h
1848.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1849.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1850.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1851.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1852`),
1853 )
1854}
Paul Duffin91756d22020-02-21 16:29:57 +00001855
1856func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1857 result := testSdkWithCc(t, `
1858 sdk {
1859 name: "mysdk",
1860 native_header_libs: ["mynativeheaders"],
1861 }
1862
1863 cc_library_headers {
1864 name: "mynativeheaders",
1865 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001866 stl: "none",
1867 }
1868 `)
1869
Paul Duffin1356d8c2020-02-25 19:26:33 +00001870 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001871 checkAndroidBpContents(`
1872// This is auto-generated. DO NOT EDIT.
1873
1874cc_prebuilt_library_headers {
1875 name: "mysdk_mynativeheaders@current",
1876 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001877 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001878 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001879 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001880}
1881
1882cc_prebuilt_library_headers {
1883 name: "mynativeheaders",
1884 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001885 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001886 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001887 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001888}
1889
1890sdk_snapshot {
1891 name: "mysdk@current",
1892 native_header_libs: ["mysdk_mynativeheaders@current"],
1893}
1894`),
1895 checkAllCopyRules(`
1896include/Test.h -> include/include/Test.h
1897`),
1898 )
1899}
1900
1901func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffin91756d22020-02-21 16:29:57 +00001902 result := testSdkWithCc(t, `
1903 sdk {
1904 name: "mysdk",
1905 device_supported: false,
1906 host_supported: true,
1907 native_header_libs: ["mynativeheaders"],
1908 }
1909
1910 cc_library_headers {
1911 name: "mynativeheaders",
1912 device_supported: false,
1913 host_supported: true,
1914 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001915 stl: "none",
1916 }
1917 `)
1918
Paul Duffin1356d8c2020-02-25 19:26:33 +00001919 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001920 checkAndroidBpContents(`
1921// This is auto-generated. DO NOT EDIT.
1922
1923cc_prebuilt_library_headers {
1924 name: "mysdk_mynativeheaders@current",
1925 sdk_member_name: "mynativeheaders",
1926 device_supported: false,
1927 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001928 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001929 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001930 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001931 target: {
1932 host: {
1933 enabled: false,
1934 },
1935 linux_glibc: {
1936 enabled: true,
1937 },
1938 },
Paul Duffin91756d22020-02-21 16:29:57 +00001939}
1940
1941cc_prebuilt_library_headers {
1942 name: "mynativeheaders",
1943 prefer: false,
1944 device_supported: false,
1945 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001946 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001947 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001948 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001949 target: {
1950 host: {
1951 enabled: false,
1952 },
1953 linux_glibc: {
1954 enabled: true,
1955 },
1956 },
Paul Duffin91756d22020-02-21 16:29:57 +00001957}
1958
1959sdk_snapshot {
1960 name: "mysdk@current",
1961 device_supported: false,
1962 host_supported: true,
1963 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001964 target: {
1965 host: {
1966 enabled: false,
1967 },
1968 linux_glibc: {
1969 enabled: true,
1970 },
1971 },
Paul Duffin91756d22020-02-21 16:29:57 +00001972}
1973`),
1974 checkAllCopyRules(`
1975include/Test.h -> include/include/Test.h
1976`),
1977 )
1978}
Paul Duffina04c1072020-03-02 10:16:35 +00001979
1980func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001981 result := testSdkWithCc(t, `
1982 sdk {
1983 name: "mysdk",
1984 host_supported: true,
1985 native_header_libs: ["mynativeheaders"],
1986 }
1987
1988 cc_library_headers {
1989 name: "mynativeheaders",
1990 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001991 stl: "none",
1992 export_system_include_dirs: ["include"],
1993 target: {
1994 android: {
1995 export_include_dirs: ["include-android"],
1996 },
1997 host: {
1998 export_include_dirs: ["include-host"],
1999 },
2000 },
2001 }
2002 `)
2003
2004 result.CheckSnapshot("mysdk", "",
2005 checkAndroidBpContents(`
2006// This is auto-generated. DO NOT EDIT.
2007
2008cc_prebuilt_library_headers {
2009 name: "mysdk_mynativeheaders@current",
2010 sdk_member_name: "mynativeheaders",
2011 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002012 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002013 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002014 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002015 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002016 host: {
2017 enabled: false,
2018 },
Paul Duffina04c1072020-03-02 10:16:35 +00002019 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002020 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002021 },
2022 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002023 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002024 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002025 },
2026 },
Paul Duffina04c1072020-03-02 10:16:35 +00002027}
2028
2029cc_prebuilt_library_headers {
2030 name: "mynativeheaders",
2031 prefer: false,
2032 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002033 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002034 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002035 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002036 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002037 host: {
2038 enabled: false,
2039 },
Paul Duffina04c1072020-03-02 10:16:35 +00002040 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002041 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002042 },
2043 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002044 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002045 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002046 },
2047 },
Paul Duffina04c1072020-03-02 10:16:35 +00002048}
2049
2050sdk_snapshot {
2051 name: "mysdk@current",
2052 host_supported: true,
2053 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002054 target: {
2055 host: {
2056 enabled: false,
2057 },
2058 linux_glibc: {
2059 enabled: true,
2060 },
2061 },
Paul Duffina04c1072020-03-02 10:16:35 +00002062}
2063`),
2064 checkAllCopyRules(`
Paul Duffined62b9c2020-06-16 16:12:50 +01002065include/Test.h -> common_os/include/include/Test.h
2066include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
2067include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
Paul Duffina04c1072020-03-02 10:16:35 +00002068`),
2069 )
2070}
Martin Stjernholm10566a02020-03-24 01:19:52 +00002071
2072func TestSystemSharedLibPropagation(t *testing.T) {
2073 result := testSdkWithCc(t, `
2074 sdk {
2075 name: "mysdk",
2076 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
2077 }
2078
2079 cc_library {
2080 name: "sslnil",
2081 host_supported: true,
2082 }
2083
2084 cc_library {
2085 name: "sslempty",
2086 system_shared_libs: [],
2087 }
2088
2089 cc_library {
2090 name: "sslnonempty",
2091 system_shared_libs: ["sslnil"],
2092 }
2093 `)
2094
2095 result.CheckSnapshot("mysdk", "",
2096 checkAndroidBpContents(`
2097// This is auto-generated. DO NOT EDIT.
2098
2099cc_prebuilt_library_shared {
2100 name: "mysdk_sslnil@current",
2101 sdk_member_name: "sslnil",
2102 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002103 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002104 arch: {
2105 arm64: {
2106 srcs: ["arm64/lib/sslnil.so"],
2107 },
2108 arm: {
2109 srcs: ["arm/lib/sslnil.so"],
2110 },
2111 },
2112}
2113
2114cc_prebuilt_library_shared {
2115 name: "sslnil",
2116 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002117 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002118 arch: {
2119 arm64: {
2120 srcs: ["arm64/lib/sslnil.so"],
2121 },
2122 arm: {
2123 srcs: ["arm/lib/sslnil.so"],
2124 },
2125 },
2126}
2127
2128cc_prebuilt_library_shared {
2129 name: "mysdk_sslempty@current",
2130 sdk_member_name: "sslempty",
2131 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002132 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002133 system_shared_libs: [],
2134 arch: {
2135 arm64: {
2136 srcs: ["arm64/lib/sslempty.so"],
2137 },
2138 arm: {
2139 srcs: ["arm/lib/sslempty.so"],
2140 },
2141 },
2142}
2143
2144cc_prebuilt_library_shared {
2145 name: "sslempty",
2146 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002147 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002148 system_shared_libs: [],
2149 arch: {
2150 arm64: {
2151 srcs: ["arm64/lib/sslempty.so"],
2152 },
2153 arm: {
2154 srcs: ["arm/lib/sslempty.so"],
2155 },
2156 },
2157}
2158
2159cc_prebuilt_library_shared {
2160 name: "mysdk_sslnonempty@current",
2161 sdk_member_name: "sslnonempty",
2162 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002163 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002164 system_shared_libs: ["mysdk_sslnil@current"],
2165 arch: {
2166 arm64: {
2167 srcs: ["arm64/lib/sslnonempty.so"],
2168 },
2169 arm: {
2170 srcs: ["arm/lib/sslnonempty.so"],
2171 },
2172 },
2173}
2174
2175cc_prebuilt_library_shared {
2176 name: "sslnonempty",
2177 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002178 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002179 system_shared_libs: ["sslnil"],
2180 arch: {
2181 arm64: {
2182 srcs: ["arm64/lib/sslnonempty.so"],
2183 },
2184 arm: {
2185 srcs: ["arm/lib/sslnonempty.so"],
2186 },
2187 },
2188}
2189
2190sdk_snapshot {
2191 name: "mysdk@current",
2192 native_shared_libs: [
2193 "mysdk_sslnil@current",
2194 "mysdk_sslempty@current",
2195 "mysdk_sslnonempty@current",
2196 ],
2197}
2198`))
2199
2200 result = testSdkWithCc(t, `
2201 sdk {
2202 name: "mysdk",
2203 host_supported: true,
2204 native_shared_libs: ["sslvariants"],
2205 }
2206
2207 cc_library {
2208 name: "sslvariants",
2209 host_supported: true,
2210 target: {
2211 android: {
2212 system_shared_libs: [],
2213 },
2214 },
2215 }
2216 `)
2217
2218 result.CheckSnapshot("mysdk", "",
2219 checkAndroidBpContents(`
2220// This is auto-generated. DO NOT EDIT.
2221
2222cc_prebuilt_library_shared {
2223 name: "mysdk_sslvariants@current",
2224 sdk_member_name: "sslvariants",
2225 host_supported: true,
2226 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002227 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002228 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002229 host: {
2230 enabled: false,
2231 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002232 android: {
2233 system_shared_libs: [],
2234 },
2235 android_arm64: {
2236 srcs: ["android/arm64/lib/sslvariants.so"],
2237 },
2238 android_arm: {
2239 srcs: ["android/arm/lib/sslvariants.so"],
2240 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002241 linux_glibc: {
2242 enabled: true,
2243 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002244 linux_glibc_x86_64: {
2245 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2246 },
2247 linux_glibc_x86: {
2248 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2249 },
2250 },
2251}
2252
2253cc_prebuilt_library_shared {
2254 name: "sslvariants",
2255 prefer: false,
2256 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002257 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002258 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002259 host: {
2260 enabled: false,
2261 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002262 android: {
2263 system_shared_libs: [],
2264 },
2265 android_arm64: {
2266 srcs: ["android/arm64/lib/sslvariants.so"],
2267 },
2268 android_arm: {
2269 srcs: ["android/arm/lib/sslvariants.so"],
2270 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002271 linux_glibc: {
2272 enabled: true,
2273 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002274 linux_glibc_x86_64: {
2275 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2276 },
2277 linux_glibc_x86: {
2278 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2279 },
2280 },
2281}
2282
2283sdk_snapshot {
2284 name: "mysdk@current",
2285 host_supported: true,
2286 native_shared_libs: ["mysdk_sslvariants@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002287 target: {
2288 host: {
2289 enabled: false,
2290 },
2291 linux_glibc: {
2292 enabled: true,
2293 },
2294 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002295}
2296`))
2297}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002298
2299func TestStubsLibrary(t *testing.T) {
2300 result := testSdkWithCc(t, `
2301 sdk {
2302 name: "mysdk",
2303 native_shared_libs: ["stubslib"],
2304 }
2305
2306 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002307 name: "internaldep",
2308 }
2309
2310 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002311 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002312 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002313 stubs: {
2314 symbol_file: "some/where/stubslib.map.txt",
2315 versions: ["1", "2", "3"],
2316 },
2317 }
2318 `)
2319
2320 result.CheckSnapshot("mysdk", "",
2321 checkAndroidBpContents(`
2322// This is auto-generated. DO NOT EDIT.
2323
2324cc_prebuilt_library_shared {
2325 name: "mysdk_stubslib@current",
2326 sdk_member_name: "stubslib",
2327 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002328 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002329 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002330 versions: ["3"],
2331 },
2332 arch: {
2333 arm64: {
2334 srcs: ["arm64/lib/stubslib.so"],
2335 },
2336 arm: {
2337 srcs: ["arm/lib/stubslib.so"],
2338 },
2339 },
2340}
2341
2342cc_prebuilt_library_shared {
2343 name: "stubslib",
2344 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002345 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002346 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002347 versions: ["3"],
2348 },
2349 arch: {
2350 arm64: {
2351 srcs: ["arm64/lib/stubslib.so"],
2352 },
2353 arm: {
2354 srcs: ["arm/lib/stubslib.so"],
2355 },
2356 },
2357}
2358
2359sdk_snapshot {
2360 name: "mysdk@current",
2361 native_shared_libs: ["mysdk_stubslib@current"],
2362}
2363`))
2364}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002365
2366func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002367 result := testSdkWithCc(t, `
2368 sdk {
2369 name: "mysdk",
2370 host_supported: true,
2371 native_shared_libs: ["stubslib"],
2372 }
2373
2374 cc_library {
2375 name: "internaldep",
2376 host_supported: true,
2377 }
2378
2379 cc_library {
2380 name: "stubslib",
2381 host_supported: true,
2382 shared_libs: ["internaldep"],
2383 stubs: {
2384 symbol_file: "some/where/stubslib.map.txt",
2385 versions: ["1", "2", "3"],
2386 },
2387 }
2388 `)
2389
2390 result.CheckSnapshot("mysdk", "",
2391 checkAndroidBpContents(`
2392// This is auto-generated. DO NOT EDIT.
2393
2394cc_prebuilt_library_shared {
2395 name: "mysdk_stubslib@current",
2396 sdk_member_name: "stubslib",
2397 host_supported: true,
2398 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002399 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002400 stubs: {
2401 versions: ["3"],
2402 },
2403 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002404 host: {
2405 enabled: false,
2406 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002407 android_arm64: {
2408 srcs: ["android/arm64/lib/stubslib.so"],
2409 },
2410 android_arm: {
2411 srcs: ["android/arm/lib/stubslib.so"],
2412 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002413 linux_glibc: {
2414 enabled: true,
2415 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002416 linux_glibc_x86_64: {
2417 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2418 },
2419 linux_glibc_x86: {
2420 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2421 },
2422 },
2423}
2424
2425cc_prebuilt_library_shared {
2426 name: "stubslib",
2427 prefer: false,
2428 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002429 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002430 stubs: {
2431 versions: ["3"],
2432 },
2433 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002434 host: {
2435 enabled: false,
2436 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002437 android_arm64: {
2438 srcs: ["android/arm64/lib/stubslib.so"],
2439 },
2440 android_arm: {
2441 srcs: ["android/arm/lib/stubslib.so"],
2442 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002443 linux_glibc: {
2444 enabled: true,
2445 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002446 linux_glibc_x86_64: {
2447 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2448 },
2449 linux_glibc_x86: {
2450 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2451 },
2452 },
2453}
2454
2455sdk_snapshot {
2456 name: "mysdk@current",
2457 host_supported: true,
2458 native_shared_libs: ["mysdk_stubslib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002459 target: {
2460 host: {
2461 enabled: false,
2462 },
2463 linux_glibc: {
2464 enabled: true,
2465 },
2466 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002467}
2468`))
2469}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002470
2471func TestUniqueHostSoname(t *testing.T) {
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002472 result := testSdkWithCc(t, `
2473 sdk {
2474 name: "mysdk",
2475 host_supported: true,
2476 native_shared_libs: ["mylib"],
2477 }
2478
2479 cc_library {
2480 name: "mylib",
2481 host_supported: true,
2482 unique_host_soname: true,
2483 }
2484 `)
2485
2486 result.CheckSnapshot("mysdk", "",
2487 checkAndroidBpContents(`
2488// This is auto-generated. DO NOT EDIT.
2489
2490cc_prebuilt_library_shared {
2491 name: "mysdk_mylib@current",
2492 sdk_member_name: "mylib",
2493 host_supported: true,
2494 installable: false,
2495 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002496 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002497 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002498 host: {
2499 enabled: false,
2500 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002501 android_arm64: {
2502 srcs: ["android/arm64/lib/mylib.so"],
2503 },
2504 android_arm: {
2505 srcs: ["android/arm/lib/mylib.so"],
2506 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002507 linux_glibc: {
2508 enabled: true,
2509 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002510 linux_glibc_x86_64: {
2511 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2512 },
2513 linux_glibc_x86: {
2514 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2515 },
2516 },
2517}
2518
2519cc_prebuilt_library_shared {
2520 name: "mylib",
2521 prefer: false,
2522 host_supported: true,
2523 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002524 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002525 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002526 host: {
2527 enabled: false,
2528 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002529 android_arm64: {
2530 srcs: ["android/arm64/lib/mylib.so"],
2531 },
2532 android_arm: {
2533 srcs: ["android/arm/lib/mylib.so"],
2534 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002535 linux_glibc: {
2536 enabled: true,
2537 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002538 linux_glibc_x86_64: {
2539 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2540 },
2541 linux_glibc_x86: {
2542 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2543 },
2544 },
2545}
2546
2547sdk_snapshot {
2548 name: "mysdk@current",
2549 host_supported: true,
2550 native_shared_libs: ["mysdk_mylib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002551 target: {
2552 host: {
2553 enabled: false,
2554 },
2555 linux_glibc: {
2556 enabled: true,
2557 },
2558 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002559}
2560`),
2561 checkAllCopyRules(`
2562.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2563.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2564.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2565.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2566`),
2567 )
2568}