blob: e3c37bb2ea25391ca29582921230d617781bd81e [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 Crossf6566ed2015-03-24 11:13:38 -070059type androidBaseContext 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 Crossf6566ed2015-03-24 11:13:38 -070083 androidBaseContext
84}
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 Crossf6566ed2015-03-24 11:13:38 -0700111 androidBaseContext
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
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700293 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800294 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700295
Steven Moreland57a23d22018-04-04 15:42:19 -0700296 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800297 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700298
Chris Wolfe998306e2016-08-15 14:47:23 -0400299 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700300 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400301
Sasha Smundakb6d23052019-04-01 18:37:36 -0700302 // names of other modules to install on host if this module is installed
303 Host_required []string `android:"arch_variant"`
304
305 // names of other modules to install on target if this module is installed
306 Target_required []string `android:"arch_variant"`
307
Colin Cross5aac3622017-08-31 15:07:09 -0700308 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800309 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700310
Dan Willemsen569edc52018-11-19 09:33:29 -0800311 Dist struct {
312 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
313 // command line and any of these targets are also on the command line, or otherwise
314 // built
315 Targets []string `android:"arch_variant"`
316
317 // The name of the output artifact. This defaults to the basename of the output of
318 // the module.
319 Dest *string `android:"arch_variant"`
320
321 // The directory within the dist directory to store the artifact. Defaults to the
322 // top level directory ("").
323 Dir *string `android:"arch_variant"`
324
325 // A suffix to add to the artifact file name (before any extension).
326 Suffix *string `android:"arch_variant"`
327 } `android:"arch_variant"`
328
Colin Crossa1ad8d12016-06-01 17:09:44 -0700329 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700330 CompileTarget Target `blueprint:"mutated"`
331 CompileMultiTargets []Target `blueprint:"mutated"`
332 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800333
334 // Set by InitAndroidModule
335 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700336 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700337
338 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800339
340 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800341}
342
343type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800344 // If set to true, build a variant of the module for the host. Defaults to false.
345 Host_supported *bool
346
347 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700348 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800349}
350
Colin Crossc472d572015-03-17 15:06:21 -0700351type Multilib string
352
353const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800354 MultilibBoth Multilib = "both"
355 MultilibFirst Multilib = "first"
356 MultilibCommon Multilib = "common"
357 MultilibCommonFirst Multilib = "common_first"
358 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700359)
360
Colin Crossa1ad8d12016-06-01 17:09:44 -0700361type HostOrDeviceSupported int
362
363const (
364 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700365
366 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700367 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700368
369 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700370 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700371
372 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700373 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700374
375 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700376 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700377
378 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700379 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700380
381 // Nothing is supported. This is not exposed to the user, but used to mark a
382 // host only module as unsupported when the module type is not supported on
383 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700384 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700385)
386
Jiyong Park2db76922017-11-08 16:03:48 +0900387type moduleKind int
388
389const (
390 platformModule moduleKind = iota
391 deviceSpecificModule
392 socSpecificModule
393 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100394 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900395)
396
397func (k moduleKind) String() string {
398 switch k {
399 case platformModule:
400 return "platform"
401 case deviceSpecificModule:
402 return "device-specific"
403 case socSpecificModule:
404 return "soc-specific"
405 case productSpecificModule:
406 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100407 case productServicesSpecificModule:
408 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900409 default:
410 panic(fmt.Errorf("unknown module kind %d", k))
411 }
412}
413
Colin Cross36242852017-06-23 15:06:31 -0700414func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800415 base := m.base()
416 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700417
Colin Cross36242852017-06-23 15:06:31 -0700418 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700419 &base.nameProperties,
420 &base.commonProperties,
421 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700422 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700423 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700424}
425
Colin Cross36242852017-06-23 15:06:31 -0700426func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
427 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700428
429 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800430 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700431 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700432 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700433 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800434
Dan Willemsen218f6562015-07-08 18:13:11 -0700435 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700436 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700437 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800438 }
439
Colin Cross36242852017-06-23 15:06:31 -0700440 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800441}
442
Colin Crossee0bc3b2018-10-02 22:01:37 -0700443func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
444 InitAndroidArchModule(m, hod, defaultMultilib)
445 m.base().commonProperties.UseTargetVariants = false
446}
447
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800448// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800449// modules. It should be included as an anonymous field in every module
450// struct definition. InitAndroidModule should then be called from the module's
451// factory function, and the return values from InitAndroidModule should be
452// returned from the factory function.
453//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800454// The ModuleBase type is responsible for implementing the GenerateBuildActions
455// method to support the blueprint.Module interface. This method will then call
456// the module's GenerateAndroidBuildActions method once for each build variant
457// that is to be built. GenerateAndroidBuildActions is passed a
458// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800459// AndroidModuleContext exposes extra functionality specific to the Android build
460// system including details about the particular build variant that is to be
461// generated.
462//
463// For example:
464//
465// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800466// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800467// )
468//
469// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800470// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800471// properties struct {
472// MyProperty string
473// }
474// }
475//
Colin Cross36242852017-06-23 15:06:31 -0700476// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800477// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700478// m.AddProperties(&m.properties)
479// android.InitAndroidModule(m)
480// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800481// }
482//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800483// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800484// // Get the CPU architecture for the current build variant.
485// variantArch := ctx.Arch()
486//
487// // ...
488// }
Colin Cross635c3b02016-05-18 15:37:25 -0700489type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800490 // Putting the curiously recurring thing pointing to the thing that contains
491 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700492 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700493 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800494
Colin Crossfc754582016-05-17 16:34:16 -0700495 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800496 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700497 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800498 hostAndDeviceProperties hostAndDeviceProperties
499 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700500 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700501 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800502
503 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700504 installFiles Paths
505 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900506 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700507
508 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
509 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800510 installTarget WritablePath
511 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700512 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700513
Colin Cross178a5092016-09-13 13:42:32 -0700514 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700515
516 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700517
518 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700519 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800520 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800521 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700522
523 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700524}
525
Colin Cross5f692ec2019-02-01 16:53:07 -0800526func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
527
Colin Cross36242852017-06-23 15:06:31 -0700528func (a *ModuleBase) AddProperties(props ...interface{}) {
529 a.registerProps = append(a.registerProps, props...)
530}
531
532func (a *ModuleBase) GetProperties() []interface{} {
533 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800534}
535
Colin Crossae887032017-10-23 17:16:14 -0700536func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700537 return a.buildParams
538}
539
Colin Cross4c83e5c2019-02-25 14:54:28 -0800540func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
541 return a.ruleParams
542}
543
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800544func (a *ModuleBase) VariablesForTests() map[string]string {
545 return a.variables
546}
547
Colin Crossa9d8bee2018-10-02 13:59:46 -0700548func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
549 a.prefer32 = prefer32
550}
551
Colin Crossce75d2c2016-10-06 16:12:58 -0700552// Name returns the name of the module. It may be overridden by individual module types, for
553// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700554func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800555 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700556}
557
Colin Crossce75d2c2016-10-06 16:12:58 -0700558// BaseModuleName returns the name of the module as specified in the blueprints file.
559func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800560 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700561}
562
Colin Cross635c3b02016-05-18 15:37:25 -0700563func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800564 return a
565}
566
Colin Crossee0bc3b2018-10-02 22:01:37 -0700567func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700568 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700569 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700570 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700571}
572
Colin Crossa1ad8d12016-06-01 17:09:44 -0700573func (a *ModuleBase) Target() Target {
574 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800575}
576
Colin Cross8b74d172016-09-13 09:59:14 -0700577func (a *ModuleBase) TargetPrimary() bool {
578 return a.commonProperties.CompilePrimary
579}
580
Colin Crossee0bc3b2018-10-02 22:01:37 -0700581func (a *ModuleBase) MultiTargets() []Target {
582 return a.commonProperties.CompileMultiTargets
583}
584
Colin Crossa1ad8d12016-06-01 17:09:44 -0700585func (a *ModuleBase) Os() OsType {
586 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800587}
588
Colin Cross635c3b02016-05-18 15:37:25 -0700589func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700590 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800591}
592
Colin Cross635c3b02016-05-18 15:37:25 -0700593func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700594 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800595}
596
Dan Willemsen0b24c742016-10-04 15:13:37 -0700597func (a *ModuleBase) ArchSpecific() bool {
598 return a.commonProperties.ArchSpecific
599}
600
Colin Crossa1ad8d12016-06-01 17:09:44 -0700601func (a *ModuleBase) OsClassSupported() []OsClass {
602 switch a.commonProperties.HostOrDeviceSupported {
603 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700604 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700605 case HostSupportedNoCross:
606 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700607 case DeviceSupported:
608 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700609 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700610 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700611 if Bool(a.hostAndDeviceProperties.Host_supported) ||
612 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
613 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700614 supported = append(supported, Host, HostCross)
615 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700616 if a.hostAndDeviceProperties.Device_supported == nil ||
617 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700618 supported = append(supported, Device)
619 }
620 return supported
621 default:
622 return nil
623 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800624}
625
Colin Cross635c3b02016-05-18 15:37:25 -0700626func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800627 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
628 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700629 (a.hostAndDeviceProperties.Device_supported == nil ||
630 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800631}
632
Jiyong Parkc678ad32018-04-10 13:07:10 +0900633func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100634 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900635}
636
637func (a *ModuleBase) DeviceSpecific() bool {
638 return Bool(a.commonProperties.Device_specific)
639}
640
641func (a *ModuleBase) SocSpecific() bool {
642 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
643}
644
645func (a *ModuleBase) ProductSpecific() bool {
646 return Bool(a.commonProperties.Product_specific)
647}
648
Dario Frenifd05a742018-05-29 13:28:54 +0100649func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100650 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100651}
652
Colin Cross635c3b02016-05-18 15:37:25 -0700653func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800654 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800655 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800656 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800657 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800658}
659
Colin Crossce75d2c2016-10-06 16:12:58 -0700660func (a *ModuleBase) SkipInstall() {
661 a.commonProperties.SkipInstall = true
662}
663
Jiyong Park374510b2018-03-19 18:23:01 +0900664func (a *ModuleBase) ExportedToMake() bool {
665 return a.commonProperties.NamespaceExportedToMake
666}
667
Colin Cross635c3b02016-05-18 15:37:25 -0700668func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700669 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800670
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700671 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700672 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800673 ctx.VisitDepsDepthFirstIf(isFileInstaller,
674 func(m blueprint.Module) {
675 fileInstaller := m.(fileInstaller)
676 files := fileInstaller.filesToInstall()
677 result = append(result, files...)
678 })
679
680 return result
681}
682
Colin Cross635c3b02016-05-18 15:37:25 -0700683func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800684 return a.installFiles
685}
686
Colin Cross635c3b02016-05-18 15:37:25 -0700687func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800688 return p.noAddressSanitizer
689}
690
Colin Cross635c3b02016-05-18 15:37:25 -0700691func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800692 return false
693}
694
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700695func (p *ModuleBase) InstallInSanitizerDir() bool {
696 return false
697}
698
Jiyong Parkf9332f12018-02-01 00:54:12 +0900699func (p *ModuleBase) InstallInRecovery() bool {
700 return Bool(p.commonProperties.Recovery)
701}
702
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900703func (a *ModuleBase) Owner() string {
704 return String(a.commonProperties.Owner)
705}
706
Jiyong Park52818fc2019-03-18 12:01:38 +0900707func (a *ModuleBase) NoticeFile() OptionalPath {
708 return a.noticeFile
709}
710
Colin Cross0875c522017-11-28 17:34:01 -0800711func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700712 allInstalledFiles := Paths{}
713 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800714 ctx.VisitAllModuleVariants(func(module Module) {
715 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700716 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
717 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800718 })
719
Colin Cross0875c522017-11-28 17:34:01 -0800720 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700721
Jeff Gaston088e29e2017-11-29 16:47:17 -0800722 namespacePrefix := ctx.Namespace().(*Namespace).id
723 if namespacePrefix != "" {
724 namespacePrefix = namespacePrefix + "-"
725 }
726
Colin Cross3f40fa42015-01-30 17:27:36 -0800727 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800728 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800729 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700730 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800731 Output: name,
732 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800733 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700734 })
735 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700736 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700737 }
738
739 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800740 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800741 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700742 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800743 Output: name,
744 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700745 })
746 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700747 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700748 }
749
750 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800751 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800752 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800753 suffix = "-soong"
754 }
755
Jeff Gaston088e29e2017-11-29 16:47:17 -0800756 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800757 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700758 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800759 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700760 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800761 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700762
763 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800764 }
765}
766
Jiyong Park2db76922017-11-08 16:03:48 +0900767func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
768 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
769 var deviceSpecific = Bool(a.commonProperties.Device_specific)
770 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100771 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900772
Dario Frenifd05a742018-05-29 13:28:54 +0100773 msg := "conflicting value set here"
774 if socSpecific && deviceSpecific {
775 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900776 if Bool(a.commonProperties.Vendor) {
777 ctx.PropertyErrorf("vendor", msg)
778 }
779 if Bool(a.commonProperties.Proprietary) {
780 ctx.PropertyErrorf("proprietary", msg)
781 }
782 if Bool(a.commonProperties.Soc_specific) {
783 ctx.PropertyErrorf("soc_specific", msg)
784 }
785 }
786
Dario Frenifd05a742018-05-29 13:28:54 +0100787 if productSpecific && productServicesSpecific {
788 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
789 ctx.PropertyErrorf("product_services_specific", msg)
790 }
791
792 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
793 if productSpecific {
794 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
795 } else {
796 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
797 }
798 if deviceSpecific {
799 ctx.PropertyErrorf("device_specific", msg)
800 } else {
801 if Bool(a.commonProperties.Vendor) {
802 ctx.PropertyErrorf("vendor", msg)
803 }
804 if Bool(a.commonProperties.Proprietary) {
805 ctx.PropertyErrorf("proprietary", msg)
806 }
807 if Bool(a.commonProperties.Soc_specific) {
808 ctx.PropertyErrorf("soc_specific", msg)
809 }
810 }
811 }
812
Jiyong Park2db76922017-11-08 16:03:48 +0900813 if productSpecific {
814 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100815 } else if productServicesSpecific {
816 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900817 } else if deviceSpecific {
818 return deviceSpecificModule
819 } else if socSpecific {
820 return socSpecificModule
821 } else {
822 return platformModule
823 }
824}
825
Colin Cross635c3b02016-05-18 15:37:25 -0700826func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700827 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700828 target: a.commonProperties.CompileTarget,
829 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700830 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900831 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700832 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800833 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800834}
835
Colin Cross0875c522017-11-28 17:34:01 -0800836func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
837 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700838 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800839 ModuleContext: blueprintCtx,
840 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
841 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700842 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800843 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800844 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800845 }
846
Colin Cross4c83e5c2019-02-25 14:54:28 -0800847 if ctx.config.captureBuild {
848 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
849 }
850
Colin Cross67a5c132017-05-09 13:45:28 -0700851 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
852 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800853 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
854 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700855 }
Colin Cross0875c522017-11-28 17:34:01 -0800856 if !ctx.PrimaryArch() {
857 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700858 }
859
860 ctx.Variable(pctx, "moduleDesc", desc)
861
862 s := ""
863 if len(suffix) > 0 {
864 s = " [" + strings.Join(suffix, " ") + "]"
865 }
866 ctx.Variable(pctx, "moduleDescSuffix", s)
867
Dan Willemsen569edc52018-11-19 09:33:29 -0800868 // Some common property checks for properties that will be used later in androidmk.go
869 if a.commonProperties.Dist.Dest != nil {
870 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
871 if err != nil {
872 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
873 }
874 }
875 if a.commonProperties.Dist.Dir != nil {
876 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
877 if err != nil {
878 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
879 }
880 }
881 if a.commonProperties.Dist.Suffix != nil {
882 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
883 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
884 }
885 }
886
Colin Cross9b1d13d2016-09-19 15:18:11 -0700887 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800888 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700889 if ctx.Failed() {
890 return
891 }
892
Colin Cross0875c522017-11-28 17:34:01 -0800893 a.installFiles = append(a.installFiles, ctx.installFiles...)
894 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800895
Jiyong Park52818fc2019-03-18 12:01:38 +0900896 notice := proptools.StringDefault(a.commonProperties.Notice, "NOTICE")
897 if m := SrcIsModule(notice); m != "" {
898 a.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
899 } else {
900 noticePath := filepath.Join(ctx.ModuleDir(), notice)
901 a.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800902 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800903 }
904
Colin Cross9b1d13d2016-09-19 15:18:11 -0700905 if a == ctx.FinalModule().(Module).base() {
906 a.generateModuleTarget(ctx)
907 if ctx.Failed() {
908 return
909 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800910 }
Colin Crosscec81712017-07-13 14:43:27 -0700911
Colin Cross0875c522017-11-28 17:34:01 -0800912 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800913 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800914 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800915}
916
Colin Crossf6566ed2015-03-24 11:13:38 -0700917type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700918 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700919 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700920 targetPrimary bool
921 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900922 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700923 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700924}
925
Colin Cross3f40fa42015-01-30 17:27:36 -0800926type androidModuleContext struct {
927 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700928 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700929 installDeps Paths
930 installFiles Paths
931 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800932 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700933 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700934
935 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700936 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800937 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800938 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800939}
940
Colin Cross67a5c132017-05-09 13:45:28 -0700941func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800942 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700943 Rule: ErrorRule,
944 Description: desc,
945 Outputs: outputs,
946 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800947 Args: map[string]string{
948 "error": err.Error(),
949 },
950 })
951 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800952}
953
Colin Crossaabf6792017-11-29 00:27:14 -0800954func (a *androidModuleContext) Config() Config {
955 return a.ModuleContext.Config().(Config)
956}
957
Colin Cross0875c522017-11-28 17:34:01 -0800958func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700959 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800960}
961
Colin Cross0875c522017-11-28 17:34:01 -0800962func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700963 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700964 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800965 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800966 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700967 Outputs: params.Outputs.Strings(),
968 ImplicitOutputs: params.ImplicitOutputs.Strings(),
969 Inputs: params.Inputs.Strings(),
970 Implicits: params.Implicits.Strings(),
971 OrderOnly: params.OrderOnly.Strings(),
972 Args: params.Args,
973 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700974 }
975
Colin Cross33bfb0a2016-11-21 17:23:08 -0800976 if params.Depfile != nil {
977 bparams.Depfile = params.Depfile.String()
978 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700979 if params.Output != nil {
980 bparams.Outputs = append(bparams.Outputs, params.Output.String())
981 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700982 if params.ImplicitOutput != nil {
983 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
984 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700985 if params.Input != nil {
986 bparams.Inputs = append(bparams.Inputs, params.Input.String())
987 }
988 if params.Implicit != nil {
989 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
990 }
991
Colin Cross0b9f31f2019-02-28 11:00:01 -0800992 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
993 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
994 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
995 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
996 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
997 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -0700998
Colin Cross0875c522017-11-28 17:34:01 -0800999 return bparams
1000}
1001
1002func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001003 if a.config.captureBuild {
1004 a.variables[name] = value
1005 }
1006
Colin Cross0875c522017-11-28 17:34:01 -08001007 a.ModuleContext.Variable(pctx.PackageContext, name, value)
1008}
1009
1010func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
1011 argNames ...string) blueprint.Rule {
1012
Colin Cross4c83e5c2019-02-25 14:54:28 -08001013 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
1014
1015 if a.config.captureBuild {
1016 a.ruleParams[rule] = params
1017 }
1018
1019 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001020}
1021
1022func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
1023 if a.config.captureBuild {
1024 a.buildParams = append(a.buildParams, params)
1025 }
1026
1027 bparams := convertBuildParams(params)
1028
1029 if bparams.Description != "" {
1030 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1031 }
1032
Colin Cross6ff51382015-12-17 16:39:19 -08001033 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -07001034 a.ninjaError(bparams.Description, bparams.Outputs,
1035 fmt.Errorf("module %s missing dependencies: %s\n",
1036 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001037 return
1038 }
1039
Colin Cross0875c522017-11-28 17:34:01 -08001040 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001041}
1042
Colin Cross6ff51382015-12-17 16:39:19 -08001043func (a *androidModuleContext) GetMissingDependencies() []string {
1044 return a.missingDeps
1045}
1046
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001047func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1048 if deps != nil {
1049 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001050 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001051 }
1052}
1053
Colin Crossd11fcda2017-10-23 17:59:01 -07001054func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1055 aModule, _ := module.(Module)
1056 if aModule == nil {
1057 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1058 return nil
1059 }
1060
1061 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001062 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001063 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1064 } else {
1065 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1066 }
1067 return nil
1068 }
1069
1070 return aModule
1071}
1072
Jiyong Parkf2976302019-04-17 21:47:37 +09001073func (a *androidModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
1074 type dep struct {
1075 mod blueprint.Module
1076 tag blueprint.DependencyTag
1077 }
1078 var deps []dep
1079 a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1080 if aModule, _ := m.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
1081 returnedTag := a.ModuleContext.OtherModuleDependencyTag(aModule)
1082 if tag == nil || returnedTag == tag {
1083 deps = append(deps, dep{aModule, returnedTag})
1084 }
1085 }
1086 })
1087 if len(deps) == 1 {
1088 return deps[0].mod, deps[0].tag
1089 } else if len(deps) >= 2 {
1090 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
1091 name, a.ModuleName()))
1092 } else {
1093 return nil, nil
1094 }
1095}
1096
Colin Cross0ef08162019-05-01 15:50:51 -07001097func (a *androidModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
1098 var deps []Module
1099 a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1100 if aModule, _ := m.(Module); aModule != nil {
1101 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1102 deps = append(deps, aModule)
1103 }
1104 }
1105 })
1106 return deps
1107}
1108
Jiyong Parkf2976302019-04-17 21:47:37 +09001109func (a *androidModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1110 m, _ := a.getDirectDepInternal(name, tag)
1111 return m
1112}
1113
1114func (a *androidModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1115 return a.getDirectDepInternal(name, nil)
1116}
1117
Colin Cross35143d02017-11-16 00:11:20 -08001118func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1119 a.ModuleContext.VisitDirectDeps(visit)
1120}
1121
Colin Crossd11fcda2017-10-23 17:59:01 -07001122func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1123 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1124 if aModule := a.validateAndroidModule(module); aModule != nil {
1125 visit(aModule)
1126 }
1127 })
1128}
1129
Colin Crossee6143c2017-12-30 17:54:27 -08001130func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1131 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1132 if aModule := a.validateAndroidModule(module); aModule != nil {
1133 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1134 visit(aModule)
1135 }
1136 }
1137 })
1138}
1139
Colin Crossd11fcda2017-10-23 17:59:01 -07001140func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1141 a.ModuleContext.VisitDirectDepsIf(
1142 // pred
1143 func(module blueprint.Module) bool {
1144 if aModule := a.validateAndroidModule(module); aModule != nil {
1145 return pred(aModule)
1146 } else {
1147 return false
1148 }
1149 },
1150 // visit
1151 func(module blueprint.Module) {
1152 visit(module.(Module))
1153 })
1154}
1155
1156func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1157 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1158 if aModule := a.validateAndroidModule(module); aModule != nil {
1159 visit(aModule)
1160 }
1161 })
1162}
1163
1164func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1165 a.ModuleContext.VisitDepsDepthFirstIf(
1166 // pred
1167 func(module blueprint.Module) bool {
1168 if aModule := a.validateAndroidModule(module); aModule != nil {
1169 return pred(aModule)
1170 } else {
1171 return false
1172 }
1173 },
1174 // visit
1175 func(module blueprint.Module) {
1176 visit(module.(Module))
1177 })
1178}
1179
Alex Light778127a2019-02-27 14:19:50 -08001180func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1181 a.ModuleContext.WalkDeps(visit)
1182}
1183
Colin Crossd11fcda2017-10-23 17:59:01 -07001184func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1185 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1186 childAndroidModule := a.validateAndroidModule(child)
1187 parentAndroidModule := a.validateAndroidModule(parent)
1188 if childAndroidModule != nil && parentAndroidModule != nil {
1189 return visit(childAndroidModule, parentAndroidModule)
1190 } else {
1191 return false
1192 }
1193 })
1194}
1195
Colin Cross0875c522017-11-28 17:34:01 -08001196func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1197 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1198 visit(module.(Module))
1199 })
1200}
1201
1202func (a *androidModuleContext) PrimaryModule() Module {
1203 return a.ModuleContext.PrimaryModule().(Module)
1204}
1205
1206func (a *androidModuleContext) FinalModule() Module {
1207 return a.ModuleContext.FinalModule().(Module)
1208}
1209
Colin Crossa1ad8d12016-06-01 17:09:44 -07001210func (a *androidBaseContextImpl) Target() Target {
1211 return a.target
1212}
1213
Colin Cross8b74d172016-09-13 09:59:14 -07001214func (a *androidBaseContextImpl) TargetPrimary() bool {
1215 return a.targetPrimary
1216}
1217
Colin Crossee0bc3b2018-10-02 22:01:37 -07001218func (a *androidBaseContextImpl) MultiTargets() []Target {
1219 return a.multiTargets
1220}
1221
Colin Crossf6566ed2015-03-24 11:13:38 -07001222func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001223 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001224}
1225
Colin Crossa1ad8d12016-06-01 17:09:44 -07001226func (a *androidBaseContextImpl) Os() OsType {
1227 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001228}
1229
Colin Crossf6566ed2015-03-24 11:13:38 -07001230func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001231 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001232}
1233
1234func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001235 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001236}
1237
Colin Cross0af4b842015-04-30 16:36:18 -07001238func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001239 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001240}
1241
Doug Horn21b94272019-01-16 12:06:11 -08001242func (a *androidBaseContextImpl) Fuchsia() bool {
1243 return a.target.Os == Fuchsia
1244}
1245
Colin Cross3edeee12017-04-04 12:59:48 -07001246func (a *androidBaseContextImpl) Windows() bool {
1247 return a.target.Os == Windows
1248}
1249
Colin Crossf6566ed2015-03-24 11:13:38 -07001250func (a *androidBaseContextImpl) Debug() bool {
1251 return a.debug
1252}
1253
Colin Cross1e7d3702016-08-24 15:25:47 -07001254func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001255 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001256 return true
1257 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001258 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001259}
1260
Colin Cross1332b002015-04-07 17:11:30 -07001261func (a *androidBaseContextImpl) AConfig() Config {
1262 return a.config
1263}
1264
Colin Cross9272ade2016-08-17 15:24:12 -07001265func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1266 return DeviceConfig{a.config.deviceConfig}
1267}
1268
Jiyong Park2db76922017-11-08 16:03:48 +09001269func (a *androidBaseContextImpl) Platform() bool {
1270 return a.kind == platformModule
1271}
1272
1273func (a *androidBaseContextImpl) DeviceSpecific() bool {
1274 return a.kind == deviceSpecificModule
1275}
1276
1277func (a *androidBaseContextImpl) SocSpecific() bool {
1278 return a.kind == socSpecificModule
1279}
1280
1281func (a *androidBaseContextImpl) ProductSpecific() bool {
1282 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001283}
1284
Dario Frenifd05a742018-05-29 13:28:54 +01001285func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1286 return a.kind == productServicesSpecificModule
1287}
1288
Jiyong Park5baac542018-08-28 09:55:37 +09001289// Makes this module a platform module, i.e. not specific to soc, device,
1290// product, or product_services.
1291func (a *ModuleBase) MakeAsPlatform() {
1292 a.commonProperties.Vendor = boolPtr(false)
1293 a.commonProperties.Proprietary = boolPtr(false)
1294 a.commonProperties.Soc_specific = boolPtr(false)
1295 a.commonProperties.Product_specific = boolPtr(false)
1296 a.commonProperties.Product_services_specific = boolPtr(false)
1297}
1298
Colin Cross8d8f8e22016-08-03 11:57:50 -07001299func (a *androidModuleContext) InstallInData() bool {
1300 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001301}
1302
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001303func (a *androidModuleContext) InstallInSanitizerDir() bool {
1304 return a.module.InstallInSanitizerDir()
1305}
1306
Jiyong Parkf9332f12018-02-01 00:54:12 +09001307func (a *androidModuleContext) InstallInRecovery() bool {
1308 return a.module.InstallInRecovery()
1309}
1310
Colin Cross893d8162017-04-26 17:34:03 -07001311func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1312 if a.module.base().commonProperties.SkipInstall {
1313 return true
1314 }
1315
Colin Cross3607f212018-05-07 15:28:05 -07001316 // We'll need a solution for choosing which of modules with the same name in different
1317 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1318 // list of namespaces to install in a Soong-only build.
1319 if !a.module.base().commonProperties.NamespaceExportedToMake {
1320 return true
1321 }
1322
Colin Cross893d8162017-04-26 17:34:03 -07001323 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001324 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001325 return true
1326 }
1327
Colin Cross6510f912017-11-29 00:27:14 -08001328 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001329 return true
1330 }
1331 }
1332
1333 return false
1334}
1335
Colin Cross5c517922017-08-31 12:29:17 -07001336func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001337 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001338 return a.installFile(installPath, name, srcPath, Cp, deps)
1339}
1340
1341func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1342 deps ...Path) OutputPath {
1343 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1344}
1345
1346func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1347 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001348
Dan Willemsen782a2d12015-12-21 14:55:28 -08001349 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001350 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001351
Colin Cross893d8162017-04-26 17:34:03 -07001352 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001353
Dan Willemsen322acaf2016-01-12 23:07:05 -08001354 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001355
Colin Cross89562dc2016-10-03 17:47:19 -07001356 var implicitDeps, orderOnlyDeps Paths
1357
1358 if a.Host() {
1359 // Installed host modules might be used during the build, depend directly on their
1360 // dependencies so their timestamp is updated whenever their dependency is updated
1361 implicitDeps = deps
1362 } else {
1363 orderOnlyDeps = deps
1364 }
1365
Colin Crossae887032017-10-23 17:16:14 -07001366 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001367 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001368 Description: "install " + fullInstallPath.Base(),
1369 Output: fullInstallPath,
1370 Input: srcPath,
1371 Implicits: implicitDeps,
1372 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001373 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001374 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001375
Dan Willemsen322acaf2016-01-12 23:07:05 -08001376 a.installFiles = append(a.installFiles, fullInstallPath)
1377 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001378 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001379 return fullInstallPath
1380}
1381
Colin Cross3854a602016-01-11 12:49:11 -08001382func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1383 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001384 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001385
Colin Cross893d8162017-04-26 17:34:03 -07001386 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001387
Alex Lightfb4353d2019-01-17 13:57:45 -08001388 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1389 if err != nil {
1390 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1391 }
Colin Crossae887032017-10-23 17:16:14 -07001392 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001393 Rule: Symlink,
1394 Description: "install symlink " + fullInstallPath.Base(),
1395 Output: fullInstallPath,
1396 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001397 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001398 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001399 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001400 },
1401 })
Colin Cross3854a602016-01-11 12:49:11 -08001402
Colin Cross12fc4972016-01-11 12:49:11 -08001403 a.installFiles = append(a.installFiles, fullInstallPath)
1404 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1405 }
Colin Cross3854a602016-01-11 12:49:11 -08001406 return fullInstallPath
1407}
1408
Jiyong Parkf1194352019-02-25 11:05:47 +09001409// installPath/name -> absPath where absPath might be a path that is available only at runtime
1410// (e.g. /apex/...)
1411func (a *androidModuleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1412 fullInstallPath := installPath.Join(a, name)
1413 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
1414
1415 if !a.skipInstall(fullInstallPath) {
1416 a.Build(pctx, BuildParams{
1417 Rule: Symlink,
1418 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1419 Output: fullInstallPath,
1420 Default: !a.Config().EmbeddedInMake(),
1421 Args: map[string]string{
1422 "fromPath": absPath,
1423 },
1424 })
1425
1426 a.installFiles = append(a.installFiles, fullInstallPath)
1427 }
1428 return fullInstallPath
1429}
1430
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001431func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001432 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1433}
1434
Colin Cross3f40fa42015-01-30 17:27:36 -08001435type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001436 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001437}
1438
1439func isFileInstaller(m blueprint.Module) bool {
1440 _, ok := m.(fileInstaller)
1441 return ok
1442}
1443
1444func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001445 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001446 return ok
1447}
Colin Crossfce53272015-04-08 11:21:40 -07001448
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001449func findStringInSlice(str string, slice []string) int {
1450 for i, s := range slice {
1451 if s == str {
1452 return i
Colin Crossfce53272015-04-08 11:21:40 -07001453 }
1454 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001455 return -1
1456}
1457
Colin Cross068e0fe2016-12-13 15:23:47 -08001458func SrcIsModule(s string) string {
1459 if len(s) > 1 && s[0] == ':' {
1460 return s[1:]
1461 }
1462 return ""
1463}
1464
1465type sourceDependencyTag struct {
1466 blueprint.BaseDependencyTag
1467}
1468
1469var SourceDepTag sourceDependencyTag
1470
Colin Cross366938f2017-12-11 16:29:02 -08001471// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1472// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001473//
1474// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001475func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1476 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001477 set := make(map[string]bool)
1478
Colin Cross068e0fe2016-12-13 15:23:47 -08001479 for _, s := range srcFiles {
1480 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001481 if _, found := set[m]; found {
1482 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1483 } else {
1484 set[m] = true
1485 deps = append(deps, m)
1486 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001487 }
1488 }
1489
1490 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1491}
1492
Colin Cross366938f2017-12-11 16:29:02 -08001493// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1494// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001495//
1496// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001497func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1498 if s != nil {
1499 if m := SrcIsModule(*s); m != "" {
1500 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1501 }
1502 }
1503}
1504
Colin Cross068e0fe2016-12-13 15:23:47 -08001505type SourceFileProducer interface {
1506 Srcs() Paths
1507}
1508
Colin Crossfe17f6f2019-03-28 19:30:56 -07001509type HostToolProvider interface {
1510 HostToolPath() OptionalPath
1511}
1512
Colin Cross27b922f2019-03-04 22:35:41 -08001513// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1514// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001515//
1516// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001517func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Cross8a497952019-03-05 22:25:09 -08001518 return PathsForModuleSrcExcludes(ctx, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001519}
1520
Colin Cross2fafa3e2019-03-05 12:39:51 -08001521// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1522// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001523//
1524// Deprecated: use PathForModuleSrc instead.
Colin Cross2fafa3e2019-03-05 12:39:51 -08001525func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
Colin Cross8a497952019-03-05 22:25:09 -08001526 return PathForModuleSrc(ctx, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001527}
1528
1529// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1530// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1531// dependency resolution.
1532func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1533 if srcFile != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001534 return OptionalPathForPath(PathForModuleSrc(ctx, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001535 }
1536 return OptionalPath{}
1537}
1538
Nan Zhang6d34b302017-02-04 17:47:46 -08001539func (ctx *androidModuleContext) RequiredModuleNames() []string {
1540 return ctx.module.base().commonProperties.Required
1541}
1542
Sasha Smundakb6d23052019-04-01 18:37:36 -07001543func (ctx *androidModuleContext) HostRequiredModuleNames() []string {
1544 return ctx.module.base().commonProperties.Host_required
1545}
1546
1547func (ctx *androidModuleContext) TargetRequiredModuleNames() []string {
1548 return ctx.module.base().commonProperties.Target_required
1549}
1550
Colin Cross7f19f372016-11-01 11:10:25 -07001551func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1552 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001553 if err != nil {
1554 ctx.ModuleErrorf("glob: %s", err.Error())
1555 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001556 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001557}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001558
Nan Zhang581fd212018-01-10 16:06:12 -08001559func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001560 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001561 if err != nil {
1562 ctx.ModuleErrorf("glob: %s", err.Error())
1563 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001564 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001565}
1566
Colin Cross463a90e2015-06-17 14:20:06 -07001567func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001568 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001569}
1570
Colin Cross0875c522017-11-28 17:34:01 -08001571func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001572 return &buildTargetSingleton{}
1573}
1574
Colin Cross87d8b562017-04-25 10:01:55 -07001575func parentDir(dir string) string {
1576 dir, _ = filepath.Split(dir)
1577 return filepath.Clean(dir)
1578}
1579
Colin Cross1f8c52b2015-06-16 16:38:17 -07001580type buildTargetSingleton struct{}
1581
Colin Cross0875c522017-11-28 17:34:01 -08001582func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1583 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001584
Colin Cross0875c522017-11-28 17:34:01 -08001585 mmTarget := func(dir string) WritablePath {
1586 return PathForPhony(ctx,
1587 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001588 }
1589
Colin Cross0875c522017-11-28 17:34:01 -08001590 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001591
Colin Cross0875c522017-11-28 17:34:01 -08001592 ctx.VisitAllModules(func(module Module) {
1593 blueprintDir := module.base().blueprintDir
1594 installTarget := module.base().installTarget
1595 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001596
Colin Cross0875c522017-11-28 17:34:01 -08001597 if checkbuildTarget != nil {
1598 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1599 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1600 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001601
Colin Cross0875c522017-11-28 17:34:01 -08001602 if installTarget != nil {
1603 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001604 }
1605 })
1606
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001607 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001608 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001609 suffix = "-soong"
1610 }
1611
Colin Cross1f8c52b2015-06-16 16:38:17 -07001612 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001613 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001614 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001615 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001616 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001617 })
1618
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001619 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001620 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001621 return
1622 }
1623
Colin Cross0875c522017-11-28 17:34:01 -08001624 sortedKeys := func(m map[string]Paths) []string {
1625 s := make([]string, 0, len(m))
1626 for k := range m {
1627 s = append(s, k)
1628 }
1629 sort.Strings(s)
1630 return s
1631 }
1632
Colin Cross87d8b562017-04-25 10:01:55 -07001633 // Ensure ancestor directories are in modulesInDir
1634 dirs := sortedKeys(modulesInDir)
1635 for _, dir := range dirs {
1636 dir := parentDir(dir)
1637 for dir != "." && dir != "/" {
1638 if _, exists := modulesInDir[dir]; exists {
1639 break
1640 }
1641 modulesInDir[dir] = nil
1642 dir = parentDir(dir)
1643 }
1644 }
1645
1646 // Make directories build their direct subdirectories
1647 dirs = sortedKeys(modulesInDir)
1648 for _, dir := range dirs {
1649 p := parentDir(dir)
1650 if p != "." && p != "/" {
1651 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1652 }
1653 }
1654
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001655 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1656 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1657 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001658 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001659 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001660 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001661 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001662 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001663 // HACK: checkbuild should be an optional build, but force it
1664 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001665 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001666 })
1667 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001668
1669 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1670 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001671 ctx.VisitAllModules(func(module Module) {
1672 if module.Enabled() {
1673 os := module.Target().Os
1674 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001675 }
1676 })
1677
Colin Cross0875c522017-11-28 17:34:01 -08001678 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001679 for os, deps := range osDeps {
1680 var className string
1681
1682 switch os.Class {
1683 case Host:
1684 className = "host"
1685 case HostCross:
1686 className = "host-cross"
1687 case Device:
1688 className = "target"
1689 default:
1690 continue
1691 }
1692
Colin Cross0875c522017-11-28 17:34:01 -08001693 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001694 osClass[className] = append(osClass[className], name)
1695
Colin Cross0875c522017-11-28 17:34:01 -08001696 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001697 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001698 Output: name,
1699 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001700 })
1701 }
1702
1703 // Wrap those into host|host-cross|target phony rules
1704 osClasses := sortedKeys(osClass)
1705 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001706 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001707 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001708 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001709 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001710 })
1711 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001712}
Colin Crossd779da42015-12-17 18:00:23 -08001713
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001714// Collect information for opening IDE project files in java/jdeps.go.
1715type IDEInfo interface {
1716 IDEInfo(ideInfo *IdeInfo)
1717 BaseModuleName() string
1718}
1719
1720// Extract the base module name from the Import name.
1721// Often the Import name has a prefix "prebuilt_".
1722// Remove the prefix explicitly if needed
1723// until we find a better solution to get the Import name.
1724type IDECustomizedModuleName interface {
1725 IDECustomizedModuleName() string
1726}
1727
1728type IdeInfo struct {
1729 Deps []string `json:"dependencies,omitempty"`
1730 Srcs []string `json:"srcs,omitempty"`
1731 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1732 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1733 Jars []string `json:"jars,omitempty"`
1734 Classes []string `json:"class,omitempty"`
1735 Installed_paths []string `json:"installed,omitempty"`
1736}