blob: b12f0c1070d76e3b0a05d3a1f1e7e44fb3946a3e [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
146 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
Colin Cross7d5136f2015-05-11 13:39:40 -0700213 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800214 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
215 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
216 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700217 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700218
219 Target struct {
220 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700221 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700222 }
223 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700224 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700225 }
226 }
227
Colin Crossee0bc3b2018-10-02 22:01:37 -0700228 UseTargetVariants bool `blueprint:"mutated"`
229 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800230
Dan Willemsen782a2d12015-12-21 14:55:28 -0800231 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700232 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800233
Colin Cross55708f32017-03-20 13:23:34 -0700234 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700235 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700236
Jiyong Park2db76922017-11-08 16:03:48 +0900237 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
238 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
239 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700240 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700241
Jiyong Park2db76922017-11-08 16:03:48 +0900242 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
243 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
244 Soc_specific *bool
245
246 // whether this module is specific to a device, not only for SoC, but also for off-chip
247 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
248 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
249 // This implies `soc_specific:true`.
250 Device_specific *bool
251
252 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900253 // network operator, etc). When set to true, it is installed into /product (or
254 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900255 Product_specific *bool
256
Dario Frenifd05a742018-05-29 13:28:54 +0100257 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100258 // to true, it is installed into /product_services (or /system/product_services if
259 // product_services partition does not exist).
260 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100261
Jiyong Parkf9332f12018-02-01 00:54:12 +0900262 // Whether this module is installed to recovery partition
263 Recovery *bool
264
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700265 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800266 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700267
Steven Moreland57a23d22018-04-04 15:42:19 -0700268 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800269 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700270
Chris Wolfe998306e2016-08-15 14:47:23 -0400271 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700272 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400273
Sasha Smundakb6d23052019-04-01 18:37:36 -0700274 // names of other modules to install on host if this module is installed
275 Host_required []string `android:"arch_variant"`
276
277 // names of other modules to install on target if this module is installed
278 Target_required []string `android:"arch_variant"`
279
Colin Cross5aac3622017-08-31 15:07:09 -0700280 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800281 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700282
Dan Willemsen569edc52018-11-19 09:33:29 -0800283 Dist struct {
284 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
285 // command line and any of these targets are also on the command line, or otherwise
286 // built
287 Targets []string `android:"arch_variant"`
288
289 // The name of the output artifact. This defaults to the basename of the output of
290 // the module.
291 Dest *string `android:"arch_variant"`
292
293 // The directory within the dist directory to store the artifact. Defaults to the
294 // top level directory ("").
295 Dir *string `android:"arch_variant"`
296
297 // A suffix to add to the artifact file name (before any extension).
298 Suffix *string `android:"arch_variant"`
299 } `android:"arch_variant"`
300
Colin Crossa1ad8d12016-06-01 17:09:44 -0700301 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700302 CompileTarget Target `blueprint:"mutated"`
303 CompileMultiTargets []Target `blueprint:"mutated"`
304 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800305
306 // Set by InitAndroidModule
307 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700308 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700309
310 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800311
312 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800313}
314
315type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800316 // If set to true, build a variant of the module for the host. Defaults to false.
317 Host_supported *bool
318
319 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700320 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800321}
322
Colin Crossc472d572015-03-17 15:06:21 -0700323type Multilib string
324
325const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800326 MultilibBoth Multilib = "both"
327 MultilibFirst Multilib = "first"
328 MultilibCommon Multilib = "common"
329 MultilibCommonFirst Multilib = "common_first"
330 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700331)
332
Colin Crossa1ad8d12016-06-01 17:09:44 -0700333type HostOrDeviceSupported int
334
335const (
336 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700337
338 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700339 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700340
341 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700342 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700343
344 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700345 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700346
347 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700348 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700349
350 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700351 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700352
353 // Nothing is supported. This is not exposed to the user, but used to mark a
354 // host only module as unsupported when the module type is not supported on
355 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700356 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700357)
358
Jiyong Park2db76922017-11-08 16:03:48 +0900359type moduleKind int
360
361const (
362 platformModule moduleKind = iota
363 deviceSpecificModule
364 socSpecificModule
365 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100366 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900367)
368
369func (k moduleKind) String() string {
370 switch k {
371 case platformModule:
372 return "platform"
373 case deviceSpecificModule:
374 return "device-specific"
375 case socSpecificModule:
376 return "soc-specific"
377 case productSpecificModule:
378 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100379 case productServicesSpecificModule:
380 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900381 default:
382 panic(fmt.Errorf("unknown module kind %d", k))
383 }
384}
385
Colin Cross36242852017-06-23 15:06:31 -0700386func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800387 base := m.base()
388 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700389
Colin Cross36242852017-06-23 15:06:31 -0700390 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700391 &base.nameProperties,
392 &base.commonProperties,
393 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700394 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700395 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700396}
397
Colin Cross36242852017-06-23 15:06:31 -0700398func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
399 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700400
401 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800402 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700403 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700404 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700405 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800406
Dan Willemsen218f6562015-07-08 18:13:11 -0700407 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700408 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700409 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800410 }
411
Colin Cross36242852017-06-23 15:06:31 -0700412 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800413}
414
Colin Crossee0bc3b2018-10-02 22:01:37 -0700415func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
416 InitAndroidArchModule(m, hod, defaultMultilib)
417 m.base().commonProperties.UseTargetVariants = false
418}
419
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800420// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800421// modules. It should be included as an anonymous field in every module
422// struct definition. InitAndroidModule should then be called from the module's
423// factory function, and the return values from InitAndroidModule should be
424// returned from the factory function.
425//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800426// The ModuleBase type is responsible for implementing the GenerateBuildActions
427// method to support the blueprint.Module interface. This method will then call
428// the module's GenerateAndroidBuildActions method once for each build variant
429// that is to be built. GenerateAndroidBuildActions is passed a
430// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800431// AndroidModuleContext exposes extra functionality specific to the Android build
432// system including details about the particular build variant that is to be
433// generated.
434//
435// For example:
436//
437// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800438// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800439// )
440//
441// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800442// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800443// properties struct {
444// MyProperty string
445// }
446// }
447//
Colin Cross36242852017-06-23 15:06:31 -0700448// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800449// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700450// m.AddProperties(&m.properties)
451// android.InitAndroidModule(m)
452// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800453// }
454//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800455// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800456// // Get the CPU architecture for the current build variant.
457// variantArch := ctx.Arch()
458//
459// // ...
460// }
Colin Cross635c3b02016-05-18 15:37:25 -0700461type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800462 // Putting the curiously recurring thing pointing to the thing that contains
463 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700464 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700465 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800466
Colin Crossfc754582016-05-17 16:34:16 -0700467 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800468 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700469 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800470 hostAndDeviceProperties hostAndDeviceProperties
471 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700472 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700473 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800474
475 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700476 installFiles Paths
477 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900478 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700479
480 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
481 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800482 installTarget WritablePath
483 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700484 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700485
Colin Cross178a5092016-09-13 13:42:32 -0700486 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700487
488 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700489
490 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700491 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800492 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800493 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700494
495 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700496}
497
Colin Cross5f692ec2019-02-01 16:53:07 -0800498func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
499
Colin Cross36242852017-06-23 15:06:31 -0700500func (a *ModuleBase) AddProperties(props ...interface{}) {
501 a.registerProps = append(a.registerProps, props...)
502}
503
504func (a *ModuleBase) GetProperties() []interface{} {
505 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800506}
507
Colin Crossae887032017-10-23 17:16:14 -0700508func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700509 return a.buildParams
510}
511
Colin Cross4c83e5c2019-02-25 14:54:28 -0800512func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
513 return a.ruleParams
514}
515
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800516func (a *ModuleBase) VariablesForTests() map[string]string {
517 return a.variables
518}
519
Colin Crossa9d8bee2018-10-02 13:59:46 -0700520func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
521 a.prefer32 = prefer32
522}
523
Colin Crossce75d2c2016-10-06 16:12:58 -0700524// Name returns the name of the module. It may be overridden by individual module types, for
525// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700526func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800527 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700528}
529
Colin Crossce75d2c2016-10-06 16:12:58 -0700530// BaseModuleName returns the name of the module as specified in the blueprints file.
531func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800532 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700533}
534
Colin Cross635c3b02016-05-18 15:37:25 -0700535func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800536 return a
537}
538
Colin Crossee0bc3b2018-10-02 22:01:37 -0700539func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700540 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700541 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700542 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700543}
544
Colin Crossa1ad8d12016-06-01 17:09:44 -0700545func (a *ModuleBase) Target() Target {
546 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800547}
548
Colin Cross8b74d172016-09-13 09:59:14 -0700549func (a *ModuleBase) TargetPrimary() bool {
550 return a.commonProperties.CompilePrimary
551}
552
Colin Crossee0bc3b2018-10-02 22:01:37 -0700553func (a *ModuleBase) MultiTargets() []Target {
554 return a.commonProperties.CompileMultiTargets
555}
556
Colin Crossa1ad8d12016-06-01 17:09:44 -0700557func (a *ModuleBase) Os() OsType {
558 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800559}
560
Colin Cross635c3b02016-05-18 15:37:25 -0700561func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700562 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800563}
564
Colin Cross635c3b02016-05-18 15:37:25 -0700565func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700566 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800567}
568
Dan Willemsen0b24c742016-10-04 15:13:37 -0700569func (a *ModuleBase) ArchSpecific() bool {
570 return a.commonProperties.ArchSpecific
571}
572
Colin Crossa1ad8d12016-06-01 17:09:44 -0700573func (a *ModuleBase) OsClassSupported() []OsClass {
574 switch a.commonProperties.HostOrDeviceSupported {
575 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700576 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700577 case HostSupportedNoCross:
578 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700579 case DeviceSupported:
580 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700581 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700582 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700583 if Bool(a.hostAndDeviceProperties.Host_supported) ||
584 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
585 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700586 supported = append(supported, Host, HostCross)
587 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700588 if a.hostAndDeviceProperties.Device_supported == nil ||
589 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700590 supported = append(supported, Device)
591 }
592 return supported
593 default:
594 return nil
595 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800596}
597
Colin Cross635c3b02016-05-18 15:37:25 -0700598func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800599 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
600 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700601 (a.hostAndDeviceProperties.Device_supported == nil ||
602 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800603}
604
Jiyong Parkc678ad32018-04-10 13:07:10 +0900605func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100606 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900607}
608
609func (a *ModuleBase) DeviceSpecific() bool {
610 return Bool(a.commonProperties.Device_specific)
611}
612
613func (a *ModuleBase) SocSpecific() bool {
614 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
615}
616
617func (a *ModuleBase) ProductSpecific() bool {
618 return Bool(a.commonProperties.Product_specific)
619}
620
Dario Frenifd05a742018-05-29 13:28:54 +0100621func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100622 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100623}
624
Colin Cross635c3b02016-05-18 15:37:25 -0700625func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800626 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800627 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800628 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800629 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800630}
631
Colin Crossce75d2c2016-10-06 16:12:58 -0700632func (a *ModuleBase) SkipInstall() {
633 a.commonProperties.SkipInstall = true
634}
635
Jiyong Park374510b2018-03-19 18:23:01 +0900636func (a *ModuleBase) ExportedToMake() bool {
637 return a.commonProperties.NamespaceExportedToMake
638}
639
Colin Cross635c3b02016-05-18 15:37:25 -0700640func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700641 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800642
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700643 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700644 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800645 ctx.VisitDepsDepthFirstIf(isFileInstaller,
646 func(m blueprint.Module) {
647 fileInstaller := m.(fileInstaller)
648 files := fileInstaller.filesToInstall()
649 result = append(result, files...)
650 })
651
652 return result
653}
654
Colin Cross635c3b02016-05-18 15:37:25 -0700655func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800656 return a.installFiles
657}
658
Colin Cross635c3b02016-05-18 15:37:25 -0700659func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800660 return p.noAddressSanitizer
661}
662
Colin Cross635c3b02016-05-18 15:37:25 -0700663func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800664 return false
665}
666
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700667func (p *ModuleBase) InstallInSanitizerDir() bool {
668 return false
669}
670
Jiyong Parkf9332f12018-02-01 00:54:12 +0900671func (p *ModuleBase) InstallInRecovery() bool {
672 return Bool(p.commonProperties.Recovery)
673}
674
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900675func (a *ModuleBase) Owner() string {
676 return String(a.commonProperties.Owner)
677}
678
Jiyong Park52818fc2019-03-18 12:01:38 +0900679func (a *ModuleBase) NoticeFile() OptionalPath {
680 return a.noticeFile
681}
682
Colin Cross0875c522017-11-28 17:34:01 -0800683func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700684 allInstalledFiles := Paths{}
685 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800686 ctx.VisitAllModuleVariants(func(module Module) {
687 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700688 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
689 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800690 })
691
Colin Cross0875c522017-11-28 17:34:01 -0800692 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700693
Jeff Gaston088e29e2017-11-29 16:47:17 -0800694 namespacePrefix := ctx.Namespace().(*Namespace).id
695 if namespacePrefix != "" {
696 namespacePrefix = namespacePrefix + "-"
697 }
698
Colin Cross3f40fa42015-01-30 17:27:36 -0800699 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800700 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800701 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700702 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800703 Output: name,
704 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800705 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700706 })
707 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700708 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700709 }
710
711 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800712 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800713 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700714 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800715 Output: name,
716 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700717 })
718 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700719 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700720 }
721
722 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800723 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800724 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800725 suffix = "-soong"
726 }
727
Jeff Gaston088e29e2017-11-29 16:47:17 -0800728 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800729 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700730 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800731 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700732 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800733 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700734
735 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800736 }
737}
738
Jiyong Park2db76922017-11-08 16:03:48 +0900739func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
740 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
741 var deviceSpecific = Bool(a.commonProperties.Device_specific)
742 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100743 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900744
Dario Frenifd05a742018-05-29 13:28:54 +0100745 msg := "conflicting value set here"
746 if socSpecific && deviceSpecific {
747 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900748 if Bool(a.commonProperties.Vendor) {
749 ctx.PropertyErrorf("vendor", msg)
750 }
751 if Bool(a.commonProperties.Proprietary) {
752 ctx.PropertyErrorf("proprietary", msg)
753 }
754 if Bool(a.commonProperties.Soc_specific) {
755 ctx.PropertyErrorf("soc_specific", msg)
756 }
757 }
758
Dario Frenifd05a742018-05-29 13:28:54 +0100759 if productSpecific && productServicesSpecific {
760 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
761 ctx.PropertyErrorf("product_services_specific", msg)
762 }
763
764 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
765 if productSpecific {
766 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
767 } else {
768 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
769 }
770 if deviceSpecific {
771 ctx.PropertyErrorf("device_specific", msg)
772 } else {
773 if Bool(a.commonProperties.Vendor) {
774 ctx.PropertyErrorf("vendor", msg)
775 }
776 if Bool(a.commonProperties.Proprietary) {
777 ctx.PropertyErrorf("proprietary", msg)
778 }
779 if Bool(a.commonProperties.Soc_specific) {
780 ctx.PropertyErrorf("soc_specific", msg)
781 }
782 }
783 }
784
Jiyong Park2db76922017-11-08 16:03:48 +0900785 if productSpecific {
786 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100787 } else if productServicesSpecific {
788 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900789 } else if deviceSpecific {
790 return deviceSpecificModule
791 } else if socSpecific {
792 return socSpecificModule
793 } else {
794 return platformModule
795 }
796}
797
Colin Cross635c3b02016-05-18 15:37:25 -0700798func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700799 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700800 target: a.commonProperties.CompileTarget,
801 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700802 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900803 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700804 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800805 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800806}
807
Colin Cross0875c522017-11-28 17:34:01 -0800808func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
809 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700810 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800811 ModuleContext: blueprintCtx,
812 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
813 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700814 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800815 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800816 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800817 }
818
Colin Cross4c83e5c2019-02-25 14:54:28 -0800819 if ctx.config.captureBuild {
820 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
821 }
822
Colin Cross67a5c132017-05-09 13:45:28 -0700823 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
824 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800825 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
826 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700827 }
Colin Cross0875c522017-11-28 17:34:01 -0800828 if !ctx.PrimaryArch() {
829 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700830 }
831
832 ctx.Variable(pctx, "moduleDesc", desc)
833
834 s := ""
835 if len(suffix) > 0 {
836 s = " [" + strings.Join(suffix, " ") + "]"
837 }
838 ctx.Variable(pctx, "moduleDescSuffix", s)
839
Dan Willemsen569edc52018-11-19 09:33:29 -0800840 // Some common property checks for properties that will be used later in androidmk.go
841 if a.commonProperties.Dist.Dest != nil {
842 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
843 if err != nil {
844 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
845 }
846 }
847 if a.commonProperties.Dist.Dir != nil {
848 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
849 if err != nil {
850 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
851 }
852 }
853 if a.commonProperties.Dist.Suffix != nil {
854 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
855 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
856 }
857 }
858
Colin Cross9b1d13d2016-09-19 15:18:11 -0700859 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800860 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700861 if ctx.Failed() {
862 return
863 }
864
Colin Cross0875c522017-11-28 17:34:01 -0800865 a.installFiles = append(a.installFiles, ctx.installFiles...)
866 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800867
Jiyong Park52818fc2019-03-18 12:01:38 +0900868 notice := proptools.StringDefault(a.commonProperties.Notice, "NOTICE")
869 if m := SrcIsModule(notice); m != "" {
870 a.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
871 } else {
872 noticePath := filepath.Join(ctx.ModuleDir(), notice)
873 a.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800874 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800875 }
876
Colin Cross9b1d13d2016-09-19 15:18:11 -0700877 if a == ctx.FinalModule().(Module).base() {
878 a.generateModuleTarget(ctx)
879 if ctx.Failed() {
880 return
881 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800882 }
Colin Crosscec81712017-07-13 14:43:27 -0700883
Colin Cross0875c522017-11-28 17:34:01 -0800884 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800885 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800886 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800887}
888
Colin Crossf6566ed2015-03-24 11:13:38 -0700889type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700890 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700891 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700892 targetPrimary bool
893 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900894 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700895 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700896}
897
Colin Cross3f40fa42015-01-30 17:27:36 -0800898type androidModuleContext struct {
899 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700900 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700901 installDeps Paths
902 installFiles Paths
903 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800904 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700905 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700906
907 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700908 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800909 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800910 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800911}
912
Colin Cross67a5c132017-05-09 13:45:28 -0700913func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800914 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700915 Rule: ErrorRule,
916 Description: desc,
917 Outputs: outputs,
918 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800919 Args: map[string]string{
920 "error": err.Error(),
921 },
922 })
923 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800924}
925
Colin Crossaabf6792017-11-29 00:27:14 -0800926func (a *androidModuleContext) Config() Config {
927 return a.ModuleContext.Config().(Config)
928}
929
Colin Cross0875c522017-11-28 17:34:01 -0800930func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700931 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800932}
933
Colin Cross0875c522017-11-28 17:34:01 -0800934func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700935 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700936 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800937 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800938 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700939 Outputs: params.Outputs.Strings(),
940 ImplicitOutputs: params.ImplicitOutputs.Strings(),
941 Inputs: params.Inputs.Strings(),
942 Implicits: params.Implicits.Strings(),
943 OrderOnly: params.OrderOnly.Strings(),
944 Args: params.Args,
945 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700946 }
947
Colin Cross33bfb0a2016-11-21 17:23:08 -0800948 if params.Depfile != nil {
949 bparams.Depfile = params.Depfile.String()
950 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700951 if params.Output != nil {
952 bparams.Outputs = append(bparams.Outputs, params.Output.String())
953 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700954 if params.ImplicitOutput != nil {
955 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
956 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700957 if params.Input != nil {
958 bparams.Inputs = append(bparams.Inputs, params.Input.String())
959 }
960 if params.Implicit != nil {
961 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
962 }
963
Colin Cross0b9f31f2019-02-28 11:00:01 -0800964 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
965 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
966 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
967 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
968 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
969 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -0700970
Colin Cross0875c522017-11-28 17:34:01 -0800971 return bparams
972}
973
974func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800975 if a.config.captureBuild {
976 a.variables[name] = value
977 }
978
Colin Cross0875c522017-11-28 17:34:01 -0800979 a.ModuleContext.Variable(pctx.PackageContext, name, value)
980}
981
982func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
983 argNames ...string) blueprint.Rule {
984
Colin Cross4c83e5c2019-02-25 14:54:28 -0800985 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
986
987 if a.config.captureBuild {
988 a.ruleParams[rule] = params
989 }
990
991 return rule
Colin Cross0875c522017-11-28 17:34:01 -0800992}
993
994func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
995 if a.config.captureBuild {
996 a.buildParams = append(a.buildParams, params)
997 }
998
999 bparams := convertBuildParams(params)
1000
1001 if bparams.Description != "" {
1002 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1003 }
1004
Colin Cross6ff51382015-12-17 16:39:19 -08001005 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -07001006 a.ninjaError(bparams.Description, bparams.Outputs,
1007 fmt.Errorf("module %s missing dependencies: %s\n",
1008 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001009 return
1010 }
1011
Colin Cross0875c522017-11-28 17:34:01 -08001012 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001013}
1014
Colin Cross6ff51382015-12-17 16:39:19 -08001015func (a *androidModuleContext) GetMissingDependencies() []string {
1016 return a.missingDeps
1017}
1018
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001019func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1020 if deps != nil {
1021 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001022 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001023 }
1024}
1025
Colin Crossd11fcda2017-10-23 17:59:01 -07001026func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1027 aModule, _ := module.(Module)
1028 if aModule == nil {
1029 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1030 return nil
1031 }
1032
1033 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001034 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001035 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1036 } else {
1037 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1038 }
1039 return nil
1040 }
1041
1042 return aModule
1043}
1044
Jiyong Parkf2976302019-04-17 21:47:37 +09001045func (a *androidModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
1046 type dep struct {
1047 mod blueprint.Module
1048 tag blueprint.DependencyTag
1049 }
1050 var deps []dep
1051 a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1052 if aModule, _ := m.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
1053 returnedTag := a.ModuleContext.OtherModuleDependencyTag(aModule)
1054 if tag == nil || returnedTag == tag {
1055 deps = append(deps, dep{aModule, returnedTag})
1056 }
1057 }
1058 })
1059 if len(deps) == 1 {
1060 return deps[0].mod, deps[0].tag
1061 } else if len(deps) >= 2 {
1062 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
1063 name, a.ModuleName()))
1064 } else {
1065 return nil, nil
1066 }
1067}
1068
1069func (a *androidModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1070 m, _ := a.getDirectDepInternal(name, tag)
1071 return m
1072}
1073
1074func (a *androidModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1075 return a.getDirectDepInternal(name, nil)
1076}
1077
Colin Cross35143d02017-11-16 00:11:20 -08001078func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1079 a.ModuleContext.VisitDirectDeps(visit)
1080}
1081
Colin Crossd11fcda2017-10-23 17:59:01 -07001082func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1083 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1084 if aModule := a.validateAndroidModule(module); aModule != nil {
1085 visit(aModule)
1086 }
1087 })
1088}
1089
Colin Crossee6143c2017-12-30 17:54:27 -08001090func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1091 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1092 if aModule := a.validateAndroidModule(module); aModule != nil {
1093 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1094 visit(aModule)
1095 }
1096 }
1097 })
1098}
1099
Colin Crossd11fcda2017-10-23 17:59:01 -07001100func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1101 a.ModuleContext.VisitDirectDepsIf(
1102 // pred
1103 func(module blueprint.Module) bool {
1104 if aModule := a.validateAndroidModule(module); aModule != nil {
1105 return pred(aModule)
1106 } else {
1107 return false
1108 }
1109 },
1110 // visit
1111 func(module blueprint.Module) {
1112 visit(module.(Module))
1113 })
1114}
1115
1116func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1117 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1118 if aModule := a.validateAndroidModule(module); aModule != nil {
1119 visit(aModule)
1120 }
1121 })
1122}
1123
1124func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1125 a.ModuleContext.VisitDepsDepthFirstIf(
1126 // pred
1127 func(module blueprint.Module) bool {
1128 if aModule := a.validateAndroidModule(module); aModule != nil {
1129 return pred(aModule)
1130 } else {
1131 return false
1132 }
1133 },
1134 // visit
1135 func(module blueprint.Module) {
1136 visit(module.(Module))
1137 })
1138}
1139
Alex Light778127a2019-02-27 14:19:50 -08001140func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1141 a.ModuleContext.WalkDeps(visit)
1142}
1143
Colin Crossd11fcda2017-10-23 17:59:01 -07001144func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1145 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1146 childAndroidModule := a.validateAndroidModule(child)
1147 parentAndroidModule := a.validateAndroidModule(parent)
1148 if childAndroidModule != nil && parentAndroidModule != nil {
1149 return visit(childAndroidModule, parentAndroidModule)
1150 } else {
1151 return false
1152 }
1153 })
1154}
1155
Colin Cross0875c522017-11-28 17:34:01 -08001156func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1157 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1158 visit(module.(Module))
1159 })
1160}
1161
1162func (a *androidModuleContext) PrimaryModule() Module {
1163 return a.ModuleContext.PrimaryModule().(Module)
1164}
1165
1166func (a *androidModuleContext) FinalModule() Module {
1167 return a.ModuleContext.FinalModule().(Module)
1168}
1169
Colin Crossa1ad8d12016-06-01 17:09:44 -07001170func (a *androidBaseContextImpl) Target() Target {
1171 return a.target
1172}
1173
Colin Cross8b74d172016-09-13 09:59:14 -07001174func (a *androidBaseContextImpl) TargetPrimary() bool {
1175 return a.targetPrimary
1176}
1177
Colin Crossee0bc3b2018-10-02 22:01:37 -07001178func (a *androidBaseContextImpl) MultiTargets() []Target {
1179 return a.multiTargets
1180}
1181
Colin Crossf6566ed2015-03-24 11:13:38 -07001182func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001183 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001184}
1185
Colin Crossa1ad8d12016-06-01 17:09:44 -07001186func (a *androidBaseContextImpl) Os() OsType {
1187 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001188}
1189
Colin Crossf6566ed2015-03-24 11:13:38 -07001190func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001191 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001192}
1193
1194func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001195 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001196}
1197
Colin Cross0af4b842015-04-30 16:36:18 -07001198func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001199 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001200}
1201
Doug Horn21b94272019-01-16 12:06:11 -08001202func (a *androidBaseContextImpl) Fuchsia() bool {
1203 return a.target.Os == Fuchsia
1204}
1205
Colin Cross3edeee12017-04-04 12:59:48 -07001206func (a *androidBaseContextImpl) Windows() bool {
1207 return a.target.Os == Windows
1208}
1209
Colin Crossf6566ed2015-03-24 11:13:38 -07001210func (a *androidBaseContextImpl) Debug() bool {
1211 return a.debug
1212}
1213
Colin Cross1e7d3702016-08-24 15:25:47 -07001214func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001215 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001216 return true
1217 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001218 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001219}
1220
Colin Cross1332b002015-04-07 17:11:30 -07001221func (a *androidBaseContextImpl) AConfig() Config {
1222 return a.config
1223}
1224
Colin Cross9272ade2016-08-17 15:24:12 -07001225func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1226 return DeviceConfig{a.config.deviceConfig}
1227}
1228
Jiyong Park2db76922017-11-08 16:03:48 +09001229func (a *androidBaseContextImpl) Platform() bool {
1230 return a.kind == platformModule
1231}
1232
1233func (a *androidBaseContextImpl) DeviceSpecific() bool {
1234 return a.kind == deviceSpecificModule
1235}
1236
1237func (a *androidBaseContextImpl) SocSpecific() bool {
1238 return a.kind == socSpecificModule
1239}
1240
1241func (a *androidBaseContextImpl) ProductSpecific() bool {
1242 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001243}
1244
Dario Frenifd05a742018-05-29 13:28:54 +01001245func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1246 return a.kind == productServicesSpecificModule
1247}
1248
Jiyong Park5baac542018-08-28 09:55:37 +09001249// Makes this module a platform module, i.e. not specific to soc, device,
1250// product, or product_services.
1251func (a *ModuleBase) MakeAsPlatform() {
1252 a.commonProperties.Vendor = boolPtr(false)
1253 a.commonProperties.Proprietary = boolPtr(false)
1254 a.commonProperties.Soc_specific = boolPtr(false)
1255 a.commonProperties.Product_specific = boolPtr(false)
1256 a.commonProperties.Product_services_specific = boolPtr(false)
1257}
1258
Colin Cross8d8f8e22016-08-03 11:57:50 -07001259func (a *androidModuleContext) InstallInData() bool {
1260 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001261}
1262
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001263func (a *androidModuleContext) InstallInSanitizerDir() bool {
1264 return a.module.InstallInSanitizerDir()
1265}
1266
Jiyong Parkf9332f12018-02-01 00:54:12 +09001267func (a *androidModuleContext) InstallInRecovery() bool {
1268 return a.module.InstallInRecovery()
1269}
1270
Colin Cross893d8162017-04-26 17:34:03 -07001271func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1272 if a.module.base().commonProperties.SkipInstall {
1273 return true
1274 }
1275
Colin Cross3607f212018-05-07 15:28:05 -07001276 // We'll need a solution for choosing which of modules with the same name in different
1277 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1278 // list of namespaces to install in a Soong-only build.
1279 if !a.module.base().commonProperties.NamespaceExportedToMake {
1280 return true
1281 }
1282
Colin Cross893d8162017-04-26 17:34:03 -07001283 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001284 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001285 return true
1286 }
1287
Colin Cross6510f912017-11-29 00:27:14 -08001288 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001289 return true
1290 }
1291 }
1292
1293 return false
1294}
1295
Colin Cross5c517922017-08-31 12:29:17 -07001296func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001297 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001298 return a.installFile(installPath, name, srcPath, Cp, deps)
1299}
1300
1301func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1302 deps ...Path) OutputPath {
1303 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1304}
1305
1306func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1307 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001308
Dan Willemsen782a2d12015-12-21 14:55:28 -08001309 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001310 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001311
Colin Cross893d8162017-04-26 17:34:03 -07001312 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001313
Dan Willemsen322acaf2016-01-12 23:07:05 -08001314 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001315
Colin Cross89562dc2016-10-03 17:47:19 -07001316 var implicitDeps, orderOnlyDeps Paths
1317
1318 if a.Host() {
1319 // Installed host modules might be used during the build, depend directly on their
1320 // dependencies so their timestamp is updated whenever their dependency is updated
1321 implicitDeps = deps
1322 } else {
1323 orderOnlyDeps = deps
1324 }
1325
Colin Crossae887032017-10-23 17:16:14 -07001326 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001327 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001328 Description: "install " + fullInstallPath.Base(),
1329 Output: fullInstallPath,
1330 Input: srcPath,
1331 Implicits: implicitDeps,
1332 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001333 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001334 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001335
Dan Willemsen322acaf2016-01-12 23:07:05 -08001336 a.installFiles = append(a.installFiles, fullInstallPath)
1337 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001338 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001339 return fullInstallPath
1340}
1341
Colin Cross3854a602016-01-11 12:49:11 -08001342func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1343 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001344 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001345
Colin Cross893d8162017-04-26 17:34:03 -07001346 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001347
Alex Lightfb4353d2019-01-17 13:57:45 -08001348 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1349 if err != nil {
1350 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1351 }
Colin Crossae887032017-10-23 17:16:14 -07001352 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001353 Rule: Symlink,
1354 Description: "install symlink " + fullInstallPath.Base(),
1355 Output: fullInstallPath,
1356 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001357 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001358 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001359 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001360 },
1361 })
Colin Cross3854a602016-01-11 12:49:11 -08001362
Colin Cross12fc4972016-01-11 12:49:11 -08001363 a.installFiles = append(a.installFiles, fullInstallPath)
1364 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1365 }
Colin Cross3854a602016-01-11 12:49:11 -08001366 return fullInstallPath
1367}
1368
Jiyong Parkf1194352019-02-25 11:05:47 +09001369// installPath/name -> absPath where absPath might be a path that is available only at runtime
1370// (e.g. /apex/...)
1371func (a *androidModuleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1372 fullInstallPath := installPath.Join(a, name)
1373 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
1374
1375 if !a.skipInstall(fullInstallPath) {
1376 a.Build(pctx, BuildParams{
1377 Rule: Symlink,
1378 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1379 Output: fullInstallPath,
1380 Default: !a.Config().EmbeddedInMake(),
1381 Args: map[string]string{
1382 "fromPath": absPath,
1383 },
1384 })
1385
1386 a.installFiles = append(a.installFiles, fullInstallPath)
1387 }
1388 return fullInstallPath
1389}
1390
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001391func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001392 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1393}
1394
Colin Cross3f40fa42015-01-30 17:27:36 -08001395type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001396 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001397}
1398
1399func isFileInstaller(m blueprint.Module) bool {
1400 _, ok := m.(fileInstaller)
1401 return ok
1402}
1403
1404func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001405 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001406 return ok
1407}
Colin Crossfce53272015-04-08 11:21:40 -07001408
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001409func findStringInSlice(str string, slice []string) int {
1410 for i, s := range slice {
1411 if s == str {
1412 return i
Colin Crossfce53272015-04-08 11:21:40 -07001413 }
1414 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001415 return -1
1416}
1417
Colin Cross068e0fe2016-12-13 15:23:47 -08001418func SrcIsModule(s string) string {
1419 if len(s) > 1 && s[0] == ':' {
1420 return s[1:]
1421 }
1422 return ""
1423}
1424
1425type sourceDependencyTag struct {
1426 blueprint.BaseDependencyTag
1427}
1428
1429var SourceDepTag sourceDependencyTag
1430
Colin Cross366938f2017-12-11 16:29:02 -08001431// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1432// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001433//
1434// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001435func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1436 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001437 set := make(map[string]bool)
1438
Colin Cross068e0fe2016-12-13 15:23:47 -08001439 for _, s := range srcFiles {
1440 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001441 if _, found := set[m]; found {
1442 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1443 } else {
1444 set[m] = true
1445 deps = append(deps, m)
1446 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001447 }
1448 }
1449
1450 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1451}
1452
Colin Cross366938f2017-12-11 16:29:02 -08001453// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1454// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001455//
1456// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001457func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1458 if s != nil {
1459 if m := SrcIsModule(*s); m != "" {
1460 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1461 }
1462 }
1463}
1464
Colin Cross068e0fe2016-12-13 15:23:47 -08001465type SourceFileProducer interface {
1466 Srcs() Paths
1467}
1468
Colin Crossfe17f6f2019-03-28 19:30:56 -07001469type HostToolProvider interface {
1470 HostToolPath() OptionalPath
1471}
1472
Colin Cross27b922f2019-03-04 22:35:41 -08001473// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1474// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001475//
1476// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001477func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Cross8a497952019-03-05 22:25:09 -08001478 return PathsForModuleSrcExcludes(ctx, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001479}
1480
Colin Cross2fafa3e2019-03-05 12:39:51 -08001481// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1482// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001483//
1484// Deprecated: use PathForModuleSrc instead.
Colin Cross2fafa3e2019-03-05 12:39:51 -08001485func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
Colin Cross8a497952019-03-05 22:25:09 -08001486 return PathForModuleSrc(ctx, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001487}
1488
1489// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1490// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1491// dependency resolution.
1492func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1493 if srcFile != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001494 return OptionalPathForPath(PathForModuleSrc(ctx, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001495 }
1496 return OptionalPath{}
1497}
1498
Nan Zhang6d34b302017-02-04 17:47:46 -08001499func (ctx *androidModuleContext) RequiredModuleNames() []string {
1500 return ctx.module.base().commonProperties.Required
1501}
1502
Sasha Smundakb6d23052019-04-01 18:37:36 -07001503func (ctx *androidModuleContext) HostRequiredModuleNames() []string {
1504 return ctx.module.base().commonProperties.Host_required
1505}
1506
1507func (ctx *androidModuleContext) TargetRequiredModuleNames() []string {
1508 return ctx.module.base().commonProperties.Target_required
1509}
1510
Colin Cross7f19f372016-11-01 11:10:25 -07001511func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1512 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001513 if err != nil {
1514 ctx.ModuleErrorf("glob: %s", err.Error())
1515 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001516 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001517}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001518
Nan Zhang581fd212018-01-10 16:06:12 -08001519func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001520 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001521 if err != nil {
1522 ctx.ModuleErrorf("glob: %s", err.Error())
1523 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001524 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001525}
1526
Colin Cross463a90e2015-06-17 14:20:06 -07001527func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001528 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001529}
1530
Colin Cross0875c522017-11-28 17:34:01 -08001531func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001532 return &buildTargetSingleton{}
1533}
1534
Colin Cross87d8b562017-04-25 10:01:55 -07001535func parentDir(dir string) string {
1536 dir, _ = filepath.Split(dir)
1537 return filepath.Clean(dir)
1538}
1539
Colin Cross1f8c52b2015-06-16 16:38:17 -07001540type buildTargetSingleton struct{}
1541
Colin Cross0875c522017-11-28 17:34:01 -08001542func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1543 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001544
Colin Cross0875c522017-11-28 17:34:01 -08001545 mmTarget := func(dir string) WritablePath {
1546 return PathForPhony(ctx,
1547 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001548 }
1549
Colin Cross0875c522017-11-28 17:34:01 -08001550 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001551
Colin Cross0875c522017-11-28 17:34:01 -08001552 ctx.VisitAllModules(func(module Module) {
1553 blueprintDir := module.base().blueprintDir
1554 installTarget := module.base().installTarget
1555 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001556
Colin Cross0875c522017-11-28 17:34:01 -08001557 if checkbuildTarget != nil {
1558 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1559 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1560 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001561
Colin Cross0875c522017-11-28 17:34:01 -08001562 if installTarget != nil {
1563 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001564 }
1565 })
1566
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001567 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001568 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001569 suffix = "-soong"
1570 }
1571
Colin Cross1f8c52b2015-06-16 16:38:17 -07001572 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001573 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001574 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001575 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001576 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001577 })
1578
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001579 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001580 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001581 return
1582 }
1583
Colin Cross0875c522017-11-28 17:34:01 -08001584 sortedKeys := func(m map[string]Paths) []string {
1585 s := make([]string, 0, len(m))
1586 for k := range m {
1587 s = append(s, k)
1588 }
1589 sort.Strings(s)
1590 return s
1591 }
1592
Colin Cross87d8b562017-04-25 10:01:55 -07001593 // Ensure ancestor directories are in modulesInDir
1594 dirs := sortedKeys(modulesInDir)
1595 for _, dir := range dirs {
1596 dir := parentDir(dir)
1597 for dir != "." && dir != "/" {
1598 if _, exists := modulesInDir[dir]; exists {
1599 break
1600 }
1601 modulesInDir[dir] = nil
1602 dir = parentDir(dir)
1603 }
1604 }
1605
1606 // Make directories build their direct subdirectories
1607 dirs = sortedKeys(modulesInDir)
1608 for _, dir := range dirs {
1609 p := parentDir(dir)
1610 if p != "." && p != "/" {
1611 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1612 }
1613 }
1614
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001615 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1616 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1617 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001618 for _, dir := range dirs {
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: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001622 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001623 // HACK: checkbuild should be an optional build, but force it
1624 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001625 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001626 })
1627 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001628
1629 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1630 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001631 ctx.VisitAllModules(func(module Module) {
1632 if module.Enabled() {
1633 os := module.Target().Os
1634 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001635 }
1636 })
1637
Colin Cross0875c522017-11-28 17:34:01 -08001638 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001639 for os, deps := range osDeps {
1640 var className string
1641
1642 switch os.Class {
1643 case Host:
1644 className = "host"
1645 case HostCross:
1646 className = "host-cross"
1647 case Device:
1648 className = "target"
1649 default:
1650 continue
1651 }
1652
Colin Cross0875c522017-11-28 17:34:01 -08001653 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001654 osClass[className] = append(osClass[className], name)
1655
Colin Cross0875c522017-11-28 17:34:01 -08001656 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001657 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001658 Output: name,
1659 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001660 })
1661 }
1662
1663 // Wrap those into host|host-cross|target phony rules
1664 osClasses := sortedKeys(osClass)
1665 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001666 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001667 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001668 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001669 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001670 })
1671 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001672}
Colin Crossd779da42015-12-17 18:00:23 -08001673
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001674// Collect information for opening IDE project files in java/jdeps.go.
1675type IDEInfo interface {
1676 IDEInfo(ideInfo *IdeInfo)
1677 BaseModuleName() string
1678}
1679
1680// Extract the base module name from the Import name.
1681// Often the Import name has a prefix "prebuilt_".
1682// Remove the prefix explicitly if needed
1683// until we find a better solution to get the Import name.
1684type IDECustomizedModuleName interface {
1685 IDECustomizedModuleName() string
1686}
1687
1688type IdeInfo struct {
1689 Deps []string `json:"dependencies,omitempty"`
1690 Srcs []string `json:"srcs,omitempty"`
1691 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1692 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1693 Jars []string `json:"jars,omitempty"`
1694 Classes []string `json:"class,omitempty"`
1695 Installed_paths []string `json:"installed,omitempty"`
1696}