blob: a12bc6f91be2bbbcf8a609b4b39b9f7ebcf0da6e [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 Duffind6abaa72020-09-07 16:39:22 +01001675 recovery_available: true,
Paul Duffind1edbd42020-08-13 19:45:31 +01001676 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001677 }
1678 `)
1679
1680 result.CheckSnapshot("myexports", "",
1681 checkAndroidBpContents(`
1682// This is auto-generated. DO NOT EDIT.
1683
1684cc_prebuilt_library {
1685 name: "myexports_mynativelib@current",
1686 sdk_member_name: "mynativelib",
1687 installable: false,
Paul Duffind6abaa72020-09-07 16:39:22 +01001688 recovery_available: true,
Paul Duffind1edbd42020-08-13 19:45:31 +01001689 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001690 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001691 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001692 export_include_dirs: ["include/include"],
1693 arch: {
1694 arm64: {
1695 static: {
1696 srcs: ["arm64/lib/mynativelib.a"],
1697 },
1698 shared: {
1699 srcs: ["arm64/lib/mynativelib.so"],
1700 },
1701 },
1702 arm: {
1703 static: {
1704 srcs: ["arm/lib/mynativelib.a"],
1705 },
1706 shared: {
1707 srcs: ["arm/lib/mynativelib.so"],
1708 },
1709 },
1710 },
1711}
1712
1713cc_prebuilt_library {
1714 name: "mynativelib",
1715 prefer: false,
Paul Duffind6abaa72020-09-07 16:39:22 +01001716 recovery_available: true,
Paul Duffind1edbd42020-08-13 19:45:31 +01001717 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001718 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001719 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001720 export_include_dirs: ["include/include"],
1721 arch: {
1722 arm64: {
1723 static: {
1724 srcs: ["arm64/lib/mynativelib.a"],
1725 },
1726 shared: {
1727 srcs: ["arm64/lib/mynativelib.so"],
1728 },
1729 },
1730 arm: {
1731 static: {
1732 srcs: ["arm/lib/mynativelib.a"],
1733 },
1734 shared: {
1735 srcs: ["arm/lib/mynativelib.so"],
1736 },
1737 },
1738 },
1739}
1740
1741module_exports_snapshot {
1742 name: "myexports@current",
1743 native_libs: ["myexports_mynativelib@current"],
1744}
1745`),
1746 checkAllCopyRules(`
1747include/Test.h -> include/include/Test.h
1748.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1749.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1750.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1751.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1752 )
1753}
1754
Paul Duffin13ad94f2020-02-19 16:19:27 +00001755func TestHostSnapshotWithMultiLib64(t *testing.T) {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001756 result := testSdkWithCc(t, `
1757 module_exports {
1758 name: "myexports",
1759 device_supported: false,
1760 host_supported: true,
1761 target: {
1762 host: {
1763 compile_multilib: "64",
1764 },
1765 },
1766 native_static_libs: ["mynativelib"],
1767 }
1768
1769 cc_library_static {
1770 name: "mynativelib",
1771 device_supported: false,
1772 host_supported: true,
1773 srcs: [
1774 "Test.cpp",
1775 "aidl/foo/bar/Test.aidl",
1776 ],
1777 export_include_dirs: ["include"],
1778 aidl: {
1779 export_aidl_headers: true,
1780 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001781 stl: "none",
1782 }
1783 `)
1784
Paul Duffin1356d8c2020-02-25 19:26:33 +00001785 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001786 checkAndroidBpContents(`
1787// This is auto-generated. DO NOT EDIT.
1788
1789cc_prebuilt_library_static {
1790 name: "myexports_mynativelib@current",
1791 sdk_member_name: "mynativelib",
1792 device_supported: false,
1793 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001794 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001795 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001796 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001797 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001798 target: {
1799 host: {
1800 enabled: false,
1801 },
1802 linux_glibc: {
1803 enabled: true,
1804 },
1805 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001806 srcs: ["x86_64/lib/mynativelib.a"],
1807 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1808 },
1809 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001810}
1811
1812cc_prebuilt_library_static {
1813 name: "mynativelib",
1814 prefer: false,
1815 device_supported: false,
1816 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001817 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001818 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001819 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001820 target: {
1821 host: {
1822 enabled: false,
1823 },
1824 linux_glibc: {
1825 enabled: true,
1826 },
1827 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001828 srcs: ["x86_64/lib/mynativelib.a"],
1829 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1830 },
1831 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001832}
1833
1834module_exports_snapshot {
1835 name: "myexports@current",
1836 device_supported: false,
1837 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001838 native_static_libs: ["myexports_mynativelib@current"],
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +01001839 compile_multilib: "64",
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001840 target: {
1841 host: {
1842 enabled: false,
1843 },
1844 linux_glibc: {
1845 enabled: true,
1846 },
1847 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001848}`),
1849 checkAllCopyRules(`
1850include/Test.h -> include/include/Test.h
1851.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1852.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1853.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1854.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1855`),
1856 )
1857}
Paul Duffin91756d22020-02-21 16:29:57 +00001858
1859func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1860 result := testSdkWithCc(t, `
1861 sdk {
1862 name: "mysdk",
1863 native_header_libs: ["mynativeheaders"],
1864 }
1865
1866 cc_library_headers {
1867 name: "mynativeheaders",
1868 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001869 stl: "none",
1870 }
1871 `)
1872
Paul Duffin1356d8c2020-02-25 19:26:33 +00001873 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001874 checkAndroidBpContents(`
1875// This is auto-generated. DO NOT EDIT.
1876
1877cc_prebuilt_library_headers {
1878 name: "mysdk_mynativeheaders@current",
1879 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001880 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001881 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001882 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001883}
1884
1885cc_prebuilt_library_headers {
1886 name: "mynativeheaders",
1887 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001888 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001889 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001890 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001891}
1892
1893sdk_snapshot {
1894 name: "mysdk@current",
1895 native_header_libs: ["mysdk_mynativeheaders@current"],
1896}
1897`),
1898 checkAllCopyRules(`
1899include/Test.h -> include/include/Test.h
1900`),
1901 )
1902}
1903
1904func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffin91756d22020-02-21 16:29:57 +00001905 result := testSdkWithCc(t, `
1906 sdk {
1907 name: "mysdk",
1908 device_supported: false,
1909 host_supported: true,
1910 native_header_libs: ["mynativeheaders"],
1911 }
1912
1913 cc_library_headers {
1914 name: "mynativeheaders",
1915 device_supported: false,
1916 host_supported: true,
1917 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001918 stl: "none",
1919 }
1920 `)
1921
Paul Duffin1356d8c2020-02-25 19:26:33 +00001922 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001923 checkAndroidBpContents(`
1924// This is auto-generated. DO NOT EDIT.
1925
1926cc_prebuilt_library_headers {
1927 name: "mysdk_mynativeheaders@current",
1928 sdk_member_name: "mynativeheaders",
1929 device_supported: false,
1930 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001931 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001932 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001933 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001934 target: {
1935 host: {
1936 enabled: false,
1937 },
1938 linux_glibc: {
1939 enabled: true,
1940 },
1941 },
Paul Duffin91756d22020-02-21 16:29:57 +00001942}
1943
1944cc_prebuilt_library_headers {
1945 name: "mynativeheaders",
1946 prefer: false,
1947 device_supported: false,
1948 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001949 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001950 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001951 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001952 target: {
1953 host: {
1954 enabled: false,
1955 },
1956 linux_glibc: {
1957 enabled: true,
1958 },
1959 },
Paul Duffin91756d22020-02-21 16:29:57 +00001960}
1961
1962sdk_snapshot {
1963 name: "mysdk@current",
1964 device_supported: false,
1965 host_supported: true,
1966 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001967 target: {
1968 host: {
1969 enabled: false,
1970 },
1971 linux_glibc: {
1972 enabled: true,
1973 },
1974 },
Paul Duffin91756d22020-02-21 16:29:57 +00001975}
1976`),
1977 checkAllCopyRules(`
1978include/Test.h -> include/include/Test.h
1979`),
1980 )
1981}
Paul Duffina04c1072020-03-02 10:16:35 +00001982
1983func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001984 result := testSdkWithCc(t, `
1985 sdk {
1986 name: "mysdk",
1987 host_supported: true,
1988 native_header_libs: ["mynativeheaders"],
1989 }
1990
1991 cc_library_headers {
1992 name: "mynativeheaders",
1993 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001994 stl: "none",
1995 export_system_include_dirs: ["include"],
1996 target: {
1997 android: {
1998 export_include_dirs: ["include-android"],
1999 },
2000 host: {
2001 export_include_dirs: ["include-host"],
2002 },
2003 },
2004 }
2005 `)
2006
2007 result.CheckSnapshot("mysdk", "",
2008 checkAndroidBpContents(`
2009// This is auto-generated. DO NOT EDIT.
2010
2011cc_prebuilt_library_headers {
2012 name: "mysdk_mynativeheaders@current",
2013 sdk_member_name: "mynativeheaders",
2014 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002015 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002016 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002017 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002018 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002019 host: {
2020 enabled: false,
2021 },
Paul Duffina04c1072020-03-02 10:16:35 +00002022 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002023 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002024 },
2025 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002026 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002027 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002028 },
2029 },
Paul Duffina04c1072020-03-02 10:16:35 +00002030}
2031
2032cc_prebuilt_library_headers {
2033 name: "mynativeheaders",
2034 prefer: false,
2035 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002036 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002037 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002038 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002039 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002040 host: {
2041 enabled: false,
2042 },
Paul Duffina04c1072020-03-02 10:16:35 +00002043 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002044 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002045 },
2046 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002047 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002048 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002049 },
2050 },
Paul Duffina04c1072020-03-02 10:16:35 +00002051}
2052
2053sdk_snapshot {
2054 name: "mysdk@current",
2055 host_supported: true,
2056 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002057 target: {
2058 host: {
2059 enabled: false,
2060 },
2061 linux_glibc: {
2062 enabled: true,
2063 },
2064 },
Paul Duffina04c1072020-03-02 10:16:35 +00002065}
2066`),
2067 checkAllCopyRules(`
Paul Duffined62b9c2020-06-16 16:12:50 +01002068include/Test.h -> common_os/include/include/Test.h
2069include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
2070include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
Paul Duffina04c1072020-03-02 10:16:35 +00002071`),
2072 )
2073}
Martin Stjernholm10566a02020-03-24 01:19:52 +00002074
2075func TestSystemSharedLibPropagation(t *testing.T) {
2076 result := testSdkWithCc(t, `
2077 sdk {
2078 name: "mysdk",
2079 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
2080 }
2081
2082 cc_library {
2083 name: "sslnil",
2084 host_supported: true,
2085 }
2086
2087 cc_library {
2088 name: "sslempty",
2089 system_shared_libs: [],
2090 }
2091
2092 cc_library {
2093 name: "sslnonempty",
2094 system_shared_libs: ["sslnil"],
2095 }
2096 `)
2097
2098 result.CheckSnapshot("mysdk", "",
2099 checkAndroidBpContents(`
2100// This is auto-generated. DO NOT EDIT.
2101
2102cc_prebuilt_library_shared {
2103 name: "mysdk_sslnil@current",
2104 sdk_member_name: "sslnil",
2105 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002106 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002107 arch: {
2108 arm64: {
2109 srcs: ["arm64/lib/sslnil.so"],
2110 },
2111 arm: {
2112 srcs: ["arm/lib/sslnil.so"],
2113 },
2114 },
2115}
2116
2117cc_prebuilt_library_shared {
2118 name: "sslnil",
2119 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002120 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002121 arch: {
2122 arm64: {
2123 srcs: ["arm64/lib/sslnil.so"],
2124 },
2125 arm: {
2126 srcs: ["arm/lib/sslnil.so"],
2127 },
2128 },
2129}
2130
2131cc_prebuilt_library_shared {
2132 name: "mysdk_sslempty@current",
2133 sdk_member_name: "sslempty",
2134 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002135 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002136 system_shared_libs: [],
2137 arch: {
2138 arm64: {
2139 srcs: ["arm64/lib/sslempty.so"],
2140 },
2141 arm: {
2142 srcs: ["arm/lib/sslempty.so"],
2143 },
2144 },
2145}
2146
2147cc_prebuilt_library_shared {
2148 name: "sslempty",
2149 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002150 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002151 system_shared_libs: [],
2152 arch: {
2153 arm64: {
2154 srcs: ["arm64/lib/sslempty.so"],
2155 },
2156 arm: {
2157 srcs: ["arm/lib/sslempty.so"],
2158 },
2159 },
2160}
2161
2162cc_prebuilt_library_shared {
2163 name: "mysdk_sslnonempty@current",
2164 sdk_member_name: "sslnonempty",
2165 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002166 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002167 system_shared_libs: ["mysdk_sslnil@current"],
2168 arch: {
2169 arm64: {
2170 srcs: ["arm64/lib/sslnonempty.so"],
2171 },
2172 arm: {
2173 srcs: ["arm/lib/sslnonempty.so"],
2174 },
2175 },
2176}
2177
2178cc_prebuilt_library_shared {
2179 name: "sslnonempty",
2180 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002181 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002182 system_shared_libs: ["sslnil"],
2183 arch: {
2184 arm64: {
2185 srcs: ["arm64/lib/sslnonempty.so"],
2186 },
2187 arm: {
2188 srcs: ["arm/lib/sslnonempty.so"],
2189 },
2190 },
2191}
2192
2193sdk_snapshot {
2194 name: "mysdk@current",
2195 native_shared_libs: [
2196 "mysdk_sslnil@current",
2197 "mysdk_sslempty@current",
2198 "mysdk_sslnonempty@current",
2199 ],
2200}
2201`))
2202
2203 result = testSdkWithCc(t, `
2204 sdk {
2205 name: "mysdk",
2206 host_supported: true,
2207 native_shared_libs: ["sslvariants"],
2208 }
2209
2210 cc_library {
2211 name: "sslvariants",
2212 host_supported: true,
2213 target: {
2214 android: {
2215 system_shared_libs: [],
2216 },
2217 },
2218 }
2219 `)
2220
2221 result.CheckSnapshot("mysdk", "",
2222 checkAndroidBpContents(`
2223// This is auto-generated. DO NOT EDIT.
2224
2225cc_prebuilt_library_shared {
2226 name: "mysdk_sslvariants@current",
2227 sdk_member_name: "sslvariants",
2228 host_supported: true,
2229 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002230 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002231 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002232 host: {
2233 enabled: false,
2234 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002235 android: {
2236 system_shared_libs: [],
2237 },
2238 android_arm64: {
2239 srcs: ["android/arm64/lib/sslvariants.so"],
2240 },
2241 android_arm: {
2242 srcs: ["android/arm/lib/sslvariants.so"],
2243 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002244 linux_glibc: {
2245 enabled: true,
2246 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002247 linux_glibc_x86_64: {
2248 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2249 },
2250 linux_glibc_x86: {
2251 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2252 },
2253 },
2254}
2255
2256cc_prebuilt_library_shared {
2257 name: "sslvariants",
2258 prefer: false,
2259 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002260 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002261 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002262 host: {
2263 enabled: false,
2264 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002265 android: {
2266 system_shared_libs: [],
2267 },
2268 android_arm64: {
2269 srcs: ["android/arm64/lib/sslvariants.so"],
2270 },
2271 android_arm: {
2272 srcs: ["android/arm/lib/sslvariants.so"],
2273 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002274 linux_glibc: {
2275 enabled: true,
2276 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002277 linux_glibc_x86_64: {
2278 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2279 },
2280 linux_glibc_x86: {
2281 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2282 },
2283 },
2284}
2285
2286sdk_snapshot {
2287 name: "mysdk@current",
2288 host_supported: true,
2289 native_shared_libs: ["mysdk_sslvariants@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002290 target: {
2291 host: {
2292 enabled: false,
2293 },
2294 linux_glibc: {
2295 enabled: true,
2296 },
2297 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002298}
2299`))
2300}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002301
2302func TestStubsLibrary(t *testing.T) {
2303 result := testSdkWithCc(t, `
2304 sdk {
2305 name: "mysdk",
2306 native_shared_libs: ["stubslib"],
2307 }
2308
2309 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002310 name: "internaldep",
2311 }
2312
2313 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002314 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002315 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002316 stubs: {
2317 symbol_file: "some/where/stubslib.map.txt",
2318 versions: ["1", "2", "3"],
2319 },
2320 }
2321 `)
2322
2323 result.CheckSnapshot("mysdk", "",
2324 checkAndroidBpContents(`
2325// This is auto-generated. DO NOT EDIT.
2326
2327cc_prebuilt_library_shared {
2328 name: "mysdk_stubslib@current",
2329 sdk_member_name: "stubslib",
2330 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002331 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002332 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002333 versions: [
2334 "1",
2335 "2",
2336 "3",
2337 ],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002338 },
2339 arch: {
2340 arm64: {
2341 srcs: ["arm64/lib/stubslib.so"],
2342 },
2343 arm: {
2344 srcs: ["arm/lib/stubslib.so"],
2345 },
2346 },
2347}
2348
2349cc_prebuilt_library_shared {
2350 name: "stubslib",
2351 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002352 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002353 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002354 versions: [
2355 "1",
2356 "2",
2357 "3",
2358 ],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002359 },
2360 arch: {
2361 arm64: {
2362 srcs: ["arm64/lib/stubslib.so"],
2363 },
2364 arm: {
2365 srcs: ["arm/lib/stubslib.so"],
2366 },
2367 },
2368}
2369
2370sdk_snapshot {
2371 name: "mysdk@current",
2372 native_shared_libs: ["mysdk_stubslib@current"],
2373}
2374`))
2375}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002376
2377func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002378 result := testSdkWithCc(t, `
2379 sdk {
2380 name: "mysdk",
2381 host_supported: true,
2382 native_shared_libs: ["stubslib"],
2383 }
2384
2385 cc_library {
2386 name: "internaldep",
2387 host_supported: true,
2388 }
2389
2390 cc_library {
2391 name: "stubslib",
2392 host_supported: true,
2393 shared_libs: ["internaldep"],
2394 stubs: {
2395 symbol_file: "some/where/stubslib.map.txt",
2396 versions: ["1", "2", "3"],
2397 },
2398 }
2399 `)
2400
2401 result.CheckSnapshot("mysdk", "",
2402 checkAndroidBpContents(`
2403// This is auto-generated. DO NOT EDIT.
2404
2405cc_prebuilt_library_shared {
2406 name: "mysdk_stubslib@current",
2407 sdk_member_name: "stubslib",
2408 host_supported: true,
2409 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002410 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002411 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002412 versions: [
2413 "1",
2414 "2",
2415 "3",
2416 ],
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002417 },
2418 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002419 host: {
2420 enabled: false,
2421 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002422 android_arm64: {
2423 srcs: ["android/arm64/lib/stubslib.so"],
2424 },
2425 android_arm: {
2426 srcs: ["android/arm/lib/stubslib.so"],
2427 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002428 linux_glibc: {
2429 enabled: true,
2430 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002431 linux_glibc_x86_64: {
2432 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2433 },
2434 linux_glibc_x86: {
2435 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2436 },
2437 },
2438}
2439
2440cc_prebuilt_library_shared {
2441 name: "stubslib",
2442 prefer: false,
2443 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002444 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002445 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002446 versions: [
2447 "1",
2448 "2",
2449 "3",
2450 ],
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002451 },
2452 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002453 host: {
2454 enabled: false,
2455 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002456 android_arm64: {
2457 srcs: ["android/arm64/lib/stubslib.so"],
2458 },
2459 android_arm: {
2460 srcs: ["android/arm/lib/stubslib.so"],
2461 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002462 linux_glibc: {
2463 enabled: true,
2464 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002465 linux_glibc_x86_64: {
2466 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2467 },
2468 linux_glibc_x86: {
2469 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2470 },
2471 },
2472}
2473
2474sdk_snapshot {
2475 name: "mysdk@current",
2476 host_supported: true,
2477 native_shared_libs: ["mysdk_stubslib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002478 target: {
2479 host: {
2480 enabled: false,
2481 },
2482 linux_glibc: {
2483 enabled: true,
2484 },
2485 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002486}
2487`))
2488}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002489
2490func TestUniqueHostSoname(t *testing.T) {
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002491 result := testSdkWithCc(t, `
2492 sdk {
2493 name: "mysdk",
2494 host_supported: true,
2495 native_shared_libs: ["mylib"],
2496 }
2497
2498 cc_library {
2499 name: "mylib",
2500 host_supported: true,
2501 unique_host_soname: true,
2502 }
2503 `)
2504
2505 result.CheckSnapshot("mysdk", "",
2506 checkAndroidBpContents(`
2507// This is auto-generated. DO NOT EDIT.
2508
2509cc_prebuilt_library_shared {
2510 name: "mysdk_mylib@current",
2511 sdk_member_name: "mylib",
2512 host_supported: true,
2513 installable: false,
2514 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002515 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002516 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002517 host: {
2518 enabled: false,
2519 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002520 android_arm64: {
2521 srcs: ["android/arm64/lib/mylib.so"],
2522 },
2523 android_arm: {
2524 srcs: ["android/arm/lib/mylib.so"],
2525 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002526 linux_glibc: {
2527 enabled: true,
2528 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002529 linux_glibc_x86_64: {
2530 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2531 },
2532 linux_glibc_x86: {
2533 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2534 },
2535 },
2536}
2537
2538cc_prebuilt_library_shared {
2539 name: "mylib",
2540 prefer: false,
2541 host_supported: true,
2542 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002543 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002544 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002545 host: {
2546 enabled: false,
2547 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002548 android_arm64: {
2549 srcs: ["android/arm64/lib/mylib.so"],
2550 },
2551 android_arm: {
2552 srcs: ["android/arm/lib/mylib.so"],
2553 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002554 linux_glibc: {
2555 enabled: true,
2556 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002557 linux_glibc_x86_64: {
2558 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2559 },
2560 linux_glibc_x86: {
2561 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2562 },
2563 },
2564}
2565
2566sdk_snapshot {
2567 name: "mysdk@current",
2568 host_supported: true,
2569 native_shared_libs: ["mysdk_mylib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002570 target: {
2571 host: {
2572 enabled: false,
2573 },
2574 linux_glibc: {
2575 enabled: true,
2576 },
2577 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002578}
2579`),
2580 checkAllCopyRules(`
2581.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2582.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2583.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2584.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2585`),
2586 )
2587}