blob: 1e6cc838818c1dc525da13e864a9430175ade449 [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 Crossfaeb7aa2017-02-01 14:12:44 -0800120 ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths
Colin Cross7f19f372016-11-01 11:10:25 -0700121 Glob(globPattern string, excludes []string) Paths
Nan Zhang581fd212018-01-10 16:06:12 -0800122 GlobFiles(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700123
Colin Cross5c517922017-08-31 12:29:17 -0700124 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
125 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800126 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) 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
Colin Cross3f68a132017-10-23 17:10:29 -0700136
137 // android.ModuleContext methods
138 // These are duplicated instead of embedded so that can eventually be wrapped to take an
139 // android.Module instead of a blueprint.Module
140 OtherModuleName(m blueprint.Module) string
141 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
142 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
143
144 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
145 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
146
147 ModuleSubDir() string
148
Colin Cross35143d02017-11-16 00:11:20 -0800149 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700150 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800151 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700152 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700153 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700154 VisitDepsDepthFirst(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 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
157 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800158 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700159
Colin Cross0875c522017-11-28 17:34:01 -0800160 Variable(pctx PackageContext, name, value string)
161 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700162 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
163 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800164 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700165
Colin Cross0875c522017-11-28 17:34:01 -0800166 PrimaryModule() Module
167 FinalModule() Module
168 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700169
170 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800171 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800172}
173
Colin Cross635c3b02016-05-18 15:37:25 -0700174type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800175 blueprint.Module
176
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700177 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
178 // but GenerateAndroidBuildActions also has access to Android-specific information.
179 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700180 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700181
Colin Cross1e676be2016-10-12 14:38:15 -0700182 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800183
Colin Cross635c3b02016-05-18 15:37:25 -0700184 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800185 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700186 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800187 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700188 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900189 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800190 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900191 ExportedToMake() bool
Colin Cross36242852017-06-23 15:06:31 -0700192
193 AddProperties(props ...interface{})
194 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700195
Colin Crossae887032017-10-23 17:16:14 -0700196 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800197 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800198 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800199}
200
Colin Crossfc754582016-05-17 16:34:16 -0700201type nameProperties struct {
202 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800203 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700204}
205
206type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800207 // emit build rules for this module
208 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800209
Colin Cross7d5136f2015-05-11 13:39:40 -0700210 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800211 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
212 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
213 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700214 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700215
216 Target struct {
217 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700218 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700219 }
220 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700221 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700222 }
223 }
224
Colin Crossee0bc3b2018-10-02 22:01:37 -0700225 UseTargetVariants bool `blueprint:"mutated"`
226 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800227
Dan Willemsen782a2d12015-12-21 14:55:28 -0800228 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700229 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800230
Colin Cross55708f32017-03-20 13:23:34 -0700231 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700232 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700233
Jiyong Park2db76922017-11-08 16:03:48 +0900234 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
235 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
236 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700237 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700238
Jiyong Park2db76922017-11-08 16:03:48 +0900239 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
240 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
241 Soc_specific *bool
242
243 // whether this module is specific to a device, not only for SoC, but also for off-chip
244 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
245 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
246 // This implies `soc_specific:true`.
247 Device_specific *bool
248
249 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900250 // network operator, etc). When set to true, it is installed into /product (or
251 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900252 Product_specific *bool
253
Dario Frenifd05a742018-05-29 13:28:54 +0100254 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100255 // to true, it is installed into /product_services (or /system/product_services if
256 // product_services partition does not exist).
257 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100258
Jiyong Parkf9332f12018-02-01 00:54:12 +0900259 // Whether this module is installed to recovery partition
260 Recovery *bool
261
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700262 // init.rc files to be installed if this module is installed
263 Init_rc []string
264
Steven Moreland57a23d22018-04-04 15:42:19 -0700265 // VINTF manifest fragments to be installed if this module is installed
266 Vintf_fragments []string
267
Chris Wolfe998306e2016-08-15 14:47:23 -0400268 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700269 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400270
Colin Cross5aac3622017-08-31 15:07:09 -0700271 // relative path to a file to include in the list of notices for the device
272 Notice *string
273
Dan Willemsen569edc52018-11-19 09:33:29 -0800274 Dist struct {
275 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
276 // command line and any of these targets are also on the command line, or otherwise
277 // built
278 Targets []string `android:"arch_variant"`
279
280 // The name of the output artifact. This defaults to the basename of the output of
281 // the module.
282 Dest *string `android:"arch_variant"`
283
284 // The directory within the dist directory to store the artifact. Defaults to the
285 // top level directory ("").
286 Dir *string `android:"arch_variant"`
287
288 // A suffix to add to the artifact file name (before any extension).
289 Suffix *string `android:"arch_variant"`
290 } `android:"arch_variant"`
291
Colin Crossa1ad8d12016-06-01 17:09:44 -0700292 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700293 CompileTarget Target `blueprint:"mutated"`
294 CompileMultiTargets []Target `blueprint:"mutated"`
295 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800296
297 // Set by InitAndroidModule
298 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700299 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700300
301 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800302
303 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800304}
305
306type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800307 // If set to true, build a variant of the module for the host. Defaults to false.
308 Host_supported *bool
309
310 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700311 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800312}
313
Colin Crossc472d572015-03-17 15:06:21 -0700314type Multilib string
315
316const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800317 MultilibBoth Multilib = "both"
318 MultilibFirst Multilib = "first"
319 MultilibCommon Multilib = "common"
320 MultilibCommonFirst Multilib = "common_first"
321 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700322)
323
Colin Crossa1ad8d12016-06-01 17:09:44 -0700324type HostOrDeviceSupported int
325
326const (
327 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700328
329 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700330 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700331
332 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700333 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700334
335 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700336 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700337
338 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700339 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700340
341 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700342 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700343
344 // Nothing is supported. This is not exposed to the user, but used to mark a
345 // host only module as unsupported when the module type is not supported on
346 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700347 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700348)
349
Jiyong Park2db76922017-11-08 16:03:48 +0900350type moduleKind int
351
352const (
353 platformModule moduleKind = iota
354 deviceSpecificModule
355 socSpecificModule
356 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100357 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900358)
359
360func (k moduleKind) String() string {
361 switch k {
362 case platformModule:
363 return "platform"
364 case deviceSpecificModule:
365 return "device-specific"
366 case socSpecificModule:
367 return "soc-specific"
368 case productSpecificModule:
369 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100370 case productServicesSpecificModule:
371 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900372 default:
373 panic(fmt.Errorf("unknown module kind %d", k))
374 }
375}
376
Colin Cross36242852017-06-23 15:06:31 -0700377func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800378 base := m.base()
379 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700380
Colin Cross36242852017-06-23 15:06:31 -0700381 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700382 &base.nameProperties,
383 &base.commonProperties,
384 &base.variableProperties)
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700385 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700386}
387
Colin Cross36242852017-06-23 15:06:31 -0700388func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
389 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700390
391 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800392 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700393 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700394 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700395 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800396
Dan Willemsen218f6562015-07-08 18:13:11 -0700397 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700398 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700399 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800400 }
401
Colin Cross36242852017-06-23 15:06:31 -0700402 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800403}
404
Colin Crossee0bc3b2018-10-02 22:01:37 -0700405func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
406 InitAndroidArchModule(m, hod, defaultMultilib)
407 m.base().commonProperties.UseTargetVariants = false
408}
409
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800410// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800411// modules. It should be included as an anonymous field in every module
412// struct definition. InitAndroidModule should then be called from the module's
413// factory function, and the return values from InitAndroidModule should be
414// returned from the factory function.
415//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800416// The ModuleBase type is responsible for implementing the GenerateBuildActions
417// method to support the blueprint.Module interface. This method will then call
418// the module's GenerateAndroidBuildActions method once for each build variant
419// that is to be built. GenerateAndroidBuildActions is passed a
420// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800421// AndroidModuleContext exposes extra functionality specific to the Android build
422// system including details about the particular build variant that is to be
423// generated.
424//
425// For example:
426//
427// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800428// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800429// )
430//
431// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800432// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800433// properties struct {
434// MyProperty string
435// }
436// }
437//
Colin Cross36242852017-06-23 15:06:31 -0700438// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800439// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700440// m.AddProperties(&m.properties)
441// android.InitAndroidModule(m)
442// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800443// }
444//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800445// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800446// // Get the CPU architecture for the current build variant.
447// variantArch := ctx.Arch()
448//
449// // ...
450// }
Colin Cross635c3b02016-05-18 15:37:25 -0700451type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800452 // Putting the curiously recurring thing pointing to the thing that contains
453 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700454 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700455 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800456
Colin Crossfc754582016-05-17 16:34:16 -0700457 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800458 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700459 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800460 hostAndDeviceProperties hostAndDeviceProperties
461 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700462 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700463 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800464
465 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700466 installFiles Paths
467 checkbuildFiles Paths
Jaewoong Jung62707f72018-11-16 13:26:43 -0800468 noticeFile Path
Colin Cross1f8c52b2015-06-16 16:38:17 -0700469
470 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
471 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800472 installTarget WritablePath
473 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700474 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700475
Colin Cross178a5092016-09-13 13:42:32 -0700476 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700477
478 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700479
480 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700481 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800482 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800483 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700484
485 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700486}
487
Colin Cross5f692ec2019-02-01 16:53:07 -0800488func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
489
Colin Cross36242852017-06-23 15:06:31 -0700490func (a *ModuleBase) AddProperties(props ...interface{}) {
491 a.registerProps = append(a.registerProps, props...)
492}
493
494func (a *ModuleBase) GetProperties() []interface{} {
495 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800496}
497
Colin Crossae887032017-10-23 17:16:14 -0700498func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700499 return a.buildParams
500}
501
Colin Cross4c83e5c2019-02-25 14:54:28 -0800502func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
503 return a.ruleParams
504}
505
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800506func (a *ModuleBase) VariablesForTests() map[string]string {
507 return a.variables
508}
509
Colin Crossa9d8bee2018-10-02 13:59:46 -0700510func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
511 a.prefer32 = prefer32
512}
513
Colin Crossce75d2c2016-10-06 16:12:58 -0700514// Name returns the name of the module. It may be overridden by individual module types, for
515// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700516func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800517 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700518}
519
Colin Crossce75d2c2016-10-06 16:12:58 -0700520// BaseModuleName returns the name of the module as specified in the blueprints file.
521func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800522 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700523}
524
Colin Cross635c3b02016-05-18 15:37:25 -0700525func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800526 return a
527}
528
Colin Crossee0bc3b2018-10-02 22:01:37 -0700529func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700530 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700531 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700532 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700533}
534
Colin Crossa1ad8d12016-06-01 17:09:44 -0700535func (a *ModuleBase) Target() Target {
536 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800537}
538
Colin Cross8b74d172016-09-13 09:59:14 -0700539func (a *ModuleBase) TargetPrimary() bool {
540 return a.commonProperties.CompilePrimary
541}
542
Colin Crossee0bc3b2018-10-02 22:01:37 -0700543func (a *ModuleBase) MultiTargets() []Target {
544 return a.commonProperties.CompileMultiTargets
545}
546
Colin Crossa1ad8d12016-06-01 17:09:44 -0700547func (a *ModuleBase) Os() OsType {
548 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800549}
550
Colin Cross635c3b02016-05-18 15:37:25 -0700551func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700552 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800553}
554
Colin Cross635c3b02016-05-18 15:37:25 -0700555func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700556 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800557}
558
Dan Willemsen0b24c742016-10-04 15:13:37 -0700559func (a *ModuleBase) ArchSpecific() bool {
560 return a.commonProperties.ArchSpecific
561}
562
Colin Crossa1ad8d12016-06-01 17:09:44 -0700563func (a *ModuleBase) OsClassSupported() []OsClass {
564 switch a.commonProperties.HostOrDeviceSupported {
565 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700566 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700567 case HostSupportedNoCross:
568 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700569 case DeviceSupported:
570 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700571 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700572 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700573 if Bool(a.hostAndDeviceProperties.Host_supported) ||
574 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
575 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700576 supported = append(supported, Host, HostCross)
577 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700578 if a.hostAndDeviceProperties.Device_supported == nil ||
579 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700580 supported = append(supported, Device)
581 }
582 return supported
583 default:
584 return nil
585 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800586}
587
Colin Cross635c3b02016-05-18 15:37:25 -0700588func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800589 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
590 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700591 (a.hostAndDeviceProperties.Device_supported == nil ||
592 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800593}
594
Jiyong Parkc678ad32018-04-10 13:07:10 +0900595func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100596 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900597}
598
599func (a *ModuleBase) DeviceSpecific() bool {
600 return Bool(a.commonProperties.Device_specific)
601}
602
603func (a *ModuleBase) SocSpecific() bool {
604 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
605}
606
607func (a *ModuleBase) ProductSpecific() bool {
608 return Bool(a.commonProperties.Product_specific)
609}
610
Dario Frenifd05a742018-05-29 13:28:54 +0100611func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100612 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100613}
614
Colin Cross635c3b02016-05-18 15:37:25 -0700615func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800616 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800617 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800618 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800619 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800620}
621
Colin Crossce75d2c2016-10-06 16:12:58 -0700622func (a *ModuleBase) SkipInstall() {
623 a.commonProperties.SkipInstall = true
624}
625
Jiyong Park374510b2018-03-19 18:23:01 +0900626func (a *ModuleBase) ExportedToMake() bool {
627 return a.commonProperties.NamespaceExportedToMake
628}
629
Colin Cross635c3b02016-05-18 15:37:25 -0700630func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700631 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800632
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700633 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700634 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800635 ctx.VisitDepsDepthFirstIf(isFileInstaller,
636 func(m blueprint.Module) {
637 fileInstaller := m.(fileInstaller)
638 files := fileInstaller.filesToInstall()
639 result = append(result, files...)
640 })
641
642 return result
643}
644
Colin Cross635c3b02016-05-18 15:37:25 -0700645func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800646 return a.installFiles
647}
648
Colin Cross635c3b02016-05-18 15:37:25 -0700649func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800650 return p.noAddressSanitizer
651}
652
Colin Cross635c3b02016-05-18 15:37:25 -0700653func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800654 return false
655}
656
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700657func (p *ModuleBase) InstallInSanitizerDir() bool {
658 return false
659}
660
Jiyong Parkf9332f12018-02-01 00:54:12 +0900661func (p *ModuleBase) InstallInRecovery() bool {
662 return Bool(p.commonProperties.Recovery)
663}
664
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900665func (a *ModuleBase) Owner() string {
666 return String(a.commonProperties.Owner)
667}
668
Colin Cross0875c522017-11-28 17:34:01 -0800669func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700670 allInstalledFiles := Paths{}
671 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800672 ctx.VisitAllModuleVariants(func(module Module) {
673 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700674 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
675 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800676 })
677
Colin Cross0875c522017-11-28 17:34:01 -0800678 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700679
Jeff Gaston088e29e2017-11-29 16:47:17 -0800680 namespacePrefix := ctx.Namespace().(*Namespace).id
681 if namespacePrefix != "" {
682 namespacePrefix = namespacePrefix + "-"
683 }
684
Colin Cross3f40fa42015-01-30 17:27:36 -0800685 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800686 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800687 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700688 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800689 Output: name,
690 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800691 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700692 })
693 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700694 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700695 }
696
697 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800698 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800699 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700700 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800701 Output: name,
702 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700703 })
704 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700705 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700706 }
707
708 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800709 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800710 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800711 suffix = "-soong"
712 }
713
Jeff Gaston088e29e2017-11-29 16:47:17 -0800714 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800715 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700716 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800717 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700718 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800719 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700720
721 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800722 }
723}
724
Jiyong Park2db76922017-11-08 16:03:48 +0900725func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
726 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
727 var deviceSpecific = Bool(a.commonProperties.Device_specific)
728 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100729 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900730
Dario Frenifd05a742018-05-29 13:28:54 +0100731 msg := "conflicting value set here"
732 if socSpecific && deviceSpecific {
733 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900734 if Bool(a.commonProperties.Vendor) {
735 ctx.PropertyErrorf("vendor", msg)
736 }
737 if Bool(a.commonProperties.Proprietary) {
738 ctx.PropertyErrorf("proprietary", msg)
739 }
740 if Bool(a.commonProperties.Soc_specific) {
741 ctx.PropertyErrorf("soc_specific", msg)
742 }
743 }
744
Dario Frenifd05a742018-05-29 13:28:54 +0100745 if productSpecific && productServicesSpecific {
746 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
747 ctx.PropertyErrorf("product_services_specific", msg)
748 }
749
750 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
751 if productSpecific {
752 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
753 } else {
754 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
755 }
756 if deviceSpecific {
757 ctx.PropertyErrorf("device_specific", msg)
758 } else {
759 if Bool(a.commonProperties.Vendor) {
760 ctx.PropertyErrorf("vendor", msg)
761 }
762 if Bool(a.commonProperties.Proprietary) {
763 ctx.PropertyErrorf("proprietary", msg)
764 }
765 if Bool(a.commonProperties.Soc_specific) {
766 ctx.PropertyErrorf("soc_specific", msg)
767 }
768 }
769 }
770
Jiyong Park2db76922017-11-08 16:03:48 +0900771 if productSpecific {
772 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100773 } else if productServicesSpecific {
774 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900775 } else if deviceSpecific {
776 return deviceSpecificModule
777 } else if socSpecific {
778 return socSpecificModule
779 } else {
780 return platformModule
781 }
782}
783
Colin Cross635c3b02016-05-18 15:37:25 -0700784func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700785 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700786 target: a.commonProperties.CompileTarget,
787 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700788 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900789 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700790 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800791 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800792}
793
Colin Cross0875c522017-11-28 17:34:01 -0800794func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
795 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700796 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800797 ModuleContext: blueprintCtx,
798 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
799 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700800 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800801 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800802 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800803 }
804
Colin Cross4c83e5c2019-02-25 14:54:28 -0800805 if ctx.config.captureBuild {
806 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
807 }
808
Colin Cross67a5c132017-05-09 13:45:28 -0700809 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
810 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800811 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
812 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700813 }
Colin Cross0875c522017-11-28 17:34:01 -0800814 if !ctx.PrimaryArch() {
815 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700816 }
817
818 ctx.Variable(pctx, "moduleDesc", desc)
819
820 s := ""
821 if len(suffix) > 0 {
822 s = " [" + strings.Join(suffix, " ") + "]"
823 }
824 ctx.Variable(pctx, "moduleDescSuffix", s)
825
Dan Willemsen569edc52018-11-19 09:33:29 -0800826 // Some common property checks for properties that will be used later in androidmk.go
827 if a.commonProperties.Dist.Dest != nil {
828 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
829 if err != nil {
830 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
831 }
832 }
833 if a.commonProperties.Dist.Dir != nil {
834 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
835 if err != nil {
836 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
837 }
838 }
839 if a.commonProperties.Dist.Suffix != nil {
840 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
841 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
842 }
843 }
844
Colin Cross9b1d13d2016-09-19 15:18:11 -0700845 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800846 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700847 if ctx.Failed() {
848 return
849 }
850
Colin Cross0875c522017-11-28 17:34:01 -0800851 a.installFiles = append(a.installFiles, ctx.installFiles...)
852 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800853
854 if a.commonProperties.Notice != nil {
855 // For filegroup-based notice file references.
856 a.noticeFile = ctx.ExpandSource(*a.commonProperties.Notice, "notice")
857 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800858 }
859
Colin Cross9b1d13d2016-09-19 15:18:11 -0700860 if a == ctx.FinalModule().(Module).base() {
861 a.generateModuleTarget(ctx)
862 if ctx.Failed() {
863 return
864 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800865 }
Colin Crosscec81712017-07-13 14:43:27 -0700866
Colin Cross0875c522017-11-28 17:34:01 -0800867 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800868 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800869 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800870}
871
Colin Crossf6566ed2015-03-24 11:13:38 -0700872type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700873 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700874 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700875 targetPrimary bool
876 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900877 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700878 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700879}
880
Colin Cross3f40fa42015-01-30 17:27:36 -0800881type androidModuleContext struct {
882 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700883 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700884 installDeps Paths
885 installFiles Paths
886 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800887 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700888 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700889
890 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700891 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800892 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800893 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800894}
895
Colin Cross67a5c132017-05-09 13:45:28 -0700896func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800897 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700898 Rule: ErrorRule,
899 Description: desc,
900 Outputs: outputs,
901 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800902 Args: map[string]string{
903 "error": err.Error(),
904 },
905 })
906 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800907}
908
Colin Crossaabf6792017-11-29 00:27:14 -0800909func (a *androidModuleContext) Config() Config {
910 return a.ModuleContext.Config().(Config)
911}
912
Colin Cross0875c522017-11-28 17:34:01 -0800913func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700914 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800915}
916
Colin Cross0875c522017-11-28 17:34:01 -0800917func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700918 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700919 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800920 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800921 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700922 Outputs: params.Outputs.Strings(),
923 ImplicitOutputs: params.ImplicitOutputs.Strings(),
924 Inputs: params.Inputs.Strings(),
925 Implicits: params.Implicits.Strings(),
926 OrderOnly: params.OrderOnly.Strings(),
927 Args: params.Args,
928 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700929 }
930
Colin Cross33bfb0a2016-11-21 17:23:08 -0800931 if params.Depfile != nil {
932 bparams.Depfile = params.Depfile.String()
933 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700934 if params.Output != nil {
935 bparams.Outputs = append(bparams.Outputs, params.Output.String())
936 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700937 if params.ImplicitOutput != nil {
938 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
939 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700940 if params.Input != nil {
941 bparams.Inputs = append(bparams.Inputs, params.Input.String())
942 }
943 if params.Implicit != nil {
944 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
945 }
946
Colin Cross0b9f31f2019-02-28 11:00:01 -0800947 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
948 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
949 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
950 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
951 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
952 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -0700953
Colin Cross0875c522017-11-28 17:34:01 -0800954 return bparams
955}
956
957func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800958 if a.config.captureBuild {
959 a.variables[name] = value
960 }
961
Colin Cross0875c522017-11-28 17:34:01 -0800962 a.ModuleContext.Variable(pctx.PackageContext, name, value)
963}
964
965func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
966 argNames ...string) blueprint.Rule {
967
Colin Cross4c83e5c2019-02-25 14:54:28 -0800968 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
969
970 if a.config.captureBuild {
971 a.ruleParams[rule] = params
972 }
973
974 return rule
Colin Cross0875c522017-11-28 17:34:01 -0800975}
976
977func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
978 if a.config.captureBuild {
979 a.buildParams = append(a.buildParams, params)
980 }
981
982 bparams := convertBuildParams(params)
983
984 if bparams.Description != "" {
985 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
986 }
987
Colin Cross6ff51382015-12-17 16:39:19 -0800988 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -0700989 a.ninjaError(bparams.Description, bparams.Outputs,
990 fmt.Errorf("module %s missing dependencies: %s\n",
991 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -0800992 return
993 }
994
Colin Cross0875c522017-11-28 17:34:01 -0800995 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700996}
997
Colin Cross6ff51382015-12-17 16:39:19 -0800998func (a *androidModuleContext) GetMissingDependencies() []string {
999 return a.missingDeps
1000}
1001
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001002func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1003 if deps != nil {
1004 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001005 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001006 }
1007}
1008
Colin Crossd11fcda2017-10-23 17:59:01 -07001009func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1010 aModule, _ := module.(Module)
1011 if aModule == nil {
1012 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1013 return nil
1014 }
1015
1016 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001017 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001018 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1019 } else {
1020 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1021 }
1022 return nil
1023 }
1024
1025 return aModule
1026}
1027
Colin Cross35143d02017-11-16 00:11:20 -08001028func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1029 a.ModuleContext.VisitDirectDeps(visit)
1030}
1031
Colin Crossd11fcda2017-10-23 17:59:01 -07001032func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1033 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1034 if aModule := a.validateAndroidModule(module); aModule != nil {
1035 visit(aModule)
1036 }
1037 })
1038}
1039
Colin Crossee6143c2017-12-30 17:54:27 -08001040func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1041 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1042 if aModule := a.validateAndroidModule(module); aModule != nil {
1043 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1044 visit(aModule)
1045 }
1046 }
1047 })
1048}
1049
Colin Crossd11fcda2017-10-23 17:59:01 -07001050func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1051 a.ModuleContext.VisitDirectDepsIf(
1052 // pred
1053 func(module blueprint.Module) bool {
1054 if aModule := a.validateAndroidModule(module); aModule != nil {
1055 return pred(aModule)
1056 } else {
1057 return false
1058 }
1059 },
1060 // visit
1061 func(module blueprint.Module) {
1062 visit(module.(Module))
1063 })
1064}
1065
1066func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1067 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1068 if aModule := a.validateAndroidModule(module); aModule != nil {
1069 visit(aModule)
1070 }
1071 })
1072}
1073
1074func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1075 a.ModuleContext.VisitDepsDepthFirstIf(
1076 // pred
1077 func(module blueprint.Module) bool {
1078 if aModule := a.validateAndroidModule(module); aModule != nil {
1079 return pred(aModule)
1080 } else {
1081 return false
1082 }
1083 },
1084 // visit
1085 func(module blueprint.Module) {
1086 visit(module.(Module))
1087 })
1088}
1089
Alex Light778127a2019-02-27 14:19:50 -08001090func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1091 a.ModuleContext.WalkDeps(visit)
1092}
1093
Colin Crossd11fcda2017-10-23 17:59:01 -07001094func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1095 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1096 childAndroidModule := a.validateAndroidModule(child)
1097 parentAndroidModule := a.validateAndroidModule(parent)
1098 if childAndroidModule != nil && parentAndroidModule != nil {
1099 return visit(childAndroidModule, parentAndroidModule)
1100 } else {
1101 return false
1102 }
1103 })
1104}
1105
Colin Cross0875c522017-11-28 17:34:01 -08001106func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1107 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1108 visit(module.(Module))
1109 })
1110}
1111
1112func (a *androidModuleContext) PrimaryModule() Module {
1113 return a.ModuleContext.PrimaryModule().(Module)
1114}
1115
1116func (a *androidModuleContext) FinalModule() Module {
1117 return a.ModuleContext.FinalModule().(Module)
1118}
1119
Colin Crossa1ad8d12016-06-01 17:09:44 -07001120func (a *androidBaseContextImpl) Target() Target {
1121 return a.target
1122}
1123
Colin Cross8b74d172016-09-13 09:59:14 -07001124func (a *androidBaseContextImpl) TargetPrimary() bool {
1125 return a.targetPrimary
1126}
1127
Colin Crossee0bc3b2018-10-02 22:01:37 -07001128func (a *androidBaseContextImpl) MultiTargets() []Target {
1129 return a.multiTargets
1130}
1131
Colin Crossf6566ed2015-03-24 11:13:38 -07001132func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001133 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001134}
1135
Colin Crossa1ad8d12016-06-01 17:09:44 -07001136func (a *androidBaseContextImpl) Os() OsType {
1137 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001138}
1139
Colin Crossf6566ed2015-03-24 11:13:38 -07001140func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001141 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001142}
1143
1144func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001145 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001146}
1147
Colin Cross0af4b842015-04-30 16:36:18 -07001148func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001149 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001150}
1151
Doug Horn21b94272019-01-16 12:06:11 -08001152func (a *androidBaseContextImpl) Fuchsia() bool {
1153 return a.target.Os == Fuchsia
1154}
1155
Colin Cross3edeee12017-04-04 12:59:48 -07001156func (a *androidBaseContextImpl) Windows() bool {
1157 return a.target.Os == Windows
1158}
1159
Colin Crossf6566ed2015-03-24 11:13:38 -07001160func (a *androidBaseContextImpl) Debug() bool {
1161 return a.debug
1162}
1163
Colin Cross1e7d3702016-08-24 15:25:47 -07001164func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001165 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001166 return true
1167 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001168 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001169}
1170
Colin Cross1332b002015-04-07 17:11:30 -07001171func (a *androidBaseContextImpl) AConfig() Config {
1172 return a.config
1173}
1174
Colin Cross9272ade2016-08-17 15:24:12 -07001175func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1176 return DeviceConfig{a.config.deviceConfig}
1177}
1178
Jiyong Park2db76922017-11-08 16:03:48 +09001179func (a *androidBaseContextImpl) Platform() bool {
1180 return a.kind == platformModule
1181}
1182
1183func (a *androidBaseContextImpl) DeviceSpecific() bool {
1184 return a.kind == deviceSpecificModule
1185}
1186
1187func (a *androidBaseContextImpl) SocSpecific() bool {
1188 return a.kind == socSpecificModule
1189}
1190
1191func (a *androidBaseContextImpl) ProductSpecific() bool {
1192 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001193}
1194
Dario Frenifd05a742018-05-29 13:28:54 +01001195func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1196 return a.kind == productServicesSpecificModule
1197}
1198
Jiyong Park5baac542018-08-28 09:55:37 +09001199// Makes this module a platform module, i.e. not specific to soc, device,
1200// product, or product_services.
1201func (a *ModuleBase) MakeAsPlatform() {
1202 a.commonProperties.Vendor = boolPtr(false)
1203 a.commonProperties.Proprietary = boolPtr(false)
1204 a.commonProperties.Soc_specific = boolPtr(false)
1205 a.commonProperties.Product_specific = boolPtr(false)
1206 a.commonProperties.Product_services_specific = boolPtr(false)
1207}
1208
Colin Cross8d8f8e22016-08-03 11:57:50 -07001209func (a *androidModuleContext) InstallInData() bool {
1210 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001211}
1212
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001213func (a *androidModuleContext) InstallInSanitizerDir() bool {
1214 return a.module.InstallInSanitizerDir()
1215}
1216
Jiyong Parkf9332f12018-02-01 00:54:12 +09001217func (a *androidModuleContext) InstallInRecovery() bool {
1218 return a.module.InstallInRecovery()
1219}
1220
Colin Cross893d8162017-04-26 17:34:03 -07001221func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1222 if a.module.base().commonProperties.SkipInstall {
1223 return true
1224 }
1225
Colin Cross3607f212018-05-07 15:28:05 -07001226 // We'll need a solution for choosing which of modules with the same name in different
1227 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1228 // list of namespaces to install in a Soong-only build.
1229 if !a.module.base().commonProperties.NamespaceExportedToMake {
1230 return true
1231 }
1232
Colin Cross893d8162017-04-26 17:34:03 -07001233 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001234 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001235 return true
1236 }
1237
Colin Cross6510f912017-11-29 00:27:14 -08001238 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001239 return true
1240 }
1241 }
1242
1243 return false
1244}
1245
Colin Cross5c517922017-08-31 12:29:17 -07001246func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001247 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001248 return a.installFile(installPath, name, srcPath, Cp, deps)
1249}
1250
1251func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1252 deps ...Path) OutputPath {
1253 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1254}
1255
1256func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1257 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001258
Dan Willemsen782a2d12015-12-21 14:55:28 -08001259 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001260 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001261
Colin Cross893d8162017-04-26 17:34:03 -07001262 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001263
Dan Willemsen322acaf2016-01-12 23:07:05 -08001264 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001265
Colin Cross89562dc2016-10-03 17:47:19 -07001266 var implicitDeps, orderOnlyDeps Paths
1267
1268 if a.Host() {
1269 // Installed host modules might be used during the build, depend directly on their
1270 // dependencies so their timestamp is updated whenever their dependency is updated
1271 implicitDeps = deps
1272 } else {
1273 orderOnlyDeps = deps
1274 }
1275
Colin Crossae887032017-10-23 17:16:14 -07001276 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001277 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001278 Description: "install " + fullInstallPath.Base(),
1279 Output: fullInstallPath,
1280 Input: srcPath,
1281 Implicits: implicitDeps,
1282 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001283 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001284 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001285
Dan Willemsen322acaf2016-01-12 23:07:05 -08001286 a.installFiles = append(a.installFiles, fullInstallPath)
1287 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001288 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001289 return fullInstallPath
1290}
1291
Colin Cross3854a602016-01-11 12:49:11 -08001292func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1293 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001294 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001295
Colin Cross893d8162017-04-26 17:34:03 -07001296 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001297
Alex Lightfb4353d2019-01-17 13:57:45 -08001298 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1299 if err != nil {
1300 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1301 }
Colin Crossae887032017-10-23 17:16:14 -07001302 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001303 Rule: Symlink,
1304 Description: "install symlink " + fullInstallPath.Base(),
1305 Output: fullInstallPath,
1306 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001307 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001308 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001309 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001310 },
1311 })
Colin Cross3854a602016-01-11 12:49:11 -08001312
Colin Cross12fc4972016-01-11 12:49:11 -08001313 a.installFiles = append(a.installFiles, fullInstallPath)
1314 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1315 }
Colin Cross3854a602016-01-11 12:49:11 -08001316 return fullInstallPath
1317}
1318
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001319func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001320 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1321}
1322
Colin Cross3f40fa42015-01-30 17:27:36 -08001323type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001324 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001325}
1326
1327func isFileInstaller(m blueprint.Module) bool {
1328 _, ok := m.(fileInstaller)
1329 return ok
1330}
1331
1332func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001333 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001334 return ok
1335}
Colin Crossfce53272015-04-08 11:21:40 -07001336
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001337func findStringInSlice(str string, slice []string) int {
1338 for i, s := range slice {
1339 if s == str {
1340 return i
Colin Crossfce53272015-04-08 11:21:40 -07001341 }
1342 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001343 return -1
1344}
1345
Colin Cross068e0fe2016-12-13 15:23:47 -08001346func SrcIsModule(s string) string {
1347 if len(s) > 1 && s[0] == ':' {
1348 return s[1:]
1349 }
1350 return ""
1351}
1352
1353type sourceDependencyTag struct {
1354 blueprint.BaseDependencyTag
1355}
1356
1357var SourceDepTag sourceDependencyTag
1358
Colin Cross366938f2017-12-11 16:29:02 -08001359// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1360// using ":module" syntax, if any.
Colin Cross068e0fe2016-12-13 15:23:47 -08001361func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1362 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001363 set := make(map[string]bool)
1364
Colin Cross068e0fe2016-12-13 15:23:47 -08001365 for _, s := range srcFiles {
1366 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001367 if _, found := set[m]; found {
1368 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1369 } else {
1370 set[m] = true
1371 deps = append(deps, m)
1372 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001373 }
1374 }
1375
1376 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1377}
1378
Colin Cross366938f2017-12-11 16:29:02 -08001379// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1380// using ":module" syntax, if any.
1381func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1382 if s != nil {
1383 if m := SrcIsModule(*s); m != "" {
1384 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1385 }
1386 }
1387}
1388
Colin Cross068e0fe2016-12-13 15:23:47 -08001389type SourceFileProducer interface {
1390 Srcs() Paths
1391}
1392
1393// Returns a list of paths expanded from globs and modules referenced using ":module" syntax.
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001394// ExtractSourcesDeps must have already been called during the dependency resolution phase.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001395func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001396 return ctx.ExpandSourcesSubDir(srcFiles, excludes, "")
1397}
1398
Colin Cross366938f2017-12-11 16:29:02 -08001399// Returns a single path expanded from globs and modules referenced using ":module" syntax.
1400// ExtractSourceDeps must have already been called during the dependency resolution phase.
1401func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
1402 srcFiles := ctx.ExpandSourcesSubDir([]string{srcFile}, nil, "")
1403 if len(srcFiles) == 1 {
1404 return srcFiles[0]
Jaewoong Jung62707f72018-11-16 13:26:43 -08001405 } else if len(srcFiles) == 0 {
1406 if ctx.Config().AllowMissingDependencies() {
1407 ctx.AddMissingDependencies([]string{srcFile})
1408 } else {
1409 ctx.PropertyErrorf(prop, "%s path %s does not exist", prop, srcFile)
1410 }
1411 return nil
Colin Cross366938f2017-12-11 16:29:02 -08001412 } else {
1413 ctx.PropertyErrorf(prop, "module providing %s must produce exactly one file", prop)
1414 return nil
1415 }
1416}
1417
Colin Cross2383f3b2018-02-06 14:40:13 -08001418// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1419// the srcFile is non-nil.
1420// ExtractSourceDeps must have already been called during the dependency resolution phase.
1421func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1422 if srcFile != nil {
1423 return OptionalPathForPath(ctx.ExpandSource(*srcFile, prop))
1424 }
1425 return OptionalPath{}
1426}
1427
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001428func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001429 prefix := PathForModuleSrc(ctx).String()
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001430
Colin Cross461b4452018-02-23 09:22:42 -08001431 var expandedExcludes []string
1432 if excludes != nil {
1433 expandedExcludes = make([]string, 0, len(excludes))
1434 }
Nan Zhang27e284d2018-02-09 21:03:53 +00001435
1436 for _, e := range excludes {
1437 if m := SrcIsModule(e); m != "" {
1438 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
1439 if module == nil {
Colin Cross1b488422019-03-04 22:33:56 -08001440 ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m)
Nan Zhang27e284d2018-02-09 21:03:53 +00001441 continue
1442 }
1443 if srcProducer, ok := module.(SourceFileProducer); ok {
1444 expandedExcludes = append(expandedExcludes, srcProducer.Srcs().Strings()...)
1445 } else {
1446 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1447 }
1448 } else {
1449 expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e))
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001450 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001451 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001452 expandedSrcFiles := make(Paths, 0, len(srcFiles))
Colin Cross8f101b42015-06-17 15:09:06 -07001453 for _, s := range srcFiles {
Colin Cross068e0fe2016-12-13 15:23:47 -08001454 if m := SrcIsModule(s); m != "" {
1455 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
Colin Cross0617bb82017-10-24 13:01:18 -07001456 if module == nil {
Colin Cross1b488422019-03-04 22:33:56 -08001457 ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m)
Colin Cross0617bb82017-10-24 13:01:18 -07001458 continue
1459 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001460 if srcProducer, ok := module.(SourceFileProducer); ok {
Nan Zhang27e284d2018-02-09 21:03:53 +00001461 moduleSrcs := srcProducer.Srcs()
1462 for _, e := range expandedExcludes {
1463 for j, ms := range moduleSrcs {
1464 if ms.String() == e {
1465 moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...)
1466 }
1467 }
1468 }
1469 expandedSrcFiles = append(expandedSrcFiles, moduleSrcs...)
Colin Cross068e0fe2016-12-13 15:23:47 -08001470 } else {
1471 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1472 }
1473 } else if pathtools.IsGlob(s) {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001474 globbedSrcFiles := ctx.GlobFiles(filepath.Join(prefix, s), expandedExcludes)
Colin Cross05a39cb2017-10-09 13:35:19 -07001475 for i, s := range globbedSrcFiles {
1476 globbedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir)
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001477 }
Colin Cross05a39cb2017-10-09 13:35:19 -07001478 expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...)
Colin Cross8f101b42015-06-17 15:09:06 -07001479 } else {
Nan Zhang27e284d2018-02-09 21:03:53 +00001480 p := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir)
1481 j := findStringInSlice(p.String(), expandedExcludes)
1482 if j == -1 {
1483 expandedSrcFiles = append(expandedSrcFiles, p)
1484 }
1485
Colin Cross8f101b42015-06-17 15:09:06 -07001486 }
1487 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001488 return expandedSrcFiles
Colin Cross8f101b42015-06-17 15:09:06 -07001489}
1490
Nan Zhang6d34b302017-02-04 17:47:46 -08001491func (ctx *androidModuleContext) RequiredModuleNames() []string {
1492 return ctx.module.base().commonProperties.Required
1493}
1494
Colin Cross7f19f372016-11-01 11:10:25 -07001495func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1496 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001497 if err != nil {
1498 ctx.ModuleErrorf("glob: %s", err.Error())
1499 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001500 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001501}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001502
Nan Zhang581fd212018-01-10 16:06:12 -08001503func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001504 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001505 if err != nil {
1506 ctx.ModuleErrorf("glob: %s", err.Error())
1507 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001508 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001509}
1510
Colin Cross463a90e2015-06-17 14:20:06 -07001511func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001512 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001513}
1514
Colin Cross0875c522017-11-28 17:34:01 -08001515func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001516 return &buildTargetSingleton{}
1517}
1518
Colin Cross87d8b562017-04-25 10:01:55 -07001519func parentDir(dir string) string {
1520 dir, _ = filepath.Split(dir)
1521 return filepath.Clean(dir)
1522}
1523
Colin Cross1f8c52b2015-06-16 16:38:17 -07001524type buildTargetSingleton struct{}
1525
Colin Cross0875c522017-11-28 17:34:01 -08001526func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1527 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001528
Colin Cross0875c522017-11-28 17:34:01 -08001529 mmTarget := func(dir string) WritablePath {
1530 return PathForPhony(ctx,
1531 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001532 }
1533
Colin Cross0875c522017-11-28 17:34:01 -08001534 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001535
Colin Cross0875c522017-11-28 17:34:01 -08001536 ctx.VisitAllModules(func(module Module) {
1537 blueprintDir := module.base().blueprintDir
1538 installTarget := module.base().installTarget
1539 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001540
Colin Cross0875c522017-11-28 17:34:01 -08001541 if checkbuildTarget != nil {
1542 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1543 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1544 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001545
Colin Cross0875c522017-11-28 17:34:01 -08001546 if installTarget != nil {
1547 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001548 }
1549 })
1550
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001551 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001552 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001553 suffix = "-soong"
1554 }
1555
Colin Cross1f8c52b2015-06-16 16:38:17 -07001556 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001557 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001558 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001559 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001560 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001561 })
1562
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001563 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001564 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001565 return
1566 }
1567
Colin Cross0875c522017-11-28 17:34:01 -08001568 sortedKeys := func(m map[string]Paths) []string {
1569 s := make([]string, 0, len(m))
1570 for k := range m {
1571 s = append(s, k)
1572 }
1573 sort.Strings(s)
1574 return s
1575 }
1576
Colin Cross87d8b562017-04-25 10:01:55 -07001577 // Ensure ancestor directories are in modulesInDir
1578 dirs := sortedKeys(modulesInDir)
1579 for _, dir := range dirs {
1580 dir := parentDir(dir)
1581 for dir != "." && dir != "/" {
1582 if _, exists := modulesInDir[dir]; exists {
1583 break
1584 }
1585 modulesInDir[dir] = nil
1586 dir = parentDir(dir)
1587 }
1588 }
1589
1590 // Make directories build their direct subdirectories
1591 dirs = sortedKeys(modulesInDir)
1592 for _, dir := range dirs {
1593 p := parentDir(dir)
1594 if p != "." && p != "/" {
1595 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1596 }
1597 }
1598
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001599 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1600 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1601 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001602 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001603 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001604 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001605 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001606 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001607 // HACK: checkbuild should be an optional build, but force it
1608 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001609 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001610 })
1611 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001612
1613 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1614 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001615 ctx.VisitAllModules(func(module Module) {
1616 if module.Enabled() {
1617 os := module.Target().Os
1618 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001619 }
1620 })
1621
Colin Cross0875c522017-11-28 17:34:01 -08001622 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001623 for os, deps := range osDeps {
1624 var className string
1625
1626 switch os.Class {
1627 case Host:
1628 className = "host"
1629 case HostCross:
1630 className = "host-cross"
1631 case Device:
1632 className = "target"
1633 default:
1634 continue
1635 }
1636
Colin Cross0875c522017-11-28 17:34:01 -08001637 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001638 osClass[className] = append(osClass[className], name)
1639
Colin Cross0875c522017-11-28 17:34:01 -08001640 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001641 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001642 Output: name,
1643 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001644 })
1645 }
1646
1647 // Wrap those into host|host-cross|target phony rules
1648 osClasses := sortedKeys(osClass)
1649 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001650 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001651 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001652 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001653 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001654 })
1655 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001656}
Colin Crossd779da42015-12-17 18:00:23 -08001657
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001658// Collect information for opening IDE project files in java/jdeps.go.
1659type IDEInfo interface {
1660 IDEInfo(ideInfo *IdeInfo)
1661 BaseModuleName() string
1662}
1663
1664// Extract the base module name from the Import name.
1665// Often the Import name has a prefix "prebuilt_".
1666// Remove the prefix explicitly if needed
1667// until we find a better solution to get the Import name.
1668type IDECustomizedModuleName interface {
1669 IDECustomizedModuleName() string
1670}
1671
1672type IdeInfo struct {
1673 Deps []string `json:"dependencies,omitempty"`
1674 Srcs []string `json:"srcs,omitempty"`
1675 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1676 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1677 Jars []string `json:"jars,omitempty"`
1678 Classes []string `json:"class,omitempty"`
1679 Installed_paths []string `json:"installed,omitempty"`
1680}