blob: 3a9ef9636f49c7f5e9dd13a70fd7da49d163d5ef [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 Cross380c69a2019-06-10 17:49:58 +000059// a Config instead of an interface{}, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -070060// about the current module.
61type BaseModuleContext interface {
62 ModuleName() string
63 ModuleDir() string
64 ModuleType() string
65 Config() Config
66
67 ContainsProperty(name string) bool
68 Errorf(pos scanner.Position, fmt string, args ...interface{})
69 ModuleErrorf(fmt string, args ...interface{})
70 PropertyErrorf(property, fmt string, args ...interface{})
71 Failed() bool
72
73 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
74 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
75 // builder whenever a file matching the pattern as added or removed, without rerunning if a
76 // file that does not match the pattern is added to a searched directory.
77 GlobWithDeps(pattern string, excludes []string) ([]string, error)
78
79 Fs() pathtools.FileSystem
80 AddNinjaFileDeps(deps ...string)
81
Colin Crossa1ad8d12016-06-01 17:09:44 -070082 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070083 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -070084 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -070085 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070086 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070087 Host() bool
88 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070089 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -080090 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -070091 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070092 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070093 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +090094 Platform() bool
95 DeviceSpecific() bool
96 SocSpecific() bool
97 ProductSpecific() bool
Dario Frenifd05a742018-05-29 13:28:54 +010098 ProductServicesSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -070099 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -0700100 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -0700101}
102
Colin Cross0ea8ba82019-06-06 14:33:29 -0700103// Deprecated: use BaseModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700104type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800105 BaseModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800106}
107
Colin Cross635c3b02016-05-18 15:37:25 -0700108type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800109 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800110
Colin Crossae887032017-10-23 17:16:14 -0700111 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800112 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700113
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700114 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800115 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800116 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Colin Cross380c69a2019-06-10 17:49:58 +0000117 Glob(globPattern string, excludes []string) Paths
118 GlobFiles(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700119
Colin Cross5c517922017-08-31 12:29:17 -0700120 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
121 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800122 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900123 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800125
126 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700127
Colin Cross8d8f8e22016-08-03 11:57:50 -0700128 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700129 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900130 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800131
132 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700133 HostRequiredModuleNames() []string
134 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700135
Colin Cross380c69a2019-06-10 17:49:58 +0000136 // android.ModuleContext methods
137 // These are duplicated instead of embedded so that can eventually be wrapped to take an
138 // android.Module instead of a blueprint.Module
139 OtherModuleName(m blueprint.Module) string
140 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
141 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
142
143 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
144 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
145 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
146
Colin Cross3f68a132017-10-23 17:10:29 -0700147 ModuleSubDir() string
148
Colin Cross380c69a2019-06-10 17:49:58 +0000149 VisitDirectDepsBlueprint(visit func(blueprint.Module))
150 VisitDirectDeps(visit func(Module))
151 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
152 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
153 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
154 VisitDepsDepthFirst(visit func(Module))
155 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
156 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
157 WalkDeps(visit func(Module, Module) bool)
158 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
159
Colin Cross0875c522017-11-28 17:34:01 -0800160 Variable(pctx PackageContext, name, value string)
161 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700162 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
163 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800164 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700165
Colin Cross0875c522017-11-28 17:34:01 -0800166 PrimaryModule() Module
167 FinalModule() Module
168 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700169
170 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800171 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800172}
173
Colin Cross635c3b02016-05-18 15:37:25 -0700174type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800175 blueprint.Module
176
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700177 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
178 // but GenerateAndroidBuildActions also has access to Android-specific information.
179 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700180 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700181
Colin Cross1e676be2016-10-12 14:38:15 -0700182 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800183
Colin Cross635c3b02016-05-18 15:37:25 -0700184 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800185 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700186 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800187 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700188 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900189 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800190 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900191 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900192 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700193
194 AddProperties(props ...interface{})
195 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700196
Colin Crossae887032017-10-23 17:16:14 -0700197 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800198 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800199 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800200}
201
Colin Crossfc754582016-05-17 16:34:16 -0700202type nameProperties struct {
203 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800204 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700205}
206
207type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800208 // emit build rules for this module
209 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800210
Paul Duffin2e61fa62019-03-28 14:10:57 +0000211 // Controls the visibility of this module to other modules. Allowable values are one or more of
212 // these formats:
213 //
214 // ["//visibility:public"]: Anyone can use this module.
215 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
216 // this module.
217 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
218 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
219 // this module. Note that sub-packages do not have access to the rule; for example,
220 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
221 // is a special module and must be used verbatim. It represents all of the modules in the
222 // package.
223 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
224 // or other or in one of their sub-packages have access to this module. For example,
225 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
226 // to depend on this rule (but not //independent:evil)
227 // ["//project"]: This is shorthand for ["//project:__pkg__"]
228 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
229 // //project is the module's package. e.g. using [":__subpackages__"] in
230 // packages/apps/Settings/Android.bp is equivalent to
231 // //packages/apps/Settings:__subpackages__.
232 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
233 // for now. It is an error if it is used in a module.
234 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
235 // more details.
236 Visibility []string
237
Colin Cross7d5136f2015-05-11 13:39:40 -0700238 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800239 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
240 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
241 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700242 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700243
244 Target struct {
245 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700246 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700247 }
248 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700249 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700250 }
251 }
252
Colin Crossee0bc3b2018-10-02 22:01:37 -0700253 UseTargetVariants bool `blueprint:"mutated"`
254 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800255
Dan Willemsen782a2d12015-12-21 14:55:28 -0800256 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700257 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800258
Colin Cross55708f32017-03-20 13:23:34 -0700259 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700260 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700261
Jiyong Park2db76922017-11-08 16:03:48 +0900262 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
263 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
264 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700265 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -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 Soc_specific *bool
270
271 // whether this module is specific to a device, not only for SoC, but also for off-chip
272 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
273 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
274 // This implies `soc_specific:true`.
275 Device_specific *bool
276
277 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900278 // network operator, etc). When set to true, it is installed into /product (or
279 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900280 Product_specific *bool
281
Dario Frenifd05a742018-05-29 13:28:54 +0100282 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100283 // to true, it is installed into /product_services (or /system/product_services if
284 // product_services partition does not exist).
285 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100286
Jiyong Parkf9332f12018-02-01 00:54:12 +0900287 // Whether this module is installed to recovery partition
288 Recovery *bool
289
dimitry1f33e402019-03-26 12:39:31 +0100290 // Whether this module is built for non-native architecures (also known as native bridge binary)
291 Native_bridge_supported *bool `android:"arch_variant"`
292
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700293 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800294 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700295
Steven Moreland57a23d22018-04-04 15:42:19 -0700296 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800297 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700298
Chris Wolfe998306e2016-08-15 14:47:23 -0400299 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700300 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400301
Sasha Smundakb6d23052019-04-01 18:37:36 -0700302 // names of other modules to install on host if this module is installed
303 Host_required []string `android:"arch_variant"`
304
305 // names of other modules to install on target if this module is installed
306 Target_required []string `android:"arch_variant"`
307
Colin Cross5aac3622017-08-31 15:07:09 -0700308 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800309 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700310
Dan Willemsen569edc52018-11-19 09:33:29 -0800311 Dist struct {
312 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
313 // command line and any of these targets are also on the command line, or otherwise
314 // built
315 Targets []string `android:"arch_variant"`
316
317 // The name of the output artifact. This defaults to the basename of the output of
318 // the module.
319 Dest *string `android:"arch_variant"`
320
321 // The directory within the dist directory to store the artifact. Defaults to the
322 // top level directory ("").
323 Dir *string `android:"arch_variant"`
324
325 // A suffix to add to the artifact file name (before any extension).
326 Suffix *string `android:"arch_variant"`
327 } `android:"arch_variant"`
328
Colin Crossa1ad8d12016-06-01 17:09:44 -0700329 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700330 CompileTarget Target `blueprint:"mutated"`
331 CompileMultiTargets []Target `blueprint:"mutated"`
332 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800333
334 // Set by InitAndroidModule
335 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700336 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700337
338 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800339
340 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700341
342 MissingDeps []string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800343}
344
345type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800346 // If set to true, build a variant of the module for the host. Defaults to false.
347 Host_supported *bool
348
349 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700350 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800351}
352
Colin Crossc472d572015-03-17 15:06:21 -0700353type Multilib string
354
355const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800356 MultilibBoth Multilib = "both"
357 MultilibFirst Multilib = "first"
358 MultilibCommon Multilib = "common"
359 MultilibCommonFirst Multilib = "common_first"
360 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700361)
362
Colin Crossa1ad8d12016-06-01 17:09:44 -0700363type HostOrDeviceSupported int
364
365const (
366 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700367
368 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700369 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700370
371 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700372 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700373
374 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700375 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700376
377 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700378 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700379
380 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700381 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700382
383 // Nothing is supported. This is not exposed to the user, but used to mark a
384 // host only module as unsupported when the module type is not supported on
385 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700386 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700387)
388
Jiyong Park2db76922017-11-08 16:03:48 +0900389type moduleKind int
390
391const (
392 platformModule moduleKind = iota
393 deviceSpecificModule
394 socSpecificModule
395 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100396 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900397)
398
399func (k moduleKind) String() string {
400 switch k {
401 case platformModule:
402 return "platform"
403 case deviceSpecificModule:
404 return "device-specific"
405 case socSpecificModule:
406 return "soc-specific"
407 case productSpecificModule:
408 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100409 case productServicesSpecificModule:
410 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900411 default:
412 panic(fmt.Errorf("unknown module kind %d", k))
413 }
414}
415
Colin Cross36242852017-06-23 15:06:31 -0700416func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800417 base := m.base()
418 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700419
Colin Cross36242852017-06-23 15:06:31 -0700420 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700421 &base.nameProperties,
422 &base.commonProperties,
423 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700424 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700425 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700426}
427
Colin Cross36242852017-06-23 15:06:31 -0700428func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
429 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700430
431 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800432 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700433 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700434 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700435 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800436
Dan Willemsen218f6562015-07-08 18:13:11 -0700437 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700438 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700439 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800440 }
441
Colin Cross36242852017-06-23 15:06:31 -0700442 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800443}
444
Colin Crossee0bc3b2018-10-02 22:01:37 -0700445func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
446 InitAndroidArchModule(m, hod, defaultMultilib)
447 m.base().commonProperties.UseTargetVariants = false
448}
449
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800450// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800451// modules. It should be included as an anonymous field in every module
452// struct definition. InitAndroidModule should then be called from the module's
453// factory function, and the return values from InitAndroidModule should be
454// returned from the factory function.
455//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800456// The ModuleBase type is responsible for implementing the GenerateBuildActions
457// method to support the blueprint.Module interface. This method will then call
458// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700459// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
460// rather than the usual blueprint.ModuleContext.
461// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800462// system including details about the particular build variant that is to be
463// generated.
464//
465// For example:
466//
467// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800468// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800469// )
470//
471// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800472// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800473// properties struct {
474// MyProperty string
475// }
476// }
477//
Colin Cross36242852017-06-23 15:06:31 -0700478// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800479// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700480// m.AddProperties(&m.properties)
481// android.InitAndroidModule(m)
482// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800483// }
484//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800485// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800486// // Get the CPU architecture for the current build variant.
487// variantArch := ctx.Arch()
488//
489// // ...
490// }
Colin Cross635c3b02016-05-18 15:37:25 -0700491type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800492 // Putting the curiously recurring thing pointing to the thing that contains
493 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700494 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700495 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800496
Colin Crossfc754582016-05-17 16:34:16 -0700497 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800498 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700499 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800500 hostAndDeviceProperties hostAndDeviceProperties
501 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700502 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700503 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800504
505 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700506 installFiles Paths
507 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900508 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700509
510 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
511 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800512 installTarget WritablePath
513 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700514 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700515
Colin Cross178a5092016-09-13 13:42:32 -0700516 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700517
518 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700519
520 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700521 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800522 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800523 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700524
525 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700526}
527
Colin Cross4157e882019-06-06 16:57:04 -0700528func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800529
Colin Cross4157e882019-06-06 16:57:04 -0700530func (m *ModuleBase) AddProperties(props ...interface{}) {
531 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700532}
533
Colin Cross4157e882019-06-06 16:57:04 -0700534func (m *ModuleBase) GetProperties() []interface{} {
535 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800536}
537
Colin Cross4157e882019-06-06 16:57:04 -0700538func (m *ModuleBase) BuildParamsForTests() []BuildParams {
539 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700540}
541
Colin Cross4157e882019-06-06 16:57:04 -0700542func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
543 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800544}
545
Colin Cross4157e882019-06-06 16:57:04 -0700546func (m *ModuleBase) VariablesForTests() map[string]string {
547 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800548}
549
Colin Cross4157e882019-06-06 16:57:04 -0700550func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
551 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700552}
553
Colin Crossce75d2c2016-10-06 16:12:58 -0700554// Name returns the name of the module. It may be overridden by individual module types, for
555// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700556func (m *ModuleBase) Name() string {
557 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700558}
559
Colin Crossce75d2c2016-10-06 16:12:58 -0700560// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700561func (m *ModuleBase) BaseModuleName() string {
562 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700563}
564
Colin Cross4157e882019-06-06 16:57:04 -0700565func (m *ModuleBase) base() *ModuleBase {
566 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800567}
568
Colin Cross4157e882019-06-06 16:57:04 -0700569func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
570 m.commonProperties.CompileTarget = target
571 m.commonProperties.CompileMultiTargets = multiTargets
572 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700573}
574
Colin Cross4157e882019-06-06 16:57:04 -0700575func (m *ModuleBase) Target() Target {
576 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800577}
578
Colin Cross4157e882019-06-06 16:57:04 -0700579func (m *ModuleBase) TargetPrimary() bool {
580 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700581}
582
Colin Cross4157e882019-06-06 16:57:04 -0700583func (m *ModuleBase) MultiTargets() []Target {
584 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700585}
586
Colin Cross4157e882019-06-06 16:57:04 -0700587func (m *ModuleBase) Os() OsType {
588 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800589}
590
Colin Cross4157e882019-06-06 16:57:04 -0700591func (m *ModuleBase) Host() bool {
592 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800593}
594
Colin Cross4157e882019-06-06 16:57:04 -0700595func (m *ModuleBase) Arch() Arch {
596 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800597}
598
Colin Cross4157e882019-06-06 16:57:04 -0700599func (m *ModuleBase) ArchSpecific() bool {
600 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700601}
602
Colin Cross4157e882019-06-06 16:57:04 -0700603func (m *ModuleBase) OsClassSupported() []OsClass {
604 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700605 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700606 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700607 case HostSupportedNoCross:
608 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700609 case DeviceSupported:
610 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700611 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700612 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700613 if Bool(m.hostAndDeviceProperties.Host_supported) ||
614 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
615 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700616 supported = append(supported, Host, HostCross)
617 }
Colin Cross4157e882019-06-06 16:57:04 -0700618 if m.hostAndDeviceProperties.Device_supported == nil ||
619 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700620 supported = append(supported, Device)
621 }
622 return supported
623 default:
624 return nil
625 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800626}
627
Colin Cross4157e882019-06-06 16:57:04 -0700628func (m *ModuleBase) DeviceSupported() bool {
629 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
630 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
631 (m.hostAndDeviceProperties.Device_supported == nil ||
632 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800633}
634
Colin Cross4157e882019-06-06 16:57:04 -0700635func (m *ModuleBase) Platform() bool {
636 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900637}
638
Colin Cross4157e882019-06-06 16:57:04 -0700639func (m *ModuleBase) DeviceSpecific() bool {
640 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900641}
642
Colin Cross4157e882019-06-06 16:57:04 -0700643func (m *ModuleBase) SocSpecific() bool {
644 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900645}
646
Colin Cross4157e882019-06-06 16:57:04 -0700647func (m *ModuleBase) ProductSpecific() bool {
648 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900649}
650
Colin Cross4157e882019-06-06 16:57:04 -0700651func (m *ModuleBase) ProductServicesSpecific() bool {
652 return Bool(m.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100653}
654
Colin Cross4157e882019-06-06 16:57:04 -0700655func (m *ModuleBase) Enabled() bool {
656 if m.commonProperties.Enabled == nil {
657 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800658 }
Colin Cross4157e882019-06-06 16:57:04 -0700659 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800660}
661
Colin Cross4157e882019-06-06 16:57:04 -0700662func (m *ModuleBase) SkipInstall() {
663 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700664}
665
Colin Cross4157e882019-06-06 16:57:04 -0700666func (m *ModuleBase) ExportedToMake() bool {
667 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900668}
669
Colin Cross4157e882019-06-06 16:57:04 -0700670func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700671 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800672
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700673 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700674 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800675 ctx.VisitDepsDepthFirstIf(isFileInstaller,
676 func(m blueprint.Module) {
677 fileInstaller := m.(fileInstaller)
678 files := fileInstaller.filesToInstall()
679 result = append(result, files...)
680 })
681
682 return result
683}
684
Colin Cross4157e882019-06-06 16:57:04 -0700685func (m *ModuleBase) filesToInstall() Paths {
686 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800687}
688
Colin Cross4157e882019-06-06 16:57:04 -0700689func (m *ModuleBase) NoAddressSanitizer() bool {
690 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800691}
692
Colin Cross4157e882019-06-06 16:57:04 -0700693func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800694 return false
695}
696
Colin Cross4157e882019-06-06 16:57:04 -0700697func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700698 return false
699}
700
Colin Cross4157e882019-06-06 16:57:04 -0700701func (m *ModuleBase) InstallInRecovery() bool {
702 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900703}
704
Colin Cross4157e882019-06-06 16:57:04 -0700705func (m *ModuleBase) Owner() string {
706 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900707}
708
Colin Cross4157e882019-06-06 16:57:04 -0700709func (m *ModuleBase) NoticeFile() OptionalPath {
710 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900711}
712
Colin Cross4157e882019-06-06 16:57:04 -0700713func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700714 allInstalledFiles := Paths{}
715 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800716 ctx.VisitAllModuleVariants(func(module Module) {
717 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700718 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
719 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800720 })
721
Colin Cross0875c522017-11-28 17:34:01 -0800722 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700723
Jeff Gaston088e29e2017-11-29 16:47:17 -0800724 namespacePrefix := ctx.Namespace().(*Namespace).id
725 if namespacePrefix != "" {
726 namespacePrefix = namespacePrefix + "-"
727 }
728
Colin Cross3f40fa42015-01-30 17:27:36 -0800729 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800730 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800731 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700732 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800733 Output: name,
734 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800735 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700736 })
737 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700738 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700739 }
740
741 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800742 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800743 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700744 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800745 Output: name,
746 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700747 })
748 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700749 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700750 }
751
752 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800753 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800754 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800755 suffix = "-soong"
756 }
757
Jeff Gaston088e29e2017-11-29 16:47:17 -0800758 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800759 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700760 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800761 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700762 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800763 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700764
Colin Cross4157e882019-06-06 16:57:04 -0700765 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800766 }
767}
768
Colin Cross4157e882019-06-06 16:57:04 -0700769func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
770 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
771 var deviceSpecific = Bool(m.commonProperties.Device_specific)
772 var productSpecific = Bool(m.commonProperties.Product_specific)
773 var productServicesSpecific = Bool(m.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900774
Dario Frenifd05a742018-05-29 13:28:54 +0100775 msg := "conflicting value set here"
776 if socSpecific && deviceSpecific {
777 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700778 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900779 ctx.PropertyErrorf("vendor", msg)
780 }
Colin Cross4157e882019-06-06 16:57:04 -0700781 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900782 ctx.PropertyErrorf("proprietary", msg)
783 }
Colin Cross4157e882019-06-06 16:57:04 -0700784 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900785 ctx.PropertyErrorf("soc_specific", msg)
786 }
787 }
788
Dario Frenifd05a742018-05-29 13:28:54 +0100789 if productSpecific && productServicesSpecific {
790 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
791 ctx.PropertyErrorf("product_services_specific", msg)
792 }
793
794 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
795 if productSpecific {
796 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
797 } else {
798 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
799 }
800 if deviceSpecific {
801 ctx.PropertyErrorf("device_specific", msg)
802 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700803 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100804 ctx.PropertyErrorf("vendor", msg)
805 }
Colin Cross4157e882019-06-06 16:57:04 -0700806 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100807 ctx.PropertyErrorf("proprietary", msg)
808 }
Colin Cross4157e882019-06-06 16:57:04 -0700809 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100810 ctx.PropertyErrorf("soc_specific", msg)
811 }
812 }
813 }
814
Jiyong Park2db76922017-11-08 16:03:48 +0900815 if productSpecific {
816 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100817 } else if productServicesSpecific {
818 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900819 } else if deviceSpecific {
820 return deviceSpecificModule
821 } else if socSpecific {
822 return socSpecificModule
823 } else {
824 return platformModule
825 }
826}
827
Colin Cross0ea8ba82019-06-06 14:33:29 -0700828func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
829 return baseModuleContext{
830 BaseModuleContext: ctx,
831 target: m.commonProperties.CompileTarget,
832 targetPrimary: m.commonProperties.CompilePrimary,
833 multiTargets: m.commonProperties.CompileMultiTargets,
834 kind: determineModuleKind(m, ctx),
835 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800836 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800837}
838
Colin Cross4157e882019-06-06 16:57:04 -0700839func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700840 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700841 module: m.module,
Colin Cross380c69a2019-06-10 17:49:58 +0000842 ModuleContext: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700843 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
844 installDeps: m.computeInstallDeps(blueprintCtx),
845 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700846 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800847 }
848
Colin Cross6c4f21f2019-06-06 15:41:36 -0700849 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
850 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
851 // TODO: This will be removed once defaults modules handle missing dependency errors
852 blueprintCtx.GetMissingDependencies()
853
Colin Cross4c83e5c2019-02-25 14:54:28 -0800854 if ctx.config.captureBuild {
855 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
856 }
857
Colin Cross67a5c132017-05-09 13:45:28 -0700858 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
859 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800860 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
861 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700862 }
Colin Cross0875c522017-11-28 17:34:01 -0800863 if !ctx.PrimaryArch() {
864 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700865 }
866
867 ctx.Variable(pctx, "moduleDesc", desc)
868
869 s := ""
870 if len(suffix) > 0 {
871 s = " [" + strings.Join(suffix, " ") + "]"
872 }
873 ctx.Variable(pctx, "moduleDescSuffix", s)
874
Dan Willemsen569edc52018-11-19 09:33:29 -0800875 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700876 if m.commonProperties.Dist.Dest != nil {
877 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800878 if err != nil {
879 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
880 }
881 }
Colin Cross4157e882019-06-06 16:57:04 -0700882 if m.commonProperties.Dist.Dir != nil {
883 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800884 if err != nil {
885 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
886 }
887 }
Colin Cross4157e882019-06-06 16:57:04 -0700888 if m.commonProperties.Dist.Suffix != nil {
889 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -0800890 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
891 }
892 }
893
Colin Cross4157e882019-06-06 16:57:04 -0700894 if m.Enabled() {
895 m.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700896 if ctx.Failed() {
897 return
898 }
899
Colin Cross4157e882019-06-06 16:57:04 -0700900 m.installFiles = append(m.installFiles, ctx.installFiles...)
901 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800902
Colin Cross4157e882019-06-06 16:57:04 -0700903 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
904 if module := SrcIsModule(notice); module != "" {
905 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +0900906 } else {
907 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -0700908 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800909 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800910 }
911
Colin Cross4157e882019-06-06 16:57:04 -0700912 if m == ctx.FinalModule().(Module).base() {
913 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700914 if ctx.Failed() {
915 return
916 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800917 }
Colin Crosscec81712017-07-13 14:43:27 -0700918
Colin Cross4157e882019-06-06 16:57:04 -0700919 m.buildParams = ctx.buildParams
920 m.ruleParams = ctx.ruleParams
921 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800922}
923
Colin Cross0ea8ba82019-06-06 14:33:29 -0700924type baseModuleContext struct {
925 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -0700926 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700927 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700928 targetPrimary bool
929 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900930 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700931 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700932}
933
Colin Cross25de6c32019-06-06 14:29:25 -0700934type moduleContext struct {
Colin Cross380c69a2019-06-10 17:49:58 +0000935 blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700936 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700937 installDeps Paths
938 installFiles Paths
939 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -0700940 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700941
942 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700943 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800944 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800945 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800946}
947
Colin Crossb88b3c52019-06-10 15:15:17 -0700948func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
949 return pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700950 Rule: ErrorRule,
Colin Crossb88b3c52019-06-10 15:15:17 -0700951 Description: params.Description,
952 Output: params.Output,
953 Outputs: params.Outputs,
Colin Cross6ff51382015-12-17 16:39:19 -0800954 Args: map[string]string{
955 "error": err.Error(),
956 },
Colin Crossb88b3c52019-06-10 15:15:17 -0700957 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800958}
959
Colin Cross380c69a2019-06-10 17:49:58 +0000960func (m *moduleContext) Config() Config {
961 return m.ModuleContext.Config().(Config)
962}
963
Colin Cross25de6c32019-06-06 14:29:25 -0700964func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
965 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800966}
967
Colin Cross0875c522017-11-28 17:34:01 -0800968func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700969 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700970 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800971 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800972 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700973 Outputs: params.Outputs.Strings(),
974 ImplicitOutputs: params.ImplicitOutputs.Strings(),
975 Inputs: params.Inputs.Strings(),
976 Implicits: params.Implicits.Strings(),
977 OrderOnly: params.OrderOnly.Strings(),
978 Args: params.Args,
979 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700980 }
981
Colin Cross33bfb0a2016-11-21 17:23:08 -0800982 if params.Depfile != nil {
983 bparams.Depfile = params.Depfile.String()
984 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700985 if params.Output != nil {
986 bparams.Outputs = append(bparams.Outputs, params.Output.String())
987 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700988 if params.ImplicitOutput != nil {
989 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
990 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700991 if params.Input != nil {
992 bparams.Inputs = append(bparams.Inputs, params.Input.String())
993 }
994 if params.Implicit != nil {
995 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
996 }
997
Colin Cross0b9f31f2019-02-28 11:00:01 -0800998 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
999 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1000 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1001 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1002 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1003 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001004
Colin Cross0875c522017-11-28 17:34:01 -08001005 return bparams
1006}
1007
Colin Cross25de6c32019-06-06 14:29:25 -07001008func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1009 if m.config.captureBuild {
1010 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001011 }
1012
Colin Cross380c69a2019-06-10 17:49:58 +00001013 m.ModuleContext.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001014}
1015
Colin Cross25de6c32019-06-06 14:29:25 -07001016func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001017 argNames ...string) blueprint.Rule {
1018
Colin Cross380c69a2019-06-10 17:49:58 +00001019 rule := m.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001020
Colin Cross25de6c32019-06-06 14:29:25 -07001021 if m.config.captureBuild {
1022 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001023 }
1024
1025 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001026}
1027
Colin Cross25de6c32019-06-06 14:29:25 -07001028func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001029 if params.Description != "" {
1030 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1031 }
1032
1033 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1034 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1035 m.ModuleName(), strings.Join(missingDeps, ", ")))
1036 }
1037
Colin Cross25de6c32019-06-06 14:29:25 -07001038 if m.config.captureBuild {
1039 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001040 }
1041
Colin Crossb88b3c52019-06-10 15:15:17 -07001042 m.ModuleContext.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001043}
1044
Colin Cross6c4f21f2019-06-06 15:41:36 -07001045func (m *moduleContext) Module() Module {
1046 return m.ModuleContext.Module().(Module)
1047}
1048
Colin Cross25de6c32019-06-06 14:29:25 -07001049func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001050 var missingDeps []string
1051 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
1052 missingDeps = append(missingDeps, m.ModuleContext.GetMissingDependencies()...)
1053 missingDeps = FirstUniqueStrings(missingDeps)
1054 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001055}
1056
Colin Cross25de6c32019-06-06 14:29:25 -07001057func (m *moduleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001058 if deps != nil {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001059 missingDeps := &m.Module().base().commonProperties.MissingDeps
1060 *missingDeps = append(*missingDeps, deps...)
1061 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001062 }
1063}
1064
Colin Cross380c69a2019-06-10 17:49:58 +00001065func (m *moduleContext) validateAndroidModule(module blueprint.Module) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001066 aModule, _ := module.(Module)
Colin Cross380c69a2019-06-10 17:49:58 +00001067 if aModule == nil {
1068 m.ModuleErrorf("module %q not an android module", m.OtherModuleName(aModule))
1069 return nil
1070 }
1071
1072 if !aModule.Enabled() {
1073 if m.Config().AllowMissingDependencies() {
1074 m.AddMissingDependencies([]string{m.OtherModuleName(aModule)})
1075 } else {
1076 m.ModuleErrorf("depends on disabled module %q", m.OtherModuleName(aModule))
1077 }
1078 return nil
1079 }
1080
Colin Crossd11fcda2017-10-23 17:59:01 -07001081 return aModule
1082}
1083
Colin Cross380c69a2019-06-10 17:49:58 +00001084func (m *moduleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001085 type dep struct {
1086 mod blueprint.Module
1087 tag blueprint.DependencyTag
1088 }
1089 var deps []dep
Colin Cross380c69a2019-06-10 17:49:58 +00001090 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001091 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross380c69a2019-06-10 17:49:58 +00001092 returnedTag := m.ModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001093 if tag == nil || returnedTag == tag {
1094 deps = append(deps, dep{aModule, returnedTag})
1095 }
1096 }
1097 })
1098 if len(deps) == 1 {
1099 return deps[0].mod, deps[0].tag
1100 } else if len(deps) >= 2 {
1101 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Cross380c69a2019-06-10 17:49:58 +00001102 name, m.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001103 } else {
1104 return nil, nil
1105 }
1106}
1107
Colin Cross380c69a2019-06-10 17:49:58 +00001108func (m *moduleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001109 var deps []Module
Colin Cross380c69a2019-06-10 17:49:58 +00001110 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001111 if aModule, _ := module.(Module); aModule != nil {
Colin Cross380c69a2019-06-10 17:49:58 +00001112 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001113 deps = append(deps, aModule)
1114 }
1115 }
1116 })
1117 return deps
1118}
1119
Colin Cross25de6c32019-06-06 14:29:25 -07001120func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1121 module, _ := m.getDirectDepInternal(name, tag)
1122 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001123}
1124
Colin Cross380c69a2019-06-10 17:49:58 +00001125func (m *moduleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1126 return m.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001127}
1128
Colin Cross380c69a2019-06-10 17:49:58 +00001129func (m *moduleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1130 m.ModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001131}
1132
Colin Cross380c69a2019-06-10 17:49:58 +00001133func (m *moduleContext) VisitDirectDeps(visit func(Module)) {
1134 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1135 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001136 visit(aModule)
1137 }
1138 })
1139}
1140
Colin Cross380c69a2019-06-10 17:49:58 +00001141func (m *moduleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1142 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1143 if aModule := m.validateAndroidModule(module); aModule != nil {
1144 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001145 visit(aModule)
1146 }
1147 }
1148 })
1149}
1150
Colin Cross380c69a2019-06-10 17:49:58 +00001151func (m *moduleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1152 m.ModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001153 // pred
1154 func(module blueprint.Module) bool {
Colin Cross380c69a2019-06-10 17:49:58 +00001155 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001156 return pred(aModule)
1157 } else {
1158 return false
1159 }
1160 },
1161 // visit
1162 func(module blueprint.Module) {
1163 visit(module.(Module))
1164 })
1165}
1166
Colin Cross380c69a2019-06-10 17:49:58 +00001167func (m *moduleContext) VisitDepsDepthFirst(visit func(Module)) {
1168 m.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1169 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001170 visit(aModule)
1171 }
1172 })
1173}
1174
Colin Cross380c69a2019-06-10 17:49:58 +00001175func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1176 m.ModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001177 // pred
1178 func(module blueprint.Module) bool {
Colin Cross380c69a2019-06-10 17:49:58 +00001179 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001180 return pred(aModule)
1181 } else {
1182 return false
1183 }
1184 },
1185 // visit
1186 func(module blueprint.Module) {
1187 visit(module.(Module))
1188 })
1189}
1190
Colin Cross380c69a2019-06-10 17:49:58 +00001191func (m *moduleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1192 m.ModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001193}
1194
Colin Cross380c69a2019-06-10 17:49:58 +00001195func (m *moduleContext) WalkDeps(visit func(Module, Module) bool) {
1196 m.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1197 childAndroidModule := m.validateAndroidModule(child)
1198 parentAndroidModule := m.validateAndroidModule(parent)
Colin Crossd11fcda2017-10-23 17:59:01 -07001199 if childAndroidModule != nil && parentAndroidModule != nil {
1200 return visit(childAndroidModule, parentAndroidModule)
1201 } else {
1202 return false
1203 }
1204 })
1205}
1206
Colin Cross25de6c32019-06-06 14:29:25 -07001207func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Cross380c69a2019-06-10 17:49:58 +00001208 m.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001209 visit(module.(Module))
1210 })
1211}
1212
Colin Cross25de6c32019-06-06 14:29:25 -07001213func (m *moduleContext) PrimaryModule() Module {
Colin Cross380c69a2019-06-10 17:49:58 +00001214 return m.ModuleContext.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001215}
1216
Colin Cross25de6c32019-06-06 14:29:25 -07001217func (m *moduleContext) FinalModule() Module {
Colin Cross380c69a2019-06-10 17:49:58 +00001218 return m.ModuleContext.FinalModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001219}
1220
Colin Cross0ea8ba82019-06-06 14:33:29 -07001221func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001222 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001223}
1224
Colin Cross0ea8ba82019-06-06 14:33:29 -07001225func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001226 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001227}
1228
Colin Cross0ea8ba82019-06-06 14:33:29 -07001229func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001230 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001231}
1232
Colin Cross0ea8ba82019-06-06 14:33:29 -07001233func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001234 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001235}
1236
Colin Cross0ea8ba82019-06-06 14:33:29 -07001237func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001238 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001239}
1240
Colin Cross0ea8ba82019-06-06 14:33:29 -07001241func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001242 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001243}
1244
Colin Cross0ea8ba82019-06-06 14:33:29 -07001245func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001246 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001247}
1248
Colin Cross0ea8ba82019-06-06 14:33:29 -07001249func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001250 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001251}
1252
Colin Cross0ea8ba82019-06-06 14:33:29 -07001253func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001254 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001255}
1256
Colin Cross0ea8ba82019-06-06 14:33:29 -07001257func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001258 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001259}
1260
Colin Cross0ea8ba82019-06-06 14:33:29 -07001261func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001262 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001263}
1264
Colin Cross0ea8ba82019-06-06 14:33:29 -07001265func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001266 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001267 return true
1268 }
Colin Cross25de6c32019-06-06 14:29:25 -07001269 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001270}
1271
Colin Cross0ea8ba82019-06-06 14:33:29 -07001272func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001273 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001274}
1275
Colin Cross0ea8ba82019-06-06 14:33:29 -07001276func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001277 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001278}
1279
Colin Cross0ea8ba82019-06-06 14:33:29 -07001280func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001281 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001282}
1283
Colin Cross0ea8ba82019-06-06 14:33:29 -07001284func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001285 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001286}
1287
Colin Cross0ea8ba82019-06-06 14:33:29 -07001288func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001289 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001290}
1291
Colin Cross0ea8ba82019-06-06 14:33:29 -07001292func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001293 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001294}
1295
Colin Cross0ea8ba82019-06-06 14:33:29 -07001296func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001297 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001298}
1299
Jiyong Park5baac542018-08-28 09:55:37 +09001300// Makes this module a platform module, i.e. not specific to soc, device,
1301// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001302func (m *ModuleBase) MakeAsPlatform() {
1303 m.commonProperties.Vendor = boolPtr(false)
1304 m.commonProperties.Proprietary = boolPtr(false)
1305 m.commonProperties.Soc_specific = boolPtr(false)
1306 m.commonProperties.Product_specific = boolPtr(false)
1307 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001308}
1309
Colin Cross4157e882019-06-06 16:57:04 -07001310func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1311 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001312}
1313
Colin Cross25de6c32019-06-06 14:29:25 -07001314func (m *moduleContext) InstallInData() bool {
1315 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001316}
1317
Colin Cross25de6c32019-06-06 14:29:25 -07001318func (m *moduleContext) InstallInSanitizerDir() bool {
1319 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001320}
1321
Colin Cross25de6c32019-06-06 14:29:25 -07001322func (m *moduleContext) InstallInRecovery() bool {
1323 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001324}
1325
Colin Cross25de6c32019-06-06 14:29:25 -07001326func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1327 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001328 return true
1329 }
1330
Colin Cross3607f212018-05-07 15:28:05 -07001331 // We'll need a solution for choosing which of modules with the same name in different
1332 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1333 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001334 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001335 return true
1336 }
1337
Colin Cross25de6c32019-06-06 14:29:25 -07001338 if m.Device() {
1339 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001340 return true
1341 }
1342
Colin Cross25de6c32019-06-06 14:29:25 -07001343 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001344 return true
1345 }
1346 }
1347
1348 return false
1349}
1350
Colin Cross25de6c32019-06-06 14:29:25 -07001351func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001352 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001353 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001354}
1355
Colin Cross25de6c32019-06-06 14:29:25 -07001356func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001357 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001358 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001359}
1360
Colin Cross25de6c32019-06-06 14:29:25 -07001361func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001362 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001363
Colin Cross25de6c32019-06-06 14:29:25 -07001364 fullInstallPath := installPath.Join(m, name)
1365 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001366
Colin Cross25de6c32019-06-06 14:29:25 -07001367 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001368
Colin Cross25de6c32019-06-06 14:29:25 -07001369 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001370
Colin Cross89562dc2016-10-03 17:47:19 -07001371 var implicitDeps, orderOnlyDeps Paths
1372
Colin Cross25de6c32019-06-06 14:29:25 -07001373 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001374 // Installed host modules might be used during the build, depend directly on their
1375 // dependencies so their timestamp is updated whenever their dependency is updated
1376 implicitDeps = deps
1377 } else {
1378 orderOnlyDeps = deps
1379 }
1380
Colin Cross25de6c32019-06-06 14:29:25 -07001381 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001382 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001383 Description: "install " + fullInstallPath.Base(),
1384 Output: fullInstallPath,
1385 Input: srcPath,
1386 Implicits: implicitDeps,
1387 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001388 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001389 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001390
Colin Cross25de6c32019-06-06 14:29:25 -07001391 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001392 }
Colin Cross25de6c32019-06-06 14:29:25 -07001393 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001394 return fullInstallPath
1395}
1396
Colin Cross25de6c32019-06-06 14:29:25 -07001397func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1398 fullInstallPath := installPath.Join(m, name)
1399 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001400
Colin Cross25de6c32019-06-06 14:29:25 -07001401 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001402
Alex Lightfb4353d2019-01-17 13:57:45 -08001403 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1404 if err != nil {
1405 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1406 }
Colin Cross25de6c32019-06-06 14:29:25 -07001407 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001408 Rule: Symlink,
1409 Description: "install symlink " + fullInstallPath.Base(),
1410 Output: fullInstallPath,
1411 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001412 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001413 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001414 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001415 },
1416 })
Colin Cross3854a602016-01-11 12:49:11 -08001417
Colin Cross25de6c32019-06-06 14:29:25 -07001418 m.installFiles = append(m.installFiles, fullInstallPath)
1419 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001420 }
Colin Cross3854a602016-01-11 12:49:11 -08001421 return fullInstallPath
1422}
1423
Jiyong Parkf1194352019-02-25 11:05:47 +09001424// installPath/name -> absPath where absPath might be a path that is available only at runtime
1425// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001426func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1427 fullInstallPath := installPath.Join(m, name)
1428 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001429
Colin Cross25de6c32019-06-06 14:29:25 -07001430 if !m.skipInstall(fullInstallPath) {
1431 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001432 Rule: Symlink,
1433 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1434 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001435 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001436 Args: map[string]string{
1437 "fromPath": absPath,
1438 },
1439 })
1440
Colin Cross25de6c32019-06-06 14:29:25 -07001441 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001442 }
1443 return fullInstallPath
1444}
1445
Colin Cross25de6c32019-06-06 14:29:25 -07001446func (m *moduleContext) CheckbuildFile(srcPath Path) {
1447 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001448}
1449
Colin Cross3f40fa42015-01-30 17:27:36 -08001450type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001451 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001452}
1453
1454func isFileInstaller(m blueprint.Module) bool {
1455 _, ok := m.(fileInstaller)
1456 return ok
1457}
1458
1459func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001460 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001461 return ok
1462}
Colin Crossfce53272015-04-08 11:21:40 -07001463
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001464func findStringInSlice(str string, slice []string) int {
1465 for i, s := range slice {
1466 if s == str {
1467 return i
Colin Crossfce53272015-04-08 11:21:40 -07001468 }
1469 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001470 return -1
1471}
1472
Colin Cross41955e82019-05-29 14:40:35 -07001473// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1474// was not a module reference.
1475func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001476 if len(s) > 1 && s[0] == ':' {
1477 return s[1:]
1478 }
1479 return ""
1480}
1481
Colin Cross41955e82019-05-29 14:40:35 -07001482// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1483// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1484func SrcIsModuleWithTag(s string) (module, tag string) {
1485 if len(s) > 1 && s[0] == ':' {
1486 module = s[1:]
1487 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1488 if module[len(module)-1] == '}' {
1489 tag = module[tagStart+1 : len(module)-1]
1490 module = module[:tagStart]
1491 return module, tag
1492 }
1493 }
1494 return module, ""
1495 }
1496 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001497}
1498
Colin Cross41955e82019-05-29 14:40:35 -07001499type sourceOrOutputDependencyTag struct {
1500 blueprint.BaseDependencyTag
1501 tag string
1502}
1503
1504func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1505 return sourceOrOutputDependencyTag{tag: tag}
1506}
1507
1508var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001509
Colin Cross366938f2017-12-11 16:29:02 -08001510// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1511// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001512//
1513// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001514func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001515 set := make(map[string]bool)
1516
Colin Cross068e0fe2016-12-13 15:23:47 -08001517 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001518 if m, t := SrcIsModuleWithTag(s); m != "" {
1519 if _, found := set[s]; found {
1520 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001521 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001522 set[s] = true
1523 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001524 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001525 }
1526 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001527}
1528
Colin Cross366938f2017-12-11 16:29:02 -08001529// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1530// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001531//
1532// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001533func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1534 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001535 if m, t := SrcIsModuleWithTag(*s); m != "" {
1536 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001537 }
1538 }
1539}
1540
Colin Cross41955e82019-05-29 14:40:35 -07001541// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1542// 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 -08001543type SourceFileProducer interface {
1544 Srcs() Paths
1545}
1546
Colin Cross41955e82019-05-29 14:40:35 -07001547// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1548// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1549// listed in the property.
1550type OutputFileProducer interface {
1551 OutputFiles(tag string) (Paths, error)
1552}
1553
Colin Crossfe17f6f2019-03-28 19:30:56 -07001554type HostToolProvider interface {
1555 HostToolPath() OptionalPath
1556}
1557
Colin Cross27b922f2019-03-04 22:35:41 -08001558// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1559// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001560//
1561// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001562func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1563 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001564}
1565
Colin Cross2fafa3e2019-03-05 12:39:51 -08001566// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1567// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001568//
1569// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001570func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1571 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001572}
1573
1574// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1575// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1576// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001577func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001578 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001579 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001580 }
1581 return OptionalPath{}
1582}
1583
Colin Cross25de6c32019-06-06 14:29:25 -07001584func (m *moduleContext) RequiredModuleNames() []string {
1585 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001586}
1587
Colin Cross25de6c32019-06-06 14:29:25 -07001588func (m *moduleContext) HostRequiredModuleNames() []string {
1589 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001590}
1591
Colin Cross25de6c32019-06-06 14:29:25 -07001592func (m *moduleContext) TargetRequiredModuleNames() []string {
1593 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001594}
1595
Colin Cross380c69a2019-06-10 17:49:58 +00001596func (m *moduleContext) Glob(globPattern string, excludes []string) Paths {
1597 ret, err := m.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001598 if err != nil {
Colin Cross380c69a2019-06-10 17:49:58 +00001599 m.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001600 }
Colin Cross380c69a2019-06-10 17:49:58 +00001601 return pathsForModuleSrcFromFullPath(m, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001602}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001603
Colin Cross380c69a2019-06-10 17:49:58 +00001604func (m *moduleContext) GlobFiles(globPattern string, excludes []string) Paths {
1605 ret, err := m.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001606 if err != nil {
Colin Cross380c69a2019-06-10 17:49:58 +00001607 m.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001608 }
Colin Cross380c69a2019-06-10 17:49:58 +00001609 return pathsForModuleSrcFromFullPath(m, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001610}
1611
Colin Cross463a90e2015-06-17 14:20:06 -07001612func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001613 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001614}
1615
Colin Cross0875c522017-11-28 17:34:01 -08001616func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001617 return &buildTargetSingleton{}
1618}
1619
Colin Cross87d8b562017-04-25 10:01:55 -07001620func parentDir(dir string) string {
1621 dir, _ = filepath.Split(dir)
1622 return filepath.Clean(dir)
1623}
1624
Colin Cross1f8c52b2015-06-16 16:38:17 -07001625type buildTargetSingleton struct{}
1626
Colin Cross0875c522017-11-28 17:34:01 -08001627func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1628 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001629
Colin Cross0875c522017-11-28 17:34:01 -08001630 mmTarget := func(dir string) WritablePath {
1631 return PathForPhony(ctx,
1632 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001633 }
1634
Colin Cross0875c522017-11-28 17:34:01 -08001635 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001636
Colin Cross0875c522017-11-28 17:34:01 -08001637 ctx.VisitAllModules(func(module Module) {
1638 blueprintDir := module.base().blueprintDir
1639 installTarget := module.base().installTarget
1640 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001641
Colin Cross0875c522017-11-28 17:34:01 -08001642 if checkbuildTarget != nil {
1643 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1644 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1645 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001646
Colin Cross0875c522017-11-28 17:34:01 -08001647 if installTarget != nil {
1648 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001649 }
1650 })
1651
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001652 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001653 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001654 suffix = "-soong"
1655 }
1656
Colin Cross1f8c52b2015-06-16 16:38:17 -07001657 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001658 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001659 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001660 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001661 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001662 })
1663
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001664 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001665 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001666 return
1667 }
1668
Colin Cross87d8b562017-04-25 10:01:55 -07001669 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001670 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001671 for _, dir := range dirs {
1672 dir := parentDir(dir)
1673 for dir != "." && dir != "/" {
1674 if _, exists := modulesInDir[dir]; exists {
1675 break
1676 }
1677 modulesInDir[dir] = nil
1678 dir = parentDir(dir)
1679 }
1680 }
1681
1682 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001683 for _, dir := range dirs {
1684 p := parentDir(dir)
1685 if p != "." && p != "/" {
1686 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1687 }
1688 }
1689
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001690 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1691 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1692 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001693 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001694 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001695 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001696 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001697 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001698 // HACK: checkbuild should be an optional build, but force it
1699 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001700 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001701 })
1702 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001703
1704 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1705 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001706 ctx.VisitAllModules(func(module Module) {
1707 if module.Enabled() {
1708 os := module.Target().Os
1709 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001710 }
1711 })
1712
Colin Cross0875c522017-11-28 17:34:01 -08001713 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001714 for os, deps := range osDeps {
1715 var className string
1716
1717 switch os.Class {
1718 case Host:
1719 className = "host"
1720 case HostCross:
1721 className = "host-cross"
1722 case Device:
1723 className = "target"
1724 default:
1725 continue
1726 }
1727
Colin Cross0875c522017-11-28 17:34:01 -08001728 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001729 osClass[className] = append(osClass[className], name)
1730
Colin Cross0875c522017-11-28 17:34:01 -08001731 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001732 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001733 Output: name,
1734 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001735 })
1736 }
1737
1738 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001739 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001740 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001741 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001742 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001743 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001744 })
1745 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001746}
Colin Crossd779da42015-12-17 18:00:23 -08001747
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001748// Collect information for opening IDE project files in java/jdeps.go.
1749type IDEInfo interface {
1750 IDEInfo(ideInfo *IdeInfo)
1751 BaseModuleName() string
1752}
1753
1754// Extract the base module name from the Import name.
1755// Often the Import name has a prefix "prebuilt_".
1756// Remove the prefix explicitly if needed
1757// until we find a better solution to get the Import name.
1758type IDECustomizedModuleName interface {
1759 IDECustomizedModuleName() string
1760}
1761
1762type IdeInfo struct {
1763 Deps []string `json:"dependencies,omitempty"`
1764 Srcs []string `json:"srcs,omitempty"`
1765 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1766 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1767 Jars []string `json:"jars,omitempty"`
1768 Classes []string `json:"class,omitempty"`
1769 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001770 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001771}