blob: 0ac2135334baacb817520ea10d322fb6f210aa97 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000019 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080020 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "path/filepath"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080023 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
25 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
29var (
30 DeviceSharedLibrary = "shared_library"
31 DeviceStaticLibrary = "static_library"
32 DeviceExecutable = "executable"
33 HostSharedLibrary = "host_shared_library"
34 HostStaticLibrary = "host_static_library"
35 HostExecutable = "host_executable"
36)
37
Colin Crossae887032017-10-23 17:16:14 -070038type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080040 Deps blueprint.Deps
41 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070043 Output WritablePath
44 Outputs WritablePaths
45 ImplicitOutput WritablePath
46 ImplicitOutputs WritablePaths
47 Input Path
48 Inputs Paths
49 Implicit Path
50 Implicits Paths
51 OrderOnly Paths
52 Default bool
53 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054}
55
Colin Crossae887032017-10-23 17:16:14 -070056type ModuleBuildParams BuildParams
57
Colin Cross1184b642019-12-30 18:43:07 -080058// EarlyModuleContext provides methods that can be called early, as soon as the properties have
59// been parsed into the module and before any mutators have run.
60type EarlyModuleContext interface {
61 Module() Module
62 ModuleName() string
63 ModuleDir() string
64 ModuleType() string
Colin Cross9d34f352019-11-22 16:03:51 -080065 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080066
67 ContainsProperty(name string) bool
68 Errorf(pos scanner.Position, fmt string, args ...interface{})
69 ModuleErrorf(fmt string, args ...interface{})
70 PropertyErrorf(property, fmt string, args ...interface{})
71 Failed() bool
72
73 AddNinjaFileDeps(deps ...string)
74
75 DeviceSpecific() bool
76 SocSpecific() bool
77 ProductSpecific() bool
78 SystemExtSpecific() bool
79 Platform() bool
80
81 Config() Config
82 DeviceConfig() DeviceConfig
83
84 // Deprecated: use Config()
85 AConfig() Config
86
87 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
88 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
89 // builder whenever a file matching the pattern as added or removed, without rerunning if a
90 // file that does not match the pattern is added to a searched directory.
91 GlobWithDeps(pattern string, excludes []string) ([]string, error)
92
93 Glob(globPattern string, excludes []string) Paths
94 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +000095 IsSymlink(path Path) bool
96 Readlink(path Path) string
Colin Cross1184b642019-12-30 18:43:07 -080097}
98
Colin Cross0ea8ba82019-06-06 14:33:29 -070099// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700100// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
101// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700102// about the current module.
103type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800104 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700105
Colin Crossdc35e212019-06-06 16:13:11 -0700106 OtherModuleName(m blueprint.Module) string
107 OtherModuleDir(m blueprint.Module) string
108 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
109 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
110 OtherModuleExists(name string) bool
Jiyong Park9e6c2422019-08-09 20:39:45 +0900111 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700112
113 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
114 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
115 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
116
117 VisitDirectDepsBlueprint(visit func(blueprint.Module))
118 VisitDirectDeps(visit func(Module))
119 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
120 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
121 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
122 VisitDepsDepthFirst(visit func(Module))
123 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
124 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
125 WalkDeps(visit func(Module, Module) bool)
126 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
127 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
128 // and returns a top-down dependency path from a start module to current child module.
129 GetWalkPath() []Module
130
Colin Crossdc35e212019-06-06 16:13:11 -0700131 AddMissingDependencies(missingDeps []string)
132
Colin Crossa1ad8d12016-06-01 17:09:44 -0700133 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700134 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -0700135 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700136 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700137 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700138 Host() bool
139 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700140 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800141 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700142 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700143 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700144 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700145}
146
Colin Cross1184b642019-12-30 18:43:07 -0800147// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700148type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800149 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800150}
151
Colin Cross635c3b02016-05-18 15:37:25 -0700152type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800153 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800154
Colin Crossae887032017-10-23 17:16:14 -0700155 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800156 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700157
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700158 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800159 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800160 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700161
Colin Cross70dda7e2019-10-01 22:05:35 -0700162 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
163 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
164 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
165 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700166 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800167
Colin Cross8d8f8e22016-08-03 11:57:50 -0700168 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700169 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700170 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900171 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700172 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700173 InstallBypassMake() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800174
175 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700176 HostRequiredModuleNames() []string
177 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700178
Colin Cross3f68a132017-10-23 17:10:29 -0700179 ModuleSubDir() string
180
Colin Cross0875c522017-11-28 17:34:01 -0800181 Variable(pctx PackageContext, name, value string)
182 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700183 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
184 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800185 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700186
Colin Cross0875c522017-11-28 17:34:01 -0800187 PrimaryModule() Module
188 FinalModule() Module
189 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700190
191 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800192 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800193}
194
Colin Cross635c3b02016-05-18 15:37:25 -0700195type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800196 blueprint.Module
197
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700198 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
199 // but GenerateAndroidBuildActions also has access to Android-specific information.
200 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700201 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700202
Colin Cross1e676be2016-10-12 14:38:15 -0700203 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800204
Colin Cross635c3b02016-05-18 15:37:25 -0700205 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800206 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700207 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800208 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700209 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700210 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900211 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700212 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700213 InstallBypassMake() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800214 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900215 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900216 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700217
218 AddProperties(props ...interface{})
219 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700220
Colin Crossae887032017-10-23 17:16:14 -0700221 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800222 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800223 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100224
Colin Cross9a362232019-07-01 15:32:45 -0700225 // String returns a string that includes the module name and variants for printing during debugging.
226 String() string
227
Paul Duffine2453c72019-05-31 14:00:04 +0100228 // Get the qualified module id for this module.
229 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
230
231 // Get information about the properties that can contain visibility rules.
232 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100233
234 // Get the visibility rules that control the visibility of this module.
235 visibility() []string
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900236
237 RequiredModuleNames() []string
238 HostRequiredModuleNames() []string
239 TargetRequiredModuleNames() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100240}
241
242// Qualified id for a module
243type qualifiedModuleName struct {
244 // The package (i.e. directory) in which the module is defined, without trailing /
245 pkg string
246
247 // The name of the module, empty string if package.
248 name string
249}
250
251func (q qualifiedModuleName) String() string {
252 if q.name == "" {
253 return "//" + q.pkg
254 }
255 return "//" + q.pkg + ":" + q.name
256}
257
Paul Duffine484f472019-06-20 16:38:08 +0100258func (q qualifiedModuleName) isRootPackage() bool {
259 return q.pkg == "" && q.name == ""
260}
261
Paul Duffine2453c72019-05-31 14:00:04 +0100262// Get the id for the package containing this module.
263func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
264 pkg := q.pkg
265 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100266 if pkg == "" {
267 panic(fmt.Errorf("Cannot get containing package id of root package"))
268 }
269
270 index := strings.LastIndex(pkg, "/")
271 if index == -1 {
272 pkg = ""
273 } else {
274 pkg = pkg[:index]
275 }
Paul Duffine2453c72019-05-31 14:00:04 +0100276 }
277 return newPackageId(pkg)
278}
279
280func newPackageId(pkg string) qualifiedModuleName {
281 // A qualified id for a package module has no name.
282 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800283}
284
Colin Crossfc754582016-05-17 16:34:16 -0700285type nameProperties struct {
286 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800287 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700288}
289
290type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800291 // emit build rules for this module
292 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800293
Paul Duffin2e61fa62019-03-28 14:10:57 +0000294 // Controls the visibility of this module to other modules. Allowable values are one or more of
295 // these formats:
296 //
297 // ["//visibility:public"]: Anyone can use this module.
298 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
299 // this module.
300 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
301 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
302 // this module. Note that sub-packages do not have access to the rule; for example,
303 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
304 // is a special module and must be used verbatim. It represents all of the modules in the
305 // package.
306 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
307 // or other or in one of their sub-packages have access to this module. For example,
308 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
309 // to depend on this rule (but not //independent:evil)
310 // ["//project"]: This is shorthand for ["//project:__pkg__"]
311 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
312 // //project is the module's package. e.g. using [":__subpackages__"] in
313 // packages/apps/Settings/Android.bp is equivalent to
314 // //packages/apps/Settings:__subpackages__.
315 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
316 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100317 //
318 // If a module does not specify the `visibility` property then it uses the
319 // `default_visibility` property of the `package` module in the module's package.
320 //
321 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100322 // it will use the `default_visibility` of its closest ancestor package for which
323 // a `default_visibility` property is specified.
324 //
325 // If no `default_visibility` property can be found then the module uses the
326 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100327 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100328 // The `visibility` property has no effect on a defaults module although it does
329 // apply to any non-defaults module that uses it. To set the visibility of a
330 // defaults module, use the `defaults_visibility` property on the defaults module;
331 // not to be confused with the `default_visibility` property on the package module.
332 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000333 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
334 // more details.
335 Visibility []string
336
Colin Cross7d5136f2015-05-11 13:39:40 -0700337 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800338 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
339 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
340 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700341 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700342
343 Target struct {
344 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700345 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700346 }
347 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700348 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700349 }
350 }
351
Colin Crossee0bc3b2018-10-02 22:01:37 -0700352 UseTargetVariants bool `blueprint:"mutated"`
353 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800354
Dan Willemsen782a2d12015-12-21 14:55:28 -0800355 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700356 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800357
Colin Cross55708f32017-03-20 13:23:34 -0700358 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700359 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700360
Jiyong Park2db76922017-11-08 16:03:48 +0900361 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
362 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
363 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700364 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700365
Jiyong Park2db76922017-11-08 16:03:48 +0900366 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
367 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
368 Soc_specific *bool
369
370 // whether this module is specific to a device, not only for SoC, but also for off-chip
371 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
372 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
373 // This implies `soc_specific:true`.
374 Device_specific *bool
375
376 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900377 // network operator, etc). When set to true, it is installed into /product (or
378 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900379 Product_specific *bool
380
Justin Yund5f6c822019-06-25 16:47:17 +0900381 // whether this module extends system. When set to true, it is installed into /system_ext
382 // (or /system/system_ext if system_ext partition does not exist).
383 System_ext_specific *bool
384
Jiyong Parkf9332f12018-02-01 00:54:12 +0900385 // Whether this module is installed to recovery partition
386 Recovery *bool
387
dimitry1f33e402019-03-26 12:39:31 +0100388 // Whether this module is built for non-native architecures (also known as native bridge binary)
389 Native_bridge_supported *bool `android:"arch_variant"`
390
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700391 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800392 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700393
Steven Moreland57a23d22018-04-04 15:42:19 -0700394 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800395 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700396
Chris Wolfe998306e2016-08-15 14:47:23 -0400397 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700398 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400399
Sasha Smundakb6d23052019-04-01 18:37:36 -0700400 // names of other modules to install on host if this module is installed
401 Host_required []string `android:"arch_variant"`
402
403 // names of other modules to install on target if this module is installed
404 Target_required []string `android:"arch_variant"`
405
Colin Cross5aac3622017-08-31 15:07:09 -0700406 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800407 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700408
Dan Willemsen569edc52018-11-19 09:33:29 -0800409 Dist struct {
410 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
411 // command line and any of these targets are also on the command line, or otherwise
412 // built
413 Targets []string `android:"arch_variant"`
414
415 // The name of the output artifact. This defaults to the basename of the output of
416 // the module.
417 Dest *string `android:"arch_variant"`
418
419 // The directory within the dist directory to store the artifact. Defaults to the
420 // top level directory ("").
421 Dir *string `android:"arch_variant"`
422
423 // A suffix to add to the artifact file name (before any extension).
424 Suffix *string `android:"arch_variant"`
425 } `android:"arch_variant"`
426
Colin Crossa1ad8d12016-06-01 17:09:44 -0700427 // Set by TargetMutator
Colin Crossa195f912019-10-16 11:07:20 -0700428 CompileOS OsType `blueprint:"mutated"`
Colin Crossee0bc3b2018-10-02 22:01:37 -0700429 CompileTarget Target `blueprint:"mutated"`
430 CompileMultiTargets []Target `blueprint:"mutated"`
431 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800432
433 // Set by InitAndroidModule
434 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700435 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700436
437 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800438
439 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700440
441 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700442
443 // Name and variant strings stored by mutators to enable Module.String()
444 DebugName string `blueprint:"mutated"`
445 DebugMutators []string `blueprint:"mutated"`
446 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800447
448 // set by ImageMutator
449 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800450}
451
452type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800453 // If set to true, build a variant of the module for the host. Defaults to false.
454 Host_supported *bool
455
456 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700457 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800458}
459
Colin Crossc472d572015-03-17 15:06:21 -0700460type Multilib string
461
462const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800463 MultilibBoth Multilib = "both"
464 MultilibFirst Multilib = "first"
465 MultilibCommon Multilib = "common"
466 MultilibCommonFirst Multilib = "common_first"
467 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700468)
469
Colin Crossa1ad8d12016-06-01 17:09:44 -0700470type HostOrDeviceSupported int
471
472const (
473 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700474
475 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700476 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700477
478 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700479 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700480
481 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700482 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700483
484 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700485 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700486
487 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700488 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700489
490 // Nothing is supported. This is not exposed to the user, but used to mark a
491 // host only module as unsupported when the module type is not supported on
492 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700493 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700494)
495
Jiyong Park2db76922017-11-08 16:03:48 +0900496type moduleKind int
497
498const (
499 platformModule moduleKind = iota
500 deviceSpecificModule
501 socSpecificModule
502 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900503 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900504)
505
506func (k moduleKind) String() string {
507 switch k {
508 case platformModule:
509 return "platform"
510 case deviceSpecificModule:
511 return "device-specific"
512 case socSpecificModule:
513 return "soc-specific"
514 case productSpecificModule:
515 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900516 case systemExtSpecificModule:
517 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900518 default:
519 panic(fmt.Errorf("unknown module kind %d", k))
520 }
521}
522
Colin Cross9d34f352019-11-22 16:03:51 -0800523func initAndroidModuleBase(m Module) {
524 m.base().module = m
525}
526
Colin Cross36242852017-06-23 15:06:31 -0700527func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800528 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800529 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700530
Colin Cross36242852017-06-23 15:06:31 -0700531 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700532 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700533 &base.commonProperties)
534
535 // Allow tests to override the default product variables
536 if base.variableProperties == nil {
537 base.variableProperties = zeroProductVariables
538 }
539
540 // Filter the product variables properties to the ones that exist on this module
541 base.variableProperties = createVariableProperties(m.GetProperties(), base.variableProperties)
542 if base.variableProperties != nil {
543 m.AddProperties(base.variableProperties)
544 }
545
Colin Crossa3a97412019-03-18 12:24:29 -0700546 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700547 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100548
549 // The default_visibility property needs to be checked and parsed by the visibility module during
550 // its checking and parsing phases.
551 base.primaryVisibilityProperty =
552 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
553 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700554}
555
Colin Cross36242852017-06-23 15:06:31 -0700556func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
557 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700558
559 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800560 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700561 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700562 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700563 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800564
Dan Willemsen218f6562015-07-08 18:13:11 -0700565 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700566 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700567 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800568 }
569
Colin Cross36242852017-06-23 15:06:31 -0700570 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800571}
572
Colin Crossee0bc3b2018-10-02 22:01:37 -0700573func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
574 InitAndroidArchModule(m, hod, defaultMultilib)
575 m.base().commonProperties.UseTargetVariants = false
576}
577
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800578// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800579// modules. It should be included as an anonymous field in every module
580// struct definition. InitAndroidModule should then be called from the module's
581// factory function, and the return values from InitAndroidModule should be
582// returned from the factory function.
583//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800584// The ModuleBase type is responsible for implementing the GenerateBuildActions
585// method to support the blueprint.Module interface. This method will then call
586// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700587// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
588// rather than the usual blueprint.ModuleContext.
589// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800590// system including details about the particular build variant that is to be
591// generated.
592//
593// For example:
594//
595// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800596// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800597// )
598//
599// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800600// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800601// properties struct {
602// MyProperty string
603// }
604// }
605//
Colin Cross36242852017-06-23 15:06:31 -0700606// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800607// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700608// m.AddProperties(&m.properties)
609// android.InitAndroidModule(m)
610// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800611// }
612//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800613// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800614// // Get the CPU architecture for the current build variant.
615// variantArch := ctx.Arch()
616//
617// // ...
618// }
Colin Cross635c3b02016-05-18 15:37:25 -0700619type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800620 // Putting the curiously recurring thing pointing to the thing that contains
621 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700622 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700623 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800624
Colin Crossfc754582016-05-17 16:34:16 -0700625 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800626 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700627 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800628 hostAndDeviceProperties hostAndDeviceProperties
629 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700630 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700631 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800632
Paul Duffin63c6e182019-07-24 14:24:38 +0100633 // Information about all the properties on the module that contains visibility rules that need
634 // checking.
635 visibilityPropertyInfo []visibilityProperty
636
637 // The primary visibility property, may be nil, that controls access to the module.
638 primaryVisibilityProperty visibilityProperty
639
Colin Cross3f40fa42015-01-30 17:27:36 -0800640 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700641 installFiles Paths
642 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900643 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700644
645 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
646 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800647 installTarget WritablePath
648 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700649 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700650
Colin Cross178a5092016-09-13 13:42:32 -0700651 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700652
653 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700654
655 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700656 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800657 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800658 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700659
660 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700661}
662
Colin Cross4157e882019-06-06 16:57:04 -0700663func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800664
Colin Cross4157e882019-06-06 16:57:04 -0700665func (m *ModuleBase) AddProperties(props ...interface{}) {
666 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700667}
668
Colin Cross4157e882019-06-06 16:57:04 -0700669func (m *ModuleBase) GetProperties() []interface{} {
670 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800671}
672
Colin Cross4157e882019-06-06 16:57:04 -0700673func (m *ModuleBase) BuildParamsForTests() []BuildParams {
674 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700675}
676
Colin Cross4157e882019-06-06 16:57:04 -0700677func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
678 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800679}
680
Colin Cross4157e882019-06-06 16:57:04 -0700681func (m *ModuleBase) VariablesForTests() map[string]string {
682 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800683}
684
Colin Cross4157e882019-06-06 16:57:04 -0700685func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
686 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700687}
688
Colin Crossce75d2c2016-10-06 16:12:58 -0700689// Name returns the name of the module. It may be overridden by individual module types, for
690// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700691func (m *ModuleBase) Name() string {
692 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700693}
694
Colin Cross9a362232019-07-01 15:32:45 -0700695// String returns a string that includes the module name and variants for printing during debugging.
696func (m *ModuleBase) String() string {
697 sb := strings.Builder{}
698 sb.WriteString(m.commonProperties.DebugName)
699 sb.WriteString("{")
700 for i := range m.commonProperties.DebugMutators {
701 if i != 0 {
702 sb.WriteString(",")
703 }
704 sb.WriteString(m.commonProperties.DebugMutators[i])
705 sb.WriteString(":")
706 sb.WriteString(m.commonProperties.DebugVariations[i])
707 }
708 sb.WriteString("}")
709 return sb.String()
710}
711
Colin Crossce75d2c2016-10-06 16:12:58 -0700712// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700713func (m *ModuleBase) BaseModuleName() string {
714 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700715}
716
Colin Cross4157e882019-06-06 16:57:04 -0700717func (m *ModuleBase) base() *ModuleBase {
718 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800719}
720
Paul Duffine2453c72019-05-31 14:00:04 +0100721func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
722 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
723}
724
725func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100726 return m.visibilityPropertyInfo
727}
728
729func (m *ModuleBase) visibility() []string {
730 // The soong_namespace module does not initialize the primaryVisibilityProperty.
731 if m.primaryVisibilityProperty != nil {
732 return m.primaryVisibilityProperty.getStrings()
733 } else {
734 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100735 }
736}
737
Colin Cross4157e882019-06-06 16:57:04 -0700738func (m *ModuleBase) Target() Target {
739 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800740}
741
Colin Cross4157e882019-06-06 16:57:04 -0700742func (m *ModuleBase) TargetPrimary() bool {
743 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700744}
745
Colin Cross4157e882019-06-06 16:57:04 -0700746func (m *ModuleBase) MultiTargets() []Target {
747 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700748}
749
Colin Cross4157e882019-06-06 16:57:04 -0700750func (m *ModuleBase) Os() OsType {
751 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800752}
753
Colin Cross4157e882019-06-06 16:57:04 -0700754func (m *ModuleBase) Host() bool {
755 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800756}
757
Colin Cross4157e882019-06-06 16:57:04 -0700758func (m *ModuleBase) Arch() Arch {
759 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800760}
761
Colin Cross4157e882019-06-06 16:57:04 -0700762func (m *ModuleBase) ArchSpecific() bool {
763 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700764}
765
Colin Cross4157e882019-06-06 16:57:04 -0700766func (m *ModuleBase) OsClassSupported() []OsClass {
767 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700768 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700769 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700770 case HostSupportedNoCross:
771 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700772 case DeviceSupported:
773 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700774 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700775 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700776 if Bool(m.hostAndDeviceProperties.Host_supported) ||
777 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
778 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700779 supported = append(supported, Host, HostCross)
780 }
Colin Cross4157e882019-06-06 16:57:04 -0700781 if m.hostAndDeviceProperties.Device_supported == nil ||
782 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700783 supported = append(supported, Device)
784 }
785 return supported
786 default:
787 return nil
788 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800789}
790
Colin Cross4157e882019-06-06 16:57:04 -0700791func (m *ModuleBase) DeviceSupported() bool {
792 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
793 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
794 (m.hostAndDeviceProperties.Device_supported == nil ||
795 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800796}
797
Paul Duffine44358f2019-11-26 18:04:12 +0000798func (m *ModuleBase) HostSupported() bool {
799 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
800 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
801 (m.hostAndDeviceProperties.Host_supported != nil &&
802 *m.hostAndDeviceProperties.Host_supported)
803}
804
Colin Cross4157e882019-06-06 16:57:04 -0700805func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900806 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900807}
808
Colin Cross4157e882019-06-06 16:57:04 -0700809func (m *ModuleBase) DeviceSpecific() bool {
810 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900811}
812
Colin Cross4157e882019-06-06 16:57:04 -0700813func (m *ModuleBase) SocSpecific() bool {
814 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900815}
816
Colin Cross4157e882019-06-06 16:57:04 -0700817func (m *ModuleBase) ProductSpecific() bool {
818 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900819}
820
Justin Yund5f6c822019-06-25 16:47:17 +0900821func (m *ModuleBase) SystemExtSpecific() bool {
822 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100823}
824
Colin Cross4157e882019-06-06 16:57:04 -0700825func (m *ModuleBase) Enabled() bool {
826 if m.commonProperties.Enabled == nil {
827 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800828 }
Colin Cross4157e882019-06-06 16:57:04 -0700829 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800830}
831
Colin Cross4157e882019-06-06 16:57:04 -0700832func (m *ModuleBase) SkipInstall() {
833 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700834}
835
Colin Cross4157e882019-06-06 16:57:04 -0700836func (m *ModuleBase) ExportedToMake() bool {
837 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900838}
839
Colin Cross4157e882019-06-06 16:57:04 -0700840func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700841 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800842
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700843 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700844 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800845 ctx.VisitDepsDepthFirstIf(isFileInstaller,
846 func(m blueprint.Module) {
847 fileInstaller := m.(fileInstaller)
848 files := fileInstaller.filesToInstall()
849 result = append(result, files...)
850 })
851
852 return result
853}
854
Colin Cross4157e882019-06-06 16:57:04 -0700855func (m *ModuleBase) filesToInstall() Paths {
856 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800857}
858
Colin Cross4157e882019-06-06 16:57:04 -0700859func (m *ModuleBase) NoAddressSanitizer() bool {
860 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800861}
862
Colin Cross4157e882019-06-06 16:57:04 -0700863func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800864 return false
865}
866
Jaewoong Jung0949f312019-09-11 10:25:18 -0700867func (m *ModuleBase) InstallInTestcases() bool {
868 return false
869}
870
Colin Cross4157e882019-06-06 16:57:04 -0700871func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700872 return false
873}
874
Colin Cross4157e882019-06-06 16:57:04 -0700875func (m *ModuleBase) InstallInRecovery() bool {
876 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900877}
878
Colin Cross90ba5f42019-10-02 11:10:58 -0700879func (m *ModuleBase) InstallInRoot() bool {
880 return false
881}
882
Colin Cross607d8582019-07-29 16:44:46 -0700883func (m *ModuleBase) InstallBypassMake() bool {
884 return false
885}
886
Colin Cross4157e882019-06-06 16:57:04 -0700887func (m *ModuleBase) Owner() string {
888 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900889}
890
Colin Cross4157e882019-06-06 16:57:04 -0700891func (m *ModuleBase) NoticeFile() OptionalPath {
892 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900893}
894
Colin Cross7228ecd2019-11-18 16:00:16 -0800895func (m *ModuleBase) setImageVariation(variant string) {
896 m.commonProperties.ImageVariation = variant
897}
898
899func (m *ModuleBase) ImageVariation() blueprint.Variation {
900 return blueprint.Variation{
901 Mutator: "image",
902 Variation: m.base().commonProperties.ImageVariation,
903 }
904}
905
906func (m *ModuleBase) InRecovery() bool {
907 return m.base().commonProperties.ImageVariation == RecoveryVariation
908}
909
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900910func (m *ModuleBase) RequiredModuleNames() []string {
911 return m.base().commonProperties.Required
912}
913
914func (m *ModuleBase) HostRequiredModuleNames() []string {
915 return m.base().commonProperties.Host_required
916}
917
918func (m *ModuleBase) TargetRequiredModuleNames() []string {
919 return m.base().commonProperties.Target_required
920}
921
Colin Cross4157e882019-06-06 16:57:04 -0700922func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700923 allInstalledFiles := Paths{}
924 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800925 ctx.VisitAllModuleVariants(func(module Module) {
926 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700927 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
928 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800929 })
930
Colin Cross0875c522017-11-28 17:34:01 -0800931 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700932
Jeff Gaston088e29e2017-11-29 16:47:17 -0800933 namespacePrefix := ctx.Namespace().(*Namespace).id
934 if namespacePrefix != "" {
935 namespacePrefix = namespacePrefix + "-"
936 }
937
Colin Cross3f40fa42015-01-30 17:27:36 -0800938 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800939 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800940 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700941 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800942 Output: name,
943 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800944 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700945 })
946 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700947 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700948 }
949
950 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800951 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800952 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700953 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800954 Output: name,
955 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700956 })
957 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700958 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700959 }
960
961 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800962 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800963 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800964 suffix = "-soong"
965 }
966
Jeff Gaston088e29e2017-11-29 16:47:17 -0800967 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800968 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700969 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800970 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700971 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800972 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700973
Colin Cross4157e882019-06-06 16:57:04 -0700974 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800975 }
976}
977
Colin Crossc34d2322020-01-03 15:23:27 -0800978func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -0700979 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
980 var deviceSpecific = Bool(m.commonProperties.Device_specific)
981 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +0900982 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900983
Dario Frenifd05a742018-05-29 13:28:54 +0100984 msg := "conflicting value set here"
985 if socSpecific && deviceSpecific {
986 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700987 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900988 ctx.PropertyErrorf("vendor", msg)
989 }
Colin Cross4157e882019-06-06 16:57:04 -0700990 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900991 ctx.PropertyErrorf("proprietary", msg)
992 }
Colin Cross4157e882019-06-06 16:57:04 -0700993 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900994 ctx.PropertyErrorf("soc_specific", msg)
995 }
996 }
997
Justin Yund5f6c822019-06-25 16:47:17 +0900998 if productSpecific && systemExtSpecific {
999 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1000 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001001 }
1002
Justin Yund5f6c822019-06-25 16:47:17 +09001003 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001004 if productSpecific {
1005 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1006 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001007 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 +01001008 }
1009 if deviceSpecific {
1010 ctx.PropertyErrorf("device_specific", msg)
1011 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001012 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001013 ctx.PropertyErrorf("vendor", msg)
1014 }
Colin Cross4157e882019-06-06 16:57:04 -07001015 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001016 ctx.PropertyErrorf("proprietary", msg)
1017 }
Colin Cross4157e882019-06-06 16:57:04 -07001018 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001019 ctx.PropertyErrorf("soc_specific", msg)
1020 }
1021 }
1022 }
1023
Jiyong Park2db76922017-11-08 16:03:48 +09001024 if productSpecific {
1025 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001026 } else if systemExtSpecific {
1027 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001028 } else if deviceSpecific {
1029 return deviceSpecificModule
1030 } else if socSpecific {
1031 return socSpecificModule
1032 } else {
1033 return platformModule
1034 }
1035}
1036
Colin Crossc34d2322020-01-03 15:23:27 -08001037func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001038 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001039 EarlyModuleContext: ctx,
1040 kind: determineModuleKind(m, ctx),
1041 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001042 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001043}
1044
Colin Cross1184b642019-12-30 18:43:07 -08001045func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1046 return baseModuleContext{
1047 bp: ctx,
1048 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1049 os: m.commonProperties.CompileOS,
1050 target: m.commonProperties.CompileTarget,
1051 targetPrimary: m.commonProperties.CompilePrimary,
1052 multiTargets: m.commonProperties.CompileMultiTargets,
1053 }
1054}
1055
Colin Cross4157e882019-06-06 16:57:04 -07001056func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001057 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001058 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001059 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001060 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1061 installDeps: m.computeInstallDeps(blueprintCtx),
1062 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001063 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001064 }
1065
Colin Cross6c4f21f2019-06-06 15:41:36 -07001066 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1067 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1068 // TODO: This will be removed once defaults modules handle missing dependency errors
1069 blueprintCtx.GetMissingDependencies()
1070
Colin Crossdc35e212019-06-06 16:13:11 -07001071 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
1072 // are enabled.
1073 ctx.baseModuleContext.strictVisitDeps = true
1074
Colin Cross4c83e5c2019-02-25 14:54:28 -08001075 if ctx.config.captureBuild {
1076 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1077 }
1078
Colin Cross67a5c132017-05-09 13:45:28 -07001079 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1080 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001081 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1082 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001083 }
Colin Cross0875c522017-11-28 17:34:01 -08001084 if !ctx.PrimaryArch() {
1085 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001086 }
1087
1088 ctx.Variable(pctx, "moduleDesc", desc)
1089
1090 s := ""
1091 if len(suffix) > 0 {
1092 s = " [" + strings.Join(suffix, " ") + "]"
1093 }
1094 ctx.Variable(pctx, "moduleDescSuffix", s)
1095
Dan Willemsen569edc52018-11-19 09:33:29 -08001096 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001097 if m.commonProperties.Dist.Dest != nil {
1098 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001099 if err != nil {
1100 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1101 }
1102 }
Colin Cross4157e882019-06-06 16:57:04 -07001103 if m.commonProperties.Dist.Dir != nil {
1104 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001105 if err != nil {
1106 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1107 }
1108 }
Colin Cross4157e882019-06-06 16:57:04 -07001109 if m.commonProperties.Dist.Suffix != nil {
1110 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001111 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1112 }
1113 }
1114
Colin Cross4157e882019-06-06 16:57:04 -07001115 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001116 // ensure all direct android.Module deps are enabled
1117 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1118 if _, ok := bm.(Module); ok {
1119 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1120 }
1121 })
1122
Colin Cross4157e882019-06-06 16:57:04 -07001123 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1124 if module := SrcIsModule(notice); module != "" {
1125 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001126 } else {
1127 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001128 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001129 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001130
1131 m.module.GenerateAndroidBuildActions(ctx)
1132 if ctx.Failed() {
1133 return
1134 }
1135
1136 m.installFiles = append(m.installFiles, ctx.installFiles...)
1137 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001138 } else if ctx.Config().AllowMissingDependencies() {
1139 // If the module is not enabled it will not create any build rules, nothing will call
1140 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1141 // and report them as an error even when AllowMissingDependencies = true. Call
1142 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1143 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001144 }
1145
Colin Cross4157e882019-06-06 16:57:04 -07001146 if m == ctx.FinalModule().(Module).base() {
1147 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001148 if ctx.Failed() {
1149 return
1150 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001151 }
Colin Crosscec81712017-07-13 14:43:27 -07001152
Colin Cross4157e882019-06-06 16:57:04 -07001153 m.buildParams = ctx.buildParams
1154 m.ruleParams = ctx.ruleParams
1155 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001156}
1157
Colin Cross1184b642019-12-30 18:43:07 -08001158type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001159 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001160
1161 kind moduleKind
1162 config Config
1163}
1164
1165func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1166 ret, err := e.GlobWithDeps(globPattern, excludes)
1167 if err != nil {
1168 e.ModuleErrorf("glob: %s", err.Error())
1169 }
1170 return pathsForModuleSrcFromFullPath(e, ret, true)
1171}
1172
1173func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1174 ret, err := e.GlobWithDeps(globPattern, excludes)
1175 if err != nil {
1176 e.ModuleErrorf("glob: %s", err.Error())
1177 }
1178 return pathsForModuleSrcFromFullPath(e, ret, false)
1179}
1180
Colin Cross988414c2020-01-11 01:11:46 +00001181func (b *earlyModuleContext) IsSymlink(path Path) bool {
1182 fileInfo, err := b.config.fs.Lstat(path.String())
1183 if err != nil {
1184 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1185 }
1186 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1187}
1188
1189func (b *earlyModuleContext) Readlink(path Path) string {
1190 dest, err := b.config.fs.Readlink(path.String())
1191 if err != nil {
1192 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1193 }
1194 return dest
1195}
1196
Colin Cross1184b642019-12-30 18:43:07 -08001197func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001198 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001199 return module
1200}
1201
1202func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001203 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001204}
1205
1206func (e *earlyModuleContext) AConfig() Config {
1207 return e.config
1208}
1209
1210func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1211 return DeviceConfig{e.config.deviceConfig}
1212}
1213
1214func (e *earlyModuleContext) Platform() bool {
1215 return e.kind == platformModule
1216}
1217
1218func (e *earlyModuleContext) DeviceSpecific() bool {
1219 return e.kind == deviceSpecificModule
1220}
1221
1222func (e *earlyModuleContext) SocSpecific() bool {
1223 return e.kind == socSpecificModule
1224}
1225
1226func (e *earlyModuleContext) ProductSpecific() bool {
1227 return e.kind == productSpecificModule
1228}
1229
1230func (e *earlyModuleContext) SystemExtSpecific() bool {
1231 return e.kind == systemExtSpecificModule
1232}
1233
1234type baseModuleContext struct {
1235 bp blueprint.BaseModuleContext
1236 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001237 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001238 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001239 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001240 targetPrimary bool
1241 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001242
1243 walkPath []Module
1244
1245 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001246}
1247
Colin Cross1184b642019-12-30 18:43:07 -08001248func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { return b.bp.OtherModuleName(m) }
1249func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
1250func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
1251 b.bp.OtherModuleErrorf(m, fmt, args)
1252}
1253func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1254 return b.bp.OtherModuleDependencyTag(m)
1255}
1256func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
1257func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { return b.bp.OtherModuleType(m) }
1258
1259func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1260 return b.bp.GetDirectDepWithTag(name, tag)
1261}
1262
Colin Cross25de6c32019-06-06 14:29:25 -07001263type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001264 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001265 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001266 installDeps Paths
1267 installFiles Paths
1268 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001269 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001270
1271 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001272 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001273 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001274 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001275}
1276
Colin Crossb88b3c52019-06-10 15:15:17 -07001277func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1278 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001279 Rule: ErrorRule,
1280 Description: params.Description,
1281 Output: params.Output,
1282 Outputs: params.Outputs,
1283 ImplicitOutput: params.ImplicitOutput,
1284 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001285 Args: map[string]string{
1286 "error": err.Error(),
1287 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001288 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001289}
1290
Colin Cross25de6c32019-06-06 14:29:25 -07001291func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1292 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001293}
1294
Colin Cross0875c522017-11-28 17:34:01 -08001295func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001296 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001297 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001298 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001299 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001300 Outputs: params.Outputs.Strings(),
1301 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1302 Inputs: params.Inputs.Strings(),
1303 Implicits: params.Implicits.Strings(),
1304 OrderOnly: params.OrderOnly.Strings(),
1305 Args: params.Args,
1306 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001307 }
1308
Colin Cross33bfb0a2016-11-21 17:23:08 -08001309 if params.Depfile != nil {
1310 bparams.Depfile = params.Depfile.String()
1311 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001312 if params.Output != nil {
1313 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1314 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001315 if params.ImplicitOutput != nil {
1316 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1317 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001318 if params.Input != nil {
1319 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1320 }
1321 if params.Implicit != nil {
1322 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1323 }
1324
Colin Cross0b9f31f2019-02-28 11:00:01 -08001325 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1326 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1327 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1328 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1329 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1330 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001331
Colin Cross0875c522017-11-28 17:34:01 -08001332 return bparams
1333}
1334
Colin Cross25de6c32019-06-06 14:29:25 -07001335func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1336 if m.config.captureBuild {
1337 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001338 }
1339
Colin Crossdc35e212019-06-06 16:13:11 -07001340 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001341}
1342
Colin Cross25de6c32019-06-06 14:29:25 -07001343func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001344 argNames ...string) blueprint.Rule {
1345
Ramy Medhatdd0418a2019-11-04 18:16:11 -05001346 if (m.config.UseGoma() || m.config.UseRBE()) && params.Pool == nil {
1347 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1348 // jobs to the local parallelism value
Colin Cross2e2dbc22019-09-25 13:31:46 -07001349 params.Pool = localPool
1350 }
1351
Colin Crossdc35e212019-06-06 16:13:11 -07001352 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001353
Colin Cross25de6c32019-06-06 14:29:25 -07001354 if m.config.captureBuild {
1355 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001356 }
1357
1358 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001359}
1360
Colin Cross25de6c32019-06-06 14:29:25 -07001361func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001362 if params.Description != "" {
1363 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1364 }
1365
1366 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1367 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1368 m.ModuleName(), strings.Join(missingDeps, ", ")))
1369 }
1370
Colin Cross25de6c32019-06-06 14:29:25 -07001371 if m.config.captureBuild {
1372 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001373 }
1374
Colin Crossdc35e212019-06-06 16:13:11 -07001375 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001376}
Colin Cross25de6c32019-06-06 14:29:25 -07001377func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001378 var missingDeps []string
1379 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001380 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001381 missingDeps = FirstUniqueStrings(missingDeps)
1382 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001383}
1384
Colin Crossdc35e212019-06-06 16:13:11 -07001385func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001386 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001387 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001388 *missingDeps = append(*missingDeps, deps...)
1389 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001390 }
1391}
1392
Colin Crossdc35e212019-06-06 16:13:11 -07001393func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001394 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001395
1396 if !strict {
1397 return aModule
1398 }
1399
Colin Cross380c69a2019-06-10 17:49:58 +00001400 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001401 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001402 return nil
1403 }
1404
1405 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001406 if b.Config().AllowMissingDependencies() {
1407 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001408 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001409 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001410 }
1411 return nil
1412 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001413 return aModule
1414}
1415
Colin Crossdc35e212019-06-06 16:13:11 -07001416func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001417 type dep struct {
1418 mod blueprint.Module
1419 tag blueprint.DependencyTag
1420 }
1421 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001422 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001423 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001424 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001425 if tag == nil || returnedTag == tag {
1426 deps = append(deps, dep{aModule, returnedTag})
1427 }
1428 }
1429 })
1430 if len(deps) == 1 {
1431 return deps[0].mod, deps[0].tag
1432 } else if len(deps) >= 2 {
1433 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001434 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001435 } else {
1436 return nil, nil
1437 }
1438}
1439
Colin Crossdc35e212019-06-06 16:13:11 -07001440func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001441 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001442 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001443 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001444 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001445 deps = append(deps, aModule)
1446 }
1447 }
1448 })
1449 return deps
1450}
1451
Colin Cross25de6c32019-06-06 14:29:25 -07001452func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1453 module, _ := m.getDirectDepInternal(name, tag)
1454 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001455}
1456
Colin Crossdc35e212019-06-06 16:13:11 -07001457func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1458 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001459}
1460
Colin Crossdc35e212019-06-06 16:13:11 -07001461func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001462 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001463}
1464
Colin Crossdc35e212019-06-06 16:13:11 -07001465func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001466 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001467 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001468 visit(aModule)
1469 }
1470 })
1471}
1472
Colin Crossdc35e212019-06-06 16:13:11 -07001473func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001474 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001475 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001476 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001477 visit(aModule)
1478 }
1479 }
1480 })
1481}
1482
Colin Crossdc35e212019-06-06 16:13:11 -07001483func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001484 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001485 // pred
1486 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001487 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001488 return pred(aModule)
1489 } else {
1490 return false
1491 }
1492 },
1493 // visit
1494 func(module blueprint.Module) {
1495 visit(module.(Module))
1496 })
1497}
1498
Colin Crossdc35e212019-06-06 16:13:11 -07001499func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001500 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001501 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001502 visit(aModule)
1503 }
1504 })
1505}
1506
Colin Crossdc35e212019-06-06 16:13:11 -07001507func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001508 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001509 // pred
1510 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001511 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001512 return pred(aModule)
1513 } else {
1514 return false
1515 }
1516 },
1517 // visit
1518 func(module blueprint.Module) {
1519 visit(module.(Module))
1520 })
1521}
1522
Colin Crossdc35e212019-06-06 16:13:11 -07001523func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001524 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001525}
1526
Colin Crossdc35e212019-06-06 16:13:11 -07001527func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1528 b.walkPath = []Module{b.Module()}
Colin Cross1184b642019-12-30 18:43:07 -08001529 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001530 childAndroidModule, _ := child.(Module)
1531 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001532 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001533 // record walkPath before visit
1534 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1535 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1536 }
1537 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001538 return visit(childAndroidModule, parentAndroidModule)
1539 } else {
1540 return false
1541 }
1542 })
1543}
1544
Colin Crossdc35e212019-06-06 16:13:11 -07001545func (b *baseModuleContext) GetWalkPath() []Module {
1546 return b.walkPath
1547}
1548
Colin Cross25de6c32019-06-06 14:29:25 -07001549func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001550 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001551 visit(module.(Module))
1552 })
1553}
1554
Colin Cross25de6c32019-06-06 14:29:25 -07001555func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001556 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001557}
1558
Colin Cross25de6c32019-06-06 14:29:25 -07001559func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001560 return m.bp.FinalModule().(Module)
1561}
1562
1563func (m *moduleContext) ModuleSubDir() string {
1564 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001565}
1566
Colin Cross0ea8ba82019-06-06 14:33:29 -07001567func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001568 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001569}
1570
Colin Cross0ea8ba82019-06-06 14:33:29 -07001571func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001572 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001573}
1574
Colin Cross0ea8ba82019-06-06 14:33:29 -07001575func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001576 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001577}
1578
Colin Cross0ea8ba82019-06-06 14:33:29 -07001579func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001580 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001581}
1582
Colin Cross0ea8ba82019-06-06 14:33:29 -07001583func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001584 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001585}
1586
Colin Cross0ea8ba82019-06-06 14:33:29 -07001587func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001588 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001589}
1590
Colin Cross0ea8ba82019-06-06 14:33:29 -07001591func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001592 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001593}
1594
Colin Cross0ea8ba82019-06-06 14:33:29 -07001595func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001596 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001597}
1598
Colin Cross0ea8ba82019-06-06 14:33:29 -07001599func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001600 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001601}
1602
Colin Cross0ea8ba82019-06-06 14:33:29 -07001603func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001604 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001605}
1606
Colin Cross0ea8ba82019-06-06 14:33:29 -07001607func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001608 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001609}
1610
Colin Cross0ea8ba82019-06-06 14:33:29 -07001611func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001612 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001613 return true
1614 }
Colin Cross25de6c32019-06-06 14:29:25 -07001615 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001616}
1617
Jiyong Park5baac542018-08-28 09:55:37 +09001618// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001619// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001620func (m *ModuleBase) MakeAsPlatform() {
1621 m.commonProperties.Vendor = boolPtr(false)
1622 m.commonProperties.Proprietary = boolPtr(false)
1623 m.commonProperties.Soc_specific = boolPtr(false)
1624 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001625 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001626}
1627
Colin Cross4157e882019-06-06 16:57:04 -07001628func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1629 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001630}
1631
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001632func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001633 m.commonProperties.Vendor = boolPtr(false)
1634 m.commonProperties.Proprietary = boolPtr(false)
1635 m.commonProperties.Soc_specific = boolPtr(false)
1636 m.commonProperties.Product_specific = boolPtr(false)
1637 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001638}
1639
Jooyung Han344d5432019-08-23 11:17:39 +09001640// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1641func (m *ModuleBase) IsNativeBridgeSupported() bool {
1642 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1643}
1644
Colin Cross25de6c32019-06-06 14:29:25 -07001645func (m *moduleContext) InstallInData() bool {
1646 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001647}
1648
Jaewoong Jung0949f312019-09-11 10:25:18 -07001649func (m *moduleContext) InstallInTestcases() bool {
1650 return m.module.InstallInTestcases()
1651}
1652
Colin Cross25de6c32019-06-06 14:29:25 -07001653func (m *moduleContext) InstallInSanitizerDir() bool {
1654 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001655}
1656
Colin Cross25de6c32019-06-06 14:29:25 -07001657func (m *moduleContext) InstallInRecovery() bool {
1658 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001659}
1660
Colin Cross90ba5f42019-10-02 11:10:58 -07001661func (m *moduleContext) InstallInRoot() bool {
1662 return m.module.InstallInRoot()
1663}
1664
Colin Cross607d8582019-07-29 16:44:46 -07001665func (m *moduleContext) InstallBypassMake() bool {
1666 return m.module.InstallBypassMake()
1667}
1668
Colin Cross70dda7e2019-10-01 22:05:35 -07001669func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001670 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001671 return true
1672 }
1673
Colin Cross3607f212018-05-07 15:28:05 -07001674 // We'll need a solution for choosing which of modules with the same name in different
1675 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1676 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001677 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001678 return true
1679 }
1680
Colin Cross25de6c32019-06-06 14:29:25 -07001681 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001682 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001683 return true
1684 }
1685
Colin Cross25de6c32019-06-06 14:29:25 -07001686 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001687 return true
1688 }
1689 }
1690
1691 return false
1692}
1693
Colin Cross70dda7e2019-10-01 22:05:35 -07001694func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
1695 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001696 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001697}
1698
Colin Cross70dda7e2019-10-01 22:05:35 -07001699func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
1700 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001701 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001702}
1703
Colin Cross70dda7e2019-10-01 22:05:35 -07001704func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
1705 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07001706
Colin Cross25de6c32019-06-06 14:29:25 -07001707 fullInstallPath := installPath.Join(m, name)
1708 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001709
Colin Cross25de6c32019-06-06 14:29:25 -07001710 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001711
Colin Cross25de6c32019-06-06 14:29:25 -07001712 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001713
Colin Cross89562dc2016-10-03 17:47:19 -07001714 var implicitDeps, orderOnlyDeps Paths
1715
Colin Cross25de6c32019-06-06 14:29:25 -07001716 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001717 // Installed host modules might be used during the build, depend directly on their
1718 // dependencies so their timestamp is updated whenever their dependency is updated
1719 implicitDeps = deps
1720 } else {
1721 orderOnlyDeps = deps
1722 }
1723
Colin Cross25de6c32019-06-06 14:29:25 -07001724 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001725 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001726 Description: "install " + fullInstallPath.Base(),
1727 Output: fullInstallPath,
1728 Input: srcPath,
1729 Implicits: implicitDeps,
1730 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001731 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001732 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001733
Colin Cross25de6c32019-06-06 14:29:25 -07001734 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001735 }
Colin Cross25de6c32019-06-06 14:29:25 -07001736 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001737 return fullInstallPath
1738}
1739
Colin Cross70dda7e2019-10-01 22:05:35 -07001740func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001741 fullInstallPath := installPath.Join(m, name)
1742 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001743
Colin Cross25de6c32019-06-06 14:29:25 -07001744 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001745
Alex Lightfb4353d2019-01-17 13:57:45 -08001746 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1747 if err != nil {
1748 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1749 }
Colin Cross25de6c32019-06-06 14:29:25 -07001750 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001751 Rule: Symlink,
1752 Description: "install symlink " + fullInstallPath.Base(),
1753 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08001754 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001755 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001756 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001757 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001758 },
1759 })
Colin Cross3854a602016-01-11 12:49:11 -08001760
Colin Cross25de6c32019-06-06 14:29:25 -07001761 m.installFiles = append(m.installFiles, fullInstallPath)
1762 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001763 }
Colin Cross3854a602016-01-11 12:49:11 -08001764 return fullInstallPath
1765}
1766
Jiyong Parkf1194352019-02-25 11:05:47 +09001767// installPath/name -> absPath where absPath might be a path that is available only at runtime
1768// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07001769func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001770 fullInstallPath := installPath.Join(m, name)
1771 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001772
Colin Cross25de6c32019-06-06 14:29:25 -07001773 if !m.skipInstall(fullInstallPath) {
1774 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001775 Rule: Symlink,
1776 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1777 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001778 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001779 Args: map[string]string{
1780 "fromPath": absPath,
1781 },
1782 })
1783
Colin Cross25de6c32019-06-06 14:29:25 -07001784 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001785 }
1786 return fullInstallPath
1787}
1788
Colin Cross25de6c32019-06-06 14:29:25 -07001789func (m *moduleContext) CheckbuildFile(srcPath Path) {
1790 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001791}
1792
Colin Cross3f40fa42015-01-30 17:27:36 -08001793type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001794 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001795}
1796
1797func isFileInstaller(m blueprint.Module) bool {
1798 _, ok := m.(fileInstaller)
1799 return ok
1800}
1801
1802func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001803 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001804 return ok
1805}
Colin Crossfce53272015-04-08 11:21:40 -07001806
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001807func findStringInSlice(str string, slice []string) int {
1808 for i, s := range slice {
1809 if s == str {
1810 return i
Colin Crossfce53272015-04-08 11:21:40 -07001811 }
1812 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001813 return -1
1814}
1815
Colin Cross41955e82019-05-29 14:40:35 -07001816// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1817// was not a module reference.
1818func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001819 if len(s) > 1 && s[0] == ':' {
1820 return s[1:]
1821 }
1822 return ""
1823}
1824
Colin Cross41955e82019-05-29 14:40:35 -07001825// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1826// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1827func SrcIsModuleWithTag(s string) (module, tag string) {
1828 if len(s) > 1 && s[0] == ':' {
1829 module = s[1:]
1830 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1831 if module[len(module)-1] == '}' {
1832 tag = module[tagStart+1 : len(module)-1]
1833 module = module[:tagStart]
1834 return module, tag
1835 }
1836 }
1837 return module, ""
1838 }
1839 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001840}
1841
Colin Cross41955e82019-05-29 14:40:35 -07001842type sourceOrOutputDependencyTag struct {
1843 blueprint.BaseDependencyTag
1844 tag string
1845}
1846
1847func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1848 return sourceOrOutputDependencyTag{tag: tag}
1849}
1850
1851var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001852
Colin Cross366938f2017-12-11 16:29:02 -08001853// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1854// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001855//
1856// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001857func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001858 set := make(map[string]bool)
1859
Colin Cross068e0fe2016-12-13 15:23:47 -08001860 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001861 if m, t := SrcIsModuleWithTag(s); m != "" {
1862 if _, found := set[s]; found {
1863 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001864 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001865 set[s] = true
1866 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001867 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001868 }
1869 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001870}
1871
Colin Cross366938f2017-12-11 16:29:02 -08001872// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1873// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001874//
1875// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001876func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1877 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001878 if m, t := SrcIsModuleWithTag(*s); m != "" {
1879 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001880 }
1881 }
1882}
1883
Colin Cross41955e82019-05-29 14:40:35 -07001884// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1885// 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 -08001886type SourceFileProducer interface {
1887 Srcs() Paths
1888}
1889
Colin Cross41955e82019-05-29 14:40:35 -07001890// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00001891// 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 -07001892// listed in the property.
1893type OutputFileProducer interface {
1894 OutputFiles(tag string) (Paths, error)
1895}
1896
Colin Cross5e708052019-08-06 13:59:50 -07001897// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
1898// module produced zero paths, it reports errors to the ctx and returns nil.
1899func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
1900 paths, err := outputFilesForModule(ctx, module, tag)
1901 if err != nil {
1902 reportPathError(ctx, err)
1903 return nil
1904 }
1905 return paths
1906}
1907
1908// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
1909// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
1910func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
1911 paths, err := outputFilesForModule(ctx, module, tag)
1912 if err != nil {
1913 reportPathError(ctx, err)
1914 return nil
1915 }
1916 if len(paths) > 1 {
1917 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
1918 pathContextName(ctx, module))
1919 return nil
1920 }
1921 return paths[0]
1922}
1923
1924func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
1925 if outputFileProducer, ok := module.(OutputFileProducer); ok {
1926 paths, err := outputFileProducer.OutputFiles(tag)
1927 if err != nil {
1928 return nil, fmt.Errorf("failed to get output file from module %q: %s",
1929 pathContextName(ctx, module), err.Error())
1930 }
1931 if len(paths) == 0 {
1932 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
1933 }
1934 return paths, nil
1935 } else {
1936 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
1937 }
1938}
1939
Colin Crossfe17f6f2019-03-28 19:30:56 -07001940type HostToolProvider interface {
1941 HostToolPath() OptionalPath
1942}
1943
Colin Cross27b922f2019-03-04 22:35:41 -08001944// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1945// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001946//
1947// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001948func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1949 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001950}
1951
Colin Cross2fafa3e2019-03-05 12:39:51 -08001952// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1953// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001954//
1955// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001956func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1957 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001958}
1959
1960// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1961// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1962// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001963func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001964 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001965 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001966 }
1967 return OptionalPath{}
1968}
1969
Colin Cross25de6c32019-06-06 14:29:25 -07001970func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001971 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08001972}
1973
Colin Cross25de6c32019-06-06 14:29:25 -07001974func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001975 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07001976}
1977
Colin Cross25de6c32019-06-06 14:29:25 -07001978func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001979 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07001980}
1981
Colin Cross463a90e2015-06-17 14:20:06 -07001982func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001983 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001984}
1985
Colin Cross0875c522017-11-28 17:34:01 -08001986func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001987 return &buildTargetSingleton{}
1988}
1989
Colin Cross87d8b562017-04-25 10:01:55 -07001990func parentDir(dir string) string {
1991 dir, _ = filepath.Split(dir)
1992 return filepath.Clean(dir)
1993}
1994
Colin Cross1f8c52b2015-06-16 16:38:17 -07001995type buildTargetSingleton struct{}
1996
Colin Cross0875c522017-11-28 17:34:01 -08001997func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1998 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001999
Colin Cross0875c522017-11-28 17:34:01 -08002000 mmTarget := func(dir string) WritablePath {
2001 return PathForPhony(ctx,
2002 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07002003 }
2004
Colin Cross0875c522017-11-28 17:34:01 -08002005 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002006
Colin Cross0875c522017-11-28 17:34:01 -08002007 ctx.VisitAllModules(func(module Module) {
2008 blueprintDir := module.base().blueprintDir
2009 installTarget := module.base().installTarget
2010 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002011
Colin Cross0875c522017-11-28 17:34:01 -08002012 if checkbuildTarget != nil {
2013 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2014 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2015 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002016
Colin Cross0875c522017-11-28 17:34:01 -08002017 if installTarget != nil {
2018 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002019 }
2020 })
2021
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002022 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002023 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002024 suffix = "-soong"
2025 }
2026
Colin Cross1f8c52b2015-06-16 16:38:17 -07002027 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08002028 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002029 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002030 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002031 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07002032 })
2033
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002034 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002035 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002036 return
2037 }
2038
Colin Cross87d8b562017-04-25 10:01:55 -07002039 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002040 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002041 for _, dir := range dirs {
2042 dir := parentDir(dir)
2043 for dir != "." && dir != "/" {
2044 if _, exists := modulesInDir[dir]; exists {
2045 break
2046 }
2047 modulesInDir[dir] = nil
2048 dir = parentDir(dir)
2049 }
2050 }
2051
2052 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002053 for _, dir := range dirs {
2054 p := parentDir(dir)
2055 if p != "." && p != "/" {
2056 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
2057 }
2058 }
2059
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002060 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2061 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2062 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002063 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08002064 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07002065 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002066 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07002067 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002068 // HACK: checkbuild should be an optional build, but force it
2069 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08002070 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07002071 })
2072 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002073
2074 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2075 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002076 ctx.VisitAllModules(func(module Module) {
2077 if module.Enabled() {
2078 os := module.Target().Os
2079 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002080 }
2081 })
2082
Colin Cross0875c522017-11-28 17:34:01 -08002083 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002084 for os, deps := range osDeps {
2085 var className string
2086
2087 switch os.Class {
2088 case Host:
2089 className = "host"
2090 case HostCross:
2091 className = "host-cross"
2092 case Device:
2093 className = "target"
2094 default:
2095 continue
2096 }
2097
Colin Cross0875c522017-11-28 17:34:01 -08002098 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002099 osClass[className] = append(osClass[className], name)
2100
Colin Cross0875c522017-11-28 17:34:01 -08002101 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002102 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002103 Output: name,
2104 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07002105 })
2106 }
2107
2108 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002109 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08002110 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07002111 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08002112 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07002113 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07002114 })
2115 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002116}
Colin Crossd779da42015-12-17 18:00:23 -08002117
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002118// Collect information for opening IDE project files in java/jdeps.go.
2119type IDEInfo interface {
2120 IDEInfo(ideInfo *IdeInfo)
2121 BaseModuleName() string
2122}
2123
2124// Extract the base module name from the Import name.
2125// Often the Import name has a prefix "prebuilt_".
2126// Remove the prefix explicitly if needed
2127// until we find a better solution to get the Import name.
2128type IDECustomizedModuleName interface {
2129 IDECustomizedModuleName() string
2130}
2131
2132type IdeInfo struct {
2133 Deps []string `json:"dependencies,omitempty"`
2134 Srcs []string `json:"srcs,omitempty"`
2135 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2136 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2137 Jars []string `json:"jars,omitempty"`
2138 Classes []string `json:"class,omitempty"`
2139 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002140 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002141}