blob: 394d0f40421901d9c3b64a5a8bb98dcf0fc2c166 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Alex Lightfb4353d2019-01-17 13:57:45 -080019 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "path/filepath"
Colin Cross6ff51382015-12-17 16:39:19 -080021 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080022 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070023
24 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070025 "github.com/google/blueprint/pathtools"
Colin Crossfe4bc362018-09-12 10:02:13 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
29var (
30 DeviceSharedLibrary = "shared_library"
31 DeviceStaticLibrary = "static_library"
32 DeviceExecutable = "executable"
33 HostSharedLibrary = "host_shared_library"
34 HostStaticLibrary = "host_static_library"
35 HostExecutable = "host_executable"
36)
37
Colin Crossae887032017-10-23 17:16:14 -070038type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080040 Deps blueprint.Deps
41 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070043 Output WritablePath
44 Outputs WritablePaths
45 ImplicitOutput WritablePath
46 ImplicitOutputs WritablePaths
47 Input Path
48 Inputs Paths
49 Implicit Path
50 Implicits Paths
51 OrderOnly Paths
52 Default bool
53 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054}
55
Colin Crossae887032017-10-23 17:16:14 -070056type ModuleBuildParams BuildParams
57
Colin Crossf6566ed2015-03-24 11:13:38 -070058type androidBaseContext interface {
Colin Crossa1ad8d12016-06-01 17:09:44 -070059 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070060 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -070061 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -070062 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070063 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070064 Host() bool
65 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070066 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -080067 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -070068 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070069 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070070 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +090071 Platform() bool
72 DeviceSpecific() bool
73 SocSpecific() bool
74 ProductSpecific() bool
Dario Frenifd05a742018-05-29 13:28:54 +010075 ProductServicesSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -070076 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -070077 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -070078}
79
Colin Cross635c3b02016-05-18 15:37:25 -070080type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -080081 BaseModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -070082 androidBaseContext
83}
84
Colin Crossaabf6792017-11-29 00:27:14 -080085// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
86// a Config instead of an interface{}.
87type BaseModuleContext interface {
88 ModuleName() string
89 ModuleDir() string
Colin Cross3d7c9822019-03-01 13:46:24 -080090 ModuleType() string
Colin Crossaabf6792017-11-29 00:27:14 -080091 Config() Config
92
93 ContainsProperty(name string) bool
94 Errorf(pos scanner.Position, fmt string, args ...interface{})
95 ModuleErrorf(fmt string, args ...interface{})
96 PropertyErrorf(property, fmt string, args ...interface{})
97 Failed() bool
98
99 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
100 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
101 // builder whenever a file matching the pattern as added or removed, without rerunning if a
102 // file that does not match the pattern is added to a searched directory.
103 GlobWithDeps(pattern string, excludes []string) ([]string, error)
104
105 Fs() pathtools.FileSystem
106 AddNinjaFileDeps(deps ...string)
107}
108
Colin Cross635c3b02016-05-18 15:37:25 -0700109type ModuleContext interface {
Colin Crossf6566ed2015-03-24 11:13:38 -0700110 androidBaseContext
Colin Crossaabf6792017-11-29 00:27:14 -0800111 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800112
Colin Crossae887032017-10-23 17:16:14 -0700113 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800114 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700115
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800117 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800118 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Colin Cross7f19f372016-11-01 11:10:25 -0700119 Glob(globPattern string, excludes []string) Paths
Nan Zhang581fd212018-01-10 16:06:12 -0800120 GlobFiles(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700121
Colin Cross5c517922017-08-31 12:29:17 -0700122 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
123 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800124 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900125 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700126 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800127
128 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700129
Colin Cross8d8f8e22016-08-03 11:57:50 -0700130 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700131 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900132 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800133
134 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700135 HostRequiredModuleNames() []string
136 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700137
138 // android.ModuleContext methods
139 // These are duplicated instead of embedded so that can eventually be wrapped to take an
140 // android.Module instead of a blueprint.Module
141 OtherModuleName(m blueprint.Module) string
142 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
143 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
144
Colin Cross0ef08162019-05-01 15:50:51 -0700145 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross3f68a132017-10-23 17:10:29 -0700146 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
147 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
148
149 ModuleSubDir() string
150
Colin Cross35143d02017-11-16 00:11:20 -0800151 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700152 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800153 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700154 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700155 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700156 VisitDepsDepthFirst(visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700157 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700158 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
159 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800160 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700161
Colin Cross0875c522017-11-28 17:34:01 -0800162 Variable(pctx PackageContext, name, value string)
163 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700164 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
165 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800166 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700167
Colin Cross0875c522017-11-28 17:34:01 -0800168 PrimaryModule() Module
169 FinalModule() Module
170 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700171
172 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800173 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800174}
175
Colin Cross635c3b02016-05-18 15:37:25 -0700176type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800177 blueprint.Module
178
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700179 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
180 // but GenerateAndroidBuildActions also has access to Android-specific information.
181 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700182 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700183
Colin Cross1e676be2016-10-12 14:38:15 -0700184 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800185
Colin Cross635c3b02016-05-18 15:37:25 -0700186 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800187 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700188 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800189 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700190 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900191 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800192 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900193 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900194 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700195
196 AddProperties(props ...interface{})
197 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700198
Colin Crossae887032017-10-23 17:16:14 -0700199 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800200 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800201 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800202}
203
Colin Crossfc754582016-05-17 16:34:16 -0700204type nameProperties struct {
205 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800206 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700207}
208
209type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800210 // emit build rules for this module
211 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800212
Paul Duffin2e61fa62019-03-28 14:10:57 +0000213 // Controls the visibility of this module to other modules. Allowable values are one or more of
214 // these formats:
215 //
216 // ["//visibility:public"]: Anyone can use this module.
217 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
218 // this module.
219 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
220 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
221 // this module. Note that sub-packages do not have access to the rule; for example,
222 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
223 // is a special module and must be used verbatim. It represents all of the modules in the
224 // package.
225 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
226 // or other or in one of their sub-packages have access to this module. For example,
227 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
228 // to depend on this rule (but not //independent:evil)
229 // ["//project"]: This is shorthand for ["//project:__pkg__"]
230 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
231 // //project is the module's package. e.g. using [":__subpackages__"] in
232 // packages/apps/Settings/Android.bp is equivalent to
233 // //packages/apps/Settings:__subpackages__.
234 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
235 // for now. It is an error if it is used in a module.
236 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
237 // more details.
238 Visibility []string
239
Colin Cross7d5136f2015-05-11 13:39:40 -0700240 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800241 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
242 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
243 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700244 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700245
246 Target struct {
247 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700248 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700249 }
250 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700251 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700252 }
253 }
254
Colin Crossee0bc3b2018-10-02 22:01:37 -0700255 UseTargetVariants bool `blueprint:"mutated"`
256 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800257
Dan Willemsen782a2d12015-12-21 14:55:28 -0800258 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700259 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800260
Colin Cross55708f32017-03-20 13:23:34 -0700261 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700262 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700263
Jiyong Park2db76922017-11-08 16:03:48 +0900264 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
265 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
266 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700267 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700268
Jiyong Park2db76922017-11-08 16:03:48 +0900269 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
270 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
271 Soc_specific *bool
272
273 // whether this module is specific to a device, not only for SoC, but also for off-chip
274 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
275 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
276 // This implies `soc_specific:true`.
277 Device_specific *bool
278
279 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900280 // network operator, etc). When set to true, it is installed into /product (or
281 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900282 Product_specific *bool
283
Dario Frenifd05a742018-05-29 13:28:54 +0100284 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100285 // to true, it is installed into /product_services (or /system/product_services if
286 // product_services partition does not exist).
287 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100288
Jiyong Parkf9332f12018-02-01 00:54:12 +0900289 // Whether this module is installed to recovery partition
290 Recovery *bool
291
dimitry1f33e402019-03-26 12:39:31 +0100292 // Whether this module is built for non-native architecures (also known as native bridge binary)
293 Native_bridge_supported *bool `android:"arch_variant"`
294
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700295 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800296 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700297
Steven Moreland57a23d22018-04-04 15:42:19 -0700298 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800299 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700300
Chris Wolfe998306e2016-08-15 14:47:23 -0400301 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700302 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400303
Sasha Smundakb6d23052019-04-01 18:37:36 -0700304 // names of other modules to install on host if this module is installed
305 Host_required []string `android:"arch_variant"`
306
307 // names of other modules to install on target if this module is installed
308 Target_required []string `android:"arch_variant"`
309
Colin Cross5aac3622017-08-31 15:07:09 -0700310 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800311 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700312
Dan Willemsen569edc52018-11-19 09:33:29 -0800313 Dist struct {
314 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
315 // command line and any of these targets are also on the command line, or otherwise
316 // built
317 Targets []string `android:"arch_variant"`
318
319 // The name of the output artifact. This defaults to the basename of the output of
320 // the module.
321 Dest *string `android:"arch_variant"`
322
323 // The directory within the dist directory to store the artifact. Defaults to the
324 // top level directory ("").
325 Dir *string `android:"arch_variant"`
326
327 // A suffix to add to the artifact file name (before any extension).
328 Suffix *string `android:"arch_variant"`
329 } `android:"arch_variant"`
330
Colin Crossa1ad8d12016-06-01 17:09:44 -0700331 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700332 CompileTarget Target `blueprint:"mutated"`
333 CompileMultiTargets []Target `blueprint:"mutated"`
334 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800335
336 // Set by InitAndroidModule
337 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700338 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700339
340 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800341
342 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800343}
344
345type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800346 // If set to true, build a variant of the module for the host. Defaults to false.
347 Host_supported *bool
348
349 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700350 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800351}
352
Colin Crossc472d572015-03-17 15:06:21 -0700353type Multilib string
354
355const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800356 MultilibBoth Multilib = "both"
357 MultilibFirst Multilib = "first"
358 MultilibCommon Multilib = "common"
359 MultilibCommonFirst Multilib = "common_first"
360 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700361)
362
Colin Crossa1ad8d12016-06-01 17:09:44 -0700363type HostOrDeviceSupported int
364
365const (
366 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700367
368 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700369 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700370
371 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700372 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700373
374 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700375 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700376
377 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700378 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700379
380 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700381 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700382
383 // Nothing is supported. This is not exposed to the user, but used to mark a
384 // host only module as unsupported when the module type is not supported on
385 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700386 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700387)
388
Jiyong Park2db76922017-11-08 16:03:48 +0900389type moduleKind int
390
391const (
392 platformModule moduleKind = iota
393 deviceSpecificModule
394 socSpecificModule
395 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100396 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900397)
398
399func (k moduleKind) String() string {
400 switch k {
401 case platformModule:
402 return "platform"
403 case deviceSpecificModule:
404 return "device-specific"
405 case socSpecificModule:
406 return "soc-specific"
407 case productSpecificModule:
408 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100409 case productServicesSpecificModule:
410 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900411 default:
412 panic(fmt.Errorf("unknown module kind %d", k))
413 }
414}
415
Colin Cross36242852017-06-23 15:06:31 -0700416func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800417 base := m.base()
418 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700419
Colin Cross36242852017-06-23 15:06:31 -0700420 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700421 &base.nameProperties,
422 &base.commonProperties,
423 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700424 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700425 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700426}
427
Colin Cross36242852017-06-23 15:06:31 -0700428func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
429 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700430
431 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800432 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700433 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700434 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700435 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800436
Dan Willemsen218f6562015-07-08 18:13:11 -0700437 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700438 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700439 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800440 }
441
Colin Cross36242852017-06-23 15:06:31 -0700442 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800443}
444
Colin Crossee0bc3b2018-10-02 22:01:37 -0700445func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
446 InitAndroidArchModule(m, hod, defaultMultilib)
447 m.base().commonProperties.UseTargetVariants = false
448}
449
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800450// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800451// modules. It should be included as an anonymous field in every module
452// struct definition. InitAndroidModule should then be called from the module's
453// factory function, and the return values from InitAndroidModule should be
454// returned from the factory function.
455//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800456// The ModuleBase type is responsible for implementing the GenerateBuildActions
457// method to support the blueprint.Module interface. This method will then call
458// the module's GenerateAndroidBuildActions method once for each build variant
459// that is to be built. GenerateAndroidBuildActions is passed a
460// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800461// AndroidModuleContext exposes extra functionality specific to the Android build
462// system including details about the particular build variant that is to be
463// generated.
464//
465// For example:
466//
467// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800468// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800469// )
470//
471// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800472// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800473// properties struct {
474// MyProperty string
475// }
476// }
477//
Colin Cross36242852017-06-23 15:06:31 -0700478// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800479// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700480// m.AddProperties(&m.properties)
481// android.InitAndroidModule(m)
482// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800483// }
484//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800485// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800486// // Get the CPU architecture for the current build variant.
487// variantArch := ctx.Arch()
488//
489// // ...
490// }
Colin Cross635c3b02016-05-18 15:37:25 -0700491type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800492 // Putting the curiously recurring thing pointing to the thing that contains
493 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700494 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700495 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800496
Colin Crossfc754582016-05-17 16:34:16 -0700497 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800498 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700499 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800500 hostAndDeviceProperties hostAndDeviceProperties
501 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700502 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700503 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800504
505 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700506 installFiles Paths
507 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900508 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700509
510 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
511 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800512 installTarget WritablePath
513 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700514 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700515
Colin Cross178a5092016-09-13 13:42:32 -0700516 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700517
518 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700519
520 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700521 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800522 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800523 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700524
525 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700526}
527
Colin Cross5f692ec2019-02-01 16:53:07 -0800528func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
529
Colin Cross36242852017-06-23 15:06:31 -0700530func (a *ModuleBase) AddProperties(props ...interface{}) {
531 a.registerProps = append(a.registerProps, props...)
532}
533
534func (a *ModuleBase) GetProperties() []interface{} {
535 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800536}
537
Colin Crossae887032017-10-23 17:16:14 -0700538func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700539 return a.buildParams
540}
541
Colin Cross4c83e5c2019-02-25 14:54:28 -0800542func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
543 return a.ruleParams
544}
545
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800546func (a *ModuleBase) VariablesForTests() map[string]string {
547 return a.variables
548}
549
Colin Crossa9d8bee2018-10-02 13:59:46 -0700550func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
551 a.prefer32 = prefer32
552}
553
Colin Crossce75d2c2016-10-06 16:12:58 -0700554// Name returns the name of the module. It may be overridden by individual module types, for
555// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700556func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800557 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700558}
559
Colin Crossce75d2c2016-10-06 16:12:58 -0700560// BaseModuleName returns the name of the module as specified in the blueprints file.
561func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800562 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700563}
564
Colin Cross635c3b02016-05-18 15:37:25 -0700565func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800566 return a
567}
568
Colin Crossee0bc3b2018-10-02 22:01:37 -0700569func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700570 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700571 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700572 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700573}
574
Colin Crossa1ad8d12016-06-01 17:09:44 -0700575func (a *ModuleBase) Target() Target {
576 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800577}
578
Colin Cross8b74d172016-09-13 09:59:14 -0700579func (a *ModuleBase) TargetPrimary() bool {
580 return a.commonProperties.CompilePrimary
581}
582
Colin Crossee0bc3b2018-10-02 22:01:37 -0700583func (a *ModuleBase) MultiTargets() []Target {
584 return a.commonProperties.CompileMultiTargets
585}
586
Colin Crossa1ad8d12016-06-01 17:09:44 -0700587func (a *ModuleBase) Os() OsType {
588 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800589}
590
Colin Cross635c3b02016-05-18 15:37:25 -0700591func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700592 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800593}
594
Colin Cross635c3b02016-05-18 15:37:25 -0700595func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700596 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800597}
598
Dan Willemsen0b24c742016-10-04 15:13:37 -0700599func (a *ModuleBase) ArchSpecific() bool {
600 return a.commonProperties.ArchSpecific
601}
602
Colin Crossa1ad8d12016-06-01 17:09:44 -0700603func (a *ModuleBase) OsClassSupported() []OsClass {
604 switch a.commonProperties.HostOrDeviceSupported {
605 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700606 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700607 case HostSupportedNoCross:
608 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700609 case DeviceSupported:
610 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700611 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700612 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700613 if Bool(a.hostAndDeviceProperties.Host_supported) ||
614 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
615 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700616 supported = append(supported, Host, HostCross)
617 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700618 if a.hostAndDeviceProperties.Device_supported == nil ||
619 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700620 supported = append(supported, Device)
621 }
622 return supported
623 default:
624 return nil
625 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800626}
627
Colin Cross635c3b02016-05-18 15:37:25 -0700628func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800629 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
630 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700631 (a.hostAndDeviceProperties.Device_supported == nil ||
632 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800633}
634
Jiyong Parkc678ad32018-04-10 13:07:10 +0900635func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100636 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900637}
638
639func (a *ModuleBase) DeviceSpecific() bool {
640 return Bool(a.commonProperties.Device_specific)
641}
642
643func (a *ModuleBase) SocSpecific() bool {
644 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
645}
646
647func (a *ModuleBase) ProductSpecific() bool {
648 return Bool(a.commonProperties.Product_specific)
649}
650
Dario Frenifd05a742018-05-29 13:28:54 +0100651func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100652 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100653}
654
Colin Cross635c3b02016-05-18 15:37:25 -0700655func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800656 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800657 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800658 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800659 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800660}
661
Colin Crossce75d2c2016-10-06 16:12:58 -0700662func (a *ModuleBase) SkipInstall() {
663 a.commonProperties.SkipInstall = true
664}
665
Jiyong Park374510b2018-03-19 18:23:01 +0900666func (a *ModuleBase) ExportedToMake() bool {
667 return a.commonProperties.NamespaceExportedToMake
668}
669
Colin Cross635c3b02016-05-18 15:37:25 -0700670func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700671 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800672
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700673 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700674 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800675 ctx.VisitDepsDepthFirstIf(isFileInstaller,
676 func(m blueprint.Module) {
677 fileInstaller := m.(fileInstaller)
678 files := fileInstaller.filesToInstall()
679 result = append(result, files...)
680 })
681
682 return result
683}
684
Colin Cross635c3b02016-05-18 15:37:25 -0700685func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800686 return a.installFiles
687}
688
Colin Cross635c3b02016-05-18 15:37:25 -0700689func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800690 return p.noAddressSanitizer
691}
692
Colin Cross635c3b02016-05-18 15:37:25 -0700693func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800694 return false
695}
696
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700697func (p *ModuleBase) InstallInSanitizerDir() bool {
698 return false
699}
700
Jiyong Parkf9332f12018-02-01 00:54:12 +0900701func (p *ModuleBase) InstallInRecovery() bool {
702 return Bool(p.commonProperties.Recovery)
703}
704
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900705func (a *ModuleBase) Owner() string {
706 return String(a.commonProperties.Owner)
707}
708
Jiyong Park52818fc2019-03-18 12:01:38 +0900709func (a *ModuleBase) NoticeFile() OptionalPath {
710 return a.noticeFile
711}
712
Colin Cross0875c522017-11-28 17:34:01 -0800713func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700714 allInstalledFiles := Paths{}
715 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800716 ctx.VisitAllModuleVariants(func(module Module) {
717 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700718 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
719 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800720 })
721
Colin Cross0875c522017-11-28 17:34:01 -0800722 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700723
Jeff Gaston088e29e2017-11-29 16:47:17 -0800724 namespacePrefix := ctx.Namespace().(*Namespace).id
725 if namespacePrefix != "" {
726 namespacePrefix = namespacePrefix + "-"
727 }
728
Colin Cross3f40fa42015-01-30 17:27:36 -0800729 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800730 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800731 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700732 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800733 Output: name,
734 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800735 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700736 })
737 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700738 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700739 }
740
741 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800742 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800743 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700744 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800745 Output: name,
746 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700747 })
748 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700749 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700750 }
751
752 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800753 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800754 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800755 suffix = "-soong"
756 }
757
Jeff Gaston088e29e2017-11-29 16:47:17 -0800758 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800759 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700760 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800761 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700762 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800763 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700764
765 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800766 }
767}
768
Jiyong Park2db76922017-11-08 16:03:48 +0900769func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
770 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
771 var deviceSpecific = Bool(a.commonProperties.Device_specific)
772 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100773 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900774
Dario Frenifd05a742018-05-29 13:28:54 +0100775 msg := "conflicting value set here"
776 if socSpecific && deviceSpecific {
777 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900778 if Bool(a.commonProperties.Vendor) {
779 ctx.PropertyErrorf("vendor", msg)
780 }
781 if Bool(a.commonProperties.Proprietary) {
782 ctx.PropertyErrorf("proprietary", msg)
783 }
784 if Bool(a.commonProperties.Soc_specific) {
785 ctx.PropertyErrorf("soc_specific", msg)
786 }
787 }
788
Dario Frenifd05a742018-05-29 13:28:54 +0100789 if productSpecific && productServicesSpecific {
790 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
791 ctx.PropertyErrorf("product_services_specific", msg)
792 }
793
794 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
795 if productSpecific {
796 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
797 } else {
798 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
799 }
800 if deviceSpecific {
801 ctx.PropertyErrorf("device_specific", msg)
802 } else {
803 if Bool(a.commonProperties.Vendor) {
804 ctx.PropertyErrorf("vendor", msg)
805 }
806 if Bool(a.commonProperties.Proprietary) {
807 ctx.PropertyErrorf("proprietary", msg)
808 }
809 if Bool(a.commonProperties.Soc_specific) {
810 ctx.PropertyErrorf("soc_specific", msg)
811 }
812 }
813 }
814
Jiyong Park2db76922017-11-08 16:03:48 +0900815 if productSpecific {
816 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100817 } else if productServicesSpecific {
818 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900819 } else if deviceSpecific {
820 return deviceSpecificModule
821 } else if socSpecific {
822 return socSpecificModule
823 } else {
824 return platformModule
825 }
826}
827
Colin Cross635c3b02016-05-18 15:37:25 -0700828func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700829 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700830 target: a.commonProperties.CompileTarget,
831 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700832 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900833 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700834 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800835 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800836}
837
Colin Cross0875c522017-11-28 17:34:01 -0800838func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
839 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700840 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800841 ModuleContext: blueprintCtx,
842 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
843 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700844 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800845 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800846 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800847 }
848
Colin Cross4c83e5c2019-02-25 14:54:28 -0800849 if ctx.config.captureBuild {
850 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
851 }
852
Colin Cross67a5c132017-05-09 13:45:28 -0700853 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
854 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800855 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
856 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700857 }
Colin Cross0875c522017-11-28 17:34:01 -0800858 if !ctx.PrimaryArch() {
859 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700860 }
861
862 ctx.Variable(pctx, "moduleDesc", desc)
863
864 s := ""
865 if len(suffix) > 0 {
866 s = " [" + strings.Join(suffix, " ") + "]"
867 }
868 ctx.Variable(pctx, "moduleDescSuffix", s)
869
Dan Willemsen569edc52018-11-19 09:33:29 -0800870 // Some common property checks for properties that will be used later in androidmk.go
871 if a.commonProperties.Dist.Dest != nil {
872 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
873 if err != nil {
874 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
875 }
876 }
877 if a.commonProperties.Dist.Dir != nil {
878 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
879 if err != nil {
880 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
881 }
882 }
883 if a.commonProperties.Dist.Suffix != nil {
884 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
885 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
886 }
887 }
888
Colin Cross9b1d13d2016-09-19 15:18:11 -0700889 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800890 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700891 if ctx.Failed() {
892 return
893 }
894
Colin Cross0875c522017-11-28 17:34:01 -0800895 a.installFiles = append(a.installFiles, ctx.installFiles...)
896 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800897
Jiyong Park52818fc2019-03-18 12:01:38 +0900898 notice := proptools.StringDefault(a.commonProperties.Notice, "NOTICE")
899 if m := SrcIsModule(notice); m != "" {
900 a.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
901 } else {
902 noticePath := filepath.Join(ctx.ModuleDir(), notice)
903 a.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800904 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800905 }
906
Colin Cross9b1d13d2016-09-19 15:18:11 -0700907 if a == ctx.FinalModule().(Module).base() {
908 a.generateModuleTarget(ctx)
909 if ctx.Failed() {
910 return
911 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800912 }
Colin Crosscec81712017-07-13 14:43:27 -0700913
Colin Cross0875c522017-11-28 17:34:01 -0800914 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800915 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800916 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800917}
918
Colin Crossf6566ed2015-03-24 11:13:38 -0700919type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700920 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700921 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700922 targetPrimary bool
923 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900924 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700925 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700926}
927
Colin Cross3f40fa42015-01-30 17:27:36 -0800928type androidModuleContext struct {
929 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700930 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700931 installDeps Paths
932 installFiles Paths
933 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800934 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700935 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700936
937 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700938 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800939 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800940 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800941}
942
Colin Cross67a5c132017-05-09 13:45:28 -0700943func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800944 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700945 Rule: ErrorRule,
946 Description: desc,
947 Outputs: outputs,
948 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800949 Args: map[string]string{
950 "error": err.Error(),
951 },
952 })
953 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800954}
955
Colin Crossaabf6792017-11-29 00:27:14 -0800956func (a *androidModuleContext) Config() Config {
957 return a.ModuleContext.Config().(Config)
958}
959
Colin Cross0875c522017-11-28 17:34:01 -0800960func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700961 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800962}
963
Colin Cross0875c522017-11-28 17:34:01 -0800964func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700965 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700966 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800967 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800968 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700969 Outputs: params.Outputs.Strings(),
970 ImplicitOutputs: params.ImplicitOutputs.Strings(),
971 Inputs: params.Inputs.Strings(),
972 Implicits: params.Implicits.Strings(),
973 OrderOnly: params.OrderOnly.Strings(),
974 Args: params.Args,
975 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700976 }
977
Colin Cross33bfb0a2016-11-21 17:23:08 -0800978 if params.Depfile != nil {
979 bparams.Depfile = params.Depfile.String()
980 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700981 if params.Output != nil {
982 bparams.Outputs = append(bparams.Outputs, params.Output.String())
983 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700984 if params.ImplicitOutput != nil {
985 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
986 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700987 if params.Input != nil {
988 bparams.Inputs = append(bparams.Inputs, params.Input.String())
989 }
990 if params.Implicit != nil {
991 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
992 }
993
Colin Cross0b9f31f2019-02-28 11:00:01 -0800994 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
995 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
996 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
997 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
998 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
999 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001000
Colin Cross0875c522017-11-28 17:34:01 -08001001 return bparams
1002}
1003
1004func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001005 if a.config.captureBuild {
1006 a.variables[name] = value
1007 }
1008
Colin Cross0875c522017-11-28 17:34:01 -08001009 a.ModuleContext.Variable(pctx.PackageContext, name, value)
1010}
1011
1012func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
1013 argNames ...string) blueprint.Rule {
1014
Colin Cross4c83e5c2019-02-25 14:54:28 -08001015 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
1016
1017 if a.config.captureBuild {
1018 a.ruleParams[rule] = params
1019 }
1020
1021 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001022}
1023
1024func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
1025 if a.config.captureBuild {
1026 a.buildParams = append(a.buildParams, params)
1027 }
1028
1029 bparams := convertBuildParams(params)
1030
1031 if bparams.Description != "" {
1032 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1033 }
1034
Colin Cross6ff51382015-12-17 16:39:19 -08001035 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -07001036 a.ninjaError(bparams.Description, bparams.Outputs,
1037 fmt.Errorf("module %s missing dependencies: %s\n",
1038 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001039 return
1040 }
1041
Colin Cross0875c522017-11-28 17:34:01 -08001042 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001043}
1044
Colin Cross6ff51382015-12-17 16:39:19 -08001045func (a *androidModuleContext) GetMissingDependencies() []string {
1046 return a.missingDeps
1047}
1048
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001049func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1050 if deps != nil {
1051 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001052 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001053 }
1054}
1055
Colin Crossd11fcda2017-10-23 17:59:01 -07001056func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1057 aModule, _ := module.(Module)
1058 if aModule == nil {
1059 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1060 return nil
1061 }
1062
1063 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001064 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001065 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1066 } else {
1067 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1068 }
1069 return nil
1070 }
1071
1072 return aModule
1073}
1074
Jiyong Parkf2976302019-04-17 21:47:37 +09001075func (a *androidModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
1076 type dep struct {
1077 mod blueprint.Module
1078 tag blueprint.DependencyTag
1079 }
1080 var deps []dep
1081 a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1082 if aModule, _ := m.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
1083 returnedTag := a.ModuleContext.OtherModuleDependencyTag(aModule)
1084 if tag == nil || returnedTag == tag {
1085 deps = append(deps, dep{aModule, returnedTag})
1086 }
1087 }
1088 })
1089 if len(deps) == 1 {
1090 return deps[0].mod, deps[0].tag
1091 } else if len(deps) >= 2 {
1092 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
1093 name, a.ModuleName()))
1094 } else {
1095 return nil, nil
1096 }
1097}
1098
Colin Cross0ef08162019-05-01 15:50:51 -07001099func (a *androidModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
1100 var deps []Module
1101 a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1102 if aModule, _ := m.(Module); aModule != nil {
1103 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1104 deps = append(deps, aModule)
1105 }
1106 }
1107 })
1108 return deps
1109}
1110
Jiyong Parkf2976302019-04-17 21:47:37 +09001111func (a *androidModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1112 m, _ := a.getDirectDepInternal(name, tag)
1113 return m
1114}
1115
1116func (a *androidModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1117 return a.getDirectDepInternal(name, nil)
1118}
1119
Colin Cross35143d02017-11-16 00:11:20 -08001120func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1121 a.ModuleContext.VisitDirectDeps(visit)
1122}
1123
Colin Crossd11fcda2017-10-23 17:59:01 -07001124func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1125 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1126 if aModule := a.validateAndroidModule(module); aModule != nil {
1127 visit(aModule)
1128 }
1129 })
1130}
1131
Colin Crossee6143c2017-12-30 17:54:27 -08001132func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1133 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1134 if aModule := a.validateAndroidModule(module); aModule != nil {
1135 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1136 visit(aModule)
1137 }
1138 }
1139 })
1140}
1141
Colin Crossd11fcda2017-10-23 17:59:01 -07001142func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1143 a.ModuleContext.VisitDirectDepsIf(
1144 // pred
1145 func(module blueprint.Module) bool {
1146 if aModule := a.validateAndroidModule(module); aModule != nil {
1147 return pred(aModule)
1148 } else {
1149 return false
1150 }
1151 },
1152 // visit
1153 func(module blueprint.Module) {
1154 visit(module.(Module))
1155 })
1156}
1157
1158func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1159 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1160 if aModule := a.validateAndroidModule(module); aModule != nil {
1161 visit(aModule)
1162 }
1163 })
1164}
1165
1166func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1167 a.ModuleContext.VisitDepsDepthFirstIf(
1168 // pred
1169 func(module blueprint.Module) bool {
1170 if aModule := a.validateAndroidModule(module); aModule != nil {
1171 return pred(aModule)
1172 } else {
1173 return false
1174 }
1175 },
1176 // visit
1177 func(module blueprint.Module) {
1178 visit(module.(Module))
1179 })
1180}
1181
Alex Light778127a2019-02-27 14:19:50 -08001182func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1183 a.ModuleContext.WalkDeps(visit)
1184}
1185
Colin Crossd11fcda2017-10-23 17:59:01 -07001186func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1187 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1188 childAndroidModule := a.validateAndroidModule(child)
1189 parentAndroidModule := a.validateAndroidModule(parent)
1190 if childAndroidModule != nil && parentAndroidModule != nil {
1191 return visit(childAndroidModule, parentAndroidModule)
1192 } else {
1193 return false
1194 }
1195 })
1196}
1197
Colin Cross0875c522017-11-28 17:34:01 -08001198func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1199 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1200 visit(module.(Module))
1201 })
1202}
1203
1204func (a *androidModuleContext) PrimaryModule() Module {
1205 return a.ModuleContext.PrimaryModule().(Module)
1206}
1207
1208func (a *androidModuleContext) FinalModule() Module {
1209 return a.ModuleContext.FinalModule().(Module)
1210}
1211
Colin Crossa1ad8d12016-06-01 17:09:44 -07001212func (a *androidBaseContextImpl) Target() Target {
1213 return a.target
1214}
1215
Colin Cross8b74d172016-09-13 09:59:14 -07001216func (a *androidBaseContextImpl) TargetPrimary() bool {
1217 return a.targetPrimary
1218}
1219
Colin Crossee0bc3b2018-10-02 22:01:37 -07001220func (a *androidBaseContextImpl) MultiTargets() []Target {
1221 return a.multiTargets
1222}
1223
Colin Crossf6566ed2015-03-24 11:13:38 -07001224func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001225 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001226}
1227
Colin Crossa1ad8d12016-06-01 17:09:44 -07001228func (a *androidBaseContextImpl) Os() OsType {
1229 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001230}
1231
Colin Crossf6566ed2015-03-24 11:13:38 -07001232func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001233 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001234}
1235
1236func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001237 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001238}
1239
Colin Cross0af4b842015-04-30 16:36:18 -07001240func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001241 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001242}
1243
Doug Horn21b94272019-01-16 12:06:11 -08001244func (a *androidBaseContextImpl) Fuchsia() bool {
1245 return a.target.Os == Fuchsia
1246}
1247
Colin Cross3edeee12017-04-04 12:59:48 -07001248func (a *androidBaseContextImpl) Windows() bool {
1249 return a.target.Os == Windows
1250}
1251
Colin Crossf6566ed2015-03-24 11:13:38 -07001252func (a *androidBaseContextImpl) Debug() bool {
1253 return a.debug
1254}
1255
Colin Cross1e7d3702016-08-24 15:25:47 -07001256func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001257 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001258 return true
1259 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001260 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001261}
1262
Colin Cross1332b002015-04-07 17:11:30 -07001263func (a *androidBaseContextImpl) AConfig() Config {
1264 return a.config
1265}
1266
Colin Cross9272ade2016-08-17 15:24:12 -07001267func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1268 return DeviceConfig{a.config.deviceConfig}
1269}
1270
Jiyong Park2db76922017-11-08 16:03:48 +09001271func (a *androidBaseContextImpl) Platform() bool {
1272 return a.kind == platformModule
1273}
1274
1275func (a *androidBaseContextImpl) DeviceSpecific() bool {
1276 return a.kind == deviceSpecificModule
1277}
1278
1279func (a *androidBaseContextImpl) SocSpecific() bool {
1280 return a.kind == socSpecificModule
1281}
1282
1283func (a *androidBaseContextImpl) ProductSpecific() bool {
1284 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001285}
1286
Dario Frenifd05a742018-05-29 13:28:54 +01001287func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1288 return a.kind == productServicesSpecificModule
1289}
1290
Jiyong Park5baac542018-08-28 09:55:37 +09001291// Makes this module a platform module, i.e. not specific to soc, device,
1292// product, or product_services.
1293func (a *ModuleBase) MakeAsPlatform() {
1294 a.commonProperties.Vendor = boolPtr(false)
1295 a.commonProperties.Proprietary = boolPtr(false)
1296 a.commonProperties.Soc_specific = boolPtr(false)
1297 a.commonProperties.Product_specific = boolPtr(false)
1298 a.commonProperties.Product_services_specific = boolPtr(false)
1299}
1300
dimitry03dc3f62019-05-09 14:07:34 +02001301func (a *ModuleBase) EnableNativeBridgeSupportByDefault() {
1302 a.commonProperties.Native_bridge_supported = boolPtr(true)
1303}
1304
Colin Cross8d8f8e22016-08-03 11:57:50 -07001305func (a *androidModuleContext) InstallInData() bool {
1306 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001307}
1308
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001309func (a *androidModuleContext) InstallInSanitizerDir() bool {
1310 return a.module.InstallInSanitizerDir()
1311}
1312
Jiyong Parkf9332f12018-02-01 00:54:12 +09001313func (a *androidModuleContext) InstallInRecovery() bool {
1314 return a.module.InstallInRecovery()
1315}
1316
Colin Cross893d8162017-04-26 17:34:03 -07001317func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1318 if a.module.base().commonProperties.SkipInstall {
1319 return true
1320 }
1321
Colin Cross3607f212018-05-07 15:28:05 -07001322 // We'll need a solution for choosing which of modules with the same name in different
1323 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1324 // list of namespaces to install in a Soong-only build.
1325 if !a.module.base().commonProperties.NamespaceExportedToMake {
1326 return true
1327 }
1328
Colin Cross893d8162017-04-26 17:34:03 -07001329 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001330 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001331 return true
1332 }
1333
Colin Cross6510f912017-11-29 00:27:14 -08001334 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001335 return true
1336 }
1337 }
1338
1339 return false
1340}
1341
Colin Cross5c517922017-08-31 12:29:17 -07001342func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001343 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001344 return a.installFile(installPath, name, srcPath, Cp, deps)
1345}
1346
1347func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1348 deps ...Path) OutputPath {
1349 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1350}
1351
1352func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1353 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001354
Dan Willemsen782a2d12015-12-21 14:55:28 -08001355 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001356 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001357
Colin Cross893d8162017-04-26 17:34:03 -07001358 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001359
Dan Willemsen322acaf2016-01-12 23:07:05 -08001360 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001361
Colin Cross89562dc2016-10-03 17:47:19 -07001362 var implicitDeps, orderOnlyDeps Paths
1363
1364 if a.Host() {
1365 // Installed host modules might be used during the build, depend directly on their
1366 // dependencies so their timestamp is updated whenever their dependency is updated
1367 implicitDeps = deps
1368 } else {
1369 orderOnlyDeps = deps
1370 }
1371
Colin Crossae887032017-10-23 17:16:14 -07001372 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001373 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001374 Description: "install " + fullInstallPath.Base(),
1375 Output: fullInstallPath,
1376 Input: srcPath,
1377 Implicits: implicitDeps,
1378 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001379 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001380 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001381
Dan Willemsen322acaf2016-01-12 23:07:05 -08001382 a.installFiles = append(a.installFiles, fullInstallPath)
1383 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001384 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001385 return fullInstallPath
1386}
1387
Colin Cross3854a602016-01-11 12:49:11 -08001388func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1389 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001390 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001391
Colin Cross893d8162017-04-26 17:34:03 -07001392 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001393
Alex Lightfb4353d2019-01-17 13:57:45 -08001394 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1395 if err != nil {
1396 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1397 }
Colin Crossae887032017-10-23 17:16:14 -07001398 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001399 Rule: Symlink,
1400 Description: "install symlink " + fullInstallPath.Base(),
1401 Output: fullInstallPath,
1402 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001403 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001404 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001405 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001406 },
1407 })
Colin Cross3854a602016-01-11 12:49:11 -08001408
Colin Cross12fc4972016-01-11 12:49:11 -08001409 a.installFiles = append(a.installFiles, fullInstallPath)
1410 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1411 }
Colin Cross3854a602016-01-11 12:49:11 -08001412 return fullInstallPath
1413}
1414
Jiyong Parkf1194352019-02-25 11:05:47 +09001415// installPath/name -> absPath where absPath might be a path that is available only at runtime
1416// (e.g. /apex/...)
1417func (a *androidModuleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1418 fullInstallPath := installPath.Join(a, name)
1419 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
1420
1421 if !a.skipInstall(fullInstallPath) {
1422 a.Build(pctx, BuildParams{
1423 Rule: Symlink,
1424 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1425 Output: fullInstallPath,
1426 Default: !a.Config().EmbeddedInMake(),
1427 Args: map[string]string{
1428 "fromPath": absPath,
1429 },
1430 })
1431
1432 a.installFiles = append(a.installFiles, fullInstallPath)
1433 }
1434 return fullInstallPath
1435}
1436
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001437func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001438 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1439}
1440
Colin Cross3f40fa42015-01-30 17:27:36 -08001441type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001442 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001443}
1444
1445func isFileInstaller(m blueprint.Module) bool {
1446 _, ok := m.(fileInstaller)
1447 return ok
1448}
1449
1450func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001451 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001452 return ok
1453}
Colin Crossfce53272015-04-08 11:21:40 -07001454
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001455func findStringInSlice(str string, slice []string) int {
1456 for i, s := range slice {
1457 if s == str {
1458 return i
Colin Crossfce53272015-04-08 11:21:40 -07001459 }
1460 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001461 return -1
1462}
1463
Colin Cross068e0fe2016-12-13 15:23:47 -08001464func SrcIsModule(s string) string {
1465 if len(s) > 1 && s[0] == ':' {
1466 return s[1:]
1467 }
1468 return ""
1469}
1470
1471type sourceDependencyTag struct {
1472 blueprint.BaseDependencyTag
1473}
1474
1475var SourceDepTag sourceDependencyTag
1476
Colin Cross366938f2017-12-11 16:29:02 -08001477// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1478// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001479//
1480// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001481func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1482 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001483 set := make(map[string]bool)
1484
Colin Cross068e0fe2016-12-13 15:23:47 -08001485 for _, s := range srcFiles {
1486 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001487 if _, found := set[m]; found {
1488 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1489 } else {
1490 set[m] = true
1491 deps = append(deps, m)
1492 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001493 }
1494 }
1495
1496 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1497}
1498
Colin Cross366938f2017-12-11 16:29:02 -08001499// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1500// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001501//
1502// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001503func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1504 if s != nil {
1505 if m := SrcIsModule(*s); m != "" {
1506 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1507 }
1508 }
1509}
1510
Colin Cross068e0fe2016-12-13 15:23:47 -08001511type SourceFileProducer interface {
1512 Srcs() Paths
1513}
1514
Colin Crossfe17f6f2019-03-28 19:30:56 -07001515type HostToolProvider interface {
1516 HostToolPath() OptionalPath
1517}
1518
Colin Cross27b922f2019-03-04 22:35:41 -08001519// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1520// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001521//
1522// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001523func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Cross8a497952019-03-05 22:25:09 -08001524 return PathsForModuleSrcExcludes(ctx, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001525}
1526
Colin Cross2fafa3e2019-03-05 12:39:51 -08001527// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1528// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001529//
1530// Deprecated: use PathForModuleSrc instead.
Colin Cross2fafa3e2019-03-05 12:39:51 -08001531func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
Colin Cross8a497952019-03-05 22:25:09 -08001532 return PathForModuleSrc(ctx, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001533}
1534
1535// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1536// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1537// dependency resolution.
1538func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1539 if srcFile != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001540 return OptionalPathForPath(PathForModuleSrc(ctx, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001541 }
1542 return OptionalPath{}
1543}
1544
Nan Zhang6d34b302017-02-04 17:47:46 -08001545func (ctx *androidModuleContext) RequiredModuleNames() []string {
1546 return ctx.module.base().commonProperties.Required
1547}
1548
Sasha Smundakb6d23052019-04-01 18:37:36 -07001549func (ctx *androidModuleContext) HostRequiredModuleNames() []string {
1550 return ctx.module.base().commonProperties.Host_required
1551}
1552
1553func (ctx *androidModuleContext) TargetRequiredModuleNames() []string {
1554 return ctx.module.base().commonProperties.Target_required
1555}
1556
Colin Cross7f19f372016-11-01 11:10:25 -07001557func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1558 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001559 if err != nil {
1560 ctx.ModuleErrorf("glob: %s", err.Error())
1561 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001562 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001563}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001564
Nan Zhang581fd212018-01-10 16:06:12 -08001565func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001566 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001567 if err != nil {
1568 ctx.ModuleErrorf("glob: %s", err.Error())
1569 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001570 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001571}
1572
Colin Cross463a90e2015-06-17 14:20:06 -07001573func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001574 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001575}
1576
Colin Cross0875c522017-11-28 17:34:01 -08001577func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001578 return &buildTargetSingleton{}
1579}
1580
Colin Cross87d8b562017-04-25 10:01:55 -07001581func parentDir(dir string) string {
1582 dir, _ = filepath.Split(dir)
1583 return filepath.Clean(dir)
1584}
1585
Colin Cross1f8c52b2015-06-16 16:38:17 -07001586type buildTargetSingleton struct{}
1587
Colin Cross0875c522017-11-28 17:34:01 -08001588func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1589 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001590
Colin Cross0875c522017-11-28 17:34:01 -08001591 mmTarget := func(dir string) WritablePath {
1592 return PathForPhony(ctx,
1593 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001594 }
1595
Colin Cross0875c522017-11-28 17:34:01 -08001596 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001597
Colin Cross0875c522017-11-28 17:34:01 -08001598 ctx.VisitAllModules(func(module Module) {
1599 blueprintDir := module.base().blueprintDir
1600 installTarget := module.base().installTarget
1601 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001602
Colin Cross0875c522017-11-28 17:34:01 -08001603 if checkbuildTarget != nil {
1604 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1605 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1606 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001607
Colin Cross0875c522017-11-28 17:34:01 -08001608 if installTarget != nil {
1609 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001610 }
1611 })
1612
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001613 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001614 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001615 suffix = "-soong"
1616 }
1617
Colin Cross1f8c52b2015-06-16 16:38:17 -07001618 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001619 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001620 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001621 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001622 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001623 })
1624
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001625 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001626 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001627 return
1628 }
1629
Colin Cross87d8b562017-04-25 10:01:55 -07001630 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001631 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001632 for _, dir := range dirs {
1633 dir := parentDir(dir)
1634 for dir != "." && dir != "/" {
1635 if _, exists := modulesInDir[dir]; exists {
1636 break
1637 }
1638 modulesInDir[dir] = nil
1639 dir = parentDir(dir)
1640 }
1641 }
1642
1643 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001644 for _, dir := range dirs {
1645 p := parentDir(dir)
1646 if p != "." && p != "/" {
1647 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1648 }
1649 }
1650
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001651 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1652 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1653 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001654 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001655 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001656 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001657 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001658 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001659 // HACK: checkbuild should be an optional build, but force it
1660 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001661 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001662 })
1663 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001664
1665 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1666 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001667 ctx.VisitAllModules(func(module Module) {
1668 if module.Enabled() {
1669 os := module.Target().Os
1670 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001671 }
1672 })
1673
Colin Cross0875c522017-11-28 17:34:01 -08001674 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001675 for os, deps := range osDeps {
1676 var className string
1677
1678 switch os.Class {
1679 case Host:
1680 className = "host"
1681 case HostCross:
1682 className = "host-cross"
1683 case Device:
1684 className = "target"
1685 default:
1686 continue
1687 }
1688
Colin Cross0875c522017-11-28 17:34:01 -08001689 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001690 osClass[className] = append(osClass[className], name)
1691
Colin Cross0875c522017-11-28 17:34:01 -08001692 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001693 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001694 Output: name,
1695 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001696 })
1697 }
1698
1699 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001700 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001701 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001702 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001703 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001704 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001705 })
1706 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001707}
Colin Crossd779da42015-12-17 18:00:23 -08001708
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001709// Collect information for opening IDE project files in java/jdeps.go.
1710type IDEInfo interface {
1711 IDEInfo(ideInfo *IdeInfo)
1712 BaseModuleName() string
1713}
1714
1715// Extract the base module name from the Import name.
1716// Often the Import name has a prefix "prebuilt_".
1717// Remove the prefix explicitly if needed
1718// until we find a better solution to get the Import name.
1719type IDECustomizedModuleName interface {
1720 IDECustomizedModuleName() string
1721}
1722
1723type IdeInfo struct {
1724 Deps []string `json:"dependencies,omitempty"`
1725 Srcs []string `json:"srcs,omitempty"`
1726 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1727 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1728 Jars []string `json:"jars,omitempty"`
1729 Classes []string `json:"class,omitempty"`
1730 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001731 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001732}