blob: 960f66a41c99ae42f53bb4ec80c47a7ee0c7a8c7 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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
15package rust
16
17import (
Ivan Lozano183a3212019-10-18 14:18:45 -070018 "fmt"
Ivan Lozanoffee3342019-08-27 12:03:00 -070019 "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
29var pctx = android.NewPackageContext("android/soong/rust")
30
31func init() {
32 // Only allow rust modules to be defined for certain projects
Ivan Lozanoffee3342019-08-27 12:03:00 -070033
34 android.AddNeverAllowRules(
35 android.NeverAllow().
Ivan Lozanoe169ad72019-09-18 08:42:54 -070036 NotIn(config.RustAllowedPaths...).
37 ModuleType(config.RustModuleTypes...))
Ivan Lozanoffee3342019-08-27 12:03:00 -070038
39 android.RegisterModuleType("rust_defaults", defaultsFactory)
40 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
41 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040042 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozanoffee3342019-08-27 12:03:00 -070043 })
44 pctx.Import("android/soong/rust/config")
Ivan Lozano4fef93c2020-07-08 08:39:44 -040045 pctx.ImportAs("ccConfig", "android/soong/cc/config")
Ivan Lozanoffee3342019-08-27 12:03:00 -070046}
47
48type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040049 GlobalRustFlags []string // Flags that apply globally to rust
50 GlobalLinkFlags []string // Flags that apply globally to linker
51 RustFlags []string // Flags that apply to rust
52 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020053 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Ivan Lozanof1c84332019-09-20 11:00:37 -070054 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040055 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020056 Clippy bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070057}
58
59type BaseProperties struct {
60 AndroidMkRlibs []string
61 AndroidMkDylibs []string
62 AndroidMkProcMacroLibs []string
63 AndroidMkSharedLibs []string
64 AndroidMkStaticLibs []string
Ivan Lozano43845682020-07-09 21:03:28 -040065
66 SubName string `blueprint:"mutated"`
67 PreventInstall bool
68 HideFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070069}
70
71type Module struct {
72 android.ModuleBase
73 android.DefaultableModuleBase
74
75 Properties BaseProperties
76
77 hod android.HostOrDeviceSupported
78 multilib android.Multilib
79
80 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040081 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020082 clippy *clippy
Ivan Lozanoffee3342019-08-27 12:03:00 -070083 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -040084 sourceProvider SourceProvider
Ivan Lozanoffee3342019-08-27 12:03:00 -070085 subAndroidMkOnce map[subAndroidMkProvider]bool
86 outputFile android.OptionalPath
Ivan Lozano4fef93c2020-07-08 08:39:44 -040087
88 subName string
Ivan Lozanoffee3342019-08-27 12:03:00 -070089}
90
Ivan Lozano43845682020-07-09 21:03:28 -040091func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
92 switch tag {
93 case "":
94 if mod.sourceProvider != nil {
95 return mod.sourceProvider.Srcs(), nil
96 } else {
97 if mod.outputFile.Valid() {
98 return android.Paths{mod.outputFile.Path()}, nil
99 }
100 return android.Paths{}, nil
101 }
102 default:
103 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
104 }
105}
106
Colin Cross7228ecd2019-11-18 16:00:16 -0800107var _ android.ImageInterface = (*Module)(nil)
108
109func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {}
110
111func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
112 return true
113}
114
Yifan Hong1b3348d2020-01-21 15:53:22 -0800115func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool {
116 return mod.InRamdisk()
117}
118
Colin Cross7228ecd2019-11-18 16:00:16 -0800119func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool {
120 return mod.InRecovery()
121}
122
123func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
124 return nil
125}
126
127func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
128}
129
Ivan Lozano52767be2019-10-18 14:49:46 -0700130func (mod *Module) BuildStubs() bool {
131 return false
132}
133
134func (mod *Module) HasStubsVariants() bool {
135 return false
136}
137
138func (mod *Module) SelectedStl() string {
139 return ""
140}
141
Ivan Lozano2b262972019-11-21 12:30:50 -0800142func (mod *Module) NonCcVariants() bool {
143 if mod.compiler != nil {
144 if library, ok := mod.compiler.(libraryInterface); ok {
145 if library.buildRlib() || library.buildDylib() {
146 return true
147 } else {
148 return false
149 }
150 }
151 }
152 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
153}
154
Ivan Lozano52767be2019-10-18 14:49:46 -0700155func (mod *Module) ApiLevel() string {
156 panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName()))
157}
158
159func (mod *Module) Static() bool {
160 if mod.compiler != nil {
161 if library, ok := mod.compiler.(libraryInterface); ok {
162 return library.static()
163 }
164 }
165 panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName()))
166}
167
168func (mod *Module) Shared() bool {
169 if mod.compiler != nil {
170 if library, ok := mod.compiler.(libraryInterface); ok {
171 return library.static()
172 }
173 }
174 panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName()))
175}
176
177func (mod *Module) Toc() android.OptionalPath {
178 if mod.compiler != nil {
179 if _, ok := mod.compiler.(libraryInterface); ok {
180 return android.OptionalPath{}
181 }
182 }
183 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
184}
185
Yifan Hong1b3348d2020-01-21 15:53:22 -0800186func (mod *Module) OnlyInRamdisk() bool {
187 return false
188}
189
Ivan Lozano52767be2019-10-18 14:49:46 -0700190func (mod *Module) OnlyInRecovery() bool {
191 return false
192}
193
Colin Crossc511bc52020-04-07 16:50:32 +0000194func (mod *Module) UseSdk() bool {
195 return false
196}
197
Ivan Lozano52767be2019-10-18 14:49:46 -0700198func (mod *Module) UseVndk() bool {
199 return false
200}
201
202func (mod *Module) MustUseVendorVariant() bool {
203 return false
204}
205
206func (mod *Module) IsVndk() bool {
207 return false
208}
209
210func (mod *Module) HasVendorVariant() bool {
211 return false
212}
213
214func (mod *Module) SdkVersion() string {
215 return ""
216}
217
Colin Crossc511bc52020-04-07 16:50:32 +0000218func (mod *Module) AlwaysSdk() bool {
219 return false
220}
221
Jiyong Park2286afd2020-06-16 21:58:53 +0900222func (mod *Module) IsSdkVariant() bool {
223 return false
224}
225
Ivan Lozano52767be2019-10-18 14:49:46 -0700226func (mod *Module) ToolchainLibrary() bool {
227 return false
228}
229
230func (mod *Module) NdkPrebuiltStl() bool {
231 return false
232}
233
234func (mod *Module) StubDecorator() bool {
235 return false
236}
237
Ivan Lozanoffee3342019-08-27 12:03:00 -0700238type Deps struct {
239 Dylibs []string
240 Rlibs []string
Matthew Maurer0f003b12020-06-29 14:34:06 -0700241 Rustlibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700242 ProcMacros []string
243 SharedLibs []string
244 StaticLibs []string
245
246 CrtBegin, CrtEnd string
247}
248
249type PathDeps struct {
250 DyLibs RustLibraries
251 RLibs RustLibraries
252 SharedLibs android.Paths
253 StaticLibs android.Paths
254 ProcMacros RustLibraries
255 linkDirs []string
256 depFlags []string
257 //ReexportedDeps android.Paths
Ivan Lozanof1c84332019-09-20 11:00:37 -0700258
Ivan Lozano45901ed2020-07-24 16:05:01 -0400259 // Used by bindgen modules which call clang
260 depClangFlags []string
261 depIncludePaths android.Paths
262 depSystemIncludePaths android.Paths
263
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400264 coverageFiles android.Paths
265
Ivan Lozanof1c84332019-09-20 11:00:37 -0700266 CrtBegin android.OptionalPath
267 CrtEnd android.OptionalPath
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700268
269 // Paths to generated source files
270 SrcDeps android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700271}
272
273type RustLibraries []RustLibrary
274
275type RustLibrary struct {
276 Path android.Path
277 CrateName string
278}
279
280type compiler interface {
281 compilerFlags(ctx ModuleContext, flags Flags) Flags
282 compilerProps() []interface{}
283 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
284 compilerDeps(ctx DepsContext, deps Deps) Deps
285 crateName() string
286
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800287 inData() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700288 install(ctx ModuleContext, path android.Path)
289 relativeInstallPath() string
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400290
291 nativeCoverage() bool
292}
293
Matthew Maurerbb3add12020-06-25 09:34:12 -0700294type exportedFlagsProducer interface {
295 exportedLinkDirs() []string
296 exportedDepFlags() []string
297 exportLinkDirs(...string)
298 exportDepFlags(...string)
299}
300
301type flagExporter struct {
302 depFlags []string
303 linkDirs []string
304}
305
306func (flagExporter *flagExporter) exportedLinkDirs() []string {
307 return flagExporter.linkDirs
308}
309
310func (flagExporter *flagExporter) exportedDepFlags() []string {
311 return flagExporter.depFlags
312}
313
314func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
315 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
316}
317
318func (flagExporter *flagExporter) exportDepFlags(flags ...string) {
319 flagExporter.depFlags = android.FirstUniqueStrings(append(flagExporter.depFlags, flags...))
320}
321
322var _ exportedFlagsProducer = (*flagExporter)(nil)
323
324func NewFlagExporter() *flagExporter {
325 return &flagExporter{
326 depFlags: []string{},
327 linkDirs: []string{},
328 }
329}
330
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400331func (mod *Module) isCoverageVariant() bool {
332 return mod.coverage.Properties.IsCoverageVariant
333}
334
335var _ cc.Coverage = (*Module)(nil)
336
337func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
338 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
339}
340
341func (mod *Module) PreventInstall() {
342 mod.Properties.PreventInstall = true
343}
344
345func (mod *Module) HideFromMake() {
346 mod.Properties.HideFromMake = true
347}
348
349func (mod *Module) MarkAsCoverageVariant(coverage bool) {
350 mod.coverage.Properties.IsCoverageVariant = coverage
351}
352
353func (mod *Module) EnableCoverageIfNeeded() {
354 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700355}
356
357func defaultsFactory() android.Module {
358 return DefaultsFactory()
359}
360
361type Defaults struct {
362 android.ModuleBase
363 android.DefaultsModuleBase
364}
365
366func DefaultsFactory(props ...interface{}) android.Module {
367 module := &Defaults{}
368
369 module.AddProperties(props...)
370 module.AddProperties(
371 &BaseProperties{},
372 &BaseCompilerProperties{},
373 &BinaryCompilerProperties{},
374 &LibraryCompilerProperties{},
375 &ProcMacroCompilerProperties{},
376 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400377 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700378 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400379 &cc.CoverageProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200380 &ClippyProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700381 )
382
383 android.InitDefaultsModule(module)
384 return module
385}
386
387func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700388 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700389}
390
Ivan Lozano183a3212019-10-18 14:18:45 -0700391func (mod *Module) CcLibrary() bool {
392 if mod.compiler != nil {
393 if _, ok := mod.compiler.(*libraryDecorator); ok {
394 return true
395 }
396 }
397 return false
398}
399
400func (mod *Module) CcLibraryInterface() bool {
401 if mod.compiler != nil {
402 if _, ok := mod.compiler.(libraryInterface); ok {
403 return true
404 }
405 }
406 return false
407}
408
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800409func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700410 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700411 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800412 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700413 }
414 }
415 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
416}
417
418func (mod *Module) SetStatic() {
419 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700420 if library, ok := mod.compiler.(libraryInterface); ok {
421 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700422 return
423 }
424 }
425 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
426}
427
428func (mod *Module) SetShared() {
429 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700430 if library, ok := mod.compiler.(libraryInterface); ok {
431 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700432 return
433 }
434 }
435 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
436}
437
438func (mod *Module) SetBuildStubs() {
439 panic("SetBuildStubs not yet implemented for rust modules")
440}
441
442func (mod *Module) SetStubsVersions(string) {
443 panic("SetStubsVersions not yet implemented for rust modules")
444}
445
Jooyung Han03b51852020-02-26 22:45:42 +0900446func (mod *Module) StubsVersion() string {
447 panic("SetStubsVersions not yet implemented for rust modules")
448}
449
Ivan Lozano183a3212019-10-18 14:18:45 -0700450func (mod *Module) BuildStaticVariant() bool {
451 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700452 if library, ok := mod.compiler.(libraryInterface); ok {
453 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700454 }
455 }
456 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
457}
458
459func (mod *Module) BuildSharedVariant() bool {
460 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700461 if library, ok := mod.compiler.(libraryInterface); ok {
462 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700463 }
464 }
465 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
466}
467
468// Rust module deps don't have a link order (?)
469func (mod *Module) SetDepsInLinkOrder([]android.Path) {}
470
471func (mod *Module) GetDepsInLinkOrder() []android.Path {
472 return []android.Path{}
473}
474
475func (mod *Module) GetStaticVariant() cc.LinkableInterface {
476 return nil
477}
478
479func (mod *Module) Module() android.Module {
480 return mod
481}
482
483func (mod *Module) StubsVersions() []string {
484 // For now, Rust has no stubs versions.
485 if mod.compiler != nil {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700486 if _, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700487 return []string{}
488 }
489 }
490 panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName()))
491}
492
493func (mod *Module) OutputFile() android.OptionalPath {
494 return mod.outputFile
495}
496
497func (mod *Module) InRecovery() bool {
498 // For now, Rust has no notion of the recovery image
499 return false
500}
501func (mod *Module) HasStaticVariant() bool {
502 if mod.GetStaticVariant() != nil {
503 return true
504 }
505 return false
506}
507
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400508func (mod *Module) CoverageFiles() android.Paths {
509 if mod.compiler != nil {
Matthew Maurerc761eec2020-06-25 00:47:46 -0700510 if !mod.compiler.nativeCoverage() {
511 return android.Paths{}
512 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400513 if library, ok := mod.compiler.(*libraryDecorator); ok {
514 if library.coverageFile != nil {
515 return android.Paths{library.coverageFile}
516 }
517 return android.Paths{}
518 }
519 }
520 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
521}
522
Ivan Lozano183a3212019-10-18 14:18:45 -0700523var _ cc.LinkableInterface = (*Module)(nil)
524
Ivan Lozanoffee3342019-08-27 12:03:00 -0700525func (mod *Module) Init() android.Module {
526 mod.AddProperties(&mod.Properties)
527
528 if mod.compiler != nil {
529 mod.AddProperties(mod.compiler.compilerProps()...)
530 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400531 if mod.coverage != nil {
532 mod.AddProperties(mod.coverage.props()...)
533 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200534 if mod.clippy != nil {
535 mod.AddProperties(mod.clippy.props()...)
536 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400537 if mod.sourceProvider != nil {
538 mod.AddProperties(mod.sourceProvider.sourceProviderProps()...)
539 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400540
Ivan Lozanoffee3342019-08-27 12:03:00 -0700541 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
542
543 android.InitDefaultableModule(mod)
544
Ivan Lozanode252912019-09-06 15:29:52 -0700545 // Explicitly disable unsupported targets.
546 android.AddLoadHook(mod, func(ctx android.LoadHookContext) {
547 disableTargets := struct {
548 Target struct {
Ivan Lozanode252912019-09-06 15:29:52 -0700549 Linux_bionic struct {
550 Enabled *bool
551 }
552 }
553 }{}
Ivan Lozanode252912019-09-06 15:29:52 -0700554 disableTargets.Target.Linux_bionic.Enabled = proptools.BoolPtr(false)
555
556 ctx.AppendProperties(&disableTargets)
557 })
558
Ivan Lozanoffee3342019-08-27 12:03:00 -0700559 return mod
560}
561
562func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
563 return &Module{
564 hod: hod,
565 multilib: multilib,
566 }
567}
568func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
569 module := newBaseModule(hod, multilib)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400570 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200571 module.clippy = &clippy{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700572 return module
573}
574
575type ModuleContext interface {
576 android.ModuleContext
577 ModuleContextIntf
578}
579
580type BaseModuleContext interface {
581 android.BaseModuleContext
582 ModuleContextIntf
583}
584
585type DepsContext interface {
586 android.BottomUpMutatorContext
587 ModuleContextIntf
588}
589
590type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200591 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700592 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700593}
594
595type depsContext struct {
596 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700597}
598
599type moduleContext struct {
600 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700601}
602
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200603type baseModuleContext struct {
604 android.BaseModuleContext
605}
606
607func (ctx *moduleContext) RustModule() *Module {
608 return ctx.Module().(*Module)
609}
610
611func (ctx *moduleContext) toolchain() config.Toolchain {
612 return ctx.RustModule().toolchain(ctx)
613}
614
615func (ctx *depsContext) RustModule() *Module {
616 return ctx.Module().(*Module)
617}
618
619func (ctx *depsContext) toolchain() config.Toolchain {
620 return ctx.RustModule().toolchain(ctx)
621}
622
623func (ctx *baseModuleContext) RustModule() *Module {
624 return ctx.Module().(*Module)
625}
626
627func (ctx *baseModuleContext) toolchain() config.Toolchain {
628 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400629}
630
631func (mod *Module) nativeCoverage() bool {
632 return mod.compiler != nil && mod.compiler.nativeCoverage()
633}
634
Ivan Lozanoffee3342019-08-27 12:03:00 -0700635func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
636 if mod.cachedToolchain == nil {
637 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
638 }
639 return mod.cachedToolchain
640}
641
642func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
643}
644
645func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
646 ctx := &moduleContext{
647 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700648 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700649
650 toolchain := mod.toolchain(ctx)
651
652 if !toolchain.Supported() {
653 // This toolchain's unsupported, there's nothing to do for this mod.
654 return
655 }
656
657 deps := mod.depsToPaths(ctx)
658 flags := Flags{
659 Toolchain: toolchain,
660 }
661
662 if mod.compiler != nil {
663 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400664 }
665 if mod.coverage != nil {
666 flags, deps = mod.coverage.flags(ctx, flags, deps)
667 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200668 if mod.clippy != nil {
669 flags, deps = mod.clippy.flags(ctx, flags, deps)
670 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400671
672 if mod.compiler != nil {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700673 outputFile := mod.compiler.compile(ctx, flags, deps)
674 mod.outputFile = android.OptionalPathForPath(outputFile)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400675 if !mod.Properties.PreventInstall {
676 mod.compiler.install(ctx, mod.outputFile.Path())
677 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400678 } else if mod.sourceProvider != nil {
Ivan Lozano45901ed2020-07-24 16:05:01 -0400679 outputFile := mod.sourceProvider.generateSource(ctx, deps)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400680 mod.outputFile = android.OptionalPathForPath(outputFile)
681 mod.subName = ctx.ModuleSubDir()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700682 }
683}
684
685func (mod *Module) deps(ctx DepsContext) Deps {
686 deps := Deps{}
687
688 if mod.compiler != nil {
689 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400690 } else if mod.sourceProvider != nil {
691 deps = mod.sourceProvider.sourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700692 }
693
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400694 if mod.coverage != nil {
695 deps = mod.coverage.deps(ctx, deps)
696 }
697
Ivan Lozanoffee3342019-08-27 12:03:00 -0700698 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
699 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700700 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700701 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
702 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
703 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
704
705 return deps
706
707}
708
Ivan Lozanoffee3342019-08-27 12:03:00 -0700709type dependencyTag struct {
710 blueprint.BaseDependencyTag
711 name string
712 library bool
713 proc_macro bool
714}
715
716var (
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -0700717 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
718 dylibDepTag = dependencyTag{name: "dylib", library: true}
719 procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
720 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700721)
722
Matthew Maurer0f003b12020-06-29 14:34:06 -0700723type autoDep struct {
724 variation string
725 depTag dependencyTag
726}
727
728var (
729 rlibAutoDep = autoDep{variation: "rlib", depTag: rlibDepTag}
730 dylibAutoDep = autoDep{variation: "dylib", depTag: dylibDepTag}
731)
732
733type autoDeppable interface {
734 autoDep() autoDep
735}
736
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400737func (mod *Module) begin(ctx BaseModuleContext) {
738 if mod.coverage != nil {
739 mod.coverage.begin(ctx)
740 }
741}
742
Ivan Lozanoffee3342019-08-27 12:03:00 -0700743func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
744 var depPaths PathDeps
745
746 directRlibDeps := []*Module{}
747 directDylibDeps := []*Module{}
748 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700749 directSharedLibDeps := [](cc.LinkableInterface){}
750 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400751 directSrcProvidersDeps := []*Module{}
752 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700753
754 ctx.VisitDirectDeps(func(dep android.Module) {
755 depName := ctx.OtherModuleName(dep)
756 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700757 if rustDep, ok := dep.(*Module); ok {
758 //Handle Rust Modules
Ivan Lozano70e0a072019-09-13 14:23:15 -0700759
Ivan Lozanoffee3342019-08-27 12:03:00 -0700760 linkFile := rustDep.outputFile
761 if !linkFile.Valid() {
762 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
763 }
764
765 switch depTag {
766 case dylibDepTag:
767 dylib, ok := rustDep.compiler.(libraryInterface)
768 if !ok || !dylib.dylib() {
769 ctx.ModuleErrorf("mod %q not an dylib library", depName)
770 return
771 }
772 directDylibDeps = append(directDylibDeps, rustDep)
773 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
774 case rlibDepTag:
775 rlib, ok := rustDep.compiler.(libraryInterface)
776 if !ok || !rlib.rlib() {
777 ctx.ModuleErrorf("mod %q not an rlib library", depName)
778 return
779 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400780 depPaths.coverageFiles = append(depPaths.coverageFiles, rustDep.CoverageFiles()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700781 directRlibDeps = append(directRlibDeps, rustDep)
782 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName)
783 case procMacroDepTag:
784 directProcMacroDeps = append(directProcMacroDeps, rustDep)
785 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400786 case android.SourceDepTag:
787 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
788 // OS/Arch variant is used.
789 var helper string
790 if ctx.Host() {
791 helper = "missing 'host_supported'?"
792 } else {
793 helper = "device module defined?"
794 }
795
796 if dep.Target().Os != ctx.Os() {
797 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
798 return
799 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
800 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
801 return
802 }
803 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700804 }
805
806 //Append the dependencies exportedDirs
Matthew Maurerbb3add12020-06-25 09:34:12 -0700807 if lib, ok := rustDep.compiler.(exportedFlagsProducer); ok {
808 depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedLinkDirs()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700809 depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700810 }
811
Ivan Lozanoffee3342019-08-27 12:03:00 -0700812 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
813 linkDir := linkPathFromFilePath(linkFile.Path())
Matthew Maurerbb3add12020-06-25 09:34:12 -0700814 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
815 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700816 }
817 }
818
Ivan Lozano52767be2019-10-18 14:49:46 -0700819 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700820
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400821 if srcDep, ok := dep.(android.SourceFileProducer); ok {
822 switch depTag {
823 case android.SourceDepTag:
824 // These are usually genrules which don't have per-target variants.
825 directSrcDeps = append(directSrcDeps, srcDep)
826 }
827 }
828
Ivan Lozano52767be2019-10-18 14:49:46 -0700829 if ccDep, ok := dep.(cc.LinkableInterface); ok {
830 //Handle C dependencies
831 if _, ok := ccDep.(*Module); !ok {
832 if ccDep.Module().Target().Os != ctx.Os() {
833 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
834 return
835 }
836 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
837 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
838 return
839 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700840 }
841
Ivan Lozanoffee3342019-08-27 12:03:00 -0700842 linkFile := ccDep.OutputFile()
843 linkPath := linkPathFromFilePath(linkFile.Path())
844 libName := libNameFromFilePath(linkFile.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -0500845 depFlag := "-l" + libName
846
Ivan Lozanoffee3342019-08-27 12:03:00 -0700847 if !linkFile.Valid() {
848 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
849 }
850
851 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -0700852 switch {
853 case cc.IsStaticDepTag(depTag):
Ivan Lozano6aa66022020-02-06 13:22:43 -0500854 depFlag = "-lstatic=" + libName
Ivan Lozanoffee3342019-08-27 12:03:00 -0700855 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano6aa66022020-02-06 13:22:43 -0500856 depPaths.depFlags = append(depPaths.depFlags, depFlag)
Ivan Lozano45901ed2020-07-24 16:05:01 -0400857 depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
858 if mod, ok := ccDep.(*cc.Module); ok {
859 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
860 depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
861 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400862 depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700863 directStaticLibDeps = append(directStaticLibDeps, ccDep)
864 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
Colin Cross6e511a92020-07-27 21:26:48 -0700865 case cc.IsSharedDepTag(depTag):
Ivan Lozano6aa66022020-02-06 13:22:43 -0500866 depFlag = "-ldylib=" + libName
Ivan Lozanoffee3342019-08-27 12:03:00 -0700867 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano6aa66022020-02-06 13:22:43 -0500868 depPaths.depFlags = append(depPaths.depFlags, depFlag)
Ivan Lozano45901ed2020-07-24 16:05:01 -0400869 depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
870 if mod, ok := ccDep.(*cc.Module); ok {
871 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
872 depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
873 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700874 directSharedLibDeps = append(directSharedLibDeps, ccDep)
875 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
876 exportDep = true
Colin Cross6e511a92020-07-27 21:26:48 -0700877 case depTag == cc.CrtBeginDepTag:
Ivan Lozanof1c84332019-09-20 11:00:37 -0700878 depPaths.CrtBegin = linkFile
Colin Cross6e511a92020-07-27 21:26:48 -0700879 case depTag == cc.CrtEndDepTag:
Ivan Lozanof1c84332019-09-20 11:00:37 -0700880 depPaths.CrtEnd = linkFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700881 }
882
883 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -0700884 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
885 lib.exportLinkDirs(linkPath)
886 lib.exportDepFlags(depFlag)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700887 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700888 }
889 })
890
891 var rlibDepFiles RustLibraries
892 for _, dep := range directRlibDeps {
893 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
894 }
895 var dylibDepFiles RustLibraries
896 for _, dep := range directDylibDeps {
897 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
898 }
899 var procMacroDepFiles RustLibraries
900 for _, dep := range directProcMacroDeps {
901 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
902 }
903
904 var staticLibDepFiles android.Paths
905 for _, dep := range directStaticLibDeps {
906 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
907 }
908
909 var sharedLibDepFiles android.Paths
910 for _, dep := range directSharedLibDeps {
911 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
912 }
913
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400914 var srcProviderDepFiles android.Paths
915 for _, dep := range directSrcProvidersDeps {
916 srcs, _ := dep.OutputFiles("")
917 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
918 }
919 for _, dep := range directSrcDeps {
920 srcs := dep.Srcs()
921 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
922 }
923
Ivan Lozanoffee3342019-08-27 12:03:00 -0700924 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
925 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
926 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
927 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
928 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400929 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700930
931 // Dedup exported flags from dependencies
932 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
933 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -0400934 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
935 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
936 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700937
938 return depPaths
939}
940
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800941func (mod *Module) InstallInData() bool {
942 if mod.compiler == nil {
943 return false
944 }
945 return mod.compiler.inData()
946}
947
Ivan Lozanoffee3342019-08-27 12:03:00 -0700948func linkPathFromFilePath(filepath android.Path) string {
949 return strings.Split(filepath.String(), filepath.Base())[0]
950}
Ivan Lozanod648c432020-02-06 12:05:10 -0500951
Ivan Lozanoffee3342019-08-27 12:03:00 -0700952func libNameFromFilePath(filepath android.Path) string {
Ivan Lozanod648c432020-02-06 12:05:10 -0500953 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
Ivan Lozano52767be2019-10-18 14:49:46 -0700954 if strings.HasPrefix(libName, "lib") {
955 libName = libName[3:]
Ivan Lozanoffee3342019-08-27 12:03:00 -0700956 }
957 return libName
958}
Ivan Lozanod648c432020-02-06 12:05:10 -0500959
Ivan Lozanoffee3342019-08-27 12:03:00 -0700960func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
961 ctx := &depsContext{
962 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700963 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700964
965 deps := mod.deps(ctx)
Ivan Lozano52767be2019-10-18 14:49:46 -0700966 commonDepVariations := []blueprint.Variation{}
Jooyung Han624d35c2020-04-10 12:57:24 +0900967 if cc.VersionVariantAvailable(mod) {
968 commonDepVariations = append(commonDepVariations,
969 blueprint.Variation{Mutator: "version", Variation: ""})
970 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700971 if !mod.Host() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700972 commonDepVariations = append(commonDepVariations,
Colin Cross7228ecd2019-11-18 16:00:16 -0800973 blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
Ivan Lozanoffee3342019-08-27 12:03:00 -0700974 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700975 actx.AddVariationDependencies(
976 append(commonDepVariations, []blueprint.Variation{
977 {Mutator: "rust_libraries", Variation: "rlib"},
978 {Mutator: "link", Variation: ""}}...),
979 rlibDepTag, deps.Rlibs...)
980 actx.AddVariationDependencies(
981 append(commonDepVariations, []blueprint.Variation{
982 {Mutator: "rust_libraries", Variation: "dylib"},
983 {Mutator: "link", Variation: ""}}...),
984 dylibDepTag, deps.Dylibs...)
985
Matthew Maurer0f003b12020-06-29 14:34:06 -0700986 if deps.Rustlibs != nil {
987 autoDep := mod.compiler.(autoDeppable).autoDep()
988 actx.AddVariationDependencies(
989 append(commonDepVariations, []blueprint.Variation{
990 {Mutator: "rust_libraries", Variation: autoDep.variation},
991 {Mutator: "link", Variation: ""}}...),
992 autoDep.depTag, deps.Rustlibs...)
993 }
994
Ivan Lozano52767be2019-10-18 14:49:46 -0700995 actx.AddVariationDependencies(append(commonDepVariations,
996 blueprint.Variation{Mutator: "link", Variation: "shared"}),
Colin Cross6e511a92020-07-27 21:26:48 -0700997 cc.SharedDepTag(), deps.SharedLibs...)
Ivan Lozano52767be2019-10-18 14:49:46 -0700998 actx.AddVariationDependencies(append(commonDepVariations,
999 blueprint.Variation{Mutator: "link", Variation: "static"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001000 cc.StaticDepTag(), deps.StaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001001
Ivan Lozanof1c84332019-09-20 11:00:37 -07001002 if deps.CrtBegin != "" {
Ivan Lozano52767be2019-10-18 14:49:46 -07001003 actx.AddVariationDependencies(commonDepVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001004 }
1005 if deps.CrtEnd != "" {
Ivan Lozano52767be2019-10-18 14:49:46 -07001006 actx.AddVariationDependencies(commonDepVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001007 }
1008
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001009 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001010 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001011}
1012
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001013func BeginMutator(ctx android.BottomUpMutatorContext) {
1014 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1015 mod.beginMutator(ctx)
1016 }
1017}
1018
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001019func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1020 ctx := &baseModuleContext{
1021 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001022 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001023
1024 mod.begin(ctx)
1025}
1026
Ivan Lozanoffee3342019-08-27 12:03:00 -07001027func (mod *Module) Name() string {
1028 name := mod.ModuleBase.Name()
1029 if p, ok := mod.compiler.(interface {
1030 Name(string) string
1031 }); ok {
1032 name = p.Name(name)
1033 }
1034 return name
1035}
1036
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001037var _ android.HostToolProvider = (*Module)(nil)
1038
1039func (mod *Module) HostToolPath() android.OptionalPath {
1040 if !mod.Host() {
1041 return android.OptionalPath{}
1042 }
1043 if _, ok := mod.compiler.(*binaryDecorator); ok {
1044 return mod.outputFile
1045 }
1046 return android.OptionalPath{}
1047}
1048
Ivan Lozanoffee3342019-08-27 12:03:00 -07001049var Bool = proptools.Bool
1050var BoolDefault = proptools.BoolDefault
1051var String = proptools.String
1052var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001053
1054var _ android.OutputFileProducer = (*Module)(nil)