blob: d1a779d5b69cc82320e8a37302da5f86a3145784 [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
91 Config() Config
92
93 ContainsProperty(name string) bool
94 Errorf(pos scanner.Position, fmt string, args ...interface{})
95 ModuleErrorf(fmt string, args ...interface{})
96 PropertyErrorf(property, fmt string, args ...interface{})
97 Failed() bool
98
99 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
100 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
101 // builder whenever a file matching the pattern as added or removed, without rerunning if a
102 // file that does not match the pattern is added to a searched directory.
103 GlobWithDeps(pattern string, excludes []string) ([]string, error)
104
105 Fs() pathtools.FileSystem
106 AddNinjaFileDeps(deps ...string)
107}
108
Colin Cross635c3b02016-05-18 15:37:25 -0700109type ModuleContext interface {
Colin Crossf6566ed2015-03-24 11:13:38 -0700110 androidBaseContext
Colin Crossaabf6792017-11-29 00:27:14 -0800111 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800112
Colin Crossae887032017-10-23 17:16:14 -0700113 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800114 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700115
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800117 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800118 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800119 ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths
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
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700126 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800127
128 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700129
Colin Cross8d8f8e22016-08-03 11:57:50 -0700130 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700131 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900132 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800133
134 RequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700135
136 // android.ModuleContext methods
137 // These are duplicated instead of embedded so that can eventually be wrapped to take an
138 // android.Module instead of a blueprint.Module
139 OtherModuleName(m blueprint.Module) string
140 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
141 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
142
143 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
144 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
145
146 ModuleSubDir() string
147
Colin Cross35143d02017-11-16 00:11:20 -0800148 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700149 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800150 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700151 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700152 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700153 VisitDepsDepthFirst(visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700154 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700155 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
156 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800157 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700158
Colin Cross0875c522017-11-28 17:34:01 -0800159 Variable(pctx PackageContext, name, value string)
160 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700161 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
162 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800163 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700164
Colin Cross0875c522017-11-28 17:34:01 -0800165 PrimaryModule() Module
166 FinalModule() Module
167 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700168
169 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800170 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800171}
172
Colin Cross635c3b02016-05-18 15:37:25 -0700173type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800174 blueprint.Module
175
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700176 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
177 // but GenerateAndroidBuildActions also has access to Android-specific information.
178 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700179 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700180
Colin Cross1e676be2016-10-12 14:38:15 -0700181 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800182
Colin Cross635c3b02016-05-18 15:37:25 -0700183 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800184 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700185 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800186 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700187 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900188 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800189 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900190 ExportedToMake() bool
Colin Cross36242852017-06-23 15:06:31 -0700191
192 AddProperties(props ...interface{})
193 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700194
Colin Crossae887032017-10-23 17:16:14 -0700195 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800196 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800197 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800198}
199
Colin Crossfc754582016-05-17 16:34:16 -0700200type nameProperties struct {
201 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800202 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700203}
204
205type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800206 // emit build rules for this module
207 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800208
Colin Cross7d5136f2015-05-11 13:39:40 -0700209 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800210 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
211 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
212 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700213 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700214
215 Target struct {
216 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700217 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700218 }
219 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700220 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700221 }
222 }
223
Colin Crossee0bc3b2018-10-02 22:01:37 -0700224 UseTargetVariants bool `blueprint:"mutated"`
225 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800226
Dan Willemsen782a2d12015-12-21 14:55:28 -0800227 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700228 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800229
Colin Cross55708f32017-03-20 13:23:34 -0700230 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700231 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700232
Jiyong Park2db76922017-11-08 16:03:48 +0900233 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
234 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
235 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700236 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700237
Jiyong Park2db76922017-11-08 16:03:48 +0900238 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
239 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
240 Soc_specific *bool
241
242 // whether this module is specific to a device, not only for SoC, but also for off-chip
243 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
244 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
245 // This implies `soc_specific:true`.
246 Device_specific *bool
247
248 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900249 // network operator, etc). When set to true, it is installed into /product (or
250 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900251 Product_specific *bool
252
Dario Frenifd05a742018-05-29 13:28:54 +0100253 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100254 // to true, it is installed into /product_services (or /system/product_services if
255 // product_services partition does not exist).
256 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100257
Jiyong Parkf9332f12018-02-01 00:54:12 +0900258 // Whether this module is installed to recovery partition
259 Recovery *bool
260
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700261 // init.rc files to be installed if this module is installed
262 Init_rc []string
263
Steven Moreland57a23d22018-04-04 15:42:19 -0700264 // VINTF manifest fragments to be installed if this module is installed
265 Vintf_fragments []string
266
Chris Wolfe998306e2016-08-15 14:47:23 -0400267 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700268 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400269
Colin Cross5aac3622017-08-31 15:07:09 -0700270 // relative path to a file to include in the list of notices for the device
271 Notice *string
272
Dan Willemsen569edc52018-11-19 09:33:29 -0800273 Dist struct {
274 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
275 // command line and any of these targets are also on the command line, or otherwise
276 // built
277 Targets []string `android:"arch_variant"`
278
279 // The name of the output artifact. This defaults to the basename of the output of
280 // the module.
281 Dest *string `android:"arch_variant"`
282
283 // The directory within the dist directory to store the artifact. Defaults to the
284 // top level directory ("").
285 Dir *string `android:"arch_variant"`
286
287 // A suffix to add to the artifact file name (before any extension).
288 Suffix *string `android:"arch_variant"`
289 } `android:"arch_variant"`
290
Colin Crossa1ad8d12016-06-01 17:09:44 -0700291 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700292 CompileTarget Target `blueprint:"mutated"`
293 CompileMultiTargets []Target `blueprint:"mutated"`
294 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800295
296 // Set by InitAndroidModule
297 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700298 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700299
300 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800301
302 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800303}
304
305type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800306 // If set to true, build a variant of the module for the host. Defaults to false.
307 Host_supported *bool
308
309 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700310 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800311}
312
Colin Crossc472d572015-03-17 15:06:21 -0700313type Multilib string
314
315const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800316 MultilibBoth Multilib = "both"
317 MultilibFirst Multilib = "first"
318 MultilibCommon Multilib = "common"
319 MultilibCommonFirst Multilib = "common_first"
320 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700321)
322
Colin Crossa1ad8d12016-06-01 17:09:44 -0700323type HostOrDeviceSupported int
324
325const (
326 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700327
328 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700329 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700330
331 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700332 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700333
334 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700335 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700336
337 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700338 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700339
340 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700341 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700342
343 // Nothing is supported. This is not exposed to the user, but used to mark a
344 // host only module as unsupported when the module type is not supported on
345 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700346 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700347)
348
Jiyong Park2db76922017-11-08 16:03:48 +0900349type moduleKind int
350
351const (
352 platformModule moduleKind = iota
353 deviceSpecificModule
354 socSpecificModule
355 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100356 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900357)
358
359func (k moduleKind) String() string {
360 switch k {
361 case platformModule:
362 return "platform"
363 case deviceSpecificModule:
364 return "device-specific"
365 case socSpecificModule:
366 return "soc-specific"
367 case productSpecificModule:
368 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100369 case productServicesSpecificModule:
370 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900371 default:
372 panic(fmt.Errorf("unknown module kind %d", k))
373 }
374}
375
Colin Cross36242852017-06-23 15:06:31 -0700376func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800377 base := m.base()
378 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700379
Colin Cross36242852017-06-23 15:06:31 -0700380 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700381 &base.nameProperties,
382 &base.commonProperties,
383 &base.variableProperties)
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700384 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700385}
386
Colin Cross36242852017-06-23 15:06:31 -0700387func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
388 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700389
390 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800391 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700392 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700393 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700394 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800395
Dan Willemsen218f6562015-07-08 18:13:11 -0700396 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700397 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700398 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800399 }
400
Colin Cross36242852017-06-23 15:06:31 -0700401 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800402}
403
Colin Crossee0bc3b2018-10-02 22:01:37 -0700404func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
405 InitAndroidArchModule(m, hod, defaultMultilib)
406 m.base().commonProperties.UseTargetVariants = false
407}
408
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800409// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800410// modules. It should be included as an anonymous field in every module
411// struct definition. InitAndroidModule should then be called from the module's
412// factory function, and the return values from InitAndroidModule should be
413// returned from the factory function.
414//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800415// The ModuleBase type is responsible for implementing the GenerateBuildActions
416// method to support the blueprint.Module interface. This method will then call
417// the module's GenerateAndroidBuildActions method once for each build variant
418// that is to be built. GenerateAndroidBuildActions is passed a
419// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800420// AndroidModuleContext exposes extra functionality specific to the Android build
421// system including details about the particular build variant that is to be
422// generated.
423//
424// For example:
425//
426// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800427// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800428// )
429//
430// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800431// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800432// properties struct {
433// MyProperty string
434// }
435// }
436//
Colin Cross36242852017-06-23 15:06:31 -0700437// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800438// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700439// m.AddProperties(&m.properties)
440// android.InitAndroidModule(m)
441// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800442// }
443//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800444// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800445// // Get the CPU architecture for the current build variant.
446// variantArch := ctx.Arch()
447//
448// // ...
449// }
Colin Cross635c3b02016-05-18 15:37:25 -0700450type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800451 // Putting the curiously recurring thing pointing to the thing that contains
452 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700453 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700454 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800455
Colin Crossfc754582016-05-17 16:34:16 -0700456 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800457 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700458 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800459 hostAndDeviceProperties hostAndDeviceProperties
460 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700461 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700462 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800463
464 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700465 installFiles Paths
466 checkbuildFiles Paths
Jaewoong Jung62707f72018-11-16 13:26:43 -0800467 noticeFile Path
Colin Cross1f8c52b2015-06-16 16:38:17 -0700468
469 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
470 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800471 installTarget WritablePath
472 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700473 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700474
Colin Cross178a5092016-09-13 13:42:32 -0700475 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700476
477 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700478
479 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700480 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800481 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800482 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700483
484 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700485}
486
Colin Cross5f692ec2019-02-01 16:53:07 -0800487func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
488
Colin Cross36242852017-06-23 15:06:31 -0700489func (a *ModuleBase) AddProperties(props ...interface{}) {
490 a.registerProps = append(a.registerProps, props...)
491}
492
493func (a *ModuleBase) GetProperties() []interface{} {
494 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800495}
496
Colin Crossae887032017-10-23 17:16:14 -0700497func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700498 return a.buildParams
499}
500
Colin Cross4c83e5c2019-02-25 14:54:28 -0800501func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
502 return a.ruleParams
503}
504
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800505func (a *ModuleBase) VariablesForTests() map[string]string {
506 return a.variables
507}
508
Colin Crossa9d8bee2018-10-02 13:59:46 -0700509func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
510 a.prefer32 = prefer32
511}
512
Colin Crossce75d2c2016-10-06 16:12:58 -0700513// Name returns the name of the module. It may be overridden by individual module types, for
514// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700515func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800516 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700517}
518
Colin Crossce75d2c2016-10-06 16:12:58 -0700519// BaseModuleName returns the name of the module as specified in the blueprints file.
520func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800521 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700522}
523
Colin Cross635c3b02016-05-18 15:37:25 -0700524func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800525 return a
526}
527
Colin Crossee0bc3b2018-10-02 22:01:37 -0700528func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700529 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700530 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700531 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700532}
533
Colin Crossa1ad8d12016-06-01 17:09:44 -0700534func (a *ModuleBase) Target() Target {
535 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800536}
537
Colin Cross8b74d172016-09-13 09:59:14 -0700538func (a *ModuleBase) TargetPrimary() bool {
539 return a.commonProperties.CompilePrimary
540}
541
Colin Crossee0bc3b2018-10-02 22:01:37 -0700542func (a *ModuleBase) MultiTargets() []Target {
543 return a.commonProperties.CompileMultiTargets
544}
545
Colin Crossa1ad8d12016-06-01 17:09:44 -0700546func (a *ModuleBase) Os() OsType {
547 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800548}
549
Colin Cross635c3b02016-05-18 15:37:25 -0700550func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700551 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800552}
553
Colin Cross635c3b02016-05-18 15:37:25 -0700554func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700555 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800556}
557
Dan Willemsen0b24c742016-10-04 15:13:37 -0700558func (a *ModuleBase) ArchSpecific() bool {
559 return a.commonProperties.ArchSpecific
560}
561
Colin Crossa1ad8d12016-06-01 17:09:44 -0700562func (a *ModuleBase) OsClassSupported() []OsClass {
563 switch a.commonProperties.HostOrDeviceSupported {
564 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700565 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700566 case HostSupportedNoCross:
567 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700568 case DeviceSupported:
569 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700570 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700571 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700572 if Bool(a.hostAndDeviceProperties.Host_supported) ||
573 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
574 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700575 supported = append(supported, Host, HostCross)
576 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700577 if a.hostAndDeviceProperties.Device_supported == nil ||
578 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700579 supported = append(supported, Device)
580 }
581 return supported
582 default:
583 return nil
584 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800585}
586
Colin Cross635c3b02016-05-18 15:37:25 -0700587func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800588 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
589 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700590 (a.hostAndDeviceProperties.Device_supported == nil ||
591 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800592}
593
Jiyong Parkc678ad32018-04-10 13:07:10 +0900594func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100595 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900596}
597
598func (a *ModuleBase) DeviceSpecific() bool {
599 return Bool(a.commonProperties.Device_specific)
600}
601
602func (a *ModuleBase) SocSpecific() bool {
603 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
604}
605
606func (a *ModuleBase) ProductSpecific() bool {
607 return Bool(a.commonProperties.Product_specific)
608}
609
Dario Frenifd05a742018-05-29 13:28:54 +0100610func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100611 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100612}
613
Colin Cross635c3b02016-05-18 15:37:25 -0700614func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800615 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800616 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800617 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800618 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800619}
620
Colin Crossce75d2c2016-10-06 16:12:58 -0700621func (a *ModuleBase) SkipInstall() {
622 a.commonProperties.SkipInstall = true
623}
624
Jiyong Park374510b2018-03-19 18:23:01 +0900625func (a *ModuleBase) ExportedToMake() bool {
626 return a.commonProperties.NamespaceExportedToMake
627}
628
Colin Cross635c3b02016-05-18 15:37:25 -0700629func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700630 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800631
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700632 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700633 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800634 ctx.VisitDepsDepthFirstIf(isFileInstaller,
635 func(m blueprint.Module) {
636 fileInstaller := m.(fileInstaller)
637 files := fileInstaller.filesToInstall()
638 result = append(result, files...)
639 })
640
641 return result
642}
643
Colin Cross635c3b02016-05-18 15:37:25 -0700644func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800645 return a.installFiles
646}
647
Colin Cross635c3b02016-05-18 15:37:25 -0700648func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800649 return p.noAddressSanitizer
650}
651
Colin Cross635c3b02016-05-18 15:37:25 -0700652func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800653 return false
654}
655
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700656func (p *ModuleBase) InstallInSanitizerDir() bool {
657 return false
658}
659
Jiyong Parkf9332f12018-02-01 00:54:12 +0900660func (p *ModuleBase) InstallInRecovery() bool {
661 return Bool(p.commonProperties.Recovery)
662}
663
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900664func (a *ModuleBase) Owner() string {
665 return String(a.commonProperties.Owner)
666}
667
Colin Cross0875c522017-11-28 17:34:01 -0800668func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700669 allInstalledFiles := Paths{}
670 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800671 ctx.VisitAllModuleVariants(func(module Module) {
672 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700673 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
674 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800675 })
676
Colin Cross0875c522017-11-28 17:34:01 -0800677 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700678
Jeff Gaston088e29e2017-11-29 16:47:17 -0800679 namespacePrefix := ctx.Namespace().(*Namespace).id
680 if namespacePrefix != "" {
681 namespacePrefix = namespacePrefix + "-"
682 }
683
Colin Cross3f40fa42015-01-30 17:27:36 -0800684 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800685 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800686 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700687 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800688 Output: name,
689 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800690 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700691 })
692 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700693 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700694 }
695
696 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800697 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800698 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700699 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800700 Output: name,
701 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700702 })
703 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700704 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700705 }
706
707 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800708 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800709 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800710 suffix = "-soong"
711 }
712
Jeff Gaston088e29e2017-11-29 16:47:17 -0800713 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800714 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700715 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800716 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700717 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800718 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700719
720 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800721 }
722}
723
Jiyong Park2db76922017-11-08 16:03:48 +0900724func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
725 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
726 var deviceSpecific = Bool(a.commonProperties.Device_specific)
727 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100728 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900729
Dario Frenifd05a742018-05-29 13:28:54 +0100730 msg := "conflicting value set here"
731 if socSpecific && deviceSpecific {
732 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900733 if Bool(a.commonProperties.Vendor) {
734 ctx.PropertyErrorf("vendor", msg)
735 }
736 if Bool(a.commonProperties.Proprietary) {
737 ctx.PropertyErrorf("proprietary", msg)
738 }
739 if Bool(a.commonProperties.Soc_specific) {
740 ctx.PropertyErrorf("soc_specific", msg)
741 }
742 }
743
Dario Frenifd05a742018-05-29 13:28:54 +0100744 if productSpecific && productServicesSpecific {
745 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
746 ctx.PropertyErrorf("product_services_specific", msg)
747 }
748
749 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
750 if productSpecific {
751 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
752 } else {
753 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
754 }
755 if deviceSpecific {
756 ctx.PropertyErrorf("device_specific", msg)
757 } else {
758 if Bool(a.commonProperties.Vendor) {
759 ctx.PropertyErrorf("vendor", msg)
760 }
761 if Bool(a.commonProperties.Proprietary) {
762 ctx.PropertyErrorf("proprietary", msg)
763 }
764 if Bool(a.commonProperties.Soc_specific) {
765 ctx.PropertyErrorf("soc_specific", msg)
766 }
767 }
768 }
769
Jiyong Park2db76922017-11-08 16:03:48 +0900770 if productSpecific {
771 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100772 } else if productServicesSpecific {
773 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900774 } else if deviceSpecific {
775 return deviceSpecificModule
776 } else if socSpecific {
777 return socSpecificModule
778 } else {
779 return platformModule
780 }
781}
782
Colin Cross635c3b02016-05-18 15:37:25 -0700783func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700784 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700785 target: a.commonProperties.CompileTarget,
786 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700787 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900788 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700789 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800790 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800791}
792
Colin Cross0875c522017-11-28 17:34:01 -0800793func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
794 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700795 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800796 ModuleContext: blueprintCtx,
797 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
798 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700799 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800800 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800801 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800802 }
803
Colin Cross4c83e5c2019-02-25 14:54:28 -0800804 if ctx.config.captureBuild {
805 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
806 }
807
Colin Cross67a5c132017-05-09 13:45:28 -0700808 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
809 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800810 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
811 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700812 }
Colin Cross0875c522017-11-28 17:34:01 -0800813 if !ctx.PrimaryArch() {
814 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700815 }
816
817 ctx.Variable(pctx, "moduleDesc", desc)
818
819 s := ""
820 if len(suffix) > 0 {
821 s = " [" + strings.Join(suffix, " ") + "]"
822 }
823 ctx.Variable(pctx, "moduleDescSuffix", s)
824
Dan Willemsen569edc52018-11-19 09:33:29 -0800825 // Some common property checks for properties that will be used later in androidmk.go
826 if a.commonProperties.Dist.Dest != nil {
827 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
828 if err != nil {
829 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
830 }
831 }
832 if a.commonProperties.Dist.Dir != nil {
833 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
834 if err != nil {
835 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
836 }
837 }
838 if a.commonProperties.Dist.Suffix != nil {
839 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
840 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
841 }
842 }
843
Colin Cross9b1d13d2016-09-19 15:18:11 -0700844 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800845 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700846 if ctx.Failed() {
847 return
848 }
849
Colin Cross0875c522017-11-28 17:34:01 -0800850 a.installFiles = append(a.installFiles, ctx.installFiles...)
851 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800852
853 if a.commonProperties.Notice != nil {
854 // For filegroup-based notice file references.
855 a.noticeFile = ctx.ExpandSource(*a.commonProperties.Notice, "notice")
856 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800857 }
858
Colin Cross9b1d13d2016-09-19 15:18:11 -0700859 if a == ctx.FinalModule().(Module).base() {
860 a.generateModuleTarget(ctx)
861 if ctx.Failed() {
862 return
863 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800864 }
Colin Crosscec81712017-07-13 14:43:27 -0700865
Colin Cross0875c522017-11-28 17:34:01 -0800866 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800867 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800868 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800869}
870
Colin Crossf6566ed2015-03-24 11:13:38 -0700871type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700872 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700873 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700874 targetPrimary bool
875 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900876 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700877 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700878}
879
Colin Cross3f40fa42015-01-30 17:27:36 -0800880type androidModuleContext struct {
881 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700882 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700883 installDeps Paths
884 installFiles Paths
885 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800886 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700887 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700888
889 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700890 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800891 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800892 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800893}
894
Colin Cross67a5c132017-05-09 13:45:28 -0700895func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800896 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700897 Rule: ErrorRule,
898 Description: desc,
899 Outputs: outputs,
900 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800901 Args: map[string]string{
902 "error": err.Error(),
903 },
904 })
905 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800906}
907
Colin Crossaabf6792017-11-29 00:27:14 -0800908func (a *androidModuleContext) Config() Config {
909 return a.ModuleContext.Config().(Config)
910}
911
Colin Cross0875c522017-11-28 17:34:01 -0800912func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700913 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800914}
915
Colin Cross0875c522017-11-28 17:34:01 -0800916func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700917 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700918 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800919 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800920 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700921 Outputs: params.Outputs.Strings(),
922 ImplicitOutputs: params.ImplicitOutputs.Strings(),
923 Inputs: params.Inputs.Strings(),
924 Implicits: params.Implicits.Strings(),
925 OrderOnly: params.OrderOnly.Strings(),
926 Args: params.Args,
927 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700928 }
929
Colin Cross33bfb0a2016-11-21 17:23:08 -0800930 if params.Depfile != nil {
931 bparams.Depfile = params.Depfile.String()
932 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700933 if params.Output != nil {
934 bparams.Outputs = append(bparams.Outputs, params.Output.String())
935 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700936 if params.ImplicitOutput != nil {
937 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
938 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700939 if params.Input != nil {
940 bparams.Inputs = append(bparams.Inputs, params.Input.String())
941 }
942 if params.Implicit != nil {
943 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
944 }
945
Colin Cross0b9f31f2019-02-28 11:00:01 -0800946 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
947 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
948 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
949 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
950 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
951 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -0700952
Colin Cross0875c522017-11-28 17:34:01 -0800953 return bparams
954}
955
956func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800957 if a.config.captureBuild {
958 a.variables[name] = value
959 }
960
Colin Cross0875c522017-11-28 17:34:01 -0800961 a.ModuleContext.Variable(pctx.PackageContext, name, value)
962}
963
964func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
965 argNames ...string) blueprint.Rule {
966
Colin Cross4c83e5c2019-02-25 14:54:28 -0800967 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
968
969 if a.config.captureBuild {
970 a.ruleParams[rule] = params
971 }
972
973 return rule
Colin Cross0875c522017-11-28 17:34:01 -0800974}
975
976func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
977 if a.config.captureBuild {
978 a.buildParams = append(a.buildParams, params)
979 }
980
981 bparams := convertBuildParams(params)
982
983 if bparams.Description != "" {
984 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
985 }
986
Colin Cross6ff51382015-12-17 16:39:19 -0800987 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -0700988 a.ninjaError(bparams.Description, bparams.Outputs,
989 fmt.Errorf("module %s missing dependencies: %s\n",
990 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -0800991 return
992 }
993
Colin Cross0875c522017-11-28 17:34:01 -0800994 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700995}
996
Colin Cross6ff51382015-12-17 16:39:19 -0800997func (a *androidModuleContext) GetMissingDependencies() []string {
998 return a.missingDeps
999}
1000
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001001func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1002 if deps != nil {
1003 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001004 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001005 }
1006}
1007
Colin Crossd11fcda2017-10-23 17:59:01 -07001008func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1009 aModule, _ := module.(Module)
1010 if aModule == nil {
1011 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1012 return nil
1013 }
1014
1015 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001016 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001017 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1018 } else {
1019 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1020 }
1021 return nil
1022 }
1023
1024 return aModule
1025}
1026
Colin Cross35143d02017-11-16 00:11:20 -08001027func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1028 a.ModuleContext.VisitDirectDeps(visit)
1029}
1030
Colin Crossd11fcda2017-10-23 17:59:01 -07001031func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1032 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1033 if aModule := a.validateAndroidModule(module); aModule != nil {
1034 visit(aModule)
1035 }
1036 })
1037}
1038
Colin Crossee6143c2017-12-30 17:54:27 -08001039func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1040 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1041 if aModule := a.validateAndroidModule(module); aModule != nil {
1042 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1043 visit(aModule)
1044 }
1045 }
1046 })
1047}
1048
Colin Crossd11fcda2017-10-23 17:59:01 -07001049func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1050 a.ModuleContext.VisitDirectDepsIf(
1051 // pred
1052 func(module blueprint.Module) bool {
1053 if aModule := a.validateAndroidModule(module); aModule != nil {
1054 return pred(aModule)
1055 } else {
1056 return false
1057 }
1058 },
1059 // visit
1060 func(module blueprint.Module) {
1061 visit(module.(Module))
1062 })
1063}
1064
1065func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1066 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1067 if aModule := a.validateAndroidModule(module); aModule != nil {
1068 visit(aModule)
1069 }
1070 })
1071}
1072
1073func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1074 a.ModuleContext.VisitDepsDepthFirstIf(
1075 // pred
1076 func(module blueprint.Module) bool {
1077 if aModule := a.validateAndroidModule(module); aModule != nil {
1078 return pred(aModule)
1079 } else {
1080 return false
1081 }
1082 },
1083 // visit
1084 func(module blueprint.Module) {
1085 visit(module.(Module))
1086 })
1087}
1088
Alex Light778127a2019-02-27 14:19:50 -08001089func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1090 a.ModuleContext.WalkDeps(visit)
1091}
1092
Colin Crossd11fcda2017-10-23 17:59:01 -07001093func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1094 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1095 childAndroidModule := a.validateAndroidModule(child)
1096 parentAndroidModule := a.validateAndroidModule(parent)
1097 if childAndroidModule != nil && parentAndroidModule != nil {
1098 return visit(childAndroidModule, parentAndroidModule)
1099 } else {
1100 return false
1101 }
1102 })
1103}
1104
Colin Cross0875c522017-11-28 17:34:01 -08001105func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1106 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1107 visit(module.(Module))
1108 })
1109}
1110
1111func (a *androidModuleContext) PrimaryModule() Module {
1112 return a.ModuleContext.PrimaryModule().(Module)
1113}
1114
1115func (a *androidModuleContext) FinalModule() Module {
1116 return a.ModuleContext.FinalModule().(Module)
1117}
1118
Colin Crossa1ad8d12016-06-01 17:09:44 -07001119func (a *androidBaseContextImpl) Target() Target {
1120 return a.target
1121}
1122
Colin Cross8b74d172016-09-13 09:59:14 -07001123func (a *androidBaseContextImpl) TargetPrimary() bool {
1124 return a.targetPrimary
1125}
1126
Colin Crossee0bc3b2018-10-02 22:01:37 -07001127func (a *androidBaseContextImpl) MultiTargets() []Target {
1128 return a.multiTargets
1129}
1130
Colin Crossf6566ed2015-03-24 11:13:38 -07001131func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001132 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001133}
1134
Colin Crossa1ad8d12016-06-01 17:09:44 -07001135func (a *androidBaseContextImpl) Os() OsType {
1136 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001137}
1138
Colin Crossf6566ed2015-03-24 11:13:38 -07001139func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001140 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001141}
1142
1143func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001144 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001145}
1146
Colin Cross0af4b842015-04-30 16:36:18 -07001147func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001148 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001149}
1150
Doug Horn21b94272019-01-16 12:06:11 -08001151func (a *androidBaseContextImpl) Fuchsia() bool {
1152 return a.target.Os == Fuchsia
1153}
1154
Colin Cross3edeee12017-04-04 12:59:48 -07001155func (a *androidBaseContextImpl) Windows() bool {
1156 return a.target.Os == Windows
1157}
1158
Colin Crossf6566ed2015-03-24 11:13:38 -07001159func (a *androidBaseContextImpl) Debug() bool {
1160 return a.debug
1161}
1162
Colin Cross1e7d3702016-08-24 15:25:47 -07001163func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001164 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001165 return true
1166 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001167 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001168}
1169
Colin Cross1332b002015-04-07 17:11:30 -07001170func (a *androidBaseContextImpl) AConfig() Config {
1171 return a.config
1172}
1173
Colin Cross9272ade2016-08-17 15:24:12 -07001174func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1175 return DeviceConfig{a.config.deviceConfig}
1176}
1177
Jiyong Park2db76922017-11-08 16:03:48 +09001178func (a *androidBaseContextImpl) Platform() bool {
1179 return a.kind == platformModule
1180}
1181
1182func (a *androidBaseContextImpl) DeviceSpecific() bool {
1183 return a.kind == deviceSpecificModule
1184}
1185
1186func (a *androidBaseContextImpl) SocSpecific() bool {
1187 return a.kind == socSpecificModule
1188}
1189
1190func (a *androidBaseContextImpl) ProductSpecific() bool {
1191 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001192}
1193
Dario Frenifd05a742018-05-29 13:28:54 +01001194func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1195 return a.kind == productServicesSpecificModule
1196}
1197
Jiyong Park5baac542018-08-28 09:55:37 +09001198// Makes this module a platform module, i.e. not specific to soc, device,
1199// product, or product_services.
1200func (a *ModuleBase) MakeAsPlatform() {
1201 a.commonProperties.Vendor = boolPtr(false)
1202 a.commonProperties.Proprietary = boolPtr(false)
1203 a.commonProperties.Soc_specific = boolPtr(false)
1204 a.commonProperties.Product_specific = boolPtr(false)
1205 a.commonProperties.Product_services_specific = boolPtr(false)
1206}
1207
Colin Cross8d8f8e22016-08-03 11:57:50 -07001208func (a *androidModuleContext) InstallInData() bool {
1209 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001210}
1211
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001212func (a *androidModuleContext) InstallInSanitizerDir() bool {
1213 return a.module.InstallInSanitizerDir()
1214}
1215
Jiyong Parkf9332f12018-02-01 00:54:12 +09001216func (a *androidModuleContext) InstallInRecovery() bool {
1217 return a.module.InstallInRecovery()
1218}
1219
Colin Cross893d8162017-04-26 17:34:03 -07001220func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1221 if a.module.base().commonProperties.SkipInstall {
1222 return true
1223 }
1224
Colin Cross3607f212018-05-07 15:28:05 -07001225 // We'll need a solution for choosing which of modules with the same name in different
1226 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1227 // list of namespaces to install in a Soong-only build.
1228 if !a.module.base().commonProperties.NamespaceExportedToMake {
1229 return true
1230 }
1231
Colin Cross893d8162017-04-26 17:34:03 -07001232 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001233 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001234 return true
1235 }
1236
Colin Cross6510f912017-11-29 00:27:14 -08001237 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001238 return true
1239 }
1240 }
1241
1242 return false
1243}
1244
Colin Cross5c517922017-08-31 12:29:17 -07001245func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001246 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001247 return a.installFile(installPath, name, srcPath, Cp, deps)
1248}
1249
1250func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1251 deps ...Path) OutputPath {
1252 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1253}
1254
1255func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1256 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001257
Dan Willemsen782a2d12015-12-21 14:55:28 -08001258 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001259 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001260
Colin Cross893d8162017-04-26 17:34:03 -07001261 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001262
Dan Willemsen322acaf2016-01-12 23:07:05 -08001263 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001264
Colin Cross89562dc2016-10-03 17:47:19 -07001265 var implicitDeps, orderOnlyDeps Paths
1266
1267 if a.Host() {
1268 // Installed host modules might be used during the build, depend directly on their
1269 // dependencies so their timestamp is updated whenever their dependency is updated
1270 implicitDeps = deps
1271 } else {
1272 orderOnlyDeps = deps
1273 }
1274
Colin Crossae887032017-10-23 17:16:14 -07001275 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001276 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001277 Description: "install " + fullInstallPath.Base(),
1278 Output: fullInstallPath,
1279 Input: srcPath,
1280 Implicits: implicitDeps,
1281 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001282 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001283 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001284
Dan Willemsen322acaf2016-01-12 23:07:05 -08001285 a.installFiles = append(a.installFiles, fullInstallPath)
1286 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001287 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001288 return fullInstallPath
1289}
1290
Colin Cross3854a602016-01-11 12:49:11 -08001291func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1292 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001293 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001294
Colin Cross893d8162017-04-26 17:34:03 -07001295 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001296
Alex Lightfb4353d2019-01-17 13:57:45 -08001297 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1298 if err != nil {
1299 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1300 }
Colin Crossae887032017-10-23 17:16:14 -07001301 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001302 Rule: Symlink,
1303 Description: "install symlink " + fullInstallPath.Base(),
1304 Output: fullInstallPath,
1305 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001306 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001307 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001308 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001309 },
1310 })
Colin Cross3854a602016-01-11 12:49:11 -08001311
Colin Cross12fc4972016-01-11 12:49:11 -08001312 a.installFiles = append(a.installFiles, fullInstallPath)
1313 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1314 }
Colin Cross3854a602016-01-11 12:49:11 -08001315 return fullInstallPath
1316}
1317
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001318func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001319 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1320}
1321
Colin Cross3f40fa42015-01-30 17:27:36 -08001322type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001323 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001324}
1325
1326func isFileInstaller(m blueprint.Module) bool {
1327 _, ok := m.(fileInstaller)
1328 return ok
1329}
1330
1331func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001332 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001333 return ok
1334}
Colin Crossfce53272015-04-08 11:21:40 -07001335
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001336func findStringInSlice(str string, slice []string) int {
1337 for i, s := range slice {
1338 if s == str {
1339 return i
Colin Crossfce53272015-04-08 11:21:40 -07001340 }
1341 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001342 return -1
1343}
1344
Colin Cross068e0fe2016-12-13 15:23:47 -08001345func SrcIsModule(s string) string {
1346 if len(s) > 1 && s[0] == ':' {
1347 return s[1:]
1348 }
1349 return ""
1350}
1351
1352type sourceDependencyTag struct {
1353 blueprint.BaseDependencyTag
1354}
1355
1356var SourceDepTag sourceDependencyTag
1357
Colin Cross366938f2017-12-11 16:29:02 -08001358// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1359// using ":module" syntax, if any.
Colin Cross068e0fe2016-12-13 15:23:47 -08001360func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1361 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001362 set := make(map[string]bool)
1363
Colin Cross068e0fe2016-12-13 15:23:47 -08001364 for _, s := range srcFiles {
1365 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001366 if _, found := set[m]; found {
1367 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1368 } else {
1369 set[m] = true
1370 deps = append(deps, m)
1371 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001372 }
1373 }
1374
1375 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1376}
1377
Colin Cross366938f2017-12-11 16:29:02 -08001378// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1379// using ":module" syntax, if any.
1380func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1381 if s != nil {
1382 if m := SrcIsModule(*s); m != "" {
1383 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1384 }
1385 }
1386}
1387
Colin Cross068e0fe2016-12-13 15:23:47 -08001388type SourceFileProducer interface {
1389 Srcs() Paths
1390}
1391
1392// Returns a list of paths expanded from globs and modules referenced using ":module" syntax.
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001393// ExtractSourcesDeps must have already been called during the dependency resolution phase.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001394func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001395 return ctx.ExpandSourcesSubDir(srcFiles, excludes, "")
1396}
1397
Colin Cross366938f2017-12-11 16:29:02 -08001398// Returns a single path expanded from globs and modules referenced using ":module" syntax.
1399// ExtractSourceDeps must have already been called during the dependency resolution phase.
1400func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
1401 srcFiles := ctx.ExpandSourcesSubDir([]string{srcFile}, nil, "")
1402 if len(srcFiles) == 1 {
1403 return srcFiles[0]
Jaewoong Jung62707f72018-11-16 13:26:43 -08001404 } else if len(srcFiles) == 0 {
1405 if ctx.Config().AllowMissingDependencies() {
1406 ctx.AddMissingDependencies([]string{srcFile})
1407 } else {
1408 ctx.PropertyErrorf(prop, "%s path %s does not exist", prop, srcFile)
1409 }
1410 return nil
Colin Cross366938f2017-12-11 16:29:02 -08001411 } else {
1412 ctx.PropertyErrorf(prop, "module providing %s must produce exactly one file", prop)
1413 return nil
1414 }
1415}
1416
Colin Cross2383f3b2018-02-06 14:40:13 -08001417// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1418// the srcFile is non-nil.
1419// ExtractSourceDeps must have already been called during the dependency resolution phase.
1420func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1421 if srcFile != nil {
1422 return OptionalPathForPath(ctx.ExpandSource(*srcFile, prop))
1423 }
1424 return OptionalPath{}
1425}
1426
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001427func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001428 prefix := PathForModuleSrc(ctx).String()
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001429
Colin Cross461b4452018-02-23 09:22:42 -08001430 var expandedExcludes []string
1431 if excludes != nil {
1432 expandedExcludes = make([]string, 0, len(excludes))
1433 }
Nan Zhang27e284d2018-02-09 21:03:53 +00001434
1435 for _, e := range excludes {
1436 if m := SrcIsModule(e); m != "" {
1437 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
1438 if module == nil {
1439 // Error will have been handled by ExtractSourcesDeps
1440 continue
1441 }
1442 if srcProducer, ok := module.(SourceFileProducer); ok {
1443 expandedExcludes = append(expandedExcludes, srcProducer.Srcs().Strings()...)
1444 } else {
1445 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1446 }
1447 } else {
1448 expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e))
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001449 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001450 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001451 expandedSrcFiles := make(Paths, 0, len(srcFiles))
Colin Cross8f101b42015-06-17 15:09:06 -07001452 for _, s := range srcFiles {
Colin Cross068e0fe2016-12-13 15:23:47 -08001453 if m := SrcIsModule(s); m != "" {
1454 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
Colin Cross0617bb82017-10-24 13:01:18 -07001455 if module == nil {
1456 // Error will have been handled by ExtractSourcesDeps
1457 continue
1458 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001459 if srcProducer, ok := module.(SourceFileProducer); ok {
Nan Zhang27e284d2018-02-09 21:03:53 +00001460 moduleSrcs := srcProducer.Srcs()
1461 for _, e := range expandedExcludes {
1462 for j, ms := range moduleSrcs {
1463 if ms.String() == e {
1464 moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...)
1465 }
1466 }
1467 }
1468 expandedSrcFiles = append(expandedSrcFiles, moduleSrcs...)
Colin Cross068e0fe2016-12-13 15:23:47 -08001469 } else {
1470 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1471 }
1472 } else if pathtools.IsGlob(s) {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001473 globbedSrcFiles := ctx.GlobFiles(filepath.Join(prefix, s), expandedExcludes)
Colin Cross05a39cb2017-10-09 13:35:19 -07001474 for i, s := range globbedSrcFiles {
1475 globbedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir)
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001476 }
Colin Cross05a39cb2017-10-09 13:35:19 -07001477 expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...)
Colin Cross8f101b42015-06-17 15:09:06 -07001478 } else {
Nan Zhang27e284d2018-02-09 21:03:53 +00001479 p := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir)
1480 j := findStringInSlice(p.String(), expandedExcludes)
1481 if j == -1 {
1482 expandedSrcFiles = append(expandedSrcFiles, p)
1483 }
1484
Colin Cross8f101b42015-06-17 15:09:06 -07001485 }
1486 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001487 return expandedSrcFiles
Colin Cross8f101b42015-06-17 15:09:06 -07001488}
1489
Nan Zhang6d34b302017-02-04 17:47:46 -08001490func (ctx *androidModuleContext) RequiredModuleNames() []string {
1491 return ctx.module.base().commonProperties.Required
1492}
1493
Colin Cross7f19f372016-11-01 11:10:25 -07001494func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1495 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001496 if err != nil {
1497 ctx.ModuleErrorf("glob: %s", err.Error())
1498 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001499 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001500}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001501
Nan Zhang581fd212018-01-10 16:06:12 -08001502func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001503 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001504 if err != nil {
1505 ctx.ModuleErrorf("glob: %s", err.Error())
1506 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001507 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001508}
1509
Colin Cross463a90e2015-06-17 14:20:06 -07001510func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001511 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001512}
1513
Colin Cross0875c522017-11-28 17:34:01 -08001514func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001515 return &buildTargetSingleton{}
1516}
1517
Colin Cross87d8b562017-04-25 10:01:55 -07001518func parentDir(dir string) string {
1519 dir, _ = filepath.Split(dir)
1520 return filepath.Clean(dir)
1521}
1522
Colin Cross1f8c52b2015-06-16 16:38:17 -07001523type buildTargetSingleton struct{}
1524
Colin Cross0875c522017-11-28 17:34:01 -08001525func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1526 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001527
Colin Cross0875c522017-11-28 17:34:01 -08001528 mmTarget := func(dir string) WritablePath {
1529 return PathForPhony(ctx,
1530 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001531 }
1532
Colin Cross0875c522017-11-28 17:34:01 -08001533 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001534
Colin Cross0875c522017-11-28 17:34:01 -08001535 ctx.VisitAllModules(func(module Module) {
1536 blueprintDir := module.base().blueprintDir
1537 installTarget := module.base().installTarget
1538 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001539
Colin Cross0875c522017-11-28 17:34:01 -08001540 if checkbuildTarget != nil {
1541 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1542 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1543 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001544
Colin Cross0875c522017-11-28 17:34:01 -08001545 if installTarget != nil {
1546 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001547 }
1548 })
1549
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001550 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001551 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001552 suffix = "-soong"
1553 }
1554
Colin Cross1f8c52b2015-06-16 16:38:17 -07001555 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001556 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001557 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001558 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001559 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001560 })
1561
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001562 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001563 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001564 return
1565 }
1566
Colin Cross0875c522017-11-28 17:34:01 -08001567 sortedKeys := func(m map[string]Paths) []string {
1568 s := make([]string, 0, len(m))
1569 for k := range m {
1570 s = append(s, k)
1571 }
1572 sort.Strings(s)
1573 return s
1574 }
1575
Colin Cross87d8b562017-04-25 10:01:55 -07001576 // Ensure ancestor directories are in modulesInDir
1577 dirs := sortedKeys(modulesInDir)
1578 for _, dir := range dirs {
1579 dir := parentDir(dir)
1580 for dir != "." && dir != "/" {
1581 if _, exists := modulesInDir[dir]; exists {
1582 break
1583 }
1584 modulesInDir[dir] = nil
1585 dir = parentDir(dir)
1586 }
1587 }
1588
1589 // Make directories build their direct subdirectories
1590 dirs = sortedKeys(modulesInDir)
1591 for _, dir := range dirs {
1592 p := parentDir(dir)
1593 if p != "." && p != "/" {
1594 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1595 }
1596 }
1597
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001598 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1599 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1600 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001601 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001602 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001603 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001604 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001605 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001606 // HACK: checkbuild should be an optional build, but force it
1607 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001608 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001609 })
1610 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001611
1612 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1613 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001614 ctx.VisitAllModules(func(module Module) {
1615 if module.Enabled() {
1616 os := module.Target().Os
1617 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001618 }
1619 })
1620
Colin Cross0875c522017-11-28 17:34:01 -08001621 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001622 for os, deps := range osDeps {
1623 var className string
1624
1625 switch os.Class {
1626 case Host:
1627 className = "host"
1628 case HostCross:
1629 className = "host-cross"
1630 case Device:
1631 className = "target"
1632 default:
1633 continue
1634 }
1635
Colin Cross0875c522017-11-28 17:34:01 -08001636 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001637 osClass[className] = append(osClass[className], name)
1638
Colin Cross0875c522017-11-28 17:34:01 -08001639 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001640 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001641 Output: name,
1642 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001643 })
1644 }
1645
1646 // Wrap those into host|host-cross|target phony rules
1647 osClasses := sortedKeys(osClass)
1648 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001649 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001650 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001651 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001652 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001653 })
1654 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001655}
Colin Crossd779da42015-12-17 18:00:23 -08001656
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001657// Collect information for opening IDE project files in java/jdeps.go.
1658type IDEInfo interface {
1659 IDEInfo(ideInfo *IdeInfo)
1660 BaseModuleName() string
1661}
1662
1663// Extract the base module name from the Import name.
1664// Often the Import name has a prefix "prebuilt_".
1665// Remove the prefix explicitly if needed
1666// until we find a better solution to get the Import name.
1667type IDECustomizedModuleName interface {
1668 IDECustomizedModuleName() string
1669}
1670
1671type IdeInfo struct {
1672 Deps []string `json:"dependencies,omitempty"`
1673 Srcs []string `json:"srcs,omitempty"`
1674 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1675 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1676 Jars []string `json:"jars,omitempty"`
1677 Classes []string `json:"class,omitempty"`
1678 Installed_paths []string `json:"installed,omitempty"`
1679}