blob: c3d5f6ad25a67a1a4a8c3b91ec81c967a15c0082 [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 Cross0875c522017-11-28 17:34:01 -080021 "sort"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080023 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
25 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070026 "github.com/google/blueprint/pathtools"
Colin Crossfe4bc362018-09-12 10:02:13 -070027 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080028)
29
30var (
31 DeviceSharedLibrary = "shared_library"
32 DeviceStaticLibrary = "static_library"
33 DeviceExecutable = "executable"
34 HostSharedLibrary = "host_shared_library"
35 HostStaticLibrary = "host_static_library"
36 HostExecutable = "host_executable"
37)
38
Colin Crossae887032017-10-23 17:16:14 -070039type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070040 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080041 Deps blueprint.Deps
42 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070043 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070044 Output WritablePath
45 Outputs WritablePaths
46 ImplicitOutput WritablePath
47 ImplicitOutputs WritablePaths
48 Input Path
49 Inputs Paths
50 Implicit Path
51 Implicits Paths
52 OrderOnly Paths
53 Default bool
54 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070055}
56
Colin Crossae887032017-10-23 17:16:14 -070057type ModuleBuildParams BuildParams
58
Colin Cross25de6c32019-06-06 14:29:25 -070059type baseContext interface {
Colin Crossa1ad8d12016-06-01 17:09:44 -070060 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070061 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -070062 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -070063 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070064 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070065 Host() bool
66 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070067 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -080068 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -070069 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070070 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070071 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +090072 Platform() bool
73 DeviceSpecific() bool
74 SocSpecific() bool
75 ProductSpecific() bool
Dario Frenifd05a742018-05-29 13:28:54 +010076 ProductServicesSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -070077 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -070078 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -070079}
80
Colin Cross635c3b02016-05-18 15:37:25 -070081type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -080082 BaseModuleContext
Colin Cross25de6c32019-06-06 14:29:25 -070083 baseContext
Colin Crossf6566ed2015-03-24 11:13:38 -070084}
85
Colin Crossaabf6792017-11-29 00:27:14 -080086// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
87// a Config instead of an interface{}.
88type BaseModuleContext interface {
89 ModuleName() string
90 ModuleDir() string
Colin Cross3d7c9822019-03-01 13:46:24 -080091 ModuleType() string
Colin Crossaabf6792017-11-29 00:27:14 -080092 Config() Config
93
94 ContainsProperty(name string) bool
95 Errorf(pos scanner.Position, fmt string, args ...interface{})
96 ModuleErrorf(fmt string, args ...interface{})
97 PropertyErrorf(property, fmt string, args ...interface{})
98 Failed() bool
99
100 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
101 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
102 // builder whenever a file matching the pattern as added or removed, without rerunning if a
103 // file that does not match the pattern is added to a searched directory.
104 GlobWithDeps(pattern string, excludes []string) ([]string, error)
105
106 Fs() pathtools.FileSystem
107 AddNinjaFileDeps(deps ...string)
108}
109
Colin Cross635c3b02016-05-18 15:37:25 -0700110type ModuleContext interface {
Colin Cross25de6c32019-06-06 14:29:25 -0700111 baseContext
Colin Crossaabf6792017-11-29 00:27:14 -0800112 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800113
Colin Crossae887032017-10-23 17:16:14 -0700114 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800115 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700116
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800118 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800119 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Colin Cross7f19f372016-11-01 11:10:25 -0700120 Glob(globPattern string, excludes []string) Paths
Nan Zhang581fd212018-01-10 16:06:12 -0800121 GlobFiles(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700122
Colin Cross5c517922017-08-31 12:29:17 -0700123 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
124 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800125 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900126 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700127 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800128
129 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700130
Colin Cross8d8f8e22016-08-03 11:57:50 -0700131 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700132 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900133 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800134
135 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700136 HostRequiredModuleNames() []string
137 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700138
139 // android.ModuleContext methods
140 // These are duplicated instead of embedded so that can eventually be wrapped to take an
141 // android.Module instead of a blueprint.Module
142 OtherModuleName(m blueprint.Module) string
143 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
144 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
145
Colin Cross0ef08162019-05-01 15:50:51 -0700146 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross3f68a132017-10-23 17:10:29 -0700147 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
148 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
149
150 ModuleSubDir() string
151
Colin Cross35143d02017-11-16 00:11:20 -0800152 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700153 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800154 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700155 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700156 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700157 VisitDepsDepthFirst(visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700158 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700159 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
160 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800161 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700162
Colin Cross0875c522017-11-28 17:34:01 -0800163 Variable(pctx PackageContext, name, value string)
164 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700165 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
166 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800167 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700168
Colin Cross0875c522017-11-28 17:34:01 -0800169 PrimaryModule() Module
170 FinalModule() Module
171 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700172
173 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800174 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800175}
176
Colin Cross635c3b02016-05-18 15:37:25 -0700177type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800178 blueprint.Module
179
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700180 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
181 // but GenerateAndroidBuildActions also has access to Android-specific information.
182 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700183 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700184
Colin Cross1e676be2016-10-12 14:38:15 -0700185 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800186
Colin Cross635c3b02016-05-18 15:37:25 -0700187 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800188 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700189 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800190 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700191 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900192 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800193 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900194 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900195 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700196
197 AddProperties(props ...interface{})
198 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700199
Colin Crossae887032017-10-23 17:16:14 -0700200 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800201 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800202 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800203}
204
Colin Crossfc754582016-05-17 16:34:16 -0700205type nameProperties struct {
206 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800207 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700208}
209
210type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800211 // emit build rules for this module
212 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800213
Paul Duffin2e61fa62019-03-28 14:10:57 +0000214 // Controls the visibility of this module to other modules. Allowable values are one or more of
215 // these formats:
216 //
217 // ["//visibility:public"]: Anyone can use this module.
218 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
219 // this module.
220 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
221 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
222 // this module. Note that sub-packages do not have access to the rule; for example,
223 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
224 // is a special module and must be used verbatim. It represents all of the modules in the
225 // package.
226 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
227 // or other or in one of their sub-packages have access to this module. For example,
228 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
229 // to depend on this rule (but not //independent:evil)
230 // ["//project"]: This is shorthand for ["//project:__pkg__"]
231 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
232 // //project is the module's package. e.g. using [":__subpackages__"] in
233 // packages/apps/Settings/Android.bp is equivalent to
234 // //packages/apps/Settings:__subpackages__.
235 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
236 // for now. It is an error if it is used in a module.
237 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
238 // more details.
239 Visibility []string
240
Colin Cross7d5136f2015-05-11 13:39:40 -0700241 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800242 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
243 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
244 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700245 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700246
247 Target struct {
248 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700249 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700250 }
251 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700252 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700253 }
254 }
255
Colin Crossee0bc3b2018-10-02 22:01:37 -0700256 UseTargetVariants bool `blueprint:"mutated"`
257 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800258
Dan Willemsen782a2d12015-12-21 14:55:28 -0800259 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700260 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800261
Colin Cross55708f32017-03-20 13:23:34 -0700262 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700263 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700264
Jiyong Park2db76922017-11-08 16:03:48 +0900265 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
266 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
267 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700268 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700269
Jiyong Park2db76922017-11-08 16:03:48 +0900270 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
271 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
272 Soc_specific *bool
273
274 // whether this module is specific to a device, not only for SoC, but also for off-chip
275 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
276 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
277 // This implies `soc_specific:true`.
278 Device_specific *bool
279
280 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900281 // network operator, etc). When set to true, it is installed into /product (or
282 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900283 Product_specific *bool
284
Dario Frenifd05a742018-05-29 13:28:54 +0100285 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100286 // to true, it is installed into /product_services (or /system/product_services if
287 // product_services partition does not exist).
288 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100289
Jiyong Parkf9332f12018-02-01 00:54:12 +0900290 // Whether this module is installed to recovery partition
291 Recovery *bool
292
dimitry1f33e402019-03-26 12:39:31 +0100293 // Whether this module is built for non-native architecures (also known as native bridge binary)
294 Native_bridge_supported *bool `android:"arch_variant"`
295
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700296 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800297 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700298
Steven Moreland57a23d22018-04-04 15:42:19 -0700299 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800300 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700301
Chris Wolfe998306e2016-08-15 14:47:23 -0400302 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700303 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400304
Sasha Smundakb6d23052019-04-01 18:37:36 -0700305 // names of other modules to install on host if this module is installed
306 Host_required []string `android:"arch_variant"`
307
308 // names of other modules to install on target if this module is installed
309 Target_required []string `android:"arch_variant"`
310
Colin Cross5aac3622017-08-31 15:07:09 -0700311 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800312 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700313
Dan Willemsen569edc52018-11-19 09:33:29 -0800314 Dist struct {
315 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
316 // command line and any of these targets are also on the command line, or otherwise
317 // built
318 Targets []string `android:"arch_variant"`
319
320 // The name of the output artifact. This defaults to the basename of the output of
321 // the module.
322 Dest *string `android:"arch_variant"`
323
324 // The directory within the dist directory to store the artifact. Defaults to the
325 // top level directory ("").
326 Dir *string `android:"arch_variant"`
327
328 // A suffix to add to the artifact file name (before any extension).
329 Suffix *string `android:"arch_variant"`
330 } `android:"arch_variant"`
331
Colin Crossa1ad8d12016-06-01 17:09:44 -0700332 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700333 CompileTarget Target `blueprint:"mutated"`
334 CompileMultiTargets []Target `blueprint:"mutated"`
335 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800336
337 // Set by InitAndroidModule
338 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700339 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700340
341 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800342
343 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800344}
345
346type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800347 // If set to true, build a variant of the module for the host. Defaults to false.
348 Host_supported *bool
349
350 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700351 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800352}
353
Colin Crossc472d572015-03-17 15:06:21 -0700354type Multilib string
355
356const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800357 MultilibBoth Multilib = "both"
358 MultilibFirst Multilib = "first"
359 MultilibCommon Multilib = "common"
360 MultilibCommonFirst Multilib = "common_first"
361 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700362)
363
Colin Crossa1ad8d12016-06-01 17:09:44 -0700364type HostOrDeviceSupported int
365
366const (
367 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700368
369 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700370 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700371
372 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700373 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700374
375 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700376 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700377
378 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700379 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700380
381 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700382 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700383
384 // Nothing is supported. This is not exposed to the user, but used to mark a
385 // host only module as unsupported when the module type is not supported on
386 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700387 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700388)
389
Jiyong Park2db76922017-11-08 16:03:48 +0900390type moduleKind int
391
392const (
393 platformModule moduleKind = iota
394 deviceSpecificModule
395 socSpecificModule
396 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100397 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900398)
399
400func (k moduleKind) String() string {
401 switch k {
402 case platformModule:
403 return "platform"
404 case deviceSpecificModule:
405 return "device-specific"
406 case socSpecificModule:
407 return "soc-specific"
408 case productSpecificModule:
409 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100410 case productServicesSpecificModule:
411 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900412 default:
413 panic(fmt.Errorf("unknown module kind %d", k))
414 }
415}
416
Colin Cross36242852017-06-23 15:06:31 -0700417func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800418 base := m.base()
419 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700420
Colin Cross36242852017-06-23 15:06:31 -0700421 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700422 &base.nameProperties,
423 &base.commonProperties,
424 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700425 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700426 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700427}
428
Colin Cross36242852017-06-23 15:06:31 -0700429func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
430 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700431
432 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800433 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700434 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700435 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700436 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800437
Dan Willemsen218f6562015-07-08 18:13:11 -0700438 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700439 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700440 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800441 }
442
Colin Cross36242852017-06-23 15:06:31 -0700443 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800444}
445
Colin Crossee0bc3b2018-10-02 22:01:37 -0700446func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
447 InitAndroidArchModule(m, hod, defaultMultilib)
448 m.base().commonProperties.UseTargetVariants = false
449}
450
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800451// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800452// modules. It should be included as an anonymous field in every module
453// struct definition. InitAndroidModule should then be called from the module's
454// factory function, and the return values from InitAndroidModule should be
455// returned from the factory function.
456//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800457// The ModuleBase type is responsible for implementing the GenerateBuildActions
458// method to support the blueprint.Module interface. This method will then call
459// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700460// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
461// rather than the usual blueprint.ModuleContext.
462// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800463// system including details about the particular build variant that is to be
464// generated.
465//
466// For example:
467//
468// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800469// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800470// )
471//
472// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800473// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800474// properties struct {
475// MyProperty string
476// }
477// }
478//
Colin Cross36242852017-06-23 15:06:31 -0700479// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800480// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700481// m.AddProperties(&m.properties)
482// android.InitAndroidModule(m)
483// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800484// }
485//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800486// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800487// // Get the CPU architecture for the current build variant.
488// variantArch := ctx.Arch()
489//
490// // ...
491// }
Colin Cross635c3b02016-05-18 15:37:25 -0700492type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800493 // Putting the curiously recurring thing pointing to the thing that contains
494 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700495 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700496 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800497
Colin Crossfc754582016-05-17 16:34:16 -0700498 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800499 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700500 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800501 hostAndDeviceProperties hostAndDeviceProperties
502 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700503 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700504 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800505
506 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700507 installFiles Paths
508 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900509 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700510
511 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
512 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800513 installTarget WritablePath
514 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700515 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700516
Colin Cross178a5092016-09-13 13:42:32 -0700517 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700518
519 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700520
521 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700522 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800523 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800524 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700525
526 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700527}
528
Colin Cross4157e882019-06-06 16:57:04 -0700529func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800530
Colin Cross4157e882019-06-06 16:57:04 -0700531func (m *ModuleBase) AddProperties(props ...interface{}) {
532 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700533}
534
Colin Cross4157e882019-06-06 16:57:04 -0700535func (m *ModuleBase) GetProperties() []interface{} {
536 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800537}
538
Colin Cross4157e882019-06-06 16:57:04 -0700539func (m *ModuleBase) BuildParamsForTests() []BuildParams {
540 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700541}
542
Colin Cross4157e882019-06-06 16:57:04 -0700543func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
544 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800545}
546
Colin Cross4157e882019-06-06 16:57:04 -0700547func (m *ModuleBase) VariablesForTests() map[string]string {
548 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800549}
550
Colin Cross4157e882019-06-06 16:57:04 -0700551func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
552 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700553}
554
Colin Crossce75d2c2016-10-06 16:12:58 -0700555// Name returns the name of the module. It may be overridden by individual module types, for
556// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700557func (m *ModuleBase) Name() string {
558 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700559}
560
Colin Crossce75d2c2016-10-06 16:12:58 -0700561// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700562func (m *ModuleBase) BaseModuleName() string {
563 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700564}
565
Colin Cross4157e882019-06-06 16:57:04 -0700566func (m *ModuleBase) base() *ModuleBase {
567 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800568}
569
Colin Cross4157e882019-06-06 16:57:04 -0700570func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
571 m.commonProperties.CompileTarget = target
572 m.commonProperties.CompileMultiTargets = multiTargets
573 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700574}
575
Colin Cross4157e882019-06-06 16:57:04 -0700576func (m *ModuleBase) Target() Target {
577 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800578}
579
Colin Cross4157e882019-06-06 16:57:04 -0700580func (m *ModuleBase) TargetPrimary() bool {
581 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700582}
583
Colin Cross4157e882019-06-06 16:57:04 -0700584func (m *ModuleBase) MultiTargets() []Target {
585 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700586}
587
Colin Cross4157e882019-06-06 16:57:04 -0700588func (m *ModuleBase) Os() OsType {
589 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800590}
591
Colin Cross4157e882019-06-06 16:57:04 -0700592func (m *ModuleBase) Host() bool {
593 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800594}
595
Colin Cross4157e882019-06-06 16:57:04 -0700596func (m *ModuleBase) Arch() Arch {
597 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800598}
599
Colin Cross4157e882019-06-06 16:57:04 -0700600func (m *ModuleBase) ArchSpecific() bool {
601 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700602}
603
Colin Cross4157e882019-06-06 16:57:04 -0700604func (m *ModuleBase) OsClassSupported() []OsClass {
605 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700606 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700607 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700608 case HostSupportedNoCross:
609 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700610 case DeviceSupported:
611 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700612 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700613 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700614 if Bool(m.hostAndDeviceProperties.Host_supported) ||
615 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
616 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700617 supported = append(supported, Host, HostCross)
618 }
Colin Cross4157e882019-06-06 16:57:04 -0700619 if m.hostAndDeviceProperties.Device_supported == nil ||
620 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700621 supported = append(supported, Device)
622 }
623 return supported
624 default:
625 return nil
626 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800627}
628
Colin Cross4157e882019-06-06 16:57:04 -0700629func (m *ModuleBase) DeviceSupported() bool {
630 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
631 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
632 (m.hostAndDeviceProperties.Device_supported == nil ||
633 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800634}
635
Colin Cross4157e882019-06-06 16:57:04 -0700636func (m *ModuleBase) Platform() bool {
637 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900638}
639
Colin Cross4157e882019-06-06 16:57:04 -0700640func (m *ModuleBase) DeviceSpecific() bool {
641 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900642}
643
Colin Cross4157e882019-06-06 16:57:04 -0700644func (m *ModuleBase) SocSpecific() bool {
645 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900646}
647
Colin Cross4157e882019-06-06 16:57:04 -0700648func (m *ModuleBase) ProductSpecific() bool {
649 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900650}
651
Colin Cross4157e882019-06-06 16:57:04 -0700652func (m *ModuleBase) ProductServicesSpecific() bool {
653 return Bool(m.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100654}
655
Colin Cross4157e882019-06-06 16:57:04 -0700656func (m *ModuleBase) Enabled() bool {
657 if m.commonProperties.Enabled == nil {
658 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800659 }
Colin Cross4157e882019-06-06 16:57:04 -0700660 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800661}
662
Colin Cross4157e882019-06-06 16:57:04 -0700663func (m *ModuleBase) SkipInstall() {
664 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700665}
666
Colin Cross4157e882019-06-06 16:57:04 -0700667func (m *ModuleBase) ExportedToMake() bool {
668 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900669}
670
Colin Cross4157e882019-06-06 16:57:04 -0700671func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700672 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800673
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700674 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700675 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800676 ctx.VisitDepsDepthFirstIf(isFileInstaller,
677 func(m blueprint.Module) {
678 fileInstaller := m.(fileInstaller)
679 files := fileInstaller.filesToInstall()
680 result = append(result, files...)
681 })
682
683 return result
684}
685
Colin Cross4157e882019-06-06 16:57:04 -0700686func (m *ModuleBase) filesToInstall() Paths {
687 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800688}
689
Colin Cross4157e882019-06-06 16:57:04 -0700690func (m *ModuleBase) NoAddressSanitizer() bool {
691 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800692}
693
Colin Cross4157e882019-06-06 16:57:04 -0700694func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800695 return false
696}
697
Colin Cross4157e882019-06-06 16:57:04 -0700698func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700699 return false
700}
701
Colin Cross4157e882019-06-06 16:57:04 -0700702func (m *ModuleBase) InstallInRecovery() bool {
703 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900704}
705
Colin Cross4157e882019-06-06 16:57:04 -0700706func (m *ModuleBase) Owner() string {
707 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900708}
709
Colin Cross4157e882019-06-06 16:57:04 -0700710func (m *ModuleBase) NoticeFile() OptionalPath {
711 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900712}
713
Colin Cross4157e882019-06-06 16:57:04 -0700714func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700715 allInstalledFiles := Paths{}
716 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800717 ctx.VisitAllModuleVariants(func(module Module) {
718 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700719 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
720 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800721 })
722
Colin Cross0875c522017-11-28 17:34:01 -0800723 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700724
Jeff Gaston088e29e2017-11-29 16:47:17 -0800725 namespacePrefix := ctx.Namespace().(*Namespace).id
726 if namespacePrefix != "" {
727 namespacePrefix = namespacePrefix + "-"
728 }
729
Colin Cross3f40fa42015-01-30 17:27:36 -0800730 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800731 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800732 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700733 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800734 Output: name,
735 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800736 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700737 })
738 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700739 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700740 }
741
742 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800743 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800744 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700745 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800746 Output: name,
747 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700748 })
749 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700750 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700751 }
752
753 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800754 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800755 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800756 suffix = "-soong"
757 }
758
Jeff Gaston088e29e2017-11-29 16:47:17 -0800759 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800760 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700761 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800762 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700763 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800764 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700765
Colin Cross4157e882019-06-06 16:57:04 -0700766 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800767 }
768}
769
Colin Cross4157e882019-06-06 16:57:04 -0700770func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
771 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
772 var deviceSpecific = Bool(m.commonProperties.Device_specific)
773 var productSpecific = Bool(m.commonProperties.Product_specific)
774 var productServicesSpecific = Bool(m.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900775
Dario Frenifd05a742018-05-29 13:28:54 +0100776 msg := "conflicting value set here"
777 if socSpecific && deviceSpecific {
778 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700779 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900780 ctx.PropertyErrorf("vendor", msg)
781 }
Colin Cross4157e882019-06-06 16:57:04 -0700782 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900783 ctx.PropertyErrorf("proprietary", msg)
784 }
Colin Cross4157e882019-06-06 16:57:04 -0700785 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900786 ctx.PropertyErrorf("soc_specific", msg)
787 }
788 }
789
Dario Frenifd05a742018-05-29 13:28:54 +0100790 if productSpecific && productServicesSpecific {
791 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
792 ctx.PropertyErrorf("product_services_specific", msg)
793 }
794
795 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
796 if productSpecific {
797 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
798 } else {
799 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
800 }
801 if deviceSpecific {
802 ctx.PropertyErrorf("device_specific", msg)
803 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700804 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100805 ctx.PropertyErrorf("vendor", msg)
806 }
Colin Cross4157e882019-06-06 16:57:04 -0700807 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100808 ctx.PropertyErrorf("proprietary", msg)
809 }
Colin Cross4157e882019-06-06 16:57:04 -0700810 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100811 ctx.PropertyErrorf("soc_specific", msg)
812 }
813 }
814 }
815
Jiyong Park2db76922017-11-08 16:03:48 +0900816 if productSpecific {
817 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100818 } else if productServicesSpecific {
819 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900820 } else if deviceSpecific {
821 return deviceSpecificModule
822 } else if socSpecific {
823 return socSpecificModule
824 } else {
825 return platformModule
826 }
827}
828
Colin Cross4157e882019-06-06 16:57:04 -0700829func (m *ModuleBase) baseContextFactory(ctx blueprint.BaseModuleContext) baseContextImpl {
Colin Cross25de6c32019-06-06 14:29:25 -0700830 return baseContextImpl{
Colin Cross4157e882019-06-06 16:57:04 -0700831 target: m.commonProperties.CompileTarget,
832 targetPrimary: m.commonProperties.CompilePrimary,
833 multiTargets: m.commonProperties.CompileMultiTargets,
834 kind: determineModuleKind(m, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700835 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 Cross4157e882019-06-06 16:57:04 -0700841 module: m.module,
Colin Cross25de6c32019-06-06 14:29:25 -0700842 ModuleContext: blueprintCtx,
Colin Cross4157e882019-06-06 16:57:04 -0700843 baseContextImpl: m.baseContextFactory(blueprintCtx),
844 installDeps: m.computeInstallDeps(blueprintCtx),
845 installFiles: m.installFiles,
Colin Cross25de6c32019-06-06 14:29:25 -0700846 missingDeps: blueprintCtx.GetMissingDependencies(),
847 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800848 }
849
Colin Cross4c83e5c2019-02-25 14:54:28 -0800850 if ctx.config.captureBuild {
851 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
852 }
853
Colin Cross67a5c132017-05-09 13:45:28 -0700854 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
855 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800856 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
857 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700858 }
Colin Cross0875c522017-11-28 17:34:01 -0800859 if !ctx.PrimaryArch() {
860 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700861 }
862
863 ctx.Variable(pctx, "moduleDesc", desc)
864
865 s := ""
866 if len(suffix) > 0 {
867 s = " [" + strings.Join(suffix, " ") + "]"
868 }
869 ctx.Variable(pctx, "moduleDescSuffix", s)
870
Dan Willemsen569edc52018-11-19 09:33:29 -0800871 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -0700872 if m.commonProperties.Dist.Dest != nil {
873 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -0800874 if err != nil {
875 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
876 }
877 }
Colin Cross4157e882019-06-06 16:57:04 -0700878 if m.commonProperties.Dist.Dir != nil {
879 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -0800880 if err != nil {
881 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
882 }
883 }
Colin Cross4157e882019-06-06 16:57:04 -0700884 if m.commonProperties.Dist.Suffix != nil {
885 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -0800886 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
887 }
888 }
889
Colin Cross4157e882019-06-06 16:57:04 -0700890 if m.Enabled() {
891 m.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700892 if ctx.Failed() {
893 return
894 }
895
Colin Cross4157e882019-06-06 16:57:04 -0700896 m.installFiles = append(m.installFiles, ctx.installFiles...)
897 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800898
Colin Cross4157e882019-06-06 16:57:04 -0700899 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
900 if module := SrcIsModule(notice); module != "" {
901 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +0900902 } else {
903 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -0700904 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800905 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800906 }
907
Colin Cross4157e882019-06-06 16:57:04 -0700908 if m == ctx.FinalModule().(Module).base() {
909 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700910 if ctx.Failed() {
911 return
912 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800913 }
Colin Crosscec81712017-07-13 14:43:27 -0700914
Colin Cross4157e882019-06-06 16:57:04 -0700915 m.buildParams = ctx.buildParams
916 m.ruleParams = ctx.ruleParams
917 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800918}
919
Colin Cross25de6c32019-06-06 14:29:25 -0700920type baseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700921 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700922 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700923 targetPrimary bool
924 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900925 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700926 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700927}
928
Colin Cross25de6c32019-06-06 14:29:25 -0700929type moduleContext struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800930 blueprint.ModuleContext
Colin Cross25de6c32019-06-06 14:29:25 -0700931 baseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700932 installDeps Paths
933 installFiles Paths
934 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800935 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700936 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700937
938 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700939 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800940 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800941 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800942}
943
Colin Cross25de6c32019-06-06 14:29:25 -0700944func (m *moduleContext) ninjaError(desc string, outputs []string, err error) {
945 m.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700946 Rule: ErrorRule,
947 Description: desc,
948 Outputs: outputs,
949 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800950 Args: map[string]string{
951 "error": err.Error(),
952 },
953 })
954 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800955}
956
Colin Cross25de6c32019-06-06 14:29:25 -0700957func (m *moduleContext) Config() Config {
958 return m.ModuleContext.Config().(Config)
Colin Crossaabf6792017-11-29 00:27:14 -0800959}
960
Colin Cross25de6c32019-06-06 14:29:25 -0700961func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
962 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800963}
964
Colin Cross0875c522017-11-28 17:34:01 -0800965func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700966 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700967 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800968 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800969 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700970 Outputs: params.Outputs.Strings(),
971 ImplicitOutputs: params.ImplicitOutputs.Strings(),
972 Inputs: params.Inputs.Strings(),
973 Implicits: params.Implicits.Strings(),
974 OrderOnly: params.OrderOnly.Strings(),
975 Args: params.Args,
976 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700977 }
978
Colin Cross33bfb0a2016-11-21 17:23:08 -0800979 if params.Depfile != nil {
980 bparams.Depfile = params.Depfile.String()
981 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700982 if params.Output != nil {
983 bparams.Outputs = append(bparams.Outputs, params.Output.String())
984 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700985 if params.ImplicitOutput != nil {
986 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
987 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700988 if params.Input != nil {
989 bparams.Inputs = append(bparams.Inputs, params.Input.String())
990 }
991 if params.Implicit != nil {
992 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
993 }
994
Colin Cross0b9f31f2019-02-28 11:00:01 -0800995 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
996 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
997 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
998 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
999 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1000 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001001
Colin Cross0875c522017-11-28 17:34:01 -08001002 return bparams
1003}
1004
Colin Cross25de6c32019-06-06 14:29:25 -07001005func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1006 if m.config.captureBuild {
1007 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001008 }
1009
Colin Cross25de6c32019-06-06 14:29:25 -07001010 m.ModuleContext.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001011}
1012
Colin Cross25de6c32019-06-06 14:29:25 -07001013func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001014 argNames ...string) blueprint.Rule {
1015
Colin Cross25de6c32019-06-06 14:29:25 -07001016 rule := m.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001017
Colin Cross25de6c32019-06-06 14:29:25 -07001018 if m.config.captureBuild {
1019 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001020 }
1021
1022 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001023}
1024
Colin Cross25de6c32019-06-06 14:29:25 -07001025func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
1026 if m.config.captureBuild {
1027 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001028 }
1029
1030 bparams := convertBuildParams(params)
1031
1032 if bparams.Description != "" {
1033 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1034 }
1035
Colin Cross25de6c32019-06-06 14:29:25 -07001036 if m.missingDeps != nil {
1037 m.ninjaError(bparams.Description, bparams.Outputs,
Colin Cross67a5c132017-05-09 13:45:28 -07001038 fmt.Errorf("module %s missing dependencies: %s\n",
Colin Cross25de6c32019-06-06 14:29:25 -07001039 m.ModuleName(), strings.Join(m.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001040 return
1041 }
1042
Colin Cross25de6c32019-06-06 14:29:25 -07001043 m.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001044}
1045
Colin Cross25de6c32019-06-06 14:29:25 -07001046func (m *moduleContext) GetMissingDependencies() []string {
1047 return m.missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001048}
1049
Colin Cross25de6c32019-06-06 14:29:25 -07001050func (m *moduleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001051 if deps != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001052 m.missingDeps = append(m.missingDeps, deps...)
1053 m.missingDeps = FirstUniqueStrings(m.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001054 }
1055}
1056
Colin Cross25de6c32019-06-06 14:29:25 -07001057func (m *moduleContext) validateAndroidModule(module blueprint.Module) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001058 aModule, _ := module.(Module)
1059 if aModule == nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001060 m.ModuleErrorf("module %q not an android module", m.OtherModuleName(aModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07001061 return nil
1062 }
1063
1064 if !aModule.Enabled() {
Colin Cross25de6c32019-06-06 14:29:25 -07001065 if m.Config().AllowMissingDependencies() {
1066 m.AddMissingDependencies([]string{m.OtherModuleName(aModule)})
Colin Crossd11fcda2017-10-23 17:59:01 -07001067 } else {
Colin Cross25de6c32019-06-06 14:29:25 -07001068 m.ModuleErrorf("depends on disabled module %q", m.OtherModuleName(aModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07001069 }
1070 return nil
1071 }
1072
1073 return aModule
1074}
1075
Colin Cross25de6c32019-06-06 14:29:25 -07001076func (m *moduleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001077 type dep struct {
1078 mod blueprint.Module
1079 tag blueprint.DependencyTag
1080 }
1081 var deps []dep
Colin Cross25de6c32019-06-06 14:29:25 -07001082 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
1083 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
1084 returnedTag := m.ModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001085 if tag == nil || returnedTag == tag {
1086 deps = append(deps, dep{aModule, returnedTag})
1087 }
1088 }
1089 })
1090 if len(deps) == 1 {
1091 return deps[0].mod, deps[0].tag
1092 } else if len(deps) >= 2 {
1093 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Cross25de6c32019-06-06 14:29:25 -07001094 name, m.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001095 } else {
1096 return nil, nil
1097 }
1098}
1099
Colin Cross25de6c32019-06-06 14:29:25 -07001100func (m *moduleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001101 var deps []Module
Colin Cross25de6c32019-06-06 14:29:25 -07001102 m.VisitDirectDepsBlueprint(func(module blueprint.Module) {
1103 if aModule, _ := module.(Module); aModule != nil {
1104 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001105 deps = append(deps, aModule)
1106 }
1107 }
1108 })
1109 return deps
1110}
1111
Colin Cross25de6c32019-06-06 14:29:25 -07001112func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1113 module, _ := m.getDirectDepInternal(name, tag)
1114 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001115}
1116
Colin Cross25de6c32019-06-06 14:29:25 -07001117func (m *moduleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1118 return m.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001119}
1120
Colin Cross25de6c32019-06-06 14:29:25 -07001121func (m *moduleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1122 m.ModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001123}
1124
Colin Cross25de6c32019-06-06 14:29:25 -07001125func (m *moduleContext) VisitDirectDeps(visit func(Module)) {
1126 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1127 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001128 visit(aModule)
1129 }
1130 })
1131}
1132
Colin Cross25de6c32019-06-06 14:29:25 -07001133func (m *moduleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1134 m.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1135 if aModule := m.validateAndroidModule(module); aModule != nil {
1136 if m.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001137 visit(aModule)
1138 }
1139 }
1140 })
1141}
1142
Colin Cross25de6c32019-06-06 14:29:25 -07001143func (m *moduleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1144 m.ModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001145 // pred
1146 func(module blueprint.Module) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001147 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001148 return pred(aModule)
1149 } else {
1150 return false
1151 }
1152 },
1153 // visit
1154 func(module blueprint.Module) {
1155 visit(module.(Module))
1156 })
1157}
1158
Colin Cross25de6c32019-06-06 14:29:25 -07001159func (m *moduleContext) VisitDepsDepthFirst(visit func(Module)) {
1160 m.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1161 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001162 visit(aModule)
1163 }
1164 })
1165}
1166
Colin Cross25de6c32019-06-06 14:29:25 -07001167func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1168 m.ModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001169 // pred
1170 func(module blueprint.Module) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001171 if aModule := m.validateAndroidModule(module); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001172 return pred(aModule)
1173 } else {
1174 return false
1175 }
1176 },
1177 // visit
1178 func(module blueprint.Module) {
1179 visit(module.(Module))
1180 })
1181}
1182
Colin Cross25de6c32019-06-06 14:29:25 -07001183func (m *moduleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1184 m.ModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001185}
1186
Colin Cross25de6c32019-06-06 14:29:25 -07001187func (m *moduleContext) WalkDeps(visit func(Module, Module) bool) {
1188 m.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1189 childAndroidModule := m.validateAndroidModule(child)
1190 parentAndroidModule := m.validateAndroidModule(parent)
Colin Crossd11fcda2017-10-23 17:59:01 -07001191 if childAndroidModule != nil && parentAndroidModule != nil {
1192 return visit(childAndroidModule, parentAndroidModule)
1193 } else {
1194 return false
1195 }
1196 })
1197}
1198
Colin Cross25de6c32019-06-06 14:29:25 -07001199func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
1200 m.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001201 visit(module.(Module))
1202 })
1203}
1204
Colin Cross25de6c32019-06-06 14:29:25 -07001205func (m *moduleContext) PrimaryModule() Module {
1206 return m.ModuleContext.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001207}
1208
Colin Cross25de6c32019-06-06 14:29:25 -07001209func (m *moduleContext) FinalModule() Module {
1210 return m.ModuleContext.FinalModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001211}
1212
Colin Cross25de6c32019-06-06 14:29:25 -07001213func (b *baseContextImpl) Target() Target {
1214 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001215}
1216
Colin Cross25de6c32019-06-06 14:29:25 -07001217func (b *baseContextImpl) TargetPrimary() bool {
1218 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001219}
1220
Colin Cross25de6c32019-06-06 14:29:25 -07001221func (b *baseContextImpl) MultiTargets() []Target {
1222 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001223}
1224
Colin Cross25de6c32019-06-06 14:29:25 -07001225func (b *baseContextImpl) Arch() Arch {
1226 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001227}
1228
Colin Cross25de6c32019-06-06 14:29:25 -07001229func (b *baseContextImpl) Os() OsType {
1230 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001231}
1232
Colin Cross25de6c32019-06-06 14:29:25 -07001233func (b *baseContextImpl) Host() bool {
1234 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001235}
1236
Colin Cross25de6c32019-06-06 14:29:25 -07001237func (b *baseContextImpl) Device() bool {
1238 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001239}
1240
Colin Cross25de6c32019-06-06 14:29:25 -07001241func (b *baseContextImpl) Darwin() bool {
1242 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001243}
1244
Colin Cross25de6c32019-06-06 14:29:25 -07001245func (b *baseContextImpl) Fuchsia() bool {
1246 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001247}
1248
Colin Cross25de6c32019-06-06 14:29:25 -07001249func (b *baseContextImpl) Windows() bool {
1250 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001251}
1252
Colin Cross25de6c32019-06-06 14:29:25 -07001253func (b *baseContextImpl) Debug() bool {
1254 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001255}
1256
Colin Cross25de6c32019-06-06 14:29:25 -07001257func (b *baseContextImpl) PrimaryArch() bool {
1258 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001259 return true
1260 }
Colin Cross25de6c32019-06-06 14:29:25 -07001261 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001262}
1263
Colin Cross25de6c32019-06-06 14:29:25 -07001264func (b *baseContextImpl) AConfig() Config {
1265 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001266}
1267
Colin Cross25de6c32019-06-06 14:29:25 -07001268func (b *baseContextImpl) DeviceConfig() DeviceConfig {
1269 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001270}
1271
Colin Cross25de6c32019-06-06 14:29:25 -07001272func (b *baseContextImpl) Platform() bool {
1273 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001274}
1275
Colin Cross25de6c32019-06-06 14:29:25 -07001276func (b *baseContextImpl) DeviceSpecific() bool {
1277 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001278}
1279
Colin Cross25de6c32019-06-06 14:29:25 -07001280func (b *baseContextImpl) SocSpecific() bool {
1281 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001282}
1283
Colin Cross25de6c32019-06-06 14:29:25 -07001284func (b *baseContextImpl) ProductSpecific() bool {
1285 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001286}
1287
Colin Cross25de6c32019-06-06 14:29:25 -07001288func (b *baseContextImpl) ProductServicesSpecific() bool {
1289 return b.kind == productServicesSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001290}
1291
Jiyong Park5baac542018-08-28 09:55:37 +09001292// Makes this module a platform module, i.e. not specific to soc, device,
1293// product, or product_services.
Colin Cross4157e882019-06-06 16:57:04 -07001294func (m *ModuleBase) MakeAsPlatform() {
1295 m.commonProperties.Vendor = boolPtr(false)
1296 m.commonProperties.Proprietary = boolPtr(false)
1297 m.commonProperties.Soc_specific = boolPtr(false)
1298 m.commonProperties.Product_specific = boolPtr(false)
1299 m.commonProperties.Product_services_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001300}
1301
Colin Cross4157e882019-06-06 16:57:04 -07001302func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1303 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001304}
1305
Colin Cross25de6c32019-06-06 14:29:25 -07001306func (m *moduleContext) InstallInData() bool {
1307 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001308}
1309
Colin Cross25de6c32019-06-06 14:29:25 -07001310func (m *moduleContext) InstallInSanitizerDir() bool {
1311 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001312}
1313
Colin Cross25de6c32019-06-06 14:29:25 -07001314func (m *moduleContext) InstallInRecovery() bool {
1315 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001316}
1317
Colin Cross25de6c32019-06-06 14:29:25 -07001318func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1319 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001320 return true
1321 }
1322
Colin Cross3607f212018-05-07 15:28:05 -07001323 // We'll need a solution for choosing which of modules with the same name in different
1324 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1325 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001326 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001327 return true
1328 }
1329
Colin Cross25de6c32019-06-06 14:29:25 -07001330 if m.Device() {
1331 if m.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001332 return true
1333 }
1334
Colin Cross25de6c32019-06-06 14:29:25 -07001335 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001336 return true
1337 }
1338 }
1339
1340 return false
1341}
1342
Colin Cross25de6c32019-06-06 14:29:25 -07001343func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001344 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001345 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001346}
1347
Colin Cross25de6c32019-06-06 14:29:25 -07001348func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001349 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001350 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001351}
1352
Colin Cross25de6c32019-06-06 14:29:25 -07001353func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001354 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001355
Colin Cross25de6c32019-06-06 14:29:25 -07001356 fullInstallPath := installPath.Join(m, name)
1357 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001358
Colin Cross25de6c32019-06-06 14:29:25 -07001359 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001360
Colin Cross25de6c32019-06-06 14:29:25 -07001361 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001362
Colin Cross89562dc2016-10-03 17:47:19 -07001363 var implicitDeps, orderOnlyDeps Paths
1364
Colin Cross25de6c32019-06-06 14:29:25 -07001365 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001366 // Installed host modules might be used during the build, depend directly on their
1367 // dependencies so their timestamp is updated whenever their dependency is updated
1368 implicitDeps = deps
1369 } else {
1370 orderOnlyDeps = deps
1371 }
1372
Colin Cross25de6c32019-06-06 14:29:25 -07001373 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001374 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001375 Description: "install " + fullInstallPath.Base(),
1376 Output: fullInstallPath,
1377 Input: srcPath,
1378 Implicits: implicitDeps,
1379 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001380 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001381 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001382
Colin Cross25de6c32019-06-06 14:29:25 -07001383 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001384 }
Colin Cross25de6c32019-06-06 14:29:25 -07001385 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001386 return fullInstallPath
1387}
1388
Colin Cross25de6c32019-06-06 14:29:25 -07001389func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1390 fullInstallPath := installPath.Join(m, name)
1391 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001392
Colin Cross25de6c32019-06-06 14:29:25 -07001393 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001394
Alex Lightfb4353d2019-01-17 13:57:45 -08001395 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1396 if err != nil {
1397 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1398 }
Colin Cross25de6c32019-06-06 14:29:25 -07001399 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001400 Rule: Symlink,
1401 Description: "install symlink " + fullInstallPath.Base(),
1402 Output: fullInstallPath,
1403 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001404 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001405 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001406 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001407 },
1408 })
Colin Cross3854a602016-01-11 12:49:11 -08001409
Colin Cross25de6c32019-06-06 14:29:25 -07001410 m.installFiles = append(m.installFiles, fullInstallPath)
1411 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001412 }
Colin Cross3854a602016-01-11 12:49:11 -08001413 return fullInstallPath
1414}
1415
Jiyong Parkf1194352019-02-25 11:05:47 +09001416// installPath/name -> absPath where absPath might be a path that is available only at runtime
1417// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001418func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1419 fullInstallPath := installPath.Join(m, name)
1420 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001421
Colin Cross25de6c32019-06-06 14:29:25 -07001422 if !m.skipInstall(fullInstallPath) {
1423 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001424 Rule: Symlink,
1425 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1426 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001427 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001428 Args: map[string]string{
1429 "fromPath": absPath,
1430 },
1431 })
1432
Colin Cross25de6c32019-06-06 14:29:25 -07001433 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001434 }
1435 return fullInstallPath
1436}
1437
Colin Cross25de6c32019-06-06 14:29:25 -07001438func (m *moduleContext) CheckbuildFile(srcPath Path) {
1439 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001440}
1441
Colin Cross3f40fa42015-01-30 17:27:36 -08001442type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001443 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001444}
1445
1446func isFileInstaller(m blueprint.Module) bool {
1447 _, ok := m.(fileInstaller)
1448 return ok
1449}
1450
1451func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001452 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001453 return ok
1454}
Colin Crossfce53272015-04-08 11:21:40 -07001455
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001456func findStringInSlice(str string, slice []string) int {
1457 for i, s := range slice {
1458 if s == str {
1459 return i
Colin Crossfce53272015-04-08 11:21:40 -07001460 }
1461 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001462 return -1
1463}
1464
Colin Cross41955e82019-05-29 14:40:35 -07001465// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1466// was not a module reference.
1467func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001468 if len(s) > 1 && s[0] == ':' {
1469 return s[1:]
1470 }
1471 return ""
1472}
1473
Colin Cross41955e82019-05-29 14:40:35 -07001474// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1475// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1476func SrcIsModuleWithTag(s string) (module, tag string) {
1477 if len(s) > 1 && s[0] == ':' {
1478 module = s[1:]
1479 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1480 if module[len(module)-1] == '}' {
1481 tag = module[tagStart+1 : len(module)-1]
1482 module = module[:tagStart]
1483 return module, tag
1484 }
1485 }
1486 return module, ""
1487 }
1488 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001489}
1490
Colin Cross41955e82019-05-29 14:40:35 -07001491type sourceOrOutputDependencyTag struct {
1492 blueprint.BaseDependencyTag
1493 tag string
1494}
1495
1496func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1497 return sourceOrOutputDependencyTag{tag: tag}
1498}
1499
1500var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001501
Colin Cross366938f2017-12-11 16:29:02 -08001502// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1503// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001504//
1505// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001506func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001507 set := make(map[string]bool)
1508
Colin Cross068e0fe2016-12-13 15:23:47 -08001509 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001510 if m, t := SrcIsModuleWithTag(s); m != "" {
1511 if _, found := set[s]; found {
1512 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001513 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001514 set[s] = true
1515 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001516 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001517 }
1518 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001519}
1520
Colin Cross366938f2017-12-11 16:29:02 -08001521// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1522// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001523//
1524// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001525func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1526 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001527 if m, t := SrcIsModuleWithTag(*s); m != "" {
1528 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001529 }
1530 }
1531}
1532
Colin Cross41955e82019-05-29 14:40:35 -07001533// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1534// 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 -08001535type SourceFileProducer interface {
1536 Srcs() Paths
1537}
1538
Colin Cross41955e82019-05-29 14:40:35 -07001539// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1540// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1541// listed in the property.
1542type OutputFileProducer interface {
1543 OutputFiles(tag string) (Paths, error)
1544}
1545
Colin Crossfe17f6f2019-03-28 19:30:56 -07001546type HostToolProvider interface {
1547 HostToolPath() OptionalPath
1548}
1549
Colin Cross27b922f2019-03-04 22:35:41 -08001550// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1551// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001552//
1553// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001554func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1555 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001556}
1557
Colin Cross2fafa3e2019-03-05 12:39:51 -08001558// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1559// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001560//
1561// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001562func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1563 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001564}
1565
1566// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1567// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1568// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001569func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001570 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001571 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001572 }
1573 return OptionalPath{}
1574}
1575
Colin Cross25de6c32019-06-06 14:29:25 -07001576func (m *moduleContext) RequiredModuleNames() []string {
1577 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001578}
1579
Colin Cross25de6c32019-06-06 14:29:25 -07001580func (m *moduleContext) HostRequiredModuleNames() []string {
1581 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001582}
1583
Colin Cross25de6c32019-06-06 14:29:25 -07001584func (m *moduleContext) TargetRequiredModuleNames() []string {
1585 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001586}
1587
Colin Cross25de6c32019-06-06 14:29:25 -07001588func (m *moduleContext) Glob(globPattern string, excludes []string) Paths {
1589 ret, err := m.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001590 if err != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001591 m.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001592 }
Colin Cross25de6c32019-06-06 14:29:25 -07001593 return pathsForModuleSrcFromFullPath(m, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001594}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001595
Colin Cross25de6c32019-06-06 14:29:25 -07001596func (m *moduleContext) GlobFiles(globPattern string, excludes []string) Paths {
1597 ret, err := m.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001598 if err != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001599 m.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001600 }
Colin Cross25de6c32019-06-06 14:29:25 -07001601 return pathsForModuleSrcFromFullPath(m, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001602}
1603
Colin Cross463a90e2015-06-17 14:20:06 -07001604func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001605 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001606}
1607
Colin Cross0875c522017-11-28 17:34:01 -08001608func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001609 return &buildTargetSingleton{}
1610}
1611
Colin Cross87d8b562017-04-25 10:01:55 -07001612func parentDir(dir string) string {
1613 dir, _ = filepath.Split(dir)
1614 return filepath.Clean(dir)
1615}
1616
Colin Cross1f8c52b2015-06-16 16:38:17 -07001617type buildTargetSingleton struct{}
1618
Colin Cross0875c522017-11-28 17:34:01 -08001619func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1620 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001621
Colin Cross0875c522017-11-28 17:34:01 -08001622 mmTarget := func(dir string) WritablePath {
1623 return PathForPhony(ctx,
1624 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001625 }
1626
Colin Cross0875c522017-11-28 17:34:01 -08001627 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001628
Colin Cross0875c522017-11-28 17:34:01 -08001629 ctx.VisitAllModules(func(module Module) {
1630 blueprintDir := module.base().blueprintDir
1631 installTarget := module.base().installTarget
1632 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001633
Colin Cross0875c522017-11-28 17:34:01 -08001634 if checkbuildTarget != nil {
1635 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1636 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1637 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001638
Colin Cross0875c522017-11-28 17:34:01 -08001639 if installTarget != nil {
1640 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001641 }
1642 })
1643
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001644 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001645 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001646 suffix = "-soong"
1647 }
1648
Colin Cross1f8c52b2015-06-16 16:38:17 -07001649 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001650 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001651 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001652 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001653 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001654 })
1655
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001656 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001657 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001658 return
1659 }
1660
Colin Cross0875c522017-11-28 17:34:01 -08001661 sortedKeys := func(m map[string]Paths) []string {
1662 s := make([]string, 0, len(m))
1663 for k := range m {
1664 s = append(s, k)
1665 }
1666 sort.Strings(s)
1667 return s
1668 }
1669
Colin Cross87d8b562017-04-25 10:01:55 -07001670 // Ensure ancestor directories are in modulesInDir
1671 dirs := sortedKeys(modulesInDir)
1672 for _, dir := range dirs {
1673 dir := parentDir(dir)
1674 for dir != "." && dir != "/" {
1675 if _, exists := modulesInDir[dir]; exists {
1676 break
1677 }
1678 modulesInDir[dir] = nil
1679 dir = parentDir(dir)
1680 }
1681 }
1682
1683 // Make directories build their direct subdirectories
1684 dirs = sortedKeys(modulesInDir)
1685 for _, dir := range dirs {
1686 p := parentDir(dir)
1687 if p != "." && p != "/" {
1688 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1689 }
1690 }
1691
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001692 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1693 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1694 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001695 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001696 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001697 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001698 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001699 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001700 // HACK: checkbuild should be an optional build, but force it
1701 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001702 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001703 })
1704 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001705
1706 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1707 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001708 ctx.VisitAllModules(func(module Module) {
1709 if module.Enabled() {
1710 os := module.Target().Os
1711 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001712 }
1713 })
1714
Colin Cross0875c522017-11-28 17:34:01 -08001715 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001716 for os, deps := range osDeps {
1717 var className string
1718
1719 switch os.Class {
1720 case Host:
1721 className = "host"
1722 case HostCross:
1723 className = "host-cross"
1724 case Device:
1725 className = "target"
1726 default:
1727 continue
1728 }
1729
Colin Cross0875c522017-11-28 17:34:01 -08001730 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001731 osClass[className] = append(osClass[className], name)
1732
Colin Cross0875c522017-11-28 17:34:01 -08001733 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001734 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001735 Output: name,
1736 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001737 })
1738 }
1739
1740 // Wrap those into host|host-cross|target phony rules
1741 osClasses := sortedKeys(osClass)
1742 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001743 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001744 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001745 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001746 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001747 })
1748 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001749}
Colin Crossd779da42015-12-17 18:00:23 -08001750
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001751// Collect information for opening IDE project files in java/jdeps.go.
1752type IDEInfo interface {
1753 IDEInfo(ideInfo *IdeInfo)
1754 BaseModuleName() string
1755}
1756
1757// Extract the base module name from the Import name.
1758// Often the Import name has a prefix "prebuilt_".
1759// Remove the prefix explicitly if needed
1760// until we find a better solution to get the Import name.
1761type IDECustomizedModuleName interface {
1762 IDECustomizedModuleName() string
1763}
1764
1765type IdeInfo struct {
1766 Deps []string `json:"dependencies,omitempty"`
1767 Srcs []string `json:"srcs,omitempty"`
1768 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1769 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1770 Jars []string `json:"jars,omitempty"`
1771 Classes []string `json:"class,omitempty"`
1772 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001773 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001774}