blob: b98f1e4d3f9dbcd40d04eda2faf33c165c67610c [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"
Alex Lightfb4353d2019-01-17 13:57:45 -080019 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "path/filepath"
Colin Cross6ff51382015-12-17 16:39:19 -080021 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080022 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070023
24 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070025 "github.com/google/blueprint/pathtools"
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
65
66 ContainsProperty(name string) bool
67 Errorf(pos scanner.Position, fmt string, args ...interface{})
68 ModuleErrorf(fmt string, args ...interface{})
69 PropertyErrorf(property, fmt string, args ...interface{})
70 Failed() bool
71
72 AddNinjaFileDeps(deps ...string)
73
74 DeviceSpecific() bool
75 SocSpecific() bool
76 ProductSpecific() bool
77 SystemExtSpecific() bool
78 Platform() bool
79
80 Config() Config
81 DeviceConfig() DeviceConfig
82
83 // Deprecated: use Config()
84 AConfig() Config
85
86 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
87 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
88 // builder whenever a file matching the pattern as added or removed, without rerunning if a
89 // file that does not match the pattern is added to a searched directory.
90 GlobWithDeps(pattern string, excludes []string) ([]string, error)
91
92 Glob(globPattern string, excludes []string) Paths
93 GlobFiles(globPattern string, excludes []string) Paths
94 Fs() pathtools.FileSystem
95}
96
Colin Cross0ea8ba82019-06-06 14:33:29 -070097// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -070098// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
99// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700100// about the current module.
101type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800102 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700103
Colin Crossdc35e212019-06-06 16:13:11 -0700104 OtherModuleName(m blueprint.Module) string
105 OtherModuleDir(m blueprint.Module) string
106 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
107 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
108 OtherModuleExists(name string) bool
Jiyong Park9e6c2422019-08-09 20:39:45 +0900109 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700110
111 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
112 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
113 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
114
115 VisitDirectDepsBlueprint(visit func(blueprint.Module))
116 VisitDirectDeps(visit func(Module))
117 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
118 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
119 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
120 VisitDepsDepthFirst(visit func(Module))
121 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
122 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
123 WalkDeps(visit func(Module, Module) bool)
124 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
125 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
126 // and returns a top-down dependency path from a start module to current child module.
127 GetWalkPath() []Module
128
Colin Crossdc35e212019-06-06 16:13:11 -0700129 AddMissingDependencies(missingDeps []string)
130
Colin Crossa1ad8d12016-06-01 17:09:44 -0700131 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700132 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -0700133 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700134 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700135 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700136 Host() bool
137 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700138 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800139 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700140 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700141 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700142 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700143}
144
Colin Cross1184b642019-12-30 18:43:07 -0800145// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700146type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800147 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800148}
149
Colin Cross635c3b02016-05-18 15:37:25 -0700150type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800151 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800152
Colin Crossae887032017-10-23 17:16:14 -0700153 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800154 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700155
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700156 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800157 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800158 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700159
Colin Cross70dda7e2019-10-01 22:05:35 -0700160 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
161 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
162 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
163 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700164 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800165
Colin Cross8d8f8e22016-08-03 11:57:50 -0700166 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700167 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700168 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900169 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700170 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700171 InstallBypassMake() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800172
173 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700174 HostRequiredModuleNames() []string
175 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700176
Colin Cross3f68a132017-10-23 17:10:29 -0700177 ModuleSubDir() string
178
Colin Cross0875c522017-11-28 17:34:01 -0800179 Variable(pctx PackageContext, name, value string)
180 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700181 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
182 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800183 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700184
Colin Cross0875c522017-11-28 17:34:01 -0800185 PrimaryModule() Module
186 FinalModule() Module
187 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700188
189 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800190 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800191}
192
Colin Cross635c3b02016-05-18 15:37:25 -0700193type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800194 blueprint.Module
195
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700196 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
197 // but GenerateAndroidBuildActions also has access to Android-specific information.
198 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700199 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700200
Colin Cross1e676be2016-10-12 14:38:15 -0700201 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800202
Colin Cross635c3b02016-05-18 15:37:25 -0700203 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800204 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700205 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800206 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700207 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700208 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900209 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700210 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700211 InstallBypassMake() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800212 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900213 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900214 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700215
216 AddProperties(props ...interface{})
217 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700218
Colin Crossae887032017-10-23 17:16:14 -0700219 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800220 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800221 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100222
Colin Cross9a362232019-07-01 15:32:45 -0700223 // String returns a string that includes the module name and variants for printing during debugging.
224 String() string
225
Paul Duffine2453c72019-05-31 14:00:04 +0100226 // Get the qualified module id for this module.
227 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
228
229 // Get information about the properties that can contain visibility rules.
230 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100231
232 // Get the visibility rules that control the visibility of this module.
233 visibility() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100234}
235
236// Qualified id for a module
237type qualifiedModuleName struct {
238 // The package (i.e. directory) in which the module is defined, without trailing /
239 pkg string
240
241 // The name of the module, empty string if package.
242 name string
243}
244
245func (q qualifiedModuleName) String() string {
246 if q.name == "" {
247 return "//" + q.pkg
248 }
249 return "//" + q.pkg + ":" + q.name
250}
251
Paul Duffine484f472019-06-20 16:38:08 +0100252func (q qualifiedModuleName) isRootPackage() bool {
253 return q.pkg == "" && q.name == ""
254}
255
Paul Duffine2453c72019-05-31 14:00:04 +0100256// Get the id for the package containing this module.
257func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
258 pkg := q.pkg
259 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100260 if pkg == "" {
261 panic(fmt.Errorf("Cannot get containing package id of root package"))
262 }
263
264 index := strings.LastIndex(pkg, "/")
265 if index == -1 {
266 pkg = ""
267 } else {
268 pkg = pkg[:index]
269 }
Paul Duffine2453c72019-05-31 14:00:04 +0100270 }
271 return newPackageId(pkg)
272}
273
274func newPackageId(pkg string) qualifiedModuleName {
275 // A qualified id for a package module has no name.
276 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800277}
278
Colin Crossfc754582016-05-17 16:34:16 -0700279type nameProperties struct {
280 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800281 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700282}
283
284type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800285 // emit build rules for this module
286 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800287
Paul Duffin2e61fa62019-03-28 14:10:57 +0000288 // Controls the visibility of this module to other modules. Allowable values are one or more of
289 // these formats:
290 //
291 // ["//visibility:public"]: Anyone can use this module.
292 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
293 // this module.
294 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
295 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
296 // this module. Note that sub-packages do not have access to the rule; for example,
297 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
298 // is a special module and must be used verbatim. It represents all of the modules in the
299 // package.
300 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
301 // or other or in one of their sub-packages have access to this module. For example,
302 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
303 // to depend on this rule (but not //independent:evil)
304 // ["//project"]: This is shorthand for ["//project:__pkg__"]
305 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
306 // //project is the module's package. e.g. using [":__subpackages__"] in
307 // packages/apps/Settings/Android.bp is equivalent to
308 // //packages/apps/Settings:__subpackages__.
309 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
310 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100311 //
312 // If a module does not specify the `visibility` property then it uses the
313 // `default_visibility` property of the `package` module in the module's package.
314 //
315 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100316 // it will use the `default_visibility` of its closest ancestor package for which
317 // a `default_visibility` property is specified.
318 //
319 // If no `default_visibility` property can be found then the module uses the
320 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100321 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100322 // The `visibility` property has no effect on a defaults module although it does
323 // apply to any non-defaults module that uses it. To set the visibility of a
324 // defaults module, use the `defaults_visibility` property on the defaults module;
325 // not to be confused with the `default_visibility` property on the package module.
326 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000327 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
328 // more details.
329 Visibility []string
330
Colin Cross7d5136f2015-05-11 13:39:40 -0700331 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800332 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
333 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
334 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700335 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700336
337 Target struct {
338 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700339 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700340 }
341 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700342 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700343 }
344 }
345
Colin Crossee0bc3b2018-10-02 22:01:37 -0700346 UseTargetVariants bool `blueprint:"mutated"`
347 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800348
Dan Willemsen782a2d12015-12-21 14:55:28 -0800349 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700350 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800351
Colin Cross55708f32017-03-20 13:23:34 -0700352 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700353 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700354
Jiyong Park2db76922017-11-08 16:03:48 +0900355 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
356 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
357 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700358 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700359
Jiyong Park2db76922017-11-08 16:03:48 +0900360 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
361 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
362 Soc_specific *bool
363
364 // whether this module is specific to a device, not only for SoC, but also for off-chip
365 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
366 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
367 // This implies `soc_specific:true`.
368 Device_specific *bool
369
370 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900371 // network operator, etc). When set to true, it is installed into /product (or
372 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900373 Product_specific *bool
374
Justin Yund5f6c822019-06-25 16:47:17 +0900375 // whether this module extends system. When set to true, it is installed into /system_ext
376 // (or /system/system_ext if system_ext partition does not exist).
377 System_ext_specific *bool
378
Jiyong Parkf9332f12018-02-01 00:54:12 +0900379 // Whether this module is installed to recovery partition
380 Recovery *bool
381
dimitry1f33e402019-03-26 12:39:31 +0100382 // Whether this module is built for non-native architecures (also known as native bridge binary)
383 Native_bridge_supported *bool `android:"arch_variant"`
384
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700385 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800386 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700387
Steven Moreland57a23d22018-04-04 15:42:19 -0700388 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800389 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700390
Chris Wolfe998306e2016-08-15 14:47:23 -0400391 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700392 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400393
Sasha Smundakb6d23052019-04-01 18:37:36 -0700394 // names of other modules to install on host if this module is installed
395 Host_required []string `android:"arch_variant"`
396
397 // names of other modules to install on target if this module is installed
398 Target_required []string `android:"arch_variant"`
399
Colin Cross5aac3622017-08-31 15:07:09 -0700400 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800401 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700402
Dan Willemsen569edc52018-11-19 09:33:29 -0800403 Dist struct {
404 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
405 // command line and any of these targets are also on the command line, or otherwise
406 // built
407 Targets []string `android:"arch_variant"`
408
409 // The name of the output artifact. This defaults to the basename of the output of
410 // the module.
411 Dest *string `android:"arch_variant"`
412
413 // The directory within the dist directory to store the artifact. Defaults to the
414 // top level directory ("").
415 Dir *string `android:"arch_variant"`
416
417 // A suffix to add to the artifact file name (before any extension).
418 Suffix *string `android:"arch_variant"`
419 } `android:"arch_variant"`
420
Colin Crossa1ad8d12016-06-01 17:09:44 -0700421 // Set by TargetMutator
Colin Crossa195f912019-10-16 11:07:20 -0700422 CompileOS OsType `blueprint:"mutated"`
Colin Crossee0bc3b2018-10-02 22:01:37 -0700423 CompileTarget Target `blueprint:"mutated"`
424 CompileMultiTargets []Target `blueprint:"mutated"`
425 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800426
427 // Set by InitAndroidModule
428 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700429 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700430
431 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800432
433 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700434
435 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700436
437 // Name and variant strings stored by mutators to enable Module.String()
438 DebugName string `blueprint:"mutated"`
439 DebugMutators []string `blueprint:"mutated"`
440 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800441
442 // set by ImageMutator
443 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800444}
445
446type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800447 // If set to true, build a variant of the module for the host. Defaults to false.
448 Host_supported *bool
449
450 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700451 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800452}
453
Colin Crossc472d572015-03-17 15:06:21 -0700454type Multilib string
455
456const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800457 MultilibBoth Multilib = "both"
458 MultilibFirst Multilib = "first"
459 MultilibCommon Multilib = "common"
460 MultilibCommonFirst Multilib = "common_first"
461 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700462)
463
Colin Crossa1ad8d12016-06-01 17:09:44 -0700464type HostOrDeviceSupported int
465
466const (
467 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700468
469 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700470 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700471
472 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700473 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700474
475 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700476 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700477
478 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700479 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700480
481 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700482 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700483
484 // Nothing is supported. This is not exposed to the user, but used to mark a
485 // host only module as unsupported when the module type is not supported on
486 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700487 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700488)
489
Jiyong Park2db76922017-11-08 16:03:48 +0900490type moduleKind int
491
492const (
493 platformModule moduleKind = iota
494 deviceSpecificModule
495 socSpecificModule
496 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900497 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900498)
499
500func (k moduleKind) String() string {
501 switch k {
502 case platformModule:
503 return "platform"
504 case deviceSpecificModule:
505 return "device-specific"
506 case socSpecificModule:
507 return "soc-specific"
508 case productSpecificModule:
509 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900510 case systemExtSpecificModule:
511 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900512 default:
513 panic(fmt.Errorf("unknown module kind %d", k))
514 }
515}
516
Colin Cross36242852017-06-23 15:06:31 -0700517func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800518 base := m.base()
519 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700520
Colin Cross36242852017-06-23 15:06:31 -0700521 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700522 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700523 &base.commonProperties)
524
525 // Allow tests to override the default product variables
526 if base.variableProperties == nil {
527 base.variableProperties = zeroProductVariables
528 }
529
530 // Filter the product variables properties to the ones that exist on this module
531 base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
532 if base.variableProperties != nil {
533 m.AddProperties(base.variableProperties)
534 }
535
Colin Crossa3a97412019-03-18 12:24:29 -0700536 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700537 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100538
539 // The default_visibility property needs to be checked and parsed by the visibility module during
540 // its checking and parsing phases.
541 base.primaryVisibilityProperty =
542 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
543 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700544}
545
Colin Cross36242852017-06-23 15:06:31 -0700546func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
547 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700548
549 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800550 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700551 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700552 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700553 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800554
Dan Willemsen218f6562015-07-08 18:13:11 -0700555 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700556 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700557 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800558 }
559
Colin Cross36242852017-06-23 15:06:31 -0700560 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800561}
562
Colin Crossee0bc3b2018-10-02 22:01:37 -0700563func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
564 InitAndroidArchModule(m, hod, defaultMultilib)
565 m.base().commonProperties.UseTargetVariants = false
566}
567
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800568// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800569// modules. It should be included as an anonymous field in every module
570// struct definition. InitAndroidModule should then be called from the module's
571// factory function, and the return values from InitAndroidModule should be
572// returned from the factory function.
573//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800574// The ModuleBase type is responsible for implementing the GenerateBuildActions
575// method to support the blueprint.Module interface. This method will then call
576// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700577// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
578// rather than the usual blueprint.ModuleContext.
579// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800580// system including details about the particular build variant that is to be
581// generated.
582//
583// For example:
584//
585// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800586// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800587// )
588//
589// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800590// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800591// properties struct {
592// MyProperty string
593// }
594// }
595//
Colin Cross36242852017-06-23 15:06:31 -0700596// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800597// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700598// m.AddProperties(&m.properties)
599// android.InitAndroidModule(m)
600// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800601// }
602//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800603// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800604// // Get the CPU architecture for the current build variant.
605// variantArch := ctx.Arch()
606//
607// // ...
608// }
Colin Cross635c3b02016-05-18 15:37:25 -0700609type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800610 // Putting the curiously recurring thing pointing to the thing that contains
611 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700612 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700613 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800614
Colin Crossfc754582016-05-17 16:34:16 -0700615 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800616 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700617 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800618 hostAndDeviceProperties hostAndDeviceProperties
619 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700620 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700621 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800622
Paul Duffin63c6e182019-07-24 14:24:38 +0100623 // Information about all the properties on the module that contains visibility rules that need
624 // checking.
625 visibilityPropertyInfo []visibilityProperty
626
627 // The primary visibility property, may be nil, that controls access to the module.
628 primaryVisibilityProperty visibilityProperty
629
Colin Cross3f40fa42015-01-30 17:27:36 -0800630 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700631 installFiles Paths
632 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900633 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700634
635 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
636 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800637 installTarget WritablePath
638 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700639 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700640
Colin Cross178a5092016-09-13 13:42:32 -0700641 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700642
643 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700644
645 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700646 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800647 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800648 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700649
650 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700651}
652
Colin Cross4157e882019-06-06 16:57:04 -0700653func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800654
Colin Cross4157e882019-06-06 16:57:04 -0700655func (m *ModuleBase) AddProperties(props ...interface{}) {
656 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700657}
658
Colin Cross4157e882019-06-06 16:57:04 -0700659func (m *ModuleBase) GetProperties() []interface{} {
660 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800661}
662
Colin Cross4157e882019-06-06 16:57:04 -0700663func (m *ModuleBase) BuildParamsForTests() []BuildParams {
664 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700665}
666
Colin Cross4157e882019-06-06 16:57:04 -0700667func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
668 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800669}
670
Colin Cross4157e882019-06-06 16:57:04 -0700671func (m *ModuleBase) VariablesForTests() map[string]string {
672 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800673}
674
Colin Cross4157e882019-06-06 16:57:04 -0700675func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
676 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700677}
678
Colin Crossce75d2c2016-10-06 16:12:58 -0700679// Name returns the name of the module. It may be overridden by individual module types, for
680// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700681func (m *ModuleBase) Name() string {
682 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700683}
684
Colin Cross9a362232019-07-01 15:32:45 -0700685// String returns a string that includes the module name and variants for printing during debugging.
686func (m *ModuleBase) String() string {
687 sb := strings.Builder{}
688 sb.WriteString(m.commonProperties.DebugName)
689 sb.WriteString("{")
690 for i := range m.commonProperties.DebugMutators {
691 if i != 0 {
692 sb.WriteString(",")
693 }
694 sb.WriteString(m.commonProperties.DebugMutators[i])
695 sb.WriteString(":")
696 sb.WriteString(m.commonProperties.DebugVariations[i])
697 }
698 sb.WriteString("}")
699 return sb.String()
700}
701
Colin Crossce75d2c2016-10-06 16:12:58 -0700702// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700703func (m *ModuleBase) BaseModuleName() string {
704 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700705}
706
Colin Cross4157e882019-06-06 16:57:04 -0700707func (m *ModuleBase) base() *ModuleBase {
708 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800709}
710
Paul Duffine2453c72019-05-31 14:00:04 +0100711func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
712 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
713}
714
715func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100716 return m.visibilityPropertyInfo
717}
718
719func (m *ModuleBase) visibility() []string {
720 // The soong_namespace module does not initialize the primaryVisibilityProperty.
721 if m.primaryVisibilityProperty != nil {
722 return m.primaryVisibilityProperty.getStrings()
723 } else {
724 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100725 }
726}
727
Colin Cross4157e882019-06-06 16:57:04 -0700728func (m *ModuleBase) Target() Target {
729 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800730}
731
Colin Cross4157e882019-06-06 16:57:04 -0700732func (m *ModuleBase) TargetPrimary() bool {
733 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700734}
735
Colin Cross4157e882019-06-06 16:57:04 -0700736func (m *ModuleBase) MultiTargets() []Target {
737 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700738}
739
Colin Cross4157e882019-06-06 16:57:04 -0700740func (m *ModuleBase) Os() OsType {
741 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800742}
743
Colin Cross4157e882019-06-06 16:57:04 -0700744func (m *ModuleBase) Host() bool {
745 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800746}
747
Colin Cross4157e882019-06-06 16:57:04 -0700748func (m *ModuleBase) Arch() Arch {
749 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800750}
751
Colin Cross4157e882019-06-06 16:57:04 -0700752func (m *ModuleBase) ArchSpecific() bool {
753 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700754}
755
Colin Cross4157e882019-06-06 16:57:04 -0700756func (m *ModuleBase) OsClassSupported() []OsClass {
757 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700758 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700759 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700760 case HostSupportedNoCross:
761 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700762 case DeviceSupported:
763 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700764 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700765 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700766 if Bool(m.hostAndDeviceProperties.Host_supported) ||
767 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
768 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700769 supported = append(supported, Host, HostCross)
770 }
Colin Cross4157e882019-06-06 16:57:04 -0700771 if m.hostAndDeviceProperties.Device_supported == nil ||
772 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700773 supported = append(supported, Device)
774 }
775 return supported
776 default:
777 return nil
778 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800779}
780
Colin Cross4157e882019-06-06 16:57:04 -0700781func (m *ModuleBase) DeviceSupported() bool {
782 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
783 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
784 (m.hostAndDeviceProperties.Device_supported == nil ||
785 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800786}
787
Paul Duffine44358f2019-11-26 18:04:12 +0000788func (m *ModuleBase) HostSupported() bool {
789 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
790 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
791 (m.hostAndDeviceProperties.Host_supported != nil &&
792 *m.hostAndDeviceProperties.Host_supported)
793}
794
Colin Cross4157e882019-06-06 16:57:04 -0700795func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900796 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900797}
798
Colin Cross4157e882019-06-06 16:57:04 -0700799func (m *ModuleBase) DeviceSpecific() bool {
800 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900801}
802
Colin Cross4157e882019-06-06 16:57:04 -0700803func (m *ModuleBase) SocSpecific() bool {
804 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900805}
806
Colin Cross4157e882019-06-06 16:57:04 -0700807func (m *ModuleBase) ProductSpecific() bool {
808 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900809}
810
Justin Yund5f6c822019-06-25 16:47:17 +0900811func (m *ModuleBase) SystemExtSpecific() bool {
812 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100813}
814
Colin Cross4157e882019-06-06 16:57:04 -0700815func (m *ModuleBase) Enabled() bool {
816 if m.commonProperties.Enabled == nil {
817 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800818 }
Colin Cross4157e882019-06-06 16:57:04 -0700819 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800820}
821
Colin Cross4157e882019-06-06 16:57:04 -0700822func (m *ModuleBase) SkipInstall() {
823 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700824}
825
Colin Cross4157e882019-06-06 16:57:04 -0700826func (m *ModuleBase) ExportedToMake() bool {
827 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900828}
829
Colin Cross4157e882019-06-06 16:57:04 -0700830func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700831 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800832
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700833 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700834 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800835 ctx.VisitDepsDepthFirstIf(isFileInstaller,
836 func(m blueprint.Module) {
837 fileInstaller := m.(fileInstaller)
838 files := fileInstaller.filesToInstall()
839 result = append(result, files...)
840 })
841
842 return result
843}
844
Colin Cross4157e882019-06-06 16:57:04 -0700845func (m *ModuleBase) filesToInstall() Paths {
846 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800847}
848
Colin Cross4157e882019-06-06 16:57:04 -0700849func (m *ModuleBase) NoAddressSanitizer() bool {
850 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800851}
852
Colin Cross4157e882019-06-06 16:57:04 -0700853func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800854 return false
855}
856
Jaewoong Jung0949f312019-09-11 10:25:18 -0700857func (m *ModuleBase) InstallInTestcases() bool {
858 return false
859}
860
Colin Cross4157e882019-06-06 16:57:04 -0700861func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700862 return false
863}
864
Colin Cross4157e882019-06-06 16:57:04 -0700865func (m *ModuleBase) InstallInRecovery() bool {
866 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900867}
868
Colin Cross90ba5f42019-10-02 11:10:58 -0700869func (m *ModuleBase) InstallInRoot() bool {
870 return false
871}
872
Colin Cross607d8582019-07-29 16:44:46 -0700873func (m *ModuleBase) InstallBypassMake() bool {
874 return false
875}
876
Colin Cross4157e882019-06-06 16:57:04 -0700877func (m *ModuleBase) Owner() string {
878 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900879}
880
Colin Cross4157e882019-06-06 16:57:04 -0700881func (m *ModuleBase) NoticeFile() OptionalPath {
882 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900883}
884
Colin Cross7228ecd2019-11-18 16:00:16 -0800885func (m *ModuleBase) setImageVariation(variant string) {
886 m.commonProperties.ImageVariation = variant
887}
888
889func (m *ModuleBase) ImageVariation() blueprint.Variation {
890 return blueprint.Variation{
891 Mutator: "image",
892 Variation: m.base().commonProperties.ImageVariation,
893 }
894}
895
896func (m *ModuleBase) InRecovery() bool {
897 return m.base().commonProperties.ImageVariation == RecoveryVariation
898}
899
Colin Cross4157e882019-06-06 16:57:04 -0700900func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700901 allInstalledFiles := Paths{}
902 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800903 ctx.VisitAllModuleVariants(func(module Module) {
904 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700905 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
906 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800907 })
908
Colin Cross0875c522017-11-28 17:34:01 -0800909 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700910
Jeff Gaston088e29e2017-11-29 16:47:17 -0800911 namespacePrefix := ctx.Namespace().(*Namespace).id
912 if namespacePrefix != "" {
913 namespacePrefix = namespacePrefix + "-"
914 }
915
Colin Cross3f40fa42015-01-30 17:27:36 -0800916 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800917 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800918 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700919 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800920 Output: name,
921 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800922 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700923 })
924 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700925 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700926 }
927
928 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800929 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800930 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700931 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800932 Output: name,
933 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700934 })
935 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700936 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700937 }
938
939 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800940 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800941 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800942 suffix = "-soong"
943 }
944
Jeff Gaston088e29e2017-11-29 16:47:17 -0800945 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800946 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700947 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800948 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700949 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800950 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700951
Colin Cross4157e882019-06-06 16:57:04 -0700952 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800953 }
954}
955
Colin Crossc34d2322020-01-03 15:23:27 -0800956func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -0700957 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
958 var deviceSpecific = Bool(m.commonProperties.Device_specific)
959 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +0900960 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900961
Dario Frenifd05a742018-05-29 13:28:54 +0100962 msg := "conflicting value set here"
963 if socSpecific && deviceSpecific {
964 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700965 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900966 ctx.PropertyErrorf("vendor", msg)
967 }
Colin Cross4157e882019-06-06 16:57:04 -0700968 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900969 ctx.PropertyErrorf("proprietary", msg)
970 }
Colin Cross4157e882019-06-06 16:57:04 -0700971 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900972 ctx.PropertyErrorf("soc_specific", msg)
973 }
974 }
975
Justin Yund5f6c822019-06-25 16:47:17 +0900976 if productSpecific && systemExtSpecific {
977 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
978 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +0100979 }
980
Justin Yund5f6c822019-06-25 16:47:17 +0900981 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100982 if productSpecific {
983 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
984 } else {
Justin Yund5f6c822019-06-25 16:47:17 +0900985 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 +0100986 }
987 if deviceSpecific {
988 ctx.PropertyErrorf("device_specific", msg)
989 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700990 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100991 ctx.PropertyErrorf("vendor", msg)
992 }
Colin Cross4157e882019-06-06 16:57:04 -0700993 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100994 ctx.PropertyErrorf("proprietary", msg)
995 }
Colin Cross4157e882019-06-06 16:57:04 -0700996 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100997 ctx.PropertyErrorf("soc_specific", msg)
998 }
999 }
1000 }
1001
Jiyong Park2db76922017-11-08 16:03:48 +09001002 if productSpecific {
1003 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001004 } else if systemExtSpecific {
1005 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001006 } else if deviceSpecific {
1007 return deviceSpecificModule
1008 } else if socSpecific {
1009 return socSpecificModule
1010 } else {
1011 return platformModule
1012 }
1013}
1014
Colin Crossc34d2322020-01-03 15:23:27 -08001015func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001016 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001017 EarlyModuleContext: ctx,
1018 kind: determineModuleKind(m, ctx),
1019 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001020 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001021}
1022
Colin Cross1184b642019-12-30 18:43:07 -08001023func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1024 return baseModuleContext{
1025 bp: ctx,
1026 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1027 os: m.commonProperties.CompileOS,
1028 target: m.commonProperties.CompileTarget,
1029 targetPrimary: m.commonProperties.CompilePrimary,
1030 multiTargets: m.commonProperties.CompileMultiTargets,
1031 }
1032}
1033
Colin Cross4157e882019-06-06 16:57:04 -07001034func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001035 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001036 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001037 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001038 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1039 installDeps: m.computeInstallDeps(blueprintCtx),
1040 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001041 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001042 }
1043
Colin Cross6c4f21f2019-06-06 15:41:36 -07001044 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1045 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1046 // TODO: This will be removed once defaults modules handle missing dependency errors
1047 blueprintCtx.GetMissingDependencies()
1048
Colin Crossdc35e212019-06-06 16:13:11 -07001049 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
1050 // are enabled.
1051 ctx.baseModuleContext.strictVisitDeps = true
1052
Colin Cross4c83e5c2019-02-25 14:54:28 -08001053 if ctx.config.captureBuild {
1054 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1055 }
1056
Colin Cross67a5c132017-05-09 13:45:28 -07001057 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1058 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001059 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1060 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001061 }
Colin Cross0875c522017-11-28 17:34:01 -08001062 if !ctx.PrimaryArch() {
1063 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001064 }
1065
1066 ctx.Variable(pctx, "moduleDesc", desc)
1067
1068 s := ""
1069 if len(suffix) > 0 {
1070 s = " [" + strings.Join(suffix, " ") + "]"
1071 }
1072 ctx.Variable(pctx, "moduleDescSuffix", s)
1073
Dan Willemsen569edc52018-11-19 09:33:29 -08001074 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001075 if m.commonProperties.Dist.Dest != nil {
1076 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001077 if err != nil {
1078 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1079 }
1080 }
Colin Cross4157e882019-06-06 16:57:04 -07001081 if m.commonProperties.Dist.Dir != nil {
1082 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001083 if err != nil {
1084 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1085 }
1086 }
Colin Cross4157e882019-06-06 16:57:04 -07001087 if m.commonProperties.Dist.Suffix != nil {
1088 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001089 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1090 }
1091 }
1092
Colin Cross4157e882019-06-06 16:57:04 -07001093 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001094 // ensure all direct android.Module deps are enabled
1095 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1096 if _, ok := bm.(Module); ok {
1097 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1098 }
1099 })
1100
Colin Cross4157e882019-06-06 16:57:04 -07001101 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1102 if module := SrcIsModule(notice); module != "" {
1103 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001104 } else {
1105 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001106 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001107 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001108
1109 m.module.GenerateAndroidBuildActions(ctx)
1110 if ctx.Failed() {
1111 return
1112 }
1113
1114 m.installFiles = append(m.installFiles, ctx.installFiles...)
1115 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001116 } else if ctx.Config().AllowMissingDependencies() {
1117 // If the module is not enabled it will not create any build rules, nothing will call
1118 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1119 // and report them as an error even when AllowMissingDependencies = true. Call
1120 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1121 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001122 }
1123
Colin Cross4157e882019-06-06 16:57:04 -07001124 if m == ctx.FinalModule().(Module).base() {
1125 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001126 if ctx.Failed() {
1127 return
1128 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001129 }
Colin Crosscec81712017-07-13 14:43:27 -07001130
Colin Cross4157e882019-06-06 16:57:04 -07001131 m.buildParams = ctx.buildParams
1132 m.ruleParams = ctx.ruleParams
1133 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001134}
1135
Colin Cross1184b642019-12-30 18:43:07 -08001136type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001137 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001138
1139 kind moduleKind
1140 config Config
1141}
1142
1143func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1144 ret, err := e.GlobWithDeps(globPattern, excludes)
1145 if err != nil {
1146 e.ModuleErrorf("glob: %s", err.Error())
1147 }
1148 return pathsForModuleSrcFromFullPath(e, ret, true)
1149}
1150
1151func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1152 ret, err := e.GlobWithDeps(globPattern, excludes)
1153 if err != nil {
1154 e.ModuleErrorf("glob: %s", err.Error())
1155 }
1156 return pathsForModuleSrcFromFullPath(e, ret, false)
1157}
1158
1159func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001160 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001161 return module
1162}
1163
1164func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001165 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001166}
1167
1168func (e *earlyModuleContext) AConfig() Config {
1169 return e.config
1170}
1171
1172func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1173 return DeviceConfig{e.config.deviceConfig}
1174}
1175
1176func (e *earlyModuleContext) Platform() bool {
1177 return e.kind == platformModule
1178}
1179
1180func (e *earlyModuleContext) DeviceSpecific() bool {
1181 return e.kind == deviceSpecificModule
1182}
1183
1184func (e *earlyModuleContext) SocSpecific() bool {
1185 return e.kind == socSpecificModule
1186}
1187
1188func (e *earlyModuleContext) ProductSpecific() bool {
1189 return e.kind == productSpecificModule
1190}
1191
1192func (e *earlyModuleContext) SystemExtSpecific() bool {
1193 return e.kind == systemExtSpecificModule
1194}
1195
1196type baseModuleContext struct {
1197 bp blueprint.BaseModuleContext
1198 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001199 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001200 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001201 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001202 targetPrimary bool
1203 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001204
1205 walkPath []Module
1206
1207 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001208}
1209
Colin Cross1184b642019-12-30 18:43:07 -08001210func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { return b.bp.OtherModuleName(m) }
1211func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
1212func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
1213 b.bp.OtherModuleErrorf(m, fmt, args)
1214}
1215func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1216 return b.bp.OtherModuleDependencyTag(m)
1217}
1218func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1219func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { return b.bp.OtherModuleType(m) }
1220
1221func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1222 return b.bp.GetDirectDepWithTag(name, tag)
1223}
1224
Colin Cross25de6c32019-06-06 14:29:25 -07001225type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001226 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001227 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001228 installDeps Paths
1229 installFiles Paths
1230 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001231 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001232
1233 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001234 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001235 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001236 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001237}
1238
Colin Crossb88b3c52019-06-10 15:15:17 -07001239func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1240 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001241 Rule: ErrorRule,
1242 Description: params.Description,
1243 Output: params.Output,
1244 Outputs: params.Outputs,
1245 ImplicitOutput: params.ImplicitOutput,
1246 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001247 Args: map[string]string{
1248 "error": err.Error(),
1249 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001250 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001251}
1252
Colin Cross25de6c32019-06-06 14:29:25 -07001253func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1254 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001255}
1256
Colin Cross0875c522017-11-28 17:34:01 -08001257func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001258 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001259 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001260 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001261 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001262 Outputs: params.Outputs.Strings(),
1263 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1264 Inputs: params.Inputs.Strings(),
1265 Implicits: params.Implicits.Strings(),
1266 OrderOnly: params.OrderOnly.Strings(),
1267 Args: params.Args,
1268 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001269 }
1270
Colin Cross33bfb0a2016-11-21 17:23:08 -08001271 if params.Depfile != nil {
1272 bparams.Depfile = params.Depfile.String()
1273 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001274 if params.Output != nil {
1275 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1276 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001277 if params.ImplicitOutput != nil {
1278 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1279 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001280 if params.Input != nil {
1281 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1282 }
1283 if params.Implicit != nil {
1284 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1285 }
1286
Colin Cross0b9f31f2019-02-28 11:00:01 -08001287 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1288 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1289 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1290 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1291 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1292 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001293
Colin Cross0875c522017-11-28 17:34:01 -08001294 return bparams
1295}
1296
Colin Cross25de6c32019-06-06 14:29:25 -07001297func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1298 if m.config.captureBuild {
1299 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001300 }
1301
Colin Crossdc35e212019-06-06 16:13:11 -07001302 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001303}
1304
Colin Cross25de6c32019-06-06 14:29:25 -07001305func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001306 argNames ...string) blueprint.Rule {
1307
Ramy Medhatdd0418a2019-11-04 18:16:11 -05001308 if (m.config.UseGoma() || m.config.UseRBE()) && params.Pool == nil {
1309 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1310 // jobs to the local parallelism value
Colin Cross2e2dbc22019-09-25 13:31:46 -07001311 params.Pool = localPool
1312 }
1313
Colin Crossdc35e212019-06-06 16:13:11 -07001314 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001315
Colin Cross25de6c32019-06-06 14:29:25 -07001316 if m.config.captureBuild {
1317 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001318 }
1319
1320 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001321}
1322
Colin Cross25de6c32019-06-06 14:29:25 -07001323func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001324 if params.Description != "" {
1325 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1326 }
1327
1328 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1329 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1330 m.ModuleName(), strings.Join(missingDeps, ", ")))
1331 }
1332
Colin Cross25de6c32019-06-06 14:29:25 -07001333 if m.config.captureBuild {
1334 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001335 }
1336
Colin Crossdc35e212019-06-06 16:13:11 -07001337 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001338}
Colin Cross25de6c32019-06-06 14:29:25 -07001339func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001340 var missingDeps []string
1341 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001342 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001343 missingDeps = FirstUniqueStrings(missingDeps)
1344 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001345}
1346
Colin Crossdc35e212019-06-06 16:13:11 -07001347func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001348 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001349 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001350 *missingDeps = append(*missingDeps, deps...)
1351 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001352 }
1353}
1354
Colin Crossdc35e212019-06-06 16:13:11 -07001355func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001356 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001357
1358 if !strict {
1359 return aModule
1360 }
1361
Colin Cross380c69a2019-06-10 17:49:58 +00001362 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001363 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001364 return nil
1365 }
1366
1367 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001368 if b.Config().AllowMissingDependencies() {
1369 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001370 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001371 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001372 }
1373 return nil
1374 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001375 return aModule
1376}
1377
Colin Crossdc35e212019-06-06 16:13:11 -07001378func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001379 type dep struct {
1380 mod blueprint.Module
1381 tag blueprint.DependencyTag
1382 }
1383 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001384 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001385 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001386 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001387 if tag == nil || returnedTag == tag {
1388 deps = append(deps, dep{aModule, returnedTag})
1389 }
1390 }
1391 })
1392 if len(deps) == 1 {
1393 return deps[0].mod, deps[0].tag
1394 } else if len(deps) >= 2 {
1395 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001396 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001397 } else {
1398 return nil, nil
1399 }
1400}
1401
Colin Crossdc35e212019-06-06 16:13:11 -07001402func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001403 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001404 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001405 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001406 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001407 deps = append(deps, aModule)
1408 }
1409 }
1410 })
1411 return deps
1412}
1413
Colin Cross25de6c32019-06-06 14:29:25 -07001414func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1415 module, _ := m.getDirectDepInternal(name, tag)
1416 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001417}
1418
Colin Crossdc35e212019-06-06 16:13:11 -07001419func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1420 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001421}
1422
Colin Crossdc35e212019-06-06 16:13:11 -07001423func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001424 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001425}
1426
Colin Crossdc35e212019-06-06 16:13:11 -07001427func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001428 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001429 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001430 visit(aModule)
1431 }
1432 })
1433}
1434
Colin Crossdc35e212019-06-06 16:13:11 -07001435func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001436 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001437 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001438 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001439 visit(aModule)
1440 }
1441 }
1442 })
1443}
1444
Colin Crossdc35e212019-06-06 16:13:11 -07001445func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001446 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001447 // pred
1448 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001449 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001450 return pred(aModule)
1451 } else {
1452 return false
1453 }
1454 },
1455 // visit
1456 func(module blueprint.Module) {
1457 visit(module.(Module))
1458 })
1459}
1460
Colin Crossdc35e212019-06-06 16:13:11 -07001461func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001462 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001463 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001464 visit(aModule)
1465 }
1466 })
1467}
1468
Colin Crossdc35e212019-06-06 16:13:11 -07001469func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001470 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001471 // pred
1472 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001473 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001474 return pred(aModule)
1475 } else {
1476 return false
1477 }
1478 },
1479 // visit
1480 func(module blueprint.Module) {
1481 visit(module.(Module))
1482 })
1483}
1484
Colin Crossdc35e212019-06-06 16:13:11 -07001485func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001486 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001487}
1488
Colin Crossdc35e212019-06-06 16:13:11 -07001489func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1490 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001491 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001492 childAndroidModule, _ := child.(Module)
1493 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001494 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001495 // record walkPath before visit
1496 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1497 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1498 }
1499 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001500 return visit(childAndroidModule, parentAndroidModule)
1501 } else {
1502 return false
1503 }
1504 })
1505}
1506
Colin Crossdc35e212019-06-06 16:13:11 -07001507func (b *baseModuleContext) GetWalkPath() []Module {
1508 return b.walkPath
1509}
1510
Colin Cross25de6c32019-06-06 14:29:25 -07001511func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001512 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001513 visit(module.(Module))
1514 })
1515}
1516
Colin Cross25de6c32019-06-06 14:29:25 -07001517func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001518 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001519}
1520
Colin Cross25de6c32019-06-06 14:29:25 -07001521func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001522 return m.bp.FinalModule().(Module)
1523}
1524
1525func (m *moduleContext) ModuleSubDir() string {
1526 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001527}
1528
Colin Cross0ea8ba82019-06-06 14:33:29 -07001529func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001530 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001531}
1532
Colin Cross0ea8ba82019-06-06 14:33:29 -07001533func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001534 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001535}
1536
Colin Cross0ea8ba82019-06-06 14:33:29 -07001537func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001538 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001539}
1540
Colin Cross0ea8ba82019-06-06 14:33:29 -07001541func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001542 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001543}
1544
Colin Cross0ea8ba82019-06-06 14:33:29 -07001545func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001546 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001547}
1548
Colin Cross0ea8ba82019-06-06 14:33:29 -07001549func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001550 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001551}
1552
Colin Cross0ea8ba82019-06-06 14:33:29 -07001553func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001554 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001555}
1556
Colin Cross0ea8ba82019-06-06 14:33:29 -07001557func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001558 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001559}
1560
Colin Cross0ea8ba82019-06-06 14:33:29 -07001561func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001562 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001563}
1564
Colin Cross0ea8ba82019-06-06 14:33:29 -07001565func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001566 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001567}
1568
Colin Cross0ea8ba82019-06-06 14:33:29 -07001569func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001570 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001571}
1572
Colin Cross0ea8ba82019-06-06 14:33:29 -07001573func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001574 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001575 return true
1576 }
Colin Cross25de6c32019-06-06 14:29:25 -07001577 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001578}
1579
Jiyong Park5baac542018-08-28 09:55:37 +09001580// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001581// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001582func (m *ModuleBase) MakeAsPlatform() {
1583 m.commonProperties.Vendor = boolPtr(false)
1584 m.commonProperties.Proprietary = boolPtr(false)
1585 m.commonProperties.Soc_specific = boolPtr(false)
1586 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001587 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001588}
1589
Colin Cross4157e882019-06-06 16:57:04 -07001590func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1591 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001592}
1593
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001594func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001595 m.commonProperties.Vendor = boolPtr(false)
1596 m.commonProperties.Proprietary = boolPtr(false)
1597 m.commonProperties.Soc_specific = boolPtr(false)
1598 m.commonProperties.Product_specific = boolPtr(false)
1599 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001600}
1601
Jooyung Han344d5432019-08-23 11:17:39 +09001602// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1603func (m *ModuleBase) IsNativeBridgeSupported() bool {
1604 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1605}
1606
Colin Cross25de6c32019-06-06 14:29:25 -07001607func (m *moduleContext) InstallInData() bool {
1608 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001609}
1610
Jaewoong Jung0949f312019-09-11 10:25:18 -07001611func (m *moduleContext) InstallInTestcases() bool {
1612 return m.module.InstallInTestcases()
1613}
1614
Colin Cross25de6c32019-06-06 14:29:25 -07001615func (m *moduleContext) InstallInSanitizerDir() bool {
1616 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001617}
1618
Colin Cross25de6c32019-06-06 14:29:25 -07001619func (m *moduleContext) InstallInRecovery() bool {
1620 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001621}
1622
Colin Cross90ba5f42019-10-02 11:10:58 -07001623func (m *moduleContext) InstallInRoot() bool {
1624 return m.module.InstallInRoot()
1625}
1626
Colin Cross607d8582019-07-29 16:44:46 -07001627func (m *moduleContext) InstallBypassMake() bool {
1628 return m.module.InstallBypassMake()
1629}
1630
Colin Cross70dda7e2019-10-01 22:05:35 -07001631func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001632 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001633 return true
1634 }
1635
Colin Cross3607f212018-05-07 15:28:05 -07001636 // We'll need a solution for choosing which of modules with the same name in different
1637 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1638 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001639 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001640 return true
1641 }
1642
Colin Cross25de6c32019-06-06 14:29:25 -07001643 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001644 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001645 return true
1646 }
1647
Colin Cross25de6c32019-06-06 14:29:25 -07001648 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001649 return true
1650 }
1651 }
1652
1653 return false
1654}
1655
Colin Cross70dda7e2019-10-01 22:05:35 -07001656func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1657 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001658 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001659}
1660
Colin Cross70dda7e2019-10-01 22:05:35 -07001661func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1662 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001663 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001664}
1665
Colin Cross70dda7e2019-10-01 22:05:35 -07001666func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1667 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001668
Colin Cross25de6c32019-06-06 14:29:25 -07001669 fullInstallPath := installPath.Join(m, name)
1670 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001671
Colin Cross25de6c32019-06-06 14:29:25 -07001672 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001673
Colin Cross25de6c32019-06-06 14:29:25 -07001674 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001675
Colin Cross89562dc2016-10-03 17:47:19 -07001676 var implicitDeps, orderOnlyDeps Paths
1677
Colin Cross25de6c32019-06-06 14:29:25 -07001678 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001679 // Installed host modules might be used during the build, depend directly on their
1680 // dependencies so their timestamp is updated whenever their dependency is updated
1681 implicitDeps = deps
1682 } else {
1683 orderOnlyDeps = deps
1684 }
1685
Colin Cross25de6c32019-06-06 14:29:25 -07001686 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001687 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001688 Description: "install " + fullInstallPath.Base(),
1689 Output: fullInstallPath,
1690 Input: srcPath,
1691 Implicits: implicitDeps,
1692 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001693 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001694 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001695
Colin Cross25de6c32019-06-06 14:29:25 -07001696 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001697 }
Colin Cross25de6c32019-06-06 14:29:25 -07001698 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001699 return fullInstallPath
1700}
1701
Colin Cross70dda7e2019-10-01 22:05:35 -07001702func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001703 fullInstallPath := installPath.Join(m, name)
1704 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001705
Colin Cross25de6c32019-06-06 14:29:25 -07001706 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001707
Alex Lightfb4353d2019-01-17 13:57:45 -08001708 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1709 if err != nil {
1710 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1711 }
Colin Cross25de6c32019-06-06 14:29:25 -07001712 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001713 Rule: Symlink,
1714 Description: "install symlink " + fullInstallPath.Base(),
1715 Output: fullInstallPath,
1716 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001717 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001718 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001719 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001720 },
1721 })
Colin Cross3854a602016-01-11 12:49:11 -08001722
Colin Cross25de6c32019-06-06 14:29:25 -07001723 m.installFiles = append(m.installFiles, fullInstallPath)
1724 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001725 }
Colin Cross3854a602016-01-11 12:49:11 -08001726 return fullInstallPath
1727}
1728
Jiyong Parkf1194352019-02-25 11:05:47 +09001729// installPath/name -> absPath where absPath might be a path that is available only at runtime
1730// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001731func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001732 fullInstallPath := installPath.Join(m, name)
1733 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001734
Colin Cross25de6c32019-06-06 14:29:25 -07001735 if !m.skipInstall(fullInstallPath) {
1736 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001737 Rule: Symlink,
1738 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1739 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001740 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001741 Args: map[string]string{
1742 "fromPath": absPath,
1743 },
1744 })
1745
Colin Cross25de6c32019-06-06 14:29:25 -07001746 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001747 }
1748 return fullInstallPath
1749}
1750
Colin Cross25de6c32019-06-06 14:29:25 -07001751func (m *moduleContext) CheckbuildFile(srcPath Path) {
1752 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001753}
1754
Colin Cross3f40fa42015-01-30 17:27:36 -08001755type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001756 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001757}
1758
1759func isFileInstaller(m blueprint.Module) bool {
1760 _, ok := m.(fileInstaller)
1761 return ok
1762}
1763
1764func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001765 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001766 return ok
1767}
Colin Crossfce53272015-04-08 11:21:40 -07001768
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001769func findStringInSlice(str string, slice []string) int {
1770 for i, s := range slice {
1771 if s == str {
1772 return i
Colin Crossfce53272015-04-08 11:21:40 -07001773 }
1774 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001775 return -1
1776}
1777
Colin Cross41955e82019-05-29 14:40:35 -07001778// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1779// was not a module reference.
1780func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001781 if len(s) > 1 && s[0] == ':' {
1782 return s[1:]
1783 }
1784 return ""
1785}
1786
Colin Cross41955e82019-05-29 14:40:35 -07001787// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1788// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1789func SrcIsModuleWithTag(s string) (module, tag string) {
1790 if len(s) > 1 && s[0] == ':' {
1791 module = s[1:]
1792 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1793 if module[len(module)-1] == '}' {
1794 tag = module[tagStart+1 : len(module)-1]
1795 module = module[:tagStart]
1796 return module, tag
1797 }
1798 }
1799 return module, ""
1800 }
1801 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001802}
1803
Colin Cross41955e82019-05-29 14:40:35 -07001804type sourceOrOutputDependencyTag struct {
1805 blueprint.BaseDependencyTag
1806 tag string
1807}
1808
1809func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1810 return sourceOrOutputDependencyTag{tag: tag}
1811}
1812
1813var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001814
Colin Cross366938f2017-12-11 16:29:02 -08001815// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1816// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001817//
1818// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001819func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001820 set := make(map[string]bool)
1821
Colin Cross068e0fe2016-12-13 15:23:47 -08001822 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001823 if m, t := SrcIsModuleWithTag(s); m != "" {
1824 if _, found := set[s]; found {
1825 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001826 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001827 set[s] = true
1828 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001829 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001830 }
1831 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001832}
1833
Colin Cross366938f2017-12-11 16:29:02 -08001834// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1835// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001836//
1837// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001838func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1839 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001840 if m, t := SrcIsModuleWithTag(*s); m != "" {
1841 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001842 }
1843 }
1844}
1845
Colin Cross41955e82019-05-29 14:40:35 -07001846// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1847// 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 -08001848type SourceFileProducer interface {
1849 Srcs() Paths
1850}
1851
Colin Cross41955e82019-05-29 14:40:35 -07001852// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00001853// 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 -07001854// listed in the property.
1855type OutputFileProducer interface {
1856 OutputFiles(tag string) (Paths, error)
1857}
1858
Colin Cross5e708052019-08-06 13:59:50 -07001859// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
1860// module produced zero paths, it reports errors to the ctx and returns nil.
1861func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
1862 paths, err := outputFilesForModule(ctx, module, tag)
1863 if err != nil {
1864 reportPathError(ctx, err)
1865 return nil
1866 }
1867 return paths
1868}
1869
1870// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
1871// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
1872func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
1873 paths, err := outputFilesForModule(ctx, module, tag)
1874 if err != nil {
1875 reportPathError(ctx, err)
1876 return nil
1877 }
1878 if len(paths) > 1 {
1879 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
1880 pathContextName(ctx, module))
1881 return nil
1882 }
1883 return paths[0]
1884}
1885
1886func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
1887 if outputFileProducer, ok := module.(OutputFileProducer); ok {
1888 paths, err := outputFileProducer.OutputFiles(tag)
1889 if err != nil {
1890 return nil, fmt.Errorf("failed to get output file from module %q: %s",
1891 pathContextName(ctx, module), err.Error())
1892 }
1893 if len(paths) == 0 {
1894 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
1895 }
1896 return paths, nil
1897 } else {
1898 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
1899 }
1900}
1901
Colin Crossfe17f6f2019-03-28 19:30:56 -07001902type HostToolProvider interface {
1903 HostToolPath() OptionalPath
1904}
1905
Colin Cross27b922f2019-03-04 22:35:41 -08001906// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1907// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001908//
1909// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001910func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1911 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001912}
1913
Colin Cross2fafa3e2019-03-05 12:39:51 -08001914// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1915// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001916//
1917// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001918func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1919 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001920}
1921
1922// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1923// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1924// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001925func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001926 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001927 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001928 }
1929 return OptionalPath{}
1930}
1931
Colin Cross25de6c32019-06-06 14:29:25 -07001932func (m *moduleContext) RequiredModuleNames() []string {
1933 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001934}
1935
Colin Cross25de6c32019-06-06 14:29:25 -07001936func (m *moduleContext) HostRequiredModuleNames() []string {
1937 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001938}
1939
Colin Cross25de6c32019-06-06 14:29:25 -07001940func (m *moduleContext) TargetRequiredModuleNames() []string {
1941 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001942}
1943
Colin Cross463a90e2015-06-17 14:20:06 -07001944func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001945 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001946}
1947
Colin Cross0875c522017-11-28 17:34:01 -08001948func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001949 return &buildTargetSingleton{}
1950}
1951
Colin Cross87d8b562017-04-25 10:01:55 -07001952func parentDir(dir string) string {
1953 dir, _ = filepath.Split(dir)
1954 return filepath.Clean(dir)
1955}
1956
Colin Cross1f8c52b2015-06-16 16:38:17 -07001957type buildTargetSingleton struct{}
1958
Colin Cross0875c522017-11-28 17:34:01 -08001959func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1960 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001961
Colin Cross0875c522017-11-28 17:34:01 -08001962 mmTarget := func(dir string) WritablePath {
1963 return PathForPhony(ctx,
1964 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001965 }
1966
Colin Cross0875c522017-11-28 17:34:01 -08001967 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001968
Colin Cross0875c522017-11-28 17:34:01 -08001969 ctx.VisitAllModules(func(module Module) {
1970 blueprintDir := module.base().blueprintDir
1971 installTarget := module.base().installTarget
1972 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001973
Colin Cross0875c522017-11-28 17:34:01 -08001974 if checkbuildTarget != nil {
1975 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1976 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1977 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001978
Colin Cross0875c522017-11-28 17:34:01 -08001979 if installTarget != nil {
1980 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001981 }
1982 })
1983
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001984 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001985 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001986 suffix = "-soong"
1987 }
1988
Colin Cross1f8c52b2015-06-16 16:38:17 -07001989 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001990 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001991 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001992 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001993 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001994 })
1995
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001996 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001997 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001998 return
1999 }
2000
Colin Cross87d8b562017-04-25 10:01:55 -07002001 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002002 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002003 for _, dir := range dirs {
2004 dir := parentDir(dir)
2005 for dir != "." && dir != "/" {
2006 if _, exists := modulesInDir[dir]; exists {
2007 break
2008 }
2009 modulesInDir[dir] = nil
2010 dir = parentDir(dir)
2011 }
2012 }
2013
2014 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002015 for _, dir := range dirs {
2016 p := parentDir(dir)
2017 if p != "." && p != "/" {
2018 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2019 }
2020 }
2021
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002022 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2023 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2024 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002025 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002026 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002027 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002028 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002029 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002030 // HACK: checkbuild should be an optional build, but force it
2031 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002032 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002033 })
2034 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002035
2036 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2037 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002038 ctx.VisitAllModules(func(module Module) {
2039 if module.Enabled() {
2040 os := module.Target().Os
2041 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002042 }
2043 })
2044
Colin Cross0875c522017-11-28 17:34:01 -08002045 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002046 for os, deps := range osDeps {
2047 var className string
2048
2049 switch os.Class {
2050 case Host:
2051 className = "host"
2052 case HostCross:
2053 className = "host-cross"
2054 case Device:
2055 className = "target"
2056 default:
2057 continue
2058 }
2059
Colin Cross0875c522017-11-28 17:34:01 -08002060 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002061 osClass[className] = append(osClass[className], name)
2062
Colin Cross0875c522017-11-28 17:34:01 -08002063 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002064 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002065 Output: name,
2066 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002067 })
2068 }
2069
2070 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002071 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002072 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002073 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002074 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002075 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002076 })
2077 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002078}
Colin Crossd779da42015-12-17 18:00:23 -08002079
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002080// Collect information for opening IDE project files in java/jdeps.go.
2081type IDEInfo interface {
2082 IDEInfo(ideInfo *IdeInfo)
2083 BaseModuleName() string
2084}
2085
2086// Extract the base module name from the Import name.
2087// Often the Import name has a prefix "prebuilt_".
2088// Remove the prefix explicitly if needed
2089// until we find a better solution to get the Import name.
2090type IDECustomizedModuleName interface {
2091 IDECustomizedModuleName() string
2092}
2093
2094type IdeInfo struct {
2095 Deps []string `json:"dependencies,omitempty"`
2096 Srcs []string `json:"srcs,omitempty"`
2097 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2098 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2099 Jars []string `json:"jars,omitempty"`
2100 Classes []string `json:"class,omitempty"`
2101 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002102 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002103}