blob: c998007276401734cafee5224c1ea8ccbfd63124 [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 Cross47e4f9e2020-01-10 18:51:04 +000025 "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
Colin Cross47e4f9e2020-01-10 18:51:04 +000094 Fs() pathtools.FileSystem
Colin Cross1184b642019-12-30 18:43:07 -080095}
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
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900234
235 RequiredModuleNames() []string
236 HostRequiredModuleNames() []string
237 TargetRequiredModuleNames() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100238}
239
240// Qualified id for a module
241type qualifiedModuleName struct {
242 // The package (i.e. directory) in which the module is defined, without trailing /
243 pkg string
244
245 // The name of the module, empty string if package.
246 name string
247}
248
249func (q qualifiedModuleName) String() string {
250 if q.name == "" {
251 return "//" + q.pkg
252 }
253 return "//" + q.pkg + ":" + q.name
254}
255
Paul Duffine484f472019-06-20 16:38:08 +0100256func (q qualifiedModuleName) isRootPackage() bool {
257 return q.pkg == "" && q.name == ""
258}
259
Paul Duffine2453c72019-05-31 14:00:04 +0100260// Get the id for the package containing this module.
261func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
262 pkg := q.pkg
263 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100264 if pkg == "" {
265 panic(fmt.Errorf("Cannot get containing package id of root package"))
266 }
267
268 index := strings.LastIndex(pkg, "/")
269 if index == -1 {
270 pkg = ""
271 } else {
272 pkg = pkg[:index]
273 }
Paul Duffine2453c72019-05-31 14:00:04 +0100274 }
275 return newPackageId(pkg)
276}
277
278func newPackageId(pkg string) qualifiedModuleName {
279 // A qualified id for a package module has no name.
280 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800281}
282
Colin Crossfc754582016-05-17 16:34:16 -0700283type nameProperties struct {
284 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800285 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700286}
287
288type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800289 // emit build rules for this module
290 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800291
Paul Duffin2e61fa62019-03-28 14:10:57 +0000292 // Controls the visibility of this module to other modules. Allowable values are one or more of
293 // these formats:
294 //
295 // ["//visibility:public"]: Anyone can use this module.
296 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
297 // this module.
298 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
299 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
300 // this module. Note that sub-packages do not have access to the rule; for example,
301 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
302 // is a special module and must be used verbatim. It represents all of the modules in the
303 // package.
304 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
305 // or other or in one of their sub-packages have access to this module. For example,
306 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
307 // to depend on this rule (but not //independent:evil)
308 // ["//project"]: This is shorthand for ["//project:__pkg__"]
309 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
310 // //project is the module's package. e.g. using [":__subpackages__"] in
311 // packages/apps/Settings/Android.bp is equivalent to
312 // //packages/apps/Settings:__subpackages__.
313 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
314 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100315 //
316 // If a module does not specify the `visibility` property then it uses the
317 // `default_visibility` property of the `package` module in the module's package.
318 //
319 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100320 // it will use the `default_visibility` of its closest ancestor package for which
321 // a `default_visibility` property is specified.
322 //
323 // If no `default_visibility` property can be found then the module uses the
324 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100325 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100326 // The `visibility` property has no effect on a defaults module although it does
327 // apply to any non-defaults module that uses it. To set the visibility of a
328 // defaults module, use the `defaults_visibility` property on the defaults module;
329 // not to be confused with the `default_visibility` property on the package module.
330 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000331 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
332 // more details.
333 Visibility []string
334
Colin Cross7d5136f2015-05-11 13:39:40 -0700335 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800336 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
337 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
338 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700339 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700340
341 Target struct {
342 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700343 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700344 }
345 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700346 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700347 }
348 }
349
Colin Crossee0bc3b2018-10-02 22:01:37 -0700350 UseTargetVariants bool `blueprint:"mutated"`
351 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800352
Dan Willemsen782a2d12015-12-21 14:55:28 -0800353 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700354 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800355
Colin Cross55708f32017-03-20 13:23:34 -0700356 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700357 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700358
Jiyong Park2db76922017-11-08 16:03:48 +0900359 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
360 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
361 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700362 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700363
Jiyong Park2db76922017-11-08 16:03:48 +0900364 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
365 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
366 Soc_specific *bool
367
368 // whether this module is specific to a device, not only for SoC, but also for off-chip
369 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
370 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
371 // This implies `soc_specific:true`.
372 Device_specific *bool
373
374 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900375 // network operator, etc). When set to true, it is installed into /product (or
376 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900377 Product_specific *bool
378
Justin Yund5f6c822019-06-25 16:47:17 +0900379 // whether this module extends system. When set to true, it is installed into /system_ext
380 // (or /system/system_ext if system_ext partition does not exist).
381 System_ext_specific *bool
382
Jiyong Parkf9332f12018-02-01 00:54:12 +0900383 // Whether this module is installed to recovery partition
384 Recovery *bool
385
dimitry1f33e402019-03-26 12:39:31 +0100386 // Whether this module is built for non-native architecures (also known as native bridge binary)
387 Native_bridge_supported *bool `android:"arch_variant"`
388
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700389 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800390 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700391
Steven Moreland57a23d22018-04-04 15:42:19 -0700392 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800393 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700394
Chris Wolfe998306e2016-08-15 14:47:23 -0400395 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700396 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400397
Sasha Smundakb6d23052019-04-01 18:37:36 -0700398 // names of other modules to install on host if this module is installed
399 Host_required []string `android:"arch_variant"`
400
401 // names of other modules to install on target if this module is installed
402 Target_required []string `android:"arch_variant"`
403
Colin Cross5aac3622017-08-31 15:07:09 -0700404 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800405 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700406
Dan Willemsen569edc52018-11-19 09:33:29 -0800407 Dist struct {
408 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
409 // command line and any of these targets are also on the command line, or otherwise
410 // built
411 Targets []string `android:"arch_variant"`
412
413 // The name of the output artifact. This defaults to the basename of the output of
414 // the module.
415 Dest *string `android:"arch_variant"`
416
417 // The directory within the dist directory to store the artifact. Defaults to the
418 // top level directory ("").
419 Dir *string `android:"arch_variant"`
420
421 // A suffix to add to the artifact file name (before any extension).
422 Suffix *string `android:"arch_variant"`
423 } `android:"arch_variant"`
424
Colin Crossa1ad8d12016-06-01 17:09:44 -0700425 // Set by TargetMutator
Colin Crossa195f912019-10-16 11:07:20 -0700426 CompileOS OsType `blueprint:"mutated"`
Colin Crossee0bc3b2018-10-02 22:01:37 -0700427 CompileTarget Target `blueprint:"mutated"`
428 CompileMultiTargets []Target `blueprint:"mutated"`
429 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800430
431 // Set by InitAndroidModule
432 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700433 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700434
435 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800436
437 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700438
439 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700440
441 // Name and variant strings stored by mutators to enable Module.String()
442 DebugName string `blueprint:"mutated"`
443 DebugMutators []string `blueprint:"mutated"`
444 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800445
446 // set by ImageMutator
447 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800448}
449
450type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800451 // If set to true, build a variant of the module for the host. Defaults to false.
452 Host_supported *bool
453
454 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700455 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800456}
457
Colin Crossc472d572015-03-17 15:06:21 -0700458type Multilib string
459
460const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800461 MultilibBoth Multilib = "both"
462 MultilibFirst Multilib = "first"
463 MultilibCommon Multilib = "common"
464 MultilibCommonFirst Multilib = "common_first"
465 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700466)
467
Colin Crossa1ad8d12016-06-01 17:09:44 -0700468type HostOrDeviceSupported int
469
470const (
471 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700472
473 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700474 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700475
476 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700477 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700478
479 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700480 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700481
482 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700483 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700484
485 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700486 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700487
488 // Nothing is supported. This is not exposed to the user, but used to mark a
489 // host only module as unsupported when the module type is not supported on
490 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700491 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700492)
493
Jiyong Park2db76922017-11-08 16:03:48 +0900494type moduleKind int
495
496const (
497 platformModule moduleKind = iota
498 deviceSpecificModule
499 socSpecificModule
500 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900501 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900502)
503
504func (k moduleKind) String() string {
505 switch k {
506 case platformModule:
507 return "platform"
508 case deviceSpecificModule:
509 return "device-specific"
510 case socSpecificModule:
511 return "soc-specific"
512 case productSpecificModule:
513 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900514 case systemExtSpecificModule:
515 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900516 default:
517 panic(fmt.Errorf("unknown module kind %d", k))
518 }
519}
520
Colin Cross36242852017-06-23 15:06:31 -0700521func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800522 base := m.base()
523 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700524
Colin Cross36242852017-06-23 15:06:31 -0700525 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700526 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700527 &base.commonProperties)
528
529 // Allow tests to override the default product variables
530 if base.variableProperties == nil {
531 base.variableProperties = zeroProductVariables
532 }
533
534 // Filter the product variables properties to the ones that exist on this module
535 base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
536 if base.variableProperties != nil {
537 m.AddProperties(base.variableProperties)
538 }
539
Colin Crossa3a97412019-03-18 12:24:29 -0700540 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700541 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100542
543 // The default_visibility property needs to be checked and parsed by the visibility module during
544 // its checking and parsing phases.
545 base.primaryVisibilityProperty =
546 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
547 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700548}
549
Colin Cross36242852017-06-23 15:06:31 -0700550func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
551 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700552
553 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800554 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700555 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700556 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700557 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800558
Dan Willemsen218f6562015-07-08 18:13:11 -0700559 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700560 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700561 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800562 }
563
Colin Cross36242852017-06-23 15:06:31 -0700564 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800565}
566
Colin Crossee0bc3b2018-10-02 22:01:37 -0700567func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
568 InitAndroidArchModule(m, hod, defaultMultilib)
569 m.base().commonProperties.UseTargetVariants = false
570}
571
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800572// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800573// modules. It should be included as an anonymous field in every module
574// struct definition. InitAndroidModule should then be called from the module's
575// factory function, and the return values from InitAndroidModule should be
576// returned from the factory function.
577//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800578// The ModuleBase type is responsible for implementing the GenerateBuildActions
579// method to support the blueprint.Module interface. This method will then call
580// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700581// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
582// rather than the usual blueprint.ModuleContext.
583// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800584// system including details about the particular build variant that is to be
585// generated.
586//
587// For example:
588//
589// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800590// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800591// )
592//
593// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800594// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800595// properties struct {
596// MyProperty string
597// }
598// }
599//
Colin Cross36242852017-06-23 15:06:31 -0700600// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800601// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700602// m.AddProperties(&m.properties)
603// android.InitAndroidModule(m)
604// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800605// }
606//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800607// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800608// // Get the CPU architecture for the current build variant.
609// variantArch := ctx.Arch()
610//
611// // ...
612// }
Colin Cross635c3b02016-05-18 15:37:25 -0700613type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800614 // Putting the curiously recurring thing pointing to the thing that contains
615 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700616 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700617 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800618
Colin Crossfc754582016-05-17 16:34:16 -0700619 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800620 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700621 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800622 hostAndDeviceProperties hostAndDeviceProperties
623 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700624 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700625 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800626
Paul Duffin63c6e182019-07-24 14:24:38 +0100627 // Information about all the properties on the module that contains visibility rules that need
628 // checking.
629 visibilityPropertyInfo []visibilityProperty
630
631 // The primary visibility property, may be nil, that controls access to the module.
632 primaryVisibilityProperty visibilityProperty
633
Colin Cross3f40fa42015-01-30 17:27:36 -0800634 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700635 installFiles Paths
636 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900637 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700638
639 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
640 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800641 installTarget WritablePath
642 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700643 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700644
Colin Cross178a5092016-09-13 13:42:32 -0700645 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700646
647 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700648
649 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700650 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800651 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800652 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700653
654 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700655}
656
Colin Cross4157e882019-06-06 16:57:04 -0700657func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800658
Colin Cross4157e882019-06-06 16:57:04 -0700659func (m *ModuleBase) AddProperties(props ...interface{}) {
660 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700661}
662
Colin Cross4157e882019-06-06 16:57:04 -0700663func (m *ModuleBase) GetProperties() []interface{} {
664 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800665}
666
Colin Cross4157e882019-06-06 16:57:04 -0700667func (m *ModuleBase) BuildParamsForTests() []BuildParams {
668 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700669}
670
Colin Cross4157e882019-06-06 16:57:04 -0700671func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
672 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800673}
674
Colin Cross4157e882019-06-06 16:57:04 -0700675func (m *ModuleBase) VariablesForTests() map[string]string {
676 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800677}
678
Colin Cross4157e882019-06-06 16:57:04 -0700679func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
680 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700681}
682
Colin Crossce75d2c2016-10-06 16:12:58 -0700683// Name returns the name of the module. It may be overridden by individual module types, for
684// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700685func (m *ModuleBase) Name() string {
686 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700687}
688
Colin Cross9a362232019-07-01 15:32:45 -0700689// String returns a string that includes the module name and variants for printing during debugging.
690func (m *ModuleBase) String() string {
691 sb := strings.Builder{}
692 sb.WriteString(m.commonProperties.DebugName)
693 sb.WriteString("{")
694 for i := range m.commonProperties.DebugMutators {
695 if i != 0 {
696 sb.WriteString(",")
697 }
698 sb.WriteString(m.commonProperties.DebugMutators[i])
699 sb.WriteString(":")
700 sb.WriteString(m.commonProperties.DebugVariations[i])
701 }
702 sb.WriteString("}")
703 return sb.String()
704}
705
Colin Crossce75d2c2016-10-06 16:12:58 -0700706// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700707func (m *ModuleBase) BaseModuleName() string {
708 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700709}
710
Colin Cross4157e882019-06-06 16:57:04 -0700711func (m *ModuleBase) base() *ModuleBase {
712 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800713}
714
Paul Duffine2453c72019-05-31 14:00:04 +0100715func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
716 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
717}
718
719func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100720 return m.visibilityPropertyInfo
721}
722
723func (m *ModuleBase) visibility() []string {
724 // The soong_namespace module does not initialize the primaryVisibilityProperty.
725 if m.primaryVisibilityProperty != nil {
726 return m.primaryVisibilityProperty.getStrings()
727 } else {
728 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100729 }
730}
731
Colin Cross4157e882019-06-06 16:57:04 -0700732func (m *ModuleBase) Target() Target {
733 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800734}
735
Colin Cross4157e882019-06-06 16:57:04 -0700736func (m *ModuleBase) TargetPrimary() bool {
737 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700738}
739
Colin Cross4157e882019-06-06 16:57:04 -0700740func (m *ModuleBase) MultiTargets() []Target {
741 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700742}
743
Colin Cross4157e882019-06-06 16:57:04 -0700744func (m *ModuleBase) Os() OsType {
745 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800746}
747
Colin Cross4157e882019-06-06 16:57:04 -0700748func (m *ModuleBase) Host() bool {
749 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800750}
751
Colin Cross4157e882019-06-06 16:57:04 -0700752func (m *ModuleBase) Arch() Arch {
753 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800754}
755
Colin Cross4157e882019-06-06 16:57:04 -0700756func (m *ModuleBase) ArchSpecific() bool {
757 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700758}
759
Colin Cross4157e882019-06-06 16:57:04 -0700760func (m *ModuleBase) OsClassSupported() []OsClass {
761 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700762 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700763 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700764 case HostSupportedNoCross:
765 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700766 case DeviceSupported:
767 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700768 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700769 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700770 if Bool(m.hostAndDeviceProperties.Host_supported) ||
771 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
772 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700773 supported = append(supported, Host, HostCross)
774 }
Colin Cross4157e882019-06-06 16:57:04 -0700775 if m.hostAndDeviceProperties.Device_supported == nil ||
776 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700777 supported = append(supported, Device)
778 }
779 return supported
780 default:
781 return nil
782 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800783}
784
Colin Cross4157e882019-06-06 16:57:04 -0700785func (m *ModuleBase) DeviceSupported() bool {
786 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
787 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
788 (m.hostAndDeviceProperties.Device_supported == nil ||
789 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800790}
791
Paul Duffine44358f2019-11-26 18:04:12 +0000792func (m *ModuleBase) HostSupported() bool {
793 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
794 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
795 (m.hostAndDeviceProperties.Host_supported != nil &&
796 *m.hostAndDeviceProperties.Host_supported)
797}
798
Colin Cross4157e882019-06-06 16:57:04 -0700799func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900800 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900801}
802
Colin Cross4157e882019-06-06 16:57:04 -0700803func (m *ModuleBase) DeviceSpecific() bool {
804 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900805}
806
Colin Cross4157e882019-06-06 16:57:04 -0700807func (m *ModuleBase) SocSpecific() bool {
808 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900809}
810
Colin Cross4157e882019-06-06 16:57:04 -0700811func (m *ModuleBase) ProductSpecific() bool {
812 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900813}
814
Justin Yund5f6c822019-06-25 16:47:17 +0900815func (m *ModuleBase) SystemExtSpecific() bool {
816 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100817}
818
Colin Cross4157e882019-06-06 16:57:04 -0700819func (m *ModuleBase) Enabled() bool {
820 if m.commonProperties.Enabled == nil {
821 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800822 }
Colin Cross4157e882019-06-06 16:57:04 -0700823 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800824}
825
Colin Cross4157e882019-06-06 16:57:04 -0700826func (m *ModuleBase) SkipInstall() {
827 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700828}
829
Colin Cross4157e882019-06-06 16:57:04 -0700830func (m *ModuleBase) ExportedToMake() bool {
831 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900832}
833
Colin Cross4157e882019-06-06 16:57:04 -0700834func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700835 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800836
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700837 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700838 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800839 ctx.VisitDepsDepthFirstIf(isFileInstaller,
840 func(m blueprint.Module) {
841 fileInstaller := m.(fileInstaller)
842 files := fileInstaller.filesToInstall()
843 result = append(result, files...)
844 })
845
846 return result
847}
848
Colin Cross4157e882019-06-06 16:57:04 -0700849func (m *ModuleBase) filesToInstall() Paths {
850 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800851}
852
Colin Cross4157e882019-06-06 16:57:04 -0700853func (m *ModuleBase) NoAddressSanitizer() bool {
854 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800855}
856
Colin Cross4157e882019-06-06 16:57:04 -0700857func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800858 return false
859}
860
Jaewoong Jung0949f312019-09-11 10:25:18 -0700861func (m *ModuleBase) InstallInTestcases() bool {
862 return false
863}
864
Colin Cross4157e882019-06-06 16:57:04 -0700865func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700866 return false
867}
868
Colin Cross4157e882019-06-06 16:57:04 -0700869func (m *ModuleBase) InstallInRecovery() bool {
870 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900871}
872
Colin Cross90ba5f42019-10-02 11:10:58 -0700873func (m *ModuleBase) InstallInRoot() bool {
874 return false
875}
876
Colin Cross607d8582019-07-29 16:44:46 -0700877func (m *ModuleBase) InstallBypassMake() bool {
878 return false
879}
880
Colin Cross4157e882019-06-06 16:57:04 -0700881func (m *ModuleBase) Owner() string {
882 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900883}
884
Colin Cross4157e882019-06-06 16:57:04 -0700885func (m *ModuleBase) NoticeFile() OptionalPath {
886 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900887}
888
Colin Cross7228ecd2019-11-18 16:00:16 -0800889func (m *ModuleBase) setImageVariation(variant string) {
890 m.commonProperties.ImageVariation = variant
891}
892
893func (m *ModuleBase) ImageVariation() blueprint.Variation {
894 return blueprint.Variation{
895 Mutator: "image",
896 Variation: m.base().commonProperties.ImageVariation,
897 }
898}
899
900func (m *ModuleBase) InRecovery() bool {
901 return m.base().commonProperties.ImageVariation == RecoveryVariation
902}
903
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900904func (m *ModuleBase) RequiredModuleNames() []string {
905 return m.base().commonProperties.Required
906}
907
908func (m *ModuleBase) HostRequiredModuleNames() []string {
909 return m.base().commonProperties.Host_required
910}
911
912func (m *ModuleBase) TargetRequiredModuleNames() []string {
913 return m.base().commonProperties.Target_required
914}
915
Colin Cross4157e882019-06-06 16:57:04 -0700916func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700917 allInstalledFiles := Paths{}
918 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800919 ctx.VisitAllModuleVariants(func(module Module) {
920 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700921 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
922 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800923 })
924
Colin Cross0875c522017-11-28 17:34:01 -0800925 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700926
Jeff Gaston088e29e2017-11-29 16:47:17 -0800927 namespacePrefix := ctx.Namespace().(*Namespace).id
928 if namespacePrefix != "" {
929 namespacePrefix = namespacePrefix + "-"
930 }
931
Colin Cross3f40fa42015-01-30 17:27:36 -0800932 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800933 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800934 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700935 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800936 Output: name,
937 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800938 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700939 })
940 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700941 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700942 }
943
944 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800945 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800946 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700947 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800948 Output: name,
949 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700950 })
951 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700952 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700953 }
954
955 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800956 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800957 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800958 suffix = "-soong"
959 }
960
Jeff Gaston088e29e2017-11-29 16:47:17 -0800961 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800962 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700963 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800964 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700965 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800966 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700967
Colin Cross4157e882019-06-06 16:57:04 -0700968 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800969 }
970}
971
Colin Crossc34d2322020-01-03 15:23:27 -0800972func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -0700973 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
974 var deviceSpecific = Bool(m.commonProperties.Device_specific)
975 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +0900976 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900977
Dario Frenifd05a742018-05-29 13:28:54 +0100978 msg := "conflicting value set here"
979 if socSpecific && deviceSpecific {
980 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700981 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900982 ctx.PropertyErrorf("vendor", msg)
983 }
Colin Cross4157e882019-06-06 16:57:04 -0700984 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900985 ctx.PropertyErrorf("proprietary", msg)
986 }
Colin Cross4157e882019-06-06 16:57:04 -0700987 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900988 ctx.PropertyErrorf("soc_specific", msg)
989 }
990 }
991
Justin Yund5f6c822019-06-25 16:47:17 +0900992 if productSpecific && systemExtSpecific {
993 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
994 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +0100995 }
996
Justin Yund5f6c822019-06-25 16:47:17 +0900997 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100998 if productSpecific {
999 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1000 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001001 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 +01001002 }
1003 if deviceSpecific {
1004 ctx.PropertyErrorf("device_specific", msg)
1005 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001006 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001007 ctx.PropertyErrorf("vendor", msg)
1008 }
Colin Cross4157e882019-06-06 16:57:04 -07001009 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001010 ctx.PropertyErrorf("proprietary", msg)
1011 }
Colin Cross4157e882019-06-06 16:57:04 -07001012 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001013 ctx.PropertyErrorf("soc_specific", msg)
1014 }
1015 }
1016 }
1017
Jiyong Park2db76922017-11-08 16:03:48 +09001018 if productSpecific {
1019 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001020 } else if systemExtSpecific {
1021 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001022 } else if deviceSpecific {
1023 return deviceSpecificModule
1024 } else if socSpecific {
1025 return socSpecificModule
1026 } else {
1027 return platformModule
1028 }
1029}
1030
Colin Crossc34d2322020-01-03 15:23:27 -08001031func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001032 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001033 EarlyModuleContext: ctx,
1034 kind: determineModuleKind(m, ctx),
1035 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001036 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001037}
1038
Colin Cross1184b642019-12-30 18:43:07 -08001039func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1040 return baseModuleContext{
1041 bp: ctx,
1042 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1043 os: m.commonProperties.CompileOS,
1044 target: m.commonProperties.CompileTarget,
1045 targetPrimary: m.commonProperties.CompilePrimary,
1046 multiTargets: m.commonProperties.CompileMultiTargets,
1047 }
1048}
1049
Colin Cross4157e882019-06-06 16:57:04 -07001050func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001051 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001052 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001053 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001054 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1055 installDeps: m.computeInstallDeps(blueprintCtx),
1056 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001057 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001058 }
1059
Colin Cross6c4f21f2019-06-06 15:41:36 -07001060 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1061 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1062 // TODO: This will be removed once defaults modules handle missing dependency errors
1063 blueprintCtx.GetMissingDependencies()
1064
Colin Crossdc35e212019-06-06 16:13:11 -07001065 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
1066 // are enabled.
1067 ctx.baseModuleContext.strictVisitDeps = true
1068
Colin Cross4c83e5c2019-02-25 14:54:28 -08001069 if ctx.config.captureBuild {
1070 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1071 }
1072
Colin Cross67a5c132017-05-09 13:45:28 -07001073 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1074 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001075 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1076 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001077 }
Colin Cross0875c522017-11-28 17:34:01 -08001078 if !ctx.PrimaryArch() {
1079 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001080 }
1081
1082 ctx.Variable(pctx, "moduleDesc", desc)
1083
1084 s := ""
1085 if len(suffix) > 0 {
1086 s = " [" + strings.Join(suffix, " ") + "]"
1087 }
1088 ctx.Variable(pctx, "moduleDescSuffix", s)
1089
Dan Willemsen569edc52018-11-19 09:33:29 -08001090 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001091 if m.commonProperties.Dist.Dest != nil {
1092 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001093 if err != nil {
1094 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1095 }
1096 }
Colin Cross4157e882019-06-06 16:57:04 -07001097 if m.commonProperties.Dist.Dir != nil {
1098 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001099 if err != nil {
1100 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1101 }
1102 }
Colin Cross4157e882019-06-06 16:57:04 -07001103 if m.commonProperties.Dist.Suffix != nil {
1104 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001105 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1106 }
1107 }
1108
Colin Cross4157e882019-06-06 16:57:04 -07001109 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001110 // ensure all direct android.Module deps are enabled
1111 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1112 if _, ok := bm.(Module); ok {
1113 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1114 }
1115 })
1116
Colin Cross4157e882019-06-06 16:57:04 -07001117 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1118 if module := SrcIsModule(notice); module != "" {
1119 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001120 } else {
1121 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001122 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001123 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001124
1125 m.module.GenerateAndroidBuildActions(ctx)
1126 if ctx.Failed() {
1127 return
1128 }
1129
1130 m.installFiles = append(m.installFiles, ctx.installFiles...)
1131 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001132 } else if ctx.Config().AllowMissingDependencies() {
1133 // If the module is not enabled it will not create any build rules, nothing will call
1134 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1135 // and report them as an error even when AllowMissingDependencies = true. Call
1136 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1137 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001138 }
1139
Colin Cross4157e882019-06-06 16:57:04 -07001140 if m == ctx.FinalModule().(Module).base() {
1141 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001142 if ctx.Failed() {
1143 return
1144 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001145 }
Colin Crosscec81712017-07-13 14:43:27 -07001146
Colin Cross4157e882019-06-06 16:57:04 -07001147 m.buildParams = ctx.buildParams
1148 m.ruleParams = ctx.ruleParams
1149 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001150}
1151
Colin Cross1184b642019-12-30 18:43:07 -08001152type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001153 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001154
1155 kind moduleKind
1156 config Config
1157}
1158
1159func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1160 ret, err := e.GlobWithDeps(globPattern, excludes)
1161 if err != nil {
1162 e.ModuleErrorf("glob: %s", err.Error())
1163 }
1164 return pathsForModuleSrcFromFullPath(e, ret, true)
1165}
1166
1167func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1168 ret, err := e.GlobWithDeps(globPattern, excludes)
1169 if err != nil {
1170 e.ModuleErrorf("glob: %s", err.Error())
1171 }
1172 return pathsForModuleSrcFromFullPath(e, ret, false)
1173}
1174
1175func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001176 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001177 return module
1178}
1179
1180func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001181 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001182}
1183
1184func (e *earlyModuleContext) AConfig() Config {
1185 return e.config
1186}
1187
1188func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1189 return DeviceConfig{e.config.deviceConfig}
1190}
1191
1192func (e *earlyModuleContext) Platform() bool {
1193 return e.kind == platformModule
1194}
1195
1196func (e *earlyModuleContext) DeviceSpecific() bool {
1197 return e.kind == deviceSpecificModule
1198}
1199
1200func (e *earlyModuleContext) SocSpecific() bool {
1201 return e.kind == socSpecificModule
1202}
1203
1204func (e *earlyModuleContext) ProductSpecific() bool {
1205 return e.kind == productSpecificModule
1206}
1207
1208func (e *earlyModuleContext) SystemExtSpecific() bool {
1209 return e.kind == systemExtSpecificModule
1210}
1211
1212type baseModuleContext struct {
1213 bp blueprint.BaseModuleContext
1214 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001215 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001216 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001217 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001218 targetPrimary bool
1219 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001220
1221 walkPath []Module
1222
1223 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001224}
1225
Colin Cross1184b642019-12-30 18:43:07 -08001226func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { return b.bp.OtherModuleName(m) }
1227func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
1228func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
1229 b.bp.OtherModuleErrorf(m, fmt, args)
1230}
1231func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1232 return b.bp.OtherModuleDependencyTag(m)
1233}
1234func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1235func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { return b.bp.OtherModuleType(m) }
1236
1237func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1238 return b.bp.GetDirectDepWithTag(name, tag)
1239}
1240
Colin Cross25de6c32019-06-06 14:29:25 -07001241type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001242 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001243 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001244 installDeps Paths
1245 installFiles Paths
1246 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001247 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001248
1249 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001250 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001251 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001252 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001253}
1254
Colin Crossb88b3c52019-06-10 15:15:17 -07001255func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1256 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001257 Rule: ErrorRule,
1258 Description: params.Description,
1259 Output: params.Output,
1260 Outputs: params.Outputs,
1261 ImplicitOutput: params.ImplicitOutput,
1262 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001263 Args: map[string]string{
1264 "error": err.Error(),
1265 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001266 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001267}
1268
Colin Cross25de6c32019-06-06 14:29:25 -07001269func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1270 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001271}
1272
Colin Cross0875c522017-11-28 17:34:01 -08001273func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001274 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001275 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001276 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001277 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001278 Outputs: params.Outputs.Strings(),
1279 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1280 Inputs: params.Inputs.Strings(),
1281 Implicits: params.Implicits.Strings(),
1282 OrderOnly: params.OrderOnly.Strings(),
1283 Args: params.Args,
1284 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001285 }
1286
Colin Cross33bfb0a2016-11-21 17:23:08 -08001287 if params.Depfile != nil {
1288 bparams.Depfile = params.Depfile.String()
1289 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001290 if params.Output != nil {
1291 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1292 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001293 if params.ImplicitOutput != nil {
1294 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1295 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001296 if params.Input != nil {
1297 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1298 }
1299 if params.Implicit != nil {
1300 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1301 }
1302
Colin Cross0b9f31f2019-02-28 11:00:01 -08001303 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1304 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1305 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1306 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1307 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1308 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001309
Colin Cross0875c522017-11-28 17:34:01 -08001310 return bparams
1311}
1312
Colin Cross25de6c32019-06-06 14:29:25 -07001313func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1314 if m.config.captureBuild {
1315 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001316 }
1317
Colin Crossdc35e212019-06-06 16:13:11 -07001318 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001319}
1320
Colin Cross25de6c32019-06-06 14:29:25 -07001321func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001322 argNames ...string) blueprint.Rule {
1323
Ramy Medhatdd0418a2019-11-04 18:16:11 -05001324 if (m.config.UseGoma() || m.config.UseRBE()) && params.Pool == nil {
1325 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1326 // jobs to the local parallelism value
Colin Cross2e2dbc22019-09-25 13:31:46 -07001327 params.Pool = localPool
1328 }
1329
Colin Crossdc35e212019-06-06 16:13:11 -07001330 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001331
Colin Cross25de6c32019-06-06 14:29:25 -07001332 if m.config.captureBuild {
1333 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001334 }
1335
1336 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001337}
1338
Colin Cross25de6c32019-06-06 14:29:25 -07001339func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001340 if params.Description != "" {
1341 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1342 }
1343
1344 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1345 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1346 m.ModuleName(), strings.Join(missingDeps, ", ")))
1347 }
1348
Colin Cross25de6c32019-06-06 14:29:25 -07001349 if m.config.captureBuild {
1350 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001351 }
1352
Colin Crossdc35e212019-06-06 16:13:11 -07001353 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001354}
Colin Cross25de6c32019-06-06 14:29:25 -07001355func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001356 var missingDeps []string
1357 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001358 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001359 missingDeps = FirstUniqueStrings(missingDeps)
1360 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001361}
1362
Colin Crossdc35e212019-06-06 16:13:11 -07001363func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001364 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001365 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001366 *missingDeps = append(*missingDeps, deps...)
1367 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001368 }
1369}
1370
Colin Crossdc35e212019-06-06 16:13:11 -07001371func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001372 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001373
1374 if !strict {
1375 return aModule
1376 }
1377
Colin Cross380c69a2019-06-10 17:49:58 +00001378 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001379 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001380 return nil
1381 }
1382
1383 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001384 if b.Config().AllowMissingDependencies() {
1385 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001386 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001387 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001388 }
1389 return nil
1390 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001391 return aModule
1392}
1393
Colin Crossdc35e212019-06-06 16:13:11 -07001394func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001395 type dep struct {
1396 mod blueprint.Module
1397 tag blueprint.DependencyTag
1398 }
1399 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001400 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001401 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001402 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001403 if tag == nil || returnedTag == tag {
1404 deps = append(deps, dep{aModule, returnedTag})
1405 }
1406 }
1407 })
1408 if len(deps) == 1 {
1409 return deps[0].mod, deps[0].tag
1410 } else if len(deps) >= 2 {
1411 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001412 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001413 } else {
1414 return nil, nil
1415 }
1416}
1417
Colin Crossdc35e212019-06-06 16:13:11 -07001418func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001419 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001420 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001421 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001422 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001423 deps = append(deps, aModule)
1424 }
1425 }
1426 })
1427 return deps
1428}
1429
Colin Cross25de6c32019-06-06 14:29:25 -07001430func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1431 module, _ := m.getDirectDepInternal(name, tag)
1432 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001433}
1434
Colin Crossdc35e212019-06-06 16:13:11 -07001435func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1436 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001437}
1438
Colin Crossdc35e212019-06-06 16:13:11 -07001439func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001440 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001441}
1442
Colin Crossdc35e212019-06-06 16:13:11 -07001443func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001444 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001445 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001446 visit(aModule)
1447 }
1448 })
1449}
1450
Colin Crossdc35e212019-06-06 16:13:11 -07001451func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001452 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001453 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001454 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001455 visit(aModule)
1456 }
1457 }
1458 })
1459}
1460
Colin Crossdc35e212019-06-06 16:13:11 -07001461func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001462 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001463 // pred
1464 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001465 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001466 return pred(aModule)
1467 } else {
1468 return false
1469 }
1470 },
1471 // visit
1472 func(module blueprint.Module) {
1473 visit(module.(Module))
1474 })
1475}
1476
Colin Crossdc35e212019-06-06 16:13:11 -07001477func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001478 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001479 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001480 visit(aModule)
1481 }
1482 })
1483}
1484
Colin Crossdc35e212019-06-06 16:13:11 -07001485func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001486 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001487 // pred
1488 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001489 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001490 return pred(aModule)
1491 } else {
1492 return false
1493 }
1494 },
1495 // visit
1496 func(module blueprint.Module) {
1497 visit(module.(Module))
1498 })
1499}
1500
Colin Crossdc35e212019-06-06 16:13:11 -07001501func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001502 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001503}
1504
Colin Crossdc35e212019-06-06 16:13:11 -07001505func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1506 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001507 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001508 childAndroidModule, _ := child.(Module)
1509 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001510 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001511 // record walkPath before visit
1512 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1513 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1514 }
1515 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001516 return visit(childAndroidModule, parentAndroidModule)
1517 } else {
1518 return false
1519 }
1520 })
1521}
1522
Colin Crossdc35e212019-06-06 16:13:11 -07001523func (b *baseModuleContext) GetWalkPath() []Module {
1524 return b.walkPath
1525}
1526
Colin Cross25de6c32019-06-06 14:29:25 -07001527func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001528 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001529 visit(module.(Module))
1530 })
1531}
1532
Colin Cross25de6c32019-06-06 14:29:25 -07001533func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001534 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001535}
1536
Colin Cross25de6c32019-06-06 14:29:25 -07001537func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001538 return m.bp.FinalModule().(Module)
1539}
1540
1541func (m *moduleContext) ModuleSubDir() string {
1542 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001543}
1544
Colin Cross0ea8ba82019-06-06 14:33:29 -07001545func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001546 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001547}
1548
Colin Cross0ea8ba82019-06-06 14:33:29 -07001549func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001550 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001551}
1552
Colin Cross0ea8ba82019-06-06 14:33:29 -07001553func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001554 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001555}
1556
Colin Cross0ea8ba82019-06-06 14:33:29 -07001557func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001558 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001559}
1560
Colin Cross0ea8ba82019-06-06 14:33:29 -07001561func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001562 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001563}
1564
Colin Cross0ea8ba82019-06-06 14:33:29 -07001565func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001566 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001567}
1568
Colin Cross0ea8ba82019-06-06 14:33:29 -07001569func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001570 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001571}
1572
Colin Cross0ea8ba82019-06-06 14:33:29 -07001573func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001574 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001575}
1576
Colin Cross0ea8ba82019-06-06 14:33:29 -07001577func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001578 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001579}
1580
Colin Cross0ea8ba82019-06-06 14:33:29 -07001581func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001582 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001583}
1584
Colin Cross0ea8ba82019-06-06 14:33:29 -07001585func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001586 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001587}
1588
Colin Cross0ea8ba82019-06-06 14:33:29 -07001589func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001590 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001591 return true
1592 }
Colin Cross25de6c32019-06-06 14:29:25 -07001593 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001594}
1595
Jiyong Park5baac542018-08-28 09:55:37 +09001596// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001597// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001598func (m *ModuleBase) MakeAsPlatform() {
1599 m.commonProperties.Vendor = boolPtr(false)
1600 m.commonProperties.Proprietary = boolPtr(false)
1601 m.commonProperties.Soc_specific = boolPtr(false)
1602 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001603 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001604}
1605
Colin Cross4157e882019-06-06 16:57:04 -07001606func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1607 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001608}
1609
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001610func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001611 m.commonProperties.Vendor = boolPtr(false)
1612 m.commonProperties.Proprietary = boolPtr(false)
1613 m.commonProperties.Soc_specific = boolPtr(false)
1614 m.commonProperties.Product_specific = boolPtr(false)
1615 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001616}
1617
Jooyung Han344d5432019-08-23 11:17:39 +09001618// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1619func (m *ModuleBase) IsNativeBridgeSupported() bool {
1620 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1621}
1622
Colin Cross25de6c32019-06-06 14:29:25 -07001623func (m *moduleContext) InstallInData() bool {
1624 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001625}
1626
Jaewoong Jung0949f312019-09-11 10:25:18 -07001627func (m *moduleContext) InstallInTestcases() bool {
1628 return m.module.InstallInTestcases()
1629}
1630
Colin Cross25de6c32019-06-06 14:29:25 -07001631func (m *moduleContext) InstallInSanitizerDir() bool {
1632 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001633}
1634
Colin Cross25de6c32019-06-06 14:29:25 -07001635func (m *moduleContext) InstallInRecovery() bool {
1636 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001637}
1638
Colin Cross90ba5f42019-10-02 11:10:58 -07001639func (m *moduleContext) InstallInRoot() bool {
1640 return m.module.InstallInRoot()
1641}
1642
Colin Cross607d8582019-07-29 16:44:46 -07001643func (m *moduleContext) InstallBypassMake() bool {
1644 return m.module.InstallBypassMake()
1645}
1646
Colin Cross70dda7e2019-10-01 22:05:35 -07001647func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001648 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001649 return true
1650 }
1651
Colin Cross3607f212018-05-07 15:28:05 -07001652 // We'll need a solution for choosing which of modules with the same name in different
1653 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1654 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001655 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001656 return true
1657 }
1658
Colin Cross25de6c32019-06-06 14:29:25 -07001659 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001660 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001661 return true
1662 }
1663
Colin Cross25de6c32019-06-06 14:29:25 -07001664 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001665 return true
1666 }
1667 }
1668
1669 return false
1670}
1671
Colin Cross70dda7e2019-10-01 22:05:35 -07001672func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1673 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001674 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001675}
1676
Colin Cross70dda7e2019-10-01 22:05:35 -07001677func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1678 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001679 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001680}
1681
Colin Cross70dda7e2019-10-01 22:05:35 -07001682func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1683 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001684
Colin Cross25de6c32019-06-06 14:29:25 -07001685 fullInstallPath := installPath.Join(m, name)
1686 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001687
Colin Cross25de6c32019-06-06 14:29:25 -07001688 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001689
Colin Cross25de6c32019-06-06 14:29:25 -07001690 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001691
Colin Cross89562dc2016-10-03 17:47:19 -07001692 var implicitDeps, orderOnlyDeps Paths
1693
Colin Cross25de6c32019-06-06 14:29:25 -07001694 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001695 // Installed host modules might be used during the build, depend directly on their
1696 // dependencies so their timestamp is updated whenever their dependency is updated
1697 implicitDeps = deps
1698 } else {
1699 orderOnlyDeps = deps
1700 }
1701
Colin Cross25de6c32019-06-06 14:29:25 -07001702 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001703 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001704 Description: "install " + fullInstallPath.Base(),
1705 Output: fullInstallPath,
1706 Input: srcPath,
1707 Implicits: implicitDeps,
1708 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001709 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001710 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001711
Colin Cross25de6c32019-06-06 14:29:25 -07001712 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001713 }
Colin Cross25de6c32019-06-06 14:29:25 -07001714 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001715 return fullInstallPath
1716}
1717
Colin Cross70dda7e2019-10-01 22:05:35 -07001718func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001719 fullInstallPath := installPath.Join(m, name)
1720 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001721
Colin Cross25de6c32019-06-06 14:29:25 -07001722 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001723
Alex Lightfb4353d2019-01-17 13:57:45 -08001724 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1725 if err != nil {
1726 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1727 }
Colin Cross25de6c32019-06-06 14:29:25 -07001728 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001729 Rule: Symlink,
1730 Description: "install symlink " + fullInstallPath.Base(),
1731 Output: fullInstallPath,
1732 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001733 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001734 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001735 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001736 },
1737 })
Colin Cross3854a602016-01-11 12:49:11 -08001738
Colin Cross25de6c32019-06-06 14:29:25 -07001739 m.installFiles = append(m.installFiles, fullInstallPath)
1740 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001741 }
Colin Cross3854a602016-01-11 12:49:11 -08001742 return fullInstallPath
1743}
1744
Jiyong Parkf1194352019-02-25 11:05:47 +09001745// installPath/name -> absPath where absPath might be a path that is available only at runtime
1746// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001747func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001748 fullInstallPath := installPath.Join(m, name)
1749 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001750
Colin Cross25de6c32019-06-06 14:29:25 -07001751 if !m.skipInstall(fullInstallPath) {
1752 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001753 Rule: Symlink,
1754 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1755 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001756 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001757 Args: map[string]string{
1758 "fromPath": absPath,
1759 },
1760 })
1761
Colin Cross25de6c32019-06-06 14:29:25 -07001762 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001763 }
1764 return fullInstallPath
1765}
1766
Colin Cross25de6c32019-06-06 14:29:25 -07001767func (m *moduleContext) CheckbuildFile(srcPath Path) {
1768 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001769}
1770
Colin Cross3f40fa42015-01-30 17:27:36 -08001771type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001772 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001773}
1774
1775func isFileInstaller(m blueprint.Module) bool {
1776 _, ok := m.(fileInstaller)
1777 return ok
1778}
1779
1780func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001781 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001782 return ok
1783}
Colin Crossfce53272015-04-08 11:21:40 -07001784
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001785func findStringInSlice(str string, slice []string) int {
1786 for i, s := range slice {
1787 if s == str {
1788 return i
Colin Crossfce53272015-04-08 11:21:40 -07001789 }
1790 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001791 return -1
1792}
1793
Colin Cross41955e82019-05-29 14:40:35 -07001794// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1795// was not a module reference.
1796func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001797 if len(s) > 1 && s[0] == ':' {
1798 return s[1:]
1799 }
1800 return ""
1801}
1802
Colin Cross41955e82019-05-29 14:40:35 -07001803// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1804// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1805func SrcIsModuleWithTag(s string) (module, tag string) {
1806 if len(s) > 1 && s[0] == ':' {
1807 module = s[1:]
1808 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1809 if module[len(module)-1] == '}' {
1810 tag = module[tagStart+1 : len(module)-1]
1811 module = module[:tagStart]
1812 return module, tag
1813 }
1814 }
1815 return module, ""
1816 }
1817 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001818}
1819
Colin Cross41955e82019-05-29 14:40:35 -07001820type sourceOrOutputDependencyTag struct {
1821 blueprint.BaseDependencyTag
1822 tag string
1823}
1824
1825func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1826 return sourceOrOutputDependencyTag{tag: tag}
1827}
1828
1829var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001830
Colin Cross366938f2017-12-11 16:29:02 -08001831// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1832// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001833//
1834// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001835func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001836 set := make(map[string]bool)
1837
Colin Cross068e0fe2016-12-13 15:23:47 -08001838 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001839 if m, t := SrcIsModuleWithTag(s); m != "" {
1840 if _, found := set[s]; found {
1841 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001842 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001843 set[s] = true
1844 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001845 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001846 }
1847 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001848}
1849
Colin Cross366938f2017-12-11 16:29:02 -08001850// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1851// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001852//
1853// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001854func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1855 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001856 if m, t := SrcIsModuleWithTag(*s); m != "" {
1857 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001858 }
1859 }
1860}
1861
Colin Cross41955e82019-05-29 14:40:35 -07001862// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1863// 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 -08001864type SourceFileProducer interface {
1865 Srcs() Paths
1866}
1867
Colin Cross41955e82019-05-29 14:40:35 -07001868// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00001869// 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 -07001870// listed in the property.
1871type OutputFileProducer interface {
1872 OutputFiles(tag string) (Paths, error)
1873}
1874
Colin Cross5e708052019-08-06 13:59:50 -07001875// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
1876// module produced zero paths, it reports errors to the ctx and returns nil.
1877func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
1878 paths, err := outputFilesForModule(ctx, module, tag)
1879 if err != nil {
1880 reportPathError(ctx, err)
1881 return nil
1882 }
1883 return paths
1884}
1885
1886// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
1887// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
1888func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
1889 paths, err := outputFilesForModule(ctx, module, tag)
1890 if err != nil {
1891 reportPathError(ctx, err)
1892 return nil
1893 }
1894 if len(paths) > 1 {
1895 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
1896 pathContextName(ctx, module))
1897 return nil
1898 }
1899 return paths[0]
1900}
1901
1902func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
1903 if outputFileProducer, ok := module.(OutputFileProducer); ok {
1904 paths, err := outputFileProducer.OutputFiles(tag)
1905 if err != nil {
1906 return nil, fmt.Errorf("failed to get output file from module %q: %s",
1907 pathContextName(ctx, module), err.Error())
1908 }
1909 if len(paths) == 0 {
1910 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
1911 }
1912 return paths, nil
1913 } else {
1914 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
1915 }
1916}
1917
Colin Crossfe17f6f2019-03-28 19:30:56 -07001918type HostToolProvider interface {
1919 HostToolPath() OptionalPath
1920}
1921
Colin Cross27b922f2019-03-04 22:35:41 -08001922// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1923// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001924//
1925// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001926func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1927 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001928}
1929
Colin Cross2fafa3e2019-03-05 12:39:51 -08001930// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1931// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001932//
1933// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001934func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1935 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001936}
1937
1938// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1939// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1940// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001941func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001942 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001943 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001944 }
1945 return OptionalPath{}
1946}
1947
Colin Cross25de6c32019-06-06 14:29:25 -07001948func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001949 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08001950}
1951
Colin Cross25de6c32019-06-06 14:29:25 -07001952func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001953 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07001954}
1955
Colin Cross25de6c32019-06-06 14:29:25 -07001956func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001957 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07001958}
1959
Colin Cross463a90e2015-06-17 14:20:06 -07001960func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001961 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001962}
1963
Colin Cross0875c522017-11-28 17:34:01 -08001964func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001965 return &buildTargetSingleton{}
1966}
1967
Colin Cross87d8b562017-04-25 10:01:55 -07001968func parentDir(dir string) string {
1969 dir, _ = filepath.Split(dir)
1970 return filepath.Clean(dir)
1971}
1972
Colin Cross1f8c52b2015-06-16 16:38:17 -07001973type buildTargetSingleton struct{}
1974
Colin Cross0875c522017-11-28 17:34:01 -08001975func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1976 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001977
Colin Cross0875c522017-11-28 17:34:01 -08001978 mmTarget := func(dir string) WritablePath {
1979 return PathForPhony(ctx,
1980 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001981 }
1982
Colin Cross0875c522017-11-28 17:34:01 -08001983 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001984
Colin Cross0875c522017-11-28 17:34:01 -08001985 ctx.VisitAllModules(func(module Module) {
1986 blueprintDir := module.base().blueprintDir
1987 installTarget := module.base().installTarget
1988 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001989
Colin Cross0875c522017-11-28 17:34:01 -08001990 if checkbuildTarget != nil {
1991 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1992 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1993 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001994
Colin Cross0875c522017-11-28 17:34:01 -08001995 if installTarget != nil {
1996 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001997 }
1998 })
1999
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002000 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002001 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002002 suffix = "-soong"
2003 }
2004
Colin Cross1f8c52b2015-06-16 16:38:17 -07002005 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08002006 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002007 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002008 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002009 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07002010 })
2011
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002012 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002013 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002014 return
2015 }
2016
Colin Cross87d8b562017-04-25 10:01:55 -07002017 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002018 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002019 for _, dir := range dirs {
2020 dir := parentDir(dir)
2021 for dir != "." && dir != "/" {
2022 if _, exists := modulesInDir[dir]; exists {
2023 break
2024 }
2025 modulesInDir[dir] = nil
2026 dir = parentDir(dir)
2027 }
2028 }
2029
2030 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002031 for _, dir := range dirs {
2032 p := parentDir(dir)
2033 if p != "." && p != "/" {
2034 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2035 }
2036 }
2037
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002038 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2039 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2040 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002041 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002042 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002043 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002044 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002045 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002046 // HACK: checkbuild should be an optional build, but force it
2047 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002048 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002049 })
2050 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002051
2052 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2053 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002054 ctx.VisitAllModules(func(module Module) {
2055 if module.Enabled() {
2056 os := module.Target().Os
2057 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002058 }
2059 })
2060
Colin Cross0875c522017-11-28 17:34:01 -08002061 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002062 for os, deps := range osDeps {
2063 var className string
2064
2065 switch os.Class {
2066 case Host:
2067 className = "host"
2068 case HostCross:
2069 className = "host-cross"
2070 case Device:
2071 className = "target"
2072 default:
2073 continue
2074 }
2075
Colin Cross0875c522017-11-28 17:34:01 -08002076 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002077 osClass[className] = append(osClass[className], name)
2078
Colin Cross0875c522017-11-28 17:34:01 -08002079 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002080 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002081 Output: name,
2082 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002083 })
2084 }
2085
2086 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002087 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002088 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002089 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002090 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002091 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002092 })
2093 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002094}
Colin Crossd779da42015-12-17 18:00:23 -08002095
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002096// Collect information for opening IDE project files in java/jdeps.go.
2097type IDEInfo interface {
2098 IDEInfo(ideInfo *IdeInfo)
2099 BaseModuleName() string
2100}
2101
2102// Extract the base module name from the Import name.
2103// Often the Import name has a prefix "prebuilt_".
2104// Remove the prefix explicitly if needed
2105// until we find a better solution to get the Import name.
2106type IDECustomizedModuleName interface {
2107 IDECustomizedModuleName() string
2108}
2109
2110type IdeInfo struct {
2111 Deps []string `json:"dependencies,omitempty"`
2112 Srcs []string `json:"srcs,omitempty"`
2113 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2114 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2115 Jars []string `json:"jars,omitempty"`
2116 Classes []string `json:"class,omitempty"`
2117 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002118 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002119}