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" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 26 | cc_config "android/soong/cc/config" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 27 | "android/soong/rust/config" |
| 28 | ) |
| 29 | |
| 30 | var pctx = android.NewPackageContext("android/soong/rust") |
| 31 | |
| 32 | func init() { |
| 33 | // Only allow rust modules to be defined for certain projects |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 34 | |
| 35 | android.AddNeverAllowRules( |
| 36 | android.NeverAllow(). |
Ivan Lozano | e169ad7 | 2019-09-18 08:42:54 -0700 | [diff] [blame] | 37 | NotIn(config.RustAllowedPaths...). |
| 38 | ModuleType(config.RustModuleTypes...)) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 39 | |
| 40 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 41 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 42 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 43 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 44 | }) |
| 45 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 46 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 50 | GlobalRustFlags []string // Flags that apply globally to rust |
| 51 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 52 | RustFlags []string // Flags that apply to rust |
| 53 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 54 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 55 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 56 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 57 | Clippy bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | type BaseProperties struct { |
| 61 | AndroidMkRlibs []string |
| 62 | AndroidMkDylibs []string |
| 63 | AndroidMkProcMacroLibs []string |
| 64 | AndroidMkSharedLibs []string |
| 65 | AndroidMkStaticLibs []string |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 66 | |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 67 | SubName string `blueprint:"mutated"` |
| 68 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 69 | PreventInstall bool |
| 70 | HideFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | type Module struct { |
| 74 | android.ModuleBase |
| 75 | android.DefaultableModuleBase |
| 76 | |
| 77 | Properties BaseProperties |
| 78 | |
| 79 | hod android.HostOrDeviceSupported |
| 80 | multilib android.Multilib |
| 81 | |
| 82 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 83 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 84 | clippy *clippy |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 85 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 86 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 87 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 88 | |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 89 | outputFile android.OptionalPath |
| 90 | generatedFile android.OptionalPath |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 93 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 94 | switch tag { |
| 95 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 96 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 97 | return mod.sourceProvider.Srcs(), nil |
| 98 | } else { |
| 99 | if mod.outputFile.Valid() { |
| 100 | return android.Paths{mod.outputFile.Path()}, nil |
| 101 | } |
| 102 | return android.Paths{}, nil |
| 103 | } |
| 104 | default: |
| 105 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 106 | } |
| 107 | } |
| 108 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 109 | var _ android.ImageInterface = (*Module)(nil) |
| 110 | |
| 111 | func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
| 112 | |
| 113 | func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 114 | return true |
| 115 | } |
| 116 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 117 | func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool { |
| 118 | return mod.InRamdisk() |
| 119 | } |
| 120 | |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 121 | func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool { |
| 122 | return mod.InRecovery() |
| 123 | } |
| 124 | |
| 125 | func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string { |
| 126 | return nil |
| 127 | } |
| 128 | |
| 129 | func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { |
| 130 | } |
| 131 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 132 | func (mod *Module) BuildStubs() bool { |
| 133 | return false |
| 134 | } |
| 135 | |
| 136 | func (mod *Module) HasStubsVariants() bool { |
| 137 | return false |
| 138 | } |
| 139 | |
| 140 | func (mod *Module) SelectedStl() string { |
| 141 | return "" |
| 142 | } |
| 143 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 144 | func (mod *Module) NonCcVariants() bool { |
| 145 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 146 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 147 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 151 | } |
| 152 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 153 | func (mod *Module) ApiLevel() string { |
| 154 | panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName())) |
| 155 | } |
| 156 | |
| 157 | func (mod *Module) Static() bool { |
| 158 | if mod.compiler != nil { |
| 159 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 160 | return library.static() |
| 161 | } |
| 162 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 163 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | func (mod *Module) Shared() bool { |
| 167 | if mod.compiler != nil { |
| 168 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 169 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 172 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func (mod *Module) Toc() android.OptionalPath { |
| 176 | if mod.compiler != nil { |
| 177 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 178 | return android.OptionalPath{} |
| 179 | } |
| 180 | } |
| 181 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 182 | } |
| 183 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 184 | func (mod *Module) OnlyInRamdisk() bool { |
| 185 | return false |
| 186 | } |
| 187 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 188 | func (mod *Module) OnlyInRecovery() bool { |
| 189 | return false |
| 190 | } |
| 191 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 192 | func (mod *Module) UseSdk() bool { |
| 193 | return false |
| 194 | } |
| 195 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 196 | func (mod *Module) UseVndk() bool { |
| 197 | return false |
| 198 | } |
| 199 | |
| 200 | func (mod *Module) MustUseVendorVariant() bool { |
| 201 | return false |
| 202 | } |
| 203 | |
| 204 | func (mod *Module) IsVndk() bool { |
| 205 | return false |
| 206 | } |
| 207 | |
| 208 | func (mod *Module) HasVendorVariant() bool { |
| 209 | return false |
| 210 | } |
| 211 | |
| 212 | func (mod *Module) SdkVersion() string { |
| 213 | return "" |
| 214 | } |
| 215 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 216 | func (mod *Module) AlwaysSdk() bool { |
| 217 | return false |
| 218 | } |
| 219 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 220 | func (mod *Module) IsSdkVariant() bool { |
| 221 | return false |
| 222 | } |
| 223 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 224 | func (mod *Module) ToolchainLibrary() bool { |
| 225 | return false |
| 226 | } |
| 227 | |
| 228 | func (mod *Module) NdkPrebuiltStl() bool { |
| 229 | return false |
| 230 | } |
| 231 | |
| 232 | func (mod *Module) StubDecorator() bool { |
| 233 | return false |
| 234 | } |
| 235 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 236 | type Deps struct { |
| 237 | Dylibs []string |
| 238 | Rlibs []string |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 239 | Rustlibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 240 | ProcMacros []string |
| 241 | SharedLibs []string |
| 242 | StaticLibs []string |
| 243 | |
| 244 | CrtBegin, CrtEnd string |
| 245 | } |
| 246 | |
| 247 | type PathDeps struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 248 | DyLibs RustLibraries |
| 249 | RLibs RustLibraries |
| 250 | SharedLibs android.Paths |
| 251 | StaticLibs android.Paths |
| 252 | ProcMacros RustLibraries |
| 253 | linkDirs []string |
| 254 | depFlags []string |
| 255 | linkObjects []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 256 | //ReexportedDeps android.Paths |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 257 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 258 | // Used by bindgen modules which call clang |
| 259 | depClangFlags []string |
| 260 | depIncludePaths android.Paths |
| 261 | depSystemIncludePaths android.Paths |
| 262 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 263 | coverageFiles android.Paths |
| 264 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 265 | CrtBegin android.OptionalPath |
| 266 | CrtEnd android.OptionalPath |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 267 | |
| 268 | // Paths to generated source files |
| 269 | SrcDeps android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | type RustLibraries []RustLibrary |
| 273 | |
| 274 | type RustLibrary struct { |
| 275 | Path android.Path |
| 276 | CrateName string |
| 277 | } |
| 278 | |
| 279 | type compiler interface { |
| 280 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 281 | compilerProps() []interface{} |
| 282 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path |
| 283 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 284 | crateName() string |
| 285 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 286 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 287 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 288 | relativeInstallPath() string |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 289 | |
| 290 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 291 | |
| 292 | Disabled() bool |
| 293 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 294 | |
| 295 | static() bool |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 296 | } |
| 297 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 298 | type exportedFlagsProducer interface { |
| 299 | exportedLinkDirs() []string |
| 300 | exportedDepFlags() []string |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 301 | exportedLinkObjects() []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 302 | exportLinkDirs(...string) |
| 303 | exportDepFlags(...string) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 304 | exportLinkObjects(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | type flagExporter struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 308 | depFlags []string |
| 309 | linkDirs []string |
| 310 | linkObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | func (flagExporter *flagExporter) exportedLinkDirs() []string { |
| 314 | return flagExporter.linkDirs |
| 315 | } |
| 316 | |
| 317 | func (flagExporter *flagExporter) exportedDepFlags() []string { |
| 318 | return flagExporter.depFlags |
| 319 | } |
| 320 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 321 | func (flagExporter *flagExporter) exportedLinkObjects() []string { |
| 322 | return flagExporter.linkObjects |
| 323 | } |
| 324 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 325 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 326 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
| 327 | } |
| 328 | |
| 329 | func (flagExporter *flagExporter) exportDepFlags(flags ...string) { |
| 330 | flagExporter.depFlags = android.FirstUniqueStrings(append(flagExporter.depFlags, flags...)) |
| 331 | } |
| 332 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 333 | func (flagExporter *flagExporter) exportLinkObjects(flags ...string) { |
| 334 | flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...)) |
| 335 | } |
| 336 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 337 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 338 | |
| 339 | func NewFlagExporter() *flagExporter { |
| 340 | return &flagExporter{ |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 341 | depFlags: []string{}, |
| 342 | linkDirs: []string{}, |
| 343 | linkObjects: []string{}, |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 347 | func (mod *Module) isCoverageVariant() bool { |
| 348 | return mod.coverage.Properties.IsCoverageVariant |
| 349 | } |
| 350 | |
| 351 | var _ cc.Coverage = (*Module)(nil) |
| 352 | |
| 353 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 354 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 355 | } |
| 356 | |
| 357 | func (mod *Module) PreventInstall() { |
| 358 | mod.Properties.PreventInstall = true |
| 359 | } |
| 360 | |
| 361 | func (mod *Module) HideFromMake() { |
| 362 | mod.Properties.HideFromMake = true |
| 363 | } |
| 364 | |
| 365 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 366 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 367 | } |
| 368 | |
| 369 | func (mod *Module) EnableCoverageIfNeeded() { |
| 370 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | func defaultsFactory() android.Module { |
| 374 | return DefaultsFactory() |
| 375 | } |
| 376 | |
| 377 | type Defaults struct { |
| 378 | android.ModuleBase |
| 379 | android.DefaultsModuleBase |
| 380 | } |
| 381 | |
| 382 | func DefaultsFactory(props ...interface{}) android.Module { |
| 383 | module := &Defaults{} |
| 384 | |
| 385 | module.AddProperties(props...) |
| 386 | module.AddProperties( |
| 387 | &BaseProperties{}, |
| 388 | &BaseCompilerProperties{}, |
| 389 | &BinaryCompilerProperties{}, |
| 390 | &LibraryCompilerProperties{}, |
| 391 | &ProcMacroCompilerProperties{}, |
| 392 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 393 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 394 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 395 | &cc.CoverageProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 396 | &ClippyProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 397 | ) |
| 398 | |
| 399 | android.InitDefaultsModule(module) |
| 400 | return module |
| 401 | } |
| 402 | |
| 403 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 404 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 407 | func (mod *Module) CcLibrary() bool { |
| 408 | if mod.compiler != nil { |
| 409 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 410 | return true |
| 411 | } |
| 412 | } |
| 413 | return false |
| 414 | } |
| 415 | |
| 416 | func (mod *Module) CcLibraryInterface() bool { |
| 417 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 418 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 419 | // VariantIs{Static,Shared} is set. |
| 420 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 421 | return true |
| 422 | } |
| 423 | } |
| 424 | return false |
| 425 | } |
| 426 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 427 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 428 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 429 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 430 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 434 | } |
| 435 | |
| 436 | func (mod *Module) SetStatic() { |
| 437 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 438 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 439 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 440 | return |
| 441 | } |
| 442 | } |
| 443 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 444 | } |
| 445 | |
| 446 | func (mod *Module) SetShared() { |
| 447 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 448 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 449 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 450 | return |
| 451 | } |
| 452 | } |
| 453 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 454 | } |
| 455 | |
| 456 | func (mod *Module) SetBuildStubs() { |
| 457 | panic("SetBuildStubs not yet implemented for rust modules") |
| 458 | } |
| 459 | |
| 460 | func (mod *Module) SetStubsVersions(string) { |
| 461 | panic("SetStubsVersions not yet implemented for rust modules") |
| 462 | } |
| 463 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 464 | func (mod *Module) StubsVersion() string { |
| 465 | panic("SetStubsVersions not yet implemented for rust modules") |
| 466 | } |
| 467 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 468 | func (mod *Module) BuildStaticVariant() bool { |
| 469 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 470 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 471 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 475 | } |
| 476 | |
| 477 | func (mod *Module) BuildSharedVariant() bool { |
| 478 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 479 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 480 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 484 | } |
| 485 | |
| 486 | // Rust module deps don't have a link order (?) |
| 487 | func (mod *Module) SetDepsInLinkOrder([]android.Path) {} |
| 488 | |
| 489 | func (mod *Module) GetDepsInLinkOrder() []android.Path { |
| 490 | return []android.Path{} |
| 491 | } |
| 492 | |
| 493 | func (mod *Module) GetStaticVariant() cc.LinkableInterface { |
| 494 | return nil |
| 495 | } |
| 496 | |
| 497 | func (mod *Module) Module() android.Module { |
| 498 | return mod |
| 499 | } |
| 500 | |
| 501 | func (mod *Module) StubsVersions() []string { |
| 502 | // For now, Rust has no stubs versions. |
| 503 | if mod.compiler != nil { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 504 | if _, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 505 | return []string{} |
| 506 | } |
| 507 | } |
| 508 | panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName())) |
| 509 | } |
| 510 | |
| 511 | func (mod *Module) OutputFile() android.OptionalPath { |
| 512 | return mod.outputFile |
| 513 | } |
| 514 | |
| 515 | func (mod *Module) InRecovery() bool { |
| 516 | // For now, Rust has no notion of the recovery image |
| 517 | return false |
| 518 | } |
| 519 | func (mod *Module) HasStaticVariant() bool { |
| 520 | if mod.GetStaticVariant() != nil { |
| 521 | return true |
| 522 | } |
| 523 | return false |
| 524 | } |
| 525 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 526 | func (mod *Module) CoverageFiles() android.Paths { |
| 527 | if mod.compiler != nil { |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 528 | if !mod.compiler.nativeCoverage() { |
| 529 | return android.Paths{} |
| 530 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 531 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
| 532 | if library.coverageFile != nil { |
| 533 | return android.Paths{library.coverageFile} |
| 534 | } |
| 535 | return android.Paths{} |
| 536 | } |
| 537 | } |
| 538 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 539 | } |
| 540 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 541 | var _ cc.LinkableInterface = (*Module)(nil) |
| 542 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 543 | func (mod *Module) Init() android.Module { |
| 544 | mod.AddProperties(&mod.Properties) |
| 545 | |
| 546 | if mod.compiler != nil { |
| 547 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 548 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 549 | if mod.coverage != nil { |
| 550 | mod.AddProperties(mod.coverage.props()...) |
| 551 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 552 | if mod.clippy != nil { |
| 553 | mod.AddProperties(mod.clippy.props()...) |
| 554 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 555 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 556 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 557 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 558 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 559 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
| 560 | |
| 561 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 562 | return mod |
| 563 | } |
| 564 | |
| 565 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 566 | return &Module{ |
| 567 | hod: hod, |
| 568 | multilib: multilib, |
| 569 | } |
| 570 | } |
| 571 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 572 | module := newBaseModule(hod, multilib) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 573 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 574 | module.clippy = &clippy{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 575 | return module |
| 576 | } |
| 577 | |
| 578 | type ModuleContext interface { |
| 579 | android.ModuleContext |
| 580 | ModuleContextIntf |
| 581 | } |
| 582 | |
| 583 | type BaseModuleContext interface { |
| 584 | android.BaseModuleContext |
| 585 | ModuleContextIntf |
| 586 | } |
| 587 | |
| 588 | type DepsContext interface { |
| 589 | android.BottomUpMutatorContext |
| 590 | ModuleContextIntf |
| 591 | } |
| 592 | |
| 593 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 594 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 595 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | type depsContext struct { |
| 599 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | type moduleContext struct { |
| 603 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 606 | type baseModuleContext struct { |
| 607 | android.BaseModuleContext |
| 608 | } |
| 609 | |
| 610 | func (ctx *moduleContext) RustModule() *Module { |
| 611 | return ctx.Module().(*Module) |
| 612 | } |
| 613 | |
| 614 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 615 | return ctx.RustModule().toolchain(ctx) |
| 616 | } |
| 617 | |
| 618 | func (ctx *depsContext) RustModule() *Module { |
| 619 | return ctx.Module().(*Module) |
| 620 | } |
| 621 | |
| 622 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 623 | return ctx.RustModule().toolchain(ctx) |
| 624 | } |
| 625 | |
| 626 | func (ctx *baseModuleContext) RustModule() *Module { |
| 627 | return ctx.Module().(*Module) |
| 628 | } |
| 629 | |
| 630 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 631 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | func (mod *Module) nativeCoverage() bool { |
| 635 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 636 | } |
| 637 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 638 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 639 | if mod.cachedToolchain == nil { |
| 640 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 641 | } |
| 642 | return mod.cachedToolchain |
| 643 | } |
| 644 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 645 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 646 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 647 | } |
| 648 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 649 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 650 | } |
| 651 | |
| 652 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 653 | ctx := &moduleContext{ |
| 654 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 655 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 656 | |
| 657 | toolchain := mod.toolchain(ctx) |
| 658 | |
| 659 | if !toolchain.Supported() { |
| 660 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 661 | return |
| 662 | } |
| 663 | |
| 664 | deps := mod.depsToPaths(ctx) |
| 665 | flags := Flags{ |
| 666 | Toolchain: toolchain, |
| 667 | } |
| 668 | |
| 669 | if mod.compiler != nil { |
| 670 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 671 | } |
| 672 | if mod.coverage != nil { |
| 673 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 674 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 675 | if mod.clippy != nil { |
| 676 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 677 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 678 | |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 679 | // SourceProvider needs to call GenerateSource() before compiler calls compile() so it can provide the source. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 680 | // TODO(b/162588681) This shouldn't have to run for every variant. |
| 681 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 682 | generatedFile := mod.sourceProvider.GenerateSource(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 683 | mod.generatedFile = android.OptionalPathForPath(generatedFile) |
| 684 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 685 | } |
| 686 | |
| 687 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 688 | outputFile := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 689 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 690 | mod.outputFile = android.OptionalPathForPath(outputFile) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 691 | if mod.outputFile.Valid() && !mod.Properties.PreventInstall { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 692 | mod.compiler.install(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 693 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 698 | deps := Deps{} |
| 699 | |
| 700 | if mod.compiler != nil { |
| 701 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 702 | } |
| 703 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 704 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 707 | if mod.coverage != nil { |
| 708 | deps = mod.coverage.deps(ctx, deps) |
| 709 | } |
| 710 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 711 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 712 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 713 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 714 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 715 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 716 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 717 | |
| 718 | return deps |
| 719 | |
| 720 | } |
| 721 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 722 | type dependencyTag struct { |
| 723 | blueprint.BaseDependencyTag |
| 724 | name string |
| 725 | library bool |
| 726 | proc_macro bool |
| 727 | } |
| 728 | |
| 729 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 730 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 731 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
| 732 | dylibDepTag = dependencyTag{name: "dylib", library: true} |
| 733 | procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true} |
| 734 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 735 | ) |
| 736 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 737 | type autoDep struct { |
| 738 | variation string |
| 739 | depTag dependencyTag |
| 740 | } |
| 741 | |
| 742 | var ( |
| 743 | rlibAutoDep = autoDep{variation: "rlib", depTag: rlibDepTag} |
| 744 | dylibAutoDep = autoDep{variation: "dylib", depTag: dylibDepTag} |
| 745 | ) |
| 746 | |
| 747 | type autoDeppable interface { |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 748 | autoDep(ctx BaseModuleContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 751 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 752 | if mod.coverage != nil { |
| 753 | mod.coverage.begin(ctx) |
| 754 | } |
| 755 | } |
| 756 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 757 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 758 | var depPaths PathDeps |
| 759 | |
| 760 | directRlibDeps := []*Module{} |
| 761 | directDylibDeps := []*Module{} |
| 762 | directProcMacroDeps := []*Module{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 763 | directSharedLibDeps := [](cc.LinkableInterface){} |
| 764 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 765 | directSrcProvidersDeps := []*Module{} |
| 766 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 767 | |
| 768 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 769 | depName := ctx.OtherModuleName(dep) |
| 770 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 771 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 772 | //Handle Rust Modules |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 773 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 774 | switch depTag { |
| 775 | case dylibDepTag: |
| 776 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 777 | if !ok || !dylib.dylib() { |
| 778 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 779 | return |
| 780 | } |
| 781 | directDylibDeps = append(directDylibDeps, rustDep) |
| 782 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName) |
| 783 | case rlibDepTag: |
| 784 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 785 | if !ok || !rlib.rlib() { |
| 786 | ctx.ModuleErrorf("mod %q not an rlib library", depName) |
| 787 | return |
| 788 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 789 | depPaths.coverageFiles = append(depPaths.coverageFiles, rustDep.CoverageFiles()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 790 | directRlibDeps = append(directRlibDeps, rustDep) |
| 791 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName) |
| 792 | case procMacroDepTag: |
| 793 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
| 794 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 795 | case android.SourceDepTag: |
| 796 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 797 | // OS/Arch variant is used. |
| 798 | var helper string |
| 799 | if ctx.Host() { |
| 800 | helper = "missing 'host_supported'?" |
| 801 | } else { |
| 802 | helper = "device module defined?" |
| 803 | } |
| 804 | |
| 805 | if dep.Target().Os != ctx.Os() { |
| 806 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 807 | return |
| 808 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 809 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 810 | return |
| 811 | } |
| 812 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 815 | //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS |
| 816 | if lib, ok := rustDep.compiler.(exportedFlagsProducer); ok && depTag != procMacroDepTag { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 817 | depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedLinkDirs()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 818 | depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 819 | depPaths.linkObjects = append(depPaths.linkObjects, lib.exportedLinkObjects()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 822 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 823 | linkFile := rustDep.outputFile |
| 824 | if !linkFile.Valid() { |
| 825 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", |
| 826 | depName, ctx.ModuleName()) |
| 827 | return |
| 828 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 829 | linkDir := linkPathFromFilePath(linkFile.Path()) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 830 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
| 831 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 835 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 836 | //Handle C dependencies |
| 837 | if _, ok := ccDep.(*Module); !ok { |
| 838 | if ccDep.Module().Target().Os != ctx.Os() { |
| 839 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 840 | return |
| 841 | } |
| 842 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 843 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 844 | return |
| 845 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 846 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 847 | linkObject := ccDep.OutputFile() |
| 848 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 849 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 850 | if !linkObject.Valid() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 851 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 852 | } |
| 853 | |
| 854 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 855 | switch { |
| 856 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 857 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 858 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 859 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...) |
| 860 | if mod, ok := ccDep.(*cc.Module); ok { |
| 861 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...) |
| 862 | depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...) |
| 863 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 864 | depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 865 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
| 866 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 867 | case cc.IsSharedDepTag(depTag): |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 868 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 869 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 870 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...) |
| 871 | if mod, ok := ccDep.(*cc.Module); ok { |
| 872 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...) |
| 873 | depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...) |
| 874 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 875 | directSharedLibDeps = append(directSharedLibDeps, ccDep) |
| 876 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) |
| 877 | exportDep = true |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 878 | case depTag == cc.CrtBeginDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 879 | depPaths.CrtBegin = linkObject |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 880 | case depTag == cc.CrtEndDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 881 | depPaths.CrtEnd = linkObject |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 885 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 886 | lib.exportLinkDirs(linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 887 | lib.exportLinkObjects(linkObject.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 888 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 889 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 890 | |
| 891 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
| 892 | switch depTag { |
| 893 | case android.SourceDepTag: |
| 894 | // These are usually genrules which don't have per-target variants. |
| 895 | directSrcDeps = append(directSrcDeps, srcDep) |
| 896 | } |
| 897 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 898 | }) |
| 899 | |
| 900 | var rlibDepFiles RustLibraries |
| 901 | for _, dep := range directRlibDeps { |
| 902 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 903 | } |
| 904 | var dylibDepFiles RustLibraries |
| 905 | for _, dep := range directDylibDeps { |
| 906 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 907 | } |
| 908 | var procMacroDepFiles RustLibraries |
| 909 | for _, dep := range directProcMacroDeps { |
| 910 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 911 | } |
| 912 | |
| 913 | var staticLibDepFiles android.Paths |
| 914 | for _, dep := range directStaticLibDeps { |
| 915 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
| 916 | } |
| 917 | |
| 918 | var sharedLibDepFiles android.Paths |
| 919 | for _, dep := range directSharedLibDeps { |
| 920 | sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) |
| 921 | } |
| 922 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 923 | var srcProviderDepFiles android.Paths |
| 924 | for _, dep := range directSrcProvidersDeps { |
| 925 | srcs, _ := dep.OutputFiles("") |
| 926 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 927 | } |
| 928 | for _, dep := range directSrcDeps { |
| 929 | srcs := dep.Srcs() |
| 930 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 931 | } |
| 932 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 933 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 934 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
| 935 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) |
| 936 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
| 937 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 938 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 939 | |
| 940 | // Dedup exported flags from dependencies |
| 941 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
| 942 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 943 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 944 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 945 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 946 | |
| 947 | return depPaths |
| 948 | } |
| 949 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 950 | func (mod *Module) InstallInData() bool { |
| 951 | if mod.compiler == nil { |
| 952 | return false |
| 953 | } |
| 954 | return mod.compiler.inData() |
| 955 | } |
| 956 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 957 | func linkPathFromFilePath(filepath android.Path) string { |
| 958 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 959 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 960 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 961 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 962 | ctx := &depsContext{ |
| 963 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 964 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 965 | |
| 966 | deps := mod.deps(ctx) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 967 | commonDepVariations := []blueprint.Variation{} |
Jooyung Han | 624d35c | 2020-04-10 12:57:24 +0900 | [diff] [blame] | 968 | if cc.VersionVariantAvailable(mod) { |
| 969 | commonDepVariations = append(commonDepVariations, |
| 970 | blueprint.Variation{Mutator: "version", Variation: ""}) |
| 971 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 972 | if !mod.Host() { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 973 | commonDepVariations = append(commonDepVariations, |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 974 | blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 975 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 976 | actx.AddVariationDependencies( |
| 977 | append(commonDepVariations, []blueprint.Variation{ |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 978 | {Mutator: "rust_libraries", Variation: "rlib"}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 979 | rlibDepTag, deps.Rlibs...) |
| 980 | actx.AddVariationDependencies( |
| 981 | append(commonDepVariations, []blueprint.Variation{ |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 982 | {Mutator: "rust_libraries", Variation: "dylib"}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 983 | dylibDepTag, deps.Dylibs...) |
| 984 | |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 985 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 986 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 987 | actx.AddVariationDependencies( |
| 988 | append(commonDepVariations, []blueprint.Variation{ |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 989 | {Mutator: "rust_libraries", Variation: autoDep.variation}}...), |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 990 | autoDep.depTag, deps.Rustlibs...) |
| 991 | } |
| 992 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 993 | actx.AddVariationDependencies(append(commonDepVariations, |
| 994 | blueprint.Variation{Mutator: "link", Variation: "shared"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 995 | cc.SharedDepTag(), deps.SharedLibs...) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 996 | actx.AddVariationDependencies(append(commonDepVariations, |
| 997 | blueprint.Variation{Mutator: "link", Variation: "static"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 998 | cc.StaticDepTag(), deps.StaticLibs...) |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 999 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1000 | crtVariations := append(cc.GetCrtVariations(ctx, mod), commonDepVariations...) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1001 | if deps.CrtBegin != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1002 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1003 | } |
| 1004 | if deps.CrtEnd != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1005 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1008 | if mod.sourceProvider != nil { |
| 1009 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1010 | bindgen.Properties.Custom_bindgen != "" { |
| 1011 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1012 | bindgen.Properties.Custom_bindgen) |
| 1013 | } |
| 1014 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1015 | // 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] | 1016 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1019 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1020 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1021 | mod.beginMutator(ctx) |
| 1022 | } |
| 1023 | } |
| 1024 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1025 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1026 | ctx := &baseModuleContext{ |
| 1027 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1028 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1029 | |
| 1030 | mod.begin(ctx) |
| 1031 | } |
| 1032 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1033 | func (mod *Module) Name() string { |
| 1034 | name := mod.ModuleBase.Name() |
| 1035 | if p, ok := mod.compiler.(interface { |
| 1036 | Name(string) string |
| 1037 | }); ok { |
| 1038 | name = p.Name(name) |
| 1039 | } |
| 1040 | return name |
| 1041 | } |
| 1042 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1043 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1044 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1045 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1049 | var _ android.HostToolProvider = (*Module)(nil) |
| 1050 | |
| 1051 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1052 | if !mod.Host() { |
| 1053 | return android.OptionalPath{} |
| 1054 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1055 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1056 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1057 | } |
| 1058 | return android.OptionalPath{} |
| 1059 | } |
| 1060 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1061 | var Bool = proptools.Bool |
| 1062 | var BoolDefault = proptools.BoolDefault |
| 1063 | var String = proptools.String |
| 1064 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1065 | |
| 1066 | var _ android.OutputFileProducer = (*Module)(nil) |