blob: 2481000fe9039d56b927cad49b8eed269d8295b6 [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 Cross25de6c32019-06-06 14:29:25 -0700948func (m *moduleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross380c69a2019-06-10 17:49:58 +0000949 m.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700950 Rule: ErrorRule,
951 Description: desc,
952 Outputs: outputs,
953 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800954 Args: map[string]string{
955 "error": err.Error(),
956 },
957 })
958 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800959}
960
Colin Cross380c69a2019-06-10 17:49:58 +0000961func (m *moduleContext) Config() Config {
962 return m.ModuleContext.Config().(Config)
963}
964
Colin Cross25de6c32019-06-06 14:29:25 -0700965func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
966 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800967}
968
Colin Cross0875c522017-11-28 17:34:01 -0800969func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700970 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700971 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800972 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800973 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700974 Outputs: params.Outputs.Strings(),
975 ImplicitOutputs: params.ImplicitOutputs.Strings(),
976 Inputs: params.Inputs.Strings(),
977 Implicits: params.Implicits.Strings(),
978 OrderOnly: params.OrderOnly.Strings(),
979 Args: params.Args,
980 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700981 }
982
Colin Cross33bfb0a2016-11-21 17:23:08 -0800983 if params.Depfile != nil {
984 bparams.Depfile = params.Depfile.String()
985 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700986 if params.Output != nil {
987 bparams.Outputs = append(bparams.Outputs, params.Output.String())
988 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700989 if params.ImplicitOutput != nil {
990 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
991 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700992 if params.Input != nil {
993 bparams.Inputs = append(bparams.Inputs, params.Input.String())
994 }
995 if params.Implicit != nil {
996 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
997 }
998
Colin Cross0b9f31f2019-02-28 11:00:01 -0800999 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1000 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1001 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1002 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1003 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1004 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001005
Colin Cross0875c522017-11-28 17:34:01 -08001006 return bparams
1007}
1008
Colin Cross25de6c32019-06-06 14:29:25 -07001009func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1010 if m.config.captureBuild {
1011 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001012 }
1013
Colin Cross380c69a2019-06-10 17:49:58 +00001014 m.ModuleContext.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001015}
1016
Colin Cross25de6c32019-06-06 14:29:25 -07001017func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001018 argNames ...string) blueprint.Rule {
1019
Colin Cross380c69a2019-06-10 17:49:58 +00001020 rule := m.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001021
Colin Cross25de6c32019-06-06 14:29:25 -07001022 if m.config.captureBuild {
1023 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001024 }
1025
1026 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001027}
1028
Colin Cross25de6c32019-06-06 14:29:25 -07001029func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
1030 if m.config.captureBuild {
1031 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001032 }
1033
1034 bparams := convertBuildParams(params)
1035
1036 if bparams.Description != "" {
1037 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1038 }
1039
Colin Cross6c4f21f2019-06-06 15:41:36 -07001040 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
Colin Cross25de6c32019-06-06 14:29:25 -07001041 m.ninjaError(bparams.Description, bparams.Outputs,
Colin Cross67a5c132017-05-09 13:45:28 -07001042 fmt.Errorf("module %s missing dependencies: %s\n",
Colin Cross6c4f21f2019-06-06 15:41:36 -07001043 m.ModuleName(), strings.Join(missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001044 return
1045 }
1046
Colin Cross380c69a2019-06-10 17:49:58 +00001047 m.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001048}
1049
Colin Cross6c4f21f2019-06-06 15:41:36 -07001050func (m *moduleContext) Module() Module {
1051 return m.ModuleContext.Module().(Module)
1052}
1053
Colin Cross25de6c32019-06-06 14:29:25 -07001054func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001055 var missingDeps []string
1056 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
1057 missingDeps = append(missingDeps, m.ModuleContext.GetMissingDependencies()...)
1058 missingDeps = FirstUniqueStrings(missingDeps)
1059 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001060}
1061
Colin Cross25de6c32019-06-06 14:29:25 -07001062func (m *moduleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001063 if deps != nil {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001064 missingDeps := &m.Module().base().commonProperties.MissingDeps
1065 *missingDeps = append(*missingDeps, deps...)
1066 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001067 }
1068}
1069
Colin Cross380c69a2019-06-10 17:49:58 +00001070func (m *moduleContext) validateAndroidModule(module blueprint.Module) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001071 aModule, _ := module.(Module)
Colin Cross380c69a2019-06-10 17:49:58 +00001072 if aModule == nil {
1073 m.ModuleErrorf("module %q not an android module", m.OtherModuleName(aModule))
1074 return nil
1075 }
1076
1077 if !aModule.Enabled() {
1078 if m.Config().AllowMissingDependencies() {
1079 m.AddMissingDependencies([]string{m.OtherModuleName(aModule)})
1080 } else {
1081 m.ModuleErrorf("depends on disabled module %q", m.OtherModuleName(aModule))
1082 }
1083 return nil
1084 }
1085
Colin Crossd11fcda2017-10-23 17:59:01 -07001086 return aModule
1087}
1088
Colin Cross380c69a2019-06-10 17:49:58 +00001089func (m *moduleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001090 type dep struct {
1091 mod blueprint.Module
1092 tag blueprint.DependencyTag
1093 }
1094 var deps []dep
Colin Cross380c69a2019-06-10 17:49:58 +00001095 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001096 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross380c69a2019-06-10 17:49:58 +00001097 returnedTag := m.ModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001098 if tag == nil || returnedTag == tag {
1099 deps = append(deps, dep{aModule, returnedTag})
1100 }
1101 }
1102 })
1103 if len(deps) == 1 {
1104 return deps[0].mod, deps[0].tag
1105 } else if len(deps) >= 2 {
1106 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Cross380c69a2019-06-10 17:49:58 +00001107 name, m.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001108 } else {
1109 return nil, nil
1110 }
1111}
1112
Colin Cross380c69a2019-06-10 17:49:58 +00001113func (m *moduleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001114 var deps []Module
Colin Cross380c69a2019-06-10 17:49:58 +00001115 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001116 if aModule, _ := module.(Module); aModule != nil {
Colin Cross380c69a2019-06-10 17:49:58 +00001117 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001118 deps = append(deps, aModule)
1119 }
1120 }
1121 })
1122 return deps
1123}
1124
Colin Cross25de6c32019-06-06 14:29:25 -07001125func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1126 module, _ := m.getDirectDepInternal(name, tag)
1127 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001128}
1129
Colin Cross380c69a2019-06-10 17:49:58 +00001130func (m *moduleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1131 return m.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001132}
1133
Colin Cross380c69a2019-06-10 17:49:58 +00001134func (m *moduleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1135 m.ModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001136}
1137
Colin Cross380c69a2019-06-10 17:49:58 +00001138func (m *moduleContext) VisitDirectDeps(visit func(Module)) {
1139 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1140 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001141 visit(aModule)
1142 }
1143 })
1144}
1145
Colin Cross380c69a2019-06-10 17:49:58 +00001146func (m *moduleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1147 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1148 if aModule := m.validateAndroidModule(module); aModule != nil {
1149 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001150 visit(aModule)
1151 }
1152 }
1153 })
1154}
1155
Colin Cross380c69a2019-06-10 17:49:58 +00001156func (m *moduleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1157 m.ModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001158 // pred
1159 func(module blueprint.Module) bool {
Colin Cross380c69a2019-06-10 17:49:58 +00001160 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001161 return pred(aModule)
1162 } else {
1163 return false
1164 }
1165 },
1166 // visit
1167 func(module blueprint.Module) {
1168 visit(module.(Module))
1169 })
1170}
1171
Colin Cross380c69a2019-06-10 17:49:58 +00001172func (m *moduleContext) VisitDepsDepthFirst(visit func(Module)) {
1173 m.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1174 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001175 visit(aModule)
1176 }
1177 })
1178}
1179
Colin Cross380c69a2019-06-10 17:49:58 +00001180func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1181 m.ModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001182 // pred
1183 func(module blueprint.Module) bool {
Colin Cross380c69a2019-06-10 17:49:58 +00001184 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001185 return pred(aModule)
1186 } else {
1187 return false
1188 }
1189 },
1190 // visit
1191 func(module blueprint.Module) {
1192 visit(module.(Module))
1193 })
1194}
1195
Colin Cross380c69a2019-06-10 17:49:58 +00001196func (m *moduleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1197 m.ModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001198}
1199
Colin Cross380c69a2019-06-10 17:49:58 +00001200func (m *moduleContext) WalkDeps(visit func(Module, Module) bool) {
1201 m.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1202 childAndroidModule := m.validateAndroidModule(child)
1203 parentAndroidModule := m.validateAndroidModule(parent)
Colin Crossd11fcda2017-10-23 17:59:01 -07001204 if childAndroidModule != nil && parentAndroidModule != nil {
1205 return visit(childAndroidModule, parentAndroidModule)
1206 } else {
1207 return false
1208 }
1209 })
1210}
1211
Colin Cross25de6c32019-06-06 14:29:25 -07001212func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Cross380c69a2019-06-10 17:49:58 +00001213 m.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001214 visit(module.(Module))
1215 })
1216}
1217
Colin Cross25de6c32019-06-06 14:29:25 -07001218func (m *moduleContext) PrimaryModule() Module {
Colin Cross380c69a2019-06-10 17:49:58 +00001219 return m.ModuleContext.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001220}
1221
Colin Cross25de6c32019-06-06 14:29:25 -07001222func (m *moduleContext) FinalModule() Module {
Colin Cross380c69a2019-06-10 17:49:58 +00001223 return m.ModuleContext.FinalModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001224}
1225
Colin Cross0ea8ba82019-06-06 14:33:29 -07001226func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001227 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001228}
1229
Colin Cross0ea8ba82019-06-06 14:33:29 -07001230func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001231 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001232}
1233
Colin Cross0ea8ba82019-06-06 14:33:29 -07001234func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001235 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001236}
1237
Colin Cross0ea8ba82019-06-06 14:33:29 -07001238func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001239 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001240}
1241
Colin Cross0ea8ba82019-06-06 14:33:29 -07001242func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001243 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001244}
1245
Colin Cross0ea8ba82019-06-06 14:33:29 -07001246func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001247 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001248}
1249
Colin Cross0ea8ba82019-06-06 14:33:29 -07001250func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001251 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001252}
1253
Colin Cross0ea8ba82019-06-06 14:33:29 -07001254func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001255 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001256}
1257
Colin Cross0ea8ba82019-06-06 14:33:29 -07001258func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001259 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001260}
1261
Colin Cross0ea8ba82019-06-06 14:33:29 -07001262func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001263 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001264}
1265
Colin Cross0ea8ba82019-06-06 14:33:29 -07001266func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001267 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001268}
1269
Colin Cross0ea8ba82019-06-06 14:33:29 -07001270func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001271 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001272 return true
1273 }
Colin Cross25de6c32019-06-06 14:29:25 -07001274 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001275}
1276
Colin Cross0ea8ba82019-06-06 14:33:29 -07001277func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001278 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001279}
1280
Colin Cross0ea8ba82019-06-06 14:33:29 -07001281func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001282 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001283}
1284
Colin Cross0ea8ba82019-06-06 14:33:29 -07001285func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001286 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001287}
1288
Colin Cross0ea8ba82019-06-06 14:33:29 -07001289func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001290 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001291}
1292
Colin Cross0ea8ba82019-06-06 14:33:29 -07001293func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001294 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001295}
1296
Colin Cross0ea8ba82019-06-06 14:33:29 -07001297func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001298 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001299}
1300
Colin Cross0ea8ba82019-06-06 14:33:29 -07001301func (b *baseModuleContext) ProductServicesSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001302 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001303}
1304
Jiyong Park5baac542018-08-28 09:55:37 +09001305// Makes this module a platform module, i.e. not specific to soc, device,
1306// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001307func (m *ModuleBase) MakeAsPlatform() {
1308 m.commonProperties.Vendor = boolPtr(false)
1309 m.commonProperties.Proprietary = boolPtr(false)
1310 m.commonProperties.Soc_specific = boolPtr(false)
1311 m.commonProperties.Product_specific = boolPtr(false)
1312 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001313}
1314
Colin Cross4157e882019-06-06 16:57:04 -07001315func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1316 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001317}
1318
Colin Cross25de6c32019-06-06 14:29:25 -07001319func (m *moduleContext) InstallInData() bool {
1320 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001321}
1322
Colin Cross25de6c32019-06-06 14:29:25 -07001323func (m *moduleContext) InstallInSanitizerDir() bool {
1324 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001325}
1326
Colin Cross25de6c32019-06-06 14:29:25 -07001327func (m *moduleContext) InstallInRecovery() bool {
1328 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001329}
1330
Colin Cross25de6c32019-06-06 14:29:25 -07001331func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1332 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001333 return true
1334 }
1335
Colin Cross3607f212018-05-07 15:28:05 -07001336 // We'll need a solution for choosing which of modules with the same name in different
1337 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1338 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001339 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001340 return true
1341 }
1342
Colin Cross25de6c32019-06-06 14:29:25 -07001343 if m.Device() {
1344 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001345 return true
1346 }
1347
Colin Cross25de6c32019-06-06 14:29:25 -07001348 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001349 return true
1350 }
1351 }
1352
1353 return false
1354}
1355
Colin Cross25de6c32019-06-06 14:29:25 -07001356func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001357 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001358 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001359}
1360
Colin Cross25de6c32019-06-06 14:29:25 -07001361func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001362 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001363 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001364}
1365
Colin Cross25de6c32019-06-06 14:29:25 -07001366func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001367 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001368
Colin Cross25de6c32019-06-06 14:29:25 -07001369 fullInstallPath := installPath.Join(m, name)
1370 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001371
Colin Cross25de6c32019-06-06 14:29:25 -07001372 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001373
Colin Cross25de6c32019-06-06 14:29:25 -07001374 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001375
Colin Cross89562dc2016-10-03 17:47:19 -07001376 var implicitDeps, orderOnlyDeps Paths
1377
Colin Cross25de6c32019-06-06 14:29:25 -07001378 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001379 // Installed host modules might be used during the build, depend directly on their
1380 // dependencies so their timestamp is updated whenever their dependency is updated
1381 implicitDeps = deps
1382 } else {
1383 orderOnlyDeps = deps
1384 }
1385
Colin Cross25de6c32019-06-06 14:29:25 -07001386 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001387 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001388 Description: "install " + fullInstallPath.Base(),
1389 Output: fullInstallPath,
1390 Input: srcPath,
1391 Implicits: implicitDeps,
1392 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001393 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001394 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001395
Colin Cross25de6c32019-06-06 14:29:25 -07001396 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001397 }
Colin Cross25de6c32019-06-06 14:29:25 -07001398 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001399 return fullInstallPath
1400}
1401
Colin Cross25de6c32019-06-06 14:29:25 -07001402func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1403 fullInstallPath := installPath.Join(m, name)
1404 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001405
Colin Cross25de6c32019-06-06 14:29:25 -07001406 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001407
Alex Lightfb4353d2019-01-17 13:57:45 -08001408 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1409 if err != nil {
1410 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1411 }
Colin Cross25de6c32019-06-06 14:29:25 -07001412 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001413 Rule: Symlink,
1414 Description: "install symlink " + fullInstallPath.Base(),
1415 Output: fullInstallPath,
1416 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001417 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001418 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001419 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001420 },
1421 })
Colin Cross3854a602016-01-11 12:49:11 -08001422
Colin Cross25de6c32019-06-06 14:29:25 -07001423 m.installFiles = append(m.installFiles, fullInstallPath)
1424 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001425 }
Colin Cross3854a602016-01-11 12:49:11 -08001426 return fullInstallPath
1427}
1428
Jiyong Parkf1194352019-02-25 11:05:47 +09001429// installPath/name -> absPath where absPath might be a path that is available only at runtime
1430// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001431func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1432 fullInstallPath := installPath.Join(m, name)
1433 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001434
Colin Cross25de6c32019-06-06 14:29:25 -07001435 if !m.skipInstall(fullInstallPath) {
1436 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001437 Rule: Symlink,
1438 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1439 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001440 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001441 Args: map[string]string{
1442 "fromPath": absPath,
1443 },
1444 })
1445
Colin Cross25de6c32019-06-06 14:29:25 -07001446 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001447 }
1448 return fullInstallPath
1449}
1450
Colin Cross25de6c32019-06-06 14:29:25 -07001451func (m *moduleContext) CheckbuildFile(srcPath Path) {
1452 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001453}
1454
Colin Cross3f40fa42015-01-30 17:27:36 -08001455type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001456 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001457}
1458
1459func isFileInstaller(m blueprint.Module) bool {
1460 _, ok := m.(fileInstaller)
1461 return ok
1462}
1463
1464func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001465 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001466 return ok
1467}
Colin Crossfce53272015-04-08 11:21:40 -07001468
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001469func findStringInSlice(str string, slice []string) int {
1470 for i, s := range slice {
1471 if s == str {
1472 return i
Colin Crossfce53272015-04-08 11:21:40 -07001473 }
1474 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001475 return -1
1476}
1477
Colin Cross41955e82019-05-29 14:40:35 -07001478// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1479// was not a module reference.
1480func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001481 if len(s) > 1 && s[0] == ':' {
1482 return s[1:]
1483 }
1484 return ""
1485}
1486
Colin Cross41955e82019-05-29 14:40:35 -07001487// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1488// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1489func SrcIsModuleWithTag(s string) (module, tag string) {
1490 if len(s) > 1 && s[0] == ':' {
1491 module = s[1:]
1492 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1493 if module[len(module)-1] == '}' {
1494 tag = module[tagStart+1 : len(module)-1]
1495 module = module[:tagStart]
1496 return module, tag
1497 }
1498 }
1499 return module, ""
1500 }
1501 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001502}
1503
Colin Cross41955e82019-05-29 14:40:35 -07001504type sourceOrOutputDependencyTag struct {
1505 blueprint.BaseDependencyTag
1506 tag string
1507}
1508
1509func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1510 return sourceOrOutputDependencyTag{tag: tag}
1511}
1512
1513var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001514
Colin Cross366938f2017-12-11 16:29:02 -08001515// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1516// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001517//
1518// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001519func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001520 set := make(map[string]bool)
1521
Colin Cross068e0fe2016-12-13 15:23:47 -08001522 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001523 if m, t := SrcIsModuleWithTag(s); m != "" {
1524 if _, found := set[s]; found {
1525 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001526 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001527 set[s] = true
1528 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001529 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001530 }
1531 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001532}
1533
Colin Cross366938f2017-12-11 16:29:02 -08001534// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1535// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001536//
1537// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001538func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1539 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001540 if m, t := SrcIsModuleWithTag(*s); m != "" {
1541 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001542 }
1543 }
1544}
1545
Colin Cross41955e82019-05-29 14:40:35 -07001546// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1547// 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 -08001548type SourceFileProducer interface {
1549 Srcs() Paths
1550}
1551
Colin Cross41955e82019-05-29 14:40:35 -07001552// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1553// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1554// listed in the property.
1555type OutputFileProducer interface {
1556 OutputFiles(tag string) (Paths, error)
1557}
1558
Colin Crossfe17f6f2019-03-28 19:30:56 -07001559type HostToolProvider interface {
1560 HostToolPath() OptionalPath
1561}
1562
Colin Cross27b922f2019-03-04 22:35:41 -08001563// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1564// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001565//
1566// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001567func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1568 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001569}
1570
Colin Cross2fafa3e2019-03-05 12:39:51 -08001571// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1572// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001573//
1574// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001575func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1576 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001577}
1578
1579// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1580// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1581// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001582func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001583 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001584 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001585 }
1586 return OptionalPath{}
1587}
1588
Colin Cross25de6c32019-06-06 14:29:25 -07001589func (m *moduleContext) RequiredModuleNames() []string {
1590 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001591}
1592
Colin Cross25de6c32019-06-06 14:29:25 -07001593func (m *moduleContext) HostRequiredModuleNames() []string {
1594 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001595}
1596
Colin Cross25de6c32019-06-06 14:29:25 -07001597func (m *moduleContext) TargetRequiredModuleNames() []string {
1598 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001599}
1600
Colin Cross380c69a2019-06-10 17:49:58 +00001601func (m *moduleContext) Glob(globPattern string, excludes []string) Paths {
1602 ret, err := m.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001603 if err != nil {
Colin Cross380c69a2019-06-10 17:49:58 +00001604 m.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001605 }
Colin Cross380c69a2019-06-10 17:49:58 +00001606 return pathsForModuleSrcFromFullPath(m, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001607}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001608
Colin Cross380c69a2019-06-10 17:49:58 +00001609func (m *moduleContext) GlobFiles(globPattern string, excludes []string) Paths {
1610 ret, err := m.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001611 if err != nil {
Colin Cross380c69a2019-06-10 17:49:58 +00001612 m.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001613 }
Colin Cross380c69a2019-06-10 17:49:58 +00001614 return pathsForModuleSrcFromFullPath(m, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001615}
1616
Colin Cross463a90e2015-06-17 14:20:06 -07001617func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001618 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001619}
1620
Colin Cross0875c522017-11-28 17:34:01 -08001621func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001622 return &buildTargetSingleton{}
1623}
1624
Colin Cross87d8b562017-04-25 10:01:55 -07001625func parentDir(dir string) string {
1626 dir, _ = filepath.Split(dir)
1627 return filepath.Clean(dir)
1628}
1629
Colin Cross1f8c52b2015-06-16 16:38:17 -07001630type buildTargetSingleton struct{}
1631
Colin Cross0875c522017-11-28 17:34:01 -08001632func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1633 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001634
Colin Cross0875c522017-11-28 17:34:01 -08001635 mmTarget := func(dir string) WritablePath {
1636 return PathForPhony(ctx,
1637 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001638 }
1639
Colin Cross0875c522017-11-28 17:34:01 -08001640 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001641
Colin Cross0875c522017-11-28 17:34:01 -08001642 ctx.VisitAllModules(func(module Module) {
1643 blueprintDir := module.base().blueprintDir
1644 installTarget := module.base().installTarget
1645 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001646
Colin Cross0875c522017-11-28 17:34:01 -08001647 if checkbuildTarget != nil {
1648 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1649 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1650 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001651
Colin Cross0875c522017-11-28 17:34:01 -08001652 if installTarget != nil {
1653 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001654 }
1655 })
1656
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001657 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001658 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001659 suffix = "-soong"
1660 }
1661
Colin Cross1f8c52b2015-06-16 16:38:17 -07001662 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001663 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001664 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001665 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001666 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001667 })
1668
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001669 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001670 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001671 return
1672 }
1673
Colin Cross87d8b562017-04-25 10:01:55 -07001674 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001675 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001676 for _, dir := range dirs {
1677 dir := parentDir(dir)
1678 for dir != "." && dir != "/" {
1679 if _, exists := modulesInDir[dir]; exists {
1680 break
1681 }
1682 modulesInDir[dir] = nil
1683 dir = parentDir(dir)
1684 }
1685 }
1686
1687 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001688 for _, dir := range dirs {
1689 p := parentDir(dir)
1690 if p != "." && p != "/" {
1691 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1692 }
1693 }
1694
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001695 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1696 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1697 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001698 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001699 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001700 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001701 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001702 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001703 // HACK: checkbuild should be an optional build, but force it
1704 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001705 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001706 })
1707 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001708
1709 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1710 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001711 ctx.VisitAllModules(func(module Module) {
1712 if module.Enabled() {
1713 os := module.Target().Os
1714 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001715 }
1716 })
1717
Colin Cross0875c522017-11-28 17:34:01 -08001718 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001719 for os, deps := range osDeps {
1720 var className string
1721
1722 switch os.Class {
1723 case Host:
1724 className = "host"
1725 case HostCross:
1726 className = "host-cross"
1727 case Device:
1728 className = "target"
1729 default:
1730 continue
1731 }
1732
Colin Cross0875c522017-11-28 17:34:01 -08001733 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001734 osClass[className] = append(osClass[className], name)
1735
Colin Cross0875c522017-11-28 17:34:01 -08001736 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001737 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001738 Output: name,
1739 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001740 })
1741 }
1742
1743 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001744 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001745 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001746 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001747 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001748 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001749 })
1750 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001751}
Colin Crossd779da42015-12-17 18:00:23 -08001752
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001753// Collect information for opening IDE project files in java/jdeps.go.
1754type IDEInfo interface {
1755 IDEInfo(ideInfo *IdeInfo)
1756 BaseModuleName() string
1757}
1758
1759// Extract the base module name from the Import name.
1760// Often the Import name has a prefix "prebuilt_".
1761// Remove the prefix explicitly if needed
1762// until we find a better solution to get the Import name.
1763type IDECustomizedModuleName interface {
1764 IDECustomizedModuleName() string
1765}
1766
1767type IdeInfo struct {
1768 Deps []string `json:"dependencies,omitempty"`
1769 Srcs []string `json:"srcs,omitempty"`
1770 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1771 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1772 Jars []string `json:"jars,omitempty"`
1773 Classes []string `json:"class,omitempty"`
1774 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001775 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001776}