blob: 2a2f5ad7042ed62eb12c3a0a185460a09f0af762 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000019 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080020 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "path/filepath"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080023 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
25 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
29var (
30 DeviceSharedLibrary = "shared_library"
31 DeviceStaticLibrary = "static_library"
32 DeviceExecutable = "executable"
33 HostSharedLibrary = "host_shared_library"
34 HostStaticLibrary = "host_static_library"
35 HostExecutable = "host_executable"
36)
37
Colin Crossae887032017-10-23 17:16:14 -070038type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080040 Deps blueprint.Deps
41 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070043 Output WritablePath
44 Outputs WritablePaths
45 ImplicitOutput WritablePath
46 ImplicitOutputs WritablePaths
47 Input Path
48 Inputs Paths
49 Implicit Path
50 Implicits Paths
51 OrderOnly Paths
52 Default bool
53 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054}
55
Colin Crossae887032017-10-23 17:16:14 -070056type ModuleBuildParams BuildParams
57
Colin Cross1184b642019-12-30 18:43:07 -080058// EarlyModuleContext provides methods that can be called early, as soon as the properties have
59// been parsed into the module and before any mutators have run.
60type EarlyModuleContext interface {
61 Module() Module
62 ModuleName() string
63 ModuleDir() string
64 ModuleType() string
Colin Cross9d34f352019-11-22 16:03:51 -080065 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080066
67 ContainsProperty(name string) bool
68 Errorf(pos scanner.Position, fmt string, args ...interface{})
69 ModuleErrorf(fmt string, args ...interface{})
70 PropertyErrorf(property, fmt string, args ...interface{})
71 Failed() bool
72
73 AddNinjaFileDeps(deps ...string)
74
75 DeviceSpecific() bool
76 SocSpecific() bool
77 ProductSpecific() bool
78 SystemExtSpecific() bool
79 Platform() bool
80
81 Config() Config
82 DeviceConfig() DeviceConfig
83
84 // Deprecated: use Config()
85 AConfig() Config
86
87 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
88 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
89 // builder whenever a file matching the pattern as added or removed, without rerunning if a
90 // file that does not match the pattern is added to a searched directory.
91 GlobWithDeps(pattern string, excludes []string) ([]string, error)
92
93 Glob(globPattern string, excludes []string) Paths
94 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +000095 IsSymlink(path Path) bool
96 Readlink(path Path) string
Colin Cross1184b642019-12-30 18:43:07 -080097}
98
Colin Cross0ea8ba82019-06-06 14:33:29 -070099// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700100// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
101// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700102// about the current module.
103type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800104 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700105
Colin Crossdc35e212019-06-06 16:13:11 -0700106 OtherModuleName(m blueprint.Module) string
107 OtherModuleDir(m blueprint.Module) string
108 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
109 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
110 OtherModuleExists(name string) bool
Jiyong Park9e6c2422019-08-09 20:39:45 +0900111 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700112
113 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
114 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
115 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
116
117 VisitDirectDepsBlueprint(visit func(blueprint.Module))
118 VisitDirectDeps(visit func(Module))
119 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
120 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
121 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
122 VisitDepsDepthFirst(visit func(Module))
123 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
124 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
125 WalkDeps(visit func(Module, Module) bool)
126 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
127 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
128 // and returns a top-down dependency path from a start module to current child module.
129 GetWalkPath() []Module
130
Colin Crossdc35e212019-06-06 16:13:11 -0700131 AddMissingDependencies(missingDeps []string)
132
Colin Crossa1ad8d12016-06-01 17:09:44 -0700133 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700134 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -0700135 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700136 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700137 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700138 Host() bool
139 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700140 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800141 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700142 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700143 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700144 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700145}
146
Colin Cross1184b642019-12-30 18:43:07 -0800147// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700148type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800149 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800150}
151
Colin Cross635c3b02016-05-18 15:37:25 -0700152type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800153 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800154
Colin Crossae887032017-10-23 17:16:14 -0700155 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800156 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700157
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700158 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800159 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800160 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700161
Colin Cross70dda7e2019-10-01 22:05:35 -0700162 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
163 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
164 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
165 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700166 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800167
Colin Cross8d8f8e22016-08-03 11:57:50 -0700168 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700169 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700170 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800171 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900172 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700173 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700174 InstallBypassMake() bool
Colin Cross6e359402020-02-10 15:29:54 -0800175 InstallForceOS() *OsType
Nan Zhang6d34b302017-02-04 17:47:46 -0800176
177 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700178 HostRequiredModuleNames() []string
179 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700180
Colin Cross3f68a132017-10-23 17:10:29 -0700181 ModuleSubDir() string
182
Colin Cross0875c522017-11-28 17:34:01 -0800183 Variable(pctx PackageContext, name, value string)
184 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700185 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
186 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800187 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700188
Colin Cross0875c522017-11-28 17:34:01 -0800189 PrimaryModule() Module
190 FinalModule() Module
191 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700192
193 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800194 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800195}
196
Colin Cross635c3b02016-05-18 15:37:25 -0700197type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800198 blueprint.Module
199
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700200 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
201 // but GenerateAndroidBuildActions also has access to Android-specific information.
202 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700203 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700204
Colin Cross1e676be2016-10-12 14:38:15 -0700205 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800206
Colin Cross635c3b02016-05-18 15:37:25 -0700207 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800208 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700209 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800210 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700211 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700212 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800213 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900214 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700215 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700216 InstallBypassMake() bool
Colin Cross6e359402020-02-10 15:29:54 -0800217 InstallForceOS() *OsType
Colin Crossa2f296f2016-11-29 15:16:18 -0800218 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900219 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900220 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700221
222 AddProperties(props ...interface{})
223 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700224
Colin Crossae887032017-10-23 17:16:14 -0700225 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800226 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800227 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100228
Colin Cross9a362232019-07-01 15:32:45 -0700229 // String returns a string that includes the module name and variants for printing during debugging.
230 String() string
231
Paul Duffine2453c72019-05-31 14:00:04 +0100232 // Get the qualified module id for this module.
233 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
234
235 // Get information about the properties that can contain visibility rules.
236 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100237
238 // Get the visibility rules that control the visibility of this module.
239 visibility() []string
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900240
241 RequiredModuleNames() []string
242 HostRequiredModuleNames() []string
243 TargetRequiredModuleNames() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100244}
245
246// Qualified id for a module
247type qualifiedModuleName struct {
248 // The package (i.e. directory) in which the module is defined, without trailing /
249 pkg string
250
251 // The name of the module, empty string if package.
252 name string
253}
254
255func (q qualifiedModuleName) String() string {
256 if q.name == "" {
257 return "//" + q.pkg
258 }
259 return "//" + q.pkg + ":" + q.name
260}
261
Paul Duffine484f472019-06-20 16:38:08 +0100262func (q qualifiedModuleName) isRootPackage() bool {
263 return q.pkg == "" && q.name == ""
264}
265
Paul Duffine2453c72019-05-31 14:00:04 +0100266// Get the id for the package containing this module.
267func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
268 pkg := q.pkg
269 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100270 if pkg == "" {
271 panic(fmt.Errorf("Cannot get containing package id of root package"))
272 }
273
274 index := strings.LastIndex(pkg, "/")
275 if index == -1 {
276 pkg = ""
277 } else {
278 pkg = pkg[:index]
279 }
Paul Duffine2453c72019-05-31 14:00:04 +0100280 }
281 return newPackageId(pkg)
282}
283
284func newPackageId(pkg string) qualifiedModuleName {
285 // A qualified id for a package module has no name.
286 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800287}
288
Colin Crossfc754582016-05-17 16:34:16 -0700289type nameProperties struct {
290 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800291 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700292}
293
294type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800295 // emit build rules for this module
296 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800297
Paul Duffin2e61fa62019-03-28 14:10:57 +0000298 // Controls the visibility of this module to other modules. Allowable values are one or more of
299 // these formats:
300 //
301 // ["//visibility:public"]: Anyone can use this module.
302 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
303 // this module.
304 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
305 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
306 // this module. Note that sub-packages do not have access to the rule; for example,
307 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
308 // is a special module and must be used verbatim. It represents all of the modules in the
309 // package.
310 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
311 // or other or in one of their sub-packages have access to this module. For example,
312 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
313 // to depend on this rule (but not //independent:evil)
314 // ["//project"]: This is shorthand for ["//project:__pkg__"]
315 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
316 // //project is the module's package. e.g. using [":__subpackages__"] in
317 // packages/apps/Settings/Android.bp is equivalent to
318 // //packages/apps/Settings:__subpackages__.
319 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
320 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100321 //
322 // If a module does not specify the `visibility` property then it uses the
323 // `default_visibility` property of the `package` module in the module's package.
324 //
325 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100326 // it will use the `default_visibility` of its closest ancestor package for which
327 // a `default_visibility` property is specified.
328 //
329 // If no `default_visibility` property can be found then the module uses the
330 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100331 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100332 // The `visibility` property has no effect on a defaults module although it does
333 // apply to any non-defaults module that uses it. To set the visibility of a
334 // defaults module, use the `defaults_visibility` property on the defaults module;
335 // not to be confused with the `default_visibility` property on the package module.
336 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000337 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
338 // more details.
339 Visibility []string
340
Colin Cross7d5136f2015-05-11 13:39:40 -0700341 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800342 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
343 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
344 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700345 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700346
347 Target struct {
348 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700349 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700350 }
351 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700352 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700353 }
354 }
355
Colin Crossee0bc3b2018-10-02 22:01:37 -0700356 UseTargetVariants bool `blueprint:"mutated"`
357 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800358
Dan Willemsen782a2d12015-12-21 14:55:28 -0800359 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700360 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800361
Colin Cross55708f32017-03-20 13:23:34 -0700362 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700363 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700364
Jiyong Park2db76922017-11-08 16:03:48 +0900365 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
366 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
367 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700368 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700369
Jiyong Park2db76922017-11-08 16:03:48 +0900370 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
371 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
372 Soc_specific *bool
373
374 // whether this module is specific to a device, not only for SoC, but also for off-chip
375 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
376 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
377 // This implies `soc_specific:true`.
378 Device_specific *bool
379
380 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900381 // network operator, etc). When set to true, it is installed into /product (or
382 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900383 Product_specific *bool
384
Justin Yund5f6c822019-06-25 16:47:17 +0900385 // whether this module extends system. When set to true, it is installed into /system_ext
386 // (or /system/system_ext if system_ext partition does not exist).
387 System_ext_specific *bool
388
Jiyong Parkf9332f12018-02-01 00:54:12 +0900389 // Whether this module is installed to recovery partition
390 Recovery *bool
391
Yifan Hong1b3348d2020-01-21 15:53:22 -0800392 // Whether this module is installed to ramdisk
393 Ramdisk *bool
394
dimitry1f33e402019-03-26 12:39:31 +0100395 // Whether this module is built for non-native architecures (also known as native bridge binary)
396 Native_bridge_supported *bool `android:"arch_variant"`
397
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700398 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800399 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700400
Steven Moreland57a23d22018-04-04 15:42:19 -0700401 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800402 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700403
Chris Wolfe998306e2016-08-15 14:47:23 -0400404 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700405 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400406
Sasha Smundakb6d23052019-04-01 18:37:36 -0700407 // names of other modules to install on host if this module is installed
408 Host_required []string `android:"arch_variant"`
409
410 // names of other modules to install on target if this module is installed
411 Target_required []string `android:"arch_variant"`
412
Colin Cross5aac3622017-08-31 15:07:09 -0700413 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800414 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700415
Dan Willemsen569edc52018-11-19 09:33:29 -0800416 Dist struct {
417 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
418 // command line and any of these targets are also on the command line, or otherwise
419 // built
420 Targets []string `android:"arch_variant"`
421
422 // The name of the output artifact. This defaults to the basename of the output of
423 // the module.
424 Dest *string `android:"arch_variant"`
425
426 // The directory within the dist directory to store the artifact. Defaults to the
427 // top level directory ("").
428 Dir *string `android:"arch_variant"`
429
430 // A suffix to add to the artifact file name (before any extension).
431 Suffix *string `android:"arch_variant"`
432 } `android:"arch_variant"`
433
Colin Crossa1ad8d12016-06-01 17:09:44 -0700434 // Set by TargetMutator
Colin Crossa195f912019-10-16 11:07:20 -0700435 CompileOS OsType `blueprint:"mutated"`
Colin Crossee0bc3b2018-10-02 22:01:37 -0700436 CompileTarget Target `blueprint:"mutated"`
437 CompileMultiTargets []Target `blueprint:"mutated"`
438 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800439
440 // Set by InitAndroidModule
441 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700442 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700443
444 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800445
446 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700447
448 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700449
450 // Name and variant strings stored by mutators to enable Module.String()
451 DebugName string `blueprint:"mutated"`
452 DebugMutators []string `blueprint:"mutated"`
453 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800454
455 // set by ImageMutator
456 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800457}
458
459type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800460 // If set to true, build a variant of the module for the host. Defaults to false.
461 Host_supported *bool
462
463 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700464 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800465}
466
Colin Crossc472d572015-03-17 15:06:21 -0700467type Multilib string
468
469const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800470 MultilibBoth Multilib = "both"
471 MultilibFirst Multilib = "first"
472 MultilibCommon Multilib = "common"
473 MultilibCommonFirst Multilib = "common_first"
474 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700475)
476
Colin Crossa1ad8d12016-06-01 17:09:44 -0700477type HostOrDeviceSupported int
478
479const (
480 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700481
482 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700483 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700484
485 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700486 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700487
488 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700489 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700490
491 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700492 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700493
494 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700495 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700496
497 // Nothing is supported. This is not exposed to the user, but used to mark a
498 // host only module as unsupported when the module type is not supported on
499 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700500 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700501)
502
Jiyong Park2db76922017-11-08 16:03:48 +0900503type moduleKind int
504
505const (
506 platformModule moduleKind = iota
507 deviceSpecificModule
508 socSpecificModule
509 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900510 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900511)
512
513func (k moduleKind) String() string {
514 switch k {
515 case platformModule:
516 return "platform"
517 case deviceSpecificModule:
518 return "device-specific"
519 case socSpecificModule:
520 return "soc-specific"
521 case productSpecificModule:
522 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900523 case systemExtSpecificModule:
524 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900525 default:
526 panic(fmt.Errorf("unknown module kind %d", k))
527 }
528}
529
Colin Cross9d34f352019-11-22 16:03:51 -0800530func initAndroidModuleBase(m Module) {
531 m.base().module = m
532}
533
Colin Cross36242852017-06-23 15:06:31 -0700534func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800535 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800536 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700537
Colin Cross36242852017-06-23 15:06:31 -0700538 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700539 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700540 &base.commonProperties)
541
542 // Allow tests to override the default product variables
543 if base.variableProperties == nil {
544 base.variableProperties = zeroProductVariables
545 }
546
547 // Filter the product variables properties to the ones that exist on this module
548 base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
549 if base.variableProperties != nil {
550 m.AddProperties(base.variableProperties)
551 }
552
Colin Crossa3a97412019-03-18 12:24:29 -0700553 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700554 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100555
556 // The default_visibility property needs to be checked and parsed by the visibility module during
557 // its checking and parsing phases.
558 base.primaryVisibilityProperty =
559 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
560 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700561}
562
Colin Cross36242852017-06-23 15:06:31 -0700563func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
564 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700565
566 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800567 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700568 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700569 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700570 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800571
Dan Willemsen218f6562015-07-08 18:13:11 -0700572 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700573 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700574 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800575 }
576
Colin Cross36242852017-06-23 15:06:31 -0700577 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800578}
579
Colin Crossee0bc3b2018-10-02 22:01:37 -0700580func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
581 InitAndroidArchModule(m, hod, defaultMultilib)
582 m.base().commonProperties.UseTargetVariants = false
583}
584
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800585// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800586// modules. It should be included as an anonymous field in every module
587// struct definition. InitAndroidModule should then be called from the module's
588// factory function, and the return values from InitAndroidModule should be
589// returned from the factory function.
590//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800591// The ModuleBase type is responsible for implementing the GenerateBuildActions
592// method to support the blueprint.Module interface. This method will then call
593// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700594// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
595// rather than the usual blueprint.ModuleContext.
596// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800597// system including details about the particular build variant that is to be
598// generated.
599//
600// For example:
601//
602// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800603// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800604// )
605//
606// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800607// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800608// properties struct {
609// MyProperty string
610// }
611// }
612//
Colin Cross36242852017-06-23 15:06:31 -0700613// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800614// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700615// m.AddProperties(&m.properties)
616// android.InitAndroidModule(m)
617// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800618// }
619//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800620// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800621// // Get the CPU architecture for the current build variant.
622// variantArch := ctx.Arch()
623//
624// // ...
625// }
Colin Cross635c3b02016-05-18 15:37:25 -0700626type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800627 // Putting the curiously recurring thing pointing to the thing that contains
628 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700629 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700630 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800631
Colin Crossfc754582016-05-17 16:34:16 -0700632 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800633 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700634 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800635 hostAndDeviceProperties hostAndDeviceProperties
636 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700637 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700638 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800639
Paul Duffin63c6e182019-07-24 14:24:38 +0100640 // Information about all the properties on the module that contains visibility rules that need
641 // checking.
642 visibilityPropertyInfo []visibilityProperty
643
644 // The primary visibility property, may be nil, that controls access to the module.
645 primaryVisibilityProperty visibilityProperty
646
Colin Cross3f40fa42015-01-30 17:27:36 -0800647 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700648 installFiles Paths
649 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900650 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700651
652 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
653 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800654 installTarget WritablePath
655 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700656 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700657
Colin Cross178a5092016-09-13 13:42:32 -0700658 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700659
660 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700661
662 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700663 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800664 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800665 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700666
667 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700668}
669
Colin Cross4157e882019-06-06 16:57:04 -0700670func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800671
Colin Cross4157e882019-06-06 16:57:04 -0700672func (m *ModuleBase) AddProperties(props ...interface{}) {
673 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700674}
675
Colin Cross4157e882019-06-06 16:57:04 -0700676func (m *ModuleBase) GetProperties() []interface{} {
677 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800678}
679
Colin Cross4157e882019-06-06 16:57:04 -0700680func (m *ModuleBase) BuildParamsForTests() []BuildParams {
681 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700682}
683
Colin Cross4157e882019-06-06 16:57:04 -0700684func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
685 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800686}
687
Colin Cross4157e882019-06-06 16:57:04 -0700688func (m *ModuleBase) VariablesForTests() map[string]string {
689 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800690}
691
Colin Cross4157e882019-06-06 16:57:04 -0700692func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
693 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700694}
695
Colin Crossce75d2c2016-10-06 16:12:58 -0700696// Name returns the name of the module. It may be overridden by individual module types, for
697// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700698func (m *ModuleBase) Name() string {
699 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700700}
701
Colin Cross9a362232019-07-01 15:32:45 -0700702// String returns a string that includes the module name and variants for printing during debugging.
703func (m *ModuleBase) String() string {
704 sb := strings.Builder{}
705 sb.WriteString(m.commonProperties.DebugName)
706 sb.WriteString("{")
707 for i := range m.commonProperties.DebugMutators {
708 if i != 0 {
709 sb.WriteString(",")
710 }
711 sb.WriteString(m.commonProperties.DebugMutators[i])
712 sb.WriteString(":")
713 sb.WriteString(m.commonProperties.DebugVariations[i])
714 }
715 sb.WriteString("}")
716 return sb.String()
717}
718
Colin Crossce75d2c2016-10-06 16:12:58 -0700719// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700720func (m *ModuleBase) BaseModuleName() string {
721 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700722}
723
Colin Cross4157e882019-06-06 16:57:04 -0700724func (m *ModuleBase) base() *ModuleBase {
725 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800726}
727
Paul Duffine2453c72019-05-31 14:00:04 +0100728func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
729 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
730}
731
732func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100733 return m.visibilityPropertyInfo
734}
735
736func (m *ModuleBase) visibility() []string {
737 // The soong_namespace module does not initialize the primaryVisibilityProperty.
738 if m.primaryVisibilityProperty != nil {
739 return m.primaryVisibilityProperty.getStrings()
740 } else {
741 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100742 }
743}
744
Colin Cross4157e882019-06-06 16:57:04 -0700745func (m *ModuleBase) Target() Target {
746 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800747}
748
Colin Cross4157e882019-06-06 16:57:04 -0700749func (m *ModuleBase) TargetPrimary() bool {
750 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700751}
752
Colin Cross4157e882019-06-06 16:57:04 -0700753func (m *ModuleBase) MultiTargets() []Target {
754 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700755}
756
Colin Cross4157e882019-06-06 16:57:04 -0700757func (m *ModuleBase) Os() OsType {
758 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800759}
760
Colin Cross4157e882019-06-06 16:57:04 -0700761func (m *ModuleBase) Host() bool {
762 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800763}
764
Colin Cross4157e882019-06-06 16:57:04 -0700765func (m *ModuleBase) Arch() Arch {
766 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800767}
768
Colin Cross4157e882019-06-06 16:57:04 -0700769func (m *ModuleBase) ArchSpecific() bool {
770 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700771}
772
Colin Cross4157e882019-06-06 16:57:04 -0700773func (m *ModuleBase) OsClassSupported() []OsClass {
774 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700775 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700776 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700777 case HostSupportedNoCross:
778 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700779 case DeviceSupported:
780 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700781 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700782 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700783 if Bool(m.hostAndDeviceProperties.Host_supported) ||
784 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
785 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700786 supported = append(supported, Host, HostCross)
787 }
Colin Cross4157e882019-06-06 16:57:04 -0700788 if m.hostAndDeviceProperties.Device_supported == nil ||
789 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700790 supported = append(supported, Device)
791 }
792 return supported
793 default:
794 return nil
795 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800796}
797
Colin Cross4157e882019-06-06 16:57:04 -0700798func (m *ModuleBase) DeviceSupported() bool {
799 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
800 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
801 (m.hostAndDeviceProperties.Device_supported == nil ||
802 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800803}
804
Paul Duffine44358f2019-11-26 18:04:12 +0000805func (m *ModuleBase) HostSupported() bool {
806 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
807 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
808 (m.hostAndDeviceProperties.Host_supported != nil &&
809 *m.hostAndDeviceProperties.Host_supported)
810}
811
Colin Cross4157e882019-06-06 16:57:04 -0700812func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900813 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900814}
815
Colin Cross4157e882019-06-06 16:57:04 -0700816func (m *ModuleBase) DeviceSpecific() bool {
817 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900818}
819
Colin Cross4157e882019-06-06 16:57:04 -0700820func (m *ModuleBase) SocSpecific() bool {
821 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900822}
823
Colin Cross4157e882019-06-06 16:57:04 -0700824func (m *ModuleBase) ProductSpecific() bool {
825 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900826}
827
Justin Yund5f6c822019-06-25 16:47:17 +0900828func (m *ModuleBase) SystemExtSpecific() bool {
829 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100830}
831
Colin Cross4157e882019-06-06 16:57:04 -0700832func (m *ModuleBase) Enabled() bool {
833 if m.commonProperties.Enabled == nil {
834 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800835 }
Colin Cross4157e882019-06-06 16:57:04 -0700836 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800837}
838
Colin Cross4157e882019-06-06 16:57:04 -0700839func (m *ModuleBase) SkipInstall() {
840 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700841}
842
Colin Cross4157e882019-06-06 16:57:04 -0700843func (m *ModuleBase) ExportedToMake() bool {
844 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900845}
846
Colin Cross4157e882019-06-06 16:57:04 -0700847func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700848 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800849
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700850 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700851 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800852 ctx.VisitDepsDepthFirstIf(isFileInstaller,
853 func(m blueprint.Module) {
854 fileInstaller := m.(fileInstaller)
855 files := fileInstaller.filesToInstall()
856 result = append(result, files...)
857 })
858
859 return result
860}
861
Colin Cross4157e882019-06-06 16:57:04 -0700862func (m *ModuleBase) filesToInstall() Paths {
863 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800864}
865
Colin Cross4157e882019-06-06 16:57:04 -0700866func (m *ModuleBase) NoAddressSanitizer() bool {
867 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800868}
869
Colin Cross4157e882019-06-06 16:57:04 -0700870func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800871 return false
872}
873
Jaewoong Jung0949f312019-09-11 10:25:18 -0700874func (m *ModuleBase) InstallInTestcases() bool {
875 return false
876}
877
Colin Cross4157e882019-06-06 16:57:04 -0700878func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700879 return false
880}
881
Yifan Hong1b3348d2020-01-21 15:53:22 -0800882func (m *ModuleBase) InstallInRamdisk() bool {
883 return Bool(m.commonProperties.Ramdisk)
884}
885
Colin Cross4157e882019-06-06 16:57:04 -0700886func (m *ModuleBase) InstallInRecovery() bool {
887 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900888}
889
Colin Cross90ba5f42019-10-02 11:10:58 -0700890func (m *ModuleBase) InstallInRoot() bool {
891 return false
892}
893
Colin Cross607d8582019-07-29 16:44:46 -0700894func (m *ModuleBase) InstallBypassMake() bool {
895 return false
896}
897
Colin Cross6e359402020-02-10 15:29:54 -0800898func (m *ModuleBase) InstallForceOS() *OsType {
899 return nil
900}
901
Colin Cross4157e882019-06-06 16:57:04 -0700902func (m *ModuleBase) Owner() string {
903 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900904}
905
Colin Cross4157e882019-06-06 16:57:04 -0700906func (m *ModuleBase) NoticeFile() OptionalPath {
907 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900908}
909
Colin Cross7228ecd2019-11-18 16:00:16 -0800910func (m *ModuleBase) setImageVariation(variant string) {
911 m.commonProperties.ImageVariation = variant
912}
913
914func (m *ModuleBase) ImageVariation() blueprint.Variation {
915 return blueprint.Variation{
916 Mutator: "image",
917 Variation: m.base().commonProperties.ImageVariation,
918 }
919}
920
Yifan Hong1b3348d2020-01-21 15:53:22 -0800921func (m *ModuleBase) InRamdisk() bool {
922 return m.base().commonProperties.ImageVariation == RamdiskVariation
923}
924
Colin Cross7228ecd2019-11-18 16:00:16 -0800925func (m *ModuleBase) InRecovery() bool {
926 return m.base().commonProperties.ImageVariation == RecoveryVariation
927}
928
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900929func (m *ModuleBase) RequiredModuleNames() []string {
930 return m.base().commonProperties.Required
931}
932
933func (m *ModuleBase) HostRequiredModuleNames() []string {
934 return m.base().commonProperties.Host_required
935}
936
937func (m *ModuleBase) TargetRequiredModuleNames() []string {
938 return m.base().commonProperties.Target_required
939}
940
Colin Cross4157e882019-06-06 16:57:04 -0700941func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700942 allInstalledFiles := Paths{}
943 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800944 ctx.VisitAllModuleVariants(func(module Module) {
945 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700946 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
947 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800948 })
949
Colin Cross0875c522017-11-28 17:34:01 -0800950 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700951
Jeff Gaston088e29e2017-11-29 16:47:17 -0800952 namespacePrefix := ctx.Namespace().(*Namespace).id
953 if namespacePrefix != "" {
954 namespacePrefix = namespacePrefix + "-"
955 }
956
Colin Cross3f40fa42015-01-30 17:27:36 -0800957 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800958 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800959 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700960 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800961 Output: name,
962 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800963 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700964 })
965 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700966 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700967 }
968
969 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800970 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800971 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700972 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800973 Output: name,
974 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700975 })
976 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700977 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700978 }
979
980 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800981 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800982 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800983 suffix = "-soong"
984 }
985
Jeff Gaston088e29e2017-11-29 16:47:17 -0800986 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800987 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700988 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800989 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700990 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800991 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700992
Colin Cross4157e882019-06-06 16:57:04 -0700993 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800994 }
995}
996
Colin Crossc34d2322020-01-03 15:23:27 -0800997func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -0700998 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
999 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1000 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001001 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001002
Dario Frenifd05a742018-05-29 13:28:54 +01001003 msg := "conflicting value set here"
1004 if socSpecific && deviceSpecific {
1005 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001006 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001007 ctx.PropertyErrorf("vendor", msg)
1008 }
Colin Cross4157e882019-06-06 16:57:04 -07001009 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001010 ctx.PropertyErrorf("proprietary", msg)
1011 }
Colin Cross4157e882019-06-06 16:57:04 -07001012 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001013 ctx.PropertyErrorf("soc_specific", msg)
1014 }
1015 }
1016
Justin Yund5f6c822019-06-25 16:47:17 +09001017 if productSpecific && systemExtSpecific {
1018 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1019 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001020 }
1021
Justin Yund5f6c822019-06-25 16:47:17 +09001022 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001023 if productSpecific {
1024 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1025 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001026 ctx.PropertyErrorf("system_ext_specific", "a module cannot be specific to SoC or device and system_ext at the same time.")
Dario Frenifd05a742018-05-29 13:28:54 +01001027 }
1028 if deviceSpecific {
1029 ctx.PropertyErrorf("device_specific", msg)
1030 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001031 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001032 ctx.PropertyErrorf("vendor", msg)
1033 }
Colin Cross4157e882019-06-06 16:57:04 -07001034 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001035 ctx.PropertyErrorf("proprietary", msg)
1036 }
Colin Cross4157e882019-06-06 16:57:04 -07001037 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001038 ctx.PropertyErrorf("soc_specific", msg)
1039 }
1040 }
1041 }
1042
Jiyong Park2db76922017-11-08 16:03:48 +09001043 if productSpecific {
1044 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001045 } else if systemExtSpecific {
1046 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001047 } else if deviceSpecific {
1048 return deviceSpecificModule
1049 } else if socSpecific {
1050 return socSpecificModule
1051 } else {
1052 return platformModule
1053 }
1054}
1055
Colin Crossc34d2322020-01-03 15:23:27 -08001056func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001057 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001058 EarlyModuleContext: ctx,
1059 kind: determineModuleKind(m, ctx),
1060 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001061 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001062}
1063
Colin Cross1184b642019-12-30 18:43:07 -08001064func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1065 return baseModuleContext{
1066 bp: ctx,
1067 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1068 os: m.commonProperties.CompileOS,
1069 target: m.commonProperties.CompileTarget,
1070 targetPrimary: m.commonProperties.CompilePrimary,
1071 multiTargets: m.commonProperties.CompileMultiTargets,
1072 }
1073}
1074
Colin Cross4157e882019-06-06 16:57:04 -07001075func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001076 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001077 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001078 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001079 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1080 installDeps: m.computeInstallDeps(blueprintCtx),
1081 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001082 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001083 }
1084
Colin Cross6c4f21f2019-06-06 15:41:36 -07001085 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1086 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1087 // TODO: This will be removed once defaults modules handle missing dependency errors
1088 blueprintCtx.GetMissingDependencies()
1089
Colin Crossdc35e212019-06-06 16:13:11 -07001090 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
1091 // are enabled.
1092 ctx.baseModuleContext.strictVisitDeps = true
1093
Colin Cross4c83e5c2019-02-25 14:54:28 -08001094 if ctx.config.captureBuild {
1095 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1096 }
1097
Colin Cross67a5c132017-05-09 13:45:28 -07001098 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1099 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001100 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1101 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001102 }
Colin Cross0875c522017-11-28 17:34:01 -08001103 if !ctx.PrimaryArch() {
1104 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001105 }
1106
1107 ctx.Variable(pctx, "moduleDesc", desc)
1108
1109 s := ""
1110 if len(suffix) > 0 {
1111 s = " [" + strings.Join(suffix, " ") + "]"
1112 }
1113 ctx.Variable(pctx, "moduleDescSuffix", s)
1114
Dan Willemsen569edc52018-11-19 09:33:29 -08001115 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001116 if m.commonProperties.Dist.Dest != nil {
1117 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001118 if err != nil {
1119 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1120 }
1121 }
Colin Cross4157e882019-06-06 16:57:04 -07001122 if m.commonProperties.Dist.Dir != nil {
1123 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001124 if err != nil {
1125 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1126 }
1127 }
Colin Cross4157e882019-06-06 16:57:04 -07001128 if m.commonProperties.Dist.Suffix != nil {
1129 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001130 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1131 }
1132 }
1133
Colin Cross4157e882019-06-06 16:57:04 -07001134 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001135 // ensure all direct android.Module deps are enabled
1136 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1137 if _, ok := bm.(Module); ok {
1138 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1139 }
1140 })
1141
Colin Cross4157e882019-06-06 16:57:04 -07001142 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1143 if module := SrcIsModule(notice); module != "" {
1144 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001145 } else {
1146 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001147 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001148 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001149
1150 m.module.GenerateAndroidBuildActions(ctx)
1151 if ctx.Failed() {
1152 return
1153 }
1154
1155 m.installFiles = append(m.installFiles, ctx.installFiles...)
1156 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001157 } else if ctx.Config().AllowMissingDependencies() {
1158 // If the module is not enabled it will not create any build rules, nothing will call
1159 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1160 // and report them as an error even when AllowMissingDependencies = true. Call
1161 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1162 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001163 }
1164
Colin Cross4157e882019-06-06 16:57:04 -07001165 if m == ctx.FinalModule().(Module).base() {
1166 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001167 if ctx.Failed() {
1168 return
1169 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001170 }
Colin Crosscec81712017-07-13 14:43:27 -07001171
Colin Cross4157e882019-06-06 16:57:04 -07001172 m.buildParams = ctx.buildParams
1173 m.ruleParams = ctx.ruleParams
1174 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001175}
1176
Colin Cross1184b642019-12-30 18:43:07 -08001177type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001178 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001179
1180 kind moduleKind
1181 config Config
1182}
1183
1184func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1185 ret, err := e.GlobWithDeps(globPattern, excludes)
1186 if err != nil {
1187 e.ModuleErrorf("glob: %s", err.Error())
1188 }
1189 return pathsForModuleSrcFromFullPath(e, ret, true)
1190}
1191
1192func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1193 ret, err := e.GlobWithDeps(globPattern, excludes)
1194 if err != nil {
1195 e.ModuleErrorf("glob: %s", err.Error())
1196 }
1197 return pathsForModuleSrcFromFullPath(e, ret, false)
1198}
1199
Colin Cross988414c2020-01-11 01:11:46 +00001200func (b *earlyModuleContext) IsSymlink(path Path) bool {
1201 fileInfo, err := b.config.fs.Lstat(path.String())
1202 if err != nil {
1203 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1204 }
1205 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1206}
1207
1208func (b *earlyModuleContext) Readlink(path Path) string {
1209 dest, err := b.config.fs.Readlink(path.String())
1210 if err != nil {
1211 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1212 }
1213 return dest
1214}
1215
Colin Cross1184b642019-12-30 18:43:07 -08001216func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001217 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001218 return module
1219}
1220
1221func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001222 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001223}
1224
1225func (e *earlyModuleContext) AConfig() Config {
1226 return e.config
1227}
1228
1229func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1230 return DeviceConfig{e.config.deviceConfig}
1231}
1232
1233func (e *earlyModuleContext) Platform() bool {
1234 return e.kind == platformModule
1235}
1236
1237func (e *earlyModuleContext) DeviceSpecific() bool {
1238 return e.kind == deviceSpecificModule
1239}
1240
1241func (e *earlyModuleContext) SocSpecific() bool {
1242 return e.kind == socSpecificModule
1243}
1244
1245func (e *earlyModuleContext) ProductSpecific() bool {
1246 return e.kind == productSpecificModule
1247}
1248
1249func (e *earlyModuleContext) SystemExtSpecific() bool {
1250 return e.kind == systemExtSpecificModule
1251}
1252
1253type baseModuleContext struct {
1254 bp blueprint.BaseModuleContext
1255 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001256 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001257 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001258 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001259 targetPrimary bool
1260 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001261
1262 walkPath []Module
1263
1264 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001265}
1266
Colin Cross1184b642019-12-30 18:43:07 -08001267func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { return b.bp.OtherModuleName(m) }
1268func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
1269func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
1270 b.bp.OtherModuleErrorf(m, fmt, args)
1271}
1272func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1273 return b.bp.OtherModuleDependencyTag(m)
1274}
1275func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1276func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { return b.bp.OtherModuleType(m) }
1277
1278func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1279 return b.bp.GetDirectDepWithTag(name, tag)
1280}
1281
Colin Cross25de6c32019-06-06 14:29:25 -07001282type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001283 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001284 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001285 installDeps Paths
1286 installFiles Paths
1287 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001288 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001289
1290 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001291 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001292 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001293 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001294}
1295
Colin Crossb88b3c52019-06-10 15:15:17 -07001296func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1297 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001298 Rule: ErrorRule,
1299 Description: params.Description,
1300 Output: params.Output,
1301 Outputs: params.Outputs,
1302 ImplicitOutput: params.ImplicitOutput,
1303 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001304 Args: map[string]string{
1305 "error": err.Error(),
1306 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001307 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001308}
1309
Colin Cross25de6c32019-06-06 14:29:25 -07001310func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1311 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001312}
1313
Colin Cross0875c522017-11-28 17:34:01 -08001314func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001315 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001316 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001317 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001318 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001319 Outputs: params.Outputs.Strings(),
1320 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1321 Inputs: params.Inputs.Strings(),
1322 Implicits: params.Implicits.Strings(),
1323 OrderOnly: params.OrderOnly.Strings(),
1324 Args: params.Args,
1325 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001326 }
1327
Colin Cross33bfb0a2016-11-21 17:23:08 -08001328 if params.Depfile != nil {
1329 bparams.Depfile = params.Depfile.String()
1330 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001331 if params.Output != nil {
1332 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1333 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001334 if params.ImplicitOutput != nil {
1335 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1336 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001337 if params.Input != nil {
1338 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1339 }
1340 if params.Implicit != nil {
1341 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1342 }
1343
Colin Cross0b9f31f2019-02-28 11:00:01 -08001344 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1345 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1346 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1347 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1348 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1349 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001350
Colin Cross0875c522017-11-28 17:34:01 -08001351 return bparams
1352}
1353
Colin Cross25de6c32019-06-06 14:29:25 -07001354func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1355 if m.config.captureBuild {
1356 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001357 }
1358
Colin Crossdc35e212019-06-06 16:13:11 -07001359 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001360}
1361
Colin Cross25de6c32019-06-06 14:29:25 -07001362func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001363 argNames ...string) blueprint.Rule {
1364
Colin Cross8b8bec32019-11-15 13:18:43 -08001365 if m.config.UseRemoteBuild() && params.Pool == nil {
Ramy Medhatdd0418a2019-11-04 18:16:11 -05001366 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1367 // jobs to the local parallelism value
Colin Cross2e2dbc22019-09-25 13:31:46 -07001368 params.Pool = localPool
1369 }
1370
Colin Crossdc35e212019-06-06 16:13:11 -07001371 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001372
Colin Cross25de6c32019-06-06 14:29:25 -07001373 if m.config.captureBuild {
1374 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001375 }
1376
1377 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001378}
1379
Colin Cross25de6c32019-06-06 14:29:25 -07001380func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001381 if params.Description != "" {
1382 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1383 }
1384
1385 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1386 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1387 m.ModuleName(), strings.Join(missingDeps, ", ")))
1388 }
1389
Colin Cross25de6c32019-06-06 14:29:25 -07001390 if m.config.captureBuild {
1391 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001392 }
1393
Colin Crossdc35e212019-06-06 16:13:11 -07001394 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001395}
Colin Cross25de6c32019-06-06 14:29:25 -07001396func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001397 var missingDeps []string
1398 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001399 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001400 missingDeps = FirstUniqueStrings(missingDeps)
1401 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001402}
1403
Colin Crossdc35e212019-06-06 16:13:11 -07001404func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001405 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001406 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001407 *missingDeps = append(*missingDeps, deps...)
1408 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001409 }
1410}
1411
Colin Crossdc35e212019-06-06 16:13:11 -07001412func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001413 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001414
1415 if !strict {
1416 return aModule
1417 }
1418
Colin Cross380c69a2019-06-10 17:49:58 +00001419 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001420 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001421 return nil
1422 }
1423
1424 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001425 if b.Config().AllowMissingDependencies() {
1426 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001427 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001428 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001429 }
1430 return nil
1431 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001432 return aModule
1433}
1434
Colin Crossdc35e212019-06-06 16:13:11 -07001435func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001436 type dep struct {
1437 mod blueprint.Module
1438 tag blueprint.DependencyTag
1439 }
1440 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001441 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001442 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001443 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001444 if tag == nil || returnedTag == tag {
1445 deps = append(deps, dep{aModule, returnedTag})
1446 }
1447 }
1448 })
1449 if len(deps) == 1 {
1450 return deps[0].mod, deps[0].tag
1451 } else if len(deps) >= 2 {
1452 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001453 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001454 } else {
1455 return nil, nil
1456 }
1457}
1458
Colin Crossdc35e212019-06-06 16:13:11 -07001459func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001460 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001461 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001462 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001463 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001464 deps = append(deps, aModule)
1465 }
1466 }
1467 })
1468 return deps
1469}
1470
Colin Cross25de6c32019-06-06 14:29:25 -07001471func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1472 module, _ := m.getDirectDepInternal(name, tag)
1473 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001474}
1475
Colin Crossdc35e212019-06-06 16:13:11 -07001476func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1477 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001478}
1479
Colin Crossdc35e212019-06-06 16:13:11 -07001480func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001481 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001482}
1483
Colin Crossdc35e212019-06-06 16:13:11 -07001484func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001485 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001486 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001487 visit(aModule)
1488 }
1489 })
1490}
1491
Colin Crossdc35e212019-06-06 16:13:11 -07001492func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001493 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001494 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001495 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001496 visit(aModule)
1497 }
1498 }
1499 })
1500}
1501
Colin Crossdc35e212019-06-06 16:13:11 -07001502func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001503 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001504 // pred
1505 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001506 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001507 return pred(aModule)
1508 } else {
1509 return false
1510 }
1511 },
1512 // visit
1513 func(module blueprint.Module) {
1514 visit(module.(Module))
1515 })
1516}
1517
Colin Crossdc35e212019-06-06 16:13:11 -07001518func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001519 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001520 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001521 visit(aModule)
1522 }
1523 })
1524}
1525
Colin Crossdc35e212019-06-06 16:13:11 -07001526func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001527 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001528 // pred
1529 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001530 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001531 return pred(aModule)
1532 } else {
1533 return false
1534 }
1535 },
1536 // visit
1537 func(module blueprint.Module) {
1538 visit(module.(Module))
1539 })
1540}
1541
Colin Crossdc35e212019-06-06 16:13:11 -07001542func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001543 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001544}
1545
Colin Crossdc35e212019-06-06 16:13:11 -07001546func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1547 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001548 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001549 childAndroidModule, _ := child.(Module)
1550 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001551 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001552 // record walkPath before visit
1553 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1554 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1555 }
1556 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001557 return visit(childAndroidModule, parentAndroidModule)
1558 } else {
1559 return false
1560 }
1561 })
1562}
1563
Colin Crossdc35e212019-06-06 16:13:11 -07001564func (b *baseModuleContext) GetWalkPath() []Module {
1565 return b.walkPath
1566}
1567
Colin Cross25de6c32019-06-06 14:29:25 -07001568func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001569 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001570 visit(module.(Module))
1571 })
1572}
1573
Colin Cross25de6c32019-06-06 14:29:25 -07001574func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001575 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001576}
1577
Colin Cross25de6c32019-06-06 14:29:25 -07001578func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001579 return m.bp.FinalModule().(Module)
1580}
1581
1582func (m *moduleContext) ModuleSubDir() string {
1583 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001584}
1585
Colin Cross0ea8ba82019-06-06 14:33:29 -07001586func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001587 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001588}
1589
Colin Cross0ea8ba82019-06-06 14:33:29 -07001590func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001591 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001592}
1593
Colin Cross0ea8ba82019-06-06 14:33:29 -07001594func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001595 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001596}
1597
Colin Cross0ea8ba82019-06-06 14:33:29 -07001598func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001599 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001600}
1601
Colin Cross0ea8ba82019-06-06 14:33:29 -07001602func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001603 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001604}
1605
Colin Cross0ea8ba82019-06-06 14:33:29 -07001606func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001607 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001608}
1609
Colin Cross0ea8ba82019-06-06 14:33:29 -07001610func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001611 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001612}
1613
Colin Cross0ea8ba82019-06-06 14:33:29 -07001614func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001615 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001616}
1617
Colin Cross0ea8ba82019-06-06 14:33:29 -07001618func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001619 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001620}
1621
Colin Cross0ea8ba82019-06-06 14:33:29 -07001622func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001623 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001624}
1625
Colin Cross0ea8ba82019-06-06 14:33:29 -07001626func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001627 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001628}
1629
Colin Cross0ea8ba82019-06-06 14:33:29 -07001630func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001631 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001632 return true
1633 }
Colin Cross25de6c32019-06-06 14:29:25 -07001634 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001635}
1636
Jiyong Park5baac542018-08-28 09:55:37 +09001637// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001638// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001639func (m *ModuleBase) MakeAsPlatform() {
1640 m.commonProperties.Vendor = boolPtr(false)
1641 m.commonProperties.Proprietary = boolPtr(false)
1642 m.commonProperties.Soc_specific = boolPtr(false)
1643 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001644 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001645}
1646
Colin Cross4157e882019-06-06 16:57:04 -07001647func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1648 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001649}
1650
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001651func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001652 m.commonProperties.Vendor = boolPtr(false)
1653 m.commonProperties.Proprietary = boolPtr(false)
1654 m.commonProperties.Soc_specific = boolPtr(false)
1655 m.commonProperties.Product_specific = boolPtr(false)
1656 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001657}
1658
Jooyung Han344d5432019-08-23 11:17:39 +09001659// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1660func (m *ModuleBase) IsNativeBridgeSupported() bool {
1661 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1662}
1663
Colin Cross25de6c32019-06-06 14:29:25 -07001664func (m *moduleContext) InstallInData() bool {
1665 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001666}
1667
Jaewoong Jung0949f312019-09-11 10:25:18 -07001668func (m *moduleContext) InstallInTestcases() bool {
1669 return m.module.InstallInTestcases()
1670}
1671
Colin Cross25de6c32019-06-06 14:29:25 -07001672func (m *moduleContext) InstallInSanitizerDir() bool {
1673 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001674}
1675
Yifan Hong1b3348d2020-01-21 15:53:22 -08001676func (m *moduleContext) InstallInRamdisk() bool {
1677 return m.module.InstallInRamdisk()
1678}
1679
Colin Cross25de6c32019-06-06 14:29:25 -07001680func (m *moduleContext) InstallInRecovery() bool {
1681 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001682}
1683
Colin Cross90ba5f42019-10-02 11:10:58 -07001684func (m *moduleContext) InstallInRoot() bool {
1685 return m.module.InstallInRoot()
1686}
1687
Colin Cross607d8582019-07-29 16:44:46 -07001688func (m *moduleContext) InstallBypassMake() bool {
1689 return m.module.InstallBypassMake()
1690}
1691
Colin Cross6e359402020-02-10 15:29:54 -08001692func (m *moduleContext) InstallForceOS() *OsType {
1693 return m.module.InstallForceOS()
1694}
1695
Colin Cross70dda7e2019-10-01 22:05:35 -07001696func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001697 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001698 return true
1699 }
1700
Colin Cross3607f212018-05-07 15:28:05 -07001701 // We'll need a solution for choosing which of modules with the same name in different
1702 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1703 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001704 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001705 return true
1706 }
1707
Colin Cross25de6c32019-06-06 14:29:25 -07001708 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001709 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001710 return true
1711 }
1712
Colin Cross25de6c32019-06-06 14:29:25 -07001713 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001714 return true
1715 }
1716 }
1717
1718 return false
1719}
1720
Colin Cross70dda7e2019-10-01 22:05:35 -07001721func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1722 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001723 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001724}
1725
Colin Cross70dda7e2019-10-01 22:05:35 -07001726func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1727 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001728 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001729}
1730
Colin Cross70dda7e2019-10-01 22:05:35 -07001731func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1732 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001733
Colin Cross25de6c32019-06-06 14:29:25 -07001734 fullInstallPath := installPath.Join(m, name)
1735 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001736
Colin Cross25de6c32019-06-06 14:29:25 -07001737 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001738
Colin Cross25de6c32019-06-06 14:29:25 -07001739 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001740
Colin Cross89562dc2016-10-03 17:47:19 -07001741 var implicitDeps, orderOnlyDeps Paths
1742
Colin Cross25de6c32019-06-06 14:29:25 -07001743 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001744 // Installed host modules might be used during the build, depend directly on their
1745 // dependencies so their timestamp is updated whenever their dependency is updated
1746 implicitDeps = deps
1747 } else {
1748 orderOnlyDeps = deps
1749 }
1750
Colin Cross25de6c32019-06-06 14:29:25 -07001751 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001752 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001753 Description: "install " + fullInstallPath.Base(),
1754 Output: fullInstallPath,
1755 Input: srcPath,
1756 Implicits: implicitDeps,
1757 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001758 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001759 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001760
Colin Cross25de6c32019-06-06 14:29:25 -07001761 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001762 }
Colin Cross25de6c32019-06-06 14:29:25 -07001763 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001764 return fullInstallPath
1765}
1766
Colin Cross70dda7e2019-10-01 22:05:35 -07001767func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001768 fullInstallPath := installPath.Join(m, name)
1769 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001770
Colin Cross25de6c32019-06-06 14:29:25 -07001771 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001772
Alex Lightfb4353d2019-01-17 13:57:45 -08001773 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1774 if err != nil {
1775 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1776 }
Colin Cross25de6c32019-06-06 14:29:25 -07001777 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001778 Rule: Symlink,
1779 Description: "install symlink " + fullInstallPath.Base(),
1780 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08001781 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001782 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001783 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001784 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001785 },
1786 })
Colin Cross3854a602016-01-11 12:49:11 -08001787
Colin Cross25de6c32019-06-06 14:29:25 -07001788 m.installFiles = append(m.installFiles, fullInstallPath)
1789 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001790 }
Colin Cross3854a602016-01-11 12:49:11 -08001791 return fullInstallPath
1792}
1793
Jiyong Parkf1194352019-02-25 11:05:47 +09001794// installPath/name -> absPath where absPath might be a path that is available only at runtime
1795// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001796func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001797 fullInstallPath := installPath.Join(m, name)
1798 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001799
Colin Cross25de6c32019-06-06 14:29:25 -07001800 if !m.skipInstall(fullInstallPath) {
1801 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001802 Rule: Symlink,
1803 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1804 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001805 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001806 Args: map[string]string{
1807 "fromPath": absPath,
1808 },
1809 })
1810
Colin Cross25de6c32019-06-06 14:29:25 -07001811 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001812 }
1813 return fullInstallPath
1814}
1815
Colin Cross25de6c32019-06-06 14:29:25 -07001816func (m *moduleContext) CheckbuildFile(srcPath Path) {
1817 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001818}
1819
Colin Cross3f40fa42015-01-30 17:27:36 -08001820type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001821 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001822}
1823
1824func isFileInstaller(m blueprint.Module) bool {
1825 _, ok := m.(fileInstaller)
1826 return ok
1827}
1828
1829func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001830 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001831 return ok
1832}
Colin Crossfce53272015-04-08 11:21:40 -07001833
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001834func findStringInSlice(str string, slice []string) int {
1835 for i, s := range slice {
1836 if s == str {
1837 return i
Colin Crossfce53272015-04-08 11:21:40 -07001838 }
1839 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001840 return -1
1841}
1842
Colin Cross41955e82019-05-29 14:40:35 -07001843// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1844// was not a module reference.
1845func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001846 if len(s) > 1 && s[0] == ':' {
1847 return s[1:]
1848 }
1849 return ""
1850}
1851
Colin Cross41955e82019-05-29 14:40:35 -07001852// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1853// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1854func SrcIsModuleWithTag(s string) (module, tag string) {
1855 if len(s) > 1 && s[0] == ':' {
1856 module = s[1:]
1857 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1858 if module[len(module)-1] == '}' {
1859 tag = module[tagStart+1 : len(module)-1]
1860 module = module[:tagStart]
1861 return module, tag
1862 }
1863 }
1864 return module, ""
1865 }
1866 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001867}
1868
Colin Cross41955e82019-05-29 14:40:35 -07001869type sourceOrOutputDependencyTag struct {
1870 blueprint.BaseDependencyTag
1871 tag string
1872}
1873
1874func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1875 return sourceOrOutputDependencyTag{tag: tag}
1876}
1877
1878var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001879
Colin Cross366938f2017-12-11 16:29:02 -08001880// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1881// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001882//
1883// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001884func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001885 set := make(map[string]bool)
1886
Colin Cross068e0fe2016-12-13 15:23:47 -08001887 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001888 if m, t := SrcIsModuleWithTag(s); m != "" {
1889 if _, found := set[s]; found {
1890 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001891 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001892 set[s] = true
1893 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001894 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001895 }
1896 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001897}
1898
Colin Cross366938f2017-12-11 16:29:02 -08001899// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1900// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001901//
1902// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001903func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1904 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001905 if m, t := SrcIsModuleWithTag(*s); m != "" {
1906 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001907 }
1908 }
1909}
1910
Colin Cross41955e82019-05-29 14:40:35 -07001911// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1912// using the ":module" syntax and provides a list of paths to be used as if they were listed in the property.
Colin Cross068e0fe2016-12-13 15:23:47 -08001913type SourceFileProducer interface {
1914 Srcs() Paths
1915}
1916
Colin Cross41955e82019-05-29 14:40:35 -07001917// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00001918// using the ":module" syntax or ":module{.tag}" syntax and provides a list of output files to be used as if they were
Colin Cross41955e82019-05-29 14:40:35 -07001919// listed in the property.
1920type OutputFileProducer interface {
1921 OutputFiles(tag string) (Paths, error)
1922}
1923
Colin Cross5e708052019-08-06 13:59:50 -07001924// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
1925// module produced zero paths, it reports errors to the ctx and returns nil.
1926func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
1927 paths, err := outputFilesForModule(ctx, module, tag)
1928 if err != nil {
1929 reportPathError(ctx, err)
1930 return nil
1931 }
1932 return paths
1933}
1934
1935// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
1936// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
1937func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
1938 paths, err := outputFilesForModule(ctx, module, tag)
1939 if err != nil {
1940 reportPathError(ctx, err)
1941 return nil
1942 }
1943 if len(paths) > 1 {
1944 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
1945 pathContextName(ctx, module))
1946 return nil
1947 }
1948 return paths[0]
1949}
1950
1951func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
1952 if outputFileProducer, ok := module.(OutputFileProducer); ok {
1953 paths, err := outputFileProducer.OutputFiles(tag)
1954 if err != nil {
1955 return nil, fmt.Errorf("failed to get output file from module %q: %s",
1956 pathContextName(ctx, module), err.Error())
1957 }
1958 if len(paths) == 0 {
1959 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
1960 }
1961 return paths, nil
1962 } else {
1963 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
1964 }
1965}
1966
Colin Crossfe17f6f2019-03-28 19:30:56 -07001967type HostToolProvider interface {
1968 HostToolPath() OptionalPath
1969}
1970
Colin Cross27b922f2019-03-04 22:35:41 -08001971// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1972// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001973//
1974// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001975func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1976 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001977}
1978
Colin Cross2fafa3e2019-03-05 12:39:51 -08001979// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1980// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001981//
1982// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001983func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1984 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001985}
1986
1987// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1988// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1989// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001990func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001991 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001992 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001993 }
1994 return OptionalPath{}
1995}
1996
Colin Cross25de6c32019-06-06 14:29:25 -07001997func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001998 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08001999}
2000
Colin Cross25de6c32019-06-06 14:29:25 -07002001func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002002 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002003}
2004
Colin Cross25de6c32019-06-06 14:29:25 -07002005func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002006 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002007}
2008
Colin Cross463a90e2015-06-17 14:20:06 -07002009func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002010 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002011}
2012
Colin Cross0875c522017-11-28 17:34:01 -08002013func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002014 return &buildTargetSingleton{}
2015}
2016
Colin Cross87d8b562017-04-25 10:01:55 -07002017func parentDir(dir string) string {
2018 dir, _ = filepath.Split(dir)
2019 return filepath.Clean(dir)
2020}
2021
Colin Cross1f8c52b2015-06-16 16:38:17 -07002022type buildTargetSingleton struct{}
2023
Colin Cross0875c522017-11-28 17:34:01 -08002024func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2025 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002026
Colin Cross0875c522017-11-28 17:34:01 -08002027 mmTarget := func(dir string) WritablePath {
2028 return PathForPhony(ctx,
2029 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07002030 }
2031
Colin Cross0875c522017-11-28 17:34:01 -08002032 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002033
Colin Cross0875c522017-11-28 17:34:01 -08002034 ctx.VisitAllModules(func(module Module) {
2035 blueprintDir := module.base().blueprintDir
2036 installTarget := module.base().installTarget
2037 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002038
Colin Cross0875c522017-11-28 17:34:01 -08002039 if checkbuildTarget != nil {
2040 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2041 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2042 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002043
Colin Cross0875c522017-11-28 17:34:01 -08002044 if installTarget != nil {
2045 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002046 }
2047 })
2048
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002049 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002050 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002051 suffix = "-soong"
2052 }
2053
Colin Cross1f8c52b2015-06-16 16:38:17 -07002054 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08002055 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002056 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002057 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002058 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07002059 })
2060
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002061 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002062 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002063 return
2064 }
2065
Colin Cross87d8b562017-04-25 10:01:55 -07002066 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002067 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002068 for _, dir := range dirs {
2069 dir := parentDir(dir)
2070 for dir != "." && dir != "/" {
2071 if _, exists := modulesInDir[dir]; exists {
2072 break
2073 }
2074 modulesInDir[dir] = nil
2075 dir = parentDir(dir)
2076 }
2077 }
2078
2079 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002080 for _, dir := range dirs {
2081 p := parentDir(dir)
2082 if p != "." && p != "/" {
2083 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2084 }
2085 }
2086
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002087 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2088 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2089 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002090 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002091 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002092 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002093 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002094 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002095 // HACK: checkbuild should be an optional build, but force it
2096 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002097 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002098 })
2099 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002100
2101 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2102 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002103 ctx.VisitAllModules(func(module Module) {
2104 if module.Enabled() {
2105 os := module.Target().Os
2106 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002107 }
2108 })
2109
Colin Cross0875c522017-11-28 17:34:01 -08002110 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002111 for os, deps := range osDeps {
2112 var className string
2113
2114 switch os.Class {
2115 case Host:
2116 className = "host"
2117 case HostCross:
2118 className = "host-cross"
2119 case Device:
2120 className = "target"
2121 default:
2122 continue
2123 }
2124
Colin Cross0875c522017-11-28 17:34:01 -08002125 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002126 osClass[className] = append(osClass[className], name)
2127
Colin Cross0875c522017-11-28 17:34:01 -08002128 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002129 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002130 Output: name,
2131 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002132 })
2133 }
2134
2135 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002136 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002137 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002138 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002139 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002140 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002141 })
2142 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002143}
Colin Crossd779da42015-12-17 18:00:23 -08002144
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002145// Collect information for opening IDE project files in java/jdeps.go.
2146type IDEInfo interface {
2147 IDEInfo(ideInfo *IdeInfo)
2148 BaseModuleName() string
2149}
2150
2151// Extract the base module name from the Import name.
2152// Often the Import name has a prefix "prebuilt_".
2153// Remove the prefix explicitly if needed
2154// until we find a better solution to get the Import name.
2155type IDECustomizedModuleName interface {
2156 IDECustomizedModuleName() string
2157}
2158
2159type IdeInfo struct {
2160 Deps []string `json:"dependencies,omitempty"`
2161 Srcs []string `json:"srcs,omitempty"`
2162 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2163 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2164 Jars []string `json:"jars,omitempty"`
2165 Classes []string `json:"class,omitempty"`
2166 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002167 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002168}