blob: 0c371e8e9c4d368745d7c779e59ba725faff3aef [file] [log] [blame]
Bob Badour37af0462021-01-07 03:34:31 +00001package android
2
3import (
4 "testing"
5
6 "github.com/google/blueprint"
7)
8
9var licensesTests = []struct {
Yu Liu47361852025-01-23 19:28:17 +000010 name string
11 fs MockFS
12 expectedErrors []string
13 effectivePackage map[string]string
14 effectiveNotices map[string][]string
15 effectiveKinds map[string][]string
16 effectiveConditions map[string][]string
Bob Badour37af0462021-01-07 03:34:31 +000017}{
18 {
19 name: "invalid module type without licenses property",
20 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020021 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +000022 mock_bad_module {
23 name: "libexample",
24 }`),
25 },
26 expectedErrors: []string{`module type "mock_bad_module" must have an applicable licenses property`},
27 },
28 {
29 name: "license must exist",
30 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020031 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +000032 mock_library {
33 name: "libexample",
34 licenses: ["notice"],
35 }`),
36 },
37 expectedErrors: []string{`"libexample" depends on undefined module "notice"`},
38 },
39 {
40 name: "all good",
41 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020042 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +000043 license_kind {
44 name: "notice",
45 conditions: ["shownotice"],
46 }
47
48 license {
49 name: "top_Apache2",
50 license_kinds: ["notice"],
51 package_name: "topDog",
52 license_text: ["LICENSE", "NOTICE"],
53 }
54
55 mock_library {
56 name: "libexample1",
57 licenses: ["top_Apache2"],
58 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020059 "top/nested/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +000060 mock_library {
61 name: "libnested",
62 licenses: ["top_Apache2"],
63 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020064 "other/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +000065 mock_library {
66 name: "libother",
67 licenses: ["top_Apache2"],
68 }`),
69 },
Bob Badour37af0462021-01-07 03:34:31 +000070 effectiveKinds: map[string][]string{
71 "libexample1": []string{"notice"},
Paul Duffin3c298a32021-03-04 17:44:03 +000072 "libnested": []string{"notice"},
73 "libother": []string{"notice"},
Bob Badour37af0462021-01-07 03:34:31 +000074 },
75 effectivePackage: map[string]string{
76 "libexample1": "topDog",
Paul Duffin3c298a32021-03-04 17:44:03 +000077 "libnested": "topDog",
78 "libother": "topDog",
Bob Badour37af0462021-01-07 03:34:31 +000079 },
80 effectiveConditions: map[string][]string{
81 "libexample1": []string{"shownotice"},
Paul Duffin3c298a32021-03-04 17:44:03 +000082 "libnested": []string{"shownotice"},
83 "libother": []string{"shownotice"},
Bob Badour37af0462021-01-07 03:34:31 +000084 },
85 effectiveNotices: map[string][]string{
Bob Badour4101c712022-02-09 11:54:35 -080086 "libexample1": []string{"top/LICENSE:topDog", "top/NOTICE:topDog"},
87 "libnested": []string{"top/LICENSE:topDog", "top/NOTICE:topDog"},
88 "libother": []string{"top/LICENSE:topDog", "top/NOTICE:topDog"},
Bob Badour37af0462021-01-07 03:34:31 +000089 },
90 },
91
92 // Defaults propagation tests
93 {
94 // Check that licenses is the union of the defaults modules.
95 name: "defaults union, basic",
96 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +020097 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +000098 license_kind {
99 name: "top_notice",
100 conditions: ["notice"],
101 }
102
103 license {
104 name: "top_other",
105 license_kinds: ["top_notice"],
106 }
107
108 mock_defaults {
109 name: "libexample_defaults",
110 licenses: ["top_other"],
111 }
112 mock_library {
113 name: "libexample",
114 licenses: ["nested_other"],
115 defaults: ["libexample_defaults"],
116 }
117 mock_library {
118 name: "libsamepackage",
119 deps: ["libexample"],
120 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200121 "top/nested/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000122 license_kind {
123 name: "nested_notice",
124 conditions: ["notice"],
125 }
126
127 license {
128 name: "nested_other",
129 license_kinds: ["nested_notice"],
130 }
131
132 mock_library {
133 name: "libnested",
134 deps: ["libexample"],
135 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200136 "other/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000137 mock_library {
138 name: "libother",
139 deps: ["libexample"],
140 }`),
141 },
Bob Badour37af0462021-01-07 03:34:31 +0000142 effectiveKinds: map[string][]string{
Paul Duffin3c298a32021-03-04 17:44:03 +0000143 "libexample": []string{"nested_notice", "top_notice"},
Bob Badour37af0462021-01-07 03:34:31 +0000144 "libsamepackage": []string{},
Paul Duffin3c298a32021-03-04 17:44:03 +0000145 "libnested": []string{},
146 "libother": []string{},
Bob Badour37af0462021-01-07 03:34:31 +0000147 },
148 effectiveConditions: map[string][]string{
Paul Duffin3c298a32021-03-04 17:44:03 +0000149 "libexample": []string{"notice"},
Bob Badour37af0462021-01-07 03:34:31 +0000150 "libsamepackage": []string{},
Paul Duffin3c298a32021-03-04 17:44:03 +0000151 "libnested": []string{},
152 "libother": []string{},
Bob Badour37af0462021-01-07 03:34:31 +0000153 },
154 },
155 {
156 name: "defaults union, multiple defaults",
157 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200158 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000159 license {
160 name: "top",
161 }
162 mock_defaults {
163 name: "libexample_defaults_1",
164 licenses: ["other"],
165 }
166 mock_defaults {
167 name: "libexample_defaults_2",
168 licenses: ["top_nested"],
169 }
170 mock_library {
171 name: "libexample",
172 defaults: ["libexample_defaults_1", "libexample_defaults_2"],
173 }
174 mock_library {
175 name: "libsamepackage",
176 deps: ["libexample"],
177 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200178 "top/nested/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000179 license {
180 name: "top_nested",
181 license_text: ["LICENSE.txt"],
182 }
183 mock_library {
184 name: "libnested",
185 deps: ["libexample"],
186 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200187 "other/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000188 license {
189 name: "other",
190 }
191 mock_library {
192 name: "libother",
193 deps: ["libexample"],
194 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200195 "outsider/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000196 mock_library {
197 name: "liboutsider",
198 deps: ["libexample"],
199 }`),
200 },
Bob Badour37af0462021-01-07 03:34:31 +0000201 effectiveKinds: map[string][]string{
Paul Duffin3c298a32021-03-04 17:44:03 +0000202 "libexample": []string{},
Bob Badour37af0462021-01-07 03:34:31 +0000203 "libsamepackage": []string{},
Paul Duffin3c298a32021-03-04 17:44:03 +0000204 "libnested": []string{},
205 "libother": []string{},
206 "liboutsider": []string{},
Bob Badour37af0462021-01-07 03:34:31 +0000207 },
208 effectiveNotices: map[string][]string{
Paul Duffin3c298a32021-03-04 17:44:03 +0000209 "libexample": []string{"top/nested/LICENSE.txt"},
Bob Badour37af0462021-01-07 03:34:31 +0000210 "libsamepackage": []string{},
Paul Duffin3c298a32021-03-04 17:44:03 +0000211 "libnested": []string{},
212 "libother": []string{},
213 "liboutsider": []string{},
Bob Badour37af0462021-01-07 03:34:31 +0000214 },
215 },
216
217 // Defaults module's defaults_licenses tests
218 {
219 name: "defaults_licenses invalid",
220 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200221 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000222 mock_defaults {
223 name: "top_defaults",
224 licenses: ["notice"],
225 }`),
226 },
227 expectedErrors: []string{`"top_defaults" depends on undefined module "notice"`},
228 },
229 {
230 name: "defaults_licenses overrides package default",
231 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200232 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000233 package {
234 default_applicable_licenses: ["by_exception_only"],
235 }
236 license {
237 name: "by_exception_only",
238 }
239 license {
240 name: "notice",
241 }
242 mock_defaults {
243 name: "top_defaults",
244 licenses: ["notice"],
245 }
246 mock_library {
247 name: "libexample",
248 }
249 mock_library {
250 name: "libdefaults",
251 defaults: ["top_defaults"],
252 }`),
253 },
Bob Badour37af0462021-01-07 03:34:31 +0000254 },
255
256 // Package default_applicable_licenses tests
257 {
258 name: "package default_applicable_licenses must exist",
259 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200260 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000261 package {
262 default_applicable_licenses: ["notice"],
263 }`),
264 },
265 expectedErrors: []string{`"//top" depends on undefined module "notice"`},
266 },
267 {
268 // This test relies on the default licenses being legacy_public.
269 name: "package default_applicable_licenses property used when no licenses specified",
270 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200271 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000272 package {
273 default_applicable_licenses: ["top_notice"],
274 }
275
276 license {
277 name: "top_notice",
278 }
279 mock_library {
280 name: "libexample",
281 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200282 "outsider/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000283 mock_library {
284 name: "liboutsider",
285 deps: ["libexample"],
286 }`),
287 },
Bob Badour37af0462021-01-07 03:34:31 +0000288 },
289 {
290 name: "package default_applicable_licenses not inherited to subpackages",
291 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200292 "top/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000293 package {
294 default_applicable_licenses: ["top_notice"],
295 }
296 license {
297 name: "top_notice",
298 }
299 mock_library {
300 name: "libexample",
301 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200302 "top/nested/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000303 package {
304 default_applicable_licenses: ["outsider"],
305 }
306
307 mock_library {
308 name: "libnested",
309 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200310 "top/other/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000311 mock_library {
312 name: "libother",
313 }`),
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200314 "outsider/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000315 license {
316 name: "outsider",
317 }
318 mock_library {
319 name: "liboutsider",
320 deps: ["libexample", "libother", "libnested"],
321 }`),
322 },
Bob Badour37af0462021-01-07 03:34:31 +0000323 },
324 {
325 name: "verify that prebuilt dependencies are included",
326 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200327 "prebuilts/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000328 license {
329 name: "prebuilt"
330 }
331 prebuilt {
332 name: "module",
333 licenses: ["prebuilt"],
334 }`),
335 "top/sources/source_file": nil,
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200336 "top/sources/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000337 license {
338 name: "top_sources"
339 }
340 source {
341 name: "module",
342 licenses: ["top_sources"],
343 }`),
344 "top/other/source_file": nil,
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200345 "top/other/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000346 source {
347 name: "other",
348 deps: [":module"],
349 }`),
350 },
Bob Badour37af0462021-01-07 03:34:31 +0000351 },
352 {
353 name: "verify that prebuilt dependencies are ignored for licenses reasons (preferred)",
354 fs: map[string][]byte{
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200355 "prebuilts/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000356 license {
357 name: "prebuilt"
358 }
359 prebuilt {
360 name: "module",
361 licenses: ["prebuilt"],
362 prefer: true,
363 }`),
364 "top/sources/source_file": nil,
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200365 "top/sources/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000366 license {
367 name: "top_sources"
368 }
369 source {
370 name: "module",
371 licenses: ["top_sources"],
372 }`),
373 "top/other/source_file": nil,
Lukacs T. Berkib838b0a2021-09-02 11:46:24 +0200374 "top/other/Android.bp": []byte(`
Bob Badour37af0462021-01-07 03:34:31 +0000375 source {
376 name: "other",
377 deps: [":module"],
378 }`),
379 },
Bob Badour37af0462021-01-07 03:34:31 +0000380 },
381}
382
383func TestLicenses(t *testing.T) {
384 for _, test := range licensesTests {
385 t.Run(test.name, func(t *testing.T) {
Paul Duffin8bd28652021-03-03 00:42:36 +0000386 // Customize the common license text fixture factory.
Paul Duffin30ac3e72021-03-20 00:36:14 +0000387 result := GroupFixturePreparers(
388 prepareForLicenseTest,
Paul Duffin8bd28652021-03-03 00:42:36 +0000389 FixtureRegisterWithContext(func(ctx RegistrationContext) {
390 ctx.RegisterModuleType("mock_bad_module", newMockLicensesBadModule)
391 ctx.RegisterModuleType("mock_library", newMockLicensesLibraryModule)
392 ctx.RegisterModuleType("mock_defaults", defaultsLicensesFactory)
393 }),
394 test.fs.AddToFixture(),
395 ).
396 ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
397 RunTest(t)
Bob Badour37af0462021-01-07 03:34:31 +0000398
Bob Badour37af0462021-01-07 03:34:31 +0000399 if test.effectivePackage != nil {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000400 checkEffectivePackage(t, result, test.effectivePackage)
Bob Badour37af0462021-01-07 03:34:31 +0000401 }
402
403 if test.effectiveNotices != nil {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000404 checkEffectiveNotices(t, result, test.effectiveNotices)
Bob Badour37af0462021-01-07 03:34:31 +0000405 }
406
407 if test.effectiveKinds != nil {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000408 checkEffectiveKinds(t, result, test.effectiveKinds)
Bob Badour37af0462021-01-07 03:34:31 +0000409 }
410
411 if test.effectiveConditions != nil {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000412 checkEffectiveConditions(t, result, test.effectiveConditions)
Bob Badour37af0462021-01-07 03:34:31 +0000413 }
Bob Badour37af0462021-01-07 03:34:31 +0000414 })
415 }
416}
417
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000418func checkEffectivePackage(t *testing.T, result *TestResult, effectivePackage map[string]string) {
Bob Badour37af0462021-01-07 03:34:31 +0000419 actualPackage := make(map[string]string)
Paul Duffin8bd28652021-03-03 00:42:36 +0000420 result.Context.Context.VisitAllModules(func(m blueprint.Module) {
Bob Badour37af0462021-01-07 03:34:31 +0000421 if _, ok := m.(*licenseModule); ok {
422 return
423 }
424 if _, ok := m.(*licenseKindModule); ok {
425 return
426 }
427 if _, ok := m.(*packageModule); ok {
428 return
429 }
430 module, ok := m.(Module)
431 if !ok {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000432 t.Errorf("%q not a module", m.Name())
Bob Badour37af0462021-01-07 03:34:31 +0000433 return
434 }
435 base := module.base()
436 if base == nil {
437 return
438 }
439
440 if base.commonProperties.Effective_package_name == nil {
441 actualPackage[m.Name()] = ""
442 } else {
443 actualPackage[m.Name()] = *base.commonProperties.Effective_package_name
444 }
445 })
446
447 for moduleName, expectedPackage := range effectivePackage {
448 packageName, ok := actualPackage[moduleName]
449 if !ok {
450 packageName = ""
451 }
452 if expectedPackage != packageName {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000453 t.Errorf("effective package mismatch for module %q: expected %q, found %q", moduleName, expectedPackage, packageName)
Bob Badour37af0462021-01-07 03:34:31 +0000454 }
455 }
456}
457
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000458func checkEffectiveNotices(t *testing.T, result *TestResult, effectiveNotices map[string][]string) {
Bob Badour37af0462021-01-07 03:34:31 +0000459 actualNotices := make(map[string][]string)
Paul Duffin8bd28652021-03-03 00:42:36 +0000460 result.Context.Context.VisitAllModules(func(m blueprint.Module) {
Bob Badour37af0462021-01-07 03:34:31 +0000461 if _, ok := m.(*licenseModule); ok {
462 return
463 }
464 if _, ok := m.(*licenseKindModule); ok {
465 return
466 }
467 if _, ok := m.(*packageModule); ok {
468 return
469 }
470 module, ok := m.(Module)
471 if !ok {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000472 t.Errorf("%q not a module", m.Name())
Bob Badour37af0462021-01-07 03:34:31 +0000473 return
474 }
475 base := module.base()
476 if base == nil {
477 return
478 }
Paul Duffinec0836a2021-05-10 22:53:30 +0100479 actualNotices[m.Name()] = base.commonProperties.Effective_license_text.Strings()
Bob Badour37af0462021-01-07 03:34:31 +0000480 })
481
482 for moduleName, expectedNotices := range effectiveNotices {
483 notices, ok := actualNotices[moduleName]
484 if !ok {
485 notices = []string{}
486 }
487 if !compareUnorderedStringArrays(expectedNotices, notices) {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000488 t.Errorf("effective notice files mismatch for module %q: expected %q, found %q", moduleName, expectedNotices, notices)
Bob Badour37af0462021-01-07 03:34:31 +0000489 }
490 }
491}
492
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000493func checkEffectiveKinds(t *testing.T, result *TestResult, effectiveKinds map[string][]string) {
Bob Badour37af0462021-01-07 03:34:31 +0000494 actualKinds := make(map[string][]string)
Paul Duffin8bd28652021-03-03 00:42:36 +0000495 result.Context.Context.VisitAllModules(func(m blueprint.Module) {
Bob Badour37af0462021-01-07 03:34:31 +0000496 if _, ok := m.(*licenseModule); ok {
497 return
498 }
499 if _, ok := m.(*licenseKindModule); ok {
500 return
501 }
502 if _, ok := m.(*packageModule); ok {
503 return
504 }
505 module, ok := m.(Module)
506 if !ok {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000507 t.Errorf("%q not a module", m.Name())
Bob Badour37af0462021-01-07 03:34:31 +0000508 return
509 }
510 base := module.base()
511 if base == nil {
512 return
513 }
514 actualKinds[m.Name()] = base.commonProperties.Effective_license_kinds
515 })
516
517 for moduleName, expectedKinds := range effectiveKinds {
518 kinds, ok := actualKinds[moduleName]
519 if !ok {
520 kinds = []string{}
521 }
522 if !compareUnorderedStringArrays(expectedKinds, kinds) {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000523 t.Errorf("effective license kinds mismatch for module %q: expected %q, found %q", moduleName, expectedKinds, kinds)
Bob Badour37af0462021-01-07 03:34:31 +0000524 }
525 }
526}
527
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000528func checkEffectiveConditions(t *testing.T, result *TestResult, effectiveConditions map[string][]string) {
Bob Badour37af0462021-01-07 03:34:31 +0000529 actualConditions := make(map[string][]string)
Paul Duffin8bd28652021-03-03 00:42:36 +0000530 result.Context.Context.VisitAllModules(func(m blueprint.Module) {
Bob Badour37af0462021-01-07 03:34:31 +0000531 if _, ok := m.(*licenseModule); ok {
532 return
533 }
534 if _, ok := m.(*licenseKindModule); ok {
535 return
536 }
537 if _, ok := m.(*packageModule); ok {
538 return
539 }
540 module, ok := m.(Module)
541 if !ok {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000542 t.Errorf("%q not a module", m.Name())
Bob Badour37af0462021-01-07 03:34:31 +0000543 return
544 }
545 base := module.base()
546 if base == nil {
547 return
548 }
549 actualConditions[m.Name()] = base.commonProperties.Effective_license_conditions
550 })
551
552 for moduleName, expectedConditions := range effectiveConditions {
553 conditions, ok := actualConditions[moduleName]
554 if !ok {
555 conditions = []string{}
556 }
557 if !compareUnorderedStringArrays(expectedConditions, conditions) {
Paul Duffin3d0ddff2021-03-12 12:20:59 +0000558 t.Errorf("effective license conditions mismatch for module %q: expected %q, found %q", moduleName, expectedConditions, conditions)
Bob Badour37af0462021-01-07 03:34:31 +0000559 }
560 }
561}
562
563func compareUnorderedStringArrays(expected, actual []string) bool {
564 if len(expected) != len(actual) {
565 return false
566 }
567 s := make(map[string]int)
568 for _, v := range expected {
569 s[v] += 1
570 }
571 for _, v := range actual {
572 c, ok := s[v]
573 if !ok {
574 return false
575 }
576 if c < 1 {
577 return false
578 }
579 s[v] -= 1
580 }
581 return true
582}
583
Bob Badour37af0462021-01-07 03:34:31 +0000584type mockLicensesBadProperties struct {
585 Visibility []string
586}
587
588type mockLicensesBadModule struct {
589 ModuleBase
590 DefaultableModuleBase
591 properties mockLicensesBadProperties
592}
593
594func newMockLicensesBadModule() Module {
595 m := &mockLicensesBadModule{}
596
597 base := m.base()
598 m.AddProperties(&base.nameProperties, &m.properties)
599
Bob Badour37af0462021-01-07 03:34:31 +0000600 // The default_visibility property needs to be checked and parsed by the visibility module during
601 // its checking and parsing phases so make it the primary visibility property.
602 setPrimaryVisibilityProperty(m, "visibility", &m.properties.Visibility)
603
604 initAndroidModuleBase(m)
605 InitDefaultableModule(m)
606
607 return m
608}
609
610func (m *mockLicensesBadModule) GenerateAndroidBuildActions(ModuleContext) {
611}
612
613type mockLicensesLibraryProperties struct {
614 Deps []string
615}
616
617type mockLicensesLibraryModule struct {
618 ModuleBase
619 DefaultableModuleBase
620 properties mockLicensesLibraryProperties
621}
622
623func newMockLicensesLibraryModule() Module {
624 m := &mockLicensesLibraryModule{}
625 m.AddProperties(&m.properties)
626 InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon)
627 InitDefaultableModule(m)
628 return m
629}
630
631type dependencyLicensesTag struct {
632 blueprint.BaseDependencyTag
633 name string
634}
635
636func (j *mockLicensesLibraryModule) DepsMutator(ctx BottomUpMutatorContext) {
637 ctx.AddVariationDependencies(nil, dependencyLicensesTag{name: "mockdeps"}, j.properties.Deps...)
638}
639
640func (p *mockLicensesLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
641}
642
643type mockLicensesDefaults struct {
644 ModuleBase
645 DefaultsModuleBase
646}
647
648func defaultsLicensesFactory() Module {
649 m := &mockLicensesDefaults{}
650 InitDefaultsModule(m)
651 return m
652}