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