blob: 87e2ca7d98f9c088e4dd8c21d0d8aecd3da317f0 [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 Cross4b69c492019-06-07 13:06:06 -0700969 Rule: ErrorRule,
970 Description: params.Description,
971 Output: params.Output,
972 Outputs: params.Outputs,
973 ImplicitOutput: params.ImplicitOutput,
974 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -0800975 Args: map[string]string{
976 "error": err.Error(),
977 },
Colin Crossb88b3c52019-06-10 15:15:17 -0700978 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800979}
980
Colin Cross25de6c32019-06-06 14:29:25 -0700981func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
982 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800983}
984
Colin Cross0875c522017-11-28 17:34:01 -0800985func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700986 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700987 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800988 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800989 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700990 Outputs: params.Outputs.Strings(),
991 ImplicitOutputs: params.ImplicitOutputs.Strings(),
992 Inputs: params.Inputs.Strings(),
993 Implicits: params.Implicits.Strings(),
994 OrderOnly: params.OrderOnly.Strings(),
995 Args: params.Args,
996 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700997 }
998
Colin Cross33bfb0a2016-11-21 17:23:08 -0800999 if params.Depfile != nil {
1000 bparams.Depfile = params.Depfile.String()
1001 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001002 if params.Output != nil {
1003 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1004 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001005 if params.ImplicitOutput != nil {
1006 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1007 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001008 if params.Input != nil {
1009 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1010 }
1011 if params.Implicit != nil {
1012 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1013 }
1014
Colin Cross0b9f31f2019-02-28 11:00:01 -08001015 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1016 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1017 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1018 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1019 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1020 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001021
Colin Cross0875c522017-11-28 17:34:01 -08001022 return bparams
1023}
1024
Colin Cross25de6c32019-06-06 14:29:25 -07001025func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1026 if m.config.captureBuild {
1027 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001028 }
1029
Colin Crossdc35e212019-06-06 16:13:11 -07001030 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001031}
1032
Colin Cross25de6c32019-06-06 14:29:25 -07001033func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001034 argNames ...string) blueprint.Rule {
1035
Colin Crossdc35e212019-06-06 16:13:11 -07001036 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001037
Colin Cross25de6c32019-06-06 14:29:25 -07001038 if m.config.captureBuild {
1039 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001040 }
1041
1042 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001043}
1044
Colin Cross25de6c32019-06-06 14:29:25 -07001045func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001046 if params.Description != "" {
1047 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1048 }
1049
1050 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1051 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1052 m.ModuleName(), strings.Join(missingDeps, ", ")))
1053 }
1054
Colin Cross25de6c32019-06-06 14:29:25 -07001055 if m.config.captureBuild {
1056 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001057 }
1058
Colin Crossdc35e212019-06-06 16:13:11 -07001059 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001060}
1061
Colin Crossdc35e212019-06-06 16:13:11 -07001062func (b *baseModuleContext) Module() Module {
1063 module, _ := b.BaseModuleContext.Module().(Module)
1064 return module
1065}
1066
1067func (b *baseModuleContext) Config() Config {
1068 return b.BaseModuleContext.Config().(Config)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001069}
1070
Colin Cross25de6c32019-06-06 14:29:25 -07001071func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001072 var missingDeps []string
1073 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001074 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001075 missingDeps = FirstUniqueStrings(missingDeps)
1076 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001077}
1078
Colin Crossdc35e212019-06-06 16:13:11 -07001079func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001080 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001081 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001082 *missingDeps = append(*missingDeps, deps...)
1083 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001084 }
1085}
1086
Colin Crossdc35e212019-06-06 16:13:11 -07001087func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001088 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001089
1090 if !strict {
1091 return aModule
1092 }
1093
Colin Cross380c69a2019-06-10 17:49:58 +00001094 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001095 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001096 return nil
1097 }
1098
1099 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001100 if b.Config().AllowMissingDependencies() {
1101 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001102 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001103 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001104 }
1105 return nil
1106 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001107 return aModule
1108}
1109
Colin Crossdc35e212019-06-06 16:13:11 -07001110func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001111 type dep struct {
1112 mod blueprint.Module
1113 tag blueprint.DependencyTag
1114 }
1115 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001116 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001117 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Crossdc35e212019-06-06 16:13:11 -07001118 returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001119 if tag == nil || returnedTag == tag {
1120 deps = append(deps, dep{aModule, returnedTag})
1121 }
1122 }
1123 })
1124 if len(deps) == 1 {
1125 return deps[0].mod, deps[0].tag
1126 } else if len(deps) >= 2 {
1127 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001128 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001129 } else {
1130 return nil, nil
1131 }
1132}
1133
Colin Crossdc35e212019-06-06 16:13:11 -07001134func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001135 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001136 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001137 if aModule, _ := module.(Module); aModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001138 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001139 deps = append(deps, aModule)
1140 }
1141 }
1142 })
1143 return deps
1144}
1145
Colin Cross25de6c32019-06-06 14:29:25 -07001146func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1147 module, _ := m.getDirectDepInternal(name, tag)
1148 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001149}
1150
Colin Crossdc35e212019-06-06 16:13:11 -07001151func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1152 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001153}
1154
Colin Crossdc35e212019-06-06 16:13:11 -07001155func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1156 b.BaseModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001157}
1158
Colin Crossdc35e212019-06-06 16:13:11 -07001159func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
1160 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1161 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001162 visit(aModule)
1163 }
1164 })
1165}
1166
Colin Crossdc35e212019-06-06 16:13:11 -07001167func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1168 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1169 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
1170 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001171 visit(aModule)
1172 }
1173 }
1174 })
1175}
1176
Colin Crossdc35e212019-06-06 16:13:11 -07001177func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1178 b.BaseModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001179 // pred
1180 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001181 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001182 return pred(aModule)
1183 } else {
1184 return false
1185 }
1186 },
1187 // visit
1188 func(module blueprint.Module) {
1189 visit(module.(Module))
1190 })
1191}
1192
Colin Crossdc35e212019-06-06 16:13:11 -07001193func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1194 b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1195 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001196 visit(aModule)
1197 }
1198 })
1199}
1200
Colin Crossdc35e212019-06-06 16:13:11 -07001201func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1202 b.BaseModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001203 // pred
1204 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001205 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001206 return pred(aModule)
1207 } else {
1208 return false
1209 }
1210 },
1211 // visit
1212 func(module blueprint.Module) {
1213 visit(module.(Module))
1214 })
1215}
1216
Colin Crossdc35e212019-06-06 16:13:11 -07001217func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1218 b.BaseModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001219}
1220
Colin Crossdc35e212019-06-06 16:13:11 -07001221func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1222 b.walkPath = []Module{b.Module()}
1223 b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1224 childAndroidModule, _ := child.(Module)
1225 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001226 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001227 // record walkPath before visit
1228 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1229 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1230 }
1231 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001232 return visit(childAndroidModule, parentAndroidModule)
1233 } else {
1234 return false
1235 }
1236 })
1237}
1238
Colin Crossdc35e212019-06-06 16:13:11 -07001239func (b *baseModuleContext) GetWalkPath() []Module {
1240 return b.walkPath
1241}
1242
Colin Cross25de6c32019-06-06 14:29:25 -07001243func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001244 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001245 visit(module.(Module))
1246 })
1247}
1248
Colin Cross25de6c32019-06-06 14:29:25 -07001249func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001250 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001251}
1252
Colin Cross25de6c32019-06-06 14:29:25 -07001253func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001254 return m.bp.FinalModule().(Module)
1255}
1256
1257func (m *moduleContext) ModuleSubDir() string {
1258 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001259}
1260
Colin Cross0ea8ba82019-06-06 14:33:29 -07001261func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001262 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001263}
1264
Colin Cross0ea8ba82019-06-06 14:33:29 -07001265func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001266 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001267}
1268
Colin Cross0ea8ba82019-06-06 14:33:29 -07001269func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001270 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001271}
1272
Colin Cross0ea8ba82019-06-06 14:33:29 -07001273func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001274 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001275}
1276
Colin Cross0ea8ba82019-06-06 14:33:29 -07001277func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001278 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001279}
1280
Colin Cross0ea8ba82019-06-06 14:33:29 -07001281func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001282 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001283}
1284
Colin Cross0ea8ba82019-06-06 14:33:29 -07001285func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001286 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001287}
1288
Colin Cross0ea8ba82019-06-06 14:33:29 -07001289func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001290 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001291}
1292
Colin Cross0ea8ba82019-06-06 14:33:29 -07001293func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001294 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001295}
1296
Colin Cross0ea8ba82019-06-06 14:33:29 -07001297func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001298 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001299}
1300
Colin Cross0ea8ba82019-06-06 14:33:29 -07001301func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001302 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001303}
1304
Colin Cross0ea8ba82019-06-06 14:33:29 -07001305func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001306 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001307 return true
1308 }
Colin Cross25de6c32019-06-06 14:29:25 -07001309 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001310}
1311
Colin Cross0ea8ba82019-06-06 14:33:29 -07001312func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001313 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001314}
1315
Colin Cross0ea8ba82019-06-06 14:33:29 -07001316func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001317 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001318}
1319
Colin Cross0ea8ba82019-06-06 14:33:29 -07001320func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001321 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001322}
1323
Colin Cross0ea8ba82019-06-06 14:33:29 -07001324func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001325 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001326}
1327
Colin Cross0ea8ba82019-06-06 14:33:29 -07001328func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001329 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001330}
1331
Colin Cross0ea8ba82019-06-06 14:33:29 -07001332func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001333 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001334}
1335
Colin Cross0ea8ba82019-06-06 14:33:29 -07001336func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001337 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001338}
1339
Jiyong Park5baac542018-08-28 09:55:37 +09001340// Makes this module a platform module, i.e. not specific to soc, device,
1341// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001342func (m *ModuleBase) MakeAsPlatform() {
1343 m.commonProperties.Vendor = boolPtr(false)
1344 m.commonProperties.Proprietary = boolPtr(false)
1345 m.commonProperties.Soc_specific = boolPtr(false)
1346 m.commonProperties.Product_specific = boolPtr(false)
1347 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001348}
1349
Colin Cross4157e882019-06-06 16:57:04 -07001350func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1351 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001352}
1353
Colin Cross25de6c32019-06-06 14:29:25 -07001354func (m *moduleContext) InstallInData() bool {
1355 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001356}
1357
Colin Cross25de6c32019-06-06 14:29:25 -07001358func (m *moduleContext) InstallInSanitizerDir() bool {
1359 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001360}
1361
Colin Cross25de6c32019-06-06 14:29:25 -07001362func (m *moduleContext) InstallInRecovery() bool {
1363 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001364}
1365
Colin Cross25de6c32019-06-06 14:29:25 -07001366func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1367 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001368 return true
1369 }
1370
Colin Cross3607f212018-05-07 15:28:05 -07001371 // We'll need a solution for choosing which of modules with the same name in different
1372 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1373 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001374 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001375 return true
1376 }
1377
Colin Cross25de6c32019-06-06 14:29:25 -07001378 if m.Device() {
1379 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001380 return true
1381 }
1382
Colin Cross25de6c32019-06-06 14:29:25 -07001383 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001384 return true
1385 }
1386 }
1387
1388 return false
1389}
1390
Colin Cross25de6c32019-06-06 14:29:25 -07001391func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001392 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001393 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001394}
1395
Colin Cross25de6c32019-06-06 14:29:25 -07001396func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001397 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001398 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001399}
1400
Colin Cross25de6c32019-06-06 14:29:25 -07001401func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001402 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001403
Colin Cross25de6c32019-06-06 14:29:25 -07001404 fullInstallPath := installPath.Join(m, name)
1405 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001406
Colin Cross25de6c32019-06-06 14:29:25 -07001407 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001408
Colin Cross25de6c32019-06-06 14:29:25 -07001409 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001410
Colin Cross89562dc2016-10-03 17:47:19 -07001411 var implicitDeps, orderOnlyDeps Paths
1412
Colin Cross25de6c32019-06-06 14:29:25 -07001413 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001414 // Installed host modules might be used during the build, depend directly on their
1415 // dependencies so their timestamp is updated whenever their dependency is updated
1416 implicitDeps = deps
1417 } else {
1418 orderOnlyDeps = deps
1419 }
1420
Colin Cross25de6c32019-06-06 14:29:25 -07001421 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001422 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001423 Description: "install " + fullInstallPath.Base(),
1424 Output: fullInstallPath,
1425 Input: srcPath,
1426 Implicits: implicitDeps,
1427 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001428 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001429 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001430
Colin Cross25de6c32019-06-06 14:29:25 -07001431 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001432 }
Colin Cross25de6c32019-06-06 14:29:25 -07001433 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001434 return fullInstallPath
1435}
1436
Colin Cross25de6c32019-06-06 14:29:25 -07001437func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1438 fullInstallPath := installPath.Join(m, name)
1439 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001440
Colin Cross25de6c32019-06-06 14:29:25 -07001441 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001442
Alex Lightfb4353d2019-01-17 13:57:45 -08001443 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1444 if err != nil {
1445 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1446 }
Colin Cross25de6c32019-06-06 14:29:25 -07001447 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001448 Rule: Symlink,
1449 Description: "install symlink " + fullInstallPath.Base(),
1450 Output: fullInstallPath,
1451 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001452 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001453 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001454 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001455 },
1456 })
Colin Cross3854a602016-01-11 12:49:11 -08001457
Colin Cross25de6c32019-06-06 14:29:25 -07001458 m.installFiles = append(m.installFiles, fullInstallPath)
1459 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001460 }
Colin Cross3854a602016-01-11 12:49:11 -08001461 return fullInstallPath
1462}
1463
Jiyong Parkf1194352019-02-25 11:05:47 +09001464// installPath/name -> absPath where absPath might be a path that is available only at runtime
1465// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001466func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1467 fullInstallPath := installPath.Join(m, name)
1468 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001469
Colin Cross25de6c32019-06-06 14:29:25 -07001470 if !m.skipInstall(fullInstallPath) {
1471 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001472 Rule: Symlink,
1473 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1474 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001475 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001476 Args: map[string]string{
1477 "fromPath": absPath,
1478 },
1479 })
1480
Colin Cross25de6c32019-06-06 14:29:25 -07001481 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001482 }
1483 return fullInstallPath
1484}
1485
Colin Cross25de6c32019-06-06 14:29:25 -07001486func (m *moduleContext) CheckbuildFile(srcPath Path) {
1487 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001488}
1489
Colin Cross3f40fa42015-01-30 17:27:36 -08001490type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001491 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001492}
1493
1494func isFileInstaller(m blueprint.Module) bool {
1495 _, ok := m.(fileInstaller)
1496 return ok
1497}
1498
1499func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001500 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001501 return ok
1502}
Colin Crossfce53272015-04-08 11:21:40 -07001503
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001504func findStringInSlice(str string, slice []string) int {
1505 for i, s := range slice {
1506 if s == str {
1507 return i
Colin Crossfce53272015-04-08 11:21:40 -07001508 }
1509 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001510 return -1
1511}
1512
Colin Cross41955e82019-05-29 14:40:35 -07001513// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1514// was not a module reference.
1515func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001516 if len(s) > 1 && s[0] == ':' {
1517 return s[1:]
1518 }
1519 return ""
1520}
1521
Colin Cross41955e82019-05-29 14:40:35 -07001522// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1523// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1524func SrcIsModuleWithTag(s string) (module, tag string) {
1525 if len(s) > 1 && s[0] == ':' {
1526 module = s[1:]
1527 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1528 if module[len(module)-1] == '}' {
1529 tag = module[tagStart+1 : len(module)-1]
1530 module = module[:tagStart]
1531 return module, tag
1532 }
1533 }
1534 return module, ""
1535 }
1536 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001537}
1538
Colin Cross41955e82019-05-29 14:40:35 -07001539type sourceOrOutputDependencyTag struct {
1540 blueprint.BaseDependencyTag
1541 tag string
1542}
1543
1544func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1545 return sourceOrOutputDependencyTag{tag: tag}
1546}
1547
1548var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001549
Colin Cross366938f2017-12-11 16:29:02 -08001550// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1551// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001552//
1553// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001554func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001555 set := make(map[string]bool)
1556
Colin Cross068e0fe2016-12-13 15:23:47 -08001557 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001558 if m, t := SrcIsModuleWithTag(s); m != "" {
1559 if _, found := set[s]; found {
1560 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001561 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001562 set[s] = true
1563 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001564 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001565 }
1566 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001567}
1568
Colin Cross366938f2017-12-11 16:29:02 -08001569// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1570// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001571//
1572// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001573func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1574 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001575 if m, t := SrcIsModuleWithTag(*s); m != "" {
1576 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001577 }
1578 }
1579}
1580
Colin Cross41955e82019-05-29 14:40:35 -07001581// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1582// 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 -08001583type SourceFileProducer interface {
1584 Srcs() Paths
1585}
1586
Colin Cross41955e82019-05-29 14:40:35 -07001587// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1588// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1589// listed in the property.
1590type OutputFileProducer interface {
1591 OutputFiles(tag string) (Paths, error)
1592}
1593
Colin Crossfe17f6f2019-03-28 19:30:56 -07001594type HostToolProvider interface {
1595 HostToolPath() OptionalPath
1596}
1597
Colin Cross27b922f2019-03-04 22:35:41 -08001598// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1599// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001600//
1601// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001602func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1603 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001604}
1605
Colin Cross2fafa3e2019-03-05 12:39:51 -08001606// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1607// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001608//
1609// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001610func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1611 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001612}
1613
1614// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1615// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1616// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001617func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001618 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001619 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001620 }
1621 return OptionalPath{}
1622}
1623
Colin Cross25de6c32019-06-06 14:29:25 -07001624func (m *moduleContext) RequiredModuleNames() []string {
1625 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001626}
1627
Colin Cross25de6c32019-06-06 14:29:25 -07001628func (m *moduleContext) HostRequiredModuleNames() []string {
1629 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001630}
1631
Colin Cross25de6c32019-06-06 14:29:25 -07001632func (m *moduleContext) TargetRequiredModuleNames() []string {
1633 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001634}
1635
Colin Crossdc35e212019-06-06 16:13:11 -07001636func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths {
1637 ret, err := b.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001638 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001639 b.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001640 }
Colin Crossdc35e212019-06-06 16:13:11 -07001641 return pathsForModuleSrcFromFullPath(b, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001642}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001643
Colin Crossdc35e212019-06-06 16:13:11 -07001644func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1645 ret, err := b.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001646 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001647 b.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001648 }
Colin Crossdc35e212019-06-06 16:13:11 -07001649 return pathsForModuleSrcFromFullPath(b, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001650}
1651
Colin Cross463a90e2015-06-17 14:20:06 -07001652func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001653 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001654}
1655
Colin Cross0875c522017-11-28 17:34:01 -08001656func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001657 return &buildTargetSingleton{}
1658}
1659
Colin Cross87d8b562017-04-25 10:01:55 -07001660func parentDir(dir string) string {
1661 dir, _ = filepath.Split(dir)
1662 return filepath.Clean(dir)
1663}
1664
Colin Cross1f8c52b2015-06-16 16:38:17 -07001665type buildTargetSingleton struct{}
1666
Colin Cross0875c522017-11-28 17:34:01 -08001667func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1668 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001669
Colin Cross0875c522017-11-28 17:34:01 -08001670 mmTarget := func(dir string) WritablePath {
1671 return PathForPhony(ctx,
1672 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001673 }
1674
Colin Cross0875c522017-11-28 17:34:01 -08001675 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001676
Colin Cross0875c522017-11-28 17:34:01 -08001677 ctx.VisitAllModules(func(module Module) {
1678 blueprintDir := module.base().blueprintDir
1679 installTarget := module.base().installTarget
1680 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001681
Colin Cross0875c522017-11-28 17:34:01 -08001682 if checkbuildTarget != nil {
1683 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1684 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1685 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001686
Colin Cross0875c522017-11-28 17:34:01 -08001687 if installTarget != nil {
1688 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001689 }
1690 })
1691
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001692 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001693 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001694 suffix = "-soong"
1695 }
1696
Colin Cross1f8c52b2015-06-16 16:38:17 -07001697 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001698 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001699 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001700 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001701 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001702 })
1703
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001704 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001705 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001706 return
1707 }
1708
Colin Cross87d8b562017-04-25 10:01:55 -07001709 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001710 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001711 for _, dir := range dirs {
1712 dir := parentDir(dir)
1713 for dir != "." && dir != "/" {
1714 if _, exists := modulesInDir[dir]; exists {
1715 break
1716 }
1717 modulesInDir[dir] = nil
1718 dir = parentDir(dir)
1719 }
1720 }
1721
1722 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001723 for _, dir := range dirs {
1724 p := parentDir(dir)
1725 if p != "." && p != "/" {
1726 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1727 }
1728 }
1729
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001730 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1731 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1732 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001733 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001734 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001735 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001736 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001737 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001738 // HACK: checkbuild should be an optional build, but force it
1739 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001740 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001741 })
1742 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001743
1744 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1745 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001746 ctx.VisitAllModules(func(module Module) {
1747 if module.Enabled() {
1748 os := module.Target().Os
1749 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001750 }
1751 })
1752
Colin Cross0875c522017-11-28 17:34:01 -08001753 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001754 for os, deps := range osDeps {
1755 var className string
1756
1757 switch os.Class {
1758 case Host:
1759 className = "host"
1760 case HostCross:
1761 className = "host-cross"
1762 case Device:
1763 className = "target"
1764 default:
1765 continue
1766 }
1767
Colin Cross0875c522017-11-28 17:34:01 -08001768 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001769 osClass[className] = append(osClass[className], name)
1770
Colin Cross0875c522017-11-28 17:34:01 -08001771 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001772 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001773 Output: name,
1774 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001775 })
1776 }
1777
1778 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001779 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001780 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001781 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001782 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001783 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001784 })
1785 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001786}
Colin Crossd779da42015-12-17 18:00:23 -08001787
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001788// Collect information for opening IDE project files in java/jdeps.go.
1789type IDEInfo interface {
1790 IDEInfo(ideInfo *IdeInfo)
1791 BaseModuleName() string
1792}
1793
1794// Extract the base module name from the Import name.
1795// Often the Import name has a prefix "prebuilt_".
1796// Remove the prefix explicitly if needed
1797// until we find a better solution to get the Import name.
1798type IDECustomizedModuleName interface {
1799 IDECustomizedModuleName() string
1800}
1801
1802type IdeInfo struct {
1803 Deps []string `json:"dependencies,omitempty"`
1804 Srcs []string `json:"srcs,omitempty"`
1805 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1806 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1807 Jars []string `json:"jars,omitempty"`
1808 Classes []string `json:"class,omitempty"`
1809 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001810 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001811}