blob: 79693a19e6fe2d470b148e906f625ffa602380c0 [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
Nan Zhang6d34b302017-02-04 17:47:46 -0800175
176 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700177 HostRequiredModuleNames() []string
178 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700179
Colin Cross3f68a132017-10-23 17:10:29 -0700180 ModuleSubDir() string
181
Colin Cross0875c522017-11-28 17:34:01 -0800182 Variable(pctx PackageContext, name, value string)
183 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700184 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
185 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800186 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700187
Colin Cross0875c522017-11-28 17:34:01 -0800188 PrimaryModule() Module
189 FinalModule() Module
190 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700191
192 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800193 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800194}
195
Colin Cross635c3b02016-05-18 15:37:25 -0700196type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800197 blueprint.Module
198
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700199 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
200 // but GenerateAndroidBuildActions also has access to Android-specific information.
201 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700202 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700203
Colin Cross1e676be2016-10-12 14:38:15 -0700204 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800205
Colin Cross635c3b02016-05-18 15:37:25 -0700206 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900207 Disable()
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 Crossa2f296f2016-11-29 15:16:18 -0800217 SkipInstall()
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000218 IsSkipInstall() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900219 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900220 InitRc() Paths
221 VintfFragments() Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900222 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700223
224 AddProperties(props ...interface{})
225 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700226
Colin Crossae887032017-10-23 17:16:14 -0700227 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800228 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800229 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100230
Colin Cross9a362232019-07-01 15:32:45 -0700231 // String returns a string that includes the module name and variants for printing during debugging.
232 String() string
233
Paul Duffine2453c72019-05-31 14:00:04 +0100234 // Get the qualified module id for this module.
235 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
236
237 // Get information about the properties that can contain visibility rules.
238 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100239
240 // Get the visibility rules that control the visibility of this module.
241 visibility() []string
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900242
243 RequiredModuleNames() []string
244 HostRequiredModuleNames() []string
245 TargetRequiredModuleNames() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100246}
247
248// Qualified id for a module
249type qualifiedModuleName struct {
250 // The package (i.e. directory) in which the module is defined, without trailing /
251 pkg string
252
253 // The name of the module, empty string if package.
254 name string
255}
256
257func (q qualifiedModuleName) String() string {
258 if q.name == "" {
259 return "//" + q.pkg
260 }
261 return "//" + q.pkg + ":" + q.name
262}
263
Paul Duffine484f472019-06-20 16:38:08 +0100264func (q qualifiedModuleName) isRootPackage() bool {
265 return q.pkg == "" && q.name == ""
266}
267
Paul Duffine2453c72019-05-31 14:00:04 +0100268// Get the id for the package containing this module.
269func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
270 pkg := q.pkg
271 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100272 if pkg == "" {
273 panic(fmt.Errorf("Cannot get containing package id of root package"))
274 }
275
276 index := strings.LastIndex(pkg, "/")
277 if index == -1 {
278 pkg = ""
279 } else {
280 pkg = pkg[:index]
281 }
Paul Duffine2453c72019-05-31 14:00:04 +0100282 }
283 return newPackageId(pkg)
284}
285
286func newPackageId(pkg string) qualifiedModuleName {
287 // A qualified id for a package module has no name.
288 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800289}
290
Colin Crossfc754582016-05-17 16:34:16 -0700291type nameProperties struct {
292 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800293 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700294}
295
296type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800297 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000298 //
299 // Disabling a module should only be done for those modules that cannot be built
300 // in the current environment. Modules that can build in the current environment
301 // but are not usually required (e.g. superceded by a prebuilt) should not be
302 // disabled as that will prevent them from being built by the checkbuild target
303 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800304 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800305
Paul Duffin2e61fa62019-03-28 14:10:57 +0000306 // Controls the visibility of this module to other modules. Allowable values are one or more of
307 // these formats:
308 //
309 // ["//visibility:public"]: Anyone can use this module.
310 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
311 // this module.
312 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
313 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
314 // this module. Note that sub-packages do not have access to the rule; for example,
315 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
316 // is a special module and must be used verbatim. It represents all of the modules in the
317 // package.
318 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
319 // or other or in one of their sub-packages have access to this module. For example,
320 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
321 // to depend on this rule (but not //independent:evil)
322 // ["//project"]: This is shorthand for ["//project:__pkg__"]
323 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
324 // //project is the module's package. e.g. using [":__subpackages__"] in
325 // packages/apps/Settings/Android.bp is equivalent to
326 // //packages/apps/Settings:__subpackages__.
327 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
328 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100329 //
330 // If a module does not specify the `visibility` property then it uses the
331 // `default_visibility` property of the `package` module in the module's package.
332 //
333 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100334 // it will use the `default_visibility` of its closest ancestor package for which
335 // a `default_visibility` property is specified.
336 //
337 // If no `default_visibility` property can be found then the module uses the
338 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100339 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100340 // The `visibility` property has no effect on a defaults module although it does
341 // apply to any non-defaults module that uses it. To set the visibility of a
342 // defaults module, use the `defaults_visibility` property on the defaults module;
343 // not to be confused with the `default_visibility` property on the package module.
344 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000345 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
346 // more details.
347 Visibility []string
348
Colin Cross7d5136f2015-05-11 13:39:40 -0700349 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800350 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
351 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
352 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700353 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700354
355 Target struct {
356 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700357 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700358 }
359 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700360 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700361 }
362 }
363
Colin Crossee0bc3b2018-10-02 22:01:37 -0700364 UseTargetVariants bool `blueprint:"mutated"`
365 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800366
Dan Willemsen782a2d12015-12-21 14:55:28 -0800367 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700368 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800369
Colin Cross55708f32017-03-20 13:23:34 -0700370 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700371 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700372
Jiyong Park2db76922017-11-08 16:03:48 +0900373 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
374 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
375 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700376 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700377
Jiyong Park2db76922017-11-08 16:03:48 +0900378 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
379 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
380 Soc_specific *bool
381
382 // whether this module is specific to a device, not only for SoC, but also for off-chip
383 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
384 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
385 // This implies `soc_specific:true`.
386 Device_specific *bool
387
388 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900389 // network operator, etc). When set to true, it is installed into /product (or
390 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900391 Product_specific *bool
392
Justin Yund5f6c822019-06-25 16:47:17 +0900393 // whether this module extends system. When set to true, it is installed into /system_ext
394 // (or /system/system_ext if system_ext partition does not exist).
395 System_ext_specific *bool
396
Jiyong Parkf9332f12018-02-01 00:54:12 +0900397 // Whether this module is installed to recovery partition
398 Recovery *bool
399
Yifan Hong1b3348d2020-01-21 15:53:22 -0800400 // Whether this module is installed to ramdisk
401 Ramdisk *bool
402
dimitry1f33e402019-03-26 12:39:31 +0100403 // Whether this module is built for non-native architecures (also known as native bridge binary)
404 Native_bridge_supported *bool `android:"arch_variant"`
405
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700406 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800407 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700408
Steven Moreland57a23d22018-04-04 15:42:19 -0700409 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800410 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700411
Chris Wolfe998306e2016-08-15 14:47:23 -0400412 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700413 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400414
Sasha Smundakb6d23052019-04-01 18:37:36 -0700415 // names of other modules to install on host if this module is installed
416 Host_required []string `android:"arch_variant"`
417
418 // names of other modules to install on target if this module is installed
419 Target_required []string `android:"arch_variant"`
420
Colin Cross5aac3622017-08-31 15:07:09 -0700421 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800422 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700423
Dan Willemsen569edc52018-11-19 09:33:29 -0800424 Dist struct {
425 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
426 // command line and any of these targets are also on the command line, or otherwise
427 // built
428 Targets []string `android:"arch_variant"`
429
430 // The name of the output artifact. This defaults to the basename of the output of
431 // the module.
432 Dest *string `android:"arch_variant"`
433
434 // The directory within the dist directory to store the artifact. Defaults to the
435 // top level directory ("").
436 Dir *string `android:"arch_variant"`
437
438 // A suffix to add to the artifact file name (before any extension).
439 Suffix *string `android:"arch_variant"`
440 } `android:"arch_variant"`
441
Colin Crossa1ad8d12016-06-01 17:09:44 -0700442 // Set by TargetMutator
Colin Crossa195f912019-10-16 11:07:20 -0700443 CompileOS OsType `blueprint:"mutated"`
Colin Crossee0bc3b2018-10-02 22:01:37 -0700444 CompileTarget Target `blueprint:"mutated"`
445 CompileMultiTargets []Target `blueprint:"mutated"`
446 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800447
448 // Set by InitAndroidModule
449 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700450 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700451
452 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800453
454 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700455
456 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700457
458 // Name and variant strings stored by mutators to enable Module.String()
459 DebugName string `blueprint:"mutated"`
460 DebugMutators []string `blueprint:"mutated"`
461 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800462
463 // set by ImageMutator
464 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800465}
466
467type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800468 // If set to true, build a variant of the module for the host. Defaults to false.
469 Host_supported *bool
470
471 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700472 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800473}
474
Colin Crossc472d572015-03-17 15:06:21 -0700475type Multilib string
476
477const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800478 MultilibBoth Multilib = "both"
479 MultilibFirst Multilib = "first"
480 MultilibCommon Multilib = "common"
481 MultilibCommonFirst Multilib = "common_first"
482 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700483)
484
Colin Crossa1ad8d12016-06-01 17:09:44 -0700485type HostOrDeviceSupported int
486
487const (
488 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700489
490 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700491 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700492
493 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700494 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700495
496 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700497 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700498
499 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700500 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700501
502 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700503 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700504
505 // Nothing is supported. This is not exposed to the user, but used to mark a
506 // host only module as unsupported when the module type is not supported on
507 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700508 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700509)
510
Jiyong Park2db76922017-11-08 16:03:48 +0900511type moduleKind int
512
513const (
514 platformModule moduleKind = iota
515 deviceSpecificModule
516 socSpecificModule
517 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900518 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900519)
520
521func (k moduleKind) String() string {
522 switch k {
523 case platformModule:
524 return "platform"
525 case deviceSpecificModule:
526 return "device-specific"
527 case socSpecificModule:
528 return "soc-specific"
529 case productSpecificModule:
530 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900531 case systemExtSpecificModule:
532 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900533 default:
534 panic(fmt.Errorf("unknown module kind %d", k))
535 }
536}
537
Colin Cross9d34f352019-11-22 16:03:51 -0800538func initAndroidModuleBase(m Module) {
539 m.base().module = m
540}
541
Colin Cross36242852017-06-23 15:06:31 -0700542func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800543 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800544 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700545
Colin Cross36242852017-06-23 15:06:31 -0700546 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700547 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700548 &base.commonProperties)
549
Colin Crosseabaedd2020-02-06 17:01:55 -0800550 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700551
Colin Crossa3a97412019-03-18 12:24:29 -0700552 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700553 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100554
555 // The default_visibility property needs to be checked and parsed by the visibility module during
556 // its checking and parsing phases.
557 base.primaryVisibilityProperty =
558 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
559 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700560}
561
Colin Cross36242852017-06-23 15:06:31 -0700562func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
563 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700564
565 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800566 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700567 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700568 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700569 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800570
Dan Willemsen218f6562015-07-08 18:13:11 -0700571 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700572 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700573 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800574 }
575
Colin Cross36242852017-06-23 15:06:31 -0700576 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800577}
578
Colin Crossee0bc3b2018-10-02 22:01:37 -0700579func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
580 InitAndroidArchModule(m, hod, defaultMultilib)
581 m.base().commonProperties.UseTargetVariants = false
582}
583
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800584// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800585// modules. It should be included as an anonymous field in every module
586// struct definition. InitAndroidModule should then be called from the module's
587// factory function, and the return values from InitAndroidModule should be
588// returned from the factory function.
589//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800590// The ModuleBase type is responsible for implementing the GenerateBuildActions
591// method to support the blueprint.Module interface. This method will then call
592// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700593// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
594// rather than the usual blueprint.ModuleContext.
595// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800596// system including details about the particular build variant that is to be
597// generated.
598//
599// For example:
600//
601// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800602// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800603// )
604//
605// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800606// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800607// properties struct {
608// MyProperty string
609// }
610// }
611//
Colin Cross36242852017-06-23 15:06:31 -0700612// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800613// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700614// m.AddProperties(&m.properties)
615// android.InitAndroidModule(m)
616// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800617// }
618//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800619// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800620// // Get the CPU architecture for the current build variant.
621// variantArch := ctx.Arch()
622//
623// // ...
624// }
Colin Cross635c3b02016-05-18 15:37:25 -0700625type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800626 // Putting the curiously recurring thing pointing to the thing that contains
627 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700628 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700629 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800630
Colin Crossfc754582016-05-17 16:34:16 -0700631 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800632 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700633 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800634 hostAndDeviceProperties hostAndDeviceProperties
635 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700636 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700637 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800638
Paul Duffin63c6e182019-07-24 14:24:38 +0100639 // Information about all the properties on the module that contains visibility rules that need
640 // checking.
641 visibilityPropertyInfo []visibilityProperty
642
643 // The primary visibility property, may be nil, that controls access to the module.
644 primaryVisibilityProperty visibilityProperty
645
Colin Cross3f40fa42015-01-30 17:27:36 -0800646 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700647 installFiles Paths
648 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900649 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700650
651 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
652 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800653 installTarget WritablePath
654 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700655 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700656
Colin Cross178a5092016-09-13 13:42:32 -0700657 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700658
659 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700660
661 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700662 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800663 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800664 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700665
Inseob Kim8471cda2019-11-15 09:59:12 +0900666 initRcPaths Paths
667 vintfFragmentsPaths Paths
668
Colin Crossa9d8bee2018-10-02 13:59:46 -0700669 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700670}
671
Colin Cross4157e882019-06-06 16:57:04 -0700672func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800673
Colin Cross4157e882019-06-06 16:57:04 -0700674func (m *ModuleBase) AddProperties(props ...interface{}) {
675 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700676}
677
Colin Cross4157e882019-06-06 16:57:04 -0700678func (m *ModuleBase) GetProperties() []interface{} {
679 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800680}
681
Colin Cross4157e882019-06-06 16:57:04 -0700682func (m *ModuleBase) BuildParamsForTests() []BuildParams {
683 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700684}
685
Colin Cross4157e882019-06-06 16:57:04 -0700686func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
687 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800688}
689
Colin Cross4157e882019-06-06 16:57:04 -0700690func (m *ModuleBase) VariablesForTests() map[string]string {
691 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800692}
693
Colin Cross4157e882019-06-06 16:57:04 -0700694func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
695 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700696}
697
Colin Crossce75d2c2016-10-06 16:12:58 -0700698// Name returns the name of the module. It may be overridden by individual module types, for
699// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700700func (m *ModuleBase) Name() string {
701 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700702}
703
Colin Cross9a362232019-07-01 15:32:45 -0700704// String returns a string that includes the module name and variants for printing during debugging.
705func (m *ModuleBase) String() string {
706 sb := strings.Builder{}
707 sb.WriteString(m.commonProperties.DebugName)
708 sb.WriteString("{")
709 for i := range m.commonProperties.DebugMutators {
710 if i != 0 {
711 sb.WriteString(",")
712 }
713 sb.WriteString(m.commonProperties.DebugMutators[i])
714 sb.WriteString(":")
715 sb.WriteString(m.commonProperties.DebugVariations[i])
716 }
717 sb.WriteString("}")
718 return sb.String()
719}
720
Colin Crossce75d2c2016-10-06 16:12:58 -0700721// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700722func (m *ModuleBase) BaseModuleName() string {
723 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700724}
725
Colin Cross4157e882019-06-06 16:57:04 -0700726func (m *ModuleBase) base() *ModuleBase {
727 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800728}
729
Paul Duffine2453c72019-05-31 14:00:04 +0100730func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
731 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
732}
733
734func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100735 return m.visibilityPropertyInfo
736}
737
738func (m *ModuleBase) visibility() []string {
739 // The soong_namespace module does not initialize the primaryVisibilityProperty.
740 if m.primaryVisibilityProperty != nil {
741 return m.primaryVisibilityProperty.getStrings()
742 } else {
743 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100744 }
745}
746
Colin Cross4157e882019-06-06 16:57:04 -0700747func (m *ModuleBase) Target() Target {
748 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800749}
750
Colin Cross4157e882019-06-06 16:57:04 -0700751func (m *ModuleBase) TargetPrimary() bool {
752 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700753}
754
Colin Cross4157e882019-06-06 16:57:04 -0700755func (m *ModuleBase) MultiTargets() []Target {
756 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700757}
758
Colin Cross4157e882019-06-06 16:57:04 -0700759func (m *ModuleBase) Os() OsType {
760 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800761}
762
Colin Cross4157e882019-06-06 16:57:04 -0700763func (m *ModuleBase) Host() bool {
764 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800765}
766
Colin Cross4157e882019-06-06 16:57:04 -0700767func (m *ModuleBase) Arch() Arch {
768 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800769}
770
Colin Cross4157e882019-06-06 16:57:04 -0700771func (m *ModuleBase) ArchSpecific() bool {
772 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700773}
774
Colin Cross4157e882019-06-06 16:57:04 -0700775func (m *ModuleBase) OsClassSupported() []OsClass {
776 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700777 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700778 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700779 case HostSupportedNoCross:
780 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700781 case DeviceSupported:
782 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700783 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700784 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700785 if Bool(m.hostAndDeviceProperties.Host_supported) ||
786 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
787 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700788 supported = append(supported, Host, HostCross)
789 }
Colin Cross4157e882019-06-06 16:57:04 -0700790 if m.hostAndDeviceProperties.Device_supported == nil ||
791 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700792 supported = append(supported, Device)
793 }
794 return supported
795 default:
796 return nil
797 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800798}
799
Colin Cross4157e882019-06-06 16:57:04 -0700800func (m *ModuleBase) DeviceSupported() bool {
801 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
802 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
803 (m.hostAndDeviceProperties.Device_supported == nil ||
804 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800805}
806
Paul Duffine44358f2019-11-26 18:04:12 +0000807func (m *ModuleBase) HostSupported() bool {
808 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
809 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
810 (m.hostAndDeviceProperties.Host_supported != nil &&
811 *m.hostAndDeviceProperties.Host_supported)
812}
813
Colin Cross4157e882019-06-06 16:57:04 -0700814func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900815 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900816}
817
Colin Cross4157e882019-06-06 16:57:04 -0700818func (m *ModuleBase) DeviceSpecific() bool {
819 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900820}
821
Colin Cross4157e882019-06-06 16:57:04 -0700822func (m *ModuleBase) SocSpecific() bool {
823 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900824}
825
Colin Cross4157e882019-06-06 16:57:04 -0700826func (m *ModuleBase) ProductSpecific() bool {
827 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900828}
829
Justin Yund5f6c822019-06-25 16:47:17 +0900830func (m *ModuleBase) SystemExtSpecific() bool {
831 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100832}
833
Bill Peckham1c610cf2020-03-20 18:33:20 -0700834func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
835 partition := "system"
836 if m.SocSpecific() {
837 // A SoC-specific module could be on the vendor partition at
838 // "vendor" or the system partition at "system/vendor".
839 if config.VendorPath() == "vendor" {
840 partition = "vendor"
841 }
842 } else if m.DeviceSpecific() {
843 // A device-specific module could be on the odm partition at
844 // "odm", the vendor partition at "vendor/odm", or the system
845 // partition at "system/vendor/odm".
846 if config.OdmPath() == "odm" {
847 partition = "odm"
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000848 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckham1c610cf2020-03-20 18:33:20 -0700849 partition = "vendor"
850 }
851 } else if m.ProductSpecific() {
852 // A product-specific module could be on the product partition
853 // at "product" or the system partition at "system/product".
854 if config.ProductPath() == "product" {
855 partition = "product"
856 }
857 } else if m.SystemExtSpecific() {
858 // A system_ext-specific module could be on the system_ext
859 // partition at "system_ext" or the system partition at
860 // "system/system_ext".
861 if config.SystemExtPath() == "system_ext" {
862 partition = "system_ext"
863 }
864 }
865 return partition
866}
867
Colin Cross4157e882019-06-06 16:57:04 -0700868func (m *ModuleBase) Enabled() bool {
869 if m.commonProperties.Enabled == nil {
870 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800871 }
Colin Cross4157e882019-06-06 16:57:04 -0700872 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800873}
874
Inseob Kimeec88e12020-01-22 11:11:29 +0900875func (m *ModuleBase) Disable() {
876 m.commonProperties.Enabled = proptools.BoolPtr(false)
877}
878
Colin Cross4157e882019-06-06 16:57:04 -0700879func (m *ModuleBase) SkipInstall() {
880 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700881}
882
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000883func (m *ModuleBase) IsSkipInstall() bool {
884 return m.commonProperties.SkipInstall == true
885}
886
Colin Cross4157e882019-06-06 16:57:04 -0700887func (m *ModuleBase) ExportedToMake() bool {
888 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900889}
890
Colin Cross4157e882019-06-06 16:57:04 -0700891func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700892 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800893
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700894 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700895 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800896 ctx.VisitDepsDepthFirstIf(isFileInstaller,
897 func(m blueprint.Module) {
898 fileInstaller := m.(fileInstaller)
899 files := fileInstaller.filesToInstall()
900 result = append(result, files...)
901 })
902
903 return result
904}
905
Colin Cross4157e882019-06-06 16:57:04 -0700906func (m *ModuleBase) filesToInstall() Paths {
907 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800908}
909
Colin Cross4157e882019-06-06 16:57:04 -0700910func (m *ModuleBase) NoAddressSanitizer() bool {
911 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800912}
913
Colin Cross4157e882019-06-06 16:57:04 -0700914func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800915 return false
916}
917
Jaewoong Jung0949f312019-09-11 10:25:18 -0700918func (m *ModuleBase) InstallInTestcases() bool {
919 return false
920}
921
Colin Cross4157e882019-06-06 16:57:04 -0700922func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700923 return false
924}
925
Yifan Hong1b3348d2020-01-21 15:53:22 -0800926func (m *ModuleBase) InstallInRamdisk() bool {
927 return Bool(m.commonProperties.Ramdisk)
928}
929
Colin Cross4157e882019-06-06 16:57:04 -0700930func (m *ModuleBase) InstallInRecovery() bool {
931 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900932}
933
Colin Cross90ba5f42019-10-02 11:10:58 -0700934func (m *ModuleBase) InstallInRoot() bool {
935 return false
936}
937
Colin Cross607d8582019-07-29 16:44:46 -0700938func (m *ModuleBase) InstallBypassMake() bool {
939 return false
940}
941
Colin Cross4157e882019-06-06 16:57:04 -0700942func (m *ModuleBase) Owner() string {
943 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900944}
945
Colin Cross4157e882019-06-06 16:57:04 -0700946func (m *ModuleBase) NoticeFile() OptionalPath {
947 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900948}
949
Colin Cross7228ecd2019-11-18 16:00:16 -0800950func (m *ModuleBase) setImageVariation(variant string) {
951 m.commonProperties.ImageVariation = variant
952}
953
954func (m *ModuleBase) ImageVariation() blueprint.Variation {
955 return blueprint.Variation{
956 Mutator: "image",
957 Variation: m.base().commonProperties.ImageVariation,
958 }
959}
960
Yifan Hong1b3348d2020-01-21 15:53:22 -0800961func (m *ModuleBase) InRamdisk() bool {
962 return m.base().commonProperties.ImageVariation == RamdiskVariation
963}
964
Colin Cross7228ecd2019-11-18 16:00:16 -0800965func (m *ModuleBase) InRecovery() bool {
966 return m.base().commonProperties.ImageVariation == RecoveryVariation
967}
968
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900969func (m *ModuleBase) RequiredModuleNames() []string {
970 return m.base().commonProperties.Required
971}
972
973func (m *ModuleBase) HostRequiredModuleNames() []string {
974 return m.base().commonProperties.Host_required
975}
976
977func (m *ModuleBase) TargetRequiredModuleNames() []string {
978 return m.base().commonProperties.Target_required
979}
980
Inseob Kim8471cda2019-11-15 09:59:12 +0900981func (m *ModuleBase) InitRc() Paths {
982 return append(Paths{}, m.initRcPaths...)
983}
984
985func (m *ModuleBase) VintfFragments() Paths {
986 return append(Paths{}, m.vintfFragmentsPaths...)
987}
988
Colin Cross4157e882019-06-06 16:57:04 -0700989func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700990 allInstalledFiles := Paths{}
991 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800992 ctx.VisitAllModuleVariants(func(module Module) {
993 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700994 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
995 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800996 })
997
Colin Cross0875c522017-11-28 17:34:01 -0800998 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700999
Jeff Gaston088e29e2017-11-29 16:47:17 -08001000 namespacePrefix := ctx.Namespace().(*Namespace).id
1001 if namespacePrefix != "" {
1002 namespacePrefix = namespacePrefix + "-"
1003 }
1004
Colin Cross3f40fa42015-01-30 17:27:36 -08001005 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -08001006 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -08001007 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001008 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001009 Output: name,
1010 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -08001011 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -07001012 })
1013 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -07001014 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -07001015 }
1016
1017 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -08001018 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -08001019 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001020 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001021 Output: name,
1022 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -07001023 })
1024 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -07001025 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -07001026 }
1027
1028 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001029 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001030 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001031 suffix = "-soong"
1032 }
1033
Jeff Gaston088e29e2017-11-29 16:47:17 -08001034 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -08001035 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001036 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -08001037 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -07001038 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -08001039 })
Colin Cross1f8c52b2015-06-16 16:38:17 -07001040
Colin Cross4157e882019-06-06 16:57:04 -07001041 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001042 }
1043}
1044
Colin Crossc34d2322020-01-03 15:23:27 -08001045func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001046 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1047 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1048 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001049 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001050
Dario Frenifd05a742018-05-29 13:28:54 +01001051 msg := "conflicting value set here"
1052 if socSpecific && deviceSpecific {
1053 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001054 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001055 ctx.PropertyErrorf("vendor", msg)
1056 }
Colin Cross4157e882019-06-06 16:57:04 -07001057 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001058 ctx.PropertyErrorf("proprietary", msg)
1059 }
Colin Cross4157e882019-06-06 16:57:04 -07001060 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001061 ctx.PropertyErrorf("soc_specific", msg)
1062 }
1063 }
1064
Justin Yund5f6c822019-06-25 16:47:17 +09001065 if productSpecific && systemExtSpecific {
1066 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1067 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001068 }
1069
Justin Yund5f6c822019-06-25 16:47:17 +09001070 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001071 if productSpecific {
1072 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1073 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001074 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 +01001075 }
1076 if deviceSpecific {
1077 ctx.PropertyErrorf("device_specific", msg)
1078 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001079 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001080 ctx.PropertyErrorf("vendor", msg)
1081 }
Colin Cross4157e882019-06-06 16:57:04 -07001082 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001083 ctx.PropertyErrorf("proprietary", msg)
1084 }
Colin Cross4157e882019-06-06 16:57:04 -07001085 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001086 ctx.PropertyErrorf("soc_specific", msg)
1087 }
1088 }
1089 }
1090
Jiyong Park2db76922017-11-08 16:03:48 +09001091 if productSpecific {
1092 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001093 } else if systemExtSpecific {
1094 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001095 } else if deviceSpecific {
1096 return deviceSpecificModule
1097 } else if socSpecific {
1098 return socSpecificModule
1099 } else {
1100 return platformModule
1101 }
1102}
1103
Colin Crossc34d2322020-01-03 15:23:27 -08001104func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001105 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001106 EarlyModuleContext: ctx,
1107 kind: determineModuleKind(m, ctx),
1108 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001109 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001110}
1111
Colin Cross1184b642019-12-30 18:43:07 -08001112func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1113 return baseModuleContext{
1114 bp: ctx,
1115 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1116 os: m.commonProperties.CompileOS,
1117 target: m.commonProperties.CompileTarget,
1118 targetPrimary: m.commonProperties.CompilePrimary,
1119 multiTargets: m.commonProperties.CompileMultiTargets,
1120 }
1121}
1122
Colin Cross4157e882019-06-06 16:57:04 -07001123func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001124 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001125 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001126 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001127 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1128 installDeps: m.computeInstallDeps(blueprintCtx),
1129 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001130 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001131 }
1132
Colin Cross6c4f21f2019-06-06 15:41:36 -07001133 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1134 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1135 // TODO: This will be removed once defaults modules handle missing dependency errors
1136 blueprintCtx.GetMissingDependencies()
1137
Colin Crossdc35e212019-06-06 16:13:11 -07001138 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
1139 // are enabled.
1140 ctx.baseModuleContext.strictVisitDeps = true
1141
Colin Cross4c83e5c2019-02-25 14:54:28 -08001142 if ctx.config.captureBuild {
1143 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1144 }
1145
Colin Cross67a5c132017-05-09 13:45:28 -07001146 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1147 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001148 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1149 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001150 }
Colin Cross0875c522017-11-28 17:34:01 -08001151 if !ctx.PrimaryArch() {
1152 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001153 }
Dan Willemsenb13a9482020-02-14 11:25:54 -08001154 if apex, ok := m.module.(ApexModule); ok && !apex.IsForPlatform() {
1155 suffix = append(suffix, apex.ApexName())
1156 }
Colin Cross67a5c132017-05-09 13:45:28 -07001157
1158 ctx.Variable(pctx, "moduleDesc", desc)
1159
1160 s := ""
1161 if len(suffix) > 0 {
1162 s = " [" + strings.Join(suffix, " ") + "]"
1163 }
1164 ctx.Variable(pctx, "moduleDescSuffix", s)
1165
Dan Willemsen569edc52018-11-19 09:33:29 -08001166 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001167 if m.commonProperties.Dist.Dest != nil {
1168 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001169 if err != nil {
1170 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1171 }
1172 }
Colin Cross4157e882019-06-06 16:57:04 -07001173 if m.commonProperties.Dist.Dir != nil {
1174 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001175 if err != nil {
1176 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1177 }
1178 }
Colin Cross4157e882019-06-06 16:57:04 -07001179 if m.commonProperties.Dist.Suffix != nil {
1180 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001181 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1182 }
1183 }
1184
Colin Cross4157e882019-06-06 16:57:04 -07001185 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001186 // ensure all direct android.Module deps are enabled
1187 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1188 if _, ok := bm.(Module); ok {
1189 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1190 }
1191 })
1192
Colin Cross4157e882019-06-06 16:57:04 -07001193 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1194 if module := SrcIsModule(notice); module != "" {
1195 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001196 } else {
1197 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001198 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001199 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001200
1201 m.module.GenerateAndroidBuildActions(ctx)
1202 if ctx.Failed() {
1203 return
1204 }
1205
1206 m.installFiles = append(m.installFiles, ctx.installFiles...)
1207 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Inseob Kim8471cda2019-11-15 09:59:12 +09001208 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1209 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
Colin Crossdc35e212019-06-06 16:13:11 -07001210 } else if ctx.Config().AllowMissingDependencies() {
1211 // If the module is not enabled it will not create any build rules, nothing will call
1212 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1213 // and report them as an error even when AllowMissingDependencies = true. Call
1214 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1215 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001216 }
1217
Colin Cross4157e882019-06-06 16:57:04 -07001218 if m == ctx.FinalModule().(Module).base() {
1219 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001220 if ctx.Failed() {
1221 return
1222 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001223 }
Colin Crosscec81712017-07-13 14:43:27 -07001224
Colin Cross4157e882019-06-06 16:57:04 -07001225 m.buildParams = ctx.buildParams
1226 m.ruleParams = ctx.ruleParams
1227 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001228}
1229
Colin Cross1184b642019-12-30 18:43:07 -08001230type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001231 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001232
1233 kind moduleKind
1234 config Config
1235}
1236
1237func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1238 ret, err := e.GlobWithDeps(globPattern, excludes)
1239 if err != nil {
1240 e.ModuleErrorf("glob: %s", err.Error())
1241 }
1242 return pathsForModuleSrcFromFullPath(e, ret, true)
1243}
1244
1245func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1246 ret, err := e.GlobWithDeps(globPattern, excludes)
1247 if err != nil {
1248 e.ModuleErrorf("glob: %s", err.Error())
1249 }
1250 return pathsForModuleSrcFromFullPath(e, ret, false)
1251}
1252
Colin Cross988414c2020-01-11 01:11:46 +00001253func (b *earlyModuleContext) IsSymlink(path Path) bool {
1254 fileInfo, err := b.config.fs.Lstat(path.String())
1255 if err != nil {
1256 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1257 }
1258 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1259}
1260
1261func (b *earlyModuleContext) Readlink(path Path) string {
1262 dest, err := b.config.fs.Readlink(path.String())
1263 if err != nil {
1264 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1265 }
1266 return dest
1267}
1268
Colin Cross1184b642019-12-30 18:43:07 -08001269func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001270 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001271 return module
1272}
1273
1274func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001275 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001276}
1277
1278func (e *earlyModuleContext) AConfig() Config {
1279 return e.config
1280}
1281
1282func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1283 return DeviceConfig{e.config.deviceConfig}
1284}
1285
1286func (e *earlyModuleContext) Platform() bool {
1287 return e.kind == platformModule
1288}
1289
1290func (e *earlyModuleContext) DeviceSpecific() bool {
1291 return e.kind == deviceSpecificModule
1292}
1293
1294func (e *earlyModuleContext) SocSpecific() bool {
1295 return e.kind == socSpecificModule
1296}
1297
1298func (e *earlyModuleContext) ProductSpecific() bool {
1299 return e.kind == productSpecificModule
1300}
1301
1302func (e *earlyModuleContext) SystemExtSpecific() bool {
1303 return e.kind == systemExtSpecificModule
1304}
1305
1306type baseModuleContext struct {
1307 bp blueprint.BaseModuleContext
1308 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001309 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001310 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001311 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001312 targetPrimary bool
1313 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001314
1315 walkPath []Module
1316
1317 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001318}
1319
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +00001320func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
1321 return b.bp.OtherModuleName(m)
1322}
1323func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08001324func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Han67b141d2020-02-26 02:05:18 +09001325 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08001326}
1327func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1328 return b.bp.OtherModuleDependencyTag(m)
1329}
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +00001330func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1331func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
1332 return b.bp.OtherModuleType(m)
1333}
Colin Cross1184b642019-12-30 18:43:07 -08001334
1335func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1336 return b.bp.GetDirectDepWithTag(name, tag)
1337}
1338
Colin Cross25de6c32019-06-06 14:29:25 -07001339type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001340 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001341 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001342 installDeps Paths
1343 installFiles Paths
1344 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001345 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001346
1347 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001348 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001349 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001350 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001351}
1352
Colin Crossb88b3c52019-06-10 15:15:17 -07001353func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1354 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001355 Rule: ErrorRule,
1356 Description: params.Description,
1357 Output: params.Output,
1358 Outputs: params.Outputs,
1359 ImplicitOutput: params.ImplicitOutput,
1360 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001361 Args: map[string]string{
1362 "error": err.Error(),
1363 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001364 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001365}
1366
Colin Cross25de6c32019-06-06 14:29:25 -07001367func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1368 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001369}
1370
Colin Cross0875c522017-11-28 17:34:01 -08001371func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001372 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001373 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001374 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001375 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001376 Outputs: params.Outputs.Strings(),
1377 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1378 Inputs: params.Inputs.Strings(),
1379 Implicits: params.Implicits.Strings(),
1380 OrderOnly: params.OrderOnly.Strings(),
1381 Args: params.Args,
1382 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001383 }
1384
Colin Cross33bfb0a2016-11-21 17:23:08 -08001385 if params.Depfile != nil {
1386 bparams.Depfile = params.Depfile.String()
1387 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001388 if params.Output != nil {
1389 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1390 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001391 if params.ImplicitOutput != nil {
1392 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1393 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001394 if params.Input != nil {
1395 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1396 }
1397 if params.Implicit != nil {
1398 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1399 }
1400
Colin Cross0b9f31f2019-02-28 11:00:01 -08001401 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1402 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1403 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1404 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1405 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1406 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001407
Colin Cross0875c522017-11-28 17:34:01 -08001408 return bparams
1409}
1410
Colin Cross25de6c32019-06-06 14:29:25 -07001411func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1412 if m.config.captureBuild {
1413 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001414 }
1415
Colin Crossdc35e212019-06-06 16:13:11 -07001416 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001417}
1418
Colin Cross25de6c32019-06-06 14:29:25 -07001419func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001420 argNames ...string) blueprint.Rule {
1421
Colin Cross8b8bec32019-11-15 13:18:43 -08001422 if m.config.UseRemoteBuild() && params.Pool == nil {
Ramy Medhatdd0418a2019-11-04 18:16:11 -05001423 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1424 // jobs to the local parallelism value
Colin Cross2e2dbc22019-09-25 13:31:46 -07001425 params.Pool = localPool
1426 }
1427
Colin Crossdc35e212019-06-06 16:13:11 -07001428 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001429
Colin Cross25de6c32019-06-06 14:29:25 -07001430 if m.config.captureBuild {
1431 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001432 }
1433
1434 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001435}
1436
Colin Cross25de6c32019-06-06 14:29:25 -07001437func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001438 if params.Description != "" {
1439 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1440 }
1441
1442 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1443 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1444 m.ModuleName(), strings.Join(missingDeps, ", ")))
1445 }
1446
Colin Cross25de6c32019-06-06 14:29:25 -07001447 if m.config.captureBuild {
1448 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001449 }
1450
Colin Crossdc35e212019-06-06 16:13:11 -07001451 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001452}
Colin Cross25de6c32019-06-06 14:29:25 -07001453func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001454 var missingDeps []string
1455 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001456 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001457 missingDeps = FirstUniqueStrings(missingDeps)
1458 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001459}
1460
Colin Crossdc35e212019-06-06 16:13:11 -07001461func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001462 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001463 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001464 *missingDeps = append(*missingDeps, deps...)
1465 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001466 }
1467}
1468
Colin Crossdc35e212019-06-06 16:13:11 -07001469func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001470 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001471
1472 if !strict {
1473 return aModule
1474 }
1475
Colin Cross380c69a2019-06-10 17:49:58 +00001476 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001477 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001478 return nil
1479 }
1480
1481 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001482 if b.Config().AllowMissingDependencies() {
1483 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001484 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001485 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001486 }
1487 return nil
1488 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001489 return aModule
1490}
1491
Colin Crossdc35e212019-06-06 16:13:11 -07001492func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001493 type dep struct {
1494 mod blueprint.Module
1495 tag blueprint.DependencyTag
1496 }
1497 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001498 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001499 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001500 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001501 if tag == nil || returnedTag == tag {
1502 deps = append(deps, dep{aModule, returnedTag})
1503 }
1504 }
1505 })
1506 if len(deps) == 1 {
1507 return deps[0].mod, deps[0].tag
1508 } else if len(deps) >= 2 {
1509 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001510 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001511 } else {
1512 return nil, nil
1513 }
1514}
1515
Colin Crossdc35e212019-06-06 16:13:11 -07001516func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001517 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001518 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001519 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001520 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001521 deps = append(deps, aModule)
1522 }
1523 }
1524 })
1525 return deps
1526}
1527
Colin Cross25de6c32019-06-06 14:29:25 -07001528func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1529 module, _ := m.getDirectDepInternal(name, tag)
1530 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001531}
1532
Colin Crossdc35e212019-06-06 16:13:11 -07001533func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1534 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001535}
1536
Colin Crossdc35e212019-06-06 16:13:11 -07001537func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001538 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001539}
1540
Colin Crossdc35e212019-06-06 16:13:11 -07001541func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001542 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001543 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001544 visit(aModule)
1545 }
1546 })
1547}
1548
Colin Crossdc35e212019-06-06 16:13:11 -07001549func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001550 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001551 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001552 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001553 visit(aModule)
1554 }
1555 }
1556 })
1557}
1558
Colin Crossdc35e212019-06-06 16:13:11 -07001559func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001560 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001561 // pred
1562 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001563 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001564 return pred(aModule)
1565 } else {
1566 return false
1567 }
1568 },
1569 // visit
1570 func(module blueprint.Module) {
1571 visit(module.(Module))
1572 })
1573}
1574
Colin Crossdc35e212019-06-06 16:13:11 -07001575func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001576 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001577 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001578 visit(aModule)
1579 }
1580 })
1581}
1582
Colin Crossdc35e212019-06-06 16:13:11 -07001583func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001584 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001585 // pred
1586 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001587 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001588 return pred(aModule)
1589 } else {
1590 return false
1591 }
1592 },
1593 // visit
1594 func(module blueprint.Module) {
1595 visit(module.(Module))
1596 })
1597}
1598
Colin Crossdc35e212019-06-06 16:13:11 -07001599func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001600 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001601}
1602
Colin Crossdc35e212019-06-06 16:13:11 -07001603func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1604 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001605 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001606 childAndroidModule, _ := child.(Module)
1607 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001608 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001609 // record walkPath before visit
1610 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1611 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1612 }
1613 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001614 return visit(childAndroidModule, parentAndroidModule)
1615 } else {
1616 return false
1617 }
1618 })
1619}
1620
Colin Crossdc35e212019-06-06 16:13:11 -07001621func (b *baseModuleContext) GetWalkPath() []Module {
1622 return b.walkPath
1623}
1624
Colin Cross25de6c32019-06-06 14:29:25 -07001625func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001626 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001627 visit(module.(Module))
1628 })
1629}
1630
Colin Cross25de6c32019-06-06 14:29:25 -07001631func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001632 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001633}
1634
Colin Cross25de6c32019-06-06 14:29:25 -07001635func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001636 return m.bp.FinalModule().(Module)
1637}
1638
1639func (m *moduleContext) ModuleSubDir() string {
1640 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001641}
1642
Colin Cross0ea8ba82019-06-06 14:33:29 -07001643func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001644 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001645}
1646
Colin Cross0ea8ba82019-06-06 14:33:29 -07001647func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001648 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001649}
1650
Colin Cross0ea8ba82019-06-06 14:33:29 -07001651func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001652 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001653}
1654
Colin Cross0ea8ba82019-06-06 14:33:29 -07001655func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001656 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001657}
1658
Colin Cross0ea8ba82019-06-06 14:33:29 -07001659func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001660 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001661}
1662
Colin Cross0ea8ba82019-06-06 14:33:29 -07001663func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001664 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001665}
1666
Colin Cross0ea8ba82019-06-06 14:33:29 -07001667func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001668 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001669}
1670
Colin Cross0ea8ba82019-06-06 14:33:29 -07001671func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001672 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001673}
1674
Colin Cross0ea8ba82019-06-06 14:33:29 -07001675func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001676 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001677}
1678
Colin Cross0ea8ba82019-06-06 14:33:29 -07001679func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001680 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001681}
1682
Colin Cross0ea8ba82019-06-06 14:33:29 -07001683func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001684 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001685}
1686
Colin Cross0ea8ba82019-06-06 14:33:29 -07001687func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001688 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001689 return true
1690 }
Colin Cross25de6c32019-06-06 14:29:25 -07001691 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001692}
1693
Jiyong Park5baac542018-08-28 09:55:37 +09001694// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001695// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001696func (m *ModuleBase) MakeAsPlatform() {
1697 m.commonProperties.Vendor = boolPtr(false)
1698 m.commonProperties.Proprietary = boolPtr(false)
1699 m.commonProperties.Soc_specific = boolPtr(false)
1700 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001701 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001702}
1703
Colin Cross4157e882019-06-06 16:57:04 -07001704func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1705 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001706}
1707
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001708func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001709 m.commonProperties.Vendor = boolPtr(false)
1710 m.commonProperties.Proprietary = boolPtr(false)
1711 m.commonProperties.Soc_specific = boolPtr(false)
1712 m.commonProperties.Product_specific = boolPtr(false)
1713 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001714}
1715
Jooyung Han344d5432019-08-23 11:17:39 +09001716// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1717func (m *ModuleBase) IsNativeBridgeSupported() bool {
1718 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1719}
1720
Colin Cross25de6c32019-06-06 14:29:25 -07001721func (m *moduleContext) InstallInData() bool {
1722 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001723}
1724
Jaewoong Jung0949f312019-09-11 10:25:18 -07001725func (m *moduleContext) InstallInTestcases() bool {
1726 return m.module.InstallInTestcases()
1727}
1728
Colin Cross25de6c32019-06-06 14:29:25 -07001729func (m *moduleContext) InstallInSanitizerDir() bool {
1730 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001731}
1732
Yifan Hong1b3348d2020-01-21 15:53:22 -08001733func (m *moduleContext) InstallInRamdisk() bool {
1734 return m.module.InstallInRamdisk()
1735}
1736
Colin Cross25de6c32019-06-06 14:29:25 -07001737func (m *moduleContext) InstallInRecovery() bool {
1738 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001739}
1740
Colin Cross90ba5f42019-10-02 11:10:58 -07001741func (m *moduleContext) InstallInRoot() bool {
1742 return m.module.InstallInRoot()
1743}
1744
Colin Cross607d8582019-07-29 16:44:46 -07001745func (m *moduleContext) InstallBypassMake() bool {
1746 return m.module.InstallBypassMake()
1747}
1748
Colin Cross70dda7e2019-10-01 22:05:35 -07001749func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001750 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001751 return true
1752 }
1753
Colin Cross3607f212018-05-07 15:28:05 -07001754 // We'll need a solution for choosing which of modules with the same name in different
1755 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1756 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001757 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001758 return true
1759 }
1760
Colin Cross25de6c32019-06-06 14:29:25 -07001761 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001762 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001763 return true
1764 }
1765
Colin Cross25de6c32019-06-06 14:29:25 -07001766 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001767 return true
1768 }
1769 }
1770
1771 return false
1772}
1773
Colin Cross70dda7e2019-10-01 22:05:35 -07001774func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1775 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001776 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001777}
1778
Colin Cross70dda7e2019-10-01 22:05:35 -07001779func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1780 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001781 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001782}
1783
Colin Cross70dda7e2019-10-01 22:05:35 -07001784func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1785 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001786
Colin Cross25de6c32019-06-06 14:29:25 -07001787 fullInstallPath := installPath.Join(m, name)
1788 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001789
Colin Cross25de6c32019-06-06 14:29:25 -07001790 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001791
Colin Cross25de6c32019-06-06 14:29:25 -07001792 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001793
Colin Cross89562dc2016-10-03 17:47:19 -07001794 var implicitDeps, orderOnlyDeps Paths
1795
Colin Cross25de6c32019-06-06 14:29:25 -07001796 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001797 // Installed host modules might be used during the build, depend directly on their
1798 // dependencies so their timestamp is updated whenever their dependency is updated
1799 implicitDeps = deps
1800 } else {
1801 orderOnlyDeps = deps
1802 }
1803
Colin Cross25de6c32019-06-06 14:29:25 -07001804 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001805 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001806 Description: "install " + fullInstallPath.Base(),
1807 Output: fullInstallPath,
1808 Input: srcPath,
1809 Implicits: implicitDeps,
1810 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001811 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001812 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001813
Colin Cross25de6c32019-06-06 14:29:25 -07001814 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001815 }
Colin Cross25de6c32019-06-06 14:29:25 -07001816 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001817 return fullInstallPath
1818}
1819
Colin Cross70dda7e2019-10-01 22:05:35 -07001820func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001821 fullInstallPath := installPath.Join(m, name)
1822 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001823
Colin Cross25de6c32019-06-06 14:29:25 -07001824 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001825
Alex Lightfb4353d2019-01-17 13:57:45 -08001826 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1827 if err != nil {
1828 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1829 }
Colin Cross25de6c32019-06-06 14:29:25 -07001830 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001831 Rule: Symlink,
1832 Description: "install symlink " + fullInstallPath.Base(),
1833 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08001834 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001835 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001836 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001837 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001838 },
1839 })
Colin Cross3854a602016-01-11 12:49:11 -08001840
Colin Cross25de6c32019-06-06 14:29:25 -07001841 m.installFiles = append(m.installFiles, fullInstallPath)
1842 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001843 }
Colin Cross3854a602016-01-11 12:49:11 -08001844 return fullInstallPath
1845}
1846
Jiyong Parkf1194352019-02-25 11:05:47 +09001847// installPath/name -> absPath where absPath might be a path that is available only at runtime
1848// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001849func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001850 fullInstallPath := installPath.Join(m, name)
1851 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001852
Colin Cross25de6c32019-06-06 14:29:25 -07001853 if !m.skipInstall(fullInstallPath) {
1854 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001855 Rule: Symlink,
1856 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1857 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001858 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001859 Args: map[string]string{
1860 "fromPath": absPath,
1861 },
1862 })
1863
Colin Cross25de6c32019-06-06 14:29:25 -07001864 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001865 }
1866 return fullInstallPath
1867}
1868
Colin Cross25de6c32019-06-06 14:29:25 -07001869func (m *moduleContext) CheckbuildFile(srcPath Path) {
1870 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001871}
1872
Colin Cross3f40fa42015-01-30 17:27:36 -08001873type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001874 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001875}
1876
1877func isFileInstaller(m blueprint.Module) bool {
1878 _, ok := m.(fileInstaller)
1879 return ok
1880}
1881
1882func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001883 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001884 return ok
1885}
Colin Crossfce53272015-04-08 11:21:40 -07001886
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001887func findStringInSlice(str string, slice []string) int {
1888 for i, s := range slice {
1889 if s == str {
1890 return i
Colin Crossfce53272015-04-08 11:21:40 -07001891 }
1892 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001893 return -1
1894}
1895
Colin Cross41955e82019-05-29 14:40:35 -07001896// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1897// was not a module reference.
1898func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001899 if len(s) > 1 && s[0] == ':' {
1900 return s[1:]
1901 }
1902 return ""
1903}
1904
Colin Cross41955e82019-05-29 14:40:35 -07001905// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1906// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1907func SrcIsModuleWithTag(s string) (module, tag string) {
1908 if len(s) > 1 && s[0] == ':' {
1909 module = s[1:]
1910 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1911 if module[len(module)-1] == '}' {
1912 tag = module[tagStart+1 : len(module)-1]
1913 module = module[:tagStart]
1914 return module, tag
1915 }
1916 }
1917 return module, ""
1918 }
1919 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001920}
1921
Colin Cross41955e82019-05-29 14:40:35 -07001922type sourceOrOutputDependencyTag struct {
1923 blueprint.BaseDependencyTag
1924 tag string
1925}
1926
1927func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1928 return sourceOrOutputDependencyTag{tag: tag}
1929}
1930
1931var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001932
Colin Cross366938f2017-12-11 16:29:02 -08001933// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1934// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001935//
1936// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001937func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001938 set := make(map[string]bool)
1939
Colin Cross068e0fe2016-12-13 15:23:47 -08001940 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001941 if m, t := SrcIsModuleWithTag(s); m != "" {
1942 if _, found := set[s]; found {
1943 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001944 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001945 set[s] = true
1946 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001947 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001948 }
1949 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001950}
1951
Colin Cross366938f2017-12-11 16:29:02 -08001952// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1953// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001954//
1955// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001956func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1957 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001958 if m, t := SrcIsModuleWithTag(*s); m != "" {
1959 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001960 }
1961 }
1962}
1963
Colin Cross41955e82019-05-29 14:40:35 -07001964// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1965// 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 -08001966type SourceFileProducer interface {
1967 Srcs() Paths
1968}
1969
Colin Cross41955e82019-05-29 14:40:35 -07001970// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00001971// 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 -07001972// listed in the property.
1973type OutputFileProducer interface {
1974 OutputFiles(tag string) (Paths, error)
1975}
1976
Colin Cross5e708052019-08-06 13:59:50 -07001977// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
1978// module produced zero paths, it reports errors to the ctx and returns nil.
1979func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
1980 paths, err := outputFilesForModule(ctx, module, tag)
1981 if err != nil {
1982 reportPathError(ctx, err)
1983 return nil
1984 }
1985 return paths
1986}
1987
1988// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
1989// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
1990func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
1991 paths, err := outputFilesForModule(ctx, module, tag)
1992 if err != nil {
1993 reportPathError(ctx, err)
1994 return nil
1995 }
1996 if len(paths) > 1 {
1997 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
1998 pathContextName(ctx, module))
1999 return nil
2000 }
2001 return paths[0]
2002}
2003
2004func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2005 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2006 paths, err := outputFileProducer.OutputFiles(tag)
2007 if err != nil {
2008 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2009 pathContextName(ctx, module), err.Error())
2010 }
2011 if len(paths) == 0 {
2012 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2013 }
2014 return paths, nil
2015 } else {
2016 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2017 }
2018}
2019
Colin Crossfe17f6f2019-03-28 19:30:56 -07002020type HostToolProvider interface {
2021 HostToolPath() OptionalPath
2022}
2023
Colin Cross27b922f2019-03-04 22:35:41 -08002024// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2025// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002026//
2027// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002028func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2029 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002030}
2031
Colin Cross2fafa3e2019-03-05 12:39:51 -08002032// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2033// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002034//
2035// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002036func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2037 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002038}
2039
2040// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2041// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2042// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002043func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002044 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002045 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002046 }
2047 return OptionalPath{}
2048}
2049
Colin Cross25de6c32019-06-06 14:29:25 -07002050func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002051 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002052}
2053
Colin Cross25de6c32019-06-06 14:29:25 -07002054func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002055 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002056}
2057
Colin Cross25de6c32019-06-06 14:29:25 -07002058func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002059 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002060}
2061
Colin Cross463a90e2015-06-17 14:20:06 -07002062func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002063 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002064}
2065
Colin Cross0875c522017-11-28 17:34:01 -08002066func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002067 return &buildTargetSingleton{}
2068}
2069
Colin Cross87d8b562017-04-25 10:01:55 -07002070func parentDir(dir string) string {
2071 dir, _ = filepath.Split(dir)
2072 return filepath.Clean(dir)
2073}
2074
Colin Cross1f8c52b2015-06-16 16:38:17 -07002075type buildTargetSingleton struct{}
2076
Colin Cross0875c522017-11-28 17:34:01 -08002077func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2078 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002079
Colin Cross0875c522017-11-28 17:34:01 -08002080 mmTarget := func(dir string) WritablePath {
2081 return PathForPhony(ctx,
2082 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07002083 }
2084
Colin Cross0875c522017-11-28 17:34:01 -08002085 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002086
Colin Cross0875c522017-11-28 17:34:01 -08002087 ctx.VisitAllModules(func(module Module) {
2088 blueprintDir := module.base().blueprintDir
2089 installTarget := module.base().installTarget
2090 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002091
Colin Cross0875c522017-11-28 17:34:01 -08002092 if checkbuildTarget != nil {
2093 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2094 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2095 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002096
Colin Cross0875c522017-11-28 17:34:01 -08002097 if installTarget != nil {
2098 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002099 }
2100 })
2101
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002102 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002103 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002104 suffix = "-soong"
2105 }
2106
Colin Cross1f8c52b2015-06-16 16:38:17 -07002107 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08002108 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002109 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002110 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002111 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07002112 })
2113
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002114 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002115 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002116 return
2117 }
2118
Colin Cross87d8b562017-04-25 10:01:55 -07002119 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002120 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002121 for _, dir := range dirs {
2122 dir := parentDir(dir)
2123 for dir != "." && dir != "/" {
2124 if _, exists := modulesInDir[dir]; exists {
2125 break
2126 }
2127 modulesInDir[dir] = nil
2128 dir = parentDir(dir)
2129 }
2130 }
2131
2132 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002133 for _, dir := range dirs {
2134 p := parentDir(dir)
2135 if p != "." && p != "/" {
2136 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2137 }
2138 }
2139
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002140 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2141 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2142 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002143 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002144 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002145 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002146 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002147 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002148 // HACK: checkbuild should be an optional build, but force it
2149 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002150 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002151 })
2152 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002153
2154 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2155 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002156 ctx.VisitAllModules(func(module Module) {
2157 if module.Enabled() {
2158 os := module.Target().Os
2159 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002160 }
2161 })
2162
Colin Cross0875c522017-11-28 17:34:01 -08002163 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002164 for os, deps := range osDeps {
2165 var className string
2166
2167 switch os.Class {
2168 case Host:
2169 className = "host"
2170 case HostCross:
2171 className = "host-cross"
2172 case Device:
2173 className = "target"
2174 default:
2175 continue
2176 }
2177
Colin Cross0875c522017-11-28 17:34:01 -08002178 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002179 osClass[className] = append(osClass[className], name)
2180
Colin Cross0875c522017-11-28 17:34:01 -08002181 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002182 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002183 Output: name,
2184 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002185 })
2186 }
2187
2188 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002189 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002190 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002191 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002192 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002193 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002194 })
2195 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002196}
Colin Crossd779da42015-12-17 18:00:23 -08002197
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002198// Collect information for opening IDE project files in java/jdeps.go.
2199type IDEInfo interface {
2200 IDEInfo(ideInfo *IdeInfo)
2201 BaseModuleName() string
2202}
2203
2204// Extract the base module name from the Import name.
2205// Often the Import name has a prefix "prebuilt_".
2206// Remove the prefix explicitly if needed
2207// until we find a better solution to get the Import name.
2208type IDECustomizedModuleName interface {
2209 IDECustomizedModuleName() string
2210}
2211
2212type IdeInfo struct {
2213 Deps []string `json:"dependencies,omitempty"`
2214 Srcs []string `json:"srcs,omitempty"`
2215 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2216 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2217 Jars []string `json:"jars,omitempty"`
2218 Classes []string `json:"class,omitempty"`
2219 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002220 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002221}