blob: 315669afe76c40b89864a7c70a24359f77b0cb6d [file] [log] [blame]
Paul Duffina80fdec2019-12-03 15:25:00 +00001// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package sdk
16
17import (
18 "testing"
19
20 "android/soong/cc"
21)
22
Paul Duffind835daa2019-11-30 17:49:09 +000023func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
24 t.Helper()
25
26 fs := map[string][]byte{
27 "Test.cpp": nil,
28 "include/Test.h": nil,
29 "libfoo.so": nil,
30 "aidl/foo/bar/Test.aidl": nil,
31 }
32 return testSdkWithFs(t, bp, fs)
33}
34
Paul Duffina80fdec2019-12-03 15:25:00 +000035// Contains tests for SDK members provided by the cc package.
36
37func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000038 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000039 sdk {
40 name: "mysdk",
41 native_shared_libs: ["sdkmember"],
42 }
43
44 cc_library_shared {
45 name: "sdkmember",
46 srcs: ["Test.cpp"],
47 system_shared_libs: [],
48 stl: "none",
49 }
50 `)
51
52 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_core_shared").(*cc.Module).OutputFile()
53 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_core_shared").(*cc.Module).OutputFile()
54
55 var inputs []string
56 buildParams := result.Module("mysdk", "android_common").BuildParamsForTests()
57 for _, bp := range buildParams {
58 if bp.Input != nil {
59 inputs = append(inputs, bp.Input.String())
60 }
61 }
62
63 // ensure that both 32/64 outputs are inputs of the sdk snapshot
64 ensureListContains(t, inputs, armOutput.String())
65 ensureListContains(t, inputs, arm64Output.String())
66}
67
68func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000069 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000070 sdk {
71 name: "mysdk",
72 native_shared_libs: ["sdkmember"],
73 }
74
75 sdk_snapshot {
76 name: "mysdk@1",
77 native_shared_libs: ["sdkmember_mysdk_1"],
78 }
79
80 sdk_snapshot {
81 name: "mysdk@2",
82 native_shared_libs: ["sdkmember_mysdk_2"],
83 }
84
85 cc_prebuilt_library_shared {
86 name: "sdkmember",
87 srcs: ["libfoo.so"],
88 prefer: false,
89 system_shared_libs: [],
90 stl: "none",
91 }
92
93 cc_prebuilt_library_shared {
94 name: "sdkmember_mysdk_1",
95 sdk_member_name: "sdkmember",
96 srcs: ["libfoo.so"],
97 system_shared_libs: [],
98 stl: "none",
99 }
100
101 cc_prebuilt_library_shared {
102 name: "sdkmember_mysdk_2",
103 sdk_member_name: "sdkmember",
104 srcs: ["libfoo.so"],
105 system_shared_libs: [],
106 stl: "none",
107 }
108
109 cc_library_shared {
110 name: "mycpplib",
111 srcs: ["Test.cpp"],
112 shared_libs: ["sdkmember"],
113 system_shared_libs: [],
114 stl: "none",
115 }
116
117 apex {
118 name: "myapex",
119 native_shared_libs: ["mycpplib"],
120 uses_sdks: ["mysdk@1"],
121 key: "myapex.key",
122 certificate: ":myapex.cert",
123 }
124
125 apex {
126 name: "myapex2",
127 native_shared_libs: ["mycpplib"],
128 uses_sdks: ["mysdk@2"],
129 key: "myapex.key",
130 certificate: ":myapex.cert",
131 }
132 `)
133
134 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_core_shared_myapex").Rule("toc").Output
135 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_core_shared_myapex2").Rule("toc").Output
136
137 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_core_shared_myapex")
138 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_core_shared_myapex2")
139
140 // Depending on the uses_sdks value, different libs are linked
141 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
142 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
143}
144
145func TestSnapshotWithCcShared(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000146 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000147 sdk {
148 name: "mysdk",
149 native_shared_libs: ["mynativelib"],
150 }
151
152 cc_library_shared {
153 name: "mynativelib",
154 srcs: [
155 "Test.cpp",
156 "aidl/foo/bar/Test.aidl",
157 ],
158 export_include_dirs: ["include"],
159 aidl: {
160 export_aidl_headers: true,
161 },
162 system_shared_libs: [],
163 stl: "none",
164 }
165 `)
166
167 result.CheckSnapshot("mysdk", "android_common",
168 checkAndroidBpContents(`
169// This is auto-generated. DO NOT EDIT.
170
171cc_prebuilt_library_shared {
172 name: "mysdk_mynativelib@current",
173 sdk_member_name: "mynativelib",
174 arch: {
175 arm64: {
176 srcs: ["arm64/lib/mynativelib.so"],
177 export_include_dirs: [
178 "arm64/include/include",
179 "arm64/include_gen/mynativelib",
180 ],
181 },
182 arm: {
183 srcs: ["arm/lib/mynativelib.so"],
184 export_include_dirs: [
185 "arm/include/include",
186 "arm/include_gen/mynativelib",
187 ],
188 },
189 },
190 stl: "none",
191 system_shared_libs: [],
192}
193
194cc_prebuilt_library_shared {
195 name: "mynativelib",
196 prefer: false,
197 arch: {
198 arm64: {
199 srcs: ["arm64/lib/mynativelib.so"],
200 export_include_dirs: [
201 "arm64/include/include",
202 "arm64/include_gen/mynativelib",
203 ],
204 },
205 arm: {
206 srcs: ["arm/lib/mynativelib.so"],
207 export_include_dirs: [
208 "arm/include/include",
209 "arm/include_gen/mynativelib",
210 ],
211 },
212 },
213 stl: "none",
214 system_shared_libs: [],
215}
216
217sdk_snapshot {
218 name: "mysdk@current",
219 native_shared_libs: ["mysdk_mynativelib@current"],
220}
221`),
222 checkAllCopyRules(`
223.intermediates/mynativelib/android_arm64_armv8-a_core_shared/mynativelib.so -> arm64/lib/mynativelib.so
224include/Test.h -> arm64/include/include/Test.h
225.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
226.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
227.intermediates/mynativelib/android_arm64_armv8-a_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
228.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/mynativelib.so -> arm/lib/mynativelib.so
229include/Test.h -> arm/include/include/Test.h
230.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
231.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
232.intermediates/mynativelib/android_arm_armv7-a-neon_core_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
233`),
234 )
235}
236
237func TestHostSnapshotWithCcShared(t *testing.T) {
238 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
239 SkipIfNotLinux(t)
240
Paul Duffind835daa2019-11-30 17:49:09 +0000241 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000242 sdk {
243 name: "mysdk",
244 device_supported: false,
245 host_supported: true,
246 native_shared_libs: ["mynativelib"],
247 }
248
249 cc_library_shared {
250 name: "mynativelib",
251 device_supported: false,
252 host_supported: true,
253 srcs: [
254 "Test.cpp",
255 "aidl/foo/bar/Test.aidl",
256 ],
257 export_include_dirs: ["include"],
258 aidl: {
259 export_aidl_headers: true,
260 },
261 system_shared_libs: [],
262 stl: "none",
263 }
264 `)
265
266 result.CheckSnapshot("mysdk", "linux_glibc_common",
267 checkAndroidBpContents(`
268// This is auto-generated. DO NOT EDIT.
269
270cc_prebuilt_library_shared {
271 name: "mysdk_mynativelib@current",
272 sdk_member_name: "mynativelib",
273 device_supported: false,
274 host_supported: true,
275 arch: {
276 x86_64: {
277 srcs: ["x86_64/lib/mynativelib.so"],
278 export_include_dirs: [
279 "x86_64/include/include",
280 "x86_64/include_gen/mynativelib",
281 ],
282 },
283 x86: {
284 srcs: ["x86/lib/mynativelib.so"],
285 export_include_dirs: [
286 "x86/include/include",
287 "x86/include_gen/mynativelib",
288 ],
289 },
290 },
291 stl: "none",
292 system_shared_libs: [],
293}
294
295cc_prebuilt_library_shared {
296 name: "mynativelib",
297 prefer: false,
298 device_supported: false,
299 host_supported: true,
300 arch: {
301 x86_64: {
302 srcs: ["x86_64/lib/mynativelib.so"],
303 export_include_dirs: [
304 "x86_64/include/include",
305 "x86_64/include_gen/mynativelib",
306 ],
307 },
308 x86: {
309 srcs: ["x86/lib/mynativelib.so"],
310 export_include_dirs: [
311 "x86/include/include",
312 "x86/include_gen/mynativelib",
313 ],
314 },
315 },
316 stl: "none",
317 system_shared_libs: [],
318}
319
320sdk_snapshot {
321 name: "mysdk@current",
322 device_supported: false,
323 host_supported: true,
324 native_shared_libs: ["mysdk_mynativelib@current"],
325}
326`),
327 checkAllCopyRules(`
328.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
329include/Test.h -> x86_64/include/include/Test.h
330.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
331.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
332.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
333.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
334include/Test.h -> x86/include/include/Test.h
335.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
336.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
337.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
338`),
339 )
340}