Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 18 | "fmt" |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 19 | "testing" |
| 20 | |
| 21 | "github.com/google/blueprint" |
| 22 | ) |
| 23 | |
| 24 | var prebuiltsTests = []struct { |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 25 | name string |
| 26 | replaceBp bool // modules is added to default bp boilerplate if false. |
| 27 | modules string |
| 28 | prebuilt []OsType |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 29 | }{ |
| 30 | { |
| 31 | name: "no prebuilt", |
| 32 | modules: ` |
| 33 | source { |
| 34 | name: "bar", |
| 35 | }`, |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 36 | prebuilt: nil, |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 37 | }, |
| 38 | { |
| 39 | name: "no source prebuilt not preferred", |
| 40 | modules: ` |
| 41 | prebuilt { |
| 42 | name: "bar", |
| 43 | prefer: false, |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 44 | srcs: ["prebuilt_file"], |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 45 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 46 | prebuilt: []OsType{Android, BuildOs}, |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 47 | }, |
| 48 | { |
| 49 | name: "no source prebuilt preferred", |
| 50 | modules: ` |
| 51 | prebuilt { |
| 52 | name: "bar", |
| 53 | prefer: true, |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 54 | srcs: ["prebuilt_file"], |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 55 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 56 | prebuilt: []OsType{Android, BuildOs}, |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 57 | }, |
| 58 | { |
| 59 | name: "prebuilt not preferred", |
| 60 | modules: ` |
| 61 | source { |
| 62 | name: "bar", |
| 63 | } |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 64 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 65 | prebuilt { |
| 66 | name: "bar", |
| 67 | prefer: false, |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 68 | srcs: ["prebuilt_file"], |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 69 | }`, |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 70 | prebuilt: nil, |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 71 | }, |
| 72 | { |
| 73 | name: "prebuilt preferred", |
| 74 | modules: ` |
| 75 | source { |
| 76 | name: "bar", |
| 77 | } |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 78 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 79 | prebuilt { |
| 80 | name: "bar", |
| 81 | prefer: true, |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 82 | srcs: ["prebuilt_file"], |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 83 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 84 | prebuilt: []OsType{Android, BuildOs}, |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 85 | }, |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 86 | { |
| 87 | name: "prebuilt no file not preferred", |
| 88 | modules: ` |
| 89 | source { |
| 90 | name: "bar", |
| 91 | } |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 92 | |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 93 | prebuilt { |
| 94 | name: "bar", |
| 95 | prefer: false, |
| 96 | }`, |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 97 | prebuilt: nil, |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 98 | }, |
| 99 | { |
| 100 | name: "prebuilt no file preferred", |
| 101 | modules: ` |
| 102 | source { |
| 103 | name: "bar", |
| 104 | } |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 105 | |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 106 | prebuilt { |
| 107 | name: "bar", |
| 108 | prefer: true, |
| 109 | }`, |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 110 | prebuilt: nil, |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 111 | }, |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 112 | { |
| 113 | name: "prebuilt file from filegroup preferred", |
| 114 | modules: ` |
| 115 | filegroup { |
| 116 | name: "fg", |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 117 | srcs: ["prebuilt_file"], |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 118 | } |
| 119 | prebuilt { |
| 120 | name: "bar", |
| 121 | prefer: true, |
| 122 | srcs: [":fg"], |
| 123 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 124 | prebuilt: []OsType{Android, BuildOs}, |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 125 | }, |
| 126 | { |
| 127 | name: "prebuilt module for device only", |
| 128 | modules: ` |
| 129 | source { |
| 130 | name: "bar", |
| 131 | } |
| 132 | |
| 133 | prebuilt { |
| 134 | name: "bar", |
| 135 | host_supported: false, |
| 136 | prefer: true, |
| 137 | srcs: ["prebuilt_file"], |
| 138 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 139 | prebuilt: []OsType{Android}, |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 140 | }, |
| 141 | { |
| 142 | name: "prebuilt file for host only", |
| 143 | modules: ` |
| 144 | source { |
| 145 | name: "bar", |
| 146 | } |
| 147 | |
| 148 | prebuilt { |
| 149 | name: "bar", |
| 150 | prefer: true, |
| 151 | target: { |
Paul Duffin | 69304cf | 2020-05-29 08:01:00 +0100 | [diff] [blame] | 152 | host: { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 153 | srcs: ["prebuilt_file"], |
| 154 | }, |
| 155 | }, |
| 156 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 157 | prebuilt: []OsType{BuildOs}, |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 158 | }, |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 159 | { |
| 160 | name: "prebuilt override not preferred", |
| 161 | modules: ` |
| 162 | source { |
| 163 | name: "baz", |
| 164 | } |
| 165 | |
| 166 | override_source { |
| 167 | name: "bar", |
| 168 | base: "baz", |
| 169 | } |
| 170 | |
| 171 | prebuilt { |
| 172 | name: "bar", |
| 173 | prefer: false, |
| 174 | srcs: ["prebuilt_file"], |
| 175 | }`, |
| 176 | prebuilt: nil, |
| 177 | }, |
| 178 | { |
| 179 | name: "prebuilt override preferred", |
| 180 | modules: ` |
| 181 | source { |
| 182 | name: "baz", |
| 183 | } |
| 184 | |
| 185 | override_source { |
| 186 | name: "bar", |
| 187 | base: "baz", |
| 188 | } |
| 189 | |
| 190 | prebuilt { |
| 191 | name: "bar", |
| 192 | prefer: true, |
| 193 | srcs: ["prebuilt_file"], |
| 194 | }`, |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 195 | prebuilt: []OsType{Android, BuildOs}, |
| 196 | }, |
| 197 | { |
| 198 | name: "prebuilt including default-disabled OS", |
| 199 | replaceBp: true, |
| 200 | modules: ` |
| 201 | source { |
| 202 | name: "foo", |
| 203 | deps: [":bar"], |
| 204 | target: { |
| 205 | windows: { |
| 206 | enabled: true, |
| 207 | }, |
| 208 | }, |
| 209 | } |
| 210 | |
| 211 | source { |
| 212 | name: "bar", |
| 213 | target: { |
| 214 | windows: { |
| 215 | enabled: true, |
| 216 | }, |
| 217 | }, |
| 218 | } |
| 219 | |
| 220 | prebuilt { |
| 221 | name: "bar", |
| 222 | prefer: true, |
| 223 | srcs: ["prebuilt_file"], |
| 224 | target: { |
| 225 | windows: { |
| 226 | enabled: true, |
| 227 | }, |
| 228 | }, |
| 229 | }`, |
| 230 | prebuilt: []OsType{Android, BuildOs, Windows}, |
| 231 | }, |
| 232 | { |
| 233 | name: "fall back to source for default-disabled OS", |
| 234 | replaceBp: true, |
| 235 | modules: ` |
| 236 | source { |
| 237 | name: "foo", |
| 238 | deps: [":bar"], |
| 239 | target: { |
| 240 | windows: { |
| 241 | enabled: true, |
| 242 | }, |
| 243 | }, |
| 244 | } |
| 245 | |
| 246 | source { |
| 247 | name: "bar", |
| 248 | target: { |
| 249 | windows: { |
| 250 | enabled: true, |
| 251 | }, |
| 252 | }, |
| 253 | } |
| 254 | |
| 255 | prebuilt { |
| 256 | name: "bar", |
| 257 | prefer: true, |
| 258 | srcs: ["prebuilt_file"], |
| 259 | }`, |
| 260 | prebuilt: []OsType{Android, BuildOs}, |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 261 | }, |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | func TestPrebuilts(t *testing.T) { |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame^] | 265 | fs := MockFS{ |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 266 | "prebuilt_file": nil, |
| 267 | "source_file": nil, |
| 268 | } |
Colin Cross | 0d614dd | 2016-10-14 15:38:43 -0700 | [diff] [blame] | 269 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 270 | for _, test := range prebuiltsTests { |
| 271 | t.Run(test.name, func(t *testing.T) { |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 272 | bp := test.modules |
| 273 | if !test.replaceBp { |
| 274 | bp = bp + ` |
| 275 | source { |
| 276 | name: "foo", |
| 277 | deps: [":bar"], |
| 278 | }` |
| 279 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 280 | |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 281 | // Add windows to the target list to test the logic when a variant is |
| 282 | // disabled by default. |
| 283 | if !Windows.DefaultDisabled { |
| 284 | t.Errorf("windows is assumed to be disabled by default") |
| 285 | } |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 286 | |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame^] | 287 | result := emptyTestFixtureFactory.Extend( |
| 288 | PrepareForTestWithArchMutator, |
| 289 | PrepareForTestWithPrebuilts, |
| 290 | PrepareForTestWithOverrides, |
| 291 | PrepareForTestWithFilegroup, |
| 292 | // Add a Windows target to the configuration. |
| 293 | FixtureModifyConfig(func(config Config) { |
| 294 | config.Targets[Windows] = []Target{ |
| 295 | {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true}, |
| 296 | } |
| 297 | }), |
| 298 | fs.AddToFixture(), |
| 299 | FixtureRegisterWithContext(registerTestPrebuiltModules), |
| 300 | ).RunTestWithBp(t, bp) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 301 | |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame^] | 302 | for _, variant := range result.ModuleVariantsForTests("foo") { |
| 303 | foo := result.ModuleForTests("foo", variant) |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 304 | t.Run(foo.Module().Target().Os.String(), func(t *testing.T) { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 305 | var dependsOnSourceModule, dependsOnPrebuiltModule bool |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame^] | 306 | result.VisitDirectDeps(foo.Module(), func(m blueprint.Module) { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 307 | if _, ok := m.(*sourceModule); ok { |
| 308 | dependsOnSourceModule = true |
| 309 | } |
| 310 | if p, ok := m.(*prebuiltModule); ok { |
| 311 | dependsOnPrebuiltModule = true |
| 312 | if !p.Prebuilt().properties.UsePrebuilt { |
| 313 | t.Errorf("dependency on prebuilt module not marked used") |
| 314 | } |
| 315 | } |
| 316 | }) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 317 | |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 318 | moduleIsDisabled := !foo.Module().Enabled() |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 319 | deps := foo.Module().(*sourceModule).deps |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 320 | if moduleIsDisabled { |
| 321 | if len(deps) > 0 { |
| 322 | t.Errorf("disabled module got deps: %v", deps) |
| 323 | } |
| 324 | } else { |
| 325 | if len(deps) != 1 { |
| 326 | t.Errorf("deps does not have single path, but is %v", deps) |
| 327 | } |
Colin Cross | c3e7fa6 | 2017-03-17 13:14:32 -0700 | [diff] [blame] | 328 | } |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 329 | |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 330 | var usingSourceFile, usingPrebuiltFile bool |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 331 | if len(deps) > 0 && deps[0].String() == "source_file" { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 332 | usingSourceFile = true |
| 333 | } |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 334 | if len(deps) > 0 && deps[0].String() == "prebuilt_file" { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 335 | usingPrebuiltFile = true |
| 336 | } |
Colin Cross | c3e7fa6 | 2017-03-17 13:14:32 -0700 | [diff] [blame] | 337 | |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 338 | prebuilt := false |
| 339 | for _, os := range test.prebuilt { |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 340 | if os == foo.Module().Target().Os { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 341 | prebuilt = true |
| 342 | } |
| 343 | } |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 344 | |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 345 | if prebuilt { |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 346 | if moduleIsDisabled { |
| 347 | t.Errorf("dependent module for prebuilt is disabled") |
| 348 | } |
| 349 | |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 350 | if !dependsOnPrebuiltModule { |
| 351 | t.Errorf("doesn't depend on prebuilt module") |
| 352 | } |
| 353 | if !usingPrebuiltFile { |
| 354 | t.Errorf("doesn't use prebuilt_file") |
| 355 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 356 | |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 357 | if dependsOnSourceModule { |
| 358 | t.Errorf("depends on source module") |
| 359 | } |
| 360 | if usingSourceFile { |
| 361 | t.Errorf("using source_file") |
| 362 | } |
Martin Stjernholm | f467732 | 2020-07-07 02:20:40 +0100 | [diff] [blame] | 363 | } else if !moduleIsDisabled { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 364 | if dependsOnPrebuiltModule { |
| 365 | t.Errorf("depends on prebuilt module") |
| 366 | } |
| 367 | if usingPrebuiltFile { |
| 368 | t.Errorf("using prebuilt_file") |
| 369 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 370 | |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 371 | if !dependsOnSourceModule { |
| 372 | t.Errorf("doesn't depend on source module") |
| 373 | } |
| 374 | if !usingSourceFile { |
| 375 | t.Errorf("doesn't use source_file") |
| 376 | } |
| 377 | } |
| 378 | }) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 379 | } |
| 380 | }) |
| 381 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Paul Duffin | 78ac5b9 | 2020-01-14 12:42:08 +0000 | [diff] [blame] | 384 | func registerTestPrebuiltBuildComponents(ctx RegistrationContext) { |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame^] | 385 | registerTestPrebuiltModules(ctx) |
Paul Duffin | 78ac5b9 | 2020-01-14 12:42:08 +0000 | [diff] [blame] | 386 | |
| 387 | RegisterPrebuiltMutators(ctx) |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 388 | ctx.PostDepsMutators(RegisterOverridePostDepsMutators) |
Paul Duffin | 78ac5b9 | 2020-01-14 12:42:08 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame^] | 391 | func registerTestPrebuiltModules(ctx RegistrationContext) { |
| 392 | ctx.RegisterModuleType("prebuilt", newPrebuiltModule) |
| 393 | ctx.RegisterModuleType("source", newSourceModule) |
| 394 | ctx.RegisterModuleType("override_source", newOverrideSourceModule) |
| 395 | } |
| 396 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 397 | type prebuiltModule struct { |
| 398 | ModuleBase |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 399 | prebuilt Prebuilt |
| 400 | properties struct { |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 401 | Srcs []string `android:"path,arch_variant"` |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 402 | } |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 403 | src Path |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 406 | func newPrebuiltModule() Module { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 407 | m := &prebuiltModule{} |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 408 | m.AddProperties(&m.properties) |
| 409 | InitPrebuiltModule(m, &m.properties.Srcs) |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 410 | InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 411 | return m |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | func (p *prebuiltModule) Name() string { |
| 415 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 416 | } |
| 417 | |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 418 | func (p *prebuiltModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 419 | if len(p.properties.Srcs) >= 1 { |
| 420 | p.src = p.prebuilt.SingleSourcePath(ctx) |
| 421 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | func (p *prebuiltModule) Prebuilt() *Prebuilt { |
| 425 | return &p.prebuilt |
| 426 | } |
| 427 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 428 | func (p *prebuiltModule) OutputFiles(tag string) (Paths, error) { |
| 429 | switch tag { |
| 430 | case "": |
| 431 | return Paths{p.src}, nil |
| 432 | default: |
| 433 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 434 | } |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 435 | } |
| 436 | |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 437 | type sourceModuleProperties struct { |
| 438 | Deps []string `android:"path,arch_variant"` |
| 439 | } |
| 440 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 441 | type sourceModule struct { |
| 442 | ModuleBase |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 443 | OverridableModuleBase |
| 444 | |
| 445 | properties sourceModuleProperties |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 446 | dependsOnSourceModule, dependsOnPrebuiltModule bool |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 447 | deps Paths |
| 448 | src Path |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 451 | func newSourceModule() Module { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 452 | m := &sourceModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 453 | m.AddProperties(&m.properties) |
Martin Stjernholm | 009a9dc | 2020-03-05 17:34:13 +0000 | [diff] [blame] | 454 | InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon) |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 455 | InitOverridableModule(m, nil) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 456 | return m |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 459 | func (s *sourceModule) OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) { |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 460 | // s.properties.Deps are annotated with android:path, so they are |
| 461 | // automatically added to the dependency by pathDeps mutator |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
Jiyong Park | d467111 | 2019-04-19 17:23:04 +0900 | [diff] [blame] | 465 | s.deps = PathsForModuleSrc(ctx, s.properties.Deps) |
| 466 | s.src = PathForModuleSrc(ctx, "source_file") |
| 467 | } |
| 468 | |
| 469 | func (s *sourceModule) Srcs() Paths { |
| 470 | return Paths{s.src} |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 471 | } |
Jaewoong Jung | fb25a64 | 2020-06-11 10:37:51 -0700 | [diff] [blame] | 472 | |
| 473 | type overrideSourceModule struct { |
| 474 | ModuleBase |
| 475 | OverrideModuleBase |
| 476 | } |
| 477 | |
| 478 | func (o *overrideSourceModule) GenerateAndroidBuildActions(_ ModuleContext) { |
| 479 | } |
| 480 | |
| 481 | func newOverrideSourceModule() Module { |
| 482 | m := &overrideSourceModule{} |
| 483 | m.AddProperties(&sourceModuleProperties{}) |
| 484 | |
| 485 | InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon) |
| 486 | InitOverrideModule(m) |
| 487 | return m |
| 488 | } |