blob: d0edf3be68ab3395e8a3c935094c5c8d02578245 [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
Paul Duffinb0cbec32020-02-25 19:26:33 +0000452 // If set to true then a CommonOS variant will be created which will have dependencies
453 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
454 // that covers all os and architecture variants.
455 //
456 // The OsType specific variants can be retrieved by calling
457 // GetOsSpecificVariantsOfCommonOSVariant
458 //
459 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
460 CreateCommonOSVariant bool `blueprint:"mutated"`
461
462 // If set to true then this variant is the CommonOS variant that has dependencies on its
463 // OsType specific variants.
464 //
465 // Set by osMutator.
466 CommonOSVariant bool `blueprint:"mutated"`
467
Colin Crossce75d2c2016-10-06 16:12:58 -0700468 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800469
470 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700471
472 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700473
474 // Name and variant strings stored by mutators to enable Module.String()
475 DebugName string `blueprint:"mutated"`
476 DebugMutators []string `blueprint:"mutated"`
477 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800478
479 // set by ImageMutator
480 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800481}
482
483type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800484 // If set to true, build a variant of the module for the host. Defaults to false.
485 Host_supported *bool
486
487 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700488 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800489}
490
Colin Crossc472d572015-03-17 15:06:21 -0700491type Multilib string
492
493const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800494 MultilibBoth Multilib = "both"
495 MultilibFirst Multilib = "first"
496 MultilibCommon Multilib = "common"
497 MultilibCommonFirst Multilib = "common_first"
498 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700499)
500
Colin Crossa1ad8d12016-06-01 17:09:44 -0700501type HostOrDeviceSupported int
502
503const (
504 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700505
506 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700507 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700508
509 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700510 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700511
512 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700513 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700514
515 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700516 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700517
518 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700519 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700520
521 // Nothing is supported. This is not exposed to the user, but used to mark a
522 // host only module as unsupported when the module type is not supported on
523 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700524 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700525)
526
Jiyong Park2db76922017-11-08 16:03:48 +0900527type moduleKind int
528
529const (
530 platformModule moduleKind = iota
531 deviceSpecificModule
532 socSpecificModule
533 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900534 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900535)
536
537func (k moduleKind) String() string {
538 switch k {
539 case platformModule:
540 return "platform"
541 case deviceSpecificModule:
542 return "device-specific"
543 case socSpecificModule:
544 return "soc-specific"
545 case productSpecificModule:
546 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900547 case systemExtSpecificModule:
548 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900549 default:
550 panic(fmt.Errorf("unknown module kind %d", k))
551 }
552}
553
Colin Cross9d34f352019-11-22 16:03:51 -0800554func initAndroidModuleBase(m Module) {
555 m.base().module = m
556}
557
Colin Cross36242852017-06-23 15:06:31 -0700558func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800559 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800560 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700561
Colin Cross36242852017-06-23 15:06:31 -0700562 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700563 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700564 &base.commonProperties)
565
Colin Crosseabaedd2020-02-06 17:01:55 -0800566 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700567
Colin Crossa3a97412019-03-18 12:24:29 -0700568 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700569 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100570
571 // The default_visibility property needs to be checked and parsed by the visibility module during
572 // its checking and parsing phases.
573 base.primaryVisibilityProperty =
574 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
575 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700576}
577
Colin Cross36242852017-06-23 15:06:31 -0700578func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
579 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700580
581 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800582 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700583 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700584 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700585 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800586
Dan Willemsen218f6562015-07-08 18:13:11 -0700587 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700588 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700589 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800590 }
591
Colin Cross36242852017-06-23 15:06:31 -0700592 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800593}
594
Colin Crossee0bc3b2018-10-02 22:01:37 -0700595func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
596 InitAndroidArchModule(m, hod, defaultMultilib)
597 m.base().commonProperties.UseTargetVariants = false
598}
599
Paul Duffinb0cbec32020-02-25 19:26:33 +0000600// As InitAndroidMultiTargetsArchModule except it creates an additional CommonOS variant that
601// has dependencies on all the OsType specific variants.
602func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
603 InitAndroidArchModule(m, hod, defaultMultilib)
604 m.base().commonProperties.UseTargetVariants = false
605 m.base().commonProperties.CreateCommonOSVariant = true
606}
607
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800608// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800609// modules. It should be included as an anonymous field in every module
610// struct definition. InitAndroidModule should then be called from the module's
611// factory function, and the return values from InitAndroidModule should be
612// returned from the factory function.
613//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800614// The ModuleBase type is responsible for implementing the GenerateBuildActions
615// method to support the blueprint.Module interface. This method will then call
616// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700617// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
618// rather than the usual blueprint.ModuleContext.
619// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800620// system including details about the particular build variant that is to be
621// generated.
622//
623// For example:
624//
625// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800626// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800627// )
628//
629// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800630// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800631// properties struct {
632// MyProperty string
633// }
634// }
635//
Colin Cross36242852017-06-23 15:06:31 -0700636// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800637// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700638// m.AddProperties(&m.properties)
639// android.InitAndroidModule(m)
640// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800641// }
642//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800643// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800644// // Get the CPU architecture for the current build variant.
645// variantArch := ctx.Arch()
646//
647// // ...
648// }
Colin Cross635c3b02016-05-18 15:37:25 -0700649type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800650 // Putting the curiously recurring thing pointing to the thing that contains
651 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700652 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700653 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800654
Colin Crossfc754582016-05-17 16:34:16 -0700655 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800656 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700657 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800658 hostAndDeviceProperties hostAndDeviceProperties
659 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700660 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700661 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800662
Paul Duffin63c6e182019-07-24 14:24:38 +0100663 // Information about all the properties on the module that contains visibility rules that need
664 // checking.
665 visibilityPropertyInfo []visibilityProperty
666
667 // The primary visibility property, may be nil, that controls access to the module.
668 primaryVisibilityProperty visibilityProperty
669
Colin Cross3f40fa42015-01-30 17:27:36 -0800670 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700671 installFiles Paths
672 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900673 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700674
675 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
676 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800677 installTarget WritablePath
678 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700679 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700680
Colin Cross178a5092016-09-13 13:42:32 -0700681 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700682
683 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700684
685 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700686 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800687 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800688 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700689
Inseob Kim8471cda2019-11-15 09:59:12 +0900690 initRcPaths Paths
691 vintfFragmentsPaths Paths
692
Colin Crossa9d8bee2018-10-02 13:59:46 -0700693 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700694}
695
Colin Cross4157e882019-06-06 16:57:04 -0700696func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800697
Colin Cross4157e882019-06-06 16:57:04 -0700698func (m *ModuleBase) AddProperties(props ...interface{}) {
699 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700700}
701
Colin Cross4157e882019-06-06 16:57:04 -0700702func (m *ModuleBase) GetProperties() []interface{} {
703 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800704}
705
Colin Cross4157e882019-06-06 16:57:04 -0700706func (m *ModuleBase) BuildParamsForTests() []BuildParams {
707 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700708}
709
Colin Cross4157e882019-06-06 16:57:04 -0700710func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
711 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800712}
713
Colin Cross4157e882019-06-06 16:57:04 -0700714func (m *ModuleBase) VariablesForTests() map[string]string {
715 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800716}
717
Colin Cross4157e882019-06-06 16:57:04 -0700718func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
719 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700720}
721
Colin Crossce75d2c2016-10-06 16:12:58 -0700722// Name returns the name of the module. It may be overridden by individual module types, for
723// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700724func (m *ModuleBase) Name() string {
725 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700726}
727
Colin Cross9a362232019-07-01 15:32:45 -0700728// String returns a string that includes the module name and variants for printing during debugging.
729func (m *ModuleBase) String() string {
730 sb := strings.Builder{}
731 sb.WriteString(m.commonProperties.DebugName)
732 sb.WriteString("{")
733 for i := range m.commonProperties.DebugMutators {
734 if i != 0 {
735 sb.WriteString(",")
736 }
737 sb.WriteString(m.commonProperties.DebugMutators[i])
738 sb.WriteString(":")
739 sb.WriteString(m.commonProperties.DebugVariations[i])
740 }
741 sb.WriteString("}")
742 return sb.String()
743}
744
Colin Crossce75d2c2016-10-06 16:12:58 -0700745// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700746func (m *ModuleBase) BaseModuleName() string {
747 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700748}
749
Colin Cross4157e882019-06-06 16:57:04 -0700750func (m *ModuleBase) base() *ModuleBase {
751 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800752}
753
Paul Duffine2453c72019-05-31 14:00:04 +0100754func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
755 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
756}
757
758func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100759 return m.visibilityPropertyInfo
760}
761
762func (m *ModuleBase) visibility() []string {
763 // The soong_namespace module does not initialize the primaryVisibilityProperty.
764 if m.primaryVisibilityProperty != nil {
765 return m.primaryVisibilityProperty.getStrings()
766 } else {
767 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100768 }
769}
770
Colin Cross4157e882019-06-06 16:57:04 -0700771func (m *ModuleBase) Target() Target {
772 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800773}
774
Colin Cross4157e882019-06-06 16:57:04 -0700775func (m *ModuleBase) TargetPrimary() bool {
776 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700777}
778
Colin Cross4157e882019-06-06 16:57:04 -0700779func (m *ModuleBase) MultiTargets() []Target {
780 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700781}
782
Colin Cross4157e882019-06-06 16:57:04 -0700783func (m *ModuleBase) Os() OsType {
784 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800785}
786
Colin Cross4157e882019-06-06 16:57:04 -0700787func (m *ModuleBase) Host() bool {
788 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800789}
790
Colin Cross4157e882019-06-06 16:57:04 -0700791func (m *ModuleBase) Arch() Arch {
792 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800793}
794
Colin Cross4157e882019-06-06 16:57:04 -0700795func (m *ModuleBase) ArchSpecific() bool {
796 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700797}
798
Paul Duffinb0cbec32020-02-25 19:26:33 +0000799// True if the current variant is a CommonOS variant, false otherwise.
800func (m *ModuleBase) IsCommonOSVariant() bool {
801 return m.commonProperties.CommonOSVariant
802}
803
Colin Cross4157e882019-06-06 16:57:04 -0700804func (m *ModuleBase) OsClassSupported() []OsClass {
805 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700806 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700807 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700808 case HostSupportedNoCross:
809 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700810 case DeviceSupported:
811 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700812 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700813 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700814 if Bool(m.hostAndDeviceProperties.Host_supported) ||
815 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
816 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700817 supported = append(supported, Host, HostCross)
818 }
Colin Cross4157e882019-06-06 16:57:04 -0700819 if m.hostAndDeviceProperties.Device_supported == nil ||
820 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700821 supported = append(supported, Device)
822 }
823 return supported
824 default:
825 return nil
826 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800827}
828
Colin Cross4157e882019-06-06 16:57:04 -0700829func (m *ModuleBase) DeviceSupported() bool {
830 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
831 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
832 (m.hostAndDeviceProperties.Device_supported == nil ||
833 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800834}
835
Paul Duffine44358f2019-11-26 18:04:12 +0000836func (m *ModuleBase) HostSupported() bool {
837 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
838 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
839 (m.hostAndDeviceProperties.Host_supported != nil &&
840 *m.hostAndDeviceProperties.Host_supported)
841}
842
Colin Cross4157e882019-06-06 16:57:04 -0700843func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900844 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900845}
846
Colin Cross4157e882019-06-06 16:57:04 -0700847func (m *ModuleBase) DeviceSpecific() bool {
848 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900849}
850
Colin Cross4157e882019-06-06 16:57:04 -0700851func (m *ModuleBase) SocSpecific() bool {
852 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900853}
854
Colin Cross4157e882019-06-06 16:57:04 -0700855func (m *ModuleBase) ProductSpecific() bool {
856 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900857}
858
Justin Yund5f6c822019-06-25 16:47:17 +0900859func (m *ModuleBase) SystemExtSpecific() bool {
860 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100861}
862
Bill Peckham1c610cf2020-03-20 18:33:20 -0700863func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
864 partition := "system"
865 if m.SocSpecific() {
866 // A SoC-specific module could be on the vendor partition at
867 // "vendor" or the system partition at "system/vendor".
868 if config.VendorPath() == "vendor" {
869 partition = "vendor"
870 }
871 } else if m.DeviceSpecific() {
872 // A device-specific module could be on the odm partition at
873 // "odm", the vendor partition at "vendor/odm", or the system
874 // partition at "system/vendor/odm".
875 if config.OdmPath() == "odm" {
876 partition = "odm"
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000877 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckham1c610cf2020-03-20 18:33:20 -0700878 partition = "vendor"
879 }
880 } else if m.ProductSpecific() {
881 // A product-specific module could be on the product partition
882 // at "product" or the system partition at "system/product".
883 if config.ProductPath() == "product" {
884 partition = "product"
885 }
886 } else if m.SystemExtSpecific() {
887 // A system_ext-specific module could be on the system_ext
888 // partition at "system_ext" or the system partition at
889 // "system/system_ext".
890 if config.SystemExtPath() == "system_ext" {
891 partition = "system_ext"
892 }
893 }
894 return partition
895}
896
Colin Cross4157e882019-06-06 16:57:04 -0700897func (m *ModuleBase) Enabled() bool {
898 if m.commonProperties.Enabled == nil {
899 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800900 }
Colin Cross4157e882019-06-06 16:57:04 -0700901 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800902}
903
Inseob Kimeec88e12020-01-22 11:11:29 +0900904func (m *ModuleBase) Disable() {
905 m.commonProperties.Enabled = proptools.BoolPtr(false)
906}
907
Colin Cross4157e882019-06-06 16:57:04 -0700908func (m *ModuleBase) SkipInstall() {
909 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700910}
911
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000912func (m *ModuleBase) IsSkipInstall() bool {
913 return m.commonProperties.SkipInstall == true
914}
915
Colin Cross4157e882019-06-06 16:57:04 -0700916func (m *ModuleBase) ExportedToMake() bool {
917 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900918}
919
Colin Cross4157e882019-06-06 16:57:04 -0700920func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700921 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800922
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700923 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700924 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800925 ctx.VisitDepsDepthFirstIf(isFileInstaller,
926 func(m blueprint.Module) {
927 fileInstaller := m.(fileInstaller)
928 files := fileInstaller.filesToInstall()
929 result = append(result, files...)
930 })
931
932 return result
933}
934
Colin Cross4157e882019-06-06 16:57:04 -0700935func (m *ModuleBase) filesToInstall() Paths {
936 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800937}
938
Colin Cross4157e882019-06-06 16:57:04 -0700939func (m *ModuleBase) NoAddressSanitizer() bool {
940 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800941}
942
Colin Cross4157e882019-06-06 16:57:04 -0700943func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800944 return false
945}
946
Jaewoong Jung0949f312019-09-11 10:25:18 -0700947func (m *ModuleBase) InstallInTestcases() bool {
948 return false
949}
950
Colin Cross4157e882019-06-06 16:57:04 -0700951func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700952 return false
953}
954
Yifan Hong1b3348d2020-01-21 15:53:22 -0800955func (m *ModuleBase) InstallInRamdisk() bool {
956 return Bool(m.commonProperties.Ramdisk)
957}
958
Colin Cross4157e882019-06-06 16:57:04 -0700959func (m *ModuleBase) InstallInRecovery() bool {
960 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900961}
962
Colin Cross90ba5f42019-10-02 11:10:58 -0700963func (m *ModuleBase) InstallInRoot() bool {
964 return false
965}
966
Colin Cross607d8582019-07-29 16:44:46 -0700967func (m *ModuleBase) InstallBypassMake() bool {
968 return false
969}
970
Colin Cross4157e882019-06-06 16:57:04 -0700971func (m *ModuleBase) Owner() string {
972 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900973}
974
Colin Cross4157e882019-06-06 16:57:04 -0700975func (m *ModuleBase) NoticeFile() OptionalPath {
976 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900977}
978
Colin Cross7228ecd2019-11-18 16:00:16 -0800979func (m *ModuleBase) setImageVariation(variant string) {
980 m.commonProperties.ImageVariation = variant
981}
982
983func (m *ModuleBase) ImageVariation() blueprint.Variation {
984 return blueprint.Variation{
985 Mutator: "image",
986 Variation: m.base().commonProperties.ImageVariation,
987 }
988}
989
Yifan Hong1b3348d2020-01-21 15:53:22 -0800990func (m *ModuleBase) InRamdisk() bool {
991 return m.base().commonProperties.ImageVariation == RamdiskVariation
992}
993
Colin Cross7228ecd2019-11-18 16:00:16 -0800994func (m *ModuleBase) InRecovery() bool {
995 return m.base().commonProperties.ImageVariation == RecoveryVariation
996}
997
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900998func (m *ModuleBase) RequiredModuleNames() []string {
999 return m.base().commonProperties.Required
1000}
1001
1002func (m *ModuleBase) HostRequiredModuleNames() []string {
1003 return m.base().commonProperties.Host_required
1004}
1005
1006func (m *ModuleBase) TargetRequiredModuleNames() []string {
1007 return m.base().commonProperties.Target_required
1008}
1009
Inseob Kim8471cda2019-11-15 09:59:12 +09001010func (m *ModuleBase) InitRc() Paths {
1011 return append(Paths{}, m.initRcPaths...)
1012}
1013
1014func (m *ModuleBase) VintfFragments() Paths {
1015 return append(Paths{}, m.vintfFragmentsPaths...)
1016}
1017
Colin Cross4157e882019-06-06 16:57:04 -07001018func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001019 allInstalledFiles := Paths{}
1020 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001021 ctx.VisitAllModuleVariants(func(module Module) {
1022 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001023 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1024 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001025 })
1026
Colin Cross0875c522017-11-28 17:34:01 -08001027 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001028
Jeff Gaston088e29e2017-11-29 16:47:17 -08001029 namespacePrefix := ctx.Namespace().(*Namespace).id
1030 if namespacePrefix != "" {
1031 namespacePrefix = namespacePrefix + "-"
1032 }
1033
Colin Cross3f40fa42015-01-30 17:27:36 -08001034 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -08001035 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -08001036 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001037 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001038 Output: name,
1039 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -08001040 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -07001041 })
1042 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -07001043 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -07001044 }
1045
1046 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -08001047 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -08001048 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001049 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001050 Output: name,
1051 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -07001052 })
1053 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -07001054 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -07001055 }
1056
1057 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001058 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001059 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001060 suffix = "-soong"
1061 }
1062
Jeff Gaston088e29e2017-11-29 16:47:17 -08001063 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -08001064 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001065 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -08001066 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -07001067 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -08001068 })
Colin Cross1f8c52b2015-06-16 16:38:17 -07001069
Colin Cross4157e882019-06-06 16:57:04 -07001070 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001071 }
1072}
1073
Colin Crossc34d2322020-01-03 15:23:27 -08001074func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001075 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1076 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1077 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001078 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001079
Dario Frenifd05a742018-05-29 13:28:54 +01001080 msg := "conflicting value set here"
1081 if socSpecific && deviceSpecific {
1082 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001083 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001084 ctx.PropertyErrorf("vendor", msg)
1085 }
Colin Cross4157e882019-06-06 16:57:04 -07001086 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001087 ctx.PropertyErrorf("proprietary", msg)
1088 }
Colin Cross4157e882019-06-06 16:57:04 -07001089 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001090 ctx.PropertyErrorf("soc_specific", msg)
1091 }
1092 }
1093
Justin Yund5f6c822019-06-25 16:47:17 +09001094 if productSpecific && systemExtSpecific {
1095 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1096 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001097 }
1098
Justin Yund5f6c822019-06-25 16:47:17 +09001099 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001100 if productSpecific {
1101 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1102 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001103 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 +01001104 }
1105 if deviceSpecific {
1106 ctx.PropertyErrorf("device_specific", msg)
1107 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001108 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001109 ctx.PropertyErrorf("vendor", msg)
1110 }
Colin Cross4157e882019-06-06 16:57:04 -07001111 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001112 ctx.PropertyErrorf("proprietary", msg)
1113 }
Colin Cross4157e882019-06-06 16:57:04 -07001114 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001115 ctx.PropertyErrorf("soc_specific", msg)
1116 }
1117 }
1118 }
1119
Jiyong Park2db76922017-11-08 16:03:48 +09001120 if productSpecific {
1121 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001122 } else if systemExtSpecific {
1123 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001124 } else if deviceSpecific {
1125 return deviceSpecificModule
1126 } else if socSpecific {
1127 return socSpecificModule
1128 } else {
1129 return platformModule
1130 }
1131}
1132
Colin Crossc34d2322020-01-03 15:23:27 -08001133func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001134 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001135 EarlyModuleContext: ctx,
1136 kind: determineModuleKind(m, ctx),
1137 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001138 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001139}
1140
Colin Cross1184b642019-12-30 18:43:07 -08001141func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1142 return baseModuleContext{
1143 bp: ctx,
1144 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1145 os: m.commonProperties.CompileOS,
1146 target: m.commonProperties.CompileTarget,
1147 targetPrimary: m.commonProperties.CompilePrimary,
1148 multiTargets: m.commonProperties.CompileMultiTargets,
1149 }
1150}
1151
Colin Cross4157e882019-06-06 16:57:04 -07001152func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001153 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001154 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001155 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001156 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1157 installDeps: m.computeInstallDeps(blueprintCtx),
1158 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001159 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001160 }
1161
Colin Cross6c4f21f2019-06-06 15:41:36 -07001162 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1163 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1164 // TODO: This will be removed once defaults modules handle missing dependency errors
1165 blueprintCtx.GetMissingDependencies()
1166
Colin Crossdc35e212019-06-06 16:13:11 -07001167 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffinb0cbec32020-02-25 19:26:33 +00001168 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1169 // (because the dependencies are added before the modules are disabled). The
1170 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1171 // ignored.
1172 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001173
Colin Cross4c83e5c2019-02-25 14:54:28 -08001174 if ctx.config.captureBuild {
1175 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1176 }
1177
Colin Cross67a5c132017-05-09 13:45:28 -07001178 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1179 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001180 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1181 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001182 }
Colin Cross0875c522017-11-28 17:34:01 -08001183 if !ctx.PrimaryArch() {
1184 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001185 }
Dan Willemsenb13a9482020-02-14 11:25:54 -08001186 if apex, ok := m.module.(ApexModule); ok && !apex.IsForPlatform() {
1187 suffix = append(suffix, apex.ApexName())
1188 }
Colin Cross67a5c132017-05-09 13:45:28 -07001189
1190 ctx.Variable(pctx, "moduleDesc", desc)
1191
1192 s := ""
1193 if len(suffix) > 0 {
1194 s = " [" + strings.Join(suffix, " ") + "]"
1195 }
1196 ctx.Variable(pctx, "moduleDescSuffix", s)
1197
Dan Willemsen569edc52018-11-19 09:33:29 -08001198 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001199 if m.commonProperties.Dist.Dest != nil {
1200 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001201 if err != nil {
1202 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1203 }
1204 }
Colin Cross4157e882019-06-06 16:57:04 -07001205 if m.commonProperties.Dist.Dir != nil {
1206 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001207 if err != nil {
1208 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1209 }
1210 }
Colin Cross4157e882019-06-06 16:57:04 -07001211 if m.commonProperties.Dist.Suffix != nil {
1212 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001213 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1214 }
1215 }
1216
Colin Cross4157e882019-06-06 16:57:04 -07001217 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001218 // ensure all direct android.Module deps are enabled
1219 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1220 if _, ok := bm.(Module); ok {
1221 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1222 }
1223 })
1224
Colin Cross4157e882019-06-06 16:57:04 -07001225 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1226 if module := SrcIsModule(notice); module != "" {
1227 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001228 } else {
1229 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001230 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001231 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001232
1233 m.module.GenerateAndroidBuildActions(ctx)
1234 if ctx.Failed() {
1235 return
1236 }
1237
1238 m.installFiles = append(m.installFiles, ctx.installFiles...)
1239 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Inseob Kim8471cda2019-11-15 09:59:12 +09001240 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1241 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
Colin Crossdc35e212019-06-06 16:13:11 -07001242 } else if ctx.Config().AllowMissingDependencies() {
1243 // If the module is not enabled it will not create any build rules, nothing will call
1244 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1245 // and report them as an error even when AllowMissingDependencies = true. Call
1246 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1247 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001248 }
1249
Colin Cross4157e882019-06-06 16:57:04 -07001250 if m == ctx.FinalModule().(Module).base() {
1251 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001252 if ctx.Failed() {
1253 return
1254 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001255 }
Colin Crosscec81712017-07-13 14:43:27 -07001256
Colin Cross4157e882019-06-06 16:57:04 -07001257 m.buildParams = ctx.buildParams
1258 m.ruleParams = ctx.ruleParams
1259 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001260}
1261
Colin Cross1184b642019-12-30 18:43:07 -08001262type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001263 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001264
1265 kind moduleKind
1266 config Config
1267}
1268
1269func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1270 ret, err := e.GlobWithDeps(globPattern, excludes)
1271 if err != nil {
1272 e.ModuleErrorf("glob: %s", err.Error())
1273 }
1274 return pathsForModuleSrcFromFullPath(e, ret, true)
1275}
1276
1277func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1278 ret, err := e.GlobWithDeps(globPattern, excludes)
1279 if err != nil {
1280 e.ModuleErrorf("glob: %s", err.Error())
1281 }
1282 return pathsForModuleSrcFromFullPath(e, ret, false)
1283}
1284
Colin Cross988414c2020-01-11 01:11:46 +00001285func (b *earlyModuleContext) IsSymlink(path Path) bool {
1286 fileInfo, err := b.config.fs.Lstat(path.String())
1287 if err != nil {
1288 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1289 }
1290 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1291}
1292
1293func (b *earlyModuleContext) Readlink(path Path) string {
1294 dest, err := b.config.fs.Readlink(path.String())
1295 if err != nil {
1296 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1297 }
1298 return dest
1299}
1300
Colin Cross1184b642019-12-30 18:43:07 -08001301func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001302 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001303 return module
1304}
1305
1306func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001307 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001308}
1309
1310func (e *earlyModuleContext) AConfig() Config {
1311 return e.config
1312}
1313
1314func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1315 return DeviceConfig{e.config.deviceConfig}
1316}
1317
1318func (e *earlyModuleContext) Platform() bool {
1319 return e.kind == platformModule
1320}
1321
1322func (e *earlyModuleContext) DeviceSpecific() bool {
1323 return e.kind == deviceSpecificModule
1324}
1325
1326func (e *earlyModuleContext) SocSpecific() bool {
1327 return e.kind == socSpecificModule
1328}
1329
1330func (e *earlyModuleContext) ProductSpecific() bool {
1331 return e.kind == productSpecificModule
1332}
1333
1334func (e *earlyModuleContext) SystemExtSpecific() bool {
1335 return e.kind == systemExtSpecificModule
1336}
1337
1338type baseModuleContext struct {
1339 bp blueprint.BaseModuleContext
1340 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001341 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001342 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001343 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001344 targetPrimary bool
1345 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001346
1347 walkPath []Module
1348
1349 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001350}
1351
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +00001352func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
1353 return b.bp.OtherModuleName(m)
1354}
1355func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08001356func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Han67b141d2020-02-26 02:05:18 +09001357 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08001358}
1359func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1360 return b.bp.OtherModuleDependencyTag(m)
1361}
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +00001362func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1363func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
1364 return b.bp.OtherModuleType(m)
1365}
Colin Cross1184b642019-12-30 18:43:07 -08001366
1367func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1368 return b.bp.GetDirectDepWithTag(name, tag)
1369}
1370
Colin Cross25de6c32019-06-06 14:29:25 -07001371type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001372 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001373 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001374 installDeps Paths
1375 installFiles Paths
1376 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001377 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001378
1379 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001380 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001381 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001382 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001383}
1384
Colin Crossb88b3c52019-06-10 15:15:17 -07001385func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1386 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001387 Rule: ErrorRule,
1388 Description: params.Description,
1389 Output: params.Output,
1390 Outputs: params.Outputs,
1391 ImplicitOutput: params.ImplicitOutput,
1392 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001393 Args: map[string]string{
1394 "error": err.Error(),
1395 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001396 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001397}
1398
Colin Cross25de6c32019-06-06 14:29:25 -07001399func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1400 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001401}
1402
Colin Cross0875c522017-11-28 17:34:01 -08001403func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001404 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001405 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001406 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001407 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001408 Outputs: params.Outputs.Strings(),
1409 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1410 Inputs: params.Inputs.Strings(),
1411 Implicits: params.Implicits.Strings(),
1412 OrderOnly: params.OrderOnly.Strings(),
1413 Args: params.Args,
1414 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001415 }
1416
Colin Cross33bfb0a2016-11-21 17:23:08 -08001417 if params.Depfile != nil {
1418 bparams.Depfile = params.Depfile.String()
1419 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001420 if params.Output != nil {
1421 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1422 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001423 if params.ImplicitOutput != nil {
1424 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1425 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001426 if params.Input != nil {
1427 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1428 }
1429 if params.Implicit != nil {
1430 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1431 }
1432
Colin Cross0b9f31f2019-02-28 11:00:01 -08001433 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1434 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1435 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1436 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1437 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1438 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001439
Colin Cross0875c522017-11-28 17:34:01 -08001440 return bparams
1441}
1442
Colin Cross25de6c32019-06-06 14:29:25 -07001443func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1444 if m.config.captureBuild {
1445 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001446 }
1447
Colin Crossdc35e212019-06-06 16:13:11 -07001448 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001449}
1450
Colin Cross25de6c32019-06-06 14:29:25 -07001451func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001452 argNames ...string) blueprint.Rule {
1453
Colin Cross8b8bec32019-11-15 13:18:43 -08001454 if m.config.UseRemoteBuild() && params.Pool == nil {
Ramy Medhatdd0418a2019-11-04 18:16:11 -05001455 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1456 // jobs to the local parallelism value
Colin Cross2e2dbc22019-09-25 13:31:46 -07001457 params.Pool = localPool
1458 }
1459
Colin Crossdc35e212019-06-06 16:13:11 -07001460 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001461
Colin Cross25de6c32019-06-06 14:29:25 -07001462 if m.config.captureBuild {
1463 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001464 }
1465
1466 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001467}
1468
Colin Cross25de6c32019-06-06 14:29:25 -07001469func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001470 if params.Description != "" {
1471 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1472 }
1473
1474 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1475 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1476 m.ModuleName(), strings.Join(missingDeps, ", ")))
1477 }
1478
Colin Cross25de6c32019-06-06 14:29:25 -07001479 if m.config.captureBuild {
1480 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001481 }
1482
Colin Crossdc35e212019-06-06 16:13:11 -07001483 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001484}
Colin Cross25de6c32019-06-06 14:29:25 -07001485func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001486 var missingDeps []string
1487 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001488 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001489 missingDeps = FirstUniqueStrings(missingDeps)
1490 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001491}
1492
Colin Crossdc35e212019-06-06 16:13:11 -07001493func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001494 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001495 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001496 *missingDeps = append(*missingDeps, deps...)
1497 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001498 }
1499}
1500
Colin Crossdc35e212019-06-06 16:13:11 -07001501func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001502 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001503
1504 if !strict {
1505 return aModule
1506 }
1507
Colin Cross380c69a2019-06-10 17:49:58 +00001508 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001509 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001510 return nil
1511 }
1512
1513 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001514 if b.Config().AllowMissingDependencies() {
1515 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001516 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001517 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001518 }
1519 return nil
1520 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001521 return aModule
1522}
1523
Colin Crossdc35e212019-06-06 16:13:11 -07001524func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001525 type dep struct {
1526 mod blueprint.Module
1527 tag blueprint.DependencyTag
1528 }
1529 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001530 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001531 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001532 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001533 if tag == nil || returnedTag == tag {
1534 deps = append(deps, dep{aModule, returnedTag})
1535 }
1536 }
1537 })
1538 if len(deps) == 1 {
1539 return deps[0].mod, deps[0].tag
1540 } else if len(deps) >= 2 {
1541 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001542 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001543 } else {
1544 return nil, nil
1545 }
1546}
1547
Colin Crossdc35e212019-06-06 16:13:11 -07001548func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001549 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001550 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001551 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001552 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001553 deps = append(deps, aModule)
1554 }
1555 }
1556 })
1557 return deps
1558}
1559
Colin Cross25de6c32019-06-06 14:29:25 -07001560func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1561 module, _ := m.getDirectDepInternal(name, tag)
1562 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001563}
1564
Colin Crossdc35e212019-06-06 16:13:11 -07001565func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1566 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001567}
1568
Colin Crossdc35e212019-06-06 16:13:11 -07001569func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001570 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001571}
1572
Colin Crossdc35e212019-06-06 16:13:11 -07001573func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001574 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001575 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001576 visit(aModule)
1577 }
1578 })
1579}
1580
Colin Crossdc35e212019-06-06 16:13:11 -07001581func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001582 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001583 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001584 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001585 visit(aModule)
1586 }
1587 }
1588 })
1589}
1590
Colin Crossdc35e212019-06-06 16:13:11 -07001591func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001592 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001593 // pred
1594 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001595 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001596 return pred(aModule)
1597 } else {
1598 return false
1599 }
1600 },
1601 // visit
1602 func(module blueprint.Module) {
1603 visit(module.(Module))
1604 })
1605}
1606
Colin Crossdc35e212019-06-06 16:13:11 -07001607func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001608 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001609 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001610 visit(aModule)
1611 }
1612 })
1613}
1614
Colin Crossdc35e212019-06-06 16:13:11 -07001615func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001616 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001617 // pred
1618 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001619 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001620 return pred(aModule)
1621 } else {
1622 return false
1623 }
1624 },
1625 // visit
1626 func(module blueprint.Module) {
1627 visit(module.(Module))
1628 })
1629}
1630
Colin Crossdc35e212019-06-06 16:13:11 -07001631func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001632 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001633}
1634
Colin Crossdc35e212019-06-06 16:13:11 -07001635func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1636 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001637 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001638 childAndroidModule, _ := child.(Module)
1639 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001640 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001641 // record walkPath before visit
1642 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1643 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1644 }
1645 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001646 return visit(childAndroidModule, parentAndroidModule)
1647 } else {
1648 return false
1649 }
1650 })
1651}
1652
Colin Crossdc35e212019-06-06 16:13:11 -07001653func (b *baseModuleContext) GetWalkPath() []Module {
1654 return b.walkPath
1655}
1656
Colin Cross25de6c32019-06-06 14:29:25 -07001657func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001658 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001659 visit(module.(Module))
1660 })
1661}
1662
Colin Cross25de6c32019-06-06 14:29:25 -07001663func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001664 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001665}
1666
Colin Cross25de6c32019-06-06 14:29:25 -07001667func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001668 return m.bp.FinalModule().(Module)
1669}
1670
1671func (m *moduleContext) ModuleSubDir() string {
1672 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001673}
1674
Colin Cross0ea8ba82019-06-06 14:33:29 -07001675func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001676 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001677}
1678
Colin Cross0ea8ba82019-06-06 14:33:29 -07001679func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001680 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001681}
1682
Colin Cross0ea8ba82019-06-06 14:33:29 -07001683func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001684 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001685}
1686
Colin Cross0ea8ba82019-06-06 14:33:29 -07001687func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001688 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001689}
1690
Colin Cross0ea8ba82019-06-06 14:33:29 -07001691func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001692 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001693}
1694
Colin Cross0ea8ba82019-06-06 14:33:29 -07001695func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001696 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001697}
1698
Colin Cross0ea8ba82019-06-06 14:33:29 -07001699func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001700 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001701}
1702
Colin Cross0ea8ba82019-06-06 14:33:29 -07001703func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001704 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001705}
1706
Colin Cross0ea8ba82019-06-06 14:33:29 -07001707func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001708 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001709}
1710
Colin Cross0ea8ba82019-06-06 14:33:29 -07001711func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001712 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001713}
1714
Colin Cross0ea8ba82019-06-06 14:33:29 -07001715func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001716 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001717}
1718
Colin Cross0ea8ba82019-06-06 14:33:29 -07001719func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001720 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001721 return true
1722 }
Colin Cross25de6c32019-06-06 14:29:25 -07001723 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001724}
1725
Jiyong Park5baac542018-08-28 09:55:37 +09001726// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001727// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001728func (m *ModuleBase) MakeAsPlatform() {
1729 m.commonProperties.Vendor = boolPtr(false)
1730 m.commonProperties.Proprietary = boolPtr(false)
1731 m.commonProperties.Soc_specific = boolPtr(false)
1732 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001733 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001734}
1735
Colin Cross4157e882019-06-06 16:57:04 -07001736func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1737 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001738}
1739
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001740func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001741 m.commonProperties.Vendor = boolPtr(false)
1742 m.commonProperties.Proprietary = boolPtr(false)
1743 m.commonProperties.Soc_specific = boolPtr(false)
1744 m.commonProperties.Product_specific = boolPtr(false)
1745 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001746}
1747
Jooyung Han344d5432019-08-23 11:17:39 +09001748// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1749func (m *ModuleBase) IsNativeBridgeSupported() bool {
1750 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1751}
1752
Colin Cross25de6c32019-06-06 14:29:25 -07001753func (m *moduleContext) InstallInData() bool {
1754 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001755}
1756
Jaewoong Jung0949f312019-09-11 10:25:18 -07001757func (m *moduleContext) InstallInTestcases() bool {
1758 return m.module.InstallInTestcases()
1759}
1760
Colin Cross25de6c32019-06-06 14:29:25 -07001761func (m *moduleContext) InstallInSanitizerDir() bool {
1762 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001763}
1764
Yifan Hong1b3348d2020-01-21 15:53:22 -08001765func (m *moduleContext) InstallInRamdisk() bool {
1766 return m.module.InstallInRamdisk()
1767}
1768
Colin Cross25de6c32019-06-06 14:29:25 -07001769func (m *moduleContext) InstallInRecovery() bool {
1770 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001771}
1772
Colin Cross90ba5f42019-10-02 11:10:58 -07001773func (m *moduleContext) InstallInRoot() bool {
1774 return m.module.InstallInRoot()
1775}
1776
Colin Cross607d8582019-07-29 16:44:46 -07001777func (m *moduleContext) InstallBypassMake() bool {
1778 return m.module.InstallBypassMake()
1779}
1780
Colin Cross70dda7e2019-10-01 22:05:35 -07001781func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001782 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001783 return true
1784 }
1785
Colin Cross3607f212018-05-07 15:28:05 -07001786 // We'll need a solution for choosing which of modules with the same name in different
1787 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1788 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001789 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001790 return true
1791 }
1792
Colin Cross25de6c32019-06-06 14:29:25 -07001793 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001794 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001795 return true
1796 }
1797
Colin Cross25de6c32019-06-06 14:29:25 -07001798 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001799 return true
1800 }
1801 }
1802
1803 return false
1804}
1805
Colin Cross70dda7e2019-10-01 22:05:35 -07001806func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1807 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001808 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001809}
1810
Colin Cross70dda7e2019-10-01 22:05:35 -07001811func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1812 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001813 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001814}
1815
Colin Cross70dda7e2019-10-01 22:05:35 -07001816func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1817 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001818
Colin Cross25de6c32019-06-06 14:29:25 -07001819 fullInstallPath := installPath.Join(m, name)
1820 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001821
Colin Cross25de6c32019-06-06 14:29:25 -07001822 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001823
Colin Cross25de6c32019-06-06 14:29:25 -07001824 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001825
Colin Cross89562dc2016-10-03 17:47:19 -07001826 var implicitDeps, orderOnlyDeps Paths
1827
Colin Cross25de6c32019-06-06 14:29:25 -07001828 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001829 // Installed host modules might be used during the build, depend directly on their
1830 // dependencies so their timestamp is updated whenever their dependency is updated
1831 implicitDeps = deps
1832 } else {
1833 orderOnlyDeps = deps
1834 }
1835
Colin Cross25de6c32019-06-06 14:29:25 -07001836 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001837 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001838 Description: "install " + fullInstallPath.Base(),
1839 Output: fullInstallPath,
1840 Input: srcPath,
1841 Implicits: implicitDeps,
1842 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001843 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001844 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001845
Colin Cross25de6c32019-06-06 14:29:25 -07001846 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001847 }
Colin Cross25de6c32019-06-06 14:29:25 -07001848 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001849 return fullInstallPath
1850}
1851
Colin Cross70dda7e2019-10-01 22:05:35 -07001852func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001853 fullInstallPath := installPath.Join(m, name)
1854 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001855
Colin Cross25de6c32019-06-06 14:29:25 -07001856 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001857
Alex Lightfb4353d2019-01-17 13:57:45 -08001858 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1859 if err != nil {
1860 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1861 }
Colin Cross25de6c32019-06-06 14:29:25 -07001862 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001863 Rule: Symlink,
1864 Description: "install symlink " + fullInstallPath.Base(),
1865 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08001866 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001867 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001868 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001869 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001870 },
1871 })
Colin Cross3854a602016-01-11 12:49:11 -08001872
Colin Cross25de6c32019-06-06 14:29:25 -07001873 m.installFiles = append(m.installFiles, fullInstallPath)
1874 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001875 }
Colin Cross3854a602016-01-11 12:49:11 -08001876 return fullInstallPath
1877}
1878
Jiyong Parkf1194352019-02-25 11:05:47 +09001879// installPath/name -> absPath where absPath might be a path that is available only at runtime
1880// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001881func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001882 fullInstallPath := installPath.Join(m, name)
1883 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001884
Colin Cross25de6c32019-06-06 14:29:25 -07001885 if !m.skipInstall(fullInstallPath) {
1886 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001887 Rule: Symlink,
1888 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1889 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001890 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001891 Args: map[string]string{
1892 "fromPath": absPath,
1893 },
1894 })
1895
Colin Cross25de6c32019-06-06 14:29:25 -07001896 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001897 }
1898 return fullInstallPath
1899}
1900
Colin Cross25de6c32019-06-06 14:29:25 -07001901func (m *moduleContext) CheckbuildFile(srcPath Path) {
1902 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001903}
1904
Colin Cross3f40fa42015-01-30 17:27:36 -08001905type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001906 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001907}
1908
1909func isFileInstaller(m blueprint.Module) bool {
1910 _, ok := m.(fileInstaller)
1911 return ok
1912}
1913
1914func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001915 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001916 return ok
1917}
Colin Crossfce53272015-04-08 11:21:40 -07001918
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001919func findStringInSlice(str string, slice []string) int {
1920 for i, s := range slice {
1921 if s == str {
1922 return i
Colin Crossfce53272015-04-08 11:21:40 -07001923 }
1924 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001925 return -1
1926}
1927
Colin Cross41955e82019-05-29 14:40:35 -07001928// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1929// was not a module reference.
1930func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001931 if len(s) > 1 && s[0] == ':' {
1932 return s[1:]
1933 }
1934 return ""
1935}
1936
Colin Cross41955e82019-05-29 14:40:35 -07001937// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1938// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1939func SrcIsModuleWithTag(s string) (module, tag string) {
1940 if len(s) > 1 && s[0] == ':' {
1941 module = s[1:]
1942 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1943 if module[len(module)-1] == '}' {
1944 tag = module[tagStart+1 : len(module)-1]
1945 module = module[:tagStart]
1946 return module, tag
1947 }
1948 }
1949 return module, ""
1950 }
1951 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001952}
1953
Colin Cross41955e82019-05-29 14:40:35 -07001954type sourceOrOutputDependencyTag struct {
1955 blueprint.BaseDependencyTag
1956 tag string
1957}
1958
1959func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1960 return sourceOrOutputDependencyTag{tag: tag}
1961}
1962
1963var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001964
Colin Cross366938f2017-12-11 16:29:02 -08001965// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1966// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001967//
1968// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001969func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001970 set := make(map[string]bool)
1971
Colin Cross068e0fe2016-12-13 15:23:47 -08001972 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001973 if m, t := SrcIsModuleWithTag(s); m != "" {
1974 if _, found := set[s]; found {
1975 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001976 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001977 set[s] = true
1978 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001979 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001980 }
1981 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001982}
1983
Colin Cross366938f2017-12-11 16:29:02 -08001984// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1985// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001986//
1987// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001988func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1989 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001990 if m, t := SrcIsModuleWithTag(*s); m != "" {
1991 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001992 }
1993 }
1994}
1995
Colin Cross41955e82019-05-29 14:40:35 -07001996// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1997// 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 -08001998type SourceFileProducer interface {
1999 Srcs() Paths
2000}
2001
Colin Cross41955e82019-05-29 14:40:35 -07002002// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002003// 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 -07002004// listed in the property.
2005type OutputFileProducer interface {
2006 OutputFiles(tag string) (Paths, error)
2007}
2008
Colin Cross5e708052019-08-06 13:59:50 -07002009// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2010// module produced zero paths, it reports errors to the ctx and returns nil.
2011func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2012 paths, err := outputFilesForModule(ctx, module, tag)
2013 if err != nil {
2014 reportPathError(ctx, err)
2015 return nil
2016 }
2017 return paths
2018}
2019
2020// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2021// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2022func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2023 paths, err := outputFilesForModule(ctx, module, tag)
2024 if err != nil {
2025 reportPathError(ctx, err)
2026 return nil
2027 }
2028 if len(paths) > 1 {
2029 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
2030 pathContextName(ctx, module))
2031 return nil
2032 }
2033 return paths[0]
2034}
2035
2036func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2037 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2038 paths, err := outputFileProducer.OutputFiles(tag)
2039 if err != nil {
2040 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2041 pathContextName(ctx, module), err.Error())
2042 }
2043 if len(paths) == 0 {
2044 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2045 }
2046 return paths, nil
2047 } else {
2048 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2049 }
2050}
2051
Colin Crossfe17f6f2019-03-28 19:30:56 -07002052type HostToolProvider interface {
2053 HostToolPath() OptionalPath
2054}
2055
Colin Cross27b922f2019-03-04 22:35:41 -08002056// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2057// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002058//
2059// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002060func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2061 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002062}
2063
Colin Cross2fafa3e2019-03-05 12:39:51 -08002064// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2065// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002066//
2067// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002068func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2069 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002070}
2071
2072// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2073// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2074// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002075func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002076 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002077 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002078 }
2079 return OptionalPath{}
2080}
2081
Colin Cross25de6c32019-06-06 14:29:25 -07002082func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002083 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002084}
2085
Colin Cross25de6c32019-06-06 14:29:25 -07002086func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002087 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002088}
2089
Colin Cross25de6c32019-06-06 14:29:25 -07002090func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002091 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002092}
2093
Colin Cross463a90e2015-06-17 14:20:06 -07002094func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002095 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002096}
2097
Colin Cross0875c522017-11-28 17:34:01 -08002098func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002099 return &buildTargetSingleton{}
2100}
2101
Colin Cross87d8b562017-04-25 10:01:55 -07002102func parentDir(dir string) string {
2103 dir, _ = filepath.Split(dir)
2104 return filepath.Clean(dir)
2105}
2106
Colin Cross1f8c52b2015-06-16 16:38:17 -07002107type buildTargetSingleton struct{}
2108
Colin Cross0875c522017-11-28 17:34:01 -08002109func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2110 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002111
Colin Cross0875c522017-11-28 17:34:01 -08002112 mmTarget := func(dir string) WritablePath {
2113 return PathForPhony(ctx,
2114 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07002115 }
2116
Colin Cross0875c522017-11-28 17:34:01 -08002117 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002118
Colin Cross0875c522017-11-28 17:34:01 -08002119 ctx.VisitAllModules(func(module Module) {
2120 blueprintDir := module.base().blueprintDir
2121 installTarget := module.base().installTarget
2122 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002123
Colin Cross0875c522017-11-28 17:34:01 -08002124 if checkbuildTarget != nil {
2125 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2126 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2127 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002128
Colin Cross0875c522017-11-28 17:34:01 -08002129 if installTarget != nil {
2130 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002131 }
2132 })
2133
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002134 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002135 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002136 suffix = "-soong"
2137 }
2138
Colin Cross1f8c52b2015-06-16 16:38:17 -07002139 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08002140 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002141 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002142 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002143 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07002144 })
2145
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002146 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002147 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002148 return
2149 }
2150
Colin Cross87d8b562017-04-25 10:01:55 -07002151 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002152 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002153 for _, dir := range dirs {
2154 dir := parentDir(dir)
2155 for dir != "." && dir != "/" {
2156 if _, exists := modulesInDir[dir]; exists {
2157 break
2158 }
2159 modulesInDir[dir] = nil
2160 dir = parentDir(dir)
2161 }
2162 }
2163
2164 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002165 for _, dir := range dirs {
2166 p := parentDir(dir)
2167 if p != "." && p != "/" {
2168 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2169 }
2170 }
2171
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002172 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2173 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2174 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002175 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002176 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002177 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002178 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002179 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002180 // HACK: checkbuild should be an optional build, but force it
2181 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002182 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002183 })
2184 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002185
2186 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2187 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002188 ctx.VisitAllModules(func(module Module) {
2189 if module.Enabled() {
2190 os := module.Target().Os
2191 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002192 }
2193 })
2194
Colin Cross0875c522017-11-28 17:34:01 -08002195 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002196 for os, deps := range osDeps {
2197 var className string
2198
2199 switch os.Class {
2200 case Host:
2201 className = "host"
2202 case HostCross:
2203 className = "host-cross"
2204 case Device:
2205 className = "target"
2206 default:
2207 continue
2208 }
2209
Colin Cross0875c522017-11-28 17:34:01 -08002210 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002211 osClass[className] = append(osClass[className], name)
2212
Colin Cross0875c522017-11-28 17:34:01 -08002213 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002214 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002215 Output: name,
2216 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002217 })
2218 }
2219
2220 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002221 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002222 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002223 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002224 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002225 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002226 })
2227 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002228}
Colin Crossd779da42015-12-17 18:00:23 -08002229
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002230// Collect information for opening IDE project files in java/jdeps.go.
2231type IDEInfo interface {
2232 IDEInfo(ideInfo *IdeInfo)
2233 BaseModuleName() string
2234}
2235
2236// Extract the base module name from the Import name.
2237// Often the Import name has a prefix "prebuilt_".
2238// Remove the prefix explicitly if needed
2239// until we find a better solution to get the Import name.
2240type IDECustomizedModuleName interface {
2241 IDECustomizedModuleName() string
2242}
2243
2244type IdeInfo struct {
2245 Deps []string `json:"dependencies,omitempty"`
2246 Srcs []string `json:"srcs,omitempty"`
2247 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2248 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2249 Jars []string `json:"jars,omitempty"`
2250 Classes []string `json:"class,omitempty"`
2251 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002252 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002253}