blob: 65fecc7fe1164de6770a269701347c79890c6778 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000019 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080020 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "path/filepath"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080023 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
25 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
29var (
30 DeviceSharedLibrary = "shared_library"
31 DeviceStaticLibrary = "static_library"
32 DeviceExecutable = "executable"
33 HostSharedLibrary = "host_shared_library"
34 HostStaticLibrary = "host_static_library"
35 HostExecutable = "host_executable"
36)
37
Colin Crossae887032017-10-23 17:16:14 -070038type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080040 Deps blueprint.Deps
41 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070043 Output WritablePath
44 Outputs WritablePaths
45 ImplicitOutput WritablePath
46 ImplicitOutputs WritablePaths
47 Input Path
48 Inputs Paths
49 Implicit Path
50 Implicits Paths
51 OrderOnly Paths
52 Default bool
53 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054}
55
Colin Crossae887032017-10-23 17:16:14 -070056type ModuleBuildParams BuildParams
57
Colin Cross1184b642019-12-30 18:43:07 -080058// EarlyModuleContext provides methods that can be called early, as soon as the properties have
59// been parsed into the module and before any mutators have run.
60type EarlyModuleContext interface {
61 Module() Module
62 ModuleName() string
63 ModuleDir() string
64 ModuleType() string
Colin Cross9d34f352019-11-22 16:03:51 -080065 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080066
67 ContainsProperty(name string) bool
68 Errorf(pos scanner.Position, fmt string, args ...interface{})
69 ModuleErrorf(fmt string, args ...interface{})
70 PropertyErrorf(property, fmt string, args ...interface{})
71 Failed() bool
72
73 AddNinjaFileDeps(deps ...string)
74
75 DeviceSpecific() bool
76 SocSpecific() bool
77 ProductSpecific() bool
78 SystemExtSpecific() bool
79 Platform() bool
80
81 Config() Config
82 DeviceConfig() DeviceConfig
83
84 // Deprecated: use Config()
85 AConfig() Config
86
87 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
88 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
89 // builder whenever a file matching the pattern as added or removed, without rerunning if a
90 // file that does not match the pattern is added to a searched directory.
91 GlobWithDeps(pattern string, excludes []string) ([]string, error)
92
93 Glob(globPattern string, excludes []string) Paths
94 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +000095 IsSymlink(path Path) bool
96 Readlink(path Path) string
Colin Cross1184b642019-12-30 18:43:07 -080097}
98
Colin Cross0ea8ba82019-06-06 14:33:29 -070099// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700100// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
101// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700102// about the current module.
103type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800104 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700105
Colin Crossdc35e212019-06-06 16:13:11 -0700106 OtherModuleName(m blueprint.Module) string
107 OtherModuleDir(m blueprint.Module) string
108 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
109 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
110 OtherModuleExists(name string) bool
Jiyong Park9e6c2422019-08-09 20:39:45 +0900111 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700112
113 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
114 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
115 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
116
117 VisitDirectDepsBlueprint(visit func(blueprint.Module))
118 VisitDirectDeps(visit func(Module))
119 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
120 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
121 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
122 VisitDepsDepthFirst(visit func(Module))
123 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
124 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
125 WalkDeps(visit func(Module, Module) bool)
126 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
127 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
128 // and returns a top-down dependency path from a start module to current child module.
129 GetWalkPath() []Module
130
Colin Crossdc35e212019-06-06 16:13:11 -0700131 AddMissingDependencies(missingDeps []string)
132
Colin Crossa1ad8d12016-06-01 17:09:44 -0700133 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700134 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -0700135 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700136 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700137 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700138 Host() bool
139 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700140 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800141 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700142 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700143 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700144 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700145}
146
Colin Cross1184b642019-12-30 18:43:07 -0800147// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700148type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800149 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800150}
151
Colin Cross635c3b02016-05-18 15:37:25 -0700152type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800153 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800154
Colin Crossae887032017-10-23 17:16:14 -0700155 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800156 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700157
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700158 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800159 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800160 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700161
Colin Cross70dda7e2019-10-01 22:05:35 -0700162 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
163 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
164 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
165 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700166 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800167
Colin Cross8d8f8e22016-08-03 11:57:50 -0700168 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700169 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700170 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800171 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900172 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700173 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700174 InstallBypassMake() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800175
176 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700177 HostRequiredModuleNames() []string
178 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700179
Colin Cross3f68a132017-10-23 17:10:29 -0700180 ModuleSubDir() string
181
Colin Cross0875c522017-11-28 17:34:01 -0800182 Variable(pctx PackageContext, name, value string)
183 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700184 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
185 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800186 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700187
Colin Cross0875c522017-11-28 17:34:01 -0800188 PrimaryModule() Module
189 FinalModule() Module
190 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700191
192 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800193 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800194}
195
Colin Cross635c3b02016-05-18 15:37:25 -0700196type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800197 blueprint.Module
198
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700199 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
200 // but GenerateAndroidBuildActions also has access to Android-specific information.
201 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700202 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700203
Colin Cross1e676be2016-10-12 14:38:15 -0700204 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800205
Colin Cross635c3b02016-05-18 15:37:25 -0700206 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900207 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800208 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700209 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800210 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700211 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700212 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800213 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900214 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700215 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700216 InstallBypassMake() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800217 SkipInstall()
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000218 IsSkipInstall() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900219 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900220 InitRc() Paths
221 VintfFragments() Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900222 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700223
224 AddProperties(props ...interface{})
225 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700226
Colin Crossae887032017-10-23 17:16:14 -0700227 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800228 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800229 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100230
Colin Cross9a362232019-07-01 15:32:45 -0700231 // String returns a string that includes the module name and variants for printing during debugging.
232 String() string
233
Paul Duffine2453c72019-05-31 14:00:04 +0100234 // Get the qualified module id for this module.
235 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
236
237 // Get information about the properties that can contain visibility rules.
238 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100239
240 // Get the visibility rules that control the visibility of this module.
241 visibility() []string
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900242
243 RequiredModuleNames() []string
244 HostRequiredModuleNames() []string
245 TargetRequiredModuleNames() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100246}
247
248// Qualified id for a module
249type qualifiedModuleName struct {
250 // The package (i.e. directory) in which the module is defined, without trailing /
251 pkg string
252
253 // The name of the module, empty string if package.
254 name string
255}
256
257func (q qualifiedModuleName) String() string {
258 if q.name == "" {
259 return "//" + q.pkg
260 }
261 return "//" + q.pkg + ":" + q.name
262}
263
Paul Duffine484f472019-06-20 16:38:08 +0100264func (q qualifiedModuleName) isRootPackage() bool {
265 return q.pkg == "" && q.name == ""
266}
267
Paul Duffine2453c72019-05-31 14:00:04 +0100268// Get the id for the package containing this module.
269func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
270 pkg := q.pkg
271 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100272 if pkg == "" {
273 panic(fmt.Errorf("Cannot get containing package id of root package"))
274 }
275
276 index := strings.LastIndex(pkg, "/")
277 if index == -1 {
278 pkg = ""
279 } else {
280 pkg = pkg[:index]
281 }
Paul Duffine2453c72019-05-31 14:00:04 +0100282 }
283 return newPackageId(pkg)
284}
285
286func newPackageId(pkg string) qualifiedModuleName {
287 // A qualified id for a package module has no name.
288 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800289}
290
Colin Crossfc754582016-05-17 16:34:16 -0700291type nameProperties struct {
292 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800293 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700294}
295
296type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800297 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000298 //
299 // Disabling a module should only be done for those modules that cannot be built
300 // in the current environment. Modules that can build in the current environment
301 // but are not usually required (e.g. superceded by a prebuilt) should not be
302 // disabled as that will prevent them from being built by the checkbuild target
303 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800304 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800305
Paul Duffin2e61fa62019-03-28 14:10:57 +0000306 // Controls the visibility of this module to other modules. Allowable values are one or more of
307 // these formats:
308 //
309 // ["//visibility:public"]: Anyone can use this module.
310 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
311 // this module.
312 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
313 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
314 // this module. Note that sub-packages do not have access to the rule; for example,
315 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
316 // is a special module and must be used verbatim. It represents all of the modules in the
317 // package.
318 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
319 // or other or in one of their sub-packages have access to this module. For example,
320 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
321 // to depend on this rule (but not //independent:evil)
322 // ["//project"]: This is shorthand for ["//project:__pkg__"]
323 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
324 // //project is the module's package. e.g. using [":__subpackages__"] in
325 // packages/apps/Settings/Android.bp is equivalent to
326 // //packages/apps/Settings:__subpackages__.
327 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
328 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100329 //
330 // If a module does not specify the `visibility` property then it uses the
331 // `default_visibility` property of the `package` module in the module's package.
332 //
333 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100334 // it will use the `default_visibility` of its closest ancestor package for which
335 // a `default_visibility` property is specified.
336 //
337 // If no `default_visibility` property can be found then the module uses the
338 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100339 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100340 // The `visibility` property has no effect on a defaults module although it does
341 // apply to any non-defaults module that uses it. To set the visibility of a
342 // defaults module, use the `defaults_visibility` property on the defaults module;
343 // not to be confused with the `default_visibility` property on the package module.
344 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000345 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
346 // more details.
347 Visibility []string
348
Colin Cross7d5136f2015-05-11 13:39:40 -0700349 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800350 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
351 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
352 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700353 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700354
355 Target struct {
356 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700357 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700358 }
359 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700360 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700361 }
362 }
363
Colin Crossee0bc3b2018-10-02 22:01:37 -0700364 UseTargetVariants bool `blueprint:"mutated"`
365 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800366
Dan Willemsen782a2d12015-12-21 14:55:28 -0800367 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700368 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800369
Colin Cross55708f32017-03-20 13:23:34 -0700370 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700371 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700372
Jiyong Park2db76922017-11-08 16:03:48 +0900373 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
374 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
375 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700376 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700377
Jiyong Park2db76922017-11-08 16:03:48 +0900378 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
379 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
380 Soc_specific *bool
381
382 // whether this module is specific to a device, not only for SoC, but also for off-chip
383 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
384 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
385 // This implies `soc_specific:true`.
386 Device_specific *bool
387
388 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900389 // network operator, etc). When set to true, it is installed into /product (or
390 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900391 Product_specific *bool
392
Justin Yund5f6c822019-06-25 16:47:17 +0900393 // whether this module extends system. When set to true, it is installed into /system_ext
394 // (or /system/system_ext if system_ext partition does not exist).
395 System_ext_specific *bool
396
Jiyong Parkf9332f12018-02-01 00:54:12 +0900397 // Whether this module is installed to recovery partition
398 Recovery *bool
399
Yifan Hong1b3348d2020-01-21 15:53:22 -0800400 // Whether this module is installed to ramdisk
401 Ramdisk *bool
402
dimitry1f33e402019-03-26 12:39:31 +0100403 // Whether this module is built for non-native architecures (also known as native bridge binary)
404 Native_bridge_supported *bool `android:"arch_variant"`
405
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700406 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800407 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700408
Steven Moreland57a23d22018-04-04 15:42:19 -0700409 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800410 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700411
Chris Wolfe998306e2016-08-15 14:47:23 -0400412 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700413 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400414
Sasha Smundakb6d23052019-04-01 18:37:36 -0700415 // names of other modules to install on host if this module is installed
416 Host_required []string `android:"arch_variant"`
417
418 // names of other modules to install on target if this module is installed
419 Target_required []string `android:"arch_variant"`
420
Colin Cross5aac3622017-08-31 15:07:09 -0700421 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800422 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700423
Dan Willemsen569edc52018-11-19 09:33:29 -0800424 Dist struct {
425 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
426 // command line and any of these targets are also on the command line, or otherwise
427 // built
428 Targets []string `android:"arch_variant"`
429
430 // The name of the output artifact. This defaults to the basename of the output of
431 // the module.
432 Dest *string `android:"arch_variant"`
433
434 // The directory within the dist directory to store the artifact. Defaults to the
435 // top level directory ("").
436 Dir *string `android:"arch_variant"`
437
438 // A suffix to add to the artifact file name (before any extension).
439 Suffix *string `android:"arch_variant"`
440 } `android:"arch_variant"`
441
Colin Crossa1ad8d12016-06-01 17:09:44 -0700442 // Set by TargetMutator
Colin Crossa195f912019-10-16 11:07:20 -0700443 CompileOS OsType `blueprint:"mutated"`
Colin Crossee0bc3b2018-10-02 22:01:37 -0700444 CompileTarget Target `blueprint:"mutated"`
445 CompileMultiTargets []Target `blueprint:"mutated"`
446 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800447
448 // Set by InitAndroidModule
449 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700450 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700451
452 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800453
454 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700455
456 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700457
458 // Name and variant strings stored by mutators to enable Module.String()
459 DebugName string `blueprint:"mutated"`
460 DebugMutators []string `blueprint:"mutated"`
461 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800462
463 // set by ImageMutator
464 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800465}
466
467type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800468 // If set to true, build a variant of the module for the host. Defaults to false.
469 Host_supported *bool
470
471 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700472 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800473}
474
Colin Crossc472d572015-03-17 15:06:21 -0700475type Multilib string
476
477const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800478 MultilibBoth Multilib = "both"
479 MultilibFirst Multilib = "first"
480 MultilibCommon Multilib = "common"
481 MultilibCommonFirst Multilib = "common_first"
482 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700483)
484
Colin Crossa1ad8d12016-06-01 17:09:44 -0700485type HostOrDeviceSupported int
486
487const (
488 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700489
490 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700491 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700492
493 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700494 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700495
496 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700497 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700498
499 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700500 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700501
502 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700503 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700504
505 // Nothing is supported. This is not exposed to the user, but used to mark a
506 // host only module as unsupported when the module type is not supported on
507 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700508 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700509)
510
Jiyong Park2db76922017-11-08 16:03:48 +0900511type moduleKind int
512
513const (
514 platformModule moduleKind = iota
515 deviceSpecificModule
516 socSpecificModule
517 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900518 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900519)
520
521func (k moduleKind) String() string {
522 switch k {
523 case platformModule:
524 return "platform"
525 case deviceSpecificModule:
526 return "device-specific"
527 case socSpecificModule:
528 return "soc-specific"
529 case productSpecificModule:
530 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900531 case systemExtSpecificModule:
532 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900533 default:
534 panic(fmt.Errorf("unknown module kind %d", k))
535 }
536}
537
Colin Cross9d34f352019-11-22 16:03:51 -0800538func initAndroidModuleBase(m Module) {
539 m.base().module = m
540}
541
Colin Cross36242852017-06-23 15:06:31 -0700542func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800543 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800544 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700545
Colin Cross36242852017-06-23 15:06:31 -0700546 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700547 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700548 &base.commonProperties)
549
Colin Crosseabaedd2020-02-06 17:01:55 -0800550 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700551
Colin Crossa3a97412019-03-18 12:24:29 -0700552 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700553 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100554
555 // The default_visibility property needs to be checked and parsed by the visibility module during
556 // its checking and parsing phases.
557 base.primaryVisibilityProperty =
558 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
559 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700560}
561
Colin Cross36242852017-06-23 15:06:31 -0700562func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
563 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700564
565 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800566 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700567 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700568 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700569 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800570
Dan Willemsen218f6562015-07-08 18:13:11 -0700571 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700572 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700573 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800574 }
575
Colin Cross36242852017-06-23 15:06:31 -0700576 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800577}
578
Colin Crossee0bc3b2018-10-02 22:01:37 -0700579func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
580 InitAndroidArchModule(m, hod, defaultMultilib)
581 m.base().commonProperties.UseTargetVariants = false
582}
583
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800584// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800585// modules. It should be included as an anonymous field in every module
586// struct definition. InitAndroidModule should then be called from the module's
587// factory function, and the return values from InitAndroidModule should be
588// returned from the factory function.
589//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800590// The ModuleBase type is responsible for implementing the GenerateBuildActions
591// method to support the blueprint.Module interface. This method will then call
592// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700593// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
594// rather than the usual blueprint.ModuleContext.
595// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800596// system including details about the particular build variant that is to be
597// generated.
598//
599// For example:
600//
601// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800602// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800603// )
604//
605// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800606// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800607// properties struct {
608// MyProperty string
609// }
610// }
611//
Colin Cross36242852017-06-23 15:06:31 -0700612// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800613// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700614// m.AddProperties(&m.properties)
615// android.InitAndroidModule(m)
616// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800617// }
618//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800619// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800620// // Get the CPU architecture for the current build variant.
621// variantArch := ctx.Arch()
622//
623// // ...
624// }
Colin Cross635c3b02016-05-18 15:37:25 -0700625type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800626 // Putting the curiously recurring thing pointing to the thing that contains
627 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700628 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700629 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800630
Colin Crossfc754582016-05-17 16:34:16 -0700631 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800632 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700633 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800634 hostAndDeviceProperties hostAndDeviceProperties
635 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700636 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700637 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800638
Paul Duffin63c6e182019-07-24 14:24:38 +0100639 // Information about all the properties on the module that contains visibility rules that need
640 // checking.
641 visibilityPropertyInfo []visibilityProperty
642
643 // The primary visibility property, may be nil, that controls access to the module.
644 primaryVisibilityProperty visibilityProperty
645
Colin Cross3f40fa42015-01-30 17:27:36 -0800646 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700647 installFiles Paths
648 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900649 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700650
651 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
652 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800653 installTarget WritablePath
654 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700655 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700656
Colin Cross178a5092016-09-13 13:42:32 -0700657 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700658
659 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700660
661 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700662 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800663 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800664 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700665
Inseob Kim8471cda2019-11-15 09:59:12 +0900666 initRcPaths Paths
667 vintfFragmentsPaths Paths
668
Colin Crossa9d8bee2018-10-02 13:59:46 -0700669 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700670}
671
Colin Cross4157e882019-06-06 16:57:04 -0700672func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800673
Colin Cross4157e882019-06-06 16:57:04 -0700674func (m *ModuleBase) AddProperties(props ...interface{}) {
675 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700676}
677
Colin Cross4157e882019-06-06 16:57:04 -0700678func (m *ModuleBase) GetProperties() []interface{} {
679 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800680}
681
Colin Cross4157e882019-06-06 16:57:04 -0700682func (m *ModuleBase) BuildParamsForTests() []BuildParams {
683 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700684}
685
Colin Cross4157e882019-06-06 16:57:04 -0700686func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
687 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800688}
689
Colin Cross4157e882019-06-06 16:57:04 -0700690func (m *ModuleBase) VariablesForTests() map[string]string {
691 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800692}
693
Colin Cross4157e882019-06-06 16:57:04 -0700694func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
695 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700696}
697
Colin Crossce75d2c2016-10-06 16:12:58 -0700698// Name returns the name of the module. It may be overridden by individual module types, for
699// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700700func (m *ModuleBase) Name() string {
701 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700702}
703
Colin Cross9a362232019-07-01 15:32:45 -0700704// String returns a string that includes the module name and variants for printing during debugging.
705func (m *ModuleBase) String() string {
706 sb := strings.Builder{}
707 sb.WriteString(m.commonProperties.DebugName)
708 sb.WriteString("{")
709 for i := range m.commonProperties.DebugMutators {
710 if i != 0 {
711 sb.WriteString(",")
712 }
713 sb.WriteString(m.commonProperties.DebugMutators[i])
714 sb.WriteString(":")
715 sb.WriteString(m.commonProperties.DebugVariations[i])
716 }
717 sb.WriteString("}")
718 return sb.String()
719}
720
Colin Crossce75d2c2016-10-06 16:12:58 -0700721// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700722func (m *ModuleBase) BaseModuleName() string {
723 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700724}
725
Colin Cross4157e882019-06-06 16:57:04 -0700726func (m *ModuleBase) base() *ModuleBase {
727 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800728}
729
Paul Duffine2453c72019-05-31 14:00:04 +0100730func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
731 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
732}
733
734func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100735 return m.visibilityPropertyInfo
736}
737
738func (m *ModuleBase) visibility() []string {
739 // The soong_namespace module does not initialize the primaryVisibilityProperty.
740 if m.primaryVisibilityProperty != nil {
741 return m.primaryVisibilityProperty.getStrings()
742 } else {
743 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100744 }
745}
746
Colin Cross4157e882019-06-06 16:57:04 -0700747func (m *ModuleBase) Target() Target {
748 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800749}
750
Colin Cross4157e882019-06-06 16:57:04 -0700751func (m *ModuleBase) TargetPrimary() bool {
752 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700753}
754
Colin Cross4157e882019-06-06 16:57:04 -0700755func (m *ModuleBase) MultiTargets() []Target {
756 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700757}
758
Colin Cross4157e882019-06-06 16:57:04 -0700759func (m *ModuleBase) Os() OsType {
760 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800761}
762
Colin Cross4157e882019-06-06 16:57:04 -0700763func (m *ModuleBase) Host() bool {
764 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800765}
766
Colin Cross4157e882019-06-06 16:57:04 -0700767func (m *ModuleBase) Arch() Arch {
768 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800769}
770
Colin Cross4157e882019-06-06 16:57:04 -0700771func (m *ModuleBase) ArchSpecific() bool {
772 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700773}
774
Colin Cross4157e882019-06-06 16:57:04 -0700775func (m *ModuleBase) OsClassSupported() []OsClass {
776 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700777 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700778 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700779 case HostSupportedNoCross:
780 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700781 case DeviceSupported:
782 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700783 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700784 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700785 if Bool(m.hostAndDeviceProperties.Host_supported) ||
786 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
787 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700788 supported = append(supported, Host, HostCross)
789 }
Colin Cross4157e882019-06-06 16:57:04 -0700790 if m.hostAndDeviceProperties.Device_supported == nil ||
791 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700792 supported = append(supported, Device)
793 }
794 return supported
795 default:
796 return nil
797 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800798}
799
Colin Cross4157e882019-06-06 16:57:04 -0700800func (m *ModuleBase) DeviceSupported() bool {
801 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
802 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
803 (m.hostAndDeviceProperties.Device_supported == nil ||
804 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800805}
806
Paul Duffine44358f2019-11-26 18:04:12 +0000807func (m *ModuleBase) HostSupported() bool {
808 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
809 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
810 (m.hostAndDeviceProperties.Host_supported != nil &&
811 *m.hostAndDeviceProperties.Host_supported)
812}
813
Colin Cross4157e882019-06-06 16:57:04 -0700814func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900815 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900816}
817
Colin Cross4157e882019-06-06 16:57:04 -0700818func (m *ModuleBase) DeviceSpecific() bool {
819 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900820}
821
Colin Cross4157e882019-06-06 16:57:04 -0700822func (m *ModuleBase) SocSpecific() bool {
823 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900824}
825
Colin Cross4157e882019-06-06 16:57:04 -0700826func (m *ModuleBase) ProductSpecific() bool {
827 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900828}
829
Justin Yund5f6c822019-06-25 16:47:17 +0900830func (m *ModuleBase) SystemExtSpecific() bool {
831 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100832}
833
Bill Peckham1c610cf2020-03-20 18:33:20 -0700834func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
835 partition := "system"
836 if m.SocSpecific() {
837 // A SoC-specific module could be on the vendor partition at
838 // "vendor" or the system partition at "system/vendor".
839 if config.VendorPath() == "vendor" {
840 partition = "vendor"
841 }
842 } else if m.DeviceSpecific() {
843 // A device-specific module could be on the odm partition at
844 // "odm", the vendor partition at "vendor/odm", or the system
845 // partition at "system/vendor/odm".
846 if config.OdmPath() == "odm" {
847 partition = "odm"
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000848 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckham1c610cf2020-03-20 18:33:20 -0700849 partition = "vendor"
850 }
851 } else if m.ProductSpecific() {
852 // A product-specific module could be on the product partition
853 // at "product" or the system partition at "system/product".
854 if config.ProductPath() == "product" {
855 partition = "product"
856 }
857 } else if m.SystemExtSpecific() {
858 // A system_ext-specific module could be on the system_ext
859 // partition at "system_ext" or the system partition at
860 // "system/system_ext".
861 if config.SystemExtPath() == "system_ext" {
862 partition = "system_ext"
863 }
864 }
865 return partition
866}
867
Colin Cross4157e882019-06-06 16:57:04 -0700868func (m *ModuleBase) Enabled() bool {
869 if m.commonProperties.Enabled == nil {
870 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800871 }
Colin Cross4157e882019-06-06 16:57:04 -0700872 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800873}
874
Inseob Kimeec88e12020-01-22 11:11:29 +0900875func (m *ModuleBase) Disable() {
876 m.commonProperties.Enabled = proptools.BoolPtr(false)
877}
878
Colin Cross4157e882019-06-06 16:57:04 -0700879func (m *ModuleBase) SkipInstall() {
880 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700881}
882
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +0000883func (m *ModuleBase) IsSkipInstall() bool {
884 return m.commonProperties.SkipInstall == true
885}
886
Colin Cross4157e882019-06-06 16:57:04 -0700887func (m *ModuleBase) ExportedToMake() bool {
888 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900889}
890
Colin Cross4157e882019-06-06 16:57:04 -0700891func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700892 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800893
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700894 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700895 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800896 ctx.VisitDepsDepthFirstIf(isFileInstaller,
897 func(m blueprint.Module) {
898 fileInstaller := m.(fileInstaller)
899 files := fileInstaller.filesToInstall()
900 result = append(result, files...)
901 })
902
903 return result
904}
905
Colin Cross4157e882019-06-06 16:57:04 -0700906func (m *ModuleBase) filesToInstall() Paths {
907 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800908}
909
Colin Cross4157e882019-06-06 16:57:04 -0700910func (m *ModuleBase) NoAddressSanitizer() bool {
911 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800912}
913
Colin Cross4157e882019-06-06 16:57:04 -0700914func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800915 return false
916}
917
Jaewoong Jung0949f312019-09-11 10:25:18 -0700918func (m *ModuleBase) InstallInTestcases() bool {
919 return false
920}
921
Colin Cross4157e882019-06-06 16:57:04 -0700922func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700923 return false
924}
925
Yifan Hong1b3348d2020-01-21 15:53:22 -0800926func (m *ModuleBase) InstallInRamdisk() bool {
927 return Bool(m.commonProperties.Ramdisk)
928}
929
Colin Cross4157e882019-06-06 16:57:04 -0700930func (m *ModuleBase) InstallInRecovery() bool {
931 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900932}
933
Colin Cross90ba5f42019-10-02 11:10:58 -0700934func (m *ModuleBase) InstallInRoot() bool {
935 return false
936}
937
Colin Cross607d8582019-07-29 16:44:46 -0700938func (m *ModuleBase) InstallBypassMake() bool {
939 return false
940}
941
Colin Cross4157e882019-06-06 16:57:04 -0700942func (m *ModuleBase) Owner() string {
943 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900944}
945
Colin Cross4157e882019-06-06 16:57:04 -0700946func (m *ModuleBase) NoticeFile() OptionalPath {
947 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900948}
949
Colin Cross7228ecd2019-11-18 16:00:16 -0800950func (m *ModuleBase) setImageVariation(variant string) {
951 m.commonProperties.ImageVariation = variant
952}
953
954func (m *ModuleBase) ImageVariation() blueprint.Variation {
955 return blueprint.Variation{
956 Mutator: "image",
957 Variation: m.base().commonProperties.ImageVariation,
958 }
959}
960
Yifan Hong1b3348d2020-01-21 15:53:22 -0800961func (m *ModuleBase) InRamdisk() bool {
962 return m.base().commonProperties.ImageVariation == RamdiskVariation
963}
964
Colin Cross7228ecd2019-11-18 16:00:16 -0800965func (m *ModuleBase) InRecovery() bool {
966 return m.base().commonProperties.ImageVariation == RecoveryVariation
967}
968
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900969func (m *ModuleBase) RequiredModuleNames() []string {
970 return m.base().commonProperties.Required
971}
972
973func (m *ModuleBase) HostRequiredModuleNames() []string {
974 return m.base().commonProperties.Host_required
975}
976
977func (m *ModuleBase) TargetRequiredModuleNames() []string {
978 return m.base().commonProperties.Target_required
979}
980
Inseob Kim8471cda2019-11-15 09:59:12 +0900981func (m *ModuleBase) InitRc() Paths {
982 return append(Paths{}, m.initRcPaths...)
983}
984
985func (m *ModuleBase) VintfFragments() Paths {
986 return append(Paths{}, m.vintfFragmentsPaths...)
987}
988
Colin Cross4157e882019-06-06 16:57:04 -0700989func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700990 allInstalledFiles := Paths{}
991 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800992 ctx.VisitAllModuleVariants(func(module Module) {
993 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700994 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
995 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800996 })
997
Colin Cross0875c522017-11-28 17:34:01 -0800998 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700999
Jeff Gaston088e29e2017-11-29 16:47:17 -08001000 namespacePrefix := ctx.Namespace().(*Namespace).id
1001 if namespacePrefix != "" {
1002 namespacePrefix = namespacePrefix + "-"
1003 }
1004
Colin Cross3f40fa42015-01-30 17:27:36 -08001005 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -08001006 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -08001007 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001008 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001009 Output: name,
1010 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -08001011 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -07001012 })
1013 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -07001014 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -07001015 }
1016
1017 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -08001018 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -08001019 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001020 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001021 Output: name,
1022 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -07001023 })
1024 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -07001025 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -07001026 }
1027
1028 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001029 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001030 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001031 suffix = "-soong"
1032 }
1033
Jeff Gaston088e29e2017-11-29 16:47:17 -08001034 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -08001035 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -07001036 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -08001037 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -07001038 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -08001039 })
Colin Cross1f8c52b2015-06-16 16:38:17 -07001040
Colin Cross4157e882019-06-06 16:57:04 -07001041 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001042 }
1043}
1044
Colin Crossc34d2322020-01-03 15:23:27 -08001045func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001046 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1047 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1048 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001049 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001050
Dario Frenifd05a742018-05-29 13:28:54 +01001051 msg := "conflicting value set here"
1052 if socSpecific && deviceSpecific {
1053 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001054 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001055 ctx.PropertyErrorf("vendor", msg)
1056 }
Colin Cross4157e882019-06-06 16:57:04 -07001057 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001058 ctx.PropertyErrorf("proprietary", msg)
1059 }
Colin Cross4157e882019-06-06 16:57:04 -07001060 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001061 ctx.PropertyErrorf("soc_specific", msg)
1062 }
1063 }
1064
Justin Yund5f6c822019-06-25 16:47:17 +09001065 if productSpecific && systemExtSpecific {
1066 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1067 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001068 }
1069
Justin Yund5f6c822019-06-25 16:47:17 +09001070 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001071 if productSpecific {
1072 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1073 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001074 ctx.PropertyErrorf("system_ext_specific", "a module cannot be specific to SoC or device and system_ext at the same time.")
Dario Frenifd05a742018-05-29 13:28:54 +01001075 }
1076 if deviceSpecific {
1077 ctx.PropertyErrorf("device_specific", msg)
1078 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001079 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001080 ctx.PropertyErrorf("vendor", msg)
1081 }
Colin Cross4157e882019-06-06 16:57:04 -07001082 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001083 ctx.PropertyErrorf("proprietary", msg)
1084 }
Colin Cross4157e882019-06-06 16:57:04 -07001085 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001086 ctx.PropertyErrorf("soc_specific", msg)
1087 }
1088 }
1089 }
1090
Jiyong Park2db76922017-11-08 16:03:48 +09001091 if productSpecific {
1092 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001093 } else if systemExtSpecific {
1094 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001095 } else if deviceSpecific {
1096 return deviceSpecificModule
1097 } else if socSpecific {
1098 return socSpecificModule
1099 } else {
1100 return platformModule
1101 }
1102}
1103
Colin Crossc34d2322020-01-03 15:23:27 -08001104func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001105 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001106 EarlyModuleContext: ctx,
1107 kind: determineModuleKind(m, ctx),
1108 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001109 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001110}
1111
Colin Cross1184b642019-12-30 18:43:07 -08001112func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1113 return baseModuleContext{
1114 bp: ctx,
1115 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1116 os: m.commonProperties.CompileOS,
1117 target: m.commonProperties.CompileTarget,
1118 targetPrimary: m.commonProperties.CompilePrimary,
1119 multiTargets: m.commonProperties.CompileMultiTargets,
1120 }
1121}
1122
Colin Cross4157e882019-06-06 16:57:04 -07001123func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001124 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001125 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001126 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001127 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1128 installDeps: m.computeInstallDeps(blueprintCtx),
1129 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001130 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001131 }
1132
Colin Cross6c4f21f2019-06-06 15:41:36 -07001133 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1134 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1135 // TODO: This will be removed once defaults modules handle missing dependency errors
1136 blueprintCtx.GetMissingDependencies()
1137
Colin Crossdc35e212019-06-06 16:13:11 -07001138 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
1139 // are enabled.
1140 ctx.baseModuleContext.strictVisitDeps = true
1141
Colin Cross4c83e5c2019-02-25 14:54:28 -08001142 if ctx.config.captureBuild {
1143 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1144 }
1145
Colin Cross67a5c132017-05-09 13:45:28 -07001146 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1147 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001148 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1149 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001150 }
Colin Cross0875c522017-11-28 17:34:01 -08001151 if !ctx.PrimaryArch() {
1152 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001153 }
Dan Willemsenb13a9482020-02-14 11:25:54 -08001154 if apex, ok := m.module.(ApexModule); ok && !apex.IsForPlatform() {
1155 suffix = append(suffix, apex.ApexName())
1156 }
Colin Cross67a5c132017-05-09 13:45:28 -07001157
1158 ctx.Variable(pctx, "moduleDesc", desc)
1159
1160 s := ""
1161 if len(suffix) > 0 {
1162 s = " [" + strings.Join(suffix, " ") + "]"
1163 }
1164 ctx.Variable(pctx, "moduleDescSuffix", s)
1165
Dan Willemsen569edc52018-11-19 09:33:29 -08001166 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001167 if m.commonProperties.Dist.Dest != nil {
1168 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001169 if err != nil {
1170 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1171 }
1172 }
Colin Cross4157e882019-06-06 16:57:04 -07001173 if m.commonProperties.Dist.Dir != nil {
1174 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001175 if err != nil {
1176 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1177 }
1178 }
Colin Cross4157e882019-06-06 16:57:04 -07001179 if m.commonProperties.Dist.Suffix != nil {
1180 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001181 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1182 }
1183 }
1184
Colin Cross4157e882019-06-06 16:57:04 -07001185 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001186 // ensure all direct android.Module deps are enabled
1187 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1188 if _, ok := bm.(Module); ok {
1189 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1190 }
1191 })
1192
Colin Cross4157e882019-06-06 16:57:04 -07001193 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1194 if module := SrcIsModule(notice); module != "" {
1195 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001196 } else {
1197 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001198 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001199 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001200
1201 m.module.GenerateAndroidBuildActions(ctx)
1202 if ctx.Failed() {
1203 return
1204 }
1205
1206 m.installFiles = append(m.installFiles, ctx.installFiles...)
1207 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Inseob Kim8471cda2019-11-15 09:59:12 +09001208 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1209 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
Colin Crossdc35e212019-06-06 16:13:11 -07001210 } else if ctx.Config().AllowMissingDependencies() {
1211 // If the module is not enabled it will not create any build rules, nothing will call
1212 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1213 // and report them as an error even when AllowMissingDependencies = true. Call
1214 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1215 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001216 }
1217
Colin Cross4157e882019-06-06 16:57:04 -07001218 if m == ctx.FinalModule().(Module).base() {
1219 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001220 if ctx.Failed() {
1221 return
1222 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001223 }
Colin Crosscec81712017-07-13 14:43:27 -07001224
Colin Cross4157e882019-06-06 16:57:04 -07001225 m.buildParams = ctx.buildParams
1226 m.ruleParams = ctx.ruleParams
1227 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001228}
1229
Colin Cross1184b642019-12-30 18:43:07 -08001230type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001231 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001232
1233 kind moduleKind
1234 config Config
1235}
1236
1237func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1238 ret, err := e.GlobWithDeps(globPattern, excludes)
1239 if err != nil {
1240 e.ModuleErrorf("glob: %s", err.Error())
1241 }
1242 return pathsForModuleSrcFromFullPath(e, ret, true)
1243}
1244
1245func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1246 ret, err := e.GlobWithDeps(globPattern, excludes)
1247 if err != nil {
1248 e.ModuleErrorf("glob: %s", err.Error())
1249 }
1250 return pathsForModuleSrcFromFullPath(e, ret, false)
1251}
1252
Colin Cross988414c2020-01-11 01:11:46 +00001253func (b *earlyModuleContext) IsSymlink(path Path) bool {
1254 fileInfo, err := b.config.fs.Lstat(path.String())
1255 if err != nil {
1256 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1257 }
1258 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1259}
1260
1261func (b *earlyModuleContext) Readlink(path Path) string {
1262 dest, err := b.config.fs.Readlink(path.String())
1263 if err != nil {
1264 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1265 }
1266 return dest
1267}
1268
Colin Cross1184b642019-12-30 18:43:07 -08001269func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001270 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001271 return module
1272}
1273
1274func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001275 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001276}
1277
1278func (e *earlyModuleContext) AConfig() Config {
1279 return e.config
1280}
1281
1282func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1283 return DeviceConfig{e.config.deviceConfig}
1284}
1285
1286func (e *earlyModuleContext) Platform() bool {
1287 return e.kind == platformModule
1288}
1289
1290func (e *earlyModuleContext) DeviceSpecific() bool {
1291 return e.kind == deviceSpecificModule
1292}
1293
1294func (e *earlyModuleContext) SocSpecific() bool {
1295 return e.kind == socSpecificModule
1296}
1297
1298func (e *earlyModuleContext) ProductSpecific() bool {
1299 return e.kind == productSpecificModule
1300}
1301
1302func (e *earlyModuleContext) SystemExtSpecific() bool {
1303 return e.kind == systemExtSpecificModule
1304}
1305
1306type baseModuleContext struct {
1307 bp blueprint.BaseModuleContext
1308 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001309 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001310 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001311 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001312 targetPrimary bool
1313 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001314
1315 walkPath []Module
1316
1317 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001318}
1319
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +00001320func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
1321 return b.bp.OtherModuleName(m)
1322}
1323func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08001324func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Han67b141d2020-02-26 02:05:18 +09001325 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08001326}
1327func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1328 return b.bp.OtherModuleDependencyTag(m)
1329}
Ulya Trafimovichcc21bba2020-01-13 15:18:16 +00001330func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1331func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
1332 return b.bp.OtherModuleType(m)
1333}
Colin Cross1184b642019-12-30 18:43:07 -08001334
1335func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1336 return b.bp.GetDirectDepWithTag(name, tag)
1337}
1338
Colin Cross25de6c32019-06-06 14:29:25 -07001339type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001340 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001341 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001342 installDeps Paths
1343 installFiles Paths
1344 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001345 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001346
1347 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001348 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001349 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001350 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001351}
1352
Colin Crossb88b3c52019-06-10 15:15:17 -07001353func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1354 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001355 Rule: ErrorRule,
1356 Description: params.Description,
1357 Output: params.Output,
1358 Outputs: params.Outputs,
1359 ImplicitOutput: params.ImplicitOutput,
1360 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001361 Args: map[string]string{
1362 "error": err.Error(),
1363 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001364 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001365}
1366
Colin Cross25de6c32019-06-06 14:29:25 -07001367func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1368 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001369}
1370
Colin Cross0875c522017-11-28 17:34:01 -08001371func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001372 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001373 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001374 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001375 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001376 Outputs: params.Outputs.Strings(),
1377 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1378 Inputs: params.Inputs.Strings(),
1379 Implicits: params.Implicits.Strings(),
1380 OrderOnly: params.OrderOnly.Strings(),
1381 Args: params.Args,
1382 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001383 }
1384
Colin Cross33bfb0a2016-11-21 17:23:08 -08001385 if params.Depfile != nil {
1386 bparams.Depfile = params.Depfile.String()
1387 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001388 if params.Output != nil {
1389 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1390 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001391 if params.ImplicitOutput != nil {
1392 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1393 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001394 if params.Input != nil {
1395 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1396 }
1397 if params.Implicit != nil {
1398 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1399 }
1400
Colin Cross0b9f31f2019-02-28 11:00:01 -08001401 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1402 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1403 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1404 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1405 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1406 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001407
Colin Cross0875c522017-11-28 17:34:01 -08001408 return bparams
1409}
1410
Colin Cross25de6c32019-06-06 14:29:25 -07001411func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1412 if m.config.captureBuild {
1413 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001414 }
1415
Colin Crossdc35e212019-06-06 16:13:11 -07001416 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001417}
1418
Colin Cross25de6c32019-06-06 14:29:25 -07001419func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001420 argNames ...string) blueprint.Rule {
1421
Ramy Medhat79c4fcc2020-03-31 22:14:52 -04001422 if m.config.UseRemoteBuild() {
1423 if params.Pool == nil {
1424 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1425 // jobs to the local parallelism value
1426 params.Pool = localPool
1427 } else if params.Pool == remotePool {
1428 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
1429 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
1430 // parallelism.
1431 params.Pool = nil
1432 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07001433 }
1434
Colin Crossdc35e212019-06-06 16:13:11 -07001435 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001436
Colin Cross25de6c32019-06-06 14:29:25 -07001437 if m.config.captureBuild {
1438 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001439 }
1440
1441 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001442}
1443
Colin Cross25de6c32019-06-06 14:29:25 -07001444func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001445 if params.Description != "" {
1446 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1447 }
1448
1449 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1450 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1451 m.ModuleName(), strings.Join(missingDeps, ", ")))
1452 }
1453
Colin Cross25de6c32019-06-06 14:29:25 -07001454 if m.config.captureBuild {
1455 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001456 }
1457
Colin Crossdc35e212019-06-06 16:13:11 -07001458 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001459}
Colin Cross25de6c32019-06-06 14:29:25 -07001460func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001461 var missingDeps []string
1462 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001463 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001464 missingDeps = FirstUniqueStrings(missingDeps)
1465 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001466}
1467
Colin Crossdc35e212019-06-06 16:13:11 -07001468func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001469 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001470 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001471 *missingDeps = append(*missingDeps, deps...)
1472 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001473 }
1474}
1475
Colin Crossdc35e212019-06-06 16:13:11 -07001476func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001477 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001478
1479 if !strict {
1480 return aModule
1481 }
1482
Colin Cross380c69a2019-06-10 17:49:58 +00001483 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001484 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001485 return nil
1486 }
1487
1488 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001489 if b.Config().AllowMissingDependencies() {
1490 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001491 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001492 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001493 }
1494 return nil
1495 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001496 return aModule
1497}
1498
Colin Crossdc35e212019-06-06 16:13:11 -07001499func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001500 type dep struct {
1501 mod blueprint.Module
1502 tag blueprint.DependencyTag
1503 }
1504 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001505 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001506 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001507 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001508 if tag == nil || returnedTag == tag {
1509 deps = append(deps, dep{aModule, returnedTag})
1510 }
1511 }
1512 })
1513 if len(deps) == 1 {
1514 return deps[0].mod, deps[0].tag
1515 } else if len(deps) >= 2 {
1516 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001517 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001518 } else {
1519 return nil, nil
1520 }
1521}
1522
Colin Crossdc35e212019-06-06 16:13:11 -07001523func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001524 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001525 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001526 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001527 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001528 deps = append(deps, aModule)
1529 }
1530 }
1531 })
1532 return deps
1533}
1534
Colin Cross25de6c32019-06-06 14:29:25 -07001535func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1536 module, _ := m.getDirectDepInternal(name, tag)
1537 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001538}
1539
Colin Crossdc35e212019-06-06 16:13:11 -07001540func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1541 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001542}
1543
Colin Crossdc35e212019-06-06 16:13:11 -07001544func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001545 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001546}
1547
Colin Crossdc35e212019-06-06 16:13:11 -07001548func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001549 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001550 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001551 visit(aModule)
1552 }
1553 })
1554}
1555
Colin Crossdc35e212019-06-06 16:13:11 -07001556func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001557 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001558 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001559 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001560 visit(aModule)
1561 }
1562 }
1563 })
1564}
1565
Colin Crossdc35e212019-06-06 16:13:11 -07001566func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001567 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001568 // pred
1569 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001570 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001571 return pred(aModule)
1572 } else {
1573 return false
1574 }
1575 },
1576 // visit
1577 func(module blueprint.Module) {
1578 visit(module.(Module))
1579 })
1580}
1581
Colin Crossdc35e212019-06-06 16:13:11 -07001582func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001583 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001584 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001585 visit(aModule)
1586 }
1587 })
1588}
1589
Colin Crossdc35e212019-06-06 16:13:11 -07001590func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001591 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001592 // pred
1593 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001594 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001595 return pred(aModule)
1596 } else {
1597 return false
1598 }
1599 },
1600 // visit
1601 func(module blueprint.Module) {
1602 visit(module.(Module))
1603 })
1604}
1605
Colin Crossdc35e212019-06-06 16:13:11 -07001606func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001607 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001608}
1609
Colin Crossdc35e212019-06-06 16:13:11 -07001610func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1611 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001612 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001613 childAndroidModule, _ := child.(Module)
1614 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001615 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001616 // record walkPath before visit
1617 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1618 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1619 }
1620 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001621 return visit(childAndroidModule, parentAndroidModule)
1622 } else {
1623 return false
1624 }
1625 })
1626}
1627
Colin Crossdc35e212019-06-06 16:13:11 -07001628func (b *baseModuleContext) GetWalkPath() []Module {
1629 return b.walkPath
1630}
1631
Colin Cross25de6c32019-06-06 14:29:25 -07001632func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001633 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001634 visit(module.(Module))
1635 })
1636}
1637
Colin Cross25de6c32019-06-06 14:29:25 -07001638func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001639 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001640}
1641
Colin Cross25de6c32019-06-06 14:29:25 -07001642func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001643 return m.bp.FinalModule().(Module)
1644}
1645
1646func (m *moduleContext) ModuleSubDir() string {
1647 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001648}
1649
Colin Cross0ea8ba82019-06-06 14:33:29 -07001650func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001651 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001652}
1653
Colin Cross0ea8ba82019-06-06 14:33:29 -07001654func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001655 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001656}
1657
Colin Cross0ea8ba82019-06-06 14:33:29 -07001658func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001659 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001660}
1661
Colin Cross0ea8ba82019-06-06 14:33:29 -07001662func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001663 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001664}
1665
Colin Cross0ea8ba82019-06-06 14:33:29 -07001666func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001667 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001668}
1669
Colin Cross0ea8ba82019-06-06 14:33:29 -07001670func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001671 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001672}
1673
Colin Cross0ea8ba82019-06-06 14:33:29 -07001674func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001675 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001676}
1677
Colin Cross0ea8ba82019-06-06 14:33:29 -07001678func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001679 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001680}
1681
Colin Cross0ea8ba82019-06-06 14:33:29 -07001682func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001683 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001684}
1685
Colin Cross0ea8ba82019-06-06 14:33:29 -07001686func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001687 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001688}
1689
Colin Cross0ea8ba82019-06-06 14:33:29 -07001690func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001691 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001692}
1693
Colin Cross0ea8ba82019-06-06 14:33:29 -07001694func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001695 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001696 return true
1697 }
Colin Cross25de6c32019-06-06 14:29:25 -07001698 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001699}
1700
Jiyong Park5baac542018-08-28 09:55:37 +09001701// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001702// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001703func (m *ModuleBase) MakeAsPlatform() {
1704 m.commonProperties.Vendor = boolPtr(false)
1705 m.commonProperties.Proprietary = boolPtr(false)
1706 m.commonProperties.Soc_specific = boolPtr(false)
1707 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001708 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001709}
1710
Colin Cross4157e882019-06-06 16:57:04 -07001711func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1712 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001713}
1714
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001715func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001716 m.commonProperties.Vendor = boolPtr(false)
1717 m.commonProperties.Proprietary = boolPtr(false)
1718 m.commonProperties.Soc_specific = boolPtr(false)
1719 m.commonProperties.Product_specific = boolPtr(false)
1720 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001721}
1722
Jooyung Han344d5432019-08-23 11:17:39 +09001723// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1724func (m *ModuleBase) IsNativeBridgeSupported() bool {
1725 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1726}
1727
Colin Cross25de6c32019-06-06 14:29:25 -07001728func (m *moduleContext) InstallInData() bool {
1729 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001730}
1731
Jaewoong Jung0949f312019-09-11 10:25:18 -07001732func (m *moduleContext) InstallInTestcases() bool {
1733 return m.module.InstallInTestcases()
1734}
1735
Colin Cross25de6c32019-06-06 14:29:25 -07001736func (m *moduleContext) InstallInSanitizerDir() bool {
1737 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001738}
1739
Yifan Hong1b3348d2020-01-21 15:53:22 -08001740func (m *moduleContext) InstallInRamdisk() bool {
1741 return m.module.InstallInRamdisk()
1742}
1743
Colin Cross25de6c32019-06-06 14:29:25 -07001744func (m *moduleContext) InstallInRecovery() bool {
1745 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001746}
1747
Colin Cross90ba5f42019-10-02 11:10:58 -07001748func (m *moduleContext) InstallInRoot() bool {
1749 return m.module.InstallInRoot()
1750}
1751
Colin Cross607d8582019-07-29 16:44:46 -07001752func (m *moduleContext) InstallBypassMake() bool {
1753 return m.module.InstallBypassMake()
1754}
1755
Colin Cross70dda7e2019-10-01 22:05:35 -07001756func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001757 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001758 return true
1759 }
1760
Colin Cross3607f212018-05-07 15:28:05 -07001761 // We'll need a solution for choosing which of modules with the same name in different
1762 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1763 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001764 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001765 return true
1766 }
1767
Colin Cross25de6c32019-06-06 14:29:25 -07001768 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001769 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001770 return true
1771 }
1772
Colin Cross25de6c32019-06-06 14:29:25 -07001773 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001774 return true
1775 }
1776 }
1777
1778 return false
1779}
1780
Colin Cross70dda7e2019-10-01 22:05:35 -07001781func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1782 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001783 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001784}
1785
Colin Cross70dda7e2019-10-01 22:05:35 -07001786func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1787 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001788 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001789}
1790
Colin Cross70dda7e2019-10-01 22:05:35 -07001791func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1792 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001793
Colin Cross25de6c32019-06-06 14:29:25 -07001794 fullInstallPath := installPath.Join(m, name)
1795 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001796
Colin Cross25de6c32019-06-06 14:29:25 -07001797 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001798
Colin Cross25de6c32019-06-06 14:29:25 -07001799 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001800
Colin Cross89562dc2016-10-03 17:47:19 -07001801 var implicitDeps, orderOnlyDeps Paths
1802
Colin Cross25de6c32019-06-06 14:29:25 -07001803 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001804 // Installed host modules might be used during the build, depend directly on their
1805 // dependencies so their timestamp is updated whenever their dependency is updated
1806 implicitDeps = deps
1807 } else {
1808 orderOnlyDeps = deps
1809 }
1810
Colin Cross25de6c32019-06-06 14:29:25 -07001811 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001812 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001813 Description: "install " + fullInstallPath.Base(),
1814 Output: fullInstallPath,
1815 Input: srcPath,
1816 Implicits: implicitDeps,
1817 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001818 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001819 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001820
Colin Cross25de6c32019-06-06 14:29:25 -07001821 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001822 }
Colin Cross25de6c32019-06-06 14:29:25 -07001823 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001824 return fullInstallPath
1825}
1826
Colin Cross70dda7e2019-10-01 22:05:35 -07001827func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001828 fullInstallPath := installPath.Join(m, name)
1829 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001830
Colin Cross25de6c32019-06-06 14:29:25 -07001831 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001832
Alex Lightfb4353d2019-01-17 13:57:45 -08001833 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1834 if err != nil {
1835 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1836 }
Colin Cross25de6c32019-06-06 14:29:25 -07001837 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001838 Rule: Symlink,
1839 Description: "install symlink " + fullInstallPath.Base(),
1840 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08001841 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001842 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001843 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001844 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001845 },
1846 })
Colin Cross3854a602016-01-11 12:49:11 -08001847
Colin Cross25de6c32019-06-06 14:29:25 -07001848 m.installFiles = append(m.installFiles, fullInstallPath)
1849 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001850 }
Colin Cross3854a602016-01-11 12:49:11 -08001851 return fullInstallPath
1852}
1853
Jiyong Parkf1194352019-02-25 11:05:47 +09001854// installPath/name -> absPath where absPath might be a path that is available only at runtime
1855// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001856func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001857 fullInstallPath := installPath.Join(m, name)
1858 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001859
Colin Cross25de6c32019-06-06 14:29:25 -07001860 if !m.skipInstall(fullInstallPath) {
1861 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001862 Rule: Symlink,
1863 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1864 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001865 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001866 Args: map[string]string{
1867 "fromPath": absPath,
1868 },
1869 })
1870
Colin Cross25de6c32019-06-06 14:29:25 -07001871 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001872 }
1873 return fullInstallPath
1874}
1875
Colin Cross25de6c32019-06-06 14:29:25 -07001876func (m *moduleContext) CheckbuildFile(srcPath Path) {
1877 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001878}
1879
Colin Cross3f40fa42015-01-30 17:27:36 -08001880type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001881 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001882}
1883
1884func isFileInstaller(m blueprint.Module) bool {
1885 _, ok := m.(fileInstaller)
1886 return ok
1887}
1888
1889func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001890 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001891 return ok
1892}
Colin Crossfce53272015-04-08 11:21:40 -07001893
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001894func findStringInSlice(str string, slice []string) int {
1895 for i, s := range slice {
1896 if s == str {
1897 return i
Colin Crossfce53272015-04-08 11:21:40 -07001898 }
1899 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001900 return -1
1901}
1902
Colin Cross41955e82019-05-29 14:40:35 -07001903// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1904// was not a module reference.
1905func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001906 if len(s) > 1 && s[0] == ':' {
1907 return s[1:]
1908 }
1909 return ""
1910}
1911
Colin Cross41955e82019-05-29 14:40:35 -07001912// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1913// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1914func SrcIsModuleWithTag(s string) (module, tag string) {
1915 if len(s) > 1 && s[0] == ':' {
1916 module = s[1:]
1917 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1918 if module[len(module)-1] == '}' {
1919 tag = module[tagStart+1 : len(module)-1]
1920 module = module[:tagStart]
1921 return module, tag
1922 }
1923 }
1924 return module, ""
1925 }
1926 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001927}
1928
Colin Cross41955e82019-05-29 14:40:35 -07001929type sourceOrOutputDependencyTag struct {
1930 blueprint.BaseDependencyTag
1931 tag string
1932}
1933
1934func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1935 return sourceOrOutputDependencyTag{tag: tag}
1936}
1937
1938var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001939
Colin Cross366938f2017-12-11 16:29:02 -08001940// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1941// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001942//
1943// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001944func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001945 set := make(map[string]bool)
1946
Colin Cross068e0fe2016-12-13 15:23:47 -08001947 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001948 if m, t := SrcIsModuleWithTag(s); m != "" {
1949 if _, found := set[s]; found {
1950 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001951 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001952 set[s] = true
1953 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001954 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001955 }
1956 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001957}
1958
Colin Cross366938f2017-12-11 16:29:02 -08001959// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1960// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001961//
1962// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001963func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1964 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001965 if m, t := SrcIsModuleWithTag(*s); m != "" {
1966 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001967 }
1968 }
1969}
1970
Colin Cross41955e82019-05-29 14:40:35 -07001971// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1972// 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 -08001973type SourceFileProducer interface {
1974 Srcs() Paths
1975}
1976
Colin Cross41955e82019-05-29 14:40:35 -07001977// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00001978// 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 -07001979// listed in the property.
1980type OutputFileProducer interface {
1981 OutputFiles(tag string) (Paths, error)
1982}
1983
Colin Cross5e708052019-08-06 13:59:50 -07001984// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
1985// module produced zero paths, it reports errors to the ctx and returns nil.
1986func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
1987 paths, err := outputFilesForModule(ctx, module, tag)
1988 if err != nil {
1989 reportPathError(ctx, err)
1990 return nil
1991 }
1992 return paths
1993}
1994
1995// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
1996// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
1997func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
1998 paths, err := outputFilesForModule(ctx, module, tag)
1999 if err != nil {
2000 reportPathError(ctx, err)
2001 return nil
2002 }
2003 if len(paths) > 1 {
2004 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
2005 pathContextName(ctx, module))
2006 return nil
2007 }
2008 return paths[0]
2009}
2010
2011func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2012 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2013 paths, err := outputFileProducer.OutputFiles(tag)
2014 if err != nil {
2015 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2016 pathContextName(ctx, module), err.Error())
2017 }
2018 if len(paths) == 0 {
2019 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2020 }
2021 return paths, nil
2022 } else {
2023 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2024 }
2025}
2026
Colin Crossfe17f6f2019-03-28 19:30:56 -07002027type HostToolProvider interface {
2028 HostToolPath() OptionalPath
2029}
2030
Colin Cross27b922f2019-03-04 22:35:41 -08002031// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2032// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002033//
2034// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002035func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2036 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002037}
2038
Colin Cross2fafa3e2019-03-05 12:39:51 -08002039// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2040// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002041//
2042// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002043func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2044 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002045}
2046
2047// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2048// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2049// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002050func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002051 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002052 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002053 }
2054 return OptionalPath{}
2055}
2056
Colin Cross25de6c32019-06-06 14:29:25 -07002057func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002058 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002059}
2060
Colin Cross25de6c32019-06-06 14:29:25 -07002061func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002062 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002063}
2064
Colin Cross25de6c32019-06-06 14:29:25 -07002065func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002066 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002067}
2068
Colin Cross463a90e2015-06-17 14:20:06 -07002069func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002070 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002071}
2072
Colin Cross0875c522017-11-28 17:34:01 -08002073func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002074 return &buildTargetSingleton{}
2075}
2076
Colin Cross87d8b562017-04-25 10:01:55 -07002077func parentDir(dir string) string {
2078 dir, _ = filepath.Split(dir)
2079 return filepath.Clean(dir)
2080}
2081
Colin Cross1f8c52b2015-06-16 16:38:17 -07002082type buildTargetSingleton struct{}
2083
Colin Cross0875c522017-11-28 17:34:01 -08002084func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2085 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002086
Colin Cross0875c522017-11-28 17:34:01 -08002087 mmTarget := func(dir string) WritablePath {
2088 return PathForPhony(ctx,
2089 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07002090 }
2091
Colin Cross0875c522017-11-28 17:34:01 -08002092 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002093
Colin Cross0875c522017-11-28 17:34:01 -08002094 ctx.VisitAllModules(func(module Module) {
2095 blueprintDir := module.base().blueprintDir
2096 installTarget := module.base().installTarget
2097 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002098
Colin Cross0875c522017-11-28 17:34:01 -08002099 if checkbuildTarget != nil {
2100 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2101 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2102 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002103
Colin Cross0875c522017-11-28 17:34:01 -08002104 if installTarget != nil {
2105 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002106 }
2107 })
2108
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002109 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002110 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002111 suffix = "-soong"
2112 }
2113
Colin Cross1f8c52b2015-06-16 16:38:17 -07002114 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08002115 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002116 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002117 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002118 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07002119 })
2120
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002121 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002122 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002123 return
2124 }
2125
Colin Cross87d8b562017-04-25 10:01:55 -07002126 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002127 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002128 for _, dir := range dirs {
2129 dir := parentDir(dir)
2130 for dir != "." && dir != "/" {
2131 if _, exists := modulesInDir[dir]; exists {
2132 break
2133 }
2134 modulesInDir[dir] = nil
2135 dir = parentDir(dir)
2136 }
2137 }
2138
2139 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002140 for _, dir := range dirs {
2141 p := parentDir(dir)
2142 if p != "." && p != "/" {
2143 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2144 }
2145 }
2146
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002147 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2148 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2149 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002150 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002151 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002152 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002153 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002154 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002155 // HACK: checkbuild should be an optional build, but force it
2156 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002157 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002158 })
2159 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002160
2161 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2162 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002163 ctx.VisitAllModules(func(module Module) {
2164 if module.Enabled() {
2165 os := module.Target().Os
2166 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002167 }
2168 })
2169
Colin Cross0875c522017-11-28 17:34:01 -08002170 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002171 for os, deps := range osDeps {
2172 var className string
2173
2174 switch os.Class {
2175 case Host:
2176 className = "host"
2177 case HostCross:
2178 className = "host-cross"
2179 case Device:
2180 className = "target"
2181 default:
2182 continue
2183 }
2184
Colin Cross0875c522017-11-28 17:34:01 -08002185 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002186 osClass[className] = append(osClass[className], name)
2187
Colin Cross0875c522017-11-28 17:34:01 -08002188 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002189 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002190 Output: name,
2191 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002192 })
2193 }
2194
2195 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002196 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002197 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002198 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002199 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002200 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002201 })
2202 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002203}
Colin Crossd779da42015-12-17 18:00:23 -08002204
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002205// Collect information for opening IDE project files in java/jdeps.go.
2206type IDEInfo interface {
2207 IDEInfo(ideInfo *IdeInfo)
2208 BaseModuleName() string
2209}
2210
2211// Extract the base module name from the Import name.
2212// Often the Import name has a prefix "prebuilt_".
2213// Remove the prefix explicitly if needed
2214// until we find a better solution to get the Import name.
2215type IDECustomizedModuleName interface {
2216 IDECustomizedModuleName() string
2217}
2218
2219type IdeInfo struct {
2220 Deps []string `json:"dependencies,omitempty"`
2221 Srcs []string `json:"srcs,omitempty"`
2222 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2223 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2224 Jars []string `json:"jars,omitempty"`
2225 Classes []string `json:"class,omitempty"`
2226 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002227 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002228}