licenses_test.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. package android
  2. import (
  3. "testing"
  4. "github.com/google/blueprint"
  5. )
  6. var licensesTests = []struct {
  7. name string
  8. fs MockFS
  9. expectedErrors []string
  10. effectiveLicenses map[string][]string
  11. effectiveInheritedLicenses map[string][]string
  12. effectivePackage map[string]string
  13. effectiveNotices map[string][]string
  14. effectiveKinds map[string][]string
  15. effectiveConditions map[string][]string
  16. }{
  17. {
  18. name: "invalid module type without licenses property",
  19. fs: map[string][]byte{
  20. "top/Android.bp": []byte(`
  21. mock_bad_module {
  22. name: "libexample",
  23. }`),
  24. },
  25. expectedErrors: []string{`module type "mock_bad_module" must have an applicable licenses property`},
  26. },
  27. {
  28. name: "license must exist",
  29. fs: map[string][]byte{
  30. "top/Android.bp": []byte(`
  31. mock_library {
  32. name: "libexample",
  33. licenses: ["notice"],
  34. }`),
  35. },
  36. expectedErrors: []string{`"libexample" depends on undefined module "notice"`},
  37. },
  38. {
  39. name: "all good",
  40. fs: map[string][]byte{
  41. "top/Android.bp": []byte(`
  42. license_kind {
  43. name: "notice",
  44. conditions: ["shownotice"],
  45. }
  46. license {
  47. name: "top_Apache2",
  48. license_kinds: ["notice"],
  49. package_name: "topDog",
  50. license_text: ["LICENSE", "NOTICE"],
  51. }
  52. mock_library {
  53. name: "libexample1",
  54. licenses: ["top_Apache2"],
  55. }`),
  56. "top/nested/Android.bp": []byte(`
  57. mock_library {
  58. name: "libnested",
  59. licenses: ["top_Apache2"],
  60. }`),
  61. "other/Android.bp": []byte(`
  62. mock_library {
  63. name: "libother",
  64. licenses: ["top_Apache2"],
  65. }`),
  66. },
  67. effectiveLicenses: map[string][]string{
  68. "libexample1": []string{"top_Apache2"},
  69. "libnested": []string{"top_Apache2"},
  70. "libother": []string{"top_Apache2"},
  71. },
  72. effectiveKinds: map[string][]string{
  73. "libexample1": []string{"notice"},
  74. "libnested": []string{"notice"},
  75. "libother": []string{"notice"},
  76. },
  77. effectivePackage: map[string]string{
  78. "libexample1": "topDog",
  79. "libnested": "topDog",
  80. "libother": "topDog",
  81. },
  82. effectiveConditions: map[string][]string{
  83. "libexample1": []string{"shownotice"},
  84. "libnested": []string{"shownotice"},
  85. "libother": []string{"shownotice"},
  86. },
  87. effectiveNotices: map[string][]string{
  88. "libexample1": []string{"top/LICENSE:topDog", "top/NOTICE:topDog"},
  89. "libnested": []string{"top/LICENSE:topDog", "top/NOTICE:topDog"},
  90. "libother": []string{"top/LICENSE:topDog", "top/NOTICE:topDog"},
  91. },
  92. },
  93. // Defaults propagation tests
  94. {
  95. // Check that licenses is the union of the defaults modules.
  96. name: "defaults union, basic",
  97. fs: map[string][]byte{
  98. "top/Android.bp": []byte(`
  99. license_kind {
  100. name: "top_notice",
  101. conditions: ["notice"],
  102. }
  103. license {
  104. name: "top_other",
  105. license_kinds: ["top_notice"],
  106. }
  107. mock_defaults {
  108. name: "libexample_defaults",
  109. licenses: ["top_other"],
  110. }
  111. mock_library {
  112. name: "libexample",
  113. licenses: ["nested_other"],
  114. defaults: ["libexample_defaults"],
  115. }
  116. mock_library {
  117. name: "libsamepackage",
  118. deps: ["libexample"],
  119. }`),
  120. "top/nested/Android.bp": []byte(`
  121. license_kind {
  122. name: "nested_notice",
  123. conditions: ["notice"],
  124. }
  125. license {
  126. name: "nested_other",
  127. license_kinds: ["nested_notice"],
  128. }
  129. mock_library {
  130. name: "libnested",
  131. deps: ["libexample"],
  132. }`),
  133. "other/Android.bp": []byte(`
  134. mock_library {
  135. name: "libother",
  136. deps: ["libexample"],
  137. }`),
  138. },
  139. effectiveLicenses: map[string][]string{
  140. "libexample": []string{"nested_other", "top_other"},
  141. "libsamepackage": []string{},
  142. "libnested": []string{},
  143. "libother": []string{},
  144. },
  145. effectiveInheritedLicenses: map[string][]string{
  146. "libexample": []string{"nested_other", "top_other"},
  147. "libsamepackage": []string{"nested_other", "top_other"},
  148. "libnested": []string{"nested_other", "top_other"},
  149. "libother": []string{"nested_other", "top_other"},
  150. },
  151. effectiveKinds: map[string][]string{
  152. "libexample": []string{"nested_notice", "top_notice"},
  153. "libsamepackage": []string{},
  154. "libnested": []string{},
  155. "libother": []string{},
  156. },
  157. effectiveConditions: map[string][]string{
  158. "libexample": []string{"notice"},
  159. "libsamepackage": []string{},
  160. "libnested": []string{},
  161. "libother": []string{},
  162. },
  163. },
  164. {
  165. name: "defaults union, multiple defaults",
  166. fs: map[string][]byte{
  167. "top/Android.bp": []byte(`
  168. license {
  169. name: "top",
  170. }
  171. mock_defaults {
  172. name: "libexample_defaults_1",
  173. licenses: ["other"],
  174. }
  175. mock_defaults {
  176. name: "libexample_defaults_2",
  177. licenses: ["top_nested"],
  178. }
  179. mock_library {
  180. name: "libexample",
  181. defaults: ["libexample_defaults_1", "libexample_defaults_2"],
  182. }
  183. mock_library {
  184. name: "libsamepackage",
  185. deps: ["libexample"],
  186. }`),
  187. "top/nested/Android.bp": []byte(`
  188. license {
  189. name: "top_nested",
  190. license_text: ["LICENSE.txt"],
  191. }
  192. mock_library {
  193. name: "libnested",
  194. deps: ["libexample"],
  195. }`),
  196. "other/Android.bp": []byte(`
  197. license {
  198. name: "other",
  199. }
  200. mock_library {
  201. name: "libother",
  202. deps: ["libexample"],
  203. }`),
  204. "outsider/Android.bp": []byte(`
  205. mock_library {
  206. name: "liboutsider",
  207. deps: ["libexample"],
  208. }`),
  209. },
  210. effectiveLicenses: map[string][]string{
  211. "libexample": []string{"other", "top_nested"},
  212. "libsamepackage": []string{},
  213. "libnested": []string{},
  214. "libother": []string{},
  215. "liboutsider": []string{},
  216. },
  217. effectiveInheritedLicenses: map[string][]string{
  218. "libexample": []string{"other", "top_nested"},
  219. "libsamepackage": []string{"other", "top_nested"},
  220. "libnested": []string{"other", "top_nested"},
  221. "libother": []string{"other", "top_nested"},
  222. "liboutsider": []string{"other", "top_nested"},
  223. },
  224. effectiveKinds: map[string][]string{
  225. "libexample": []string{},
  226. "libsamepackage": []string{},
  227. "libnested": []string{},
  228. "libother": []string{},
  229. "liboutsider": []string{},
  230. },
  231. effectiveNotices: map[string][]string{
  232. "libexample": []string{"top/nested/LICENSE.txt"},
  233. "libsamepackage": []string{},
  234. "libnested": []string{},
  235. "libother": []string{},
  236. "liboutsider": []string{},
  237. },
  238. },
  239. // Defaults module's defaults_licenses tests
  240. {
  241. name: "defaults_licenses invalid",
  242. fs: map[string][]byte{
  243. "top/Android.bp": []byte(`
  244. mock_defaults {
  245. name: "top_defaults",
  246. licenses: ["notice"],
  247. }`),
  248. },
  249. expectedErrors: []string{`"top_defaults" depends on undefined module "notice"`},
  250. },
  251. {
  252. name: "defaults_licenses overrides package default",
  253. fs: map[string][]byte{
  254. "top/Android.bp": []byte(`
  255. package {
  256. default_applicable_licenses: ["by_exception_only"],
  257. }
  258. license {
  259. name: "by_exception_only",
  260. }
  261. license {
  262. name: "notice",
  263. }
  264. mock_defaults {
  265. name: "top_defaults",
  266. licenses: ["notice"],
  267. }
  268. mock_library {
  269. name: "libexample",
  270. }
  271. mock_library {
  272. name: "libdefaults",
  273. defaults: ["top_defaults"],
  274. }`),
  275. },
  276. effectiveLicenses: map[string][]string{
  277. "libexample": []string{"by_exception_only"},
  278. "libdefaults": []string{"notice"},
  279. },
  280. effectiveInheritedLicenses: map[string][]string{
  281. "libexample": []string{"by_exception_only"},
  282. "libdefaults": []string{"notice"},
  283. },
  284. },
  285. // Package default_applicable_licenses tests
  286. {
  287. name: "package default_applicable_licenses must exist",
  288. fs: map[string][]byte{
  289. "top/Android.bp": []byte(`
  290. package {
  291. default_applicable_licenses: ["notice"],
  292. }`),
  293. },
  294. expectedErrors: []string{`"//top" depends on undefined module "notice"`},
  295. },
  296. {
  297. // This test relies on the default licenses being legacy_public.
  298. name: "package default_applicable_licenses property used when no licenses specified",
  299. fs: map[string][]byte{
  300. "top/Android.bp": []byte(`
  301. package {
  302. default_applicable_licenses: ["top_notice"],
  303. }
  304. license {
  305. name: "top_notice",
  306. }
  307. mock_library {
  308. name: "libexample",
  309. }`),
  310. "outsider/Android.bp": []byte(`
  311. mock_library {
  312. name: "liboutsider",
  313. deps: ["libexample"],
  314. }`),
  315. },
  316. effectiveLicenses: map[string][]string{
  317. "libexample": []string{"top_notice"},
  318. "liboutsider": []string{},
  319. },
  320. effectiveInheritedLicenses: map[string][]string{
  321. "libexample": []string{"top_notice"},
  322. "liboutsider": []string{"top_notice"},
  323. },
  324. },
  325. {
  326. name: "package default_applicable_licenses not inherited to subpackages",
  327. fs: map[string][]byte{
  328. "top/Android.bp": []byte(`
  329. package {
  330. default_applicable_licenses: ["top_notice"],
  331. }
  332. license {
  333. name: "top_notice",
  334. }
  335. mock_library {
  336. name: "libexample",
  337. }`),
  338. "top/nested/Android.bp": []byte(`
  339. package {
  340. default_applicable_licenses: ["outsider"],
  341. }
  342. mock_library {
  343. name: "libnested",
  344. }`),
  345. "top/other/Android.bp": []byte(`
  346. mock_library {
  347. name: "libother",
  348. }`),
  349. "outsider/Android.bp": []byte(`
  350. license {
  351. name: "outsider",
  352. }
  353. mock_library {
  354. name: "liboutsider",
  355. deps: ["libexample", "libother", "libnested"],
  356. }`),
  357. },
  358. effectiveLicenses: map[string][]string{
  359. "libexample": []string{"top_notice"},
  360. "libnested": []string{"outsider"},
  361. "libother": []string{},
  362. "liboutsider": []string{},
  363. },
  364. effectiveInheritedLicenses: map[string][]string{
  365. "libexample": []string{"top_notice"},
  366. "libnested": []string{"outsider"},
  367. "libother": []string{},
  368. "liboutsider": []string{"top_notice", "outsider"},
  369. },
  370. },
  371. {
  372. name: "verify that prebuilt dependencies are included",
  373. fs: map[string][]byte{
  374. "prebuilts/Android.bp": []byte(`
  375. license {
  376. name: "prebuilt"
  377. }
  378. prebuilt {
  379. name: "module",
  380. licenses: ["prebuilt"],
  381. }`),
  382. "top/sources/source_file": nil,
  383. "top/sources/Android.bp": []byte(`
  384. license {
  385. name: "top_sources"
  386. }
  387. source {
  388. name: "module",
  389. licenses: ["top_sources"],
  390. }`),
  391. "top/other/source_file": nil,
  392. "top/other/Android.bp": []byte(`
  393. source {
  394. name: "other",
  395. deps: [":module"],
  396. }`),
  397. },
  398. effectiveLicenses: map[string][]string{
  399. "other": []string{},
  400. },
  401. effectiveInheritedLicenses: map[string][]string{
  402. "other": []string{"prebuilt", "top_sources"},
  403. },
  404. },
  405. {
  406. name: "verify that prebuilt dependencies are ignored for licenses reasons (preferred)",
  407. fs: map[string][]byte{
  408. "prebuilts/Android.bp": []byte(`
  409. license {
  410. name: "prebuilt"
  411. }
  412. prebuilt {
  413. name: "module",
  414. licenses: ["prebuilt"],
  415. prefer: true,
  416. }`),
  417. "top/sources/source_file": nil,
  418. "top/sources/Android.bp": []byte(`
  419. license {
  420. name: "top_sources"
  421. }
  422. source {
  423. name: "module",
  424. licenses: ["top_sources"],
  425. }`),
  426. "top/other/source_file": nil,
  427. "top/other/Android.bp": []byte(`
  428. source {
  429. name: "other",
  430. deps: [":module"],
  431. }`),
  432. },
  433. effectiveLicenses: map[string][]string{
  434. "other": []string{},
  435. },
  436. effectiveInheritedLicenses: map[string][]string{
  437. "module": []string{"prebuilt", "top_sources"},
  438. "other": []string{"prebuilt", "top_sources"},
  439. },
  440. },
  441. }
  442. func TestLicenses(t *testing.T) {
  443. for _, test := range licensesTests {
  444. t.Run(test.name, func(t *testing.T) {
  445. // Customize the common license text fixture factory.
  446. result := GroupFixturePreparers(
  447. prepareForLicenseTest,
  448. FixtureRegisterWithContext(func(ctx RegistrationContext) {
  449. ctx.RegisterModuleType("mock_bad_module", newMockLicensesBadModule)
  450. ctx.RegisterModuleType("mock_library", newMockLicensesLibraryModule)
  451. ctx.RegisterModuleType("mock_defaults", defaultsLicensesFactory)
  452. }),
  453. test.fs.AddToFixture(),
  454. ).
  455. ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
  456. RunTest(t)
  457. if test.effectiveLicenses != nil {
  458. checkEffectiveLicenses(t, result, test.effectiveLicenses)
  459. }
  460. if test.effectivePackage != nil {
  461. checkEffectivePackage(t, result, test.effectivePackage)
  462. }
  463. if test.effectiveNotices != nil {
  464. checkEffectiveNotices(t, result, test.effectiveNotices)
  465. }
  466. if test.effectiveKinds != nil {
  467. checkEffectiveKinds(t, result, test.effectiveKinds)
  468. }
  469. if test.effectiveConditions != nil {
  470. checkEffectiveConditions(t, result, test.effectiveConditions)
  471. }
  472. if test.effectiveInheritedLicenses != nil {
  473. checkEffectiveInheritedLicenses(t, result, test.effectiveInheritedLicenses)
  474. }
  475. })
  476. }
  477. }
  478. func checkEffectiveLicenses(t *testing.T, result *TestResult, effectiveLicenses map[string][]string) {
  479. actualLicenses := make(map[string][]string)
  480. result.Context.Context.VisitAllModules(func(m blueprint.Module) {
  481. if _, ok := m.(*licenseModule); ok {
  482. return
  483. }
  484. if _, ok := m.(*licenseKindModule); ok {
  485. return
  486. }
  487. if _, ok := m.(*packageModule); ok {
  488. return
  489. }
  490. module, ok := m.(Module)
  491. if !ok {
  492. t.Errorf("%q not a module", m.Name())
  493. return
  494. }
  495. base := module.base()
  496. if base == nil {
  497. return
  498. }
  499. actualLicenses[m.Name()] = base.commonProperties.Effective_licenses
  500. })
  501. for moduleName, expectedLicenses := range effectiveLicenses {
  502. licenses, ok := actualLicenses[moduleName]
  503. if !ok {
  504. licenses = []string{}
  505. }
  506. if !compareUnorderedStringArrays(expectedLicenses, licenses) {
  507. t.Errorf("effective licenses mismatch for module %q: expected %q, found %q", moduleName, expectedLicenses, licenses)
  508. }
  509. }
  510. }
  511. func checkEffectiveInheritedLicenses(t *testing.T, result *TestResult, effectiveInheritedLicenses map[string][]string) {
  512. actualLicenses := make(map[string][]string)
  513. result.Context.Context.VisitAllModules(func(m blueprint.Module) {
  514. if _, ok := m.(*licenseModule); ok {
  515. return
  516. }
  517. if _, ok := m.(*licenseKindModule); ok {
  518. return
  519. }
  520. if _, ok := m.(*packageModule); ok {
  521. return
  522. }
  523. module, ok := m.(Module)
  524. if !ok {
  525. t.Errorf("%q not a module", m.Name())
  526. return
  527. }
  528. base := module.base()
  529. if base == nil {
  530. return
  531. }
  532. inherited := make(map[string]bool)
  533. for _, l := range base.commonProperties.Effective_licenses {
  534. inherited[l] = true
  535. }
  536. result.Context.Context.VisitDepsDepthFirst(m, func(c blueprint.Module) {
  537. if _, ok := c.(*licenseModule); ok {
  538. return
  539. }
  540. if _, ok := c.(*licenseKindModule); ok {
  541. return
  542. }
  543. if _, ok := c.(*packageModule); ok {
  544. return
  545. }
  546. cmodule, ok := c.(Module)
  547. if !ok {
  548. t.Errorf("%q not a module", c.Name())
  549. return
  550. }
  551. cbase := cmodule.base()
  552. if cbase == nil {
  553. return
  554. }
  555. for _, l := range cbase.commonProperties.Effective_licenses {
  556. inherited[l] = true
  557. }
  558. })
  559. actualLicenses[m.Name()] = []string{}
  560. for l := range inherited {
  561. actualLicenses[m.Name()] = append(actualLicenses[m.Name()], l)
  562. }
  563. })
  564. for moduleName, expectedInheritedLicenses := range effectiveInheritedLicenses {
  565. licenses, ok := actualLicenses[moduleName]
  566. if !ok {
  567. licenses = []string{}
  568. }
  569. if !compareUnorderedStringArrays(expectedInheritedLicenses, licenses) {
  570. t.Errorf("effective inherited licenses mismatch for module %q: expected %q, found %q", moduleName, expectedInheritedLicenses, licenses)
  571. }
  572. }
  573. }
  574. func checkEffectivePackage(t *testing.T, result *TestResult, effectivePackage map[string]string) {
  575. actualPackage := make(map[string]string)
  576. result.Context.Context.VisitAllModules(func(m blueprint.Module) {
  577. if _, ok := m.(*licenseModule); ok {
  578. return
  579. }
  580. if _, ok := m.(*licenseKindModule); ok {
  581. return
  582. }
  583. if _, ok := m.(*packageModule); ok {
  584. return
  585. }
  586. module, ok := m.(Module)
  587. if !ok {
  588. t.Errorf("%q not a module", m.Name())
  589. return
  590. }
  591. base := module.base()
  592. if base == nil {
  593. return
  594. }
  595. if base.commonProperties.Effective_package_name == nil {
  596. actualPackage[m.Name()] = ""
  597. } else {
  598. actualPackage[m.Name()] = *base.commonProperties.Effective_package_name
  599. }
  600. })
  601. for moduleName, expectedPackage := range effectivePackage {
  602. packageName, ok := actualPackage[moduleName]
  603. if !ok {
  604. packageName = ""
  605. }
  606. if expectedPackage != packageName {
  607. t.Errorf("effective package mismatch for module %q: expected %q, found %q", moduleName, expectedPackage, packageName)
  608. }
  609. }
  610. }
  611. func checkEffectiveNotices(t *testing.T, result *TestResult, effectiveNotices map[string][]string) {
  612. actualNotices := make(map[string][]string)
  613. result.Context.Context.VisitAllModules(func(m blueprint.Module) {
  614. if _, ok := m.(*licenseModule); ok {
  615. return
  616. }
  617. if _, ok := m.(*licenseKindModule); ok {
  618. return
  619. }
  620. if _, ok := m.(*packageModule); ok {
  621. return
  622. }
  623. module, ok := m.(Module)
  624. if !ok {
  625. t.Errorf("%q not a module", m.Name())
  626. return
  627. }
  628. base := module.base()
  629. if base == nil {
  630. return
  631. }
  632. actualNotices[m.Name()] = base.commonProperties.Effective_license_text.Strings()
  633. })
  634. for moduleName, expectedNotices := range effectiveNotices {
  635. notices, ok := actualNotices[moduleName]
  636. if !ok {
  637. notices = []string{}
  638. }
  639. if !compareUnorderedStringArrays(expectedNotices, notices) {
  640. t.Errorf("effective notice files mismatch for module %q: expected %q, found %q", moduleName, expectedNotices, notices)
  641. }
  642. }
  643. }
  644. func checkEffectiveKinds(t *testing.T, result *TestResult, effectiveKinds map[string][]string) {
  645. actualKinds := make(map[string][]string)
  646. result.Context.Context.VisitAllModules(func(m blueprint.Module) {
  647. if _, ok := m.(*licenseModule); ok {
  648. return
  649. }
  650. if _, ok := m.(*licenseKindModule); ok {
  651. return
  652. }
  653. if _, ok := m.(*packageModule); ok {
  654. return
  655. }
  656. module, ok := m.(Module)
  657. if !ok {
  658. t.Errorf("%q not a module", m.Name())
  659. return
  660. }
  661. base := module.base()
  662. if base == nil {
  663. return
  664. }
  665. actualKinds[m.Name()] = base.commonProperties.Effective_license_kinds
  666. })
  667. for moduleName, expectedKinds := range effectiveKinds {
  668. kinds, ok := actualKinds[moduleName]
  669. if !ok {
  670. kinds = []string{}
  671. }
  672. if !compareUnorderedStringArrays(expectedKinds, kinds) {
  673. t.Errorf("effective license kinds mismatch for module %q: expected %q, found %q", moduleName, expectedKinds, kinds)
  674. }
  675. }
  676. }
  677. func checkEffectiveConditions(t *testing.T, result *TestResult, effectiveConditions map[string][]string) {
  678. actualConditions := make(map[string][]string)
  679. result.Context.Context.VisitAllModules(func(m blueprint.Module) {
  680. if _, ok := m.(*licenseModule); ok {
  681. return
  682. }
  683. if _, ok := m.(*licenseKindModule); ok {
  684. return
  685. }
  686. if _, ok := m.(*packageModule); ok {
  687. return
  688. }
  689. module, ok := m.(Module)
  690. if !ok {
  691. t.Errorf("%q not a module", m.Name())
  692. return
  693. }
  694. base := module.base()
  695. if base == nil {
  696. return
  697. }
  698. actualConditions[m.Name()] = base.commonProperties.Effective_license_conditions
  699. })
  700. for moduleName, expectedConditions := range effectiveConditions {
  701. conditions, ok := actualConditions[moduleName]
  702. if !ok {
  703. conditions = []string{}
  704. }
  705. if !compareUnorderedStringArrays(expectedConditions, conditions) {
  706. t.Errorf("effective license conditions mismatch for module %q: expected %q, found %q", moduleName, expectedConditions, conditions)
  707. }
  708. }
  709. }
  710. func compareUnorderedStringArrays(expected, actual []string) bool {
  711. if len(expected) != len(actual) {
  712. return false
  713. }
  714. s := make(map[string]int)
  715. for _, v := range expected {
  716. s[v] += 1
  717. }
  718. for _, v := range actual {
  719. c, ok := s[v]
  720. if !ok {
  721. return false
  722. }
  723. if c < 1 {
  724. return false
  725. }
  726. s[v] -= 1
  727. }
  728. return true
  729. }
  730. type mockLicensesBadProperties struct {
  731. Visibility []string
  732. }
  733. type mockLicensesBadModule struct {
  734. ModuleBase
  735. DefaultableModuleBase
  736. properties mockLicensesBadProperties
  737. }
  738. func newMockLicensesBadModule() Module {
  739. m := &mockLicensesBadModule{}
  740. base := m.base()
  741. m.AddProperties(&base.nameProperties, &m.properties)
  742. // The default_visibility property needs to be checked and parsed by the visibility module during
  743. // its checking and parsing phases so make it the primary visibility property.
  744. setPrimaryVisibilityProperty(m, "visibility", &m.properties.Visibility)
  745. initAndroidModuleBase(m)
  746. InitDefaultableModule(m)
  747. return m
  748. }
  749. func (m *mockLicensesBadModule) GenerateAndroidBuildActions(ModuleContext) {
  750. }
  751. type mockLicensesLibraryProperties struct {
  752. Deps []string
  753. }
  754. type mockLicensesLibraryModule struct {
  755. ModuleBase
  756. DefaultableModuleBase
  757. properties mockLicensesLibraryProperties
  758. }
  759. func newMockLicensesLibraryModule() Module {
  760. m := &mockLicensesLibraryModule{}
  761. m.AddProperties(&m.properties)
  762. InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon)
  763. InitDefaultableModule(m)
  764. return m
  765. }
  766. type dependencyLicensesTag struct {
  767. blueprint.BaseDependencyTag
  768. name string
  769. }
  770. func (j *mockLicensesLibraryModule) DepsMutator(ctx BottomUpMutatorContext) {
  771. ctx.AddVariationDependencies(nil, dependencyLicensesTag{name: "mockdeps"}, j.properties.Deps...)
  772. }
  773. func (p *mockLicensesLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
  774. }
  775. type mockLicensesDefaults struct {
  776. ModuleBase
  777. DefaultsModuleBase
  778. }
  779. func defaultsLicensesFactory() Module {
  780. m := &mockLicensesDefaults{}
  781. InitDefaultsModule(m)
  782. return m
  783. }