blob: b9127262e92b45c23aa17ce81367199adf100d8a [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
206 // Get the qualified module id for this module.
207 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
208
209 // Get information about the properties that can contain visibility rules.
210 visibilityProperties() []visibilityProperty
211}
212
213// Qualified id for a module
214type qualifiedModuleName struct {
215 // The package (i.e. directory) in which the module is defined, without trailing /
216 pkg string
217
218 // The name of the module, empty string if package.
219 name string
220}
221
222func (q qualifiedModuleName) String() string {
223 if q.name == "" {
224 return "//" + q.pkg
225 }
226 return "//" + q.pkg + ":" + q.name
227}
228
229// Get the id for the package containing this module.
230func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
231 pkg := q.pkg
232 if q.name == "" {
233 panic(fmt.Errorf("Cannot get containing package id of package module %s", pkg))
234 }
235 return newPackageId(pkg)
236}
237
238func newPackageId(pkg string) qualifiedModuleName {
239 // A qualified id for a package module has no name.
240 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800241}
242
Colin Crossfc754582016-05-17 16:34:16 -0700243type nameProperties struct {
244 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800245 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700246}
247
248type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800249 // emit build rules for this module
250 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800251
Paul Duffin2e61fa62019-03-28 14:10:57 +0000252 // Controls the visibility of this module to other modules. Allowable values are one or more of
253 // these formats:
254 //
255 // ["//visibility:public"]: Anyone can use this module.
256 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
257 // this module.
258 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
259 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
260 // this module. Note that sub-packages do not have access to the rule; for example,
261 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
262 // is a special module and must be used verbatim. It represents all of the modules in the
263 // package.
264 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
265 // or other or in one of their sub-packages have access to this module. For example,
266 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
267 // to depend on this rule (but not //independent:evil)
268 // ["//project"]: This is shorthand for ["//project:__pkg__"]
269 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
270 // //project is the module's package. e.g. using [":__subpackages__"] in
271 // packages/apps/Settings/Android.bp is equivalent to
272 // //packages/apps/Settings:__subpackages__.
273 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
274 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100275 //
276 // If a module does not specify the `visibility` property then it uses the
277 // `default_visibility` property of the `package` module in the module's package.
278 //
279 // If the `default_visibility` property is not set for the module's package then
280 // the module uses `//visibility:legacy_public`.
281 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000282 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
283 // more details.
284 Visibility []string
285
Colin Cross7d5136f2015-05-11 13:39:40 -0700286 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800287 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
288 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
289 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700290 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700291
292 Target struct {
293 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700294 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700295 }
296 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700297 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700298 }
299 }
300
Colin Crossee0bc3b2018-10-02 22:01:37 -0700301 UseTargetVariants bool `blueprint:"mutated"`
302 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800303
Dan Willemsen782a2d12015-12-21 14:55:28 -0800304 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700305 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800306
Colin Cross55708f32017-03-20 13:23:34 -0700307 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700308 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700309
Jiyong Park2db76922017-11-08 16:03:48 +0900310 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
311 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
312 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700313 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700314
Jiyong Park2db76922017-11-08 16:03:48 +0900315 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
316 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
317 Soc_specific *bool
318
319 // whether this module is specific to a device, not only for SoC, but also for off-chip
320 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
321 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
322 // This implies `soc_specific:true`.
323 Device_specific *bool
324
325 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900326 // network operator, etc). When set to true, it is installed into /product (or
327 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900328 Product_specific *bool
329
Dario Frenifd05a742018-05-29 13:28:54 +0100330 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100331 // to true, it is installed into /product_services (or /system/product_services if
332 // product_services partition does not exist).
333 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100334
Jiyong Parkf9332f12018-02-01 00:54:12 +0900335 // Whether this module is installed to recovery partition
336 Recovery *bool
337
dimitry1f33e402019-03-26 12:39:31 +0100338 // Whether this module is built for non-native architecures (also known as native bridge binary)
339 Native_bridge_supported *bool `android:"arch_variant"`
340
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700341 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800342 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700343
Steven Moreland57a23d22018-04-04 15:42:19 -0700344 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800345 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700346
Chris Wolfe998306e2016-08-15 14:47:23 -0400347 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700348 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400349
Sasha Smundakb6d23052019-04-01 18:37:36 -0700350 // names of other modules to install on host if this module is installed
351 Host_required []string `android:"arch_variant"`
352
353 // names of other modules to install on target if this module is installed
354 Target_required []string `android:"arch_variant"`
355
Colin Cross5aac3622017-08-31 15:07:09 -0700356 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800357 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700358
Dan Willemsen569edc52018-11-19 09:33:29 -0800359 Dist struct {
360 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
361 // command line and any of these targets are also on the command line, or otherwise
362 // built
363 Targets []string `android:"arch_variant"`
364
365 // The name of the output artifact. This defaults to the basename of the output of
366 // the module.
367 Dest *string `android:"arch_variant"`
368
369 // The directory within the dist directory to store the artifact. Defaults to the
370 // top level directory ("").
371 Dir *string `android:"arch_variant"`
372
373 // A suffix to add to the artifact file name (before any extension).
374 Suffix *string `android:"arch_variant"`
375 } `android:"arch_variant"`
376
Colin Crossa1ad8d12016-06-01 17:09:44 -0700377 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700378 CompileTarget Target `blueprint:"mutated"`
379 CompileMultiTargets []Target `blueprint:"mutated"`
380 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800381
382 // Set by InitAndroidModule
383 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700384 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700385
386 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800387
388 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700389
390 MissingDeps []string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800391}
392
393type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800394 // If set to true, build a variant of the module for the host. Defaults to false.
395 Host_supported *bool
396
397 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700398 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800399}
400
Colin Crossc472d572015-03-17 15:06:21 -0700401type Multilib string
402
403const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800404 MultilibBoth Multilib = "both"
405 MultilibFirst Multilib = "first"
406 MultilibCommon Multilib = "common"
407 MultilibCommonFirst Multilib = "common_first"
408 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700409)
410
Colin Crossa1ad8d12016-06-01 17:09:44 -0700411type HostOrDeviceSupported int
412
413const (
414 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700415
416 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700417 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700418
419 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700420 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700421
422 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700423 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700424
425 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700426 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700427
428 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700429 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700430
431 // Nothing is supported. This is not exposed to the user, but used to mark a
432 // host only module as unsupported when the module type is not supported on
433 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700434 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700435)
436
Jiyong Park2db76922017-11-08 16:03:48 +0900437type moduleKind int
438
439const (
440 platformModule moduleKind = iota
441 deviceSpecificModule
442 socSpecificModule
443 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100444 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900445)
446
447func (k moduleKind) String() string {
448 switch k {
449 case platformModule:
450 return "platform"
451 case deviceSpecificModule:
452 return "device-specific"
453 case socSpecificModule:
454 return "soc-specific"
455 case productSpecificModule:
456 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100457 case productServicesSpecificModule:
458 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900459 default:
460 panic(fmt.Errorf("unknown module kind %d", k))
461 }
462}
463
Colin Cross36242852017-06-23 15:06:31 -0700464func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800465 base := m.base()
466 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700467
Colin Cross36242852017-06-23 15:06:31 -0700468 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700469 &base.nameProperties,
470 &base.commonProperties,
471 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700472 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700473 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700474}
475
Colin Cross36242852017-06-23 15:06:31 -0700476func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
477 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700478
479 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800480 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700481 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700482 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700483 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800484
Dan Willemsen218f6562015-07-08 18:13:11 -0700485 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700486 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700487 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800488 }
489
Colin Cross36242852017-06-23 15:06:31 -0700490 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800491}
492
Colin Crossee0bc3b2018-10-02 22:01:37 -0700493func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
494 InitAndroidArchModule(m, hod, defaultMultilib)
495 m.base().commonProperties.UseTargetVariants = false
496}
497
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800498// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800499// modules. It should be included as an anonymous field in every module
500// struct definition. InitAndroidModule should then be called from the module's
501// factory function, and the return values from InitAndroidModule should be
502// returned from the factory function.
503//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800504// The ModuleBase type is responsible for implementing the GenerateBuildActions
505// method to support the blueprint.Module interface. This method will then call
506// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700507// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
508// rather than the usual blueprint.ModuleContext.
509// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800510// system including details about the particular build variant that is to be
511// generated.
512//
513// For example:
514//
515// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800516// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800517// )
518//
519// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800520// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800521// properties struct {
522// MyProperty string
523// }
524// }
525//
Colin Cross36242852017-06-23 15:06:31 -0700526// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800527// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700528// m.AddProperties(&m.properties)
529// android.InitAndroidModule(m)
530// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800531// }
532//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800533// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800534// // Get the CPU architecture for the current build variant.
535// variantArch := ctx.Arch()
536//
537// // ...
538// }
Colin Cross635c3b02016-05-18 15:37:25 -0700539type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800540 // Putting the curiously recurring thing pointing to the thing that contains
541 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700542 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700543 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800544
Colin Crossfc754582016-05-17 16:34:16 -0700545 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800546 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700547 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800548 hostAndDeviceProperties hostAndDeviceProperties
549 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700550 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700551 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800552
553 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700554 installFiles Paths
555 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900556 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700557
558 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
559 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800560 installTarget WritablePath
561 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700562 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700563
Colin Cross178a5092016-09-13 13:42:32 -0700564 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700565
566 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700567
568 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700569 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800570 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800571 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700572
573 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700574}
575
Colin Cross4157e882019-06-06 16:57:04 -0700576func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800577
Colin Cross4157e882019-06-06 16:57:04 -0700578func (m *ModuleBase) AddProperties(props ...interface{}) {
579 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700580}
581
Colin Cross4157e882019-06-06 16:57:04 -0700582func (m *ModuleBase) GetProperties() []interface{} {
583 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800584}
585
Colin Cross4157e882019-06-06 16:57:04 -0700586func (m *ModuleBase) BuildParamsForTests() []BuildParams {
587 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700588}
589
Colin Cross4157e882019-06-06 16:57:04 -0700590func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
591 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800592}
593
Colin Cross4157e882019-06-06 16:57:04 -0700594func (m *ModuleBase) VariablesForTests() map[string]string {
595 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800596}
597
Colin Cross4157e882019-06-06 16:57:04 -0700598func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
599 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700600}
601
Colin Crossce75d2c2016-10-06 16:12:58 -0700602// Name returns the name of the module. It may be overridden by individual module types, for
603// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700604func (m *ModuleBase) Name() string {
605 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700606}
607
Colin Crossce75d2c2016-10-06 16:12:58 -0700608// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700609func (m *ModuleBase) BaseModuleName() string {
610 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700611}
612
Colin Cross4157e882019-06-06 16:57:04 -0700613func (m *ModuleBase) base() *ModuleBase {
614 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800615}
616
Paul Duffine2453c72019-05-31 14:00:04 +0100617func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
618 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
619}
620
621func (m *ModuleBase) visibilityProperties() []visibilityProperty {
622 return []visibilityProperty{
623 newVisibilityProperty("visibility", func() []string {
624 return m.base().commonProperties.Visibility
625 }),
626 }
627}
628
Colin Cross4157e882019-06-06 16:57:04 -0700629func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
630 m.commonProperties.CompileTarget = target
631 m.commonProperties.CompileMultiTargets = multiTargets
632 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700633}
634
Colin Cross4157e882019-06-06 16:57:04 -0700635func (m *ModuleBase) Target() Target {
636 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800637}
638
Colin Cross4157e882019-06-06 16:57:04 -0700639func (m *ModuleBase) TargetPrimary() bool {
640 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700641}
642
Colin Cross4157e882019-06-06 16:57:04 -0700643func (m *ModuleBase) MultiTargets() []Target {
644 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700645}
646
Colin Cross4157e882019-06-06 16:57:04 -0700647func (m *ModuleBase) Os() OsType {
648 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800649}
650
Colin Cross4157e882019-06-06 16:57:04 -0700651func (m *ModuleBase) Host() bool {
652 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800653}
654
Colin Cross4157e882019-06-06 16:57:04 -0700655func (m *ModuleBase) Arch() Arch {
656 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800657}
658
Colin Cross4157e882019-06-06 16:57:04 -0700659func (m *ModuleBase) ArchSpecific() bool {
660 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700661}
662
Colin Cross4157e882019-06-06 16:57:04 -0700663func (m *ModuleBase) OsClassSupported() []OsClass {
664 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700665 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700666 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700667 case HostSupportedNoCross:
668 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700669 case DeviceSupported:
670 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700671 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700672 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700673 if Bool(m.hostAndDeviceProperties.Host_supported) ||
674 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
675 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700676 supported = append(supported, Host, HostCross)
677 }
Colin Cross4157e882019-06-06 16:57:04 -0700678 if m.hostAndDeviceProperties.Device_supported == nil ||
679 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700680 supported = append(supported, Device)
681 }
682 return supported
683 default:
684 return nil
685 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800686}
687
Colin Cross4157e882019-06-06 16:57:04 -0700688func (m *ModuleBase) DeviceSupported() bool {
689 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
690 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
691 (m.hostAndDeviceProperties.Device_supported == nil ||
692 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800693}
694
Colin Cross4157e882019-06-06 16:57:04 -0700695func (m *ModuleBase) Platform() bool {
696 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900697}
698
Colin Cross4157e882019-06-06 16:57:04 -0700699func (m *ModuleBase) DeviceSpecific() bool {
700 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900701}
702
Colin Cross4157e882019-06-06 16:57:04 -0700703func (m *ModuleBase) SocSpecific() bool {
704 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900705}
706
Colin Cross4157e882019-06-06 16:57:04 -0700707func (m *ModuleBase) ProductSpecific() bool {
708 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900709}
710
Colin Cross4157e882019-06-06 16:57:04 -0700711func (m *ModuleBase) ProductServicesSpecific() bool {
712 return Bool(m.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100713}
714
Colin Cross4157e882019-06-06 16:57:04 -0700715func (m *ModuleBase) Enabled() bool {
716 if m.commonProperties.Enabled == nil {
717 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800718 }
Colin Cross4157e882019-06-06 16:57:04 -0700719 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800720}
721
Colin Cross4157e882019-06-06 16:57:04 -0700722func (m *ModuleBase) SkipInstall() {
723 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700724}
725
Colin Cross4157e882019-06-06 16:57:04 -0700726func (m *ModuleBase) ExportedToMake() bool {
727 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900728}
729
Colin Cross4157e882019-06-06 16:57:04 -0700730func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700731 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800732
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700733 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700734 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800735 ctx.VisitDepsDepthFirstIf(isFileInstaller,
736 func(m blueprint.Module) {
737 fileInstaller := m.(fileInstaller)
738 files := fileInstaller.filesToInstall()
739 result = append(result, files...)
740 })
741
742 return result
743}
744
Colin Cross4157e882019-06-06 16:57:04 -0700745func (m *ModuleBase) filesToInstall() Paths {
746 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800747}
748
Colin Cross4157e882019-06-06 16:57:04 -0700749func (m *ModuleBase) NoAddressSanitizer() bool {
750 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800751}
752
Colin Cross4157e882019-06-06 16:57:04 -0700753func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800754 return false
755}
756
Colin Cross4157e882019-06-06 16:57:04 -0700757func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700758 return false
759}
760
Colin Cross4157e882019-06-06 16:57:04 -0700761func (m *ModuleBase) InstallInRecovery() bool {
762 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900763}
764
Colin Cross4157e882019-06-06 16:57:04 -0700765func (m *ModuleBase) Owner() string {
766 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900767}
768
Colin Cross4157e882019-06-06 16:57:04 -0700769func (m *ModuleBase) NoticeFile() OptionalPath {
770 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900771}
772
Colin Cross4157e882019-06-06 16:57:04 -0700773func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700774 allInstalledFiles := Paths{}
775 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800776 ctx.VisitAllModuleVariants(func(module Module) {
777 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700778 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
779 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800780 })
781
Colin Cross0875c522017-11-28 17:34:01 -0800782 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700783
Jeff Gaston088e29e2017-11-29 16:47:17 -0800784 namespacePrefix := ctx.Namespace().(*Namespace).id
785 if namespacePrefix != "" {
786 namespacePrefix = namespacePrefix + "-"
787 }
788
Colin Cross3f40fa42015-01-30 17:27:36 -0800789 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800790 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800791 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700792 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800793 Output: name,
794 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800795 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700796 })
797 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700798 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700799 }
800
801 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800802 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800803 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700804 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800805 Output: name,
806 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700807 })
808 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700809 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700810 }
811
812 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800813 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800814 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800815 suffix = "-soong"
816 }
817
Jeff Gaston088e29e2017-11-29 16:47:17 -0800818 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800819 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700820 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800821 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700822 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800823 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700824
Colin Cross4157e882019-06-06 16:57:04 -0700825 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800826 }
827}
828
Colin Cross4157e882019-06-06 16:57:04 -0700829func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
830 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
831 var deviceSpecific = Bool(m.commonProperties.Device_specific)
832 var productSpecific = Bool(m.commonProperties.Product_specific)
833 var productServicesSpecific = Bool(m.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900834
Dario Frenifd05a742018-05-29 13:28:54 +0100835 msg := "conflicting value set here"
836 if socSpecific && deviceSpecific {
837 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700838 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900839 ctx.PropertyErrorf("vendor", msg)
840 }
Colin Cross4157e882019-06-06 16:57:04 -0700841 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900842 ctx.PropertyErrorf("proprietary", msg)
843 }
Colin Cross4157e882019-06-06 16:57:04 -0700844 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900845 ctx.PropertyErrorf("soc_specific", msg)
846 }
847 }
848
Dario Frenifd05a742018-05-29 13:28:54 +0100849 if productSpecific && productServicesSpecific {
850 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
851 ctx.PropertyErrorf("product_services_specific", msg)
852 }
853
854 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
855 if productSpecific {
856 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
857 } else {
858 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
859 }
860 if deviceSpecific {
861 ctx.PropertyErrorf("device_specific", msg)
862 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700863 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100864 ctx.PropertyErrorf("vendor", msg)
865 }
Colin Cross4157e882019-06-06 16:57:04 -0700866 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100867 ctx.PropertyErrorf("proprietary", msg)
868 }
Colin Cross4157e882019-06-06 16:57:04 -0700869 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100870 ctx.PropertyErrorf("soc_specific", msg)
871 }
872 }
873 }
874
Jiyong Park2db76922017-11-08 16:03:48 +0900875 if productSpecific {
876 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100877 } else if productServicesSpecific {
878 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900879 } else if deviceSpecific {
880 return deviceSpecificModule
881 } else if socSpecific {
882 return socSpecificModule
883 } else {
884 return platformModule
885 }
886}
887
Colin Cross0ea8ba82019-06-06 14:33:29 -0700888func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
889 return baseModuleContext{
890 BaseModuleContext: ctx,
891 target: m.commonProperties.CompileTarget,
892 targetPrimary: m.commonProperties.CompilePrimary,
893 multiTargets: m.commonProperties.CompileMultiTargets,
894 kind: determineModuleKind(m, ctx),
895 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800896 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800897}
898
Colin Cross4157e882019-06-06 16:57:04 -0700899func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700900 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700901 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -0700902 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700903 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
904 installDeps: m.computeInstallDeps(blueprintCtx),
905 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700906 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800907 }
908
Colin Cross6c4f21f2019-06-06 15:41:36 -0700909 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
910 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
911 // TODO: This will be removed once defaults modules handle missing dependency errors
912 blueprintCtx.GetMissingDependencies()
913
Colin Crossdc35e212019-06-06 16:13:11 -0700914 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
915 // are enabled.
916 ctx.baseModuleContext.strictVisitDeps = true
917
Colin Cross4c83e5c2019-02-25 14:54:28 -0800918 if ctx.config.captureBuild {
919 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
920 }
921
Colin Cross67a5c132017-05-09 13:45:28 -0700922 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
923 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800924 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
925 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700926 }
Colin Cross0875c522017-11-28 17:34:01 -0800927 if !ctx.PrimaryArch() {
928 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700929 }
930
931 ctx.Variable(pctx, "moduleDesc", desc)
932
933 s := ""
934 if len(suffix) > 0 {
935 s = " [" + strings.Join(suffix, " ") + "]"
936 }
937 ctx.Variable(pctx, "moduleDescSuffix", s)
938
Dan Willemsen569edc52018-11-19 09:33:29 -0800939 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700940 if m.commonProperties.Dist.Dest != nil {
941 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800942 if err != nil {
943 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
944 }
945 }
Colin Cross4157e882019-06-06 16:57:04 -0700946 if m.commonProperties.Dist.Dir != nil {
947 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800948 if err != nil {
949 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
950 }
951 }
Colin Cross4157e882019-06-06 16:57:04 -0700952 if m.commonProperties.Dist.Suffix != nil {
953 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -0800954 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
955 }
956 }
957
Colin Cross4157e882019-06-06 16:57:04 -0700958 if m.Enabled() {
Colin Cross4157e882019-06-06 16:57:04 -0700959 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
960 if module := SrcIsModule(notice); module != "" {
961 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +0900962 } else {
963 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -0700964 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800965 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700966
967 m.module.GenerateAndroidBuildActions(ctx)
968 if ctx.Failed() {
969 return
970 }
971
972 m.installFiles = append(m.installFiles, ctx.installFiles...)
973 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -0700974 } else if ctx.Config().AllowMissingDependencies() {
975 // If the module is not enabled it will not create any build rules, nothing will call
976 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
977 // and report them as an error even when AllowMissingDependencies = true. Call
978 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
979 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -0800980 }
981
Colin Cross4157e882019-06-06 16:57:04 -0700982 if m == ctx.FinalModule().(Module).base() {
983 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700984 if ctx.Failed() {
985 return
986 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800987 }
Colin Crosscec81712017-07-13 14:43:27 -0700988
Colin Cross4157e882019-06-06 16:57:04 -0700989 m.buildParams = ctx.buildParams
990 m.ruleParams = ctx.ruleParams
991 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800992}
993
Colin Cross0ea8ba82019-06-06 14:33:29 -0700994type baseModuleContext struct {
995 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -0700996 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700997 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700998 targetPrimary bool
999 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +09001000 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -07001001 config Config
Colin Crossdc35e212019-06-06 16:13:11 -07001002
1003 walkPath []Module
1004
1005 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001006}
1007
Colin Cross25de6c32019-06-06 14:29:25 -07001008type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001009 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001010 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001011 installDeps Paths
1012 installFiles Paths
1013 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001014 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001015
1016 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001017 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001018 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001019 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001020}
1021
Colin Crossb88b3c52019-06-10 15:15:17 -07001022func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1023 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001024 Rule: ErrorRule,
1025 Description: params.Description,
1026 Output: params.Output,
1027 Outputs: params.Outputs,
1028 ImplicitOutput: params.ImplicitOutput,
1029 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001030 Args: map[string]string{
1031 "error": err.Error(),
1032 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001033 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001034}
1035
Colin Cross25de6c32019-06-06 14:29:25 -07001036func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1037 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001038}
1039
Colin Cross0875c522017-11-28 17:34:01 -08001040func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001041 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001042 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001043 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001044 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001045 Outputs: params.Outputs.Strings(),
1046 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1047 Inputs: params.Inputs.Strings(),
1048 Implicits: params.Implicits.Strings(),
1049 OrderOnly: params.OrderOnly.Strings(),
1050 Args: params.Args,
1051 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001052 }
1053
Colin Cross33bfb0a2016-11-21 17:23:08 -08001054 if params.Depfile != nil {
1055 bparams.Depfile = params.Depfile.String()
1056 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001057 if params.Output != nil {
1058 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1059 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001060 if params.ImplicitOutput != nil {
1061 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1062 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001063 if params.Input != nil {
1064 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1065 }
1066 if params.Implicit != nil {
1067 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1068 }
1069
Colin Cross0b9f31f2019-02-28 11:00:01 -08001070 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1071 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1072 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1073 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1074 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1075 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001076
Colin Cross0875c522017-11-28 17:34:01 -08001077 return bparams
1078}
1079
Colin Cross25de6c32019-06-06 14:29:25 -07001080func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1081 if m.config.captureBuild {
1082 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001083 }
1084
Colin Crossdc35e212019-06-06 16:13:11 -07001085 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001086}
1087
Colin Cross25de6c32019-06-06 14:29:25 -07001088func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001089 argNames ...string) blueprint.Rule {
1090
Colin Crossdc35e212019-06-06 16:13:11 -07001091 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001092
Colin Cross25de6c32019-06-06 14:29:25 -07001093 if m.config.captureBuild {
1094 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001095 }
1096
1097 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001098}
1099
Colin Cross25de6c32019-06-06 14:29:25 -07001100func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001101 if params.Description != "" {
1102 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1103 }
1104
1105 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1106 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1107 m.ModuleName(), strings.Join(missingDeps, ", ")))
1108 }
1109
Colin Cross25de6c32019-06-06 14:29:25 -07001110 if m.config.captureBuild {
1111 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001112 }
1113
Colin Crossdc35e212019-06-06 16:13:11 -07001114 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001115}
1116
Colin Crossdc35e212019-06-06 16:13:11 -07001117func (b *baseModuleContext) Module() Module {
1118 module, _ := b.BaseModuleContext.Module().(Module)
1119 return module
1120}
1121
1122func (b *baseModuleContext) Config() Config {
1123 return b.BaseModuleContext.Config().(Config)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001124}
1125
Colin Cross25de6c32019-06-06 14:29:25 -07001126func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001127 var missingDeps []string
1128 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001129 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001130 missingDeps = FirstUniqueStrings(missingDeps)
1131 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001132}
1133
Colin Crossdc35e212019-06-06 16:13:11 -07001134func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001135 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001136 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001137 *missingDeps = append(*missingDeps, deps...)
1138 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001139 }
1140}
1141
Colin Crossdc35e212019-06-06 16:13:11 -07001142func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001143 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001144
1145 if !strict {
1146 return aModule
1147 }
1148
Colin Cross380c69a2019-06-10 17:49:58 +00001149 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001150 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001151 return nil
1152 }
1153
1154 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001155 if b.Config().AllowMissingDependencies() {
1156 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001157 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001158 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001159 }
1160 return nil
1161 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001162 return aModule
1163}
1164
Colin Crossdc35e212019-06-06 16:13:11 -07001165func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001166 type dep struct {
1167 mod blueprint.Module
1168 tag blueprint.DependencyTag
1169 }
1170 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001171 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001172 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Crossdc35e212019-06-06 16:13:11 -07001173 returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001174 if tag == nil || returnedTag == tag {
1175 deps = append(deps, dep{aModule, returnedTag})
1176 }
1177 }
1178 })
1179 if len(deps) == 1 {
1180 return deps[0].mod, deps[0].tag
1181 } else if len(deps) >= 2 {
1182 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001183 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001184 } else {
1185 return nil, nil
1186 }
1187}
1188
Colin Crossdc35e212019-06-06 16:13:11 -07001189func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001190 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001191 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001192 if aModule, _ := module.(Module); aModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001193 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001194 deps = append(deps, aModule)
1195 }
1196 }
1197 })
1198 return deps
1199}
1200
Colin Cross25de6c32019-06-06 14:29:25 -07001201func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1202 module, _ := m.getDirectDepInternal(name, tag)
1203 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001204}
1205
Colin Crossdc35e212019-06-06 16:13:11 -07001206func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1207 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001208}
1209
Colin Crossdc35e212019-06-06 16:13:11 -07001210func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1211 b.BaseModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001212}
1213
Colin Crossdc35e212019-06-06 16:13:11 -07001214func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
1215 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1216 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001217 visit(aModule)
1218 }
1219 })
1220}
1221
Colin Crossdc35e212019-06-06 16:13:11 -07001222func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1223 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1224 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
1225 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001226 visit(aModule)
1227 }
1228 }
1229 })
1230}
1231
Colin Crossdc35e212019-06-06 16:13:11 -07001232func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1233 b.BaseModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001234 // pred
1235 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001236 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001237 return pred(aModule)
1238 } else {
1239 return false
1240 }
1241 },
1242 // visit
1243 func(module blueprint.Module) {
1244 visit(module.(Module))
1245 })
1246}
1247
Colin Crossdc35e212019-06-06 16:13:11 -07001248func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1249 b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1250 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001251 visit(aModule)
1252 }
1253 })
1254}
1255
Colin Crossdc35e212019-06-06 16:13:11 -07001256func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1257 b.BaseModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001258 // pred
1259 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001260 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001261 return pred(aModule)
1262 } else {
1263 return false
1264 }
1265 },
1266 // visit
1267 func(module blueprint.Module) {
1268 visit(module.(Module))
1269 })
1270}
1271
Colin Crossdc35e212019-06-06 16:13:11 -07001272func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1273 b.BaseModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001274}
1275
Colin Crossdc35e212019-06-06 16:13:11 -07001276func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1277 b.walkPath = []Module{b.Module()}
1278 b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1279 childAndroidModule, _ := child.(Module)
1280 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001281 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001282 // record walkPath before visit
1283 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1284 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1285 }
1286 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001287 return visit(childAndroidModule, parentAndroidModule)
1288 } else {
1289 return false
1290 }
1291 })
1292}
1293
Colin Crossdc35e212019-06-06 16:13:11 -07001294func (b *baseModuleContext) GetWalkPath() []Module {
1295 return b.walkPath
1296}
1297
Colin Cross25de6c32019-06-06 14:29:25 -07001298func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001299 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001300 visit(module.(Module))
1301 })
1302}
1303
Colin Cross25de6c32019-06-06 14:29:25 -07001304func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001305 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001306}
1307
Colin Cross25de6c32019-06-06 14:29:25 -07001308func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001309 return m.bp.FinalModule().(Module)
1310}
1311
1312func (m *moduleContext) ModuleSubDir() string {
1313 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001314}
1315
Colin Cross0ea8ba82019-06-06 14:33:29 -07001316func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001317 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001318}
1319
Colin Cross0ea8ba82019-06-06 14:33:29 -07001320func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001321 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001322}
1323
Colin Cross0ea8ba82019-06-06 14:33:29 -07001324func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001325 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001326}
1327
Colin Cross0ea8ba82019-06-06 14:33:29 -07001328func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001329 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001330}
1331
Colin Cross0ea8ba82019-06-06 14:33:29 -07001332func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001333 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001334}
1335
Colin Cross0ea8ba82019-06-06 14:33:29 -07001336func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001337 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001338}
1339
Colin Cross0ea8ba82019-06-06 14:33:29 -07001340func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001341 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001342}
1343
Colin Cross0ea8ba82019-06-06 14:33:29 -07001344func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001345 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001346}
1347
Colin Cross0ea8ba82019-06-06 14:33:29 -07001348func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001349 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001350}
1351
Colin Cross0ea8ba82019-06-06 14:33:29 -07001352func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001353 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001354}
1355
Colin Cross0ea8ba82019-06-06 14:33:29 -07001356func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001357 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001358}
1359
Colin Cross0ea8ba82019-06-06 14:33:29 -07001360func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001361 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001362 return true
1363 }
Colin Cross25de6c32019-06-06 14:29:25 -07001364 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001365}
1366
Colin Cross0ea8ba82019-06-06 14:33:29 -07001367func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001368 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001369}
1370
Colin Cross0ea8ba82019-06-06 14:33:29 -07001371func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001372 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001373}
1374
Colin Cross0ea8ba82019-06-06 14:33:29 -07001375func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001376 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001377}
1378
Colin Cross0ea8ba82019-06-06 14:33:29 -07001379func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001380 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001381}
1382
Colin Cross0ea8ba82019-06-06 14:33:29 -07001383func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001384 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001385}
1386
Colin Cross0ea8ba82019-06-06 14:33:29 -07001387func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001388 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001389}
1390
Colin Cross0ea8ba82019-06-06 14:33:29 -07001391func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001392 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001393}
1394
Jiyong Park5baac542018-08-28 09:55:37 +09001395// Makes this module a platform module, i.e. not specific to soc, device,
1396// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001397func (m *ModuleBase) MakeAsPlatform() {
1398 m.commonProperties.Vendor = boolPtr(false)
1399 m.commonProperties.Proprietary = boolPtr(false)
1400 m.commonProperties.Soc_specific = boolPtr(false)
1401 m.commonProperties.Product_specific = boolPtr(false)
1402 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001403}
1404
Colin Cross4157e882019-06-06 16:57:04 -07001405func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1406 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001407}
1408
Colin Cross25de6c32019-06-06 14:29:25 -07001409func (m *moduleContext) InstallInData() bool {
1410 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001411}
1412
Colin Cross25de6c32019-06-06 14:29:25 -07001413func (m *moduleContext) InstallInSanitizerDir() bool {
1414 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001415}
1416
Colin Cross25de6c32019-06-06 14:29:25 -07001417func (m *moduleContext) InstallInRecovery() bool {
1418 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001419}
1420
Colin Cross25de6c32019-06-06 14:29:25 -07001421func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1422 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001423 return true
1424 }
1425
Colin Cross3607f212018-05-07 15:28:05 -07001426 // We'll need a solution for choosing which of modules with the same name in different
1427 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1428 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001429 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001430 return true
1431 }
1432
Colin Cross25de6c32019-06-06 14:29:25 -07001433 if m.Device() {
1434 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001435 return true
1436 }
1437
Colin Cross25de6c32019-06-06 14:29:25 -07001438 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001439 return true
1440 }
1441 }
1442
1443 return false
1444}
1445
Colin Cross25de6c32019-06-06 14:29:25 -07001446func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001447 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001448 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001449}
1450
Colin Cross25de6c32019-06-06 14:29:25 -07001451func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001452 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001453 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001454}
1455
Colin Cross25de6c32019-06-06 14:29:25 -07001456func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001457 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001458
Colin Cross25de6c32019-06-06 14:29:25 -07001459 fullInstallPath := installPath.Join(m, name)
1460 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001461
Colin Cross25de6c32019-06-06 14:29:25 -07001462 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001463
Colin Cross25de6c32019-06-06 14:29:25 -07001464 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001465
Colin Cross89562dc2016-10-03 17:47:19 -07001466 var implicitDeps, orderOnlyDeps Paths
1467
Colin Cross25de6c32019-06-06 14:29:25 -07001468 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001469 // Installed host modules might be used during the build, depend directly on their
1470 // dependencies so their timestamp is updated whenever their dependency is updated
1471 implicitDeps = deps
1472 } else {
1473 orderOnlyDeps = deps
1474 }
1475
Colin Cross25de6c32019-06-06 14:29:25 -07001476 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001477 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001478 Description: "install " + fullInstallPath.Base(),
1479 Output: fullInstallPath,
1480 Input: srcPath,
1481 Implicits: implicitDeps,
1482 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001483 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001484 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001485
Colin Cross25de6c32019-06-06 14:29:25 -07001486 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001487 }
Colin Cross25de6c32019-06-06 14:29:25 -07001488 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001489 return fullInstallPath
1490}
1491
Colin Cross25de6c32019-06-06 14:29:25 -07001492func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1493 fullInstallPath := installPath.Join(m, name)
1494 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001495
Colin Cross25de6c32019-06-06 14:29:25 -07001496 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001497
Alex Lightfb4353d2019-01-17 13:57:45 -08001498 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1499 if err != nil {
1500 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1501 }
Colin Cross25de6c32019-06-06 14:29:25 -07001502 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001503 Rule: Symlink,
1504 Description: "install symlink " + fullInstallPath.Base(),
1505 Output: fullInstallPath,
1506 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001507 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001508 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001509 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001510 },
1511 })
Colin Cross3854a602016-01-11 12:49:11 -08001512
Colin Cross25de6c32019-06-06 14:29:25 -07001513 m.installFiles = append(m.installFiles, fullInstallPath)
1514 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001515 }
Colin Cross3854a602016-01-11 12:49:11 -08001516 return fullInstallPath
1517}
1518
Jiyong Parkf1194352019-02-25 11:05:47 +09001519// installPath/name -> absPath where absPath might be a path that is available only at runtime
1520// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001521func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1522 fullInstallPath := installPath.Join(m, name)
1523 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001524
Colin Cross25de6c32019-06-06 14:29:25 -07001525 if !m.skipInstall(fullInstallPath) {
1526 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001527 Rule: Symlink,
1528 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1529 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001530 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001531 Args: map[string]string{
1532 "fromPath": absPath,
1533 },
1534 })
1535
Colin Cross25de6c32019-06-06 14:29:25 -07001536 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001537 }
1538 return fullInstallPath
1539}
1540
Colin Cross25de6c32019-06-06 14:29:25 -07001541func (m *moduleContext) CheckbuildFile(srcPath Path) {
1542 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001543}
1544
Colin Cross3f40fa42015-01-30 17:27:36 -08001545type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001546 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001547}
1548
1549func isFileInstaller(m blueprint.Module) bool {
1550 _, ok := m.(fileInstaller)
1551 return ok
1552}
1553
1554func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001555 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001556 return ok
1557}
Colin Crossfce53272015-04-08 11:21:40 -07001558
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001559func findStringInSlice(str string, slice []string) int {
1560 for i, s := range slice {
1561 if s == str {
1562 return i
Colin Crossfce53272015-04-08 11:21:40 -07001563 }
1564 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001565 return -1
1566}
1567
Colin Cross41955e82019-05-29 14:40:35 -07001568// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1569// was not a module reference.
1570func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001571 if len(s) > 1 && s[0] == ':' {
1572 return s[1:]
1573 }
1574 return ""
1575}
1576
Colin Cross41955e82019-05-29 14:40:35 -07001577// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1578// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1579func SrcIsModuleWithTag(s string) (module, tag string) {
1580 if len(s) > 1 && s[0] == ':' {
1581 module = s[1:]
1582 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1583 if module[len(module)-1] == '}' {
1584 tag = module[tagStart+1 : len(module)-1]
1585 module = module[:tagStart]
1586 return module, tag
1587 }
1588 }
1589 return module, ""
1590 }
1591 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001592}
1593
Colin Cross41955e82019-05-29 14:40:35 -07001594type sourceOrOutputDependencyTag struct {
1595 blueprint.BaseDependencyTag
1596 tag string
1597}
1598
1599func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1600 return sourceOrOutputDependencyTag{tag: tag}
1601}
1602
1603var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001604
Colin Cross366938f2017-12-11 16:29:02 -08001605// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1606// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001607//
1608// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001609func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001610 set := make(map[string]bool)
1611
Colin Cross068e0fe2016-12-13 15:23:47 -08001612 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001613 if m, t := SrcIsModuleWithTag(s); m != "" {
1614 if _, found := set[s]; found {
1615 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001616 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001617 set[s] = true
1618 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001619 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001620 }
1621 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001622}
1623
Colin Cross366938f2017-12-11 16:29:02 -08001624// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1625// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001626//
1627// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001628func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1629 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001630 if m, t := SrcIsModuleWithTag(*s); m != "" {
1631 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001632 }
1633 }
1634}
1635
Colin Cross41955e82019-05-29 14:40:35 -07001636// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1637// 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 -08001638type SourceFileProducer interface {
1639 Srcs() Paths
1640}
1641
Colin Cross41955e82019-05-29 14:40:35 -07001642// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1643// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1644// listed in the property.
1645type OutputFileProducer interface {
1646 OutputFiles(tag string) (Paths, error)
1647}
1648
Colin Crossfe17f6f2019-03-28 19:30:56 -07001649type HostToolProvider interface {
1650 HostToolPath() OptionalPath
1651}
1652
Colin Cross27b922f2019-03-04 22:35:41 -08001653// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1654// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001655//
1656// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001657func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1658 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001659}
1660
Colin Cross2fafa3e2019-03-05 12:39:51 -08001661// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1662// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001663//
1664// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001665func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1666 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001667}
1668
1669// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1670// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1671// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001672func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001673 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001674 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001675 }
1676 return OptionalPath{}
1677}
1678
Colin Cross25de6c32019-06-06 14:29:25 -07001679func (m *moduleContext) RequiredModuleNames() []string {
1680 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001681}
1682
Colin Cross25de6c32019-06-06 14:29:25 -07001683func (m *moduleContext) HostRequiredModuleNames() []string {
1684 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001685}
1686
Colin Cross25de6c32019-06-06 14:29:25 -07001687func (m *moduleContext) TargetRequiredModuleNames() []string {
1688 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001689}
1690
Colin Crossdc35e212019-06-06 16:13:11 -07001691func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths {
1692 ret, err := b.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001693 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001694 b.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001695 }
Colin Crossdc35e212019-06-06 16:13:11 -07001696 return pathsForModuleSrcFromFullPath(b, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001697}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001698
Colin Crossdc35e212019-06-06 16:13:11 -07001699func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1700 ret, err := b.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001701 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001702 b.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001703 }
Colin Crossdc35e212019-06-06 16:13:11 -07001704 return pathsForModuleSrcFromFullPath(b, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001705}
1706
Colin Cross463a90e2015-06-17 14:20:06 -07001707func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001708 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001709}
1710
Colin Cross0875c522017-11-28 17:34:01 -08001711func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001712 return &buildTargetSingleton{}
1713}
1714
Colin Cross87d8b562017-04-25 10:01:55 -07001715func parentDir(dir string) string {
1716 dir, _ = filepath.Split(dir)
1717 return filepath.Clean(dir)
1718}
1719
Colin Cross1f8c52b2015-06-16 16:38:17 -07001720type buildTargetSingleton struct{}
1721
Colin Cross0875c522017-11-28 17:34:01 -08001722func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1723 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001724
Colin Cross0875c522017-11-28 17:34:01 -08001725 mmTarget := func(dir string) WritablePath {
1726 return PathForPhony(ctx,
1727 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001728 }
1729
Colin Cross0875c522017-11-28 17:34:01 -08001730 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001731
Colin Cross0875c522017-11-28 17:34:01 -08001732 ctx.VisitAllModules(func(module Module) {
1733 blueprintDir := module.base().blueprintDir
1734 installTarget := module.base().installTarget
1735 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001736
Colin Cross0875c522017-11-28 17:34:01 -08001737 if checkbuildTarget != nil {
1738 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1739 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1740 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001741
Colin Cross0875c522017-11-28 17:34:01 -08001742 if installTarget != nil {
1743 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001744 }
1745 })
1746
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001747 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001748 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001749 suffix = "-soong"
1750 }
1751
Colin Cross1f8c52b2015-06-16 16:38:17 -07001752 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001753 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001754 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001755 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001756 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001757 })
1758
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001759 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001760 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001761 return
1762 }
1763
Colin Cross87d8b562017-04-25 10:01:55 -07001764 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001765 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001766 for _, dir := range dirs {
1767 dir := parentDir(dir)
1768 for dir != "." && dir != "/" {
1769 if _, exists := modulesInDir[dir]; exists {
1770 break
1771 }
1772 modulesInDir[dir] = nil
1773 dir = parentDir(dir)
1774 }
1775 }
1776
1777 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001778 for _, dir := range dirs {
1779 p := parentDir(dir)
1780 if p != "." && p != "/" {
1781 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1782 }
1783 }
1784
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001785 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1786 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1787 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001788 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001789 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001790 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001791 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001792 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001793 // HACK: checkbuild should be an optional build, but force it
1794 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001795 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001796 })
1797 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001798
1799 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1800 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001801 ctx.VisitAllModules(func(module Module) {
1802 if module.Enabled() {
1803 os := module.Target().Os
1804 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001805 }
1806 })
1807
Colin Cross0875c522017-11-28 17:34:01 -08001808 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001809 for os, deps := range osDeps {
1810 var className string
1811
1812 switch os.Class {
1813 case Host:
1814 className = "host"
1815 case HostCross:
1816 className = "host-cross"
1817 case Device:
1818 className = "target"
1819 default:
1820 continue
1821 }
1822
Colin Cross0875c522017-11-28 17:34:01 -08001823 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001824 osClass[className] = append(osClass[className], name)
1825
Colin Cross0875c522017-11-28 17:34:01 -08001826 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001827 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001828 Output: name,
1829 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001830 })
1831 }
1832
1833 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001834 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001835 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001836 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001837 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001838 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001839 })
1840 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001841}
Colin Crossd779da42015-12-17 18:00:23 -08001842
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001843// Collect information for opening IDE project files in java/jdeps.go.
1844type IDEInfo interface {
1845 IDEInfo(ideInfo *IdeInfo)
1846 BaseModuleName() string
1847}
1848
1849// Extract the base module name from the Import name.
1850// Often the Import name has a prefix "prebuilt_".
1851// Remove the prefix explicitly if needed
1852// until we find a better solution to get the Import name.
1853type IDECustomizedModuleName interface {
1854 IDECustomizedModuleName() string
1855}
1856
1857type IdeInfo struct {
1858 Deps []string `json:"dependencies,omitempty"`
1859 Srcs []string `json:"srcs,omitempty"`
1860 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1861 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1862 Jars []string `json:"jars,omitempty"`
1863 Classes []string `json:"class,omitempty"`
1864 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001865 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001866}