Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Android Open Source Project |
| 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 rust |
| 16 | |
| 17 | import ( |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 18 | "fmt" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 19 | "strings" |
| 20 | |
| 21 | "github.com/google/blueprint" |
| 22 | "github.com/google/blueprint/proptools" |
| 23 | |
| 24 | "android/soong/android" |
| 25 | "android/soong/cc" |
| 26 | "android/soong/rust/config" |
| 27 | ) |
| 28 | |
| 29 | var pctx = android.NewPackageContext("android/soong/rust") |
| 30 | |
| 31 | func init() { |
| 32 | // Only allow rust modules to be defined for certain projects |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 33 | |
| 34 | android.AddNeverAllowRules( |
| 35 | android.NeverAllow(). |
Ivan Lozano | e169ad7 | 2019-09-18 08:42:54 -0700 | [diff] [blame] | 36 | NotIn(config.RustAllowedPaths...). |
| 37 | ModuleType(config.RustModuleTypes...)) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 38 | |
| 39 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 40 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 41 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 42 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 43 | }) |
| 44 | pctx.Import("android/soong/rust/config") |
| 45 | } |
| 46 | |
| 47 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 48 | GlobalRustFlags []string // Flags that apply globally to rust |
| 49 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 50 | RustFlags []string // Flags that apply to rust |
| 51 | LinkFlags []string // Flags that apply to linker |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 52 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 53 | Coverage bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | type BaseProperties struct { |
| 57 | AndroidMkRlibs []string |
| 58 | AndroidMkDylibs []string |
| 59 | AndroidMkProcMacroLibs []string |
| 60 | AndroidMkSharedLibs []string |
| 61 | AndroidMkStaticLibs []string |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 62 | SubName string `blueprint:"mutated"` |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 63 | PreventInstall bool |
| 64 | HideFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | type Module struct { |
| 68 | android.ModuleBase |
| 69 | android.DefaultableModuleBase |
| 70 | |
| 71 | Properties BaseProperties |
| 72 | |
| 73 | hod android.HostOrDeviceSupported |
| 74 | multilib android.Multilib |
| 75 | |
| 76 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 77 | coverage *coverage |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 78 | cachedToolchain config.Toolchain |
| 79 | subAndroidMkOnce map[subAndroidMkProvider]bool |
| 80 | outputFile android.OptionalPath |
| 81 | } |
| 82 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 83 | var _ android.ImageInterface = (*Module)(nil) |
| 84 | |
| 85 | func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
| 86 | |
| 87 | func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 88 | return true |
| 89 | } |
| 90 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 91 | func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool { |
| 92 | return mod.InRamdisk() |
| 93 | } |
| 94 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 95 | func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool { |
| 96 | return mod.InRecovery() |
| 97 | } |
| 98 | |
| 99 | func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string { |
| 100 | return nil |
| 101 | } |
| 102 | |
| 103 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { |
| 104 | } |
| 105 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 106 | func (mod *Module) BuildStubs() bool { |
| 107 | return false |
| 108 | } |
| 109 | |
| 110 | func (mod *Module) HasStubsVariants() bool { |
| 111 | return false |
| 112 | } |
| 113 | |
| 114 | func (mod *Module) SelectedStl() string { |
| 115 | return "" |
| 116 | } |
| 117 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 118 | func (mod *Module) NonCcVariants() bool { |
| 119 | if mod.compiler != nil { |
| 120 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 121 | if library.buildRlib() || library.buildDylib() { |
| 122 | return true |
| 123 | } else { |
| 124 | return false |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 129 | } |
| 130 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 131 | func (mod *Module) ApiLevel() string { |
| 132 | panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName())) |
| 133 | } |
| 134 | |
| 135 | func (mod *Module) Static() bool { |
| 136 | if mod.compiler != nil { |
| 137 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 138 | return library.static() |
| 139 | } |
| 140 | } |
| 141 | panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName())) |
| 142 | } |
| 143 | |
| 144 | func (mod *Module) Shared() bool { |
| 145 | if mod.compiler != nil { |
| 146 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 147 | return library.static() |
| 148 | } |
| 149 | } |
| 150 | panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName())) |
| 151 | } |
| 152 | |
| 153 | func (mod *Module) Toc() android.OptionalPath { |
| 154 | if mod.compiler != nil { |
| 155 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 156 | return android.OptionalPath{} |
| 157 | } |
| 158 | } |
| 159 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 160 | } |
| 161 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 162 | func (mod *Module) OnlyInRamdisk() bool { |
| 163 | return false |
| 164 | } |
| 165 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 166 | func (mod *Module) OnlyInRecovery() bool { |
| 167 | return false |
| 168 | } |
| 169 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 170 | func (mod *Module) UseSdk() bool { |
| 171 | return false |
| 172 | } |
| 173 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 174 | func (mod *Module) UseVndk() bool { |
| 175 | return false |
| 176 | } |
| 177 | |
| 178 | func (mod *Module) MustUseVendorVariant() bool { |
| 179 | return false |
| 180 | } |
| 181 | |
| 182 | func (mod *Module) IsVndk() bool { |
| 183 | return false |
| 184 | } |
| 185 | |
| 186 | func (mod *Module) HasVendorVariant() bool { |
| 187 | return false |
| 188 | } |
| 189 | |
| 190 | func (mod *Module) SdkVersion() string { |
| 191 | return "" |
| 192 | } |
| 193 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 194 | func (mod *Module) AlwaysSdk() bool { |
| 195 | return false |
| 196 | } |
| 197 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 198 | func (mod *Module) IsSdkVariant() bool { |
| 199 | return false |
| 200 | } |
| 201 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 202 | func (mod *Module) ToolchainLibrary() bool { |
| 203 | return false |
| 204 | } |
| 205 | |
| 206 | func (mod *Module) NdkPrebuiltStl() bool { |
| 207 | return false |
| 208 | } |
| 209 | |
| 210 | func (mod *Module) StubDecorator() bool { |
| 211 | return false |
| 212 | } |
| 213 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 214 | type Deps struct { |
| 215 | Dylibs []string |
| 216 | Rlibs []string |
| 217 | ProcMacros []string |
| 218 | SharedLibs []string |
| 219 | StaticLibs []string |
| 220 | |
| 221 | CrtBegin, CrtEnd string |
| 222 | } |
| 223 | |
| 224 | type PathDeps struct { |
| 225 | DyLibs RustLibraries |
| 226 | RLibs RustLibraries |
| 227 | SharedLibs android.Paths |
| 228 | StaticLibs android.Paths |
| 229 | ProcMacros RustLibraries |
| 230 | linkDirs []string |
| 231 | depFlags []string |
| 232 | //ReexportedDeps android.Paths |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 233 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 234 | coverageFiles android.Paths |
| 235 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 236 | CrtBegin android.OptionalPath |
| 237 | CrtEnd android.OptionalPath |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | type RustLibraries []RustLibrary |
| 241 | |
| 242 | type RustLibrary struct { |
| 243 | Path android.Path |
| 244 | CrateName string |
| 245 | } |
| 246 | |
| 247 | type compiler interface { |
| 248 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 249 | compilerProps() []interface{} |
| 250 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path |
| 251 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 252 | crateName() string |
| 253 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 254 | inData() bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 255 | install(ctx ModuleContext, path android.Path) |
| 256 | relativeInstallPath() string |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 257 | |
| 258 | nativeCoverage() bool |
| 259 | } |
| 260 | |
| 261 | func (mod *Module) isCoverageVariant() bool { |
| 262 | return mod.coverage.Properties.IsCoverageVariant |
| 263 | } |
| 264 | |
| 265 | var _ cc.Coverage = (*Module)(nil) |
| 266 | |
| 267 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 268 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 269 | } |
| 270 | |
| 271 | func (mod *Module) PreventInstall() { |
| 272 | mod.Properties.PreventInstall = true |
| 273 | } |
| 274 | |
| 275 | func (mod *Module) HideFromMake() { |
| 276 | mod.Properties.HideFromMake = true |
| 277 | } |
| 278 | |
| 279 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 280 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 281 | } |
| 282 | |
| 283 | func (mod *Module) EnableCoverageIfNeeded() { |
| 284 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | func defaultsFactory() android.Module { |
| 288 | return DefaultsFactory() |
| 289 | } |
| 290 | |
| 291 | type Defaults struct { |
| 292 | android.ModuleBase |
| 293 | android.DefaultsModuleBase |
| 294 | } |
| 295 | |
| 296 | func DefaultsFactory(props ...interface{}) android.Module { |
| 297 | module := &Defaults{} |
| 298 | |
| 299 | module.AddProperties(props...) |
| 300 | module.AddProperties( |
| 301 | &BaseProperties{}, |
| 302 | &BaseCompilerProperties{}, |
| 303 | &BinaryCompilerProperties{}, |
| 304 | &LibraryCompilerProperties{}, |
| 305 | &ProcMacroCompilerProperties{}, |
| 306 | &PrebuiltProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 307 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 308 | &cc.CoverageProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 309 | ) |
| 310 | |
| 311 | android.InitDefaultsModule(module) |
| 312 | return module |
| 313 | } |
| 314 | |
| 315 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 316 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 319 | func (mod *Module) CcLibrary() bool { |
| 320 | if mod.compiler != nil { |
| 321 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 322 | return true |
| 323 | } |
| 324 | } |
| 325 | return false |
| 326 | } |
| 327 | |
| 328 | func (mod *Module) CcLibraryInterface() bool { |
| 329 | if mod.compiler != nil { |
| 330 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 331 | return true |
| 332 | } |
| 333 | } |
| 334 | return false |
| 335 | } |
| 336 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 337 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 338 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 339 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 340 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 344 | } |
| 345 | |
| 346 | func (mod *Module) SetStatic() { |
| 347 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 348 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 349 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 350 | return |
| 351 | } |
| 352 | } |
| 353 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 354 | } |
| 355 | |
| 356 | func (mod *Module) SetShared() { |
| 357 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 358 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 359 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 360 | return |
| 361 | } |
| 362 | } |
| 363 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 364 | } |
| 365 | |
| 366 | func (mod *Module) SetBuildStubs() { |
| 367 | panic("SetBuildStubs not yet implemented for rust modules") |
| 368 | } |
| 369 | |
| 370 | func (mod *Module) SetStubsVersions(string) { |
| 371 | panic("SetStubsVersions not yet implemented for rust modules") |
| 372 | } |
| 373 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 374 | func (mod *Module) StubsVersion() string { |
| 375 | panic("SetStubsVersions not yet implemented for rust modules") |
| 376 | } |
| 377 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 378 | func (mod *Module) BuildStaticVariant() bool { |
| 379 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 380 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 381 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 385 | } |
| 386 | |
| 387 | func (mod *Module) BuildSharedVariant() bool { |
| 388 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 389 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 390 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 394 | } |
| 395 | |
| 396 | // Rust module deps don't have a link order (?) |
| 397 | func (mod *Module) SetDepsInLinkOrder([]android.Path) {} |
| 398 | |
| 399 | func (mod *Module) GetDepsInLinkOrder() []android.Path { |
| 400 | return []android.Path{} |
| 401 | } |
| 402 | |
| 403 | func (mod *Module) GetStaticVariant() cc.LinkableInterface { |
| 404 | return nil |
| 405 | } |
| 406 | |
| 407 | func (mod *Module) Module() android.Module { |
| 408 | return mod |
| 409 | } |
| 410 | |
| 411 | func (mod *Module) StubsVersions() []string { |
| 412 | // For now, Rust has no stubs versions. |
| 413 | if mod.compiler != nil { |
| 414 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 415 | return []string{} |
| 416 | } |
| 417 | } |
| 418 | panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName())) |
| 419 | } |
| 420 | |
| 421 | func (mod *Module) OutputFile() android.OptionalPath { |
| 422 | return mod.outputFile |
| 423 | } |
| 424 | |
| 425 | func (mod *Module) InRecovery() bool { |
| 426 | // For now, Rust has no notion of the recovery image |
| 427 | return false |
| 428 | } |
| 429 | func (mod *Module) HasStaticVariant() bool { |
| 430 | if mod.GetStaticVariant() != nil { |
| 431 | return true |
| 432 | } |
| 433 | return false |
| 434 | } |
| 435 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 436 | func (mod *Module) CoverageFiles() android.Paths { |
| 437 | if mod.compiler != nil { |
| 438 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
| 439 | if library.coverageFile != nil { |
| 440 | return android.Paths{library.coverageFile} |
| 441 | } |
| 442 | return android.Paths{} |
| 443 | } |
| 444 | } |
| 445 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 446 | } |
| 447 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 448 | var _ cc.LinkableInterface = (*Module)(nil) |
| 449 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 450 | func (mod *Module) Init() android.Module { |
| 451 | mod.AddProperties(&mod.Properties) |
| 452 | |
| 453 | if mod.compiler != nil { |
| 454 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 455 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 456 | if mod.coverage != nil { |
| 457 | mod.AddProperties(mod.coverage.props()...) |
| 458 | } |
| 459 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 460 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
| 461 | |
| 462 | android.InitDefaultableModule(mod) |
| 463 | |
Ivan Lozano | de25291 | 2019-09-06 15:29:52 -0700 | [diff] [blame] | 464 | // Explicitly disable unsupported targets. |
| 465 | android.AddLoadHook(mod, func(ctx android.LoadHookContext) { |
| 466 | disableTargets := struct { |
| 467 | Target struct { |
Ivan Lozano | de25291 | 2019-09-06 15:29:52 -0700 | [diff] [blame] | 468 | Linux_bionic struct { |
| 469 | Enabled *bool |
| 470 | } |
| 471 | } |
| 472 | }{} |
Ivan Lozano | de25291 | 2019-09-06 15:29:52 -0700 | [diff] [blame] | 473 | disableTargets.Target.Linux_bionic.Enabled = proptools.BoolPtr(false) |
| 474 | |
| 475 | ctx.AppendProperties(&disableTargets) |
| 476 | }) |
| 477 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 478 | return mod |
| 479 | } |
| 480 | |
| 481 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 482 | return &Module{ |
| 483 | hod: hod, |
| 484 | multilib: multilib, |
| 485 | } |
| 486 | } |
| 487 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 488 | module := newBaseModule(hod, multilib) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 489 | module.coverage = &coverage{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 490 | return module |
| 491 | } |
| 492 | |
| 493 | type ModuleContext interface { |
| 494 | android.ModuleContext |
| 495 | ModuleContextIntf |
| 496 | } |
| 497 | |
| 498 | type BaseModuleContext interface { |
| 499 | android.BaseModuleContext |
| 500 | ModuleContextIntf |
| 501 | } |
| 502 | |
| 503 | type DepsContext interface { |
| 504 | android.BottomUpMutatorContext |
| 505 | ModuleContextIntf |
| 506 | } |
| 507 | |
| 508 | type ModuleContextIntf interface { |
| 509 | toolchain() config.Toolchain |
| 510 | baseModuleName() string |
| 511 | CrateName() string |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 512 | nativeCoverage() bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | type depsContext struct { |
| 516 | android.BottomUpMutatorContext |
| 517 | moduleContextImpl |
| 518 | } |
| 519 | |
| 520 | type moduleContext struct { |
| 521 | android.ModuleContext |
| 522 | moduleContextImpl |
| 523 | } |
| 524 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 525 | func (ctx *moduleContextImpl) nativeCoverage() bool { |
| 526 | return ctx.mod.nativeCoverage() |
| 527 | } |
| 528 | |
| 529 | func (mod *Module) nativeCoverage() bool { |
| 530 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 531 | } |
| 532 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 533 | type moduleContextImpl struct { |
| 534 | mod *Module |
| 535 | ctx BaseModuleContext |
| 536 | } |
| 537 | |
| 538 | func (ctx *moduleContextImpl) toolchain() config.Toolchain { |
| 539 | return ctx.mod.toolchain(ctx.ctx) |
| 540 | } |
| 541 | |
| 542 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 543 | if mod.cachedToolchain == nil { |
| 544 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 545 | } |
| 546 | return mod.cachedToolchain |
| 547 | } |
| 548 | |
| 549 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 550 | } |
| 551 | |
| 552 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 553 | ctx := &moduleContext{ |
| 554 | ModuleContext: actx, |
| 555 | moduleContextImpl: moduleContextImpl{ |
| 556 | mod: mod, |
| 557 | }, |
| 558 | } |
| 559 | ctx.ctx = ctx |
| 560 | |
| 561 | toolchain := mod.toolchain(ctx) |
| 562 | |
| 563 | if !toolchain.Supported() { |
| 564 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 565 | return |
| 566 | } |
| 567 | |
| 568 | deps := mod.depsToPaths(ctx) |
| 569 | flags := Flags{ |
| 570 | Toolchain: toolchain, |
| 571 | } |
| 572 | |
| 573 | if mod.compiler != nil { |
| 574 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 575 | } |
| 576 | if mod.coverage != nil { |
| 577 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 578 | } |
| 579 | |
| 580 | if mod.compiler != nil { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 581 | outputFile := mod.compiler.compile(ctx, flags, deps) |
| 582 | mod.outputFile = android.OptionalPathForPath(outputFile) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 583 | if !mod.Properties.PreventInstall { |
| 584 | mod.compiler.install(ctx, mod.outputFile.Path()) |
| 585 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 590 | deps := Deps{} |
| 591 | |
| 592 | if mod.compiler != nil { |
| 593 | deps = mod.compiler.compilerDeps(ctx, deps) |
| 594 | } |
| 595 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 596 | if mod.coverage != nil { |
| 597 | deps = mod.coverage.deps(ctx, deps) |
| 598 | } |
| 599 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 600 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 601 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
| 602 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 603 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 604 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 605 | |
| 606 | return deps |
| 607 | |
| 608 | } |
| 609 | |
| 610 | func (ctx *moduleContextImpl) baseModuleName() string { |
| 611 | return ctx.mod.ModuleBase.BaseModuleName() |
| 612 | } |
| 613 | |
| 614 | func (ctx *moduleContextImpl) CrateName() string { |
| 615 | return ctx.mod.CrateName() |
| 616 | } |
| 617 | |
| 618 | type dependencyTag struct { |
| 619 | blueprint.BaseDependencyTag |
| 620 | name string |
| 621 | library bool |
| 622 | proc_macro bool |
| 623 | } |
| 624 | |
| 625 | var ( |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 626 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
| 627 | dylibDepTag = dependencyTag{name: "dylib", library: true} |
| 628 | procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true} |
| 629 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 630 | ) |
| 631 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 632 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 633 | if mod.coverage != nil { |
| 634 | mod.coverage.begin(ctx) |
| 635 | } |
| 636 | } |
| 637 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 638 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 639 | var depPaths PathDeps |
| 640 | |
| 641 | directRlibDeps := []*Module{} |
| 642 | directDylibDeps := []*Module{} |
| 643 | directProcMacroDeps := []*Module{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 644 | directSharedLibDeps := [](cc.LinkableInterface){} |
| 645 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 646 | |
| 647 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 648 | depName := ctx.OtherModuleName(dep) |
| 649 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 650 | if rustDep, ok := dep.(*Module); ok { |
| 651 | //Handle Rust Modules |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 652 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 653 | linkFile := rustDep.outputFile |
| 654 | if !linkFile.Valid() { |
| 655 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 656 | } |
| 657 | |
| 658 | switch depTag { |
| 659 | case dylibDepTag: |
| 660 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 661 | if !ok || !dylib.dylib() { |
| 662 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 663 | return |
| 664 | } |
| 665 | directDylibDeps = append(directDylibDeps, rustDep) |
| 666 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName) |
| 667 | case rlibDepTag: |
| 668 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 669 | if !ok || !rlib.rlib() { |
| 670 | ctx.ModuleErrorf("mod %q not an rlib library", depName) |
| 671 | return |
| 672 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 673 | depPaths.coverageFiles = append(depPaths.coverageFiles, rustDep.CoverageFiles()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 674 | directRlibDeps = append(directRlibDeps, rustDep) |
| 675 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName) |
| 676 | case procMacroDepTag: |
| 677 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
| 678 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName) |
| 679 | } |
| 680 | |
| 681 | //Append the dependencies exportedDirs |
| 682 | if lib, ok := rustDep.compiler.(*libraryDecorator); ok { |
| 683 | depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedDirs()...) |
| 684 | depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | // Append this dependencies output to this mod's linkDirs so they can be exported to dependencies |
| 688 | // This can be probably be refactored by defining a common exporter interface similar to cc's |
| 689 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
| 690 | linkDir := linkPathFromFilePath(linkFile.Path()) |
| 691 | if lib, ok := mod.compiler.(*libraryDecorator); ok { |
| 692 | lib.linkDirs = append(lib.linkDirs, linkDir) |
| 693 | } else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok { |
| 694 | procMacro.linkDirs = append(procMacro.linkDirs, linkDir) |
| 695 | } |
| 696 | } |
| 697 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 698 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 699 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 700 | if ccDep, ok := dep.(cc.LinkableInterface); ok { |
| 701 | //Handle C dependencies |
| 702 | if _, ok := ccDep.(*Module); !ok { |
| 703 | if ccDep.Module().Target().Os != ctx.Os() { |
| 704 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 705 | return |
| 706 | } |
| 707 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 708 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 709 | return |
| 710 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 713 | linkFile := ccDep.OutputFile() |
| 714 | linkPath := linkPathFromFilePath(linkFile.Path()) |
| 715 | libName := libNameFromFilePath(linkFile.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 716 | depFlag := "-l" + libName |
| 717 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 718 | if !linkFile.Valid() { |
| 719 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 720 | } |
| 721 | |
| 722 | exportDep := false |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 723 | switch depTag { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 724 | case cc.StaticDepTag: |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 725 | depFlag = "-lstatic=" + libName |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 726 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 727 | depPaths.depFlags = append(depPaths.depFlags, depFlag) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 728 | depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 729 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
| 730 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName) |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 731 | case cc.SharedDepTag: |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 732 | depFlag = "-ldylib=" + libName |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 733 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 734 | depPaths.depFlags = append(depPaths.depFlags, depFlag) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 735 | directSharedLibDeps = append(directSharedLibDeps, ccDep) |
| 736 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) |
| 737 | exportDep = true |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 738 | case cc.CrtBeginDepTag: |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 739 | depPaths.CrtBegin = linkFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 740 | case cc.CrtEndDepTag: |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 741 | depPaths.CrtEnd = linkFile |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | // Make sure these dependencies are propagated |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 745 | if lib, ok := mod.compiler.(*libraryDecorator); ok && exportDep { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 746 | lib.linkDirs = append(lib.linkDirs, linkPath) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 747 | lib.depFlags = append(lib.depFlags, depFlag) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 748 | } else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok && exportDep { |
| 749 | procMacro.linkDirs = append(procMacro.linkDirs, linkPath) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 750 | procMacro.depFlags = append(procMacro.depFlags, depFlag) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | } |
| 754 | }) |
| 755 | |
| 756 | var rlibDepFiles RustLibraries |
| 757 | for _, dep := range directRlibDeps { |
| 758 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 759 | } |
| 760 | var dylibDepFiles RustLibraries |
| 761 | for _, dep := range directDylibDeps { |
| 762 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 763 | } |
| 764 | var procMacroDepFiles RustLibraries |
| 765 | for _, dep := range directProcMacroDeps { |
| 766 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 767 | } |
| 768 | |
| 769 | var staticLibDepFiles android.Paths |
| 770 | for _, dep := range directStaticLibDeps { |
| 771 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
| 772 | } |
| 773 | |
| 774 | var sharedLibDepFiles android.Paths |
| 775 | for _, dep := range directSharedLibDeps { |
| 776 | sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) |
| 777 | } |
| 778 | |
| 779 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 780 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
| 781 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) |
| 782 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
| 783 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
| 784 | |
| 785 | // Dedup exported flags from dependencies |
| 786 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
| 787 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
| 788 | |
| 789 | return depPaths |
| 790 | } |
| 791 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 792 | func (mod *Module) InstallInData() bool { |
| 793 | if mod.compiler == nil { |
| 794 | return false |
| 795 | } |
| 796 | return mod.compiler.inData() |
| 797 | } |
| 798 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 799 | func linkPathFromFilePath(filepath android.Path) string { |
| 800 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 801 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 802 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 803 | func libNameFromFilePath(filepath android.Path) string { |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 804 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 805 | if strings.HasPrefix(libName, "lib") { |
| 806 | libName = libName[3:] |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 807 | } |
| 808 | return libName |
| 809 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 810 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 811 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 812 | ctx := &depsContext{ |
| 813 | BottomUpMutatorContext: actx, |
| 814 | moduleContextImpl: moduleContextImpl{ |
| 815 | mod: mod, |
| 816 | }, |
| 817 | } |
| 818 | ctx.ctx = ctx |
| 819 | |
| 820 | deps := mod.deps(ctx) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 821 | commonDepVariations := []blueprint.Variation{} |
Jooyung Han | 624d35c | 2020-04-10 12:57:24 +0900 | [diff] [blame] | 822 | if cc.VersionVariantAvailable(mod) { |
| 823 | commonDepVariations = append(commonDepVariations, |
| 824 | blueprint.Variation{Mutator: "version", Variation: ""}) |
| 825 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 826 | if !mod.Host() { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 827 | commonDepVariations = append(commonDepVariations, |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 828 | blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 829 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 830 | actx.AddVariationDependencies( |
| 831 | append(commonDepVariations, []blueprint.Variation{ |
| 832 | {Mutator: "rust_libraries", Variation: "rlib"}, |
| 833 | {Mutator: "link", Variation: ""}}...), |
| 834 | rlibDepTag, deps.Rlibs...) |
| 835 | actx.AddVariationDependencies( |
| 836 | append(commonDepVariations, []blueprint.Variation{ |
| 837 | {Mutator: "rust_libraries", Variation: "dylib"}, |
| 838 | {Mutator: "link", Variation: ""}}...), |
| 839 | dylibDepTag, deps.Dylibs...) |
| 840 | |
| 841 | actx.AddVariationDependencies(append(commonDepVariations, |
| 842 | blueprint.Variation{Mutator: "link", Variation: "shared"}), |
| 843 | cc.SharedDepTag, deps.SharedLibs...) |
| 844 | actx.AddVariationDependencies(append(commonDepVariations, |
| 845 | blueprint.Variation{Mutator: "link", Variation: "static"}), |
| 846 | cc.StaticDepTag, deps.StaticLibs...) |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 847 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 848 | if deps.CrtBegin != "" { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 849 | actx.AddVariationDependencies(commonDepVariations, cc.CrtBeginDepTag, deps.CrtBegin) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 850 | } |
| 851 | if deps.CrtEnd != "" { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 852 | actx.AddVariationDependencies(commonDepVariations, cc.CrtEndDepTag, deps.CrtEnd) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 855 | // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 856 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 859 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 860 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 861 | mod.beginMutator(ctx) |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | type baseModuleContext struct { |
| 866 | android.BaseModuleContext |
| 867 | moduleContextImpl |
| 868 | } |
| 869 | |
| 870 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 871 | ctx := &baseModuleContext{ |
| 872 | BaseModuleContext: actx, |
| 873 | moduleContextImpl: moduleContextImpl{ |
| 874 | mod: mod, |
| 875 | }, |
| 876 | } |
| 877 | ctx.ctx = ctx |
| 878 | |
| 879 | mod.begin(ctx) |
| 880 | } |
| 881 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 882 | func (mod *Module) Name() string { |
| 883 | name := mod.ModuleBase.Name() |
| 884 | if p, ok := mod.compiler.(interface { |
| 885 | Name(string) string |
| 886 | }); ok { |
| 887 | name = p.Name(name) |
| 888 | } |
| 889 | return name |
| 890 | } |
| 891 | |
| 892 | var Bool = proptools.Bool |
| 893 | var BoolDefault = proptools.BoolDefault |
| 894 | var String = proptools.String |
| 895 | var StringPtr = proptools.StringPtr |