blob: 84b905c9d6f422f25ca70d8508c473cd668e8064 [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",
1675 }
1676 `)
1677
1678 result.CheckSnapshot("myexports", "",
1679 checkAndroidBpContents(`
1680// This is auto-generated. DO NOT EDIT.
1681
1682cc_prebuilt_library {
1683 name: "myexports_mynativelib@current",
1684 sdk_member_name: "mynativelib",
1685 installable: false,
1686 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001687 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001688 export_include_dirs: ["include/include"],
1689 arch: {
1690 arm64: {
1691 static: {
1692 srcs: ["arm64/lib/mynativelib.a"],
1693 },
1694 shared: {
1695 srcs: ["arm64/lib/mynativelib.so"],
1696 },
1697 },
1698 arm: {
1699 static: {
1700 srcs: ["arm/lib/mynativelib.a"],
1701 },
1702 shared: {
1703 srcs: ["arm/lib/mynativelib.so"],
1704 },
1705 },
1706 },
1707}
1708
1709cc_prebuilt_library {
1710 name: "mynativelib",
1711 prefer: false,
1712 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001713 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001714 export_include_dirs: ["include/include"],
1715 arch: {
1716 arm64: {
1717 static: {
1718 srcs: ["arm64/lib/mynativelib.a"],
1719 },
1720 shared: {
1721 srcs: ["arm64/lib/mynativelib.so"],
1722 },
1723 },
1724 arm: {
1725 static: {
1726 srcs: ["arm/lib/mynativelib.a"],
1727 },
1728 shared: {
1729 srcs: ["arm/lib/mynativelib.so"],
1730 },
1731 },
1732 },
1733}
1734
1735module_exports_snapshot {
1736 name: "myexports@current",
1737 native_libs: ["myexports_mynativelib@current"],
1738}
1739`),
1740 checkAllCopyRules(`
1741include/Test.h -> include/include/Test.h
1742.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1743.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1744.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1745.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1746 )
1747}
1748
Paul Duffin13ad94f2020-02-19 16:19:27 +00001749func TestHostSnapshotWithMultiLib64(t *testing.T) {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001750 result := testSdkWithCc(t, `
1751 module_exports {
1752 name: "myexports",
1753 device_supported: false,
1754 host_supported: true,
1755 target: {
1756 host: {
1757 compile_multilib: "64",
1758 },
1759 },
1760 native_static_libs: ["mynativelib"],
1761 }
1762
1763 cc_library_static {
1764 name: "mynativelib",
1765 device_supported: false,
1766 host_supported: true,
1767 srcs: [
1768 "Test.cpp",
1769 "aidl/foo/bar/Test.aidl",
1770 ],
1771 export_include_dirs: ["include"],
1772 aidl: {
1773 export_aidl_headers: true,
1774 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001775 stl: "none",
1776 }
1777 `)
1778
Paul Duffin1356d8c2020-02-25 19:26:33 +00001779 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001780 checkAndroidBpContents(`
1781// This is auto-generated. DO NOT EDIT.
1782
1783cc_prebuilt_library_static {
1784 name: "myexports_mynativelib@current",
1785 sdk_member_name: "mynativelib",
1786 device_supported: false,
1787 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001788 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001789 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001790 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001791 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001792 target: {
1793 host: {
1794 enabled: false,
1795 },
1796 linux_glibc: {
1797 enabled: true,
1798 },
1799 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001800 srcs: ["x86_64/lib/mynativelib.a"],
1801 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1802 },
1803 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001804}
1805
1806cc_prebuilt_library_static {
1807 name: "mynativelib",
1808 prefer: false,
1809 device_supported: false,
1810 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001811 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001812 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001813 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001814 target: {
1815 host: {
1816 enabled: false,
1817 },
1818 linux_glibc: {
1819 enabled: true,
1820 },
1821 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001822 srcs: ["x86_64/lib/mynativelib.a"],
1823 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1824 },
1825 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001826}
1827
1828module_exports_snapshot {
1829 name: "myexports@current",
1830 device_supported: false,
1831 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001832 native_static_libs: ["myexports_mynativelib@current"],
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +01001833 compile_multilib: "64",
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001834 target: {
1835 host: {
1836 enabled: false,
1837 },
1838 linux_glibc: {
1839 enabled: true,
1840 },
1841 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001842}`),
1843 checkAllCopyRules(`
1844include/Test.h -> include/include/Test.h
1845.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1846.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1847.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1848.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1849`),
1850 )
1851}
Paul Duffin91756d22020-02-21 16:29:57 +00001852
1853func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1854 result := testSdkWithCc(t, `
1855 sdk {
1856 name: "mysdk",
1857 native_header_libs: ["mynativeheaders"],
1858 }
1859
1860 cc_library_headers {
1861 name: "mynativeheaders",
1862 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001863 stl: "none",
1864 }
1865 `)
1866
Paul Duffin1356d8c2020-02-25 19:26:33 +00001867 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001868 checkAndroidBpContents(`
1869// This is auto-generated. DO NOT EDIT.
1870
1871cc_prebuilt_library_headers {
1872 name: "mysdk_mynativeheaders@current",
1873 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001874 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001875 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001876 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001877}
1878
1879cc_prebuilt_library_headers {
1880 name: "mynativeheaders",
1881 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001882 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001883 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001884 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001885}
1886
1887sdk_snapshot {
1888 name: "mysdk@current",
1889 native_header_libs: ["mysdk_mynativeheaders@current"],
1890}
1891`),
1892 checkAllCopyRules(`
1893include/Test.h -> include/include/Test.h
1894`),
1895 )
1896}
1897
1898func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffin91756d22020-02-21 16:29:57 +00001899 result := testSdkWithCc(t, `
1900 sdk {
1901 name: "mysdk",
1902 device_supported: false,
1903 host_supported: true,
1904 native_header_libs: ["mynativeheaders"],
1905 }
1906
1907 cc_library_headers {
1908 name: "mynativeheaders",
1909 device_supported: false,
1910 host_supported: true,
1911 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001912 stl: "none",
1913 }
1914 `)
1915
Paul Duffin1356d8c2020-02-25 19:26:33 +00001916 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001917 checkAndroidBpContents(`
1918// This is auto-generated. DO NOT EDIT.
1919
1920cc_prebuilt_library_headers {
1921 name: "mysdk_mynativeheaders@current",
1922 sdk_member_name: "mynativeheaders",
1923 device_supported: false,
1924 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001925 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001926 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001927 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001928 target: {
1929 host: {
1930 enabled: false,
1931 },
1932 linux_glibc: {
1933 enabled: true,
1934 },
1935 },
Paul Duffin91756d22020-02-21 16:29:57 +00001936}
1937
1938cc_prebuilt_library_headers {
1939 name: "mynativeheaders",
1940 prefer: false,
1941 device_supported: false,
1942 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001943 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001944 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001945 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001946 target: {
1947 host: {
1948 enabled: false,
1949 },
1950 linux_glibc: {
1951 enabled: true,
1952 },
1953 },
Paul Duffin91756d22020-02-21 16:29:57 +00001954}
1955
1956sdk_snapshot {
1957 name: "mysdk@current",
1958 device_supported: false,
1959 host_supported: true,
1960 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001961 target: {
1962 host: {
1963 enabled: false,
1964 },
1965 linux_glibc: {
1966 enabled: true,
1967 },
1968 },
Paul Duffin91756d22020-02-21 16:29:57 +00001969}
1970`),
1971 checkAllCopyRules(`
1972include/Test.h -> include/include/Test.h
1973`),
1974 )
1975}
Paul Duffina04c1072020-03-02 10:16:35 +00001976
1977func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001978 result := testSdkWithCc(t, `
1979 sdk {
1980 name: "mysdk",
1981 host_supported: true,
1982 native_header_libs: ["mynativeheaders"],
1983 }
1984
1985 cc_library_headers {
1986 name: "mynativeheaders",
1987 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001988 stl: "none",
1989 export_system_include_dirs: ["include"],
1990 target: {
1991 android: {
1992 export_include_dirs: ["include-android"],
1993 },
1994 host: {
1995 export_include_dirs: ["include-host"],
1996 },
1997 },
1998 }
1999 `)
2000
2001 result.CheckSnapshot("mysdk", "",
2002 checkAndroidBpContents(`
2003// This is auto-generated. DO NOT EDIT.
2004
2005cc_prebuilt_library_headers {
2006 name: "mysdk_mynativeheaders@current",
2007 sdk_member_name: "mynativeheaders",
2008 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002009 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002010 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002011 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002012 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002013 host: {
2014 enabled: false,
2015 },
Paul Duffina04c1072020-03-02 10:16:35 +00002016 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002017 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002018 },
2019 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002020 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002021 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002022 },
2023 },
Paul Duffina04c1072020-03-02 10:16:35 +00002024}
2025
2026cc_prebuilt_library_headers {
2027 name: "mynativeheaders",
2028 prefer: false,
2029 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002030 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002031 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002032 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002033 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002034 host: {
2035 enabled: false,
2036 },
Paul Duffina04c1072020-03-02 10:16:35 +00002037 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002038 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002039 },
2040 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002041 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002042 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002043 },
2044 },
Paul Duffina04c1072020-03-02 10:16:35 +00002045}
2046
2047sdk_snapshot {
2048 name: "mysdk@current",
2049 host_supported: true,
2050 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002051 target: {
2052 host: {
2053 enabled: false,
2054 },
2055 linux_glibc: {
2056 enabled: true,
2057 },
2058 },
Paul Duffina04c1072020-03-02 10:16:35 +00002059}
2060`),
2061 checkAllCopyRules(`
Paul Duffined62b9c2020-06-16 16:12:50 +01002062include/Test.h -> common_os/include/include/Test.h
2063include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
2064include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
Paul Duffina04c1072020-03-02 10:16:35 +00002065`),
2066 )
2067}
Martin Stjernholm10566a02020-03-24 01:19:52 +00002068
2069func TestSystemSharedLibPropagation(t *testing.T) {
2070 result := testSdkWithCc(t, `
2071 sdk {
2072 name: "mysdk",
2073 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
2074 }
2075
2076 cc_library {
2077 name: "sslnil",
2078 host_supported: true,
2079 }
2080
2081 cc_library {
2082 name: "sslempty",
2083 system_shared_libs: [],
2084 }
2085
2086 cc_library {
2087 name: "sslnonempty",
2088 system_shared_libs: ["sslnil"],
2089 }
2090 `)
2091
2092 result.CheckSnapshot("mysdk", "",
2093 checkAndroidBpContents(`
2094// This is auto-generated. DO NOT EDIT.
2095
2096cc_prebuilt_library_shared {
2097 name: "mysdk_sslnil@current",
2098 sdk_member_name: "sslnil",
2099 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002100 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002101 arch: {
2102 arm64: {
2103 srcs: ["arm64/lib/sslnil.so"],
2104 },
2105 arm: {
2106 srcs: ["arm/lib/sslnil.so"],
2107 },
2108 },
2109}
2110
2111cc_prebuilt_library_shared {
2112 name: "sslnil",
2113 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002114 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002115 arch: {
2116 arm64: {
2117 srcs: ["arm64/lib/sslnil.so"],
2118 },
2119 arm: {
2120 srcs: ["arm/lib/sslnil.so"],
2121 },
2122 },
2123}
2124
2125cc_prebuilt_library_shared {
2126 name: "mysdk_sslempty@current",
2127 sdk_member_name: "sslempty",
2128 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002129 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002130 system_shared_libs: [],
2131 arch: {
2132 arm64: {
2133 srcs: ["arm64/lib/sslempty.so"],
2134 },
2135 arm: {
2136 srcs: ["arm/lib/sslempty.so"],
2137 },
2138 },
2139}
2140
2141cc_prebuilt_library_shared {
2142 name: "sslempty",
2143 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002144 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002145 system_shared_libs: [],
2146 arch: {
2147 arm64: {
2148 srcs: ["arm64/lib/sslempty.so"],
2149 },
2150 arm: {
2151 srcs: ["arm/lib/sslempty.so"],
2152 },
2153 },
2154}
2155
2156cc_prebuilt_library_shared {
2157 name: "mysdk_sslnonempty@current",
2158 sdk_member_name: "sslnonempty",
2159 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002160 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002161 system_shared_libs: ["mysdk_sslnil@current"],
2162 arch: {
2163 arm64: {
2164 srcs: ["arm64/lib/sslnonempty.so"],
2165 },
2166 arm: {
2167 srcs: ["arm/lib/sslnonempty.so"],
2168 },
2169 },
2170}
2171
2172cc_prebuilt_library_shared {
2173 name: "sslnonempty",
2174 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002175 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002176 system_shared_libs: ["sslnil"],
2177 arch: {
2178 arm64: {
2179 srcs: ["arm64/lib/sslnonempty.so"],
2180 },
2181 arm: {
2182 srcs: ["arm/lib/sslnonempty.so"],
2183 },
2184 },
2185}
2186
2187sdk_snapshot {
2188 name: "mysdk@current",
2189 native_shared_libs: [
2190 "mysdk_sslnil@current",
2191 "mysdk_sslempty@current",
2192 "mysdk_sslnonempty@current",
2193 ],
2194}
2195`))
2196
2197 result = testSdkWithCc(t, `
2198 sdk {
2199 name: "mysdk",
2200 host_supported: true,
2201 native_shared_libs: ["sslvariants"],
2202 }
2203
2204 cc_library {
2205 name: "sslvariants",
2206 host_supported: true,
2207 target: {
2208 android: {
2209 system_shared_libs: [],
2210 },
2211 },
2212 }
2213 `)
2214
2215 result.CheckSnapshot("mysdk", "",
2216 checkAndroidBpContents(`
2217// This is auto-generated. DO NOT EDIT.
2218
2219cc_prebuilt_library_shared {
2220 name: "mysdk_sslvariants@current",
2221 sdk_member_name: "sslvariants",
2222 host_supported: true,
2223 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002224 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002225 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002226 host: {
2227 enabled: false,
2228 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002229 android: {
2230 system_shared_libs: [],
2231 },
2232 android_arm64: {
2233 srcs: ["android/arm64/lib/sslvariants.so"],
2234 },
2235 android_arm: {
2236 srcs: ["android/arm/lib/sslvariants.so"],
2237 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002238 linux_glibc: {
2239 enabled: true,
2240 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002241 linux_glibc_x86_64: {
2242 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2243 },
2244 linux_glibc_x86: {
2245 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2246 },
2247 },
2248}
2249
2250cc_prebuilt_library_shared {
2251 name: "sslvariants",
2252 prefer: false,
2253 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002254 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002255 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002256 host: {
2257 enabled: false,
2258 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002259 android: {
2260 system_shared_libs: [],
2261 },
2262 android_arm64: {
2263 srcs: ["android/arm64/lib/sslvariants.so"],
2264 },
2265 android_arm: {
2266 srcs: ["android/arm/lib/sslvariants.so"],
2267 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002268 linux_glibc: {
2269 enabled: true,
2270 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002271 linux_glibc_x86_64: {
2272 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2273 },
2274 linux_glibc_x86: {
2275 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2276 },
2277 },
2278}
2279
2280sdk_snapshot {
2281 name: "mysdk@current",
2282 host_supported: true,
2283 native_shared_libs: ["mysdk_sslvariants@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002284 target: {
2285 host: {
2286 enabled: false,
2287 },
2288 linux_glibc: {
2289 enabled: true,
2290 },
2291 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002292}
2293`))
2294}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002295
2296func TestStubsLibrary(t *testing.T) {
2297 result := testSdkWithCc(t, `
2298 sdk {
2299 name: "mysdk",
2300 native_shared_libs: ["stubslib"],
2301 }
2302
2303 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002304 name: "internaldep",
2305 }
2306
2307 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002308 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002309 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002310 stubs: {
2311 symbol_file: "some/where/stubslib.map.txt",
2312 versions: ["1", "2", "3"],
2313 },
2314 }
2315 `)
2316
2317 result.CheckSnapshot("mysdk", "",
2318 checkAndroidBpContents(`
2319// This is auto-generated. DO NOT EDIT.
2320
2321cc_prebuilt_library_shared {
2322 name: "mysdk_stubslib@current",
2323 sdk_member_name: "stubslib",
2324 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002325 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002326 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002327 versions: ["3"],
2328 },
2329 arch: {
2330 arm64: {
2331 srcs: ["arm64/lib/stubslib.so"],
2332 },
2333 arm: {
2334 srcs: ["arm/lib/stubslib.so"],
2335 },
2336 },
2337}
2338
2339cc_prebuilt_library_shared {
2340 name: "stubslib",
2341 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002342 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002343 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002344 versions: ["3"],
2345 },
2346 arch: {
2347 arm64: {
2348 srcs: ["arm64/lib/stubslib.so"],
2349 },
2350 arm: {
2351 srcs: ["arm/lib/stubslib.so"],
2352 },
2353 },
2354}
2355
2356sdk_snapshot {
2357 name: "mysdk@current",
2358 native_shared_libs: ["mysdk_stubslib@current"],
2359}
2360`))
2361}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002362
2363func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002364 result := testSdkWithCc(t, `
2365 sdk {
2366 name: "mysdk",
2367 host_supported: true,
2368 native_shared_libs: ["stubslib"],
2369 }
2370
2371 cc_library {
2372 name: "internaldep",
2373 host_supported: true,
2374 }
2375
2376 cc_library {
2377 name: "stubslib",
2378 host_supported: true,
2379 shared_libs: ["internaldep"],
2380 stubs: {
2381 symbol_file: "some/where/stubslib.map.txt",
2382 versions: ["1", "2", "3"],
2383 },
2384 }
2385 `)
2386
2387 result.CheckSnapshot("mysdk", "",
2388 checkAndroidBpContents(`
2389// This is auto-generated. DO NOT EDIT.
2390
2391cc_prebuilt_library_shared {
2392 name: "mysdk_stubslib@current",
2393 sdk_member_name: "stubslib",
2394 host_supported: true,
2395 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002396 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002397 stubs: {
2398 versions: ["3"],
2399 },
2400 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002401 host: {
2402 enabled: false,
2403 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002404 android_arm64: {
2405 srcs: ["android/arm64/lib/stubslib.so"],
2406 },
2407 android_arm: {
2408 srcs: ["android/arm/lib/stubslib.so"],
2409 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002410 linux_glibc: {
2411 enabled: true,
2412 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002413 linux_glibc_x86_64: {
2414 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2415 },
2416 linux_glibc_x86: {
2417 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2418 },
2419 },
2420}
2421
2422cc_prebuilt_library_shared {
2423 name: "stubslib",
2424 prefer: false,
2425 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002426 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002427 stubs: {
2428 versions: ["3"],
2429 },
2430 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002431 host: {
2432 enabled: false,
2433 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002434 android_arm64: {
2435 srcs: ["android/arm64/lib/stubslib.so"],
2436 },
2437 android_arm: {
2438 srcs: ["android/arm/lib/stubslib.so"],
2439 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002440 linux_glibc: {
2441 enabled: true,
2442 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002443 linux_glibc_x86_64: {
2444 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2445 },
2446 linux_glibc_x86: {
2447 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2448 },
2449 },
2450}
2451
2452sdk_snapshot {
2453 name: "mysdk@current",
2454 host_supported: true,
2455 native_shared_libs: ["mysdk_stubslib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002456 target: {
2457 host: {
2458 enabled: false,
2459 },
2460 linux_glibc: {
2461 enabled: true,
2462 },
2463 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002464}
2465`))
2466}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002467
2468func TestUniqueHostSoname(t *testing.T) {
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002469 result := testSdkWithCc(t, `
2470 sdk {
2471 name: "mysdk",
2472 host_supported: true,
2473 native_shared_libs: ["mylib"],
2474 }
2475
2476 cc_library {
2477 name: "mylib",
2478 host_supported: true,
2479 unique_host_soname: true,
2480 }
2481 `)
2482
2483 result.CheckSnapshot("mysdk", "",
2484 checkAndroidBpContents(`
2485// This is auto-generated. DO NOT EDIT.
2486
2487cc_prebuilt_library_shared {
2488 name: "mysdk_mylib@current",
2489 sdk_member_name: "mylib",
2490 host_supported: true,
2491 installable: false,
2492 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002493 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002494 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002495 host: {
2496 enabled: false,
2497 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002498 android_arm64: {
2499 srcs: ["android/arm64/lib/mylib.so"],
2500 },
2501 android_arm: {
2502 srcs: ["android/arm/lib/mylib.so"],
2503 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002504 linux_glibc: {
2505 enabled: true,
2506 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002507 linux_glibc_x86_64: {
2508 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2509 },
2510 linux_glibc_x86: {
2511 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2512 },
2513 },
2514}
2515
2516cc_prebuilt_library_shared {
2517 name: "mylib",
2518 prefer: false,
2519 host_supported: true,
2520 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002521 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002522 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002523 host: {
2524 enabled: false,
2525 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002526 android_arm64: {
2527 srcs: ["android/arm64/lib/mylib.so"],
2528 },
2529 android_arm: {
2530 srcs: ["android/arm/lib/mylib.so"],
2531 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002532 linux_glibc: {
2533 enabled: true,
2534 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002535 linux_glibc_x86_64: {
2536 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2537 },
2538 linux_glibc_x86: {
2539 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2540 },
2541 },
2542}
2543
2544sdk_snapshot {
2545 name: "mysdk@current",
2546 host_supported: true,
2547 native_shared_libs: ["mysdk_mylib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002548 target: {
2549 host: {
2550 enabled: false,
2551 },
2552 linux_glibc: {
2553 enabled: true,
2554 },
2555 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002556}
2557`),
2558 checkAllCopyRules(`
2559.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2560.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2561.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2562.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2563`),
2564 )
2565}