blob: 17a6d86e28a284717d37ed6265972b9cbf13fa22 [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
Martin Stjernholmb0249572020-09-15 02:32:35 +0100438// Verify that when the shared library has some common and some arch specific
439// properties that the generated snapshot is optimized properly. Substruct
440// handling is tested with the sanitize clauses (but note there's a lot of
441// built-in logic in sanitize.go that can affect those flags).
Paul Duffina7cd8c82019-12-11 20:00:57 +0000442func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
443 result := testSdkWithCc(t, `
444 sdk {
445 name: "mysdk",
446 native_shared_libs: ["mynativelib"],
447 }
448
449 cc_library_shared {
450 name: "mynativelib",
451 srcs: [
452 "Test.cpp",
453 "aidl/foo/bar/Test.aidl",
454 ],
455 export_include_dirs: ["include"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100456 sanitize: {
457 fuzzer: false,
458 integer_overflow: true,
459 diag: { undefined: false },
460 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000461 arch: {
462 arm64: {
463 export_system_include_dirs: ["arm64/include"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100464 sanitize: {
465 hwaddress: true,
466 integer_overflow: false,
467 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000468 },
469 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000470 stl: "none",
471 }
472 `)
473
Paul Duffin1356d8c2020-02-25 19:26:33 +0000474 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000475 checkAndroidBpContents(`
476// This is auto-generated. DO NOT EDIT.
477
478cc_prebuilt_library_shared {
479 name: "mysdk_mynativelib@current",
480 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000481 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000482 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100483 compile_multilib: "both",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000484 export_include_dirs: ["include/include"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100485 sanitize: {
486 fuzzer: false,
487 diag: {
488 undefined: false,
489 },
490 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000491 arch: {
492 arm64: {
493 srcs: ["arm64/lib/mynativelib.so"],
494 export_system_include_dirs: ["arm64/include/arm64/include"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100495 sanitize: {
496 hwaddress: true,
497 integer_overflow: false,
498 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000499 },
500 arm: {
501 srcs: ["arm/lib/mynativelib.so"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100502 sanitize: {
503 integer_overflow: true,
504 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000505 },
506 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000507}
508
509cc_prebuilt_library_shared {
510 name: "mynativelib",
511 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000512 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100513 compile_multilib: "both",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000514 export_include_dirs: ["include/include"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100515 sanitize: {
516 fuzzer: false,
517 diag: {
518 undefined: false,
519 },
520 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000521 arch: {
522 arm64: {
523 srcs: ["arm64/lib/mynativelib.so"],
524 export_system_include_dirs: ["arm64/include/arm64/include"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100525 sanitize: {
526 hwaddress: true,
527 integer_overflow: false,
528 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000529 },
530 arm: {
531 srcs: ["arm/lib/mynativelib.so"],
Martin Stjernholmb0249572020-09-15 02:32:35 +0100532 sanitize: {
533 integer_overflow: true,
534 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000535 },
536 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000537}
538
539sdk_snapshot {
540 name: "mysdk@current",
541 native_shared_libs: ["mysdk_mynativelib@current"],
542}
543`),
544 checkAllCopyRules(`
545include/Test.h -> include/include/Test.h
Martin Stjernholmb0249572020-09-15 02:32:35 +0100546.intermediates/mynativelib/android_arm64_armv8-a_shared_hwasan/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000547arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800548.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000549 )
550}
551
Paul Duffin25ce04b2020-01-16 11:47:25 +0000552func TestSnapshotWithCcBinary(t *testing.T) {
553 result := testSdkWithCc(t, `
554 module_exports {
555 name: "mymodule_exports",
556 native_binaries: ["mynativebinary"],
557 }
558
559 cc_binary {
560 name: "mynativebinary",
561 srcs: [
562 "Test.cpp",
563 ],
564 compile_multilib: "both",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000565 }
566 `)
567
Paul Duffin1356d8c2020-02-25 19:26:33 +0000568 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000569 checkAndroidBpContents(`
570// This is auto-generated. DO NOT EDIT.
571
572cc_prebuilt_binary {
573 name: "mymodule_exports_mynativebinary@current",
574 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000575 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000576 compile_multilib: "both",
577 arch: {
578 arm64: {
579 srcs: ["arm64/bin/mynativebinary"],
580 },
581 arm: {
582 srcs: ["arm/bin/mynativebinary"],
583 },
584 },
585}
586
587cc_prebuilt_binary {
588 name: "mynativebinary",
589 prefer: false,
590 compile_multilib: "both",
591 arch: {
592 arm64: {
593 srcs: ["arm64/bin/mynativebinary"],
594 },
595 arm: {
596 srcs: ["arm/bin/mynativebinary"],
597 },
598 },
599}
600
601module_exports_snapshot {
602 name: "mymodule_exports@current",
603 native_binaries: ["mymodule_exports_mynativebinary@current"],
604}
605`),
606 checkAllCopyRules(`
607.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
608.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
609`),
610 )
611}
612
Paul Duffina04c1072020-03-02 10:16:35 +0000613func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +0000614 result := testSdkWithCc(t, `
615 module_exports {
616 name: "myexports",
617 device_supported: false,
618 host_supported: true,
619 native_binaries: ["mynativebinary"],
620 target: {
621 windows: {
622 enabled: true,
623 },
624 },
625 }
626
627 cc_binary {
628 name: "mynativebinary",
629 device_supported: false,
630 host_supported: true,
631 srcs: [
632 "Test.cpp",
633 ],
634 compile_multilib: "both",
Paul Duffina04c1072020-03-02 10:16:35 +0000635 stl: "none",
636 target: {
637 windows: {
638 enabled: true,
639 },
640 },
641 }
642 `)
643
644 result.CheckSnapshot("myexports", "",
645 checkAndroidBpContents(`
646// This is auto-generated. DO NOT EDIT.
647
648cc_prebuilt_binary {
649 name: "myexports_mynativebinary@current",
650 sdk_member_name: "mynativebinary",
651 device_supported: false,
652 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000653 installable: false,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100654 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000655 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100656 host: {
657 enabled: false,
658 },
Paul Duffina04c1072020-03-02 10:16:35 +0000659 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100660 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000661 compile_multilib: "both",
662 },
663 linux_glibc_x86_64: {
664 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
665 },
666 linux_glibc_x86: {
667 srcs: ["linux_glibc/x86/bin/mynativebinary"],
668 },
669 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100670 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000671 compile_multilib: "64",
672 },
673 windows_x86_64: {
674 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
675 },
676 },
677}
678
679cc_prebuilt_binary {
680 name: "mynativebinary",
681 prefer: false,
682 device_supported: false,
683 host_supported: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100684 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000685 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100686 host: {
687 enabled: false,
688 },
Paul Duffina04c1072020-03-02 10:16:35 +0000689 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100690 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000691 compile_multilib: "both",
692 },
693 linux_glibc_x86_64: {
694 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
695 },
696 linux_glibc_x86: {
697 srcs: ["linux_glibc/x86/bin/mynativebinary"],
698 },
699 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100700 enabled: true,
Paul Duffina04c1072020-03-02 10:16:35 +0000701 compile_multilib: "64",
702 },
703 windows_x86_64: {
704 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
705 },
706 },
707}
708
709module_exports_snapshot {
710 name: "myexports@current",
711 device_supported: false,
712 host_supported: true,
713 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000714 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100715 host: {
716 enabled: false,
717 },
718 linux_glibc: {
719 enabled: true,
720 },
Paul Duffin6a7e9532020-03-20 17:50:07 +0000721 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100722 enabled: true,
Paul Duffin6a7e9532020-03-20 17:50:07 +0000723 compile_multilib: "64",
724 },
725 },
Paul Duffina04c1072020-03-02 10:16:35 +0000726}
727`),
728 checkAllCopyRules(`
729.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
730.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
731.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
732`),
733 )
734}
735
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100736func TestSnapshotWithSingleHostOsType(t *testing.T) {
737 ctx, config := testSdkContext(`
738 cc_defaults {
739 name: "mydefaults",
740 device_supported: false,
741 host_supported: true,
742 compile_multilib: "64",
743 target: {
744 host: {
745 enabled: false,
746 },
747 linux_bionic: {
748 enabled: true,
749 },
750 },
751 }
752
753 module_exports {
754 name: "myexports",
755 defaults: ["mydefaults"],
756 native_shared_libs: ["mynativelib"],
757 native_binaries: ["mynativebinary"],
758 compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults.
759 }
760
761 cc_library {
762 name: "mynativelib",
763 defaults: ["mydefaults"],
764 srcs: [
765 "Test.cpp",
766 ],
767 stl: "none",
768 }
769
770 cc_binary {
771 name: "mynativebinary",
772 defaults: ["mydefaults"],
773 srcs: [
774 "Test.cpp",
775 ],
776 stl: "none",
777 }
778 `, ccTestFs, []android.OsType{android.LinuxBionic})
779
780 result := runTests(t, ctx, config)
781
782 result.CheckSnapshot("myexports", "",
783 checkAndroidBpContents(`
784// This is auto-generated. DO NOT EDIT.
785
786cc_prebuilt_binary {
787 name: "myexports_mynativebinary@current",
788 sdk_member_name: "mynativebinary",
789 device_supported: false,
790 host_supported: true,
791 installable: false,
792 stl: "none",
793 compile_multilib: "64",
794 target: {
795 host: {
796 enabled: false,
797 },
798 linux_bionic: {
799 enabled: true,
800 },
801 linux_bionic_x86_64: {
802 srcs: ["x86_64/bin/mynativebinary"],
803 },
804 },
805}
806
807cc_prebuilt_binary {
808 name: "mynativebinary",
809 prefer: false,
810 device_supported: false,
811 host_supported: true,
812 stl: "none",
813 compile_multilib: "64",
814 target: {
815 host: {
816 enabled: false,
817 },
818 linux_bionic: {
819 enabled: true,
820 },
821 linux_bionic_x86_64: {
822 srcs: ["x86_64/bin/mynativebinary"],
823 },
824 },
825}
826
827cc_prebuilt_library_shared {
828 name: "myexports_mynativelib@current",
829 sdk_member_name: "mynativelib",
830 device_supported: false,
831 host_supported: true,
832 installable: false,
833 stl: "none",
834 compile_multilib: "64",
835 target: {
836 host: {
837 enabled: false,
838 },
839 linux_bionic: {
840 enabled: true,
841 },
842 linux_bionic_x86_64: {
843 srcs: ["x86_64/lib/mynativelib.so"],
844 },
845 },
846}
847
848cc_prebuilt_library_shared {
849 name: "mynativelib",
850 prefer: false,
851 device_supported: false,
852 host_supported: true,
853 stl: "none",
854 compile_multilib: "64",
855 target: {
856 host: {
857 enabled: false,
858 },
859 linux_bionic: {
860 enabled: true,
861 },
862 linux_bionic_x86_64: {
863 srcs: ["x86_64/lib/mynativelib.so"],
864 },
865 },
866}
867
868module_exports_snapshot {
869 name: "myexports@current",
870 device_supported: false,
871 host_supported: true,
872 native_binaries: ["myexports_mynativebinary@current"],
873 native_shared_libs: ["myexports_mynativelib@current"],
874 compile_multilib: "64",
875 target: {
876 host: {
877 enabled: false,
878 },
879 linux_bionic: {
880 enabled: true,
881 },
882 },
883}
884`),
885 checkAllCopyRules(`
886.intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary
887.intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
888`),
889 )
890}
891
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100892// Test that we support the necessary flags for the linker binary, which is
893// special in several ways.
894func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100895 result := testSdkWithCc(t, `
896 module_exports {
897 name: "mymodule_exports",
898 host_supported: true,
899 device_supported: false,
900 native_binaries: ["linker"],
901 }
902
903 cc_binary {
904 name: "linker",
905 host_supported: true,
906 static_executable: true,
907 nocrt: true,
908 stl: "none",
909 srcs: [
910 "Test.cpp",
911 ],
912 compile_multilib: "both",
913 }
914 `)
915
916 result.CheckSnapshot("mymodule_exports", "",
917 checkAndroidBpContents(`
918// This is auto-generated. DO NOT EDIT.
919
920cc_prebuilt_binary {
921 name: "mymodule_exports_linker@current",
922 sdk_member_name: "linker",
923 device_supported: false,
924 host_supported: true,
925 installable: false,
926 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100927 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100928 static_executable: true,
929 nocrt: true,
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100930 target: {
931 host: {
932 enabled: false,
933 },
934 linux_glibc: {
935 enabled: true,
936 },
937 linux_glibc_x86_64: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100938 srcs: ["x86_64/bin/linker"],
939 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100940 linux_glibc_x86: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100941 srcs: ["x86/bin/linker"],
942 },
943 },
944}
945
946cc_prebuilt_binary {
947 name: "linker",
948 prefer: false,
949 device_supported: false,
950 host_supported: true,
951 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100952 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100953 static_executable: true,
954 nocrt: true,
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100955 target: {
956 host: {
957 enabled: false,
958 },
959 linux_glibc: {
960 enabled: true,
961 },
962 linux_glibc_x86_64: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100963 srcs: ["x86_64/bin/linker"],
964 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100965 linux_glibc_x86: {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100966 srcs: ["x86/bin/linker"],
967 },
968 },
969}
970
971module_exports_snapshot {
972 name: "mymodule_exports@current",
973 device_supported: false,
974 host_supported: true,
975 native_binaries: ["mymodule_exports_linker@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +0100976 target: {
977 host: {
978 enabled: false,
979 },
980 linux_glibc: {
981 enabled: true,
982 },
983 },
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100984}
985`),
986 checkAllCopyRules(`
987.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
988.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
989`),
990 )
991}
992
Paul Duffin9ab556f2019-12-11 18:42:17 +0000993func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000994 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000995 sdk {
996 name: "mysdk",
997 native_shared_libs: ["mynativelib"],
998 }
999
1000 cc_library_shared {
1001 name: "mynativelib",
1002 srcs: [
1003 "Test.cpp",
1004 "aidl/foo/bar/Test.aidl",
1005 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +00001006 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001007 export_include_dirs: ["include"],
1008 aidl: {
1009 export_aidl_headers: true,
1010 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001011 stl: "none",
1012 }
1013 `)
1014
Paul Duffin1356d8c2020-02-25 19:26:33 +00001015 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +00001016 checkAndroidBpContents(`
1017// This is auto-generated. DO NOT EDIT.
1018
1019cc_prebuilt_library_shared {
1020 name: "mysdk_mynativelib@current",
1021 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +00001022 apex_available: [
1023 "apex1",
1024 "apex2",
1025 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +00001026 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001027 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001028 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001029 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001030 arch: {
1031 arm64: {
1032 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001033 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001034 },
1035 arm: {
1036 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001037 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001038 },
1039 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001040}
1041
1042cc_prebuilt_library_shared {
1043 name: "mynativelib",
1044 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +00001045 apex_available: [
1046 "apex1",
1047 "apex2",
1048 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +00001049 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001050 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001051 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001052 arch: {
1053 arm64: {
1054 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001055 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001056 },
1057 arm: {
1058 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001059 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001060 },
1061 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001062}
1063
1064sdk_snapshot {
1065 name: "mysdk@current",
1066 native_shared_libs: ["mysdk_mynativelib@current"],
1067}
1068`),
1069 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001070include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001071.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1072.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1073.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1074.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1075.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1076.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1077.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1078.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 +00001079`),
1080 )
1081}
1082
Paul Duffin13f02712020-03-06 12:30:43 +00001083func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
1084 result := testSdkWithCc(t, `
1085 sdk {
1086 name: "mysdk",
1087 native_shared_libs: [
1088 "mynativelib",
1089 "myothernativelib",
1090 "mysystemnativelib",
1091 ],
1092 }
1093
1094 cc_library {
1095 name: "mysystemnativelib",
1096 srcs: [
1097 "Test.cpp",
1098 ],
Paul Duffin13f02712020-03-06 12:30:43 +00001099 stl: "none",
1100 }
1101
1102 cc_library_shared {
1103 name: "myothernativelib",
1104 srcs: [
1105 "Test.cpp",
1106 ],
1107 system_shared_libs: [
1108 // A reference to a library that is not an sdk member. Uses libm as that
1109 // is in the default set of modules available to this test and so is available
1110 // both here and also when the generated Android.bp file is tested in
1111 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
1112 // handles references to modules that are not sdk members.
1113 "libm",
1114 ],
1115 stl: "none",
1116 }
1117
1118 cc_library {
1119 name: "mynativelib",
1120 srcs: [
1121 "Test.cpp",
1122 ],
1123 shared_libs: [
1124 // A reference to another sdk member.
1125 "myothernativelib",
1126 ],
1127 target: {
1128 android: {
1129 shared: {
1130 shared_libs: [
1131 // A reference to a library that is not an sdk member. The libc library
1132 // is used here to check that the shared_libs property is handled correctly
1133 // in a similar way to how libm is used to check system_shared_libs above.
1134 "libc",
1135 ],
1136 },
1137 },
1138 },
Paul Duffin13f02712020-03-06 12:30:43 +00001139 stl: "none",
1140 }
1141 `)
1142
1143 result.CheckSnapshot("mysdk", "",
1144 checkAndroidBpContents(`
1145// This is auto-generated. DO NOT EDIT.
1146
1147cc_prebuilt_library_shared {
1148 name: "mysdk_mynativelib@current",
1149 sdk_member_name: "mynativelib",
1150 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001151 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001152 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001153 shared_libs: [
1154 "mysdk_myothernativelib@current",
1155 "libc",
1156 ],
1157 arch: {
1158 arm64: {
1159 srcs: ["arm64/lib/mynativelib.so"],
1160 },
1161 arm: {
1162 srcs: ["arm/lib/mynativelib.so"],
1163 },
1164 },
Paul Duffin13f02712020-03-06 12:30:43 +00001165}
1166
1167cc_prebuilt_library_shared {
1168 name: "mynativelib",
1169 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001170 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001171 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001172 shared_libs: [
1173 "myothernativelib",
1174 "libc",
1175 ],
1176 arch: {
1177 arm64: {
1178 srcs: ["arm64/lib/mynativelib.so"],
1179 },
1180 arm: {
1181 srcs: ["arm/lib/mynativelib.so"],
1182 },
1183 },
Paul Duffin13f02712020-03-06 12:30:43 +00001184}
1185
1186cc_prebuilt_library_shared {
1187 name: "mysdk_myothernativelib@current",
1188 sdk_member_name: "myothernativelib",
1189 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001190 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001191 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001192 system_shared_libs: ["libm"],
1193 arch: {
1194 arm64: {
1195 srcs: ["arm64/lib/myothernativelib.so"],
1196 },
1197 arm: {
1198 srcs: ["arm/lib/myothernativelib.so"],
1199 },
1200 },
Paul Duffin13f02712020-03-06 12:30:43 +00001201}
1202
1203cc_prebuilt_library_shared {
1204 name: "myothernativelib",
1205 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001206 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001207 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001208 system_shared_libs: ["libm"],
1209 arch: {
1210 arm64: {
1211 srcs: ["arm64/lib/myothernativelib.so"],
1212 },
1213 arm: {
1214 srcs: ["arm/lib/myothernativelib.so"],
1215 },
1216 },
Paul Duffin13f02712020-03-06 12:30:43 +00001217}
1218
1219cc_prebuilt_library_shared {
1220 name: "mysdk_mysystemnativelib@current",
1221 sdk_member_name: "mysystemnativelib",
1222 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001223 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001224 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001225 arch: {
1226 arm64: {
1227 srcs: ["arm64/lib/mysystemnativelib.so"],
1228 },
1229 arm: {
1230 srcs: ["arm/lib/mysystemnativelib.so"],
1231 },
1232 },
Paul Duffin13f02712020-03-06 12:30:43 +00001233}
1234
1235cc_prebuilt_library_shared {
1236 name: "mysystemnativelib",
1237 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001238 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001239 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +00001240 arch: {
1241 arm64: {
1242 srcs: ["arm64/lib/mysystemnativelib.so"],
1243 },
1244 arm: {
1245 srcs: ["arm/lib/mysystemnativelib.so"],
1246 },
1247 },
Paul Duffin13f02712020-03-06 12:30:43 +00001248}
1249
1250sdk_snapshot {
1251 name: "mysdk@current",
1252 native_shared_libs: [
1253 "mysdk_mynativelib@current",
1254 "mysdk_myothernativelib@current",
1255 "mysdk_mysystemnativelib@current",
1256 ],
1257}
1258`),
1259 checkAllCopyRules(`
1260.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1261.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1262.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
1263.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
1264.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
1265.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
1266`),
1267 )
1268}
1269
Paul Duffin9ab556f2019-12-11 18:42:17 +00001270func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +00001271 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +00001272 sdk {
1273 name: "mysdk",
1274 device_supported: false,
1275 host_supported: true,
1276 native_shared_libs: ["mynativelib"],
1277 }
1278
1279 cc_library_shared {
1280 name: "mynativelib",
1281 device_supported: false,
1282 host_supported: true,
1283 srcs: [
1284 "Test.cpp",
1285 "aidl/foo/bar/Test.aidl",
1286 ],
1287 export_include_dirs: ["include"],
1288 aidl: {
1289 export_aidl_headers: true,
1290 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001291 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +00001292 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +00001293 }
1294 `)
1295
Paul Duffin1356d8c2020-02-25 19:26:33 +00001296 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +00001297 checkAndroidBpContents(`
1298// This is auto-generated. DO NOT EDIT.
1299
1300cc_prebuilt_library_shared {
1301 name: "mysdk_mynativelib@current",
1302 sdk_member_name: "mynativelib",
1303 device_supported: false,
1304 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001305 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +00001306 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001307 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001308 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001309 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001310 target: {
1311 host: {
1312 enabled: false,
1313 },
1314 linux_glibc: {
1315 enabled: true,
1316 },
1317 linux_glibc_x86_64: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001318 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001319 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001320 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001321 linux_glibc_x86: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001322 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001323 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001324 },
1325 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001326}
1327
1328cc_prebuilt_library_shared {
1329 name: "mynativelib",
1330 prefer: false,
1331 device_supported: false,
1332 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +00001333 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001334 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001335 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001336 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001337 target: {
1338 host: {
1339 enabled: false,
1340 },
1341 linux_glibc: {
1342 enabled: true,
1343 },
1344 linux_glibc_x86_64: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001345 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001346 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001347 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001348 linux_glibc_x86: {
Paul Duffina80fdec2019-12-03 15:25:00 +00001349 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001350 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001351 },
1352 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001353}
1354
1355sdk_snapshot {
1356 name: "mysdk@current",
1357 device_supported: false,
1358 host_supported: true,
1359 native_shared_libs: ["mysdk_mynativelib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001360 target: {
1361 host: {
1362 enabled: false,
1363 },
1364 linux_glibc: {
1365 enabled: true,
1366 },
1367 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001368}
1369`),
1370 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001371include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +00001372.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001373.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1374.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1375.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1376.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001377.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1378.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1379.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1380`),
1381 )
1382}
Paul Duffin9ab556f2019-12-11 18:42:17 +00001383
Paul Duffina04c1072020-03-02 10:16:35 +00001384func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001385 result := testSdkWithCc(t, `
1386 sdk {
1387 name: "mysdk",
1388 device_supported: false,
1389 host_supported: true,
1390 native_shared_libs: ["mynativelib"],
1391 target: {
1392 windows: {
1393 enabled: true,
1394 },
1395 },
1396 }
1397
1398 cc_library_shared {
1399 name: "mynativelib",
1400 device_supported: false,
1401 host_supported: true,
1402 srcs: [
1403 "Test.cpp",
1404 ],
Paul Duffina04c1072020-03-02 10:16:35 +00001405 stl: "none",
1406 target: {
1407 windows: {
1408 enabled: true,
1409 },
1410 },
1411 }
1412 `)
1413
1414 result.CheckSnapshot("mysdk", "",
1415 checkAndroidBpContents(`
1416// This is auto-generated. DO NOT EDIT.
1417
1418cc_prebuilt_library_shared {
1419 name: "mysdk_mynativelib@current",
1420 sdk_member_name: "mynativelib",
1421 device_supported: false,
1422 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001423 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001424 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001425 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001426 host: {
1427 enabled: false,
1428 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001429 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001430 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001431 compile_multilib: "both",
1432 },
Paul Duffina04c1072020-03-02 10:16:35 +00001433 linux_glibc_x86_64: {
1434 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1435 },
1436 linux_glibc_x86: {
1437 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1438 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001439 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001440 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001441 compile_multilib: "64",
1442 },
Paul Duffina04c1072020-03-02 10:16:35 +00001443 windows_x86_64: {
1444 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1445 },
1446 },
Paul Duffina04c1072020-03-02 10:16:35 +00001447}
1448
1449cc_prebuilt_library_shared {
1450 name: "mynativelib",
1451 prefer: false,
1452 device_supported: false,
1453 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001454 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001455 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001456 host: {
1457 enabled: false,
1458 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001459 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001460 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001461 compile_multilib: "both",
1462 },
Paul Duffina04c1072020-03-02 10:16:35 +00001463 linux_glibc_x86_64: {
1464 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1465 },
1466 linux_glibc_x86: {
1467 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1468 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001469 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001470 enabled: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001471 compile_multilib: "64",
1472 },
Paul Duffina04c1072020-03-02 10:16:35 +00001473 windows_x86_64: {
1474 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1475 },
1476 },
Paul Duffina04c1072020-03-02 10:16:35 +00001477}
1478
1479sdk_snapshot {
1480 name: "mysdk@current",
1481 device_supported: false,
1482 host_supported: true,
1483 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001484 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001485 host: {
1486 enabled: false,
1487 },
1488 linux_glibc: {
1489 enabled: true,
1490 },
Paul Duffin6a7e9532020-03-20 17:50:07 +00001491 windows: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001492 enabled: true,
Paul Duffin6a7e9532020-03-20 17:50:07 +00001493 compile_multilib: "64",
1494 },
1495 },
Paul Duffina04c1072020-03-02 10:16:35 +00001496}
1497`),
1498 checkAllCopyRules(`
1499.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1500.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1501.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1502`),
1503 )
1504}
1505
Paul Duffin9ab556f2019-12-11 18:42:17 +00001506func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1507 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001508 module_exports {
1509 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001510 native_static_libs: ["mynativelib"],
1511 }
1512
1513 cc_library_static {
1514 name: "mynativelib",
1515 srcs: [
1516 "Test.cpp",
1517 "aidl/foo/bar/Test.aidl",
1518 ],
1519 export_include_dirs: ["include"],
1520 aidl: {
1521 export_aidl_headers: true,
1522 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001523 stl: "none",
1524 }
1525 `)
1526
Paul Duffin1356d8c2020-02-25 19:26:33 +00001527 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001528 checkAndroidBpContents(`
1529// This is auto-generated. DO NOT EDIT.
1530
1531cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001532 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001533 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001534 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001535 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001536 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001537 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001538 arch: {
1539 arm64: {
1540 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001541 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001542 },
1543 arm: {
1544 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001545 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001546 },
1547 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001548}
1549
1550cc_prebuilt_library_static {
1551 name: "mynativelib",
1552 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001553 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001554 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001555 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001556 arch: {
1557 arm64: {
1558 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001559 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001560 },
1561 arm: {
1562 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001563 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001564 },
1565 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001566}
1567
Paul Duffine6029182019-12-16 17:43:48 +00001568module_exports_snapshot {
1569 name: "myexports@current",
1570 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001571}
1572`),
1573 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001574include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001575.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1576.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1577.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1578.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1579.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1580.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1581.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1582.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 +00001583`),
1584 )
1585}
1586
1587func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001588 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001589 module_exports {
1590 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001591 device_supported: false,
1592 host_supported: true,
1593 native_static_libs: ["mynativelib"],
1594 }
1595
1596 cc_library_static {
1597 name: "mynativelib",
1598 device_supported: false,
1599 host_supported: true,
1600 srcs: [
1601 "Test.cpp",
1602 "aidl/foo/bar/Test.aidl",
1603 ],
1604 export_include_dirs: ["include"],
1605 aidl: {
1606 export_aidl_headers: true,
1607 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001608 stl: "none",
1609 }
1610 `)
1611
Paul Duffin1356d8c2020-02-25 19:26:33 +00001612 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001613 checkAndroidBpContents(`
1614// This is auto-generated. DO NOT EDIT.
1615
1616cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001617 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001618 sdk_member_name: "mynativelib",
1619 device_supported: false,
1620 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001621 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001622 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001623 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001624 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001625 target: {
1626 host: {
1627 enabled: false,
1628 },
1629 linux_glibc: {
1630 enabled: true,
1631 },
1632 linux_glibc_x86_64: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001633 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001634 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001635 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001636 linux_glibc_x86: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001637 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001638 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001639 },
1640 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001641}
1642
1643cc_prebuilt_library_static {
1644 name: "mynativelib",
1645 prefer: false,
1646 device_supported: false,
1647 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001648 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001649 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001650 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001651 target: {
1652 host: {
1653 enabled: false,
1654 },
1655 linux_glibc: {
1656 enabled: true,
1657 },
1658 linux_glibc_x86_64: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001659 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001660 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001661 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001662 linux_glibc_x86: {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001663 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001664 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001665 },
1666 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001667}
1668
Paul Duffine6029182019-12-16 17:43:48 +00001669module_exports_snapshot {
1670 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001671 device_supported: false,
1672 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001673 native_static_libs: ["myexports_mynativelib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001674 target: {
1675 host: {
1676 enabled: false,
1677 },
1678 linux_glibc: {
1679 enabled: true,
1680 },
1681 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001682}
1683`),
1684 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001685include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001686.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001687.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1688.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1689.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1690.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001691.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1692.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1693.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1694`),
1695 )
1696}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001697
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001698func TestSnapshotWithCcLibrary(t *testing.T) {
1699 result := testSdkWithCc(t, `
1700 module_exports {
1701 name: "myexports",
1702 native_libs: ["mynativelib"],
1703 }
1704
1705 cc_library {
1706 name: "mynativelib",
1707 srcs: [
1708 "Test.cpp",
1709 ],
1710 export_include_dirs: ["include"],
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001711 stl: "none",
Paul Duffind6abaa72020-09-07 16:39:22 +01001712 recovery_available: true,
Paul Duffind1edbd42020-08-13 19:45:31 +01001713 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001714 }
1715 `)
1716
1717 result.CheckSnapshot("myexports", "",
1718 checkAndroidBpContents(`
1719// This is auto-generated. DO NOT EDIT.
1720
1721cc_prebuilt_library {
1722 name: "myexports_mynativelib@current",
1723 sdk_member_name: "mynativelib",
1724 installable: false,
Paul Duffind6abaa72020-09-07 16:39:22 +01001725 recovery_available: true,
Paul Duffind1edbd42020-08-13 19:45:31 +01001726 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001727 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001728 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001729 export_include_dirs: ["include/include"],
1730 arch: {
1731 arm64: {
1732 static: {
1733 srcs: ["arm64/lib/mynativelib.a"],
1734 },
1735 shared: {
1736 srcs: ["arm64/lib/mynativelib.so"],
1737 },
1738 },
1739 arm: {
1740 static: {
1741 srcs: ["arm/lib/mynativelib.a"],
1742 },
1743 shared: {
1744 srcs: ["arm/lib/mynativelib.so"],
1745 },
1746 },
1747 },
1748}
1749
1750cc_prebuilt_library {
1751 name: "mynativelib",
1752 prefer: false,
Paul Duffind6abaa72020-09-07 16:39:22 +01001753 recovery_available: true,
Paul Duffind1edbd42020-08-13 19:45:31 +01001754 vendor_available: true,
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001755 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001756 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001757 export_include_dirs: ["include/include"],
1758 arch: {
1759 arm64: {
1760 static: {
1761 srcs: ["arm64/lib/mynativelib.a"],
1762 },
1763 shared: {
1764 srcs: ["arm64/lib/mynativelib.so"],
1765 },
1766 },
1767 arm: {
1768 static: {
1769 srcs: ["arm/lib/mynativelib.a"],
1770 },
1771 shared: {
1772 srcs: ["arm/lib/mynativelib.so"],
1773 },
1774 },
1775 },
1776}
1777
1778module_exports_snapshot {
1779 name: "myexports@current",
1780 native_libs: ["myexports_mynativelib@current"],
1781}
1782`),
1783 checkAllCopyRules(`
1784include/Test.h -> include/include/Test.h
1785.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1786.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1787.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1788.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1789 )
1790}
1791
Paul Duffin13ad94f2020-02-19 16:19:27 +00001792func TestHostSnapshotWithMultiLib64(t *testing.T) {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001793 result := testSdkWithCc(t, `
1794 module_exports {
1795 name: "myexports",
1796 device_supported: false,
1797 host_supported: true,
1798 target: {
1799 host: {
1800 compile_multilib: "64",
1801 },
1802 },
1803 native_static_libs: ["mynativelib"],
1804 }
1805
1806 cc_library_static {
1807 name: "mynativelib",
1808 device_supported: false,
1809 host_supported: true,
1810 srcs: [
1811 "Test.cpp",
1812 "aidl/foo/bar/Test.aidl",
1813 ],
1814 export_include_dirs: ["include"],
1815 aidl: {
1816 export_aidl_headers: true,
1817 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001818 stl: "none",
1819 }
1820 `)
1821
Paul Duffin1356d8c2020-02-25 19:26:33 +00001822 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001823 checkAndroidBpContents(`
1824// This is auto-generated. DO NOT EDIT.
1825
1826cc_prebuilt_library_static {
1827 name: "myexports_mynativelib@current",
1828 sdk_member_name: "mynativelib",
1829 device_supported: false,
1830 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001831 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001832 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001833 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001834 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001835 target: {
1836 host: {
1837 enabled: false,
1838 },
1839 linux_glibc: {
1840 enabled: true,
1841 },
1842 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001843 srcs: ["x86_64/lib/mynativelib.a"],
1844 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1845 },
1846 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001847}
1848
1849cc_prebuilt_library_static {
1850 name: "mynativelib",
1851 prefer: false,
1852 device_supported: false,
1853 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001854 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001855 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001856 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001857 target: {
1858 host: {
1859 enabled: false,
1860 },
1861 linux_glibc: {
1862 enabled: true,
1863 },
1864 linux_glibc_x86_64: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001865 srcs: ["x86_64/lib/mynativelib.a"],
1866 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1867 },
1868 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001869}
1870
1871module_exports_snapshot {
1872 name: "myexports@current",
1873 device_supported: false,
1874 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001875 native_static_libs: ["myexports_mynativelib@current"],
Martin Stjernholm4cfa2c62020-07-10 19:55:36 +01001876 compile_multilib: "64",
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001877 target: {
1878 host: {
1879 enabled: false,
1880 },
1881 linux_glibc: {
1882 enabled: true,
1883 },
1884 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001885}`),
1886 checkAllCopyRules(`
1887include/Test.h -> include/include/Test.h
1888.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1889.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1890.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1891.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1892`),
1893 )
1894}
Paul Duffin91756d22020-02-21 16:29:57 +00001895
1896func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1897 result := testSdkWithCc(t, `
1898 sdk {
1899 name: "mysdk",
1900 native_header_libs: ["mynativeheaders"],
1901 }
1902
1903 cc_library_headers {
1904 name: "mynativeheaders",
1905 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001906 stl: "none",
1907 }
1908 `)
1909
Paul Duffin1356d8c2020-02-25 19:26:33 +00001910 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001911 checkAndroidBpContents(`
1912// This is auto-generated. DO NOT EDIT.
1913
1914cc_prebuilt_library_headers {
1915 name: "mysdk_mynativeheaders@current",
1916 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001917 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001918 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001919 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001920}
1921
1922cc_prebuilt_library_headers {
1923 name: "mynativeheaders",
1924 prefer: false,
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"],
Paul Duffin91756d22020-02-21 16:29:57 +00001928}
1929
1930sdk_snapshot {
1931 name: "mysdk@current",
1932 native_header_libs: ["mysdk_mynativeheaders@current"],
1933}
1934`),
1935 checkAllCopyRules(`
1936include/Test.h -> include/include/Test.h
1937`),
1938 )
1939}
1940
1941func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffin91756d22020-02-21 16:29:57 +00001942 result := testSdkWithCc(t, `
1943 sdk {
1944 name: "mysdk",
1945 device_supported: false,
1946 host_supported: true,
1947 native_header_libs: ["mynativeheaders"],
1948 }
1949
1950 cc_library_headers {
1951 name: "mynativeheaders",
1952 device_supported: false,
1953 host_supported: true,
1954 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001955 stl: "none",
1956 }
1957 `)
1958
Paul Duffin1356d8c2020-02-25 19:26:33 +00001959 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001960 checkAndroidBpContents(`
1961// This is auto-generated. DO NOT EDIT.
1962
1963cc_prebuilt_library_headers {
1964 name: "mysdk_mynativeheaders@current",
1965 sdk_member_name: "mynativeheaders",
1966 device_supported: false,
1967 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001968 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001969 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001970 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001971 target: {
1972 host: {
1973 enabled: false,
1974 },
1975 linux_glibc: {
1976 enabled: true,
1977 },
1978 },
Paul Duffin91756d22020-02-21 16:29:57 +00001979}
1980
1981cc_prebuilt_library_headers {
1982 name: "mynativeheaders",
1983 prefer: false,
1984 device_supported: false,
1985 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001986 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001987 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001988 export_include_dirs: ["include/include"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01001989 target: {
1990 host: {
1991 enabled: false,
1992 },
1993 linux_glibc: {
1994 enabled: true,
1995 },
1996 },
Paul Duffin91756d22020-02-21 16:29:57 +00001997}
1998
1999sdk_snapshot {
2000 name: "mysdk@current",
2001 device_supported: false,
2002 host_supported: true,
2003 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002004 target: {
2005 host: {
2006 enabled: false,
2007 },
2008 linux_glibc: {
2009 enabled: true,
2010 },
2011 },
Paul Duffin91756d22020-02-21 16:29:57 +00002012}
2013`),
2014 checkAllCopyRules(`
2015include/Test.h -> include/include/Test.h
2016`),
2017 )
2018}
Paul Duffina04c1072020-03-02 10:16:35 +00002019
2020func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00002021 result := testSdkWithCc(t, `
2022 sdk {
2023 name: "mysdk",
2024 host_supported: true,
2025 native_header_libs: ["mynativeheaders"],
2026 }
2027
2028 cc_library_headers {
2029 name: "mynativeheaders",
2030 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00002031 stl: "none",
2032 export_system_include_dirs: ["include"],
2033 target: {
2034 android: {
2035 export_include_dirs: ["include-android"],
2036 },
2037 host: {
2038 export_include_dirs: ["include-host"],
2039 },
2040 },
2041 }
2042 `)
2043
2044 result.CheckSnapshot("mysdk", "",
2045 checkAndroidBpContents(`
2046// This is auto-generated. DO NOT EDIT.
2047
2048cc_prebuilt_library_headers {
2049 name: "mysdk_mynativeheaders@current",
2050 sdk_member_name: "mynativeheaders",
2051 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002052 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002053 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002054 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002055 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002056 host: {
2057 enabled: false,
2058 },
Paul Duffina04c1072020-03-02 10:16:35 +00002059 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002060 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002061 },
2062 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002063 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002064 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002065 },
2066 },
Paul Duffina04c1072020-03-02 10:16:35 +00002067}
2068
2069cc_prebuilt_library_headers {
2070 name: "mynativeheaders",
2071 prefer: false,
2072 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00002073 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01002074 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01002075 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00002076 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002077 host: {
2078 enabled: false,
2079 },
Paul Duffina04c1072020-03-02 10:16:35 +00002080 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01002081 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00002082 },
2083 linux_glibc: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002084 enabled: true,
Paul Duffined62b9c2020-06-16 16:12:50 +01002085 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00002086 },
2087 },
Paul Duffina04c1072020-03-02 10:16:35 +00002088}
2089
2090sdk_snapshot {
2091 name: "mysdk@current",
2092 host_supported: true,
2093 native_header_libs: ["mysdk_mynativeheaders@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002094 target: {
2095 host: {
2096 enabled: false,
2097 },
2098 linux_glibc: {
2099 enabled: true,
2100 },
2101 },
Paul Duffina04c1072020-03-02 10:16:35 +00002102}
2103`),
2104 checkAllCopyRules(`
Paul Duffined62b9c2020-06-16 16:12:50 +01002105include/Test.h -> common_os/include/include/Test.h
2106include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
2107include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
Paul Duffina04c1072020-03-02 10:16:35 +00002108`),
2109 )
2110}
Martin Stjernholm10566a02020-03-24 01:19:52 +00002111
2112func TestSystemSharedLibPropagation(t *testing.T) {
2113 result := testSdkWithCc(t, `
2114 sdk {
2115 name: "mysdk",
2116 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
2117 }
2118
2119 cc_library {
2120 name: "sslnil",
2121 host_supported: true,
2122 }
2123
2124 cc_library {
2125 name: "sslempty",
2126 system_shared_libs: [],
2127 }
2128
2129 cc_library {
2130 name: "sslnonempty",
2131 system_shared_libs: ["sslnil"],
2132 }
2133 `)
2134
2135 result.CheckSnapshot("mysdk", "",
2136 checkAndroidBpContents(`
2137// This is auto-generated. DO NOT EDIT.
2138
2139cc_prebuilt_library_shared {
2140 name: "mysdk_sslnil@current",
2141 sdk_member_name: "sslnil",
2142 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002143 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002144 arch: {
2145 arm64: {
2146 srcs: ["arm64/lib/sslnil.so"],
2147 },
2148 arm: {
2149 srcs: ["arm/lib/sslnil.so"],
2150 },
2151 },
2152}
2153
2154cc_prebuilt_library_shared {
2155 name: "sslnil",
2156 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002157 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002158 arch: {
2159 arm64: {
2160 srcs: ["arm64/lib/sslnil.so"],
2161 },
2162 arm: {
2163 srcs: ["arm/lib/sslnil.so"],
2164 },
2165 },
2166}
2167
2168cc_prebuilt_library_shared {
2169 name: "mysdk_sslempty@current",
2170 sdk_member_name: "sslempty",
2171 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002172 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002173 system_shared_libs: [],
2174 arch: {
2175 arm64: {
2176 srcs: ["arm64/lib/sslempty.so"],
2177 },
2178 arm: {
2179 srcs: ["arm/lib/sslempty.so"],
2180 },
2181 },
2182}
2183
2184cc_prebuilt_library_shared {
2185 name: "sslempty",
2186 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002187 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002188 system_shared_libs: [],
2189 arch: {
2190 arm64: {
2191 srcs: ["arm64/lib/sslempty.so"],
2192 },
2193 arm: {
2194 srcs: ["arm/lib/sslempty.so"],
2195 },
2196 },
2197}
2198
2199cc_prebuilt_library_shared {
2200 name: "mysdk_sslnonempty@current",
2201 sdk_member_name: "sslnonempty",
2202 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002203 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002204 system_shared_libs: ["mysdk_sslnil@current"],
2205 arch: {
2206 arm64: {
2207 srcs: ["arm64/lib/sslnonempty.so"],
2208 },
2209 arm: {
2210 srcs: ["arm/lib/sslnonempty.so"],
2211 },
2212 },
2213}
2214
2215cc_prebuilt_library_shared {
2216 name: "sslnonempty",
2217 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002218 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002219 system_shared_libs: ["sslnil"],
2220 arch: {
2221 arm64: {
2222 srcs: ["arm64/lib/sslnonempty.so"],
2223 },
2224 arm: {
2225 srcs: ["arm/lib/sslnonempty.so"],
2226 },
2227 },
2228}
2229
2230sdk_snapshot {
2231 name: "mysdk@current",
2232 native_shared_libs: [
2233 "mysdk_sslnil@current",
2234 "mysdk_sslempty@current",
2235 "mysdk_sslnonempty@current",
2236 ],
2237}
2238`))
2239
2240 result = testSdkWithCc(t, `
2241 sdk {
2242 name: "mysdk",
2243 host_supported: true,
2244 native_shared_libs: ["sslvariants"],
2245 }
2246
2247 cc_library {
2248 name: "sslvariants",
2249 host_supported: true,
2250 target: {
2251 android: {
2252 system_shared_libs: [],
2253 },
2254 },
2255 }
2256 `)
2257
2258 result.CheckSnapshot("mysdk", "",
2259 checkAndroidBpContents(`
2260// This is auto-generated. DO NOT EDIT.
2261
2262cc_prebuilt_library_shared {
2263 name: "mysdk_sslvariants@current",
2264 sdk_member_name: "sslvariants",
2265 host_supported: true,
2266 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002267 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002268 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002269 host: {
2270 enabled: false,
2271 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002272 android: {
2273 system_shared_libs: [],
2274 },
2275 android_arm64: {
2276 srcs: ["android/arm64/lib/sslvariants.so"],
2277 },
2278 android_arm: {
2279 srcs: ["android/arm/lib/sslvariants.so"],
2280 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002281 linux_glibc: {
2282 enabled: true,
2283 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002284 linux_glibc_x86_64: {
2285 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2286 },
2287 linux_glibc_x86: {
2288 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2289 },
2290 },
2291}
2292
2293cc_prebuilt_library_shared {
2294 name: "sslvariants",
2295 prefer: false,
2296 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002297 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00002298 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002299 host: {
2300 enabled: false,
2301 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002302 android: {
2303 system_shared_libs: [],
2304 },
2305 android_arm64: {
2306 srcs: ["android/arm64/lib/sslvariants.so"],
2307 },
2308 android_arm: {
2309 srcs: ["android/arm/lib/sslvariants.so"],
2310 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002311 linux_glibc: {
2312 enabled: true,
2313 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002314 linux_glibc_x86_64: {
2315 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2316 },
2317 linux_glibc_x86: {
2318 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2319 },
2320 },
2321}
2322
2323sdk_snapshot {
2324 name: "mysdk@current",
2325 host_supported: true,
2326 native_shared_libs: ["mysdk_sslvariants@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002327 target: {
2328 host: {
2329 enabled: false,
2330 },
2331 linux_glibc: {
2332 enabled: true,
2333 },
2334 },
Martin Stjernholm10566a02020-03-24 01:19:52 +00002335}
2336`))
2337}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002338
2339func TestStubsLibrary(t *testing.T) {
2340 result := testSdkWithCc(t, `
2341 sdk {
2342 name: "mysdk",
2343 native_shared_libs: ["stubslib"],
2344 }
2345
2346 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002347 name: "internaldep",
2348 }
2349
2350 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002351 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01002352 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002353 stubs: {
2354 symbol_file: "some/where/stubslib.map.txt",
2355 versions: ["1", "2", "3"],
2356 },
2357 }
2358 `)
2359
2360 result.CheckSnapshot("mysdk", "",
2361 checkAndroidBpContents(`
2362// This is auto-generated. DO NOT EDIT.
2363
2364cc_prebuilt_library_shared {
2365 name: "mysdk_stubslib@current",
2366 sdk_member_name: "stubslib",
2367 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002368 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002369 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002370 versions: [
2371 "1",
2372 "2",
2373 "3",
2374 ],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002375 },
2376 arch: {
2377 arm64: {
2378 srcs: ["arm64/lib/stubslib.so"],
2379 },
2380 arm: {
2381 srcs: ["arm/lib/stubslib.so"],
2382 },
2383 },
2384}
2385
2386cc_prebuilt_library_shared {
2387 name: "stubslib",
2388 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002389 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002390 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002391 versions: [
2392 "1",
2393 "2",
2394 "3",
2395 ],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002396 },
2397 arch: {
2398 arm64: {
2399 srcs: ["arm64/lib/stubslib.so"],
2400 },
2401 arm: {
2402 srcs: ["arm/lib/stubslib.so"],
2403 },
2404 },
2405}
2406
2407sdk_snapshot {
2408 name: "mysdk@current",
2409 native_shared_libs: ["mysdk_stubslib@current"],
2410}
2411`))
2412}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002413
2414func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002415 result := testSdkWithCc(t, `
2416 sdk {
2417 name: "mysdk",
2418 host_supported: true,
2419 native_shared_libs: ["stubslib"],
2420 }
2421
2422 cc_library {
2423 name: "internaldep",
2424 host_supported: true,
2425 }
2426
2427 cc_library {
2428 name: "stubslib",
2429 host_supported: true,
2430 shared_libs: ["internaldep"],
2431 stubs: {
2432 symbol_file: "some/where/stubslib.map.txt",
2433 versions: ["1", "2", "3"],
2434 },
2435 }
2436 `)
2437
2438 result.CheckSnapshot("mysdk", "",
2439 checkAndroidBpContents(`
2440// This is auto-generated. DO NOT EDIT.
2441
2442cc_prebuilt_library_shared {
2443 name: "mysdk_stubslib@current",
2444 sdk_member_name: "stubslib",
2445 host_supported: true,
2446 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002447 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002448 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002449 versions: [
2450 "1",
2451 "2",
2452 "3",
2453 ],
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002454 },
2455 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002456 host: {
2457 enabled: false,
2458 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002459 android_arm64: {
2460 srcs: ["android/arm64/lib/stubslib.so"],
2461 },
2462 android_arm: {
2463 srcs: ["android/arm/lib/stubslib.so"],
2464 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002465 linux_glibc: {
2466 enabled: true,
2467 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002468 linux_glibc_x86_64: {
2469 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2470 },
2471 linux_glibc_x86: {
2472 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2473 },
2474 },
2475}
2476
2477cc_prebuilt_library_shared {
2478 name: "stubslib",
2479 prefer: false,
2480 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002481 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002482 stubs: {
Martin Stjernholm618b6712020-09-24 16:53:04 +01002483 versions: [
2484 "1",
2485 "2",
2486 "3",
2487 ],
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002488 },
2489 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002490 host: {
2491 enabled: false,
2492 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002493 android_arm64: {
2494 srcs: ["android/arm64/lib/stubslib.so"],
2495 },
2496 android_arm: {
2497 srcs: ["android/arm/lib/stubslib.so"],
2498 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002499 linux_glibc: {
2500 enabled: true,
2501 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002502 linux_glibc_x86_64: {
2503 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2504 },
2505 linux_glibc_x86: {
2506 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2507 },
2508 },
2509}
2510
2511sdk_snapshot {
2512 name: "mysdk@current",
2513 host_supported: true,
2514 native_shared_libs: ["mysdk_stubslib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002515 target: {
2516 host: {
2517 enabled: false,
2518 },
2519 linux_glibc: {
2520 enabled: true,
2521 },
2522 },
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002523}
2524`))
2525}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002526
2527func TestUniqueHostSoname(t *testing.T) {
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002528 result := testSdkWithCc(t, `
2529 sdk {
2530 name: "mysdk",
2531 host_supported: true,
2532 native_shared_libs: ["mylib"],
2533 }
2534
2535 cc_library {
2536 name: "mylib",
2537 host_supported: true,
2538 unique_host_soname: true,
2539 }
2540 `)
2541
2542 result.CheckSnapshot("mysdk", "",
2543 checkAndroidBpContents(`
2544// This is auto-generated. DO NOT EDIT.
2545
2546cc_prebuilt_library_shared {
2547 name: "mysdk_mylib@current",
2548 sdk_member_name: "mylib",
2549 host_supported: true,
2550 installable: false,
2551 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002552 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002553 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002554 host: {
2555 enabled: false,
2556 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002557 android_arm64: {
2558 srcs: ["android/arm64/lib/mylib.so"],
2559 },
2560 android_arm: {
2561 srcs: ["android/arm/lib/mylib.so"],
2562 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002563 linux_glibc: {
2564 enabled: true,
2565 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002566 linux_glibc_x86_64: {
2567 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2568 },
2569 linux_glibc_x86: {
2570 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2571 },
2572 },
2573}
2574
2575cc_prebuilt_library_shared {
2576 name: "mylib",
2577 prefer: false,
2578 host_supported: true,
2579 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002580 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002581 target: {
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002582 host: {
2583 enabled: false,
2584 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002585 android_arm64: {
2586 srcs: ["android/arm64/lib/mylib.so"],
2587 },
2588 android_arm: {
2589 srcs: ["android/arm/lib/mylib.so"],
2590 },
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002591 linux_glibc: {
2592 enabled: true,
2593 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002594 linux_glibc_x86_64: {
2595 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2596 },
2597 linux_glibc_x86: {
2598 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2599 },
2600 },
2601}
2602
2603sdk_snapshot {
2604 name: "mysdk@current",
2605 host_supported: true,
2606 native_shared_libs: ["mysdk_mylib@current"],
Martin Stjernholmcaa47d72020-07-11 04:52:24 +01002607 target: {
2608 host: {
2609 enabled: false,
2610 },
2611 linux_glibc: {
2612 enabled: true,
2613 },
2614 },
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002615}
2616`),
2617 checkAllCopyRules(`
2618.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2619.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2620.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2621.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2622`),
2623 )
2624}