blob: adb9454e03b3dd0b117060757e153fe29559009a [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Alex Lightfb4353d2019-01-17 13:57:45 -080019 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "path/filepath"
Colin Cross6ff51382015-12-17 16:39:19 -080021 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080022 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070023
24 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070025 "github.com/google/blueprint/pathtools"
Colin Crossfe4bc362018-09-12 10:02:13 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
29var (
30 DeviceSharedLibrary = "shared_library"
31 DeviceStaticLibrary = "static_library"
32 DeviceExecutable = "executable"
33 HostSharedLibrary = "host_shared_library"
34 HostStaticLibrary = "host_static_library"
35 HostExecutable = "host_executable"
36)
37
Colin Crossae887032017-10-23 17:16:14 -070038type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080040 Deps blueprint.Deps
41 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070043 Output WritablePath
44 Outputs WritablePaths
45 ImplicitOutput WritablePath
46 ImplicitOutputs WritablePaths
47 Input Path
48 Inputs Paths
49 Implicit Path
50 Implicits Paths
51 OrderOnly Paths
52 Default bool
53 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054}
55
Colin Crossae887032017-10-23 17:16:14 -070056type ModuleBuildParams BuildParams
57
Colin Cross0ea8ba82019-06-06 14:33:29 -070058// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -070059// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
60// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -070061// about the current module.
62type BaseModuleContext interface {
Colin Crossdc35e212019-06-06 16:13:11 -070063 Module() Module
Colin Cross0ea8ba82019-06-06 14:33:29 -070064 ModuleName() string
65 ModuleDir() string
66 ModuleType() string
67 Config() Config
68
Colin Crossdc35e212019-06-06 16:13:11 -070069 OtherModuleName(m blueprint.Module) string
70 OtherModuleDir(m blueprint.Module) string
71 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
72 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
73 OtherModuleExists(name string) bool
74
75 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
76 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
77 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
78
79 VisitDirectDepsBlueprint(visit func(blueprint.Module))
80 VisitDirectDeps(visit func(Module))
81 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
82 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
83 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
84 VisitDepsDepthFirst(visit func(Module))
85 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
86 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
87 WalkDeps(visit func(Module, Module) bool)
88 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
89 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
90 // and returns a top-down dependency path from a start module to current child module.
91 GetWalkPath() []Module
92
Colin Cross0ea8ba82019-06-06 14:33:29 -070093 ContainsProperty(name string) bool
94 Errorf(pos scanner.Position, fmt string, args ...interface{})
95 ModuleErrorf(fmt string, args ...interface{})
96 PropertyErrorf(property, fmt string, args ...interface{})
97 Failed() bool
98
99 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
100 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
101 // builder whenever a file matching the pattern as added or removed, without rerunning if a
102 // file that does not match the pattern is added to a searched directory.
103 GlobWithDeps(pattern string, excludes []string) ([]string, error)
104
Colin Crossdc35e212019-06-06 16:13:11 -0700105 Glob(globPattern string, excludes []string) Paths
106 GlobFiles(globPattern string, excludes []string) Paths
107
Colin Cross0ea8ba82019-06-06 14:33:29 -0700108 Fs() pathtools.FileSystem
109 AddNinjaFileDeps(deps ...string)
110
Colin Crossdc35e212019-06-06 16:13:11 -0700111 AddMissingDependencies(missingDeps []string)
112
Colin Crossa1ad8d12016-06-01 17:09:44 -0700113 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700114 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -0700115 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700116 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700117 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700118 Host() bool
119 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700120 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800121 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700122 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700123 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700124 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +0900125 Platform() bool
126 DeviceSpecific() bool
127 SocSpecific() bool
128 ProductSpecific() bool
Justin Yund5f6c822019-06-25 16:47:17 +0900129 SystemExtSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -0700130 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -0700131 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -0700132}
133
Colin Cross0ea8ba82019-06-06 14:33:29 -0700134// Deprecated: use BaseModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700135type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800136 BaseModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800137}
138
Colin Cross635c3b02016-05-18 15:37:25 -0700139type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800140 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800141
Colin Crossae887032017-10-23 17:16:14 -0700142 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800143 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700144
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700145 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800146 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800147 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700148
Colin Cross5c517922017-08-31 12:29:17 -0700149 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
150 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800151 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900152 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700153 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800154
Colin Cross8d8f8e22016-08-03 11:57:50 -0700155 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700156 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900157 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800158
159 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700160 HostRequiredModuleNames() []string
161 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700162
Colin Cross3f68a132017-10-23 17:10:29 -0700163 ModuleSubDir() string
164
Colin Cross0875c522017-11-28 17:34:01 -0800165 Variable(pctx PackageContext, name, value string)
166 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700167 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
168 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800169 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700170
Colin Cross0875c522017-11-28 17:34:01 -0800171 PrimaryModule() Module
172 FinalModule() Module
173 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700174
175 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800176 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800177}
178
Colin Cross635c3b02016-05-18 15:37:25 -0700179type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800180 blueprint.Module
181
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700182 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
183 // but GenerateAndroidBuildActions also has access to Android-specific information.
184 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700185 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700186
Colin Cross1e676be2016-10-12 14:38:15 -0700187 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800188
Colin Cross635c3b02016-05-18 15:37:25 -0700189 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800190 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700191 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800192 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700193 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900194 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800195 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900196 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900197 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700198
199 AddProperties(props ...interface{})
200 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700201
Colin Crossae887032017-10-23 17:16:14 -0700202 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800203 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800204 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100205
Colin Cross9a362232019-07-01 15:32:45 -0700206 // String returns a string that includes the module name and variants for printing during debugging.
207 String() string
208
Paul Duffine2453c72019-05-31 14:00:04 +0100209 // Get the qualified module id for this module.
210 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
211
212 // Get information about the properties that can contain visibility rules.
213 visibilityProperties() []visibilityProperty
214}
215
216// Qualified id for a module
217type qualifiedModuleName struct {
218 // The package (i.e. directory) in which the module is defined, without trailing /
219 pkg string
220
221 // The name of the module, empty string if package.
222 name string
223}
224
225func (q qualifiedModuleName) String() string {
226 if q.name == "" {
227 return "//" + q.pkg
228 }
229 return "//" + q.pkg + ":" + q.name
230}
231
Paul Duffine484f472019-06-20 16:38:08 +0100232func (q qualifiedModuleName) isRootPackage() bool {
233 return q.pkg == "" && q.name == ""
234}
235
Paul Duffine2453c72019-05-31 14:00:04 +0100236// Get the id for the package containing this module.
237func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
238 pkg := q.pkg
239 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100240 if pkg == "" {
241 panic(fmt.Errorf("Cannot get containing package id of root package"))
242 }
243
244 index := strings.LastIndex(pkg, "/")
245 if index == -1 {
246 pkg = ""
247 } else {
248 pkg = pkg[:index]
249 }
Paul Duffine2453c72019-05-31 14:00:04 +0100250 }
251 return newPackageId(pkg)
252}
253
254func newPackageId(pkg string) qualifiedModuleName {
255 // A qualified id for a package module has no name.
256 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800257}
258
Colin Crossfc754582016-05-17 16:34:16 -0700259type nameProperties struct {
260 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800261 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700262}
263
264type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800265 // emit build rules for this module
266 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800267
Paul Duffin2e61fa62019-03-28 14:10:57 +0000268 // Controls the visibility of this module to other modules. Allowable values are one or more of
269 // these formats:
270 //
271 // ["//visibility:public"]: Anyone can use this module.
272 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
273 // this module.
274 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
275 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
276 // this module. Note that sub-packages do not have access to the rule; for example,
277 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
278 // is a special module and must be used verbatim. It represents all of the modules in the
279 // package.
280 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
281 // or other or in one of their sub-packages have access to this module. For example,
282 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
283 // to depend on this rule (but not //independent:evil)
284 // ["//project"]: This is shorthand for ["//project:__pkg__"]
285 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
286 // //project is the module's package. e.g. using [":__subpackages__"] in
287 // packages/apps/Settings/Android.bp is equivalent to
288 // //packages/apps/Settings:__subpackages__.
289 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
290 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100291 //
292 // If a module does not specify the `visibility` property then it uses the
293 // `default_visibility` property of the `package` module in the module's package.
294 //
Paul Duffine484f472019-06-20 16:38:08 +0100295 // If a module does not specify the `visibility` property then it uses the
296 // `default_visibility` property of the `package` module in the module's package.
297 //
Paul Duffine2453c72019-05-31 14:00:04 +0100298 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100299 // it will use the `default_visibility` of its closest ancestor package for which
300 // a `default_visibility` property is specified.
301 //
302 // If no `default_visibility` property can be found then the module uses the
303 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100304 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000305 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
306 // more details.
307 Visibility []string
308
Colin Cross7d5136f2015-05-11 13:39:40 -0700309 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800310 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
311 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
312 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700313 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700314
315 Target struct {
316 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700317 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700318 }
319 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700320 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700321 }
322 }
323
Colin Crossee0bc3b2018-10-02 22:01:37 -0700324 UseTargetVariants bool `blueprint:"mutated"`
325 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800326
Dan Willemsen782a2d12015-12-21 14:55:28 -0800327 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700328 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800329
Colin Cross55708f32017-03-20 13:23:34 -0700330 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700331 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700332
Jiyong Park2db76922017-11-08 16:03:48 +0900333 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
334 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
335 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700336 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700337
Jiyong Park2db76922017-11-08 16:03:48 +0900338 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
339 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
340 Soc_specific *bool
341
342 // whether this module is specific to a device, not only for SoC, but also for off-chip
343 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
344 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
345 // This implies `soc_specific:true`.
346 Device_specific *bool
347
348 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900349 // network operator, etc). When set to true, it is installed into /product (or
350 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900351 Product_specific *bool
352
Justin Yund5f6c822019-06-25 16:47:17 +0900353 // TODO(b/135957588) Product_services_specific will be removed once we clear all Android.bp
354 // files that have 'product_services_specific: true'. This will be converted to
355 // Product_speicific as a workaround.
Dario Freni95cf7672018-08-17 00:57:57 +0100356 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100357
Justin Yund5f6c822019-06-25 16:47:17 +0900358 // whether this module extends system. When set to true, it is installed into /system_ext
359 // (or /system/system_ext if system_ext partition does not exist).
360 System_ext_specific *bool
361
Jiyong Parkf9332f12018-02-01 00:54:12 +0900362 // Whether this module is installed to recovery partition
363 Recovery *bool
364
dimitry1f33e402019-03-26 12:39:31 +0100365 // Whether this module is built for non-native architecures (also known as native bridge binary)
366 Native_bridge_supported *bool `android:"arch_variant"`
367
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700368 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800369 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700370
Steven Moreland57a23d22018-04-04 15:42:19 -0700371 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800372 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700373
Chris Wolfe998306e2016-08-15 14:47:23 -0400374 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700375 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400376
Sasha Smundakb6d23052019-04-01 18:37:36 -0700377 // names of other modules to install on host if this module is installed
378 Host_required []string `android:"arch_variant"`
379
380 // names of other modules to install on target if this module is installed
381 Target_required []string `android:"arch_variant"`
382
Colin Cross5aac3622017-08-31 15:07:09 -0700383 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800384 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700385
Dan Willemsen569edc52018-11-19 09:33:29 -0800386 Dist struct {
387 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
388 // command line and any of these targets are also on the command line, or otherwise
389 // built
390 Targets []string `android:"arch_variant"`
391
392 // The name of the output artifact. This defaults to the basename of the output of
393 // the module.
394 Dest *string `android:"arch_variant"`
395
396 // The directory within the dist directory to store the artifact. Defaults to the
397 // top level directory ("").
398 Dir *string `android:"arch_variant"`
399
400 // A suffix to add to the artifact file name (before any extension).
401 Suffix *string `android:"arch_variant"`
402 } `android:"arch_variant"`
403
Colin Crossa1ad8d12016-06-01 17:09:44 -0700404 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700405 CompileTarget Target `blueprint:"mutated"`
406 CompileMultiTargets []Target `blueprint:"mutated"`
407 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800408
409 // Set by InitAndroidModule
410 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700411 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700412
413 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800414
415 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700416
417 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700418
419 // Name and variant strings stored by mutators to enable Module.String()
420 DebugName string `blueprint:"mutated"`
421 DebugMutators []string `blueprint:"mutated"`
422 DebugVariations []string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800423}
424
425type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800426 // If set to true, build a variant of the module for the host. Defaults to false.
427 Host_supported *bool
428
429 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700430 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800431}
432
Colin Crossc472d572015-03-17 15:06:21 -0700433type Multilib string
434
435const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800436 MultilibBoth Multilib = "both"
437 MultilibFirst Multilib = "first"
438 MultilibCommon Multilib = "common"
439 MultilibCommonFirst Multilib = "common_first"
440 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700441)
442
Colin Crossa1ad8d12016-06-01 17:09:44 -0700443type HostOrDeviceSupported int
444
445const (
446 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700447
448 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700449 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700450
451 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700452 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700453
454 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700455 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700456
457 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700458 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700459
460 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700461 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700462
463 // Nothing is supported. This is not exposed to the user, but used to mark a
464 // host only module as unsupported when the module type is not supported on
465 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700466 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700467)
468
Jiyong Park2db76922017-11-08 16:03:48 +0900469type moduleKind int
470
471const (
472 platformModule moduleKind = iota
473 deviceSpecificModule
474 socSpecificModule
475 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900476 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900477)
478
479func (k moduleKind) String() string {
480 switch k {
481 case platformModule:
482 return "platform"
483 case deviceSpecificModule:
484 return "device-specific"
485 case socSpecificModule:
486 return "soc-specific"
487 case productSpecificModule:
488 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900489 case systemExtSpecificModule:
490 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900491 default:
492 panic(fmt.Errorf("unknown module kind %d", k))
493 }
494}
495
Colin Cross36242852017-06-23 15:06:31 -0700496func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800497 base := m.base()
498 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700499
Colin Cross36242852017-06-23 15:06:31 -0700500 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700501 &base.nameProperties,
502 &base.commonProperties,
503 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700504 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700505 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700506}
507
Colin Cross36242852017-06-23 15:06:31 -0700508func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
509 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700510
511 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800512 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700513 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700514 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700515 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800516
Dan Willemsen218f6562015-07-08 18:13:11 -0700517 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700518 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700519 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800520 }
521
Colin Cross36242852017-06-23 15:06:31 -0700522 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800523}
524
Colin Crossee0bc3b2018-10-02 22:01:37 -0700525func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
526 InitAndroidArchModule(m, hod, defaultMultilib)
527 m.base().commonProperties.UseTargetVariants = false
528}
529
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800530// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800531// modules. It should be included as an anonymous field in every module
532// struct definition. InitAndroidModule should then be called from the module's
533// factory function, and the return values from InitAndroidModule should be
534// returned from the factory function.
535//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800536// The ModuleBase type is responsible for implementing the GenerateBuildActions
537// method to support the blueprint.Module interface. This method will then call
538// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700539// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
540// rather than the usual blueprint.ModuleContext.
541// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800542// system including details about the particular build variant that is to be
543// generated.
544//
545// For example:
546//
547// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800548// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800549// )
550//
551// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800552// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800553// properties struct {
554// MyProperty string
555// }
556// }
557//
Colin Cross36242852017-06-23 15:06:31 -0700558// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800559// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700560// m.AddProperties(&m.properties)
561// android.InitAndroidModule(m)
562// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800563// }
564//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800565// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800566// // Get the CPU architecture for the current build variant.
567// variantArch := ctx.Arch()
568//
569// // ...
570// }
Colin Cross635c3b02016-05-18 15:37:25 -0700571type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800572 // Putting the curiously recurring thing pointing to the thing that contains
573 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700574 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700575 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800576
Colin Crossfc754582016-05-17 16:34:16 -0700577 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800578 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700579 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800580 hostAndDeviceProperties hostAndDeviceProperties
581 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700582 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700583 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800584
585 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700586 installFiles Paths
587 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900588 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700589
590 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
591 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800592 installTarget WritablePath
593 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700594 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700595
Colin Cross178a5092016-09-13 13:42:32 -0700596 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700597
598 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700599
600 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700601 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800602 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800603 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700604
605 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700606}
607
Colin Cross4157e882019-06-06 16:57:04 -0700608func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800609
Colin Cross4157e882019-06-06 16:57:04 -0700610func (m *ModuleBase) AddProperties(props ...interface{}) {
611 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700612}
613
Colin Cross4157e882019-06-06 16:57:04 -0700614func (m *ModuleBase) GetProperties() []interface{} {
615 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800616}
617
Colin Cross4157e882019-06-06 16:57:04 -0700618func (m *ModuleBase) BuildParamsForTests() []BuildParams {
619 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700620}
621
Colin Cross4157e882019-06-06 16:57:04 -0700622func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
623 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800624}
625
Colin Cross4157e882019-06-06 16:57:04 -0700626func (m *ModuleBase) VariablesForTests() map[string]string {
627 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800628}
629
Colin Cross4157e882019-06-06 16:57:04 -0700630func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
631 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700632}
633
Colin Crossce75d2c2016-10-06 16:12:58 -0700634// Name returns the name of the module. It may be overridden by individual module types, for
635// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700636func (m *ModuleBase) Name() string {
637 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700638}
639
Colin Cross9a362232019-07-01 15:32:45 -0700640// String returns a string that includes the module name and variants for printing during debugging.
641func (m *ModuleBase) String() string {
642 sb := strings.Builder{}
643 sb.WriteString(m.commonProperties.DebugName)
644 sb.WriteString("{")
645 for i := range m.commonProperties.DebugMutators {
646 if i != 0 {
647 sb.WriteString(",")
648 }
649 sb.WriteString(m.commonProperties.DebugMutators[i])
650 sb.WriteString(":")
651 sb.WriteString(m.commonProperties.DebugVariations[i])
652 }
653 sb.WriteString("}")
654 return sb.String()
655}
656
Colin Crossce75d2c2016-10-06 16:12:58 -0700657// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700658func (m *ModuleBase) BaseModuleName() string {
659 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700660}
661
Colin Cross4157e882019-06-06 16:57:04 -0700662func (m *ModuleBase) base() *ModuleBase {
663 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800664}
665
Paul Duffine2453c72019-05-31 14:00:04 +0100666func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
667 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
668}
669
670func (m *ModuleBase) visibilityProperties() []visibilityProperty {
671 return []visibilityProperty{
672 newVisibilityProperty("visibility", func() []string {
673 return m.base().commonProperties.Visibility
674 }),
675 }
676}
677
Colin Cross4157e882019-06-06 16:57:04 -0700678func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
679 m.commonProperties.CompileTarget = target
680 m.commonProperties.CompileMultiTargets = multiTargets
681 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700682}
683
Colin Cross4157e882019-06-06 16:57:04 -0700684func (m *ModuleBase) Target() Target {
685 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800686}
687
Colin Cross4157e882019-06-06 16:57:04 -0700688func (m *ModuleBase) TargetPrimary() bool {
689 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700690}
691
Colin Cross4157e882019-06-06 16:57:04 -0700692func (m *ModuleBase) MultiTargets() []Target {
693 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700694}
695
Colin Cross4157e882019-06-06 16:57:04 -0700696func (m *ModuleBase) Os() OsType {
697 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800698}
699
Colin Cross4157e882019-06-06 16:57:04 -0700700func (m *ModuleBase) Host() bool {
701 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800702}
703
Colin Cross4157e882019-06-06 16:57:04 -0700704func (m *ModuleBase) Arch() Arch {
705 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800706}
707
Colin Cross4157e882019-06-06 16:57:04 -0700708func (m *ModuleBase) ArchSpecific() bool {
709 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700710}
711
Colin Cross4157e882019-06-06 16:57:04 -0700712func (m *ModuleBase) OsClassSupported() []OsClass {
713 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700714 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700715 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700716 case HostSupportedNoCross:
717 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700718 case DeviceSupported:
719 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700720 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700721 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700722 if Bool(m.hostAndDeviceProperties.Host_supported) ||
723 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
724 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700725 supported = append(supported, Host, HostCross)
726 }
Colin Cross4157e882019-06-06 16:57:04 -0700727 if m.hostAndDeviceProperties.Device_supported == nil ||
728 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700729 supported = append(supported, Device)
730 }
731 return supported
732 default:
733 return nil
734 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800735}
736
Colin Cross4157e882019-06-06 16:57:04 -0700737func (m *ModuleBase) DeviceSupported() bool {
738 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
739 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
740 (m.hostAndDeviceProperties.Device_supported == nil ||
741 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800742}
743
Colin Cross4157e882019-06-06 16:57:04 -0700744func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900745 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900746}
747
Colin Cross4157e882019-06-06 16:57:04 -0700748func (m *ModuleBase) DeviceSpecific() bool {
749 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900750}
751
Colin Cross4157e882019-06-06 16:57:04 -0700752func (m *ModuleBase) SocSpecific() bool {
753 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900754}
755
Colin Cross4157e882019-06-06 16:57:04 -0700756func (m *ModuleBase) ProductSpecific() bool {
757 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900758}
759
Justin Yund5f6c822019-06-25 16:47:17 +0900760func (m *ModuleBase) SystemExtSpecific() bool {
761 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100762}
763
Colin Cross4157e882019-06-06 16:57:04 -0700764func (m *ModuleBase) Enabled() bool {
765 if m.commonProperties.Enabled == nil {
766 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800767 }
Colin Cross4157e882019-06-06 16:57:04 -0700768 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800769}
770
Colin Cross4157e882019-06-06 16:57:04 -0700771func (m *ModuleBase) SkipInstall() {
772 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700773}
774
Colin Cross4157e882019-06-06 16:57:04 -0700775func (m *ModuleBase) ExportedToMake() bool {
776 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900777}
778
Colin Cross4157e882019-06-06 16:57:04 -0700779func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700780 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800781
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700782 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700783 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800784 ctx.VisitDepsDepthFirstIf(isFileInstaller,
785 func(m blueprint.Module) {
786 fileInstaller := m.(fileInstaller)
787 files := fileInstaller.filesToInstall()
788 result = append(result, files...)
789 })
790
791 return result
792}
793
Colin Cross4157e882019-06-06 16:57:04 -0700794func (m *ModuleBase) filesToInstall() Paths {
795 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800796}
797
Colin Cross4157e882019-06-06 16:57:04 -0700798func (m *ModuleBase) NoAddressSanitizer() bool {
799 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800800}
801
Colin Cross4157e882019-06-06 16:57:04 -0700802func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800803 return false
804}
805
Colin Cross4157e882019-06-06 16:57:04 -0700806func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700807 return false
808}
809
Colin Cross4157e882019-06-06 16:57:04 -0700810func (m *ModuleBase) InstallInRecovery() bool {
811 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900812}
813
Colin Cross4157e882019-06-06 16:57:04 -0700814func (m *ModuleBase) Owner() string {
815 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900816}
817
Colin Cross4157e882019-06-06 16:57:04 -0700818func (m *ModuleBase) NoticeFile() OptionalPath {
819 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900820}
821
Colin Cross4157e882019-06-06 16:57:04 -0700822func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700823 allInstalledFiles := Paths{}
824 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800825 ctx.VisitAllModuleVariants(func(module Module) {
826 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700827 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
828 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800829 })
830
Colin Cross0875c522017-11-28 17:34:01 -0800831 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700832
Jeff Gaston088e29e2017-11-29 16:47:17 -0800833 namespacePrefix := ctx.Namespace().(*Namespace).id
834 if namespacePrefix != "" {
835 namespacePrefix = namespacePrefix + "-"
836 }
837
Colin Cross3f40fa42015-01-30 17:27:36 -0800838 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800839 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800840 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700841 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800842 Output: name,
843 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800844 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700845 })
846 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700847 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700848 }
849
850 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800851 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800852 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700853 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800854 Output: name,
855 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700856 })
857 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700858 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700859 }
860
861 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800862 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800863 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800864 suffix = "-soong"
865 }
866
Jeff Gaston088e29e2017-11-29 16:47:17 -0800867 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800868 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700869 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800870 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700871 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800872 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700873
Colin Cross4157e882019-06-06 16:57:04 -0700874 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800875 }
876}
877
Colin Cross4157e882019-06-06 16:57:04 -0700878func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
879 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
880 var deviceSpecific = Bool(m.commonProperties.Device_specific)
881 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +0900882 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900883
Dario Frenifd05a742018-05-29 13:28:54 +0100884 msg := "conflicting value set here"
885 if socSpecific && deviceSpecific {
886 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700887 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900888 ctx.PropertyErrorf("vendor", msg)
889 }
Colin Cross4157e882019-06-06 16:57:04 -0700890 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900891 ctx.PropertyErrorf("proprietary", msg)
892 }
Colin Cross4157e882019-06-06 16:57:04 -0700893 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900894 ctx.PropertyErrorf("soc_specific", msg)
895 }
896 }
897
Justin Yund5f6c822019-06-25 16:47:17 +0900898 if productSpecific && systemExtSpecific {
899 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
900 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +0100901 }
902
Justin Yund5f6c822019-06-25 16:47:17 +0900903 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100904 if productSpecific {
905 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
906 } else {
Justin Yund5f6c822019-06-25 16:47:17 +0900907 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 +0100908 }
909 if deviceSpecific {
910 ctx.PropertyErrorf("device_specific", msg)
911 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700912 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100913 ctx.PropertyErrorf("vendor", msg)
914 }
Colin Cross4157e882019-06-06 16:57:04 -0700915 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100916 ctx.PropertyErrorf("proprietary", msg)
917 }
Colin Cross4157e882019-06-06 16:57:04 -0700918 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100919 ctx.PropertyErrorf("soc_specific", msg)
920 }
921 }
922 }
923
Jiyong Park2db76922017-11-08 16:03:48 +0900924 if productSpecific {
925 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900926 } else if systemExtSpecific {
927 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900928 } else if deviceSpecific {
929 return deviceSpecificModule
930 } else if socSpecific {
931 return socSpecificModule
932 } else {
933 return platformModule
934 }
935}
936
Colin Cross0ea8ba82019-06-06 14:33:29 -0700937func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
938 return baseModuleContext{
939 BaseModuleContext: ctx,
940 target: m.commonProperties.CompileTarget,
941 targetPrimary: m.commonProperties.CompilePrimary,
942 multiTargets: m.commonProperties.CompileMultiTargets,
943 kind: determineModuleKind(m, ctx),
944 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800945 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800946}
947
Colin Cross4157e882019-06-06 16:57:04 -0700948func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700949 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700950 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -0700951 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700952 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
953 installDeps: m.computeInstallDeps(blueprintCtx),
954 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700955 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800956 }
957
Colin Cross6c4f21f2019-06-06 15:41:36 -0700958 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
959 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
960 // TODO: This will be removed once defaults modules handle missing dependency errors
961 blueprintCtx.GetMissingDependencies()
962
Colin Crossdc35e212019-06-06 16:13:11 -0700963 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
964 // are enabled.
965 ctx.baseModuleContext.strictVisitDeps = true
966
Colin Cross4c83e5c2019-02-25 14:54:28 -0800967 if ctx.config.captureBuild {
968 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
969 }
970
Colin Cross67a5c132017-05-09 13:45:28 -0700971 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
972 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800973 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
974 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700975 }
Colin Cross0875c522017-11-28 17:34:01 -0800976 if !ctx.PrimaryArch() {
977 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700978 }
979
980 ctx.Variable(pctx, "moduleDesc", desc)
981
982 s := ""
983 if len(suffix) > 0 {
984 s = " [" + strings.Join(suffix, " ") + "]"
985 }
986 ctx.Variable(pctx, "moduleDescSuffix", s)
987
Dan Willemsen569edc52018-11-19 09:33:29 -0800988 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700989 if m.commonProperties.Dist.Dest != nil {
990 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800991 if err != nil {
992 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
993 }
994 }
Colin Cross4157e882019-06-06 16:57:04 -0700995 if m.commonProperties.Dist.Dir != nil {
996 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800997 if err != nil {
998 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
999 }
1000 }
Colin Cross4157e882019-06-06 16:57:04 -07001001 if m.commonProperties.Dist.Suffix != nil {
1002 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001003 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1004 }
1005 }
1006
Colin Cross4157e882019-06-06 16:57:04 -07001007 if m.Enabled() {
Colin Cross4157e882019-06-06 16:57:04 -07001008 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1009 if module := SrcIsModule(notice); module != "" {
1010 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001011 } else {
1012 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001013 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001014 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001015
1016 m.module.GenerateAndroidBuildActions(ctx)
1017 if ctx.Failed() {
1018 return
1019 }
1020
1021 m.installFiles = append(m.installFiles, ctx.installFiles...)
1022 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001023 } else if ctx.Config().AllowMissingDependencies() {
1024 // If the module is not enabled it will not create any build rules, nothing will call
1025 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1026 // and report them as an error even when AllowMissingDependencies = true. Call
1027 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1028 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001029 }
1030
Colin Cross4157e882019-06-06 16:57:04 -07001031 if m == ctx.FinalModule().(Module).base() {
1032 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001033 if ctx.Failed() {
1034 return
1035 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001036 }
Colin Crosscec81712017-07-13 14:43:27 -07001037
Colin Cross4157e882019-06-06 16:57:04 -07001038 m.buildParams = ctx.buildParams
1039 m.ruleParams = ctx.ruleParams
1040 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001041}
1042
Colin Cross0ea8ba82019-06-06 14:33:29 -07001043type baseModuleContext struct {
1044 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -07001045 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001046 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001047 targetPrimary bool
1048 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +09001049 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -07001050 config Config
Colin Crossdc35e212019-06-06 16:13:11 -07001051
1052 walkPath []Module
1053
1054 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001055}
1056
Colin Cross25de6c32019-06-06 14:29:25 -07001057type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001058 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001059 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001060 installDeps Paths
1061 installFiles Paths
1062 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001063 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001064
1065 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001066 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001067 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001068 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001069}
1070
Colin Crossb88b3c52019-06-10 15:15:17 -07001071func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1072 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001073 Rule: ErrorRule,
1074 Description: params.Description,
1075 Output: params.Output,
1076 Outputs: params.Outputs,
1077 ImplicitOutput: params.ImplicitOutput,
1078 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001079 Args: map[string]string{
1080 "error": err.Error(),
1081 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001082 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001083}
1084
Colin Cross25de6c32019-06-06 14:29:25 -07001085func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1086 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001087}
1088
Colin Cross0875c522017-11-28 17:34:01 -08001089func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001090 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001091 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001092 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001093 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001094 Outputs: params.Outputs.Strings(),
1095 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1096 Inputs: params.Inputs.Strings(),
1097 Implicits: params.Implicits.Strings(),
1098 OrderOnly: params.OrderOnly.Strings(),
1099 Args: params.Args,
1100 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001101 }
1102
Colin Cross33bfb0a2016-11-21 17:23:08 -08001103 if params.Depfile != nil {
1104 bparams.Depfile = params.Depfile.String()
1105 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001106 if params.Output != nil {
1107 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1108 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001109 if params.ImplicitOutput != nil {
1110 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1111 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001112 if params.Input != nil {
1113 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1114 }
1115 if params.Implicit != nil {
1116 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1117 }
1118
Colin Cross0b9f31f2019-02-28 11:00:01 -08001119 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1120 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1121 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1122 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1123 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1124 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001125
Colin Cross0875c522017-11-28 17:34:01 -08001126 return bparams
1127}
1128
Colin Cross25de6c32019-06-06 14:29:25 -07001129func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1130 if m.config.captureBuild {
1131 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001132 }
1133
Colin Crossdc35e212019-06-06 16:13:11 -07001134 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001135}
1136
Colin Cross25de6c32019-06-06 14:29:25 -07001137func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001138 argNames ...string) blueprint.Rule {
1139
Colin Crossdc35e212019-06-06 16:13:11 -07001140 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001141
Colin Cross25de6c32019-06-06 14:29:25 -07001142 if m.config.captureBuild {
1143 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001144 }
1145
1146 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001147}
1148
Colin Cross25de6c32019-06-06 14:29:25 -07001149func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001150 if params.Description != "" {
1151 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1152 }
1153
1154 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1155 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1156 m.ModuleName(), strings.Join(missingDeps, ", ")))
1157 }
1158
Colin Cross25de6c32019-06-06 14:29:25 -07001159 if m.config.captureBuild {
1160 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001161 }
1162
Colin Crossdc35e212019-06-06 16:13:11 -07001163 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001164}
1165
Colin Crossdc35e212019-06-06 16:13:11 -07001166func (b *baseModuleContext) Module() Module {
1167 module, _ := b.BaseModuleContext.Module().(Module)
1168 return module
1169}
1170
1171func (b *baseModuleContext) Config() Config {
1172 return b.BaseModuleContext.Config().(Config)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001173}
1174
Colin Cross25de6c32019-06-06 14:29:25 -07001175func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001176 var missingDeps []string
1177 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001178 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001179 missingDeps = FirstUniqueStrings(missingDeps)
1180 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001181}
1182
Colin Crossdc35e212019-06-06 16:13:11 -07001183func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001184 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001185 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001186 *missingDeps = append(*missingDeps, deps...)
1187 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001188 }
1189}
1190
Colin Crossdc35e212019-06-06 16:13:11 -07001191func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001192 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001193
1194 if !strict {
1195 return aModule
1196 }
1197
Colin Cross380c69a2019-06-10 17:49:58 +00001198 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001199 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001200 return nil
1201 }
1202
1203 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001204 if b.Config().AllowMissingDependencies() {
1205 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001206 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001207 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001208 }
1209 return nil
1210 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001211 return aModule
1212}
1213
Colin Crossdc35e212019-06-06 16:13:11 -07001214func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001215 type dep struct {
1216 mod blueprint.Module
1217 tag blueprint.DependencyTag
1218 }
1219 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001220 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001221 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Crossdc35e212019-06-06 16:13:11 -07001222 returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001223 if tag == nil || returnedTag == tag {
1224 deps = append(deps, dep{aModule, returnedTag})
1225 }
1226 }
1227 })
1228 if len(deps) == 1 {
1229 return deps[0].mod, deps[0].tag
1230 } else if len(deps) >= 2 {
1231 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001232 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001233 } else {
1234 return nil, nil
1235 }
1236}
1237
Colin Crossdc35e212019-06-06 16:13:11 -07001238func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001239 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001240 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001241 if aModule, _ := module.(Module); aModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001242 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001243 deps = append(deps, aModule)
1244 }
1245 }
1246 })
1247 return deps
1248}
1249
Colin Cross25de6c32019-06-06 14:29:25 -07001250func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1251 module, _ := m.getDirectDepInternal(name, tag)
1252 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001253}
1254
Colin Crossdc35e212019-06-06 16:13:11 -07001255func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1256 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001257}
1258
Colin Crossdc35e212019-06-06 16:13:11 -07001259func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1260 b.BaseModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001261}
1262
Colin Crossdc35e212019-06-06 16:13:11 -07001263func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
1264 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1265 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001266 visit(aModule)
1267 }
1268 })
1269}
1270
Colin Crossdc35e212019-06-06 16:13:11 -07001271func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1272 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1273 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
1274 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001275 visit(aModule)
1276 }
1277 }
1278 })
1279}
1280
Colin Crossdc35e212019-06-06 16:13:11 -07001281func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1282 b.BaseModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001283 // pred
1284 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001285 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001286 return pred(aModule)
1287 } else {
1288 return false
1289 }
1290 },
1291 // visit
1292 func(module blueprint.Module) {
1293 visit(module.(Module))
1294 })
1295}
1296
Colin Crossdc35e212019-06-06 16:13:11 -07001297func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1298 b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1299 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001300 visit(aModule)
1301 }
1302 })
1303}
1304
Colin Crossdc35e212019-06-06 16:13:11 -07001305func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1306 b.BaseModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001307 // pred
1308 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001309 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001310 return pred(aModule)
1311 } else {
1312 return false
1313 }
1314 },
1315 // visit
1316 func(module blueprint.Module) {
1317 visit(module.(Module))
1318 })
1319}
1320
Colin Crossdc35e212019-06-06 16:13:11 -07001321func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1322 b.BaseModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001323}
1324
Colin Crossdc35e212019-06-06 16:13:11 -07001325func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1326 b.walkPath = []Module{b.Module()}
1327 b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1328 childAndroidModule, _ := child.(Module)
1329 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001330 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001331 // record walkPath before visit
1332 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1333 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1334 }
1335 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001336 return visit(childAndroidModule, parentAndroidModule)
1337 } else {
1338 return false
1339 }
1340 })
1341}
1342
Colin Crossdc35e212019-06-06 16:13:11 -07001343func (b *baseModuleContext) GetWalkPath() []Module {
1344 return b.walkPath
1345}
1346
Colin Cross25de6c32019-06-06 14:29:25 -07001347func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001348 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001349 visit(module.(Module))
1350 })
1351}
1352
Colin Cross25de6c32019-06-06 14:29:25 -07001353func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001354 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001355}
1356
Colin Cross25de6c32019-06-06 14:29:25 -07001357func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001358 return m.bp.FinalModule().(Module)
1359}
1360
1361func (m *moduleContext) ModuleSubDir() string {
1362 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001363}
1364
Colin Cross0ea8ba82019-06-06 14:33:29 -07001365func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001366 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001367}
1368
Colin Cross0ea8ba82019-06-06 14:33:29 -07001369func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001370 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001371}
1372
Colin Cross0ea8ba82019-06-06 14:33:29 -07001373func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001374 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001375}
1376
Colin Cross0ea8ba82019-06-06 14:33:29 -07001377func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001378 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001379}
1380
Colin Cross0ea8ba82019-06-06 14:33:29 -07001381func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001382 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001383}
1384
Colin Cross0ea8ba82019-06-06 14:33:29 -07001385func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001386 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001387}
1388
Colin Cross0ea8ba82019-06-06 14:33:29 -07001389func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001390 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001391}
1392
Colin Cross0ea8ba82019-06-06 14:33:29 -07001393func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001394 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001395}
1396
Colin Cross0ea8ba82019-06-06 14:33:29 -07001397func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001398 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001399}
1400
Colin Cross0ea8ba82019-06-06 14:33:29 -07001401func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001402 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001403}
1404
Colin Cross0ea8ba82019-06-06 14:33:29 -07001405func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001406 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001407}
1408
Colin Cross0ea8ba82019-06-06 14:33:29 -07001409func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001410 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001411 return true
1412 }
Colin Cross25de6c32019-06-06 14:29:25 -07001413 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001414}
1415
Colin Cross0ea8ba82019-06-06 14:33:29 -07001416func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001417 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001418}
1419
Colin Cross0ea8ba82019-06-06 14:33:29 -07001420func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001421 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001422}
1423
Colin Cross0ea8ba82019-06-06 14:33:29 -07001424func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001425 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001426}
1427
Colin Cross0ea8ba82019-06-06 14:33:29 -07001428func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001429 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001430}
1431
Colin Cross0ea8ba82019-06-06 14:33:29 -07001432func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001433 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001434}
1435
Colin Cross0ea8ba82019-06-06 14:33:29 -07001436func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001437 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001438}
1439
Justin Yund5f6c822019-06-25 16:47:17 +09001440func (b *baseModuleContext) SystemExtSpecific() bool {
1441 return b.kind == systemExtSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001442}
1443
Jiyong Park5baac542018-08-28 09:55:37 +09001444// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001445// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001446func (m *ModuleBase) MakeAsPlatform() {
1447 m.commonProperties.Vendor = boolPtr(false)
1448 m.commonProperties.Proprietary = boolPtr(false)
1449 m.commonProperties.Soc_specific = boolPtr(false)
1450 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001451 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001452}
1453
Colin Cross4157e882019-06-06 16:57:04 -07001454func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1455 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001456}
1457
Colin Cross25de6c32019-06-06 14:29:25 -07001458func (m *moduleContext) InstallInData() bool {
1459 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001460}
1461
Colin Cross25de6c32019-06-06 14:29:25 -07001462func (m *moduleContext) InstallInSanitizerDir() bool {
1463 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001464}
1465
Colin Cross25de6c32019-06-06 14:29:25 -07001466func (m *moduleContext) InstallInRecovery() bool {
1467 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001468}
1469
Colin Cross25de6c32019-06-06 14:29:25 -07001470func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1471 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001472 return true
1473 }
1474
Colin Cross3607f212018-05-07 15:28:05 -07001475 // We'll need a solution for choosing which of modules with the same name in different
1476 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1477 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001478 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001479 return true
1480 }
1481
Colin Cross25de6c32019-06-06 14:29:25 -07001482 if m.Device() {
1483 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001484 return true
1485 }
1486
Colin Cross25de6c32019-06-06 14:29:25 -07001487 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001488 return true
1489 }
1490 }
1491
1492 return false
1493}
1494
Colin Cross25de6c32019-06-06 14:29:25 -07001495func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001496 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001497 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001498}
1499
Colin Cross25de6c32019-06-06 14:29:25 -07001500func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001501 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001502 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001503}
1504
Colin Cross25de6c32019-06-06 14:29:25 -07001505func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001506 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001507
Colin Cross25de6c32019-06-06 14:29:25 -07001508 fullInstallPath := installPath.Join(m, name)
1509 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001510
Colin Cross25de6c32019-06-06 14:29:25 -07001511 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001512
Colin Cross25de6c32019-06-06 14:29:25 -07001513 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001514
Colin Cross89562dc2016-10-03 17:47:19 -07001515 var implicitDeps, orderOnlyDeps Paths
1516
Colin Cross25de6c32019-06-06 14:29:25 -07001517 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001518 // Installed host modules might be used during the build, depend directly on their
1519 // dependencies so their timestamp is updated whenever their dependency is updated
1520 implicitDeps = deps
1521 } else {
1522 orderOnlyDeps = deps
1523 }
1524
Colin Cross25de6c32019-06-06 14:29:25 -07001525 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001526 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001527 Description: "install " + fullInstallPath.Base(),
1528 Output: fullInstallPath,
1529 Input: srcPath,
1530 Implicits: implicitDeps,
1531 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001532 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001533 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001534
Colin Cross25de6c32019-06-06 14:29:25 -07001535 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001536 }
Colin Cross25de6c32019-06-06 14:29:25 -07001537 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001538 return fullInstallPath
1539}
1540
Colin Cross25de6c32019-06-06 14:29:25 -07001541func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1542 fullInstallPath := installPath.Join(m, name)
1543 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001544
Colin Cross25de6c32019-06-06 14:29:25 -07001545 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001546
Alex Lightfb4353d2019-01-17 13:57:45 -08001547 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1548 if err != nil {
1549 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1550 }
Colin Cross25de6c32019-06-06 14:29:25 -07001551 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001552 Rule: Symlink,
1553 Description: "install symlink " + fullInstallPath.Base(),
1554 Output: fullInstallPath,
1555 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001556 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001557 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001558 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001559 },
1560 })
Colin Cross3854a602016-01-11 12:49:11 -08001561
Colin Cross25de6c32019-06-06 14:29:25 -07001562 m.installFiles = append(m.installFiles, fullInstallPath)
1563 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001564 }
Colin Cross3854a602016-01-11 12:49:11 -08001565 return fullInstallPath
1566}
1567
Jiyong Parkf1194352019-02-25 11:05:47 +09001568// installPath/name -> absPath where absPath might be a path that is available only at runtime
1569// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001570func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1571 fullInstallPath := installPath.Join(m, name)
1572 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001573
Colin Cross25de6c32019-06-06 14:29:25 -07001574 if !m.skipInstall(fullInstallPath) {
1575 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001576 Rule: Symlink,
1577 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1578 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001579 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001580 Args: map[string]string{
1581 "fromPath": absPath,
1582 },
1583 })
1584
Colin Cross25de6c32019-06-06 14:29:25 -07001585 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001586 }
1587 return fullInstallPath
1588}
1589
Colin Cross25de6c32019-06-06 14:29:25 -07001590func (m *moduleContext) CheckbuildFile(srcPath Path) {
1591 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001592}
1593
Colin Cross3f40fa42015-01-30 17:27:36 -08001594type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001595 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001596}
1597
1598func isFileInstaller(m blueprint.Module) bool {
1599 _, ok := m.(fileInstaller)
1600 return ok
1601}
1602
1603func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001604 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001605 return ok
1606}
Colin Crossfce53272015-04-08 11:21:40 -07001607
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001608func findStringInSlice(str string, slice []string) int {
1609 for i, s := range slice {
1610 if s == str {
1611 return i
Colin Crossfce53272015-04-08 11:21:40 -07001612 }
1613 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001614 return -1
1615}
1616
Colin Cross41955e82019-05-29 14:40:35 -07001617// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1618// was not a module reference.
1619func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001620 if len(s) > 1 && s[0] == ':' {
1621 return s[1:]
1622 }
1623 return ""
1624}
1625
Colin Cross41955e82019-05-29 14:40:35 -07001626// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1627// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1628func SrcIsModuleWithTag(s string) (module, tag string) {
1629 if len(s) > 1 && s[0] == ':' {
1630 module = s[1:]
1631 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1632 if module[len(module)-1] == '}' {
1633 tag = module[tagStart+1 : len(module)-1]
1634 module = module[:tagStart]
1635 return module, tag
1636 }
1637 }
1638 return module, ""
1639 }
1640 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001641}
1642
Colin Cross41955e82019-05-29 14:40:35 -07001643type sourceOrOutputDependencyTag struct {
1644 blueprint.BaseDependencyTag
1645 tag string
1646}
1647
1648func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1649 return sourceOrOutputDependencyTag{tag: tag}
1650}
1651
1652var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001653
Colin Cross366938f2017-12-11 16:29:02 -08001654// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1655// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001656//
1657// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001658func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001659 set := make(map[string]bool)
1660
Colin Cross068e0fe2016-12-13 15:23:47 -08001661 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001662 if m, t := SrcIsModuleWithTag(s); m != "" {
1663 if _, found := set[s]; found {
1664 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001665 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001666 set[s] = true
1667 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001668 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001669 }
1670 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001671}
1672
Colin Cross366938f2017-12-11 16:29:02 -08001673// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1674// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001675//
1676// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001677func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1678 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001679 if m, t := SrcIsModuleWithTag(*s); m != "" {
1680 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001681 }
1682 }
1683}
1684
Colin Cross41955e82019-05-29 14:40:35 -07001685// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1686// 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 -08001687type SourceFileProducer interface {
1688 Srcs() Paths
1689}
1690
Colin Cross41955e82019-05-29 14:40:35 -07001691// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1692// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1693// listed in the property.
1694type OutputFileProducer interface {
1695 OutputFiles(tag string) (Paths, error)
1696}
1697
Colin Crossfe17f6f2019-03-28 19:30:56 -07001698type HostToolProvider interface {
1699 HostToolPath() OptionalPath
1700}
1701
Colin Cross27b922f2019-03-04 22:35:41 -08001702// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1703// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001704//
1705// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001706func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1707 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001708}
1709
Colin Cross2fafa3e2019-03-05 12:39:51 -08001710// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1711// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001712//
1713// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001714func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1715 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001716}
1717
1718// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1719// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1720// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001721func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001722 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001723 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001724 }
1725 return OptionalPath{}
1726}
1727
Colin Cross25de6c32019-06-06 14:29:25 -07001728func (m *moduleContext) RequiredModuleNames() []string {
1729 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001730}
1731
Colin Cross25de6c32019-06-06 14:29:25 -07001732func (m *moduleContext) HostRequiredModuleNames() []string {
1733 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001734}
1735
Colin Cross25de6c32019-06-06 14:29:25 -07001736func (m *moduleContext) TargetRequiredModuleNames() []string {
1737 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001738}
1739
Colin Crossdc35e212019-06-06 16:13:11 -07001740func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths {
1741 ret, err := b.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001742 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001743 b.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001744 }
Colin Crossdc35e212019-06-06 16:13:11 -07001745 return pathsForModuleSrcFromFullPath(b, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001746}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001747
Colin Crossdc35e212019-06-06 16:13:11 -07001748func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1749 ret, err := b.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001750 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001751 b.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001752 }
Colin Crossdc35e212019-06-06 16:13:11 -07001753 return pathsForModuleSrcFromFullPath(b, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001754}
1755
Colin Cross463a90e2015-06-17 14:20:06 -07001756func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001757 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001758}
1759
Colin Cross0875c522017-11-28 17:34:01 -08001760func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001761 return &buildTargetSingleton{}
1762}
1763
Colin Cross87d8b562017-04-25 10:01:55 -07001764func parentDir(dir string) string {
1765 dir, _ = filepath.Split(dir)
1766 return filepath.Clean(dir)
1767}
1768
Colin Cross1f8c52b2015-06-16 16:38:17 -07001769type buildTargetSingleton struct{}
1770
Colin Cross0875c522017-11-28 17:34:01 -08001771func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1772 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001773
Colin Cross0875c522017-11-28 17:34:01 -08001774 mmTarget := func(dir string) WritablePath {
1775 return PathForPhony(ctx,
1776 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001777 }
1778
Colin Cross0875c522017-11-28 17:34:01 -08001779 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001780
Colin Cross0875c522017-11-28 17:34:01 -08001781 ctx.VisitAllModules(func(module Module) {
1782 blueprintDir := module.base().blueprintDir
1783 installTarget := module.base().installTarget
1784 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001785
Colin Cross0875c522017-11-28 17:34:01 -08001786 if checkbuildTarget != nil {
1787 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1788 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1789 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001790
Colin Cross0875c522017-11-28 17:34:01 -08001791 if installTarget != nil {
1792 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001793 }
1794 })
1795
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001796 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001797 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001798 suffix = "-soong"
1799 }
1800
Colin Cross1f8c52b2015-06-16 16:38:17 -07001801 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001802 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001803 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001804 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001805 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001806 })
1807
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001808 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001809 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001810 return
1811 }
1812
Colin Cross87d8b562017-04-25 10:01:55 -07001813 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001814 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001815 for _, dir := range dirs {
1816 dir := parentDir(dir)
1817 for dir != "." && dir != "/" {
1818 if _, exists := modulesInDir[dir]; exists {
1819 break
1820 }
1821 modulesInDir[dir] = nil
1822 dir = parentDir(dir)
1823 }
1824 }
1825
1826 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001827 for _, dir := range dirs {
1828 p := parentDir(dir)
1829 if p != "." && p != "/" {
1830 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1831 }
1832 }
1833
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001834 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1835 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1836 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001837 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001838 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001839 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001840 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001841 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001842 // HACK: checkbuild should be an optional build, but force it
1843 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001844 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001845 })
1846 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001847
1848 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1849 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001850 ctx.VisitAllModules(func(module Module) {
1851 if module.Enabled() {
1852 os := module.Target().Os
1853 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001854 }
1855 })
1856
Colin Cross0875c522017-11-28 17:34:01 -08001857 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001858 for os, deps := range osDeps {
1859 var className string
1860
1861 switch os.Class {
1862 case Host:
1863 className = "host"
1864 case HostCross:
1865 className = "host-cross"
1866 case Device:
1867 className = "target"
1868 default:
1869 continue
1870 }
1871
Colin Cross0875c522017-11-28 17:34:01 -08001872 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001873 osClass[className] = append(osClass[className], name)
1874
Colin Cross0875c522017-11-28 17:34:01 -08001875 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001876 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001877 Output: name,
1878 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001879 })
1880 }
1881
1882 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001883 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001884 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001885 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001886 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001887 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001888 })
1889 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001890}
Colin Crossd779da42015-12-17 18:00:23 -08001891
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001892// Collect information for opening IDE project files in java/jdeps.go.
1893type IDEInfo interface {
1894 IDEInfo(ideInfo *IdeInfo)
1895 BaseModuleName() string
1896}
1897
1898// Extract the base module name from the Import name.
1899// Often the Import name has a prefix "prebuilt_".
1900// Remove the prefix explicitly if needed
1901// until we find a better solution to get the Import name.
1902type IDECustomizedModuleName interface {
1903 IDECustomizedModuleName() string
1904}
1905
1906type IdeInfo struct {
1907 Deps []string `json:"dependencies,omitempty"`
1908 Srcs []string `json:"srcs,omitempty"`
1909 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1910 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1911 Jars []string `json:"jars,omitempty"`
1912 Classes []string `json:"class,omitempty"`
1913 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001914 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001915}