blob: 03993e5198b0f18eb8bdb3334d684a0845e3fd4c [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
Colin Cross3f40fa42015-01-30 17:27:36 -0800205}
206
Colin Crossfc754582016-05-17 16:34:16 -0700207type nameProperties struct {
208 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800209 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700210}
211
212type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800213 // emit build rules for this module
214 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800215
Paul Duffin2e61fa62019-03-28 14:10:57 +0000216 // Controls the visibility of this module to other modules. Allowable values are one or more of
217 // these formats:
218 //
219 // ["//visibility:public"]: Anyone can use this module.
220 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
221 // this module.
222 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
223 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
224 // this module. Note that sub-packages do not have access to the rule; for example,
225 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
226 // is a special module and must be used verbatim. It represents all of the modules in the
227 // package.
228 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
229 // or other or in one of their sub-packages have access to this module. For example,
230 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
231 // to depend on this rule (but not //independent:evil)
232 // ["//project"]: This is shorthand for ["//project:__pkg__"]
233 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
234 // //project is the module's package. e.g. using [":__subpackages__"] in
235 // packages/apps/Settings/Android.bp is equivalent to
236 // //packages/apps/Settings:__subpackages__.
237 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
238 // for now. It is an error if it is used in a module.
239 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
240 // more details.
241 Visibility []string
242
Colin Cross7d5136f2015-05-11 13:39:40 -0700243 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800244 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
245 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
246 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700247 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700248
249 Target struct {
250 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700251 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700252 }
253 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700254 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700255 }
256 }
257
Colin Crossee0bc3b2018-10-02 22:01:37 -0700258 UseTargetVariants bool `blueprint:"mutated"`
259 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800260
Dan Willemsen782a2d12015-12-21 14:55:28 -0800261 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700262 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800263
Colin Cross55708f32017-03-20 13:23:34 -0700264 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700265 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700266
Jiyong Park2db76922017-11-08 16:03:48 +0900267 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
268 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
269 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700270 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700271
Jiyong Park2db76922017-11-08 16:03:48 +0900272 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
273 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
274 Soc_specific *bool
275
276 // whether this module is specific to a device, not only for SoC, but also for off-chip
277 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
278 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
279 // This implies `soc_specific:true`.
280 Device_specific *bool
281
282 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900283 // network operator, etc). When set to true, it is installed into /product (or
284 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900285 Product_specific *bool
286
Dario Frenifd05a742018-05-29 13:28:54 +0100287 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100288 // to true, it is installed into /product_services (or /system/product_services if
289 // product_services partition does not exist).
290 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100291
Jiyong Parkf9332f12018-02-01 00:54:12 +0900292 // Whether this module is installed to recovery partition
293 Recovery *bool
294
dimitry1f33e402019-03-26 12:39:31 +0100295 // Whether this module is built for non-native architecures (also known as native bridge binary)
296 Native_bridge_supported *bool `android:"arch_variant"`
297
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700298 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800299 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700300
Steven Moreland57a23d22018-04-04 15:42:19 -0700301 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800302 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700303
Chris Wolfe998306e2016-08-15 14:47:23 -0400304 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700305 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400306
Sasha Smundakb6d23052019-04-01 18:37:36 -0700307 // names of other modules to install on host if this module is installed
308 Host_required []string `android:"arch_variant"`
309
310 // names of other modules to install on target if this module is installed
311 Target_required []string `android:"arch_variant"`
312
Colin Cross5aac3622017-08-31 15:07:09 -0700313 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800314 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700315
Dan Willemsen569edc52018-11-19 09:33:29 -0800316 Dist struct {
317 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
318 // command line and any of these targets are also on the command line, or otherwise
319 // built
320 Targets []string `android:"arch_variant"`
321
322 // The name of the output artifact. This defaults to the basename of the output of
323 // the module.
324 Dest *string `android:"arch_variant"`
325
326 // The directory within the dist directory to store the artifact. Defaults to the
327 // top level directory ("").
328 Dir *string `android:"arch_variant"`
329
330 // A suffix to add to the artifact file name (before any extension).
331 Suffix *string `android:"arch_variant"`
332 } `android:"arch_variant"`
333
Colin Crossa1ad8d12016-06-01 17:09:44 -0700334 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700335 CompileTarget Target `blueprint:"mutated"`
336 CompileMultiTargets []Target `blueprint:"mutated"`
337 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800338
339 // Set by InitAndroidModule
340 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700341 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700342
343 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800344
345 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700346
347 MissingDeps []string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800348}
349
350type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800351 // If set to true, build a variant of the module for the host. Defaults to false.
352 Host_supported *bool
353
354 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700355 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800356}
357
Colin Crossc472d572015-03-17 15:06:21 -0700358type Multilib string
359
360const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800361 MultilibBoth Multilib = "both"
362 MultilibFirst Multilib = "first"
363 MultilibCommon Multilib = "common"
364 MultilibCommonFirst Multilib = "common_first"
365 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700366)
367
Colin Crossa1ad8d12016-06-01 17:09:44 -0700368type HostOrDeviceSupported int
369
370const (
371 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700372
373 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700374 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700375
376 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700377 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700378
379 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700380 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700381
382 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700383 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700384
385 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700386 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700387
388 // Nothing is supported. This is not exposed to the user, but used to mark a
389 // host only module as unsupported when the module type is not supported on
390 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700391 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700392)
393
Jiyong Park2db76922017-11-08 16:03:48 +0900394type moduleKind int
395
396const (
397 platformModule moduleKind = iota
398 deviceSpecificModule
399 socSpecificModule
400 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100401 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900402)
403
404func (k moduleKind) String() string {
405 switch k {
406 case platformModule:
407 return "platform"
408 case deviceSpecificModule:
409 return "device-specific"
410 case socSpecificModule:
411 return "soc-specific"
412 case productSpecificModule:
413 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100414 case productServicesSpecificModule:
415 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900416 default:
417 panic(fmt.Errorf("unknown module kind %d", k))
418 }
419}
420
Colin Cross36242852017-06-23 15:06:31 -0700421func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800422 base := m.base()
423 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700424
Colin Cross36242852017-06-23 15:06:31 -0700425 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700426 &base.nameProperties,
427 &base.commonProperties,
428 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700429 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700430 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700431}
432
Colin Cross36242852017-06-23 15:06:31 -0700433func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
434 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700435
436 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800437 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700438 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700439 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700440 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800441
Dan Willemsen218f6562015-07-08 18:13:11 -0700442 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700443 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700444 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800445 }
446
Colin Cross36242852017-06-23 15:06:31 -0700447 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800448}
449
Colin Crossee0bc3b2018-10-02 22:01:37 -0700450func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
451 InitAndroidArchModule(m, hod, defaultMultilib)
452 m.base().commonProperties.UseTargetVariants = false
453}
454
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800455// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800456// modules. It should be included as an anonymous field in every module
457// struct definition. InitAndroidModule should then be called from the module's
458// factory function, and the return values from InitAndroidModule should be
459// returned from the factory function.
460//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800461// The ModuleBase type is responsible for implementing the GenerateBuildActions
462// method to support the blueprint.Module interface. This method will then call
463// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700464// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
465// rather than the usual blueprint.ModuleContext.
466// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800467// system including details about the particular build variant that is to be
468// generated.
469//
470// For example:
471//
472// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800473// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800474// )
475//
476// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800477// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800478// properties struct {
479// MyProperty string
480// }
481// }
482//
Colin Cross36242852017-06-23 15:06:31 -0700483// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800484// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700485// m.AddProperties(&m.properties)
486// android.InitAndroidModule(m)
487// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800488// }
489//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800490// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800491// // Get the CPU architecture for the current build variant.
492// variantArch := ctx.Arch()
493//
494// // ...
495// }
Colin Cross635c3b02016-05-18 15:37:25 -0700496type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800497 // Putting the curiously recurring thing pointing to the thing that contains
498 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700499 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700500 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800501
Colin Crossfc754582016-05-17 16:34:16 -0700502 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800503 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700504 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800505 hostAndDeviceProperties hostAndDeviceProperties
506 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700507 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700508 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800509
510 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700511 installFiles Paths
512 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900513 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700514
515 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
516 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800517 installTarget WritablePath
518 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700519 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700520
Colin Cross178a5092016-09-13 13:42:32 -0700521 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700522
523 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700524
525 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700526 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800527 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800528 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700529
530 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700531}
532
Colin Cross4157e882019-06-06 16:57:04 -0700533func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800534
Colin Cross4157e882019-06-06 16:57:04 -0700535func (m *ModuleBase) AddProperties(props ...interface{}) {
536 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700537}
538
Colin Cross4157e882019-06-06 16:57:04 -0700539func (m *ModuleBase) GetProperties() []interface{} {
540 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800541}
542
Colin Cross4157e882019-06-06 16:57:04 -0700543func (m *ModuleBase) BuildParamsForTests() []BuildParams {
544 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700545}
546
Colin Cross4157e882019-06-06 16:57:04 -0700547func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
548 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800549}
550
Colin Cross4157e882019-06-06 16:57:04 -0700551func (m *ModuleBase) VariablesForTests() map[string]string {
552 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800553}
554
Colin Cross4157e882019-06-06 16:57:04 -0700555func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
556 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700557}
558
Colin Crossce75d2c2016-10-06 16:12:58 -0700559// Name returns the name of the module. It may be overridden by individual module types, for
560// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700561func (m *ModuleBase) Name() string {
562 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700563}
564
Colin Crossce75d2c2016-10-06 16:12:58 -0700565// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700566func (m *ModuleBase) BaseModuleName() string {
567 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700568}
569
Colin Cross4157e882019-06-06 16:57:04 -0700570func (m *ModuleBase) base() *ModuleBase {
571 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800572}
573
Colin Cross4157e882019-06-06 16:57:04 -0700574func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
575 m.commonProperties.CompileTarget = target
576 m.commonProperties.CompileMultiTargets = multiTargets
577 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700578}
579
Colin Cross4157e882019-06-06 16:57:04 -0700580func (m *ModuleBase) Target() Target {
581 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800582}
583
Colin Cross4157e882019-06-06 16:57:04 -0700584func (m *ModuleBase) TargetPrimary() bool {
585 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700586}
587
Colin Cross4157e882019-06-06 16:57:04 -0700588func (m *ModuleBase) MultiTargets() []Target {
589 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700590}
591
Colin Cross4157e882019-06-06 16:57:04 -0700592func (m *ModuleBase) Os() OsType {
593 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800594}
595
Colin Cross4157e882019-06-06 16:57:04 -0700596func (m *ModuleBase) Host() bool {
597 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800598}
599
Colin Cross4157e882019-06-06 16:57:04 -0700600func (m *ModuleBase) Arch() Arch {
601 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800602}
603
Colin Cross4157e882019-06-06 16:57:04 -0700604func (m *ModuleBase) ArchSpecific() bool {
605 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700606}
607
Colin Cross4157e882019-06-06 16:57:04 -0700608func (m *ModuleBase) OsClassSupported() []OsClass {
609 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700610 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700611 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700612 case HostSupportedNoCross:
613 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700614 case DeviceSupported:
615 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700616 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700617 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700618 if Bool(m.hostAndDeviceProperties.Host_supported) ||
619 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
620 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700621 supported = append(supported, Host, HostCross)
622 }
Colin Cross4157e882019-06-06 16:57:04 -0700623 if m.hostAndDeviceProperties.Device_supported == nil ||
624 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700625 supported = append(supported, Device)
626 }
627 return supported
628 default:
629 return nil
630 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800631}
632
Colin Cross4157e882019-06-06 16:57:04 -0700633func (m *ModuleBase) DeviceSupported() bool {
634 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
635 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
636 (m.hostAndDeviceProperties.Device_supported == nil ||
637 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800638}
639
Colin Cross4157e882019-06-06 16:57:04 -0700640func (m *ModuleBase) Platform() bool {
641 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900642}
643
Colin Cross4157e882019-06-06 16:57:04 -0700644func (m *ModuleBase) DeviceSpecific() bool {
645 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900646}
647
Colin Cross4157e882019-06-06 16:57:04 -0700648func (m *ModuleBase) SocSpecific() bool {
649 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900650}
651
Colin Cross4157e882019-06-06 16:57:04 -0700652func (m *ModuleBase) ProductSpecific() bool {
653 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900654}
655
Colin Cross4157e882019-06-06 16:57:04 -0700656func (m *ModuleBase) ProductServicesSpecific() bool {
657 return Bool(m.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100658}
659
Colin Cross4157e882019-06-06 16:57:04 -0700660func (m *ModuleBase) Enabled() bool {
661 if m.commonProperties.Enabled == nil {
662 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800663 }
Colin Cross4157e882019-06-06 16:57:04 -0700664 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800665}
666
Colin Cross4157e882019-06-06 16:57:04 -0700667func (m *ModuleBase) SkipInstall() {
668 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700669}
670
Colin Cross4157e882019-06-06 16:57:04 -0700671func (m *ModuleBase) ExportedToMake() bool {
672 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900673}
674
Colin Cross4157e882019-06-06 16:57:04 -0700675func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700676 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800677
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700678 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700679 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800680 ctx.VisitDepsDepthFirstIf(isFileInstaller,
681 func(m blueprint.Module) {
682 fileInstaller := m.(fileInstaller)
683 files := fileInstaller.filesToInstall()
684 result = append(result, files...)
685 })
686
687 return result
688}
689
Colin Cross4157e882019-06-06 16:57:04 -0700690func (m *ModuleBase) filesToInstall() Paths {
691 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800692}
693
Colin Cross4157e882019-06-06 16:57:04 -0700694func (m *ModuleBase) NoAddressSanitizer() bool {
695 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800696}
697
Colin Cross4157e882019-06-06 16:57:04 -0700698func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800699 return false
700}
701
Colin Cross4157e882019-06-06 16:57:04 -0700702func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700703 return false
704}
705
Colin Cross4157e882019-06-06 16:57:04 -0700706func (m *ModuleBase) InstallInRecovery() bool {
707 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900708}
709
Colin Cross4157e882019-06-06 16:57:04 -0700710func (m *ModuleBase) Owner() string {
711 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900712}
713
Colin Cross4157e882019-06-06 16:57:04 -0700714func (m *ModuleBase) NoticeFile() OptionalPath {
715 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900716}
717
Colin Cross4157e882019-06-06 16:57:04 -0700718func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700719 allInstalledFiles := Paths{}
720 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800721 ctx.VisitAllModuleVariants(func(module Module) {
722 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700723 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
724 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800725 })
726
Colin Cross0875c522017-11-28 17:34:01 -0800727 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700728
Jeff Gaston088e29e2017-11-29 16:47:17 -0800729 namespacePrefix := ctx.Namespace().(*Namespace).id
730 if namespacePrefix != "" {
731 namespacePrefix = namespacePrefix + "-"
732 }
733
Colin Cross3f40fa42015-01-30 17:27:36 -0800734 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800735 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800736 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700737 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800738 Output: name,
739 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800740 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700741 })
742 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700743 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700744 }
745
746 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800747 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800748 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700749 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800750 Output: name,
751 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700752 })
753 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700754 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700755 }
756
757 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800758 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800759 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800760 suffix = "-soong"
761 }
762
Jeff Gaston088e29e2017-11-29 16:47:17 -0800763 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800764 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700765 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800766 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700767 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800768 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700769
Colin Cross4157e882019-06-06 16:57:04 -0700770 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800771 }
772}
773
Colin Cross4157e882019-06-06 16:57:04 -0700774func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
775 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
776 var deviceSpecific = Bool(m.commonProperties.Device_specific)
777 var productSpecific = Bool(m.commonProperties.Product_specific)
778 var productServicesSpecific = Bool(m.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900779
Dario Frenifd05a742018-05-29 13:28:54 +0100780 msg := "conflicting value set here"
781 if socSpecific && deviceSpecific {
782 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700783 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900784 ctx.PropertyErrorf("vendor", msg)
785 }
Colin Cross4157e882019-06-06 16:57:04 -0700786 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900787 ctx.PropertyErrorf("proprietary", msg)
788 }
Colin Cross4157e882019-06-06 16:57:04 -0700789 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900790 ctx.PropertyErrorf("soc_specific", msg)
791 }
792 }
793
Dario Frenifd05a742018-05-29 13:28:54 +0100794 if productSpecific && productServicesSpecific {
795 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
796 ctx.PropertyErrorf("product_services_specific", msg)
797 }
798
799 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
800 if productSpecific {
801 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
802 } else {
803 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
804 }
805 if deviceSpecific {
806 ctx.PropertyErrorf("device_specific", msg)
807 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700808 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100809 ctx.PropertyErrorf("vendor", msg)
810 }
Colin Cross4157e882019-06-06 16:57:04 -0700811 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100812 ctx.PropertyErrorf("proprietary", msg)
813 }
Colin Cross4157e882019-06-06 16:57:04 -0700814 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100815 ctx.PropertyErrorf("soc_specific", msg)
816 }
817 }
818 }
819
Jiyong Park2db76922017-11-08 16:03:48 +0900820 if productSpecific {
821 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100822 } else if productServicesSpecific {
823 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900824 } else if deviceSpecific {
825 return deviceSpecificModule
826 } else if socSpecific {
827 return socSpecificModule
828 } else {
829 return platformModule
830 }
831}
832
Colin Cross0ea8ba82019-06-06 14:33:29 -0700833func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
834 return baseModuleContext{
835 BaseModuleContext: ctx,
836 target: m.commonProperties.CompileTarget,
837 targetPrimary: m.commonProperties.CompilePrimary,
838 multiTargets: m.commonProperties.CompileMultiTargets,
839 kind: determineModuleKind(m, ctx),
840 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800841 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800842}
843
Colin Cross4157e882019-06-06 16:57:04 -0700844func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700845 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700846 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -0700847 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700848 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
849 installDeps: m.computeInstallDeps(blueprintCtx),
850 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700851 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800852 }
853
Colin Cross6c4f21f2019-06-06 15:41:36 -0700854 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
855 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
856 // TODO: This will be removed once defaults modules handle missing dependency errors
857 blueprintCtx.GetMissingDependencies()
858
Colin Crossdc35e212019-06-06 16:13:11 -0700859 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
860 // are enabled.
861 ctx.baseModuleContext.strictVisitDeps = true
862
Colin Cross4c83e5c2019-02-25 14:54:28 -0800863 if ctx.config.captureBuild {
864 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
865 }
866
Colin Cross67a5c132017-05-09 13:45:28 -0700867 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
868 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800869 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
870 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700871 }
Colin Cross0875c522017-11-28 17:34:01 -0800872 if !ctx.PrimaryArch() {
873 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700874 }
875
876 ctx.Variable(pctx, "moduleDesc", desc)
877
878 s := ""
879 if len(suffix) > 0 {
880 s = " [" + strings.Join(suffix, " ") + "]"
881 }
882 ctx.Variable(pctx, "moduleDescSuffix", s)
883
Dan Willemsen569edc52018-11-19 09:33:29 -0800884 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700885 if m.commonProperties.Dist.Dest != nil {
886 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800887 if err != nil {
888 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
889 }
890 }
Colin Cross4157e882019-06-06 16:57:04 -0700891 if m.commonProperties.Dist.Dir != nil {
892 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800893 if err != nil {
894 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
895 }
896 }
Colin Cross4157e882019-06-06 16:57:04 -0700897 if m.commonProperties.Dist.Suffix != nil {
898 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -0800899 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
900 }
901 }
902
Colin Cross4157e882019-06-06 16:57:04 -0700903 if m.Enabled() {
904 m.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700905 if ctx.Failed() {
906 return
907 }
908
Colin Cross4157e882019-06-06 16:57:04 -0700909 m.installFiles = append(m.installFiles, ctx.installFiles...)
910 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800911
Colin Cross4157e882019-06-06 16:57:04 -0700912 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
913 if module := SrcIsModule(notice); module != "" {
914 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +0900915 } else {
916 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -0700917 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800918 }
Colin Crossdc35e212019-06-06 16:13:11 -0700919 } else if ctx.Config().AllowMissingDependencies() {
920 // If the module is not enabled it will not create any build rules, nothing will call
921 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
922 // and report them as an error even when AllowMissingDependencies = true. Call
923 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
924 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -0800925 }
926
Colin Cross4157e882019-06-06 16:57:04 -0700927 if m == ctx.FinalModule().(Module).base() {
928 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700929 if ctx.Failed() {
930 return
931 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800932 }
Colin Crosscec81712017-07-13 14:43:27 -0700933
Colin Cross4157e882019-06-06 16:57:04 -0700934 m.buildParams = ctx.buildParams
935 m.ruleParams = ctx.ruleParams
936 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800937}
938
Colin Cross0ea8ba82019-06-06 14:33:29 -0700939type baseModuleContext struct {
940 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -0700941 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700942 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700943 targetPrimary bool
944 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900945 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700946 config Config
Colin Crossdc35e212019-06-06 16:13:11 -0700947
948 walkPath []Module
949
950 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -0700951}
952
Colin Cross25de6c32019-06-06 14:29:25 -0700953type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700954 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700955 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700956 installDeps Paths
957 installFiles Paths
958 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -0700959 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700960
961 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700962 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800963 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800964 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800965}
966
Colin Crossb88b3c52019-06-10 15:15:17 -0700967func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
968 return pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700969 Rule: ErrorRule,
Colin Crossb88b3c52019-06-10 15:15:17 -0700970 Description: params.Description,
971 Output: params.Output,
972 Outputs: params.Outputs,
Colin Cross6ff51382015-12-17 16:39:19 -0800973 Args: map[string]string{
974 "error": err.Error(),
975 },
Colin Crossb88b3c52019-06-10 15:15:17 -0700976 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800977}
978
Colin Cross25de6c32019-06-06 14:29:25 -0700979func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
980 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800981}
982
Colin Cross0875c522017-11-28 17:34:01 -0800983func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700984 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700985 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800986 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800987 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700988 Outputs: params.Outputs.Strings(),
989 ImplicitOutputs: params.ImplicitOutputs.Strings(),
990 Inputs: params.Inputs.Strings(),
991 Implicits: params.Implicits.Strings(),
992 OrderOnly: params.OrderOnly.Strings(),
993 Args: params.Args,
994 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700995 }
996
Colin Cross33bfb0a2016-11-21 17:23:08 -0800997 if params.Depfile != nil {
998 bparams.Depfile = params.Depfile.String()
999 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001000 if params.Output != nil {
1001 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1002 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001003 if params.ImplicitOutput != nil {
1004 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1005 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001006 if params.Input != nil {
1007 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1008 }
1009 if params.Implicit != nil {
1010 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1011 }
1012
Colin Cross0b9f31f2019-02-28 11:00:01 -08001013 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1014 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1015 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1016 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1017 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1018 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001019
Colin Cross0875c522017-11-28 17:34:01 -08001020 return bparams
1021}
1022
Colin Cross25de6c32019-06-06 14:29:25 -07001023func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1024 if m.config.captureBuild {
1025 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001026 }
1027
Colin Crossdc35e212019-06-06 16:13:11 -07001028 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001029}
1030
Colin Cross25de6c32019-06-06 14:29:25 -07001031func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001032 argNames ...string) blueprint.Rule {
1033
Colin Crossdc35e212019-06-06 16:13:11 -07001034 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001035
Colin Cross25de6c32019-06-06 14:29:25 -07001036 if m.config.captureBuild {
1037 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001038 }
1039
1040 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001041}
1042
Colin Cross25de6c32019-06-06 14:29:25 -07001043func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001044 if params.Description != "" {
1045 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1046 }
1047
1048 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1049 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1050 m.ModuleName(), strings.Join(missingDeps, ", ")))
1051 }
1052
Colin Cross25de6c32019-06-06 14:29:25 -07001053 if m.config.captureBuild {
1054 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001055 }
1056
Colin Crossdc35e212019-06-06 16:13:11 -07001057 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001058}
1059
Colin Crossdc35e212019-06-06 16:13:11 -07001060func (b *baseModuleContext) Module() Module {
1061 module, _ := b.BaseModuleContext.Module().(Module)
1062 return module
1063}
1064
1065func (b *baseModuleContext) Config() Config {
1066 return b.BaseModuleContext.Config().(Config)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001067}
1068
Colin Cross25de6c32019-06-06 14:29:25 -07001069func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001070 var missingDeps []string
1071 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001072 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001073 missingDeps = FirstUniqueStrings(missingDeps)
1074 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001075}
1076
Colin Crossdc35e212019-06-06 16:13:11 -07001077func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001078 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001079 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001080 *missingDeps = append(*missingDeps, deps...)
1081 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001082 }
1083}
1084
Colin Crossdc35e212019-06-06 16:13:11 -07001085func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001086 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001087
1088 if !strict {
1089 return aModule
1090 }
1091
Colin Cross380c69a2019-06-10 17:49:58 +00001092 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001093 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001094 return nil
1095 }
1096
1097 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001098 if b.Config().AllowMissingDependencies() {
1099 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001100 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001101 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001102 }
1103 return nil
1104 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001105 return aModule
1106}
1107
Colin Crossdc35e212019-06-06 16:13:11 -07001108func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001109 type dep struct {
1110 mod blueprint.Module
1111 tag blueprint.DependencyTag
1112 }
1113 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001114 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001115 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Crossdc35e212019-06-06 16:13:11 -07001116 returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001117 if tag == nil || returnedTag == tag {
1118 deps = append(deps, dep{aModule, returnedTag})
1119 }
1120 }
1121 })
1122 if len(deps) == 1 {
1123 return deps[0].mod, deps[0].tag
1124 } else if len(deps) >= 2 {
1125 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001126 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001127 } else {
1128 return nil, nil
1129 }
1130}
1131
Colin Crossdc35e212019-06-06 16:13:11 -07001132func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001133 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001134 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001135 if aModule, _ := module.(Module); aModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001136 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001137 deps = append(deps, aModule)
1138 }
1139 }
1140 })
1141 return deps
1142}
1143
Colin Cross25de6c32019-06-06 14:29:25 -07001144func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1145 module, _ := m.getDirectDepInternal(name, tag)
1146 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001147}
1148
Colin Crossdc35e212019-06-06 16:13:11 -07001149func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1150 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001151}
1152
Colin Crossdc35e212019-06-06 16:13:11 -07001153func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1154 b.BaseModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001155}
1156
Colin Crossdc35e212019-06-06 16:13:11 -07001157func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
1158 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1159 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001160 visit(aModule)
1161 }
1162 })
1163}
1164
Colin Crossdc35e212019-06-06 16:13:11 -07001165func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1166 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1167 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
1168 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001169 visit(aModule)
1170 }
1171 }
1172 })
1173}
1174
Colin Crossdc35e212019-06-06 16:13:11 -07001175func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1176 b.BaseModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001177 // pred
1178 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001179 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001180 return pred(aModule)
1181 } else {
1182 return false
1183 }
1184 },
1185 // visit
1186 func(module blueprint.Module) {
1187 visit(module.(Module))
1188 })
1189}
1190
Colin Crossdc35e212019-06-06 16:13:11 -07001191func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1192 b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1193 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001194 visit(aModule)
1195 }
1196 })
1197}
1198
Colin Crossdc35e212019-06-06 16:13:11 -07001199func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1200 b.BaseModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001201 // pred
1202 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001203 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001204 return pred(aModule)
1205 } else {
1206 return false
1207 }
1208 },
1209 // visit
1210 func(module blueprint.Module) {
1211 visit(module.(Module))
1212 })
1213}
1214
Colin Crossdc35e212019-06-06 16:13:11 -07001215func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1216 b.BaseModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001217}
1218
Colin Crossdc35e212019-06-06 16:13:11 -07001219func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1220 b.walkPath = []Module{b.Module()}
1221 b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1222 childAndroidModule, _ := child.(Module)
1223 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001224 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001225 // record walkPath before visit
1226 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1227 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1228 }
1229 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001230 return visit(childAndroidModule, parentAndroidModule)
1231 } else {
1232 return false
1233 }
1234 })
1235}
1236
Colin Crossdc35e212019-06-06 16:13:11 -07001237func (b *baseModuleContext) GetWalkPath() []Module {
1238 return b.walkPath
1239}
1240
Colin Cross25de6c32019-06-06 14:29:25 -07001241func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001242 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001243 visit(module.(Module))
1244 })
1245}
1246
Colin Cross25de6c32019-06-06 14:29:25 -07001247func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001248 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001249}
1250
Colin Cross25de6c32019-06-06 14:29:25 -07001251func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001252 return m.bp.FinalModule().(Module)
1253}
1254
1255func (m *moduleContext) ModuleSubDir() string {
1256 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001257}
1258
Colin Cross0ea8ba82019-06-06 14:33:29 -07001259func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001260 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001261}
1262
Colin Cross0ea8ba82019-06-06 14:33:29 -07001263func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001264 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001265}
1266
Colin Cross0ea8ba82019-06-06 14:33:29 -07001267func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001268 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001269}
1270
Colin Cross0ea8ba82019-06-06 14:33:29 -07001271func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001272 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001273}
1274
Colin Cross0ea8ba82019-06-06 14:33:29 -07001275func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001276 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001277}
1278
Colin Cross0ea8ba82019-06-06 14:33:29 -07001279func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001280 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001281}
1282
Colin Cross0ea8ba82019-06-06 14:33:29 -07001283func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001284 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001285}
1286
Colin Cross0ea8ba82019-06-06 14:33:29 -07001287func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001288 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001289}
1290
Colin Cross0ea8ba82019-06-06 14:33:29 -07001291func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001292 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001293}
1294
Colin Cross0ea8ba82019-06-06 14:33:29 -07001295func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001296 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001297}
1298
Colin Cross0ea8ba82019-06-06 14:33:29 -07001299func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001300 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001301}
1302
Colin Cross0ea8ba82019-06-06 14:33:29 -07001303func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001304 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001305 return true
1306 }
Colin Cross25de6c32019-06-06 14:29:25 -07001307 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001308}
1309
Colin Cross0ea8ba82019-06-06 14:33:29 -07001310func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001311 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001312}
1313
Colin Cross0ea8ba82019-06-06 14:33:29 -07001314func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001315 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001316}
1317
Colin Cross0ea8ba82019-06-06 14:33:29 -07001318func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001319 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001320}
1321
Colin Cross0ea8ba82019-06-06 14:33:29 -07001322func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001323 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001324}
1325
Colin Cross0ea8ba82019-06-06 14:33:29 -07001326func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001327 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001328}
1329
Colin Cross0ea8ba82019-06-06 14:33:29 -07001330func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001331 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001332}
1333
Colin Cross0ea8ba82019-06-06 14:33:29 -07001334func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001335 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001336}
1337
Jiyong Park5baac542018-08-28 09:55:37 +09001338// Makes this module a platform module, i.e. not specific to soc, device,
1339// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001340func (m *ModuleBase) MakeAsPlatform() {
1341 m.commonProperties.Vendor = boolPtr(false)
1342 m.commonProperties.Proprietary = boolPtr(false)
1343 m.commonProperties.Soc_specific = boolPtr(false)
1344 m.commonProperties.Product_specific = boolPtr(false)
1345 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001346}
1347
Colin Cross4157e882019-06-06 16:57:04 -07001348func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1349 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001350}
1351
Colin Cross25de6c32019-06-06 14:29:25 -07001352func (m *moduleContext) InstallInData() bool {
1353 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001354}
1355
Colin Cross25de6c32019-06-06 14:29:25 -07001356func (m *moduleContext) InstallInSanitizerDir() bool {
1357 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001358}
1359
Colin Cross25de6c32019-06-06 14:29:25 -07001360func (m *moduleContext) InstallInRecovery() bool {
1361 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001362}
1363
Colin Cross25de6c32019-06-06 14:29:25 -07001364func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1365 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001366 return true
1367 }
1368
Colin Cross3607f212018-05-07 15:28:05 -07001369 // We'll need a solution for choosing which of modules with the same name in different
1370 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1371 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001372 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001373 return true
1374 }
1375
Colin Cross25de6c32019-06-06 14:29:25 -07001376 if m.Device() {
1377 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001378 return true
1379 }
1380
Colin Cross25de6c32019-06-06 14:29:25 -07001381 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001382 return true
1383 }
1384 }
1385
1386 return false
1387}
1388
Colin Cross25de6c32019-06-06 14:29:25 -07001389func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001390 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001391 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001392}
1393
Colin Cross25de6c32019-06-06 14:29:25 -07001394func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001395 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001396 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001397}
1398
Colin Cross25de6c32019-06-06 14:29:25 -07001399func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001400 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001401
Colin Cross25de6c32019-06-06 14:29:25 -07001402 fullInstallPath := installPath.Join(m, name)
1403 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001404
Colin Cross25de6c32019-06-06 14:29:25 -07001405 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001406
Colin Cross25de6c32019-06-06 14:29:25 -07001407 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001408
Colin Cross89562dc2016-10-03 17:47:19 -07001409 var implicitDeps, orderOnlyDeps Paths
1410
Colin Cross25de6c32019-06-06 14:29:25 -07001411 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001412 // Installed host modules might be used during the build, depend directly on their
1413 // dependencies so their timestamp is updated whenever their dependency is updated
1414 implicitDeps = deps
1415 } else {
1416 orderOnlyDeps = deps
1417 }
1418
Colin Cross25de6c32019-06-06 14:29:25 -07001419 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001420 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001421 Description: "install " + fullInstallPath.Base(),
1422 Output: fullInstallPath,
1423 Input: srcPath,
1424 Implicits: implicitDeps,
1425 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001426 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001427 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001428
Colin Cross25de6c32019-06-06 14:29:25 -07001429 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001430 }
Colin Cross25de6c32019-06-06 14:29:25 -07001431 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001432 return fullInstallPath
1433}
1434
Colin Cross25de6c32019-06-06 14:29:25 -07001435func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1436 fullInstallPath := installPath.Join(m, name)
1437 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001438
Colin Cross25de6c32019-06-06 14:29:25 -07001439 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001440
Alex Lightfb4353d2019-01-17 13:57:45 -08001441 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1442 if err != nil {
1443 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1444 }
Colin Cross25de6c32019-06-06 14:29:25 -07001445 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001446 Rule: Symlink,
1447 Description: "install symlink " + fullInstallPath.Base(),
1448 Output: fullInstallPath,
1449 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001450 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001451 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001452 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001453 },
1454 })
Colin Cross3854a602016-01-11 12:49:11 -08001455
Colin Cross25de6c32019-06-06 14:29:25 -07001456 m.installFiles = append(m.installFiles, fullInstallPath)
1457 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001458 }
Colin Cross3854a602016-01-11 12:49:11 -08001459 return fullInstallPath
1460}
1461
Jiyong Parkf1194352019-02-25 11:05:47 +09001462// installPath/name -> absPath where absPath might be a path that is available only at runtime
1463// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001464func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1465 fullInstallPath := installPath.Join(m, name)
1466 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001467
Colin Cross25de6c32019-06-06 14:29:25 -07001468 if !m.skipInstall(fullInstallPath) {
1469 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001470 Rule: Symlink,
1471 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1472 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001473 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001474 Args: map[string]string{
1475 "fromPath": absPath,
1476 },
1477 })
1478
Colin Cross25de6c32019-06-06 14:29:25 -07001479 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001480 }
1481 return fullInstallPath
1482}
1483
Colin Cross25de6c32019-06-06 14:29:25 -07001484func (m *moduleContext) CheckbuildFile(srcPath Path) {
1485 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001486}
1487
Colin Cross3f40fa42015-01-30 17:27:36 -08001488type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001489 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001490}
1491
1492func isFileInstaller(m blueprint.Module) bool {
1493 _, ok := m.(fileInstaller)
1494 return ok
1495}
1496
1497func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001498 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001499 return ok
1500}
Colin Crossfce53272015-04-08 11:21:40 -07001501
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001502func findStringInSlice(str string, slice []string) int {
1503 for i, s := range slice {
1504 if s == str {
1505 return i
Colin Crossfce53272015-04-08 11:21:40 -07001506 }
1507 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001508 return -1
1509}
1510
Colin Cross41955e82019-05-29 14:40:35 -07001511// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1512// was not a module reference.
1513func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001514 if len(s) > 1 && s[0] == ':' {
1515 return s[1:]
1516 }
1517 return ""
1518}
1519
Colin Cross41955e82019-05-29 14:40:35 -07001520// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1521// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1522func SrcIsModuleWithTag(s string) (module, tag string) {
1523 if len(s) > 1 && s[0] == ':' {
1524 module = s[1:]
1525 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1526 if module[len(module)-1] == '}' {
1527 tag = module[tagStart+1 : len(module)-1]
1528 module = module[:tagStart]
1529 return module, tag
1530 }
1531 }
1532 return module, ""
1533 }
1534 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001535}
1536
Colin Cross41955e82019-05-29 14:40:35 -07001537type sourceOrOutputDependencyTag struct {
1538 blueprint.BaseDependencyTag
1539 tag string
1540}
1541
1542func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1543 return sourceOrOutputDependencyTag{tag: tag}
1544}
1545
1546var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001547
Colin Cross366938f2017-12-11 16:29:02 -08001548// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1549// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001550//
1551// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001552func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001553 set := make(map[string]bool)
1554
Colin Cross068e0fe2016-12-13 15:23:47 -08001555 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001556 if m, t := SrcIsModuleWithTag(s); m != "" {
1557 if _, found := set[s]; found {
1558 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001559 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001560 set[s] = true
1561 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001562 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001563 }
1564 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001565}
1566
Colin Cross366938f2017-12-11 16:29:02 -08001567// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1568// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001569//
1570// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001571func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1572 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001573 if m, t := SrcIsModuleWithTag(*s); m != "" {
1574 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001575 }
1576 }
1577}
1578
Colin Cross41955e82019-05-29 14:40:35 -07001579// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1580// 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 -08001581type SourceFileProducer interface {
1582 Srcs() Paths
1583}
1584
Colin Cross41955e82019-05-29 14:40:35 -07001585// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1586// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1587// listed in the property.
1588type OutputFileProducer interface {
1589 OutputFiles(tag string) (Paths, error)
1590}
1591
Colin Crossfe17f6f2019-03-28 19:30:56 -07001592type HostToolProvider interface {
1593 HostToolPath() OptionalPath
1594}
1595
Colin Cross27b922f2019-03-04 22:35:41 -08001596// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1597// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001598//
1599// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001600func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1601 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001602}
1603
Colin Cross2fafa3e2019-03-05 12:39:51 -08001604// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1605// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001606//
1607// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001608func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1609 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001610}
1611
1612// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1613// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1614// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001615func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001616 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001617 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001618 }
1619 return OptionalPath{}
1620}
1621
Colin Cross25de6c32019-06-06 14:29:25 -07001622func (m *moduleContext) RequiredModuleNames() []string {
1623 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001624}
1625
Colin Cross25de6c32019-06-06 14:29:25 -07001626func (m *moduleContext) HostRequiredModuleNames() []string {
1627 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001628}
1629
Colin Cross25de6c32019-06-06 14:29:25 -07001630func (m *moduleContext) TargetRequiredModuleNames() []string {
1631 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001632}
1633
Colin Crossdc35e212019-06-06 16:13:11 -07001634func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths {
1635 ret, err := b.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001636 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001637 b.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001638 }
Colin Crossdc35e212019-06-06 16:13:11 -07001639 return pathsForModuleSrcFromFullPath(b, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001640}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001641
Colin Crossdc35e212019-06-06 16:13:11 -07001642func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1643 ret, err := b.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001644 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001645 b.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001646 }
Colin Crossdc35e212019-06-06 16:13:11 -07001647 return pathsForModuleSrcFromFullPath(b, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001648}
1649
Colin Cross463a90e2015-06-17 14:20:06 -07001650func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001651 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001652}
1653
Colin Cross0875c522017-11-28 17:34:01 -08001654func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001655 return &buildTargetSingleton{}
1656}
1657
Colin Cross87d8b562017-04-25 10:01:55 -07001658func parentDir(dir string) string {
1659 dir, _ = filepath.Split(dir)
1660 return filepath.Clean(dir)
1661}
1662
Colin Cross1f8c52b2015-06-16 16:38:17 -07001663type buildTargetSingleton struct{}
1664
Colin Cross0875c522017-11-28 17:34:01 -08001665func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1666 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001667
Colin Cross0875c522017-11-28 17:34:01 -08001668 mmTarget := func(dir string) WritablePath {
1669 return PathForPhony(ctx,
1670 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001671 }
1672
Colin Cross0875c522017-11-28 17:34:01 -08001673 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001674
Colin Cross0875c522017-11-28 17:34:01 -08001675 ctx.VisitAllModules(func(module Module) {
1676 blueprintDir := module.base().blueprintDir
1677 installTarget := module.base().installTarget
1678 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001679
Colin Cross0875c522017-11-28 17:34:01 -08001680 if checkbuildTarget != nil {
1681 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1682 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1683 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001684
Colin Cross0875c522017-11-28 17:34:01 -08001685 if installTarget != nil {
1686 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001687 }
1688 })
1689
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001690 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001691 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001692 suffix = "-soong"
1693 }
1694
Colin Cross1f8c52b2015-06-16 16:38:17 -07001695 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001696 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001697 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001698 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001699 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001700 })
1701
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001702 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001703 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001704 return
1705 }
1706
Colin Cross87d8b562017-04-25 10:01:55 -07001707 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001708 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001709 for _, dir := range dirs {
1710 dir := parentDir(dir)
1711 for dir != "." && dir != "/" {
1712 if _, exists := modulesInDir[dir]; exists {
1713 break
1714 }
1715 modulesInDir[dir] = nil
1716 dir = parentDir(dir)
1717 }
1718 }
1719
1720 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001721 for _, dir := range dirs {
1722 p := parentDir(dir)
1723 if p != "." && p != "/" {
1724 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1725 }
1726 }
1727
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001728 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1729 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1730 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001731 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001732 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001733 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001734 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001735 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001736 // HACK: checkbuild should be an optional build, but force it
1737 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001738 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001739 })
1740 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001741
1742 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1743 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001744 ctx.VisitAllModules(func(module Module) {
1745 if module.Enabled() {
1746 os := module.Target().Os
1747 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001748 }
1749 })
1750
Colin Cross0875c522017-11-28 17:34:01 -08001751 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001752 for os, deps := range osDeps {
1753 var className string
1754
1755 switch os.Class {
1756 case Host:
1757 className = "host"
1758 case HostCross:
1759 className = "host-cross"
1760 case Device:
1761 className = "target"
1762 default:
1763 continue
1764 }
1765
Colin Cross0875c522017-11-28 17:34:01 -08001766 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001767 osClass[className] = append(osClass[className], name)
1768
Colin Cross0875c522017-11-28 17:34:01 -08001769 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001770 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001771 Output: name,
1772 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001773 })
1774 }
1775
1776 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001777 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001778 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001779 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001780 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001781 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001782 })
1783 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001784}
Colin Crossd779da42015-12-17 18:00:23 -08001785
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001786// Collect information for opening IDE project files in java/jdeps.go.
1787type IDEInfo interface {
1788 IDEInfo(ideInfo *IdeInfo)
1789 BaseModuleName() string
1790}
1791
1792// Extract the base module name from the Import name.
1793// Often the Import name has a prefix "prebuilt_".
1794// Remove the prefix explicitly if needed
1795// until we find a better solution to get the Import name.
1796type IDECustomizedModuleName interface {
1797 IDECustomizedModuleName() string
1798}
1799
1800type IdeInfo struct {
1801 Deps []string `json:"dependencies,omitempty"`
1802 Srcs []string `json:"srcs,omitempty"`
1803 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1804 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1805 Jars []string `json:"jars,omitempty"`
1806 Classes []string `json:"class,omitempty"`
1807 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001808 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001809}