blob: 85e3d875e537f8cfc16cdd9ca998cc8a95401ca2 [file] [log] [blame]
Jiyong Parkd1063c12019-07-17 20:08:41 +09001// Copyright 2019 Google Inc. All rights reserved.
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 (
Martin Stjernholm3ff2e662020-07-15 14:38:15 +010018 "log"
19 "os"
Colin Cross0c66bc62021-07-20 09:47:41 -070020 "runtime"
Jiyong Parkd1063c12019-07-17 20:08:41 +090021 "testing"
Paul Duffinb07fa512020-03-10 22:17:04 +000022
Colin Cross0c66bc62021-07-20 09:47:41 -070023 "android/soong/android"
24
Paul Duffinb07fa512020-03-10 22:17:04 +000025 "github.com/google/blueprint/proptools"
Jiyong Parkd1063c12019-07-17 20:08:41 +090026)
27
Paul Duffin82d90432019-11-30 09:24:33 +000028// Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE.
29func TestMain(m *testing.M) {
Colin Cross0c66bc62021-07-20 09:47:41 -070030 if runtime.GOOS != "linux" {
Martin Stjernholm3ff2e662020-07-15 14:38:15 +010031 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
Colin Cross0c66bc62021-07-20 09:47:41 -070032 log.Printf("Skipping as sdk snapshot generation is only supported on linux not %s", runtime.GOOS)
Martin Stjernholm3ff2e662020-07-15 14:38:15 +010033 os.Exit(0)
34 }
35
Paul Duffinabbf63d2021-03-18 01:47:31 +000036 os.Exit(m.Run())
Jiyong Parkd1063c12019-07-17 20:08:41 +090037}
38
Jiyong Parka7bc8ad2019-10-15 15:20:07 +090039func TestDepNotInRequiredSdks(t *testing.T) {
40 testSdkError(t, `module "myjavalib".*depends on "otherlib".*that isn't part of the required SDKs:.*`, `
41 sdk {
42 name: "mysdk",
Paul Duffina0dbf432019-12-05 11:25:53 +000043 java_header_libs: ["sdkmember"],
Jiyong Parka7bc8ad2019-10-15 15:20:07 +090044 }
45
46 sdk_snapshot {
47 name: "mysdk@1",
Paul Duffina0dbf432019-12-05 11:25:53 +000048 java_header_libs: ["sdkmember_mysdk_1"],
Jiyong Parka7bc8ad2019-10-15 15:20:07 +090049 }
50
51 java_import {
52 name: "sdkmember",
53 prefer: false,
54 host_supported: true,
55 }
56
57 java_import {
58 name: "sdkmember_mysdk_1",
59 sdk_member_name: "sdkmember",
60 host_supported: true,
61 }
62
63 java_library {
64 name: "myjavalib",
65 srcs: ["Test.java"],
66 libs: [
67 "sdkmember",
68 "otherlib",
69 ],
70 system_modules: "none",
71 sdk_version: "none",
72 compile_dex: true,
73 host_supported: true,
Jooyung Han5e9013b2020-03-10 06:23:13 +090074 apex_available: ["myapex"],
Jiyong Parka7bc8ad2019-10-15 15:20:07 +090075 }
76
77 // this lib is no in mysdk
78 java_library {
79 name: "otherlib",
80 srcs: ["Test.java"],
81 system_modules: "none",
82 sdk_version: "none",
83 compile_dex: true,
84 host_supported: true,
85 }
86
87 apex {
88 name: "myapex",
89 java_libs: ["myjavalib"],
90 uses_sdks: ["mysdk@1"],
91 key: "myapex.key",
92 certificate: ":myapex.cert",
93 }
94 `)
95}
Paul Duffin593b3c92019-12-05 14:31:48 +000096
97// Ensure that prebuilt modules have the same effective visibility as the source
98// modules.
99func TestSnapshotVisibility(t *testing.T) {
100 packageBp := `
101 package {
102 default_visibility: ["//other/foo"],
103 }
104
105 sdk {
106 name: "mysdk",
107 visibility: [
108 "//other/foo",
109 // This short form will be replaced with //package:__subpackages__ in the
110 // generated sdk_snapshot.
111 ":__subpackages__",
112 ],
Paul Duffin157f40f2020-09-29 16:01:08 +0100113 prebuilt_visibility: [
114 "//prebuilts/mysdk",
115 ],
Paul Duffin593b3c92019-12-05 14:31:48 +0000116 java_header_libs: [
117 "myjavalib",
118 "mypublicjavalib",
119 "mydefaultedjavalib",
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100120 "myprivatejavalib",
Paul Duffin593b3c92019-12-05 14:31:48 +0000121 ],
122 }
123
124 java_library {
125 name: "myjavalib",
126 // Uses package default visibility
127 srcs: ["Test.java"],
128 system_modules: "none",
129 sdk_version: "none",
130 }
131
Paul Duffin44885e22020-02-19 16:10:09 +0000132 java_defaults {
133 name: "java-defaults",
Jooyung Han5e9013b2020-03-10 06:23:13 +0900134 visibility: ["//other/bar"],
Paul Duffin44885e22020-02-19 16:10:09 +0000135 }
136
Paul Duffin593b3c92019-12-05 14:31:48 +0000137 java_library {
138 name: "mypublicjavalib",
Paul Duffin44885e22020-02-19 16:10:09 +0000139 defaults: ["java-defaults"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000140 visibility: ["//visibility:public"],
141 srcs: ["Test.java"],
142 system_modules: "none",
143 sdk_version: "none",
144 }
145
146 java_defaults {
147 name: "myjavadefaults",
148 visibility: ["//other/bar"],
149 }
150
151 java_library {
152 name: "mydefaultedjavalib",
153 defaults: ["myjavadefaults"],
154 srcs: ["Test.java"],
155 system_modules: "none",
156 sdk_version: "none",
157 }
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100158
159 java_library {
160 name: "myprivatejavalib",
161 srcs: ["Test.java"],
162 visibility: ["//visibility:private"],
163 system_modules: "none",
164 sdk_version: "none",
165 }
Paul Duffin593b3c92019-12-05 14:31:48 +0000166 `
167
168 result := testSdkWithFs(t, ``,
169 map[string][]byte{
170 "package/Test.java": nil,
171 "package/Android.bp": []byte(packageBp),
172 })
173
Paul Duffin36474d32021-03-12 12:19:43 +0000174 CheckSnapshot(t, result, "mysdk", "package",
Paul Duffin593b3c92019-12-05 14:31:48 +0000175 checkAndroidBpContents(`
176// This is auto-generated. DO NOT EDIT.
177
178java_import {
179 name: "mysdk_myjavalib@current",
180 sdk_member_name: "myjavalib",
Martin Stjernholm0641d182020-05-13 02:20:06 +0100181 visibility: [
182 "//other/foo",
183 "//package",
Paul Duffin157f40f2020-09-29 16:01:08 +0100184 "//prebuilts/mysdk",
Martin Stjernholm0641d182020-05-13 02:20:06 +0100185 ],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000186 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000187 jars: ["java/myjavalib.jar"],
188}
189
190java_import {
191 name: "myjavalib",
192 prefer: false,
Martin Stjernholm0641d182020-05-13 02:20:06 +0100193 visibility: [
194 "//other/foo",
195 "//package",
Paul Duffin157f40f2020-09-29 16:01:08 +0100196 "//prebuilts/mysdk",
Martin Stjernholm0641d182020-05-13 02:20:06 +0100197 ],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000198 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000199 jars: ["java/myjavalib.jar"],
200}
201
202java_import {
203 name: "mysdk_mypublicjavalib@current",
204 sdk_member_name: "mypublicjavalib",
205 visibility: ["//visibility:public"],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000206 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000207 jars: ["java/mypublicjavalib.jar"],
208}
209
210java_import {
211 name: "mypublicjavalib",
212 prefer: false,
213 visibility: ["//visibility:public"],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000214 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000215 jars: ["java/mypublicjavalib.jar"],
216}
217
218java_import {
219 name: "mysdk_mydefaultedjavalib@current",
220 sdk_member_name: "mydefaultedjavalib",
Martin Stjernholm0641d182020-05-13 02:20:06 +0100221 visibility: [
222 "//other/bar",
223 "//package",
Paul Duffin157f40f2020-09-29 16:01:08 +0100224 "//prebuilts/mysdk",
Martin Stjernholm0641d182020-05-13 02:20:06 +0100225 ],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000226 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000227 jars: ["java/mydefaultedjavalib.jar"],
228}
229
230java_import {
231 name: "mydefaultedjavalib",
232 prefer: false,
Martin Stjernholm0641d182020-05-13 02:20:06 +0100233 visibility: [
234 "//other/bar",
235 "//package",
Paul Duffin157f40f2020-09-29 16:01:08 +0100236 "//prebuilts/mysdk",
Martin Stjernholm0641d182020-05-13 02:20:06 +0100237 ],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000238 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000239 jars: ["java/mydefaultedjavalib.jar"],
240}
241
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100242java_import {
243 name: "mysdk_myprivatejavalib@current",
244 sdk_member_name: "myprivatejavalib",
Paul Duffin157f40f2020-09-29 16:01:08 +0100245 visibility: [
246 "//package",
247 "//prebuilts/mysdk",
248 ],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000249 apex_available: ["//apex_available:platform"],
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100250 jars: ["java/myprivatejavalib.jar"],
251}
252
253java_import {
254 name: "myprivatejavalib",
255 prefer: false,
Paul Duffin157f40f2020-09-29 16:01:08 +0100256 visibility: [
257 "//package",
258 "//prebuilts/mysdk",
259 ],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000260 apex_available: ["//apex_available:platform"],
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100261 jars: ["java/myprivatejavalib.jar"],
262}
263
Paul Duffin593b3c92019-12-05 14:31:48 +0000264sdk_snapshot {
265 name: "mysdk@current",
266 visibility: [
Martin Stjernholm01407c52020-05-13 01:54:21 +0100267 "//other/foo",
Paul Duffin593b3c92019-12-05 14:31:48 +0000268 "//package:__subpackages__",
269 ],
270 java_header_libs: [
271 "mysdk_myjavalib@current",
272 "mysdk_mypublicjavalib@current",
273 "mysdk_mydefaultedjavalib@current",
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100274 "mysdk_myprivatejavalib@current",
Paul Duffin593b3c92019-12-05 14:31:48 +0000275 ],
276}
277`))
278}
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000279
Paul Duffin157f40f2020-09-29 16:01:08 +0100280func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) {
281 testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, `
282 sdk {
283 name: "mysdk",
284 prebuilt_visibility: [
285 "//foo",
286 "//visibility:private",
287 ],
288 }
289`)
290}
291
292func TestPrebuiltVisibilityProperty_AddPrivate(t *testing.T) {
293 testSdkError(t, `prebuilt_visibility: "//visibility:private" does not widen the visibility`, `
294 sdk {
295 name: "mysdk",
296 prebuilt_visibility: [
297 "//visibility:private",
298 ],
299 java_header_libs: [
300 "myjavalib",
301 ],
302 }
303
304 java_library {
305 name: "myjavalib",
306 // Uses package default visibility
307 srcs: ["Test.java"],
308 system_modules: "none",
309 sdk_version: "none",
310 }
311`)
312}
313
Paul Duffin8edc99c2021-03-09 23:02:20 +0000314func TestSdkInstall(t *testing.T) {
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000315 sdk := `
316 sdk {
317 name: "mysdk",
318 }
319 `
Paul Duffin8edc99c2021-03-09 23:02:20 +0000320 result := testSdkWithFs(t, sdk, nil)
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000321
Paul Duffin36474d32021-03-12 12:19:43 +0000322 CheckSnapshot(t, result, "mysdk", "",
323 checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`))
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000324}
Paul Duffinb07fa512020-03-10 22:17:04 +0000325
326type EmbeddedPropertiesStruct struct {
Paul Duffin864e1b42020-05-06 10:23:19 +0100327 S_Embedded_Common string `android:"arch_variant"`
328 S_Embedded_Different string `android:"arch_variant"`
Paul Duffinb07fa512020-03-10 22:17:04 +0000329}
330
331type testPropertiesStruct struct {
Paul Duffin4b8b7932020-05-06 12:35:38 +0100332 name string
Paul Duffinb07fa512020-03-10 22:17:04 +0000333 private string
334 Public_Kept string `sdk:"keep"`
335 S_Common string
Paul Duffin864e1b42020-05-06 10:23:19 +0100336 S_Different string `android:"arch_variant"`
Paul Duffinb07fa512020-03-10 22:17:04 +0000337 A_Common []string
Paul Duffin864e1b42020-05-06 10:23:19 +0100338 A_Different []string `android:"arch_variant"`
Paul Duffinb07fa512020-03-10 22:17:04 +0000339 F_Common *bool
Paul Duffin864e1b42020-05-06 10:23:19 +0100340 F_Different *bool `android:"arch_variant"`
Paul Duffinb07fa512020-03-10 22:17:04 +0000341 EmbeddedPropertiesStruct
342}
343
Paul Duffinf34f6d82020-04-30 15:48:31 +0100344func (p *testPropertiesStruct) optimizableProperties() interface{} {
345 return p
346}
347
Paul Duffin4b8b7932020-05-06 12:35:38 +0100348func (p *testPropertiesStruct) String() string {
349 return p.name
350}
351
352var _ propertiesContainer = (*testPropertiesStruct)(nil)
353
Paul Duffinb07fa512020-03-10 22:17:04 +0000354func TestCommonValueOptimization(t *testing.T) {
Paul Duffin4b8b7932020-05-06 12:35:38 +0100355 common := &testPropertiesStruct{name: "common"}
Paul Duffinf34f6d82020-04-30 15:48:31 +0100356 structs := []propertiesContainer{
Paul Duffinb07fa512020-03-10 22:17:04 +0000357 &testPropertiesStruct{
Paul Duffin4b8b7932020-05-06 12:35:38 +0100358 name: "struct-0",
Paul Duffinb07fa512020-03-10 22:17:04 +0000359 private: "common",
360 Public_Kept: "common",
361 S_Common: "common",
362 S_Different: "upper",
363 A_Common: []string{"first", "second"},
364 A_Different: []string{"alpha", "beta"},
365 F_Common: proptools.BoolPtr(false),
366 F_Different: proptools.BoolPtr(false),
367 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
368 S_Embedded_Common: "embedded_common",
369 S_Embedded_Different: "embedded_upper",
370 },
371 },
372 &testPropertiesStruct{
Paul Duffin4b8b7932020-05-06 12:35:38 +0100373 name: "struct-1",
Paul Duffinb07fa512020-03-10 22:17:04 +0000374 private: "common",
375 Public_Kept: "common",
376 S_Common: "common",
377 S_Different: "lower",
378 A_Common: []string{"first", "second"},
379 A_Different: []string{"alpha", "delta"},
380 F_Common: proptools.BoolPtr(false),
381 F_Different: proptools.BoolPtr(true),
382 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
383 S_Embedded_Common: "embedded_common",
384 S_Embedded_Different: "embedded_lower",
385 },
386 },
387 }
388
389 extractor := newCommonValueExtractor(common)
Paul Duffinb07fa512020-03-10 22:17:04 +0000390
Paul Duffinc459f892020-04-30 18:08:29 +0100391 err := extractor.extractCommonProperties(common, structs)
Paul Duffin36474d32021-03-12 12:19:43 +0000392 android.AssertDeepEquals(t, "unexpected error", nil, err)
Paul Duffinc459f892020-04-30 18:08:29 +0100393
Paul Duffin36474d32021-03-12 12:19:43 +0000394 android.AssertDeepEquals(t, "common properties not correct",
Paul Duffinb07fa512020-03-10 22:17:04 +0000395 &testPropertiesStruct{
Paul Duffin4b8b7932020-05-06 12:35:38 +0100396 name: "common",
Paul Duffinb07fa512020-03-10 22:17:04 +0000397 private: "",
398 Public_Kept: "",
399 S_Common: "common",
400 S_Different: "",
401 A_Common: []string{"first", "second"},
402 A_Different: []string(nil),
403 F_Common: proptools.BoolPtr(false),
404 F_Different: nil,
405 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
406 S_Embedded_Common: "embedded_common",
407 S_Embedded_Different: "",
408 },
Paul Duffin1d6c0df2020-05-06 12:50:19 +0100409 },
410 common)
Paul Duffinb07fa512020-03-10 22:17:04 +0000411
Paul Duffin36474d32021-03-12 12:19:43 +0000412 android.AssertDeepEquals(t, "updated properties[0] not correct",
Paul Duffinb07fa512020-03-10 22:17:04 +0000413 &testPropertiesStruct{
Paul Duffin4b8b7932020-05-06 12:35:38 +0100414 name: "struct-0",
Paul Duffinb07fa512020-03-10 22:17:04 +0000415 private: "common",
416 Public_Kept: "common",
417 S_Common: "",
418 S_Different: "upper",
419 A_Common: nil,
420 A_Different: []string{"alpha", "beta"},
421 F_Common: nil,
422 F_Different: proptools.BoolPtr(false),
423 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
424 S_Embedded_Common: "",
425 S_Embedded_Different: "embedded_upper",
426 },
Paul Duffin1d6c0df2020-05-06 12:50:19 +0100427 },
428 structs[0])
Paul Duffinb07fa512020-03-10 22:17:04 +0000429
Paul Duffin36474d32021-03-12 12:19:43 +0000430 android.AssertDeepEquals(t, "updated properties[1] not correct",
Paul Duffinb07fa512020-03-10 22:17:04 +0000431 &testPropertiesStruct{
Paul Duffin4b8b7932020-05-06 12:35:38 +0100432 name: "struct-1",
Paul Duffinb07fa512020-03-10 22:17:04 +0000433 private: "common",
434 Public_Kept: "common",
435 S_Common: "",
436 S_Different: "lower",
437 A_Common: nil,
438 A_Different: []string{"alpha", "delta"},
439 F_Common: nil,
440 F_Different: proptools.BoolPtr(true),
441 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
442 S_Embedded_Common: "",
443 S_Embedded_Different: "embedded_lower",
444 },
Paul Duffin1d6c0df2020-05-06 12:50:19 +0100445 },
446 structs[1])
Paul Duffinb07fa512020-03-10 22:17:04 +0000447}
Paul Duffin864e1b42020-05-06 10:23:19 +0100448
449func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) {
450 common := &testPropertiesStruct{name: "common"}
451 structs := []propertiesContainer{
452 &testPropertiesStruct{
453 name: "struct-0",
454 S_Common: "should-be-but-is-not-common0",
455 },
456 &testPropertiesStruct{
457 name: "struct-1",
458 S_Common: "should-be-but-is-not-common1",
459 },
460 }
461
462 extractor := newCommonValueExtractor(common)
463
Paul Duffin864e1b42020-05-06 10:23:19 +0100464 err := extractor.extractCommonProperties(common, structs)
Paul Duffin36474d32021-03-12 12:19:43 +0000465 android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties:
Paul Duffin864e1b42020-05-06 10:23:19 +0100466 "struct-0" has value "should-be-but-is-not-common0"
467 "struct-1" has value "should-be-but-is-not-common1"`, err)
468}
Paul Duffin62035b52021-05-05 21:35:49 +0100469
470// Ensure that sdk snapshot related environment variables work correctly.
471func TestSnapshot_EnvConfiguration(t *testing.T) {
472 bp := `
473 sdk {
474 name: "mysdk",
475 java_header_libs: ["myjavalib"],
476 }
477
478 java_library {
479 name: "myjavalib",
480 srcs: ["Test.java"],
481 system_modules: "none",
482 sdk_version: "none",
483 compile_dex: true,
484 host_supported: true,
485 }
486 `
487 preparer := android.GroupFixturePreparers(
488 prepareForSdkTestWithJava,
489 android.FixtureWithRootAndroidBp(bp),
490 )
491
492 checkZipFile := func(t *testing.T, result *android.TestResult, expected string) {
493 zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles")
494 android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String())
495 }
496
497 t.Run("no env variables", func(t *testing.T) {
498 result := preparer.RunTest(t)
499
500 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
501
502 CheckSnapshot(t, result, "mysdk", "",
503 checkAndroidBpContents(`
504// This is auto-generated. DO NOT EDIT.
505
506java_import {
507 name: "mysdk_myjavalib@current",
508 sdk_member_name: "myjavalib",
509 visibility: ["//visibility:public"],
510 apex_available: ["//apex_available:platform"],
511 jars: ["java/myjavalib.jar"],
512}
513
514java_import {
515 name: "myjavalib",
516 prefer: false,
517 visibility: ["//visibility:public"],
518 apex_available: ["//apex_available:platform"],
519 jars: ["java/myjavalib.jar"],
520}
521
522sdk_snapshot {
523 name: "mysdk@current",
524 visibility: ["//visibility:public"],
525 java_header_libs: ["mysdk_myjavalib@current"],
526}
527 `),
528 )
529 })
Paul Duffin64fb5262021-05-05 21:36:04 +0100530
531 t.Run("SOONG_SDK_SNAPSHOT_PREFER=true", func(t *testing.T) {
532 result := android.GroupFixturePreparers(
533 preparer,
534 android.FixtureMergeEnv(map[string]string{
535 "SOONG_SDK_SNAPSHOT_PREFER": "true",
536 }),
537 ).RunTest(t)
538
539 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
540
541 CheckSnapshot(t, result, "mysdk", "",
542 checkAndroidBpContents(`
543// This is auto-generated. DO NOT EDIT.
544
545java_import {
546 name: "mysdk_myjavalib@current",
547 sdk_member_name: "myjavalib",
548 visibility: ["//visibility:public"],
549 apex_available: ["//apex_available:platform"],
550 jars: ["java/myjavalib.jar"],
551}
552
553java_import {
554 name: "myjavalib",
555 prefer: true,
556 visibility: ["//visibility:public"],
557 apex_available: ["//apex_available:platform"],
558 jars: ["java/myjavalib.jar"],
559}
560
561sdk_snapshot {
562 name: "mysdk@current",
563 visibility: ["//visibility:public"],
564 java_header_libs: ["mysdk_myjavalib@current"],
565}
566 `),
567 )
568 })
Paul Duffin43f7bf02021-05-05 22:00:51 +0100569
Paul Duffinfb9a7f92021-07-06 17:18:42 +0100570 t.Run("SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR=module:build_from_source", func(t *testing.T) {
571 result := android.GroupFixturePreparers(
572 preparer,
573 android.FixtureMergeEnv(map[string]string{
574 "SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR": "module:build_from_source",
575 }),
576 ).RunTest(t)
577
578 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
579
580 CheckSnapshot(t, result, "mysdk", "",
581 checkAndroidBpContents(`
582// This is auto-generated. DO NOT EDIT.
583
584java_import {
585 name: "mysdk_myjavalib@current",
586 sdk_member_name: "myjavalib",
587 visibility: ["//visibility:public"],
588 apex_available: ["//apex_available:platform"],
589 jars: ["java/myjavalib.jar"],
590}
591
592java_import {
593 name: "myjavalib",
594 prefer: false,
595 use_source_config_var: {
596 config_namespace: "module",
597 var_name: "build_from_source",
598 },
599 visibility: ["//visibility:public"],
600 apex_available: ["//apex_available:platform"],
601 jars: ["java/myjavalib.jar"],
602}
603
604sdk_snapshot {
605 name: "mysdk@current",
606 visibility: ["//visibility:public"],
607 java_header_libs: ["mysdk_myjavalib@current"],
608}
609 `),
610 )
611 })
612
Paul Duffin43f7bf02021-05-05 22:00:51 +0100613 t.Run("SOONG_SDK_SNAPSHOT_VERSION=unversioned", func(t *testing.T) {
614 result := android.GroupFixturePreparers(
615 preparer,
616 android.FixtureMergeEnv(map[string]string{
617 "SOONG_SDK_SNAPSHOT_VERSION": "unversioned",
618 }),
619 ).RunTest(t)
620
621 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk.zip")
622
623 CheckSnapshot(t, result, "mysdk", "",
624 checkAndroidBpContents(`
625// This is auto-generated. DO NOT EDIT.
626
627java_import {
628 name: "myjavalib",
629 prefer: false,
630 visibility: ["//visibility:public"],
631 apex_available: ["//apex_available:platform"],
632 jars: ["java/myjavalib.jar"],
633}
634 `),
635 )
636 })
637
638 t.Run("SOONG_SDK_SNAPSHOT_VERSION=current", func(t *testing.T) {
639 result := android.GroupFixturePreparers(
640 preparer,
641 android.FixtureMergeEnv(map[string]string{
642 "SOONG_SDK_SNAPSHOT_VERSION": "current",
643 }),
644 ).RunTest(t)
645
646 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
647
648 CheckSnapshot(t, result, "mysdk", "",
649 checkAndroidBpContents(`
650// This is auto-generated. DO NOT EDIT.
651
652java_import {
653 name: "mysdk_myjavalib@current",
654 sdk_member_name: "myjavalib",
655 visibility: ["//visibility:public"],
656 apex_available: ["//apex_available:platform"],
657 jars: ["java/myjavalib.jar"],
658}
659
660java_import {
661 name: "myjavalib",
662 prefer: false,
663 visibility: ["//visibility:public"],
664 apex_available: ["//apex_available:platform"],
665 jars: ["java/myjavalib.jar"],
666}
667
668sdk_snapshot {
669 name: "mysdk@current",
670 visibility: ["//visibility:public"],
671 java_header_libs: ["mysdk_myjavalib@current"],
672}
673 `),
674 )
675 })
676
677 t.Run("SOONG_SDK_SNAPSHOT_VERSION=2", func(t *testing.T) {
678 result := android.GroupFixturePreparers(
679 preparer,
680 android.FixtureMergeEnv(map[string]string{
681 "SOONG_SDK_SNAPSHOT_VERSION": "2",
682 }),
683 ).RunTest(t)
684
685 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-2.zip")
686
687 CheckSnapshot(t, result, "mysdk", "",
688 checkAndroidBpContents(`
689// This is auto-generated. DO NOT EDIT.
690
691java_import {
692 name: "mysdk_myjavalib@2",
693 sdk_member_name: "myjavalib",
694 visibility: ["//visibility:public"],
695 apex_available: ["//apex_available:platform"],
696 jars: ["java/myjavalib.jar"],
697}
698
699sdk_snapshot {
700 name: "mysdk@2",
701 visibility: ["//visibility:public"],
702 java_header_libs: ["mysdk_myjavalib@2"],
703}
704 `),
705 // A versioned snapshot cannot be used on its own so add the source back in.
706 snapshotTestPreparer(checkSnapshotWithoutSource, android.FixtureWithRootAndroidBp(bp)),
707 )
708 })
Paul Duffin62035b52021-05-05 21:35:49 +0100709}