blob: 2d4c1b593df4c395cc8bb3fa1ac15738e15f7a70 [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
Dario Frenifd05a742018-05-29 13:28:54 +0100129 ProductServicesSpecific() 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
Dario Frenifd05a742018-05-29 13:28:54 +0100353 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100354 // to true, it is installed into /product_services (or /system/product_services if
355 // product_services partition does not exist).
356 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100357
Jiyong Parkf9332f12018-02-01 00:54:12 +0900358 // Whether this module is installed to recovery partition
359 Recovery *bool
360
dimitry1f33e402019-03-26 12:39:31 +0100361 // Whether this module is built for non-native architecures (also known as native bridge binary)
362 Native_bridge_supported *bool `android:"arch_variant"`
363
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700364 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800365 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700366
Steven Moreland57a23d22018-04-04 15:42:19 -0700367 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800368 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700369
Chris Wolfe998306e2016-08-15 14:47:23 -0400370 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700371 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400372
Sasha Smundakb6d23052019-04-01 18:37:36 -0700373 // names of other modules to install on host if this module is installed
374 Host_required []string `android:"arch_variant"`
375
376 // names of other modules to install on target if this module is installed
377 Target_required []string `android:"arch_variant"`
378
Colin Cross5aac3622017-08-31 15:07:09 -0700379 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800380 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700381
Dan Willemsen569edc52018-11-19 09:33:29 -0800382 Dist struct {
383 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
384 // command line and any of these targets are also on the command line, or otherwise
385 // built
386 Targets []string `android:"arch_variant"`
387
388 // The name of the output artifact. This defaults to the basename of the output of
389 // the module.
390 Dest *string `android:"arch_variant"`
391
392 // The directory within the dist directory to store the artifact. Defaults to the
393 // top level directory ("").
394 Dir *string `android:"arch_variant"`
395
396 // A suffix to add to the artifact file name (before any extension).
397 Suffix *string `android:"arch_variant"`
398 } `android:"arch_variant"`
399
Colin Crossa1ad8d12016-06-01 17:09:44 -0700400 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700401 CompileTarget Target `blueprint:"mutated"`
402 CompileMultiTargets []Target `blueprint:"mutated"`
403 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800404
405 // Set by InitAndroidModule
406 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700407 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700408
409 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800410
411 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700412
413 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700414
415 // Name and variant strings stored by mutators to enable Module.String()
416 DebugName string `blueprint:"mutated"`
417 DebugMutators []string `blueprint:"mutated"`
418 DebugVariations []string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800419}
420
421type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800422 // If set to true, build a variant of the module for the host. Defaults to false.
423 Host_supported *bool
424
425 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700426 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800427}
428
Colin Crossc472d572015-03-17 15:06:21 -0700429type Multilib string
430
431const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800432 MultilibBoth Multilib = "both"
433 MultilibFirst Multilib = "first"
434 MultilibCommon Multilib = "common"
435 MultilibCommonFirst Multilib = "common_first"
436 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700437)
438
Colin Crossa1ad8d12016-06-01 17:09:44 -0700439type HostOrDeviceSupported int
440
441const (
442 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700443
444 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700445 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700446
447 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700448 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700449
450 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700451 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700452
453 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700454 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700455
456 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700457 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700458
459 // Nothing is supported. This is not exposed to the user, but used to mark a
460 // host only module as unsupported when the module type is not supported on
461 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700462 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700463)
464
Jiyong Park2db76922017-11-08 16:03:48 +0900465type moduleKind int
466
467const (
468 platformModule moduleKind = iota
469 deviceSpecificModule
470 socSpecificModule
471 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100472 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900473)
474
475func (k moduleKind) String() string {
476 switch k {
477 case platformModule:
478 return "platform"
479 case deviceSpecificModule:
480 return "device-specific"
481 case socSpecificModule:
482 return "soc-specific"
483 case productSpecificModule:
484 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100485 case productServicesSpecificModule:
486 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900487 default:
488 panic(fmt.Errorf("unknown module kind %d", k))
489 }
490}
491
Colin Cross36242852017-06-23 15:06:31 -0700492func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800493 base := m.base()
494 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700495
Colin Cross36242852017-06-23 15:06:31 -0700496 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700497 &base.nameProperties,
498 &base.commonProperties,
499 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700500 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700501 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700502}
503
Colin Cross36242852017-06-23 15:06:31 -0700504func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
505 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700506
507 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800508 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700509 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700510 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700511 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800512
Dan Willemsen218f6562015-07-08 18:13:11 -0700513 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700514 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700515 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800516 }
517
Colin Cross36242852017-06-23 15:06:31 -0700518 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800519}
520
Colin Crossee0bc3b2018-10-02 22:01:37 -0700521func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
522 InitAndroidArchModule(m, hod, defaultMultilib)
523 m.base().commonProperties.UseTargetVariants = false
524}
525
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800526// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800527// modules. It should be included as an anonymous field in every module
528// struct definition. InitAndroidModule should then be called from the module's
529// factory function, and the return values from InitAndroidModule should be
530// returned from the factory function.
531//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800532// The ModuleBase type is responsible for implementing the GenerateBuildActions
533// method to support the blueprint.Module interface. This method will then call
534// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700535// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
536// rather than the usual blueprint.ModuleContext.
537// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800538// system including details about the particular build variant that is to be
539// generated.
540//
541// For example:
542//
543// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800544// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800545// )
546//
547// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800548// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800549// properties struct {
550// MyProperty string
551// }
552// }
553//
Colin Cross36242852017-06-23 15:06:31 -0700554// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800555// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700556// m.AddProperties(&m.properties)
557// android.InitAndroidModule(m)
558// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800559// }
560//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800561// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800562// // Get the CPU architecture for the current build variant.
563// variantArch := ctx.Arch()
564//
565// // ...
566// }
Colin Cross635c3b02016-05-18 15:37:25 -0700567type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800568 // Putting the curiously recurring thing pointing to the thing that contains
569 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700570 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700571 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800572
Colin Crossfc754582016-05-17 16:34:16 -0700573 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800574 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700575 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800576 hostAndDeviceProperties hostAndDeviceProperties
577 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700578 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700579 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800580
581 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700582 installFiles Paths
583 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900584 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700585
586 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
587 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800588 installTarget WritablePath
589 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700590 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700591
Colin Cross178a5092016-09-13 13:42:32 -0700592 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700593
594 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700595
596 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700597 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800598 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800599 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700600
601 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700602}
603
Colin Cross4157e882019-06-06 16:57:04 -0700604func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800605
Colin Cross4157e882019-06-06 16:57:04 -0700606func (m *ModuleBase) AddProperties(props ...interface{}) {
607 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700608}
609
Colin Cross4157e882019-06-06 16:57:04 -0700610func (m *ModuleBase) GetProperties() []interface{} {
611 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800612}
613
Colin Cross4157e882019-06-06 16:57:04 -0700614func (m *ModuleBase) BuildParamsForTests() []BuildParams {
615 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700616}
617
Colin Cross4157e882019-06-06 16:57:04 -0700618func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
619 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800620}
621
Colin Cross4157e882019-06-06 16:57:04 -0700622func (m *ModuleBase) VariablesForTests() map[string]string {
623 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800624}
625
Colin Cross4157e882019-06-06 16:57:04 -0700626func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
627 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700628}
629
Colin Crossce75d2c2016-10-06 16:12:58 -0700630// Name returns the name of the module. It may be overridden by individual module types, for
631// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700632func (m *ModuleBase) Name() string {
633 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700634}
635
Colin Cross9a362232019-07-01 15:32:45 -0700636// String returns a string that includes the module name and variants for printing during debugging.
637func (m *ModuleBase) String() string {
638 sb := strings.Builder{}
639 sb.WriteString(m.commonProperties.DebugName)
640 sb.WriteString("{")
641 for i := range m.commonProperties.DebugMutators {
642 if i != 0 {
643 sb.WriteString(",")
644 }
645 sb.WriteString(m.commonProperties.DebugMutators[i])
646 sb.WriteString(":")
647 sb.WriteString(m.commonProperties.DebugVariations[i])
648 }
649 sb.WriteString("}")
650 return sb.String()
651}
652
Colin Crossce75d2c2016-10-06 16:12:58 -0700653// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700654func (m *ModuleBase) BaseModuleName() string {
655 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700656}
657
Colin Cross4157e882019-06-06 16:57:04 -0700658func (m *ModuleBase) base() *ModuleBase {
659 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800660}
661
Paul Duffine2453c72019-05-31 14:00:04 +0100662func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
663 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
664}
665
666func (m *ModuleBase) visibilityProperties() []visibilityProperty {
667 return []visibilityProperty{
668 newVisibilityProperty("visibility", func() []string {
669 return m.base().commonProperties.Visibility
670 }),
671 }
672}
673
Colin Cross4157e882019-06-06 16:57:04 -0700674func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
675 m.commonProperties.CompileTarget = target
676 m.commonProperties.CompileMultiTargets = multiTargets
677 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700678}
679
Colin Cross4157e882019-06-06 16:57:04 -0700680func (m *ModuleBase) Target() Target {
681 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800682}
683
Colin Cross4157e882019-06-06 16:57:04 -0700684func (m *ModuleBase) TargetPrimary() bool {
685 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700686}
687
Colin Cross4157e882019-06-06 16:57:04 -0700688func (m *ModuleBase) MultiTargets() []Target {
689 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700690}
691
Colin Cross4157e882019-06-06 16:57:04 -0700692func (m *ModuleBase) Os() OsType {
693 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800694}
695
Colin Cross4157e882019-06-06 16:57:04 -0700696func (m *ModuleBase) Host() bool {
697 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800698}
699
Colin Cross4157e882019-06-06 16:57:04 -0700700func (m *ModuleBase) Arch() Arch {
701 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800702}
703
Colin Cross4157e882019-06-06 16:57:04 -0700704func (m *ModuleBase) ArchSpecific() bool {
705 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700706}
707
Colin Cross4157e882019-06-06 16:57:04 -0700708func (m *ModuleBase) OsClassSupported() []OsClass {
709 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700710 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700711 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700712 case HostSupportedNoCross:
713 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700714 case DeviceSupported:
715 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700716 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700717 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700718 if Bool(m.hostAndDeviceProperties.Host_supported) ||
719 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
720 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700721 supported = append(supported, Host, HostCross)
722 }
Colin Cross4157e882019-06-06 16:57:04 -0700723 if m.hostAndDeviceProperties.Device_supported == nil ||
724 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700725 supported = append(supported, Device)
726 }
727 return supported
728 default:
729 return nil
730 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800731}
732
Colin Cross4157e882019-06-06 16:57:04 -0700733func (m *ModuleBase) DeviceSupported() bool {
734 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
735 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
736 (m.hostAndDeviceProperties.Device_supported == nil ||
737 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800738}
739
Colin Cross4157e882019-06-06 16:57:04 -0700740func (m *ModuleBase) Platform() bool {
741 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900742}
743
Colin Cross4157e882019-06-06 16:57:04 -0700744func (m *ModuleBase) DeviceSpecific() bool {
745 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900746}
747
Colin Cross4157e882019-06-06 16:57:04 -0700748func (m *ModuleBase) SocSpecific() bool {
749 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900750}
751
Colin Cross4157e882019-06-06 16:57:04 -0700752func (m *ModuleBase) ProductSpecific() bool {
753 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900754}
755
Colin Cross4157e882019-06-06 16:57:04 -0700756func (m *ModuleBase) ProductServicesSpecific() bool {
757 return Bool(m.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100758}
759
Colin Cross4157e882019-06-06 16:57:04 -0700760func (m *ModuleBase) Enabled() bool {
761 if m.commonProperties.Enabled == nil {
762 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800763 }
Colin Cross4157e882019-06-06 16:57:04 -0700764 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800765}
766
Colin Cross4157e882019-06-06 16:57:04 -0700767func (m *ModuleBase) SkipInstall() {
768 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700769}
770
Colin Cross4157e882019-06-06 16:57:04 -0700771func (m *ModuleBase) ExportedToMake() bool {
772 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900773}
774
Colin Cross4157e882019-06-06 16:57:04 -0700775func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700776 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800777
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700778 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700779 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800780 ctx.VisitDepsDepthFirstIf(isFileInstaller,
781 func(m blueprint.Module) {
782 fileInstaller := m.(fileInstaller)
783 files := fileInstaller.filesToInstall()
784 result = append(result, files...)
785 })
786
787 return result
788}
789
Colin Cross4157e882019-06-06 16:57:04 -0700790func (m *ModuleBase) filesToInstall() Paths {
791 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800792}
793
Colin Cross4157e882019-06-06 16:57:04 -0700794func (m *ModuleBase) NoAddressSanitizer() bool {
795 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800796}
797
Colin Cross4157e882019-06-06 16:57:04 -0700798func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800799 return false
800}
801
Colin Cross4157e882019-06-06 16:57:04 -0700802func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700803 return false
804}
805
Colin Cross4157e882019-06-06 16:57:04 -0700806func (m *ModuleBase) InstallInRecovery() bool {
807 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900808}
809
Colin Cross4157e882019-06-06 16:57:04 -0700810func (m *ModuleBase) Owner() string {
811 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900812}
813
Colin Cross4157e882019-06-06 16:57:04 -0700814func (m *ModuleBase) NoticeFile() OptionalPath {
815 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900816}
817
Colin Cross4157e882019-06-06 16:57:04 -0700818func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700819 allInstalledFiles := Paths{}
820 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800821 ctx.VisitAllModuleVariants(func(module Module) {
822 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700823 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
824 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800825 })
826
Colin Cross0875c522017-11-28 17:34:01 -0800827 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700828
Jeff Gaston088e29e2017-11-29 16:47:17 -0800829 namespacePrefix := ctx.Namespace().(*Namespace).id
830 if namespacePrefix != "" {
831 namespacePrefix = namespacePrefix + "-"
832 }
833
Colin Cross3f40fa42015-01-30 17:27:36 -0800834 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800835 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800836 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700837 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800838 Output: name,
839 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800840 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700841 })
842 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700843 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700844 }
845
846 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800847 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800848 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700849 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800850 Output: name,
851 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700852 })
853 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700854 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700855 }
856
857 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800858 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800859 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800860 suffix = "-soong"
861 }
862
Jeff Gaston088e29e2017-11-29 16:47:17 -0800863 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800864 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700865 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800866 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700867 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800868 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700869
Colin Cross4157e882019-06-06 16:57:04 -0700870 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800871 }
872}
873
Colin Cross4157e882019-06-06 16:57:04 -0700874func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
875 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
876 var deviceSpecific = Bool(m.commonProperties.Device_specific)
877 var productSpecific = Bool(m.commonProperties.Product_specific)
878 var productServicesSpecific = Bool(m.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900879
Dario Frenifd05a742018-05-29 13:28:54 +0100880 msg := "conflicting value set here"
881 if socSpecific && deviceSpecific {
882 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700883 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900884 ctx.PropertyErrorf("vendor", msg)
885 }
Colin Cross4157e882019-06-06 16:57:04 -0700886 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900887 ctx.PropertyErrorf("proprietary", msg)
888 }
Colin Cross4157e882019-06-06 16:57:04 -0700889 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900890 ctx.PropertyErrorf("soc_specific", msg)
891 }
892 }
893
Dario Frenifd05a742018-05-29 13:28:54 +0100894 if productSpecific && productServicesSpecific {
895 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
896 ctx.PropertyErrorf("product_services_specific", msg)
897 }
898
899 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
900 if productSpecific {
901 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
902 } else {
903 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
904 }
905 if deviceSpecific {
906 ctx.PropertyErrorf("device_specific", msg)
907 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700908 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100909 ctx.PropertyErrorf("vendor", msg)
910 }
Colin Cross4157e882019-06-06 16:57:04 -0700911 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100912 ctx.PropertyErrorf("proprietary", msg)
913 }
Colin Cross4157e882019-06-06 16:57:04 -0700914 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100915 ctx.PropertyErrorf("soc_specific", msg)
916 }
917 }
918 }
919
Jiyong Park2db76922017-11-08 16:03:48 +0900920 if productSpecific {
921 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100922 } else if productServicesSpecific {
923 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900924 } else if deviceSpecific {
925 return deviceSpecificModule
926 } else if socSpecific {
927 return socSpecificModule
928 } else {
929 return platformModule
930 }
931}
932
Colin Cross0ea8ba82019-06-06 14:33:29 -0700933func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
934 return baseModuleContext{
935 BaseModuleContext: ctx,
936 target: m.commonProperties.CompileTarget,
937 targetPrimary: m.commonProperties.CompilePrimary,
938 multiTargets: m.commonProperties.CompileMultiTargets,
939 kind: determineModuleKind(m, ctx),
940 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800941 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800942}
943
Colin Cross4157e882019-06-06 16:57:04 -0700944func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700945 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700946 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -0700947 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700948 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
949 installDeps: m.computeInstallDeps(blueprintCtx),
950 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700951 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800952 }
953
Colin Cross6c4f21f2019-06-06 15:41:36 -0700954 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
955 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
956 // TODO: This will be removed once defaults modules handle missing dependency errors
957 blueprintCtx.GetMissingDependencies()
958
Colin Crossdc35e212019-06-06 16:13:11 -0700959 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
960 // are enabled.
961 ctx.baseModuleContext.strictVisitDeps = true
962
Colin Cross4c83e5c2019-02-25 14:54:28 -0800963 if ctx.config.captureBuild {
964 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
965 }
966
Colin Cross67a5c132017-05-09 13:45:28 -0700967 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
968 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800969 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
970 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700971 }
Colin Cross0875c522017-11-28 17:34:01 -0800972 if !ctx.PrimaryArch() {
973 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700974 }
975
976 ctx.Variable(pctx, "moduleDesc", desc)
977
978 s := ""
979 if len(suffix) > 0 {
980 s = " [" + strings.Join(suffix, " ") + "]"
981 }
982 ctx.Variable(pctx, "moduleDescSuffix", s)
983
Dan Willemsen569edc52018-11-19 09:33:29 -0800984 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700985 if m.commonProperties.Dist.Dest != nil {
986 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800987 if err != nil {
988 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
989 }
990 }
Colin Cross4157e882019-06-06 16:57:04 -0700991 if m.commonProperties.Dist.Dir != nil {
992 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800993 if err != nil {
994 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
995 }
996 }
Colin Cross4157e882019-06-06 16:57:04 -0700997 if m.commonProperties.Dist.Suffix != nil {
998 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -0800999 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1000 }
1001 }
1002
Colin Cross4157e882019-06-06 16:57:04 -07001003 if m.Enabled() {
Colin Cross4157e882019-06-06 16:57:04 -07001004 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1005 if module := SrcIsModule(notice); module != "" {
1006 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001007 } else {
1008 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001009 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001010 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001011
1012 m.module.GenerateAndroidBuildActions(ctx)
1013 if ctx.Failed() {
1014 return
1015 }
1016
1017 m.installFiles = append(m.installFiles, ctx.installFiles...)
1018 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001019 } else if ctx.Config().AllowMissingDependencies() {
1020 // If the module is not enabled it will not create any build rules, nothing will call
1021 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1022 // and report them as an error even when AllowMissingDependencies = true. Call
1023 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1024 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001025 }
1026
Colin Cross4157e882019-06-06 16:57:04 -07001027 if m == ctx.FinalModule().(Module).base() {
1028 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001029 if ctx.Failed() {
1030 return
1031 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001032 }
Colin Crosscec81712017-07-13 14:43:27 -07001033
Colin Cross4157e882019-06-06 16:57:04 -07001034 m.buildParams = ctx.buildParams
1035 m.ruleParams = ctx.ruleParams
1036 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001037}
1038
Colin Cross0ea8ba82019-06-06 14:33:29 -07001039type baseModuleContext struct {
1040 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -07001041 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001042 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001043 targetPrimary bool
1044 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +09001045 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -07001046 config Config
Colin Crossdc35e212019-06-06 16:13:11 -07001047
1048 walkPath []Module
1049
1050 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001051}
1052
Colin Cross25de6c32019-06-06 14:29:25 -07001053type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001054 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001055 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001056 installDeps Paths
1057 installFiles Paths
1058 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001059 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001060
1061 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001062 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001063 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001064 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001065}
1066
Colin Crossb88b3c52019-06-10 15:15:17 -07001067func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1068 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001069 Rule: ErrorRule,
1070 Description: params.Description,
1071 Output: params.Output,
1072 Outputs: params.Outputs,
1073 ImplicitOutput: params.ImplicitOutput,
1074 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001075 Args: map[string]string{
1076 "error": err.Error(),
1077 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001078 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001079}
1080
Colin Cross25de6c32019-06-06 14:29:25 -07001081func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1082 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001083}
1084
Colin Cross0875c522017-11-28 17:34:01 -08001085func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001086 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001087 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001088 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001089 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001090 Outputs: params.Outputs.Strings(),
1091 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1092 Inputs: params.Inputs.Strings(),
1093 Implicits: params.Implicits.Strings(),
1094 OrderOnly: params.OrderOnly.Strings(),
1095 Args: params.Args,
1096 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001097 }
1098
Colin Cross33bfb0a2016-11-21 17:23:08 -08001099 if params.Depfile != nil {
1100 bparams.Depfile = params.Depfile.String()
1101 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001102 if params.Output != nil {
1103 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1104 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001105 if params.ImplicitOutput != nil {
1106 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1107 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001108 if params.Input != nil {
1109 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1110 }
1111 if params.Implicit != nil {
1112 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1113 }
1114
Colin Cross0b9f31f2019-02-28 11:00:01 -08001115 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1116 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1117 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1118 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1119 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1120 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001121
Colin Cross0875c522017-11-28 17:34:01 -08001122 return bparams
1123}
1124
Colin Cross25de6c32019-06-06 14:29:25 -07001125func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1126 if m.config.captureBuild {
1127 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001128 }
1129
Colin Crossdc35e212019-06-06 16:13:11 -07001130 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001131}
1132
Colin Cross25de6c32019-06-06 14:29:25 -07001133func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001134 argNames ...string) blueprint.Rule {
1135
Colin Crossdc35e212019-06-06 16:13:11 -07001136 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001137
Colin Cross25de6c32019-06-06 14:29:25 -07001138 if m.config.captureBuild {
1139 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001140 }
1141
1142 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001143}
1144
Colin Cross25de6c32019-06-06 14:29:25 -07001145func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001146 if params.Description != "" {
1147 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1148 }
1149
1150 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1151 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1152 m.ModuleName(), strings.Join(missingDeps, ", ")))
1153 }
1154
Colin Cross25de6c32019-06-06 14:29:25 -07001155 if m.config.captureBuild {
1156 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001157 }
1158
Colin Crossdc35e212019-06-06 16:13:11 -07001159 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001160}
1161
Colin Crossdc35e212019-06-06 16:13:11 -07001162func (b *baseModuleContext) Module() Module {
1163 module, _ := b.BaseModuleContext.Module().(Module)
1164 return module
1165}
1166
1167func (b *baseModuleContext) Config() Config {
1168 return b.BaseModuleContext.Config().(Config)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001169}
1170
Colin Cross25de6c32019-06-06 14:29:25 -07001171func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001172 var missingDeps []string
1173 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001174 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001175 missingDeps = FirstUniqueStrings(missingDeps)
1176 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001177}
1178
Colin Crossdc35e212019-06-06 16:13:11 -07001179func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001180 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001181 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001182 *missingDeps = append(*missingDeps, deps...)
1183 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001184 }
1185}
1186
Colin Crossdc35e212019-06-06 16:13:11 -07001187func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001188 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001189
1190 if !strict {
1191 return aModule
1192 }
1193
Colin Cross380c69a2019-06-10 17:49:58 +00001194 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001195 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001196 return nil
1197 }
1198
1199 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001200 if b.Config().AllowMissingDependencies() {
1201 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001202 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001203 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001204 }
1205 return nil
1206 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001207 return aModule
1208}
1209
Colin Crossdc35e212019-06-06 16:13:11 -07001210func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001211 type dep struct {
1212 mod blueprint.Module
1213 tag blueprint.DependencyTag
1214 }
1215 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001216 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001217 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Crossdc35e212019-06-06 16:13:11 -07001218 returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001219 if tag == nil || returnedTag == tag {
1220 deps = append(deps, dep{aModule, returnedTag})
1221 }
1222 }
1223 })
1224 if len(deps) == 1 {
1225 return deps[0].mod, deps[0].tag
1226 } else if len(deps) >= 2 {
1227 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001228 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001229 } else {
1230 return nil, nil
1231 }
1232}
1233
Colin Crossdc35e212019-06-06 16:13:11 -07001234func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001235 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001236 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001237 if aModule, _ := module.(Module); aModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001238 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001239 deps = append(deps, aModule)
1240 }
1241 }
1242 })
1243 return deps
1244}
1245
Colin Cross25de6c32019-06-06 14:29:25 -07001246func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1247 module, _ := m.getDirectDepInternal(name, tag)
1248 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001249}
1250
Colin Crossdc35e212019-06-06 16:13:11 -07001251func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1252 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001253}
1254
Colin Crossdc35e212019-06-06 16:13:11 -07001255func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1256 b.BaseModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001257}
1258
Colin Crossdc35e212019-06-06 16:13:11 -07001259func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
1260 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1261 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001262 visit(aModule)
1263 }
1264 })
1265}
1266
Colin Crossdc35e212019-06-06 16:13:11 -07001267func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1268 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1269 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
1270 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001271 visit(aModule)
1272 }
1273 }
1274 })
1275}
1276
Colin Crossdc35e212019-06-06 16:13:11 -07001277func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1278 b.BaseModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001279 // pred
1280 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001281 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001282 return pred(aModule)
1283 } else {
1284 return false
1285 }
1286 },
1287 // visit
1288 func(module blueprint.Module) {
1289 visit(module.(Module))
1290 })
1291}
1292
Colin Crossdc35e212019-06-06 16:13:11 -07001293func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1294 b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1295 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001296 visit(aModule)
1297 }
1298 })
1299}
1300
Colin Crossdc35e212019-06-06 16:13:11 -07001301func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1302 b.BaseModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001303 // pred
1304 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001305 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001306 return pred(aModule)
1307 } else {
1308 return false
1309 }
1310 },
1311 // visit
1312 func(module blueprint.Module) {
1313 visit(module.(Module))
1314 })
1315}
1316
Colin Crossdc35e212019-06-06 16:13:11 -07001317func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1318 b.BaseModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001319}
1320
Colin Crossdc35e212019-06-06 16:13:11 -07001321func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1322 b.walkPath = []Module{b.Module()}
1323 b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1324 childAndroidModule, _ := child.(Module)
1325 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001326 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001327 // record walkPath before visit
1328 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1329 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1330 }
1331 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001332 return visit(childAndroidModule, parentAndroidModule)
1333 } else {
1334 return false
1335 }
1336 })
1337}
1338
Colin Crossdc35e212019-06-06 16:13:11 -07001339func (b *baseModuleContext) GetWalkPath() []Module {
1340 return b.walkPath
1341}
1342
Colin Cross25de6c32019-06-06 14:29:25 -07001343func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001344 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001345 visit(module.(Module))
1346 })
1347}
1348
Colin Cross25de6c32019-06-06 14:29:25 -07001349func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001350 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001351}
1352
Colin Cross25de6c32019-06-06 14:29:25 -07001353func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001354 return m.bp.FinalModule().(Module)
1355}
1356
1357func (m *moduleContext) ModuleSubDir() string {
1358 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001359}
1360
Colin Cross0ea8ba82019-06-06 14:33:29 -07001361func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001362 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001363}
1364
Colin Cross0ea8ba82019-06-06 14:33:29 -07001365func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001366 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001367}
1368
Colin Cross0ea8ba82019-06-06 14:33:29 -07001369func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001370 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001371}
1372
Colin Cross0ea8ba82019-06-06 14:33:29 -07001373func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001374 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001375}
1376
Colin Cross0ea8ba82019-06-06 14:33:29 -07001377func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001378 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001379}
1380
Colin Cross0ea8ba82019-06-06 14:33:29 -07001381func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001382 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001383}
1384
Colin Cross0ea8ba82019-06-06 14:33:29 -07001385func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001386 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001387}
1388
Colin Cross0ea8ba82019-06-06 14:33:29 -07001389func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001390 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001391}
1392
Colin Cross0ea8ba82019-06-06 14:33:29 -07001393func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001394 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001395}
1396
Colin Cross0ea8ba82019-06-06 14:33:29 -07001397func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001398 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001399}
1400
Colin Cross0ea8ba82019-06-06 14:33:29 -07001401func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001402 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001403}
1404
Colin Cross0ea8ba82019-06-06 14:33:29 -07001405func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001406 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001407 return true
1408 }
Colin Cross25de6c32019-06-06 14:29:25 -07001409 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001410}
1411
Colin Cross0ea8ba82019-06-06 14:33:29 -07001412func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001413 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001414}
1415
Colin Cross0ea8ba82019-06-06 14:33:29 -07001416func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001417 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001418}
1419
Colin Cross0ea8ba82019-06-06 14:33:29 -07001420func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001421 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001422}
1423
Colin Cross0ea8ba82019-06-06 14:33:29 -07001424func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001425 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001426}
1427
Colin Cross0ea8ba82019-06-06 14:33:29 -07001428func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001429 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001430}
1431
Colin Cross0ea8ba82019-06-06 14:33:29 -07001432func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001433 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001434}
1435
Colin Cross0ea8ba82019-06-06 14:33:29 -07001436func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001437 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001438}
1439
Jiyong Park5baac542018-08-28 09:55:37 +09001440// Makes this module a platform module, i.e. not specific to soc, device,
1441// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001442func (m *ModuleBase) MakeAsPlatform() {
1443 m.commonProperties.Vendor = boolPtr(false)
1444 m.commonProperties.Proprietary = boolPtr(false)
1445 m.commonProperties.Soc_specific = boolPtr(false)
1446 m.commonProperties.Product_specific = boolPtr(false)
1447 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001448}
1449
Colin Cross4157e882019-06-06 16:57:04 -07001450func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1451 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001452}
1453
Colin Cross25de6c32019-06-06 14:29:25 -07001454func (m *moduleContext) InstallInData() bool {
1455 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001456}
1457
Colin Cross25de6c32019-06-06 14:29:25 -07001458func (m *moduleContext) InstallInSanitizerDir() bool {
1459 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001460}
1461
Colin Cross25de6c32019-06-06 14:29:25 -07001462func (m *moduleContext) InstallInRecovery() bool {
1463 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001464}
1465
Colin Cross25de6c32019-06-06 14:29:25 -07001466func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1467 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001468 return true
1469 }
1470
Colin Cross3607f212018-05-07 15:28:05 -07001471 // We'll need a solution for choosing which of modules with the same name in different
1472 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1473 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001474 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001475 return true
1476 }
1477
Colin Cross25de6c32019-06-06 14:29:25 -07001478 if m.Device() {
1479 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001480 return true
1481 }
1482
Colin Cross25de6c32019-06-06 14:29:25 -07001483 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001484 return true
1485 }
1486 }
1487
1488 return false
1489}
1490
Colin Cross25de6c32019-06-06 14:29:25 -07001491func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001492 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001493 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001494}
1495
Colin Cross25de6c32019-06-06 14:29:25 -07001496func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001497 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001498 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001499}
1500
Colin Cross25de6c32019-06-06 14:29:25 -07001501func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001502 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001503
Colin Cross25de6c32019-06-06 14:29:25 -07001504 fullInstallPath := installPath.Join(m, name)
1505 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001506
Colin Cross25de6c32019-06-06 14:29:25 -07001507 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001508
Colin Cross25de6c32019-06-06 14:29:25 -07001509 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001510
Colin Cross89562dc2016-10-03 17:47:19 -07001511 var implicitDeps, orderOnlyDeps Paths
1512
Colin Cross25de6c32019-06-06 14:29:25 -07001513 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001514 // Installed host modules might be used during the build, depend directly on their
1515 // dependencies so their timestamp is updated whenever their dependency is updated
1516 implicitDeps = deps
1517 } else {
1518 orderOnlyDeps = deps
1519 }
1520
Colin Cross25de6c32019-06-06 14:29:25 -07001521 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001522 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001523 Description: "install " + fullInstallPath.Base(),
1524 Output: fullInstallPath,
1525 Input: srcPath,
1526 Implicits: implicitDeps,
1527 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001528 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001529 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001530
Colin Cross25de6c32019-06-06 14:29:25 -07001531 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001532 }
Colin Cross25de6c32019-06-06 14:29:25 -07001533 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001534 return fullInstallPath
1535}
1536
Colin Cross25de6c32019-06-06 14:29:25 -07001537func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1538 fullInstallPath := installPath.Join(m, name)
1539 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001540
Colin Cross25de6c32019-06-06 14:29:25 -07001541 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001542
Alex Lightfb4353d2019-01-17 13:57:45 -08001543 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1544 if err != nil {
1545 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1546 }
Colin Cross25de6c32019-06-06 14:29:25 -07001547 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001548 Rule: Symlink,
1549 Description: "install symlink " + fullInstallPath.Base(),
1550 Output: fullInstallPath,
1551 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001552 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001553 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001554 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001555 },
1556 })
Colin Cross3854a602016-01-11 12:49:11 -08001557
Colin Cross25de6c32019-06-06 14:29:25 -07001558 m.installFiles = append(m.installFiles, fullInstallPath)
1559 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001560 }
Colin Cross3854a602016-01-11 12:49:11 -08001561 return fullInstallPath
1562}
1563
Jiyong Parkf1194352019-02-25 11:05:47 +09001564// installPath/name -> absPath where absPath might be a path that is available only at runtime
1565// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001566func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1567 fullInstallPath := installPath.Join(m, name)
1568 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001569
Colin Cross25de6c32019-06-06 14:29:25 -07001570 if !m.skipInstall(fullInstallPath) {
1571 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001572 Rule: Symlink,
1573 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1574 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001575 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001576 Args: map[string]string{
1577 "fromPath": absPath,
1578 },
1579 })
1580
Colin Cross25de6c32019-06-06 14:29:25 -07001581 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001582 }
1583 return fullInstallPath
1584}
1585
Colin Cross25de6c32019-06-06 14:29:25 -07001586func (m *moduleContext) CheckbuildFile(srcPath Path) {
1587 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001588}
1589
Colin Cross3f40fa42015-01-30 17:27:36 -08001590type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001591 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001592}
1593
1594func isFileInstaller(m blueprint.Module) bool {
1595 _, ok := m.(fileInstaller)
1596 return ok
1597}
1598
1599func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001600 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001601 return ok
1602}
Colin Crossfce53272015-04-08 11:21:40 -07001603
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001604func findStringInSlice(str string, slice []string) int {
1605 for i, s := range slice {
1606 if s == str {
1607 return i
Colin Crossfce53272015-04-08 11:21:40 -07001608 }
1609 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001610 return -1
1611}
1612
Colin Cross41955e82019-05-29 14:40:35 -07001613// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1614// was not a module reference.
1615func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001616 if len(s) > 1 && s[0] == ':' {
1617 return s[1:]
1618 }
1619 return ""
1620}
1621
Colin Cross41955e82019-05-29 14:40:35 -07001622// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1623// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1624func SrcIsModuleWithTag(s string) (module, tag string) {
1625 if len(s) > 1 && s[0] == ':' {
1626 module = s[1:]
1627 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1628 if module[len(module)-1] == '}' {
1629 tag = module[tagStart+1 : len(module)-1]
1630 module = module[:tagStart]
1631 return module, tag
1632 }
1633 }
1634 return module, ""
1635 }
1636 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001637}
1638
Colin Cross41955e82019-05-29 14:40:35 -07001639type sourceOrOutputDependencyTag struct {
1640 blueprint.BaseDependencyTag
1641 tag string
1642}
1643
1644func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1645 return sourceOrOutputDependencyTag{tag: tag}
1646}
1647
1648var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001649
Colin Cross366938f2017-12-11 16:29:02 -08001650// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1651// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001652//
1653// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001654func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001655 set := make(map[string]bool)
1656
Colin Cross068e0fe2016-12-13 15:23:47 -08001657 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001658 if m, t := SrcIsModuleWithTag(s); m != "" {
1659 if _, found := set[s]; found {
1660 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001661 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001662 set[s] = true
1663 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001664 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001665 }
1666 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001667}
1668
Colin Cross366938f2017-12-11 16:29:02 -08001669// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1670// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001671//
1672// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001673func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1674 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001675 if m, t := SrcIsModuleWithTag(*s); m != "" {
1676 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001677 }
1678 }
1679}
1680
Colin Cross41955e82019-05-29 14:40:35 -07001681// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1682// 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 -08001683type SourceFileProducer interface {
1684 Srcs() Paths
1685}
1686
Colin Cross41955e82019-05-29 14:40:35 -07001687// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1688// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1689// listed in the property.
1690type OutputFileProducer interface {
1691 OutputFiles(tag string) (Paths, error)
1692}
1693
Colin Crossfe17f6f2019-03-28 19:30:56 -07001694type HostToolProvider interface {
1695 HostToolPath() OptionalPath
1696}
1697
Colin Cross27b922f2019-03-04 22:35:41 -08001698// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1699// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001700//
1701// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001702func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1703 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001704}
1705
Colin Cross2fafa3e2019-03-05 12:39:51 -08001706// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1707// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001708//
1709// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001710func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1711 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001712}
1713
1714// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1715// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1716// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001717func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001718 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001719 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001720 }
1721 return OptionalPath{}
1722}
1723
Colin Cross25de6c32019-06-06 14:29:25 -07001724func (m *moduleContext) RequiredModuleNames() []string {
1725 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001726}
1727
Colin Cross25de6c32019-06-06 14:29:25 -07001728func (m *moduleContext) HostRequiredModuleNames() []string {
1729 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001730}
1731
Colin Cross25de6c32019-06-06 14:29:25 -07001732func (m *moduleContext) TargetRequiredModuleNames() []string {
1733 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001734}
1735
Colin Crossdc35e212019-06-06 16:13:11 -07001736func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths {
1737 ret, err := b.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001738 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001739 b.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001740 }
Colin Crossdc35e212019-06-06 16:13:11 -07001741 return pathsForModuleSrcFromFullPath(b, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001742}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001743
Colin Crossdc35e212019-06-06 16:13:11 -07001744func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1745 ret, err := b.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001746 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001747 b.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001748 }
Colin Crossdc35e212019-06-06 16:13:11 -07001749 return pathsForModuleSrcFromFullPath(b, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001750}
1751
Colin Cross463a90e2015-06-17 14:20:06 -07001752func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001753 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001754}
1755
Colin Cross0875c522017-11-28 17:34:01 -08001756func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001757 return &buildTargetSingleton{}
1758}
1759
Colin Cross87d8b562017-04-25 10:01:55 -07001760func parentDir(dir string) string {
1761 dir, _ = filepath.Split(dir)
1762 return filepath.Clean(dir)
1763}
1764
Colin Cross1f8c52b2015-06-16 16:38:17 -07001765type buildTargetSingleton struct{}
1766
Colin Cross0875c522017-11-28 17:34:01 -08001767func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1768 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001769
Colin Cross0875c522017-11-28 17:34:01 -08001770 mmTarget := func(dir string) WritablePath {
1771 return PathForPhony(ctx,
1772 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001773 }
1774
Colin Cross0875c522017-11-28 17:34:01 -08001775 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001776
Colin Cross0875c522017-11-28 17:34:01 -08001777 ctx.VisitAllModules(func(module Module) {
1778 blueprintDir := module.base().blueprintDir
1779 installTarget := module.base().installTarget
1780 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001781
Colin Cross0875c522017-11-28 17:34:01 -08001782 if checkbuildTarget != nil {
1783 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1784 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1785 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001786
Colin Cross0875c522017-11-28 17:34:01 -08001787 if installTarget != nil {
1788 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001789 }
1790 })
1791
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001792 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001793 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001794 suffix = "-soong"
1795 }
1796
Colin Cross1f8c52b2015-06-16 16:38:17 -07001797 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001798 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001799 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001800 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001801 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001802 })
1803
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001804 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001805 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001806 return
1807 }
1808
Colin Cross87d8b562017-04-25 10:01:55 -07001809 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001810 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001811 for _, dir := range dirs {
1812 dir := parentDir(dir)
1813 for dir != "." && dir != "/" {
1814 if _, exists := modulesInDir[dir]; exists {
1815 break
1816 }
1817 modulesInDir[dir] = nil
1818 dir = parentDir(dir)
1819 }
1820 }
1821
1822 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001823 for _, dir := range dirs {
1824 p := parentDir(dir)
1825 if p != "." && p != "/" {
1826 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1827 }
1828 }
1829
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001830 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1831 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1832 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001833 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001834 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001835 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001836 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001837 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001838 // HACK: checkbuild should be an optional build, but force it
1839 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001840 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001841 })
1842 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001843
1844 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1845 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001846 ctx.VisitAllModules(func(module Module) {
1847 if module.Enabled() {
1848 os := module.Target().Os
1849 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001850 }
1851 })
1852
Colin Cross0875c522017-11-28 17:34:01 -08001853 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001854 for os, deps := range osDeps {
1855 var className string
1856
1857 switch os.Class {
1858 case Host:
1859 className = "host"
1860 case HostCross:
1861 className = "host-cross"
1862 case Device:
1863 className = "target"
1864 default:
1865 continue
1866 }
1867
Colin Cross0875c522017-11-28 17:34:01 -08001868 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001869 osClass[className] = append(osClass[className], name)
1870
Colin Cross0875c522017-11-28 17:34:01 -08001871 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001872 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001873 Output: name,
1874 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001875 })
1876 }
1877
1878 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001879 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001880 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001881 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001882 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001883 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001884 })
1885 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001886}
Colin Crossd779da42015-12-17 18:00:23 -08001887
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001888// Collect information for opening IDE project files in java/jdeps.go.
1889type IDEInfo interface {
1890 IDEInfo(ideInfo *IdeInfo)
1891 BaseModuleName() string
1892}
1893
1894// Extract the base module name from the Import name.
1895// Often the Import name has a prefix "prebuilt_".
1896// Remove the prefix explicitly if needed
1897// until we find a better solution to get the Import name.
1898type IDECustomizedModuleName interface {
1899 IDECustomizedModuleName() string
1900}
1901
1902type IdeInfo struct {
1903 Deps []string `json:"dependencies,omitempty"`
1904 Srcs []string `json:"srcs,omitempty"`
1905 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1906 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1907 Jars []string `json:"jars,omitempty"`
1908 Classes []string `json:"class,omitempty"`
1909 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001910 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001911}