blob: 9a69a26313423c40b664c491b337d16a18345825 [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
Jiyong Parkf1194352019-02-25 11:05:47 +0900127 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700128 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800129
130 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700131
Colin Cross8d8f8e22016-08-03 11:57:50 -0700132 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700133 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900134 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800135
136 RequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700137
138 // android.ModuleContext methods
139 // These are duplicated instead of embedded so that can eventually be wrapped to take an
140 // android.Module instead of a blueprint.Module
141 OtherModuleName(m blueprint.Module) string
142 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
143 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
144
145 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
146 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
147
148 ModuleSubDir() string
149
Colin Cross35143d02017-11-16 00:11:20 -0800150 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700151 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800152 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700153 VisitDirectDepsIf(pred func(Module) bool, 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 VisitDepsDepthFirst(visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700156 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700157 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
158 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800159 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700160
Colin Cross0875c522017-11-28 17:34:01 -0800161 Variable(pctx PackageContext, name, value string)
162 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700163 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
164 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800165 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700166
Colin Cross0875c522017-11-28 17:34:01 -0800167 PrimaryModule() Module
168 FinalModule() Module
169 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700170
171 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800172 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800173}
174
Colin Cross635c3b02016-05-18 15:37:25 -0700175type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800176 blueprint.Module
177
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700178 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
179 // but GenerateAndroidBuildActions also has access to Android-specific information.
180 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700181 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700182
Colin Cross1e676be2016-10-12 14:38:15 -0700183 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800184
Colin Cross635c3b02016-05-18 15:37:25 -0700185 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800186 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700187 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800188 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700189 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900190 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800191 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900192 ExportedToMake() bool
Colin Cross36242852017-06-23 15:06:31 -0700193
194 AddProperties(props ...interface{})
195 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700196
Colin Crossae887032017-10-23 17:16:14 -0700197 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800198 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800199 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800200}
201
Colin Crossfc754582016-05-17 16:34:16 -0700202type nameProperties struct {
203 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800204 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700205}
206
207type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800208 // emit build rules for this module
209 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800210
Colin Cross7d5136f2015-05-11 13:39:40 -0700211 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800212 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
213 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
214 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700215 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700216
217 Target struct {
218 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700219 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700220 }
221 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700222 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700223 }
224 }
225
Colin Crossee0bc3b2018-10-02 22:01:37 -0700226 UseTargetVariants bool `blueprint:"mutated"`
227 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800228
Dan Willemsen782a2d12015-12-21 14:55:28 -0800229 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700230 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800231
Colin Cross55708f32017-03-20 13:23:34 -0700232 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700233 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700234
Jiyong Park2db76922017-11-08 16:03:48 +0900235 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
236 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
237 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700238 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700239
Jiyong Park2db76922017-11-08 16:03:48 +0900240 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
241 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
242 Soc_specific *bool
243
244 // whether this module is specific to a device, not only for SoC, but also for off-chip
245 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
246 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
247 // This implies `soc_specific:true`.
248 Device_specific *bool
249
250 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900251 // network operator, etc). When set to true, it is installed into /product (or
252 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900253 Product_specific *bool
254
Dario Frenifd05a742018-05-29 13:28:54 +0100255 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100256 // to true, it is installed into /product_services (or /system/product_services if
257 // product_services partition does not exist).
258 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100259
Jiyong Parkf9332f12018-02-01 00:54:12 +0900260 // Whether this module is installed to recovery partition
261 Recovery *bool
262
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700263 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800264 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700265
Steven Moreland57a23d22018-04-04 15:42:19 -0700266 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800267 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700268
Chris Wolfe998306e2016-08-15 14:47:23 -0400269 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700270 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400271
Colin Cross5aac3622017-08-31 15:07:09 -0700272 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800273 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700274
Dan Willemsen569edc52018-11-19 09:33:29 -0800275 Dist struct {
276 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
277 // command line and any of these targets are also on the command line, or otherwise
278 // built
279 Targets []string `android:"arch_variant"`
280
281 // The name of the output artifact. This defaults to the basename of the output of
282 // the module.
283 Dest *string `android:"arch_variant"`
284
285 // The directory within the dist directory to store the artifact. Defaults to the
286 // top level directory ("").
287 Dir *string `android:"arch_variant"`
288
289 // A suffix to add to the artifact file name (before any extension).
290 Suffix *string `android:"arch_variant"`
291 } `android:"arch_variant"`
292
Colin Crossa1ad8d12016-06-01 17:09:44 -0700293 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700294 CompileTarget Target `blueprint:"mutated"`
295 CompileMultiTargets []Target `blueprint:"mutated"`
296 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800297
298 // Set by InitAndroidModule
299 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700300 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700301
302 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800303
304 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800305}
306
307type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800308 // If set to true, build a variant of the module for the host. Defaults to false.
309 Host_supported *bool
310
311 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700312 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800313}
314
Colin Crossc472d572015-03-17 15:06:21 -0700315type Multilib string
316
317const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800318 MultilibBoth Multilib = "both"
319 MultilibFirst Multilib = "first"
320 MultilibCommon Multilib = "common"
321 MultilibCommonFirst Multilib = "common_first"
322 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700323)
324
Colin Crossa1ad8d12016-06-01 17:09:44 -0700325type HostOrDeviceSupported int
326
327const (
328 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700329
330 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700331 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700332
333 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700334 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700335
336 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700337 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700338
339 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700340 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700341
342 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700343 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700344
345 // Nothing is supported. This is not exposed to the user, but used to mark a
346 // host only module as unsupported when the module type is not supported on
347 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700348 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700349)
350
Jiyong Park2db76922017-11-08 16:03:48 +0900351type moduleKind int
352
353const (
354 platformModule moduleKind = iota
355 deviceSpecificModule
356 socSpecificModule
357 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100358 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900359)
360
361func (k moduleKind) String() string {
362 switch k {
363 case platformModule:
364 return "platform"
365 case deviceSpecificModule:
366 return "device-specific"
367 case socSpecificModule:
368 return "soc-specific"
369 case productSpecificModule:
370 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100371 case productServicesSpecificModule:
372 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900373 default:
374 panic(fmt.Errorf("unknown module kind %d", k))
375 }
376}
377
Colin Cross36242852017-06-23 15:06:31 -0700378func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800379 base := m.base()
380 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700381
Colin Cross36242852017-06-23 15:06:31 -0700382 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700383 &base.nameProperties,
384 &base.commonProperties,
385 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700386 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700387 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700388}
389
Colin Cross36242852017-06-23 15:06:31 -0700390func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
391 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700392
393 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800394 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700395 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700396 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700397 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800398
Dan Willemsen218f6562015-07-08 18:13:11 -0700399 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700400 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700401 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800402 }
403
Colin Cross36242852017-06-23 15:06:31 -0700404 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800405}
406
Colin Crossee0bc3b2018-10-02 22:01:37 -0700407func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
408 InitAndroidArchModule(m, hod, defaultMultilib)
409 m.base().commonProperties.UseTargetVariants = false
410}
411
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800412// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800413// modules. It should be included as an anonymous field in every module
414// struct definition. InitAndroidModule should then be called from the module's
415// factory function, and the return values from InitAndroidModule should be
416// returned from the factory function.
417//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800418// The ModuleBase type is responsible for implementing the GenerateBuildActions
419// method to support the blueprint.Module interface. This method will then call
420// the module's GenerateAndroidBuildActions method once for each build variant
421// that is to be built. GenerateAndroidBuildActions is passed a
422// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800423// AndroidModuleContext exposes extra functionality specific to the Android build
424// system including details about the particular build variant that is to be
425// generated.
426//
427// For example:
428//
429// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800430// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800431// )
432//
433// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800434// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800435// properties struct {
436// MyProperty string
437// }
438// }
439//
Colin Cross36242852017-06-23 15:06:31 -0700440// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800441// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700442// m.AddProperties(&m.properties)
443// android.InitAndroidModule(m)
444// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800445// }
446//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800447// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800448// // Get the CPU architecture for the current build variant.
449// variantArch := ctx.Arch()
450//
451// // ...
452// }
Colin Cross635c3b02016-05-18 15:37:25 -0700453type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800454 // Putting the curiously recurring thing pointing to the thing that contains
455 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700456 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700457 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800458
Colin Crossfc754582016-05-17 16:34:16 -0700459 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800460 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700461 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800462 hostAndDeviceProperties hostAndDeviceProperties
463 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700464 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700465 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800466
467 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700468 installFiles Paths
469 checkbuildFiles Paths
Jaewoong Jung62707f72018-11-16 13:26:43 -0800470 noticeFile Path
Colin Cross1f8c52b2015-06-16 16:38:17 -0700471
472 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
473 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800474 installTarget WritablePath
475 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700476 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700477
Colin Cross178a5092016-09-13 13:42:32 -0700478 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700479
480 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700481
482 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700483 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800484 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800485 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700486
487 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700488}
489
Colin Cross5f692ec2019-02-01 16:53:07 -0800490func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
491
Colin Cross36242852017-06-23 15:06:31 -0700492func (a *ModuleBase) AddProperties(props ...interface{}) {
493 a.registerProps = append(a.registerProps, props...)
494}
495
496func (a *ModuleBase) GetProperties() []interface{} {
497 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800498}
499
Colin Crossae887032017-10-23 17:16:14 -0700500func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700501 return a.buildParams
502}
503
Colin Cross4c83e5c2019-02-25 14:54:28 -0800504func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
505 return a.ruleParams
506}
507
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800508func (a *ModuleBase) VariablesForTests() map[string]string {
509 return a.variables
510}
511
Colin Crossa9d8bee2018-10-02 13:59:46 -0700512func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
513 a.prefer32 = prefer32
514}
515
Colin Crossce75d2c2016-10-06 16:12:58 -0700516// Name returns the name of the module. It may be overridden by individual module types, for
517// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700518func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800519 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700520}
521
Colin Crossce75d2c2016-10-06 16:12:58 -0700522// BaseModuleName returns the name of the module as specified in the blueprints file.
523func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800524 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700525}
526
Colin Cross635c3b02016-05-18 15:37:25 -0700527func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800528 return a
529}
530
Colin Crossee0bc3b2018-10-02 22:01:37 -0700531func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700532 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700533 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700534 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700535}
536
Colin Crossa1ad8d12016-06-01 17:09:44 -0700537func (a *ModuleBase) Target() Target {
538 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800539}
540
Colin Cross8b74d172016-09-13 09:59:14 -0700541func (a *ModuleBase) TargetPrimary() bool {
542 return a.commonProperties.CompilePrimary
543}
544
Colin Crossee0bc3b2018-10-02 22:01:37 -0700545func (a *ModuleBase) MultiTargets() []Target {
546 return a.commonProperties.CompileMultiTargets
547}
548
Colin Crossa1ad8d12016-06-01 17:09:44 -0700549func (a *ModuleBase) Os() OsType {
550 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800551}
552
Colin Cross635c3b02016-05-18 15:37:25 -0700553func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700554 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800555}
556
Colin Cross635c3b02016-05-18 15:37:25 -0700557func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700558 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800559}
560
Dan Willemsen0b24c742016-10-04 15:13:37 -0700561func (a *ModuleBase) ArchSpecific() bool {
562 return a.commonProperties.ArchSpecific
563}
564
Colin Crossa1ad8d12016-06-01 17:09:44 -0700565func (a *ModuleBase) OsClassSupported() []OsClass {
566 switch a.commonProperties.HostOrDeviceSupported {
567 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700568 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700569 case HostSupportedNoCross:
570 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700571 case DeviceSupported:
572 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700573 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700574 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700575 if Bool(a.hostAndDeviceProperties.Host_supported) ||
576 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
577 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700578 supported = append(supported, Host, HostCross)
579 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700580 if a.hostAndDeviceProperties.Device_supported == nil ||
581 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700582 supported = append(supported, Device)
583 }
584 return supported
585 default:
586 return nil
587 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800588}
589
Colin Cross635c3b02016-05-18 15:37:25 -0700590func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800591 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
592 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700593 (a.hostAndDeviceProperties.Device_supported == nil ||
594 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800595}
596
Jiyong Parkc678ad32018-04-10 13:07:10 +0900597func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100598 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900599}
600
601func (a *ModuleBase) DeviceSpecific() bool {
602 return Bool(a.commonProperties.Device_specific)
603}
604
605func (a *ModuleBase) SocSpecific() bool {
606 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
607}
608
609func (a *ModuleBase) ProductSpecific() bool {
610 return Bool(a.commonProperties.Product_specific)
611}
612
Dario Frenifd05a742018-05-29 13:28:54 +0100613func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100614 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100615}
616
Colin Cross635c3b02016-05-18 15:37:25 -0700617func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800618 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800619 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800620 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800621 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800622}
623
Colin Crossce75d2c2016-10-06 16:12:58 -0700624func (a *ModuleBase) SkipInstall() {
625 a.commonProperties.SkipInstall = true
626}
627
Jiyong Park374510b2018-03-19 18:23:01 +0900628func (a *ModuleBase) ExportedToMake() bool {
629 return a.commonProperties.NamespaceExportedToMake
630}
631
Colin Cross635c3b02016-05-18 15:37:25 -0700632func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700633 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800634
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700635 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700636 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800637 ctx.VisitDepsDepthFirstIf(isFileInstaller,
638 func(m blueprint.Module) {
639 fileInstaller := m.(fileInstaller)
640 files := fileInstaller.filesToInstall()
641 result = append(result, files...)
642 })
643
644 return result
645}
646
Colin Cross635c3b02016-05-18 15:37:25 -0700647func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800648 return a.installFiles
649}
650
Colin Cross635c3b02016-05-18 15:37:25 -0700651func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800652 return p.noAddressSanitizer
653}
654
Colin Cross635c3b02016-05-18 15:37:25 -0700655func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800656 return false
657}
658
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700659func (p *ModuleBase) InstallInSanitizerDir() bool {
660 return false
661}
662
Jiyong Parkf9332f12018-02-01 00:54:12 +0900663func (p *ModuleBase) InstallInRecovery() bool {
664 return Bool(p.commonProperties.Recovery)
665}
666
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900667func (a *ModuleBase) Owner() string {
668 return String(a.commonProperties.Owner)
669}
670
Colin Cross0875c522017-11-28 17:34:01 -0800671func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700672 allInstalledFiles := Paths{}
673 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800674 ctx.VisitAllModuleVariants(func(module Module) {
675 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700676 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
677 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800678 })
679
Colin Cross0875c522017-11-28 17:34:01 -0800680 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700681
Jeff Gaston088e29e2017-11-29 16:47:17 -0800682 namespacePrefix := ctx.Namespace().(*Namespace).id
683 if namespacePrefix != "" {
684 namespacePrefix = namespacePrefix + "-"
685 }
686
Colin Cross3f40fa42015-01-30 17:27:36 -0800687 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800688 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800689 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700690 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800691 Output: name,
692 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800693 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700694 })
695 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700696 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700697 }
698
699 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800700 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800701 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700702 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800703 Output: name,
704 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700705 })
706 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700707 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700708 }
709
710 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800711 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800712 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800713 suffix = "-soong"
714 }
715
Jeff Gaston088e29e2017-11-29 16:47:17 -0800716 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800717 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700718 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800719 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700720 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800721 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700722
723 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800724 }
725}
726
Jiyong Park2db76922017-11-08 16:03:48 +0900727func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
728 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
729 var deviceSpecific = Bool(a.commonProperties.Device_specific)
730 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100731 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900732
Dario Frenifd05a742018-05-29 13:28:54 +0100733 msg := "conflicting value set here"
734 if socSpecific && deviceSpecific {
735 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900736 if Bool(a.commonProperties.Vendor) {
737 ctx.PropertyErrorf("vendor", msg)
738 }
739 if Bool(a.commonProperties.Proprietary) {
740 ctx.PropertyErrorf("proprietary", msg)
741 }
742 if Bool(a.commonProperties.Soc_specific) {
743 ctx.PropertyErrorf("soc_specific", msg)
744 }
745 }
746
Dario Frenifd05a742018-05-29 13:28:54 +0100747 if productSpecific && productServicesSpecific {
748 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
749 ctx.PropertyErrorf("product_services_specific", msg)
750 }
751
752 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
753 if productSpecific {
754 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
755 } else {
756 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
757 }
758 if deviceSpecific {
759 ctx.PropertyErrorf("device_specific", msg)
760 } else {
761 if Bool(a.commonProperties.Vendor) {
762 ctx.PropertyErrorf("vendor", msg)
763 }
764 if Bool(a.commonProperties.Proprietary) {
765 ctx.PropertyErrorf("proprietary", msg)
766 }
767 if Bool(a.commonProperties.Soc_specific) {
768 ctx.PropertyErrorf("soc_specific", msg)
769 }
770 }
771 }
772
Jiyong Park2db76922017-11-08 16:03:48 +0900773 if productSpecific {
774 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100775 } else if productServicesSpecific {
776 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900777 } else if deviceSpecific {
778 return deviceSpecificModule
779 } else if socSpecific {
780 return socSpecificModule
781 } else {
782 return platformModule
783 }
784}
785
Colin Cross635c3b02016-05-18 15:37:25 -0700786func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700787 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700788 target: a.commonProperties.CompileTarget,
789 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700790 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900791 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700792 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800793 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800794}
795
Colin Cross0875c522017-11-28 17:34:01 -0800796func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
797 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700798 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800799 ModuleContext: blueprintCtx,
800 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
801 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700802 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800803 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800804 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800805 }
806
Colin Cross4c83e5c2019-02-25 14:54:28 -0800807 if ctx.config.captureBuild {
808 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
809 }
810
Colin Cross67a5c132017-05-09 13:45:28 -0700811 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
812 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800813 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
814 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700815 }
Colin Cross0875c522017-11-28 17:34:01 -0800816 if !ctx.PrimaryArch() {
817 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700818 }
819
820 ctx.Variable(pctx, "moduleDesc", desc)
821
822 s := ""
823 if len(suffix) > 0 {
824 s = " [" + strings.Join(suffix, " ") + "]"
825 }
826 ctx.Variable(pctx, "moduleDescSuffix", s)
827
Dan Willemsen569edc52018-11-19 09:33:29 -0800828 // Some common property checks for properties that will be used later in androidmk.go
829 if a.commonProperties.Dist.Dest != nil {
830 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
831 if err != nil {
832 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
833 }
834 }
835 if a.commonProperties.Dist.Dir != nil {
836 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
837 if err != nil {
838 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
839 }
840 }
841 if a.commonProperties.Dist.Suffix != nil {
842 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
843 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
844 }
845 }
846
Colin Cross9b1d13d2016-09-19 15:18:11 -0700847 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800848 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700849 if ctx.Failed() {
850 return
851 }
852
Colin Cross0875c522017-11-28 17:34:01 -0800853 a.installFiles = append(a.installFiles, ctx.installFiles...)
854 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800855
856 if a.commonProperties.Notice != nil {
857 // For filegroup-based notice file references.
858 a.noticeFile = ctx.ExpandSource(*a.commonProperties.Notice, "notice")
859 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800860 }
861
Colin Cross9b1d13d2016-09-19 15:18:11 -0700862 if a == ctx.FinalModule().(Module).base() {
863 a.generateModuleTarget(ctx)
864 if ctx.Failed() {
865 return
866 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800867 }
Colin Crosscec81712017-07-13 14:43:27 -0700868
Colin Cross0875c522017-11-28 17:34:01 -0800869 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800870 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800871 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800872}
873
Colin Crossf6566ed2015-03-24 11:13:38 -0700874type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700875 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700876 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700877 targetPrimary bool
878 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900879 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700880 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700881}
882
Colin Cross3f40fa42015-01-30 17:27:36 -0800883type androidModuleContext struct {
884 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700885 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700886 installDeps Paths
887 installFiles Paths
888 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800889 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700890 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700891
892 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700893 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800894 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800895 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800896}
897
Colin Cross67a5c132017-05-09 13:45:28 -0700898func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800899 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700900 Rule: ErrorRule,
901 Description: desc,
902 Outputs: outputs,
903 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800904 Args: map[string]string{
905 "error": err.Error(),
906 },
907 })
908 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800909}
910
Colin Crossaabf6792017-11-29 00:27:14 -0800911func (a *androidModuleContext) Config() Config {
912 return a.ModuleContext.Config().(Config)
913}
914
Colin Cross0875c522017-11-28 17:34:01 -0800915func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700916 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800917}
918
Colin Cross0875c522017-11-28 17:34:01 -0800919func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700920 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700921 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800922 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800923 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700924 Outputs: params.Outputs.Strings(),
925 ImplicitOutputs: params.ImplicitOutputs.Strings(),
926 Inputs: params.Inputs.Strings(),
927 Implicits: params.Implicits.Strings(),
928 OrderOnly: params.OrderOnly.Strings(),
929 Args: params.Args,
930 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700931 }
932
Colin Cross33bfb0a2016-11-21 17:23:08 -0800933 if params.Depfile != nil {
934 bparams.Depfile = params.Depfile.String()
935 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700936 if params.Output != nil {
937 bparams.Outputs = append(bparams.Outputs, params.Output.String())
938 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700939 if params.ImplicitOutput != nil {
940 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
941 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700942 if params.Input != nil {
943 bparams.Inputs = append(bparams.Inputs, params.Input.String())
944 }
945 if params.Implicit != nil {
946 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
947 }
948
Colin Cross0b9f31f2019-02-28 11:00:01 -0800949 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
950 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
951 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
952 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
953 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
954 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -0700955
Colin Cross0875c522017-11-28 17:34:01 -0800956 return bparams
957}
958
959func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800960 if a.config.captureBuild {
961 a.variables[name] = value
962 }
963
Colin Cross0875c522017-11-28 17:34:01 -0800964 a.ModuleContext.Variable(pctx.PackageContext, name, value)
965}
966
967func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
968 argNames ...string) blueprint.Rule {
969
Colin Cross4c83e5c2019-02-25 14:54:28 -0800970 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
971
972 if a.config.captureBuild {
973 a.ruleParams[rule] = params
974 }
975
976 return rule
Colin Cross0875c522017-11-28 17:34:01 -0800977}
978
979func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
980 if a.config.captureBuild {
981 a.buildParams = append(a.buildParams, params)
982 }
983
984 bparams := convertBuildParams(params)
985
986 if bparams.Description != "" {
987 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
988 }
989
Colin Cross6ff51382015-12-17 16:39:19 -0800990 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -0700991 a.ninjaError(bparams.Description, bparams.Outputs,
992 fmt.Errorf("module %s missing dependencies: %s\n",
993 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -0800994 return
995 }
996
Colin Cross0875c522017-11-28 17:34:01 -0800997 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700998}
999
Colin Cross6ff51382015-12-17 16:39:19 -08001000func (a *androidModuleContext) GetMissingDependencies() []string {
1001 return a.missingDeps
1002}
1003
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001004func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1005 if deps != nil {
1006 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001007 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001008 }
1009}
1010
Colin Crossd11fcda2017-10-23 17:59:01 -07001011func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1012 aModule, _ := module.(Module)
1013 if aModule == nil {
1014 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1015 return nil
1016 }
1017
1018 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001019 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001020 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1021 } else {
1022 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1023 }
1024 return nil
1025 }
1026
1027 return aModule
1028}
1029
Colin Cross35143d02017-11-16 00:11:20 -08001030func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1031 a.ModuleContext.VisitDirectDeps(visit)
1032}
1033
Colin Crossd11fcda2017-10-23 17:59:01 -07001034func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1035 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1036 if aModule := a.validateAndroidModule(module); aModule != nil {
1037 visit(aModule)
1038 }
1039 })
1040}
1041
Colin Crossee6143c2017-12-30 17:54:27 -08001042func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1043 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1044 if aModule := a.validateAndroidModule(module); aModule != nil {
1045 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1046 visit(aModule)
1047 }
1048 }
1049 })
1050}
1051
Colin Crossd11fcda2017-10-23 17:59:01 -07001052func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1053 a.ModuleContext.VisitDirectDepsIf(
1054 // pred
1055 func(module blueprint.Module) bool {
1056 if aModule := a.validateAndroidModule(module); aModule != nil {
1057 return pred(aModule)
1058 } else {
1059 return false
1060 }
1061 },
1062 // visit
1063 func(module blueprint.Module) {
1064 visit(module.(Module))
1065 })
1066}
1067
1068func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1069 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1070 if aModule := a.validateAndroidModule(module); aModule != nil {
1071 visit(aModule)
1072 }
1073 })
1074}
1075
1076func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1077 a.ModuleContext.VisitDepsDepthFirstIf(
1078 // pred
1079 func(module blueprint.Module) bool {
1080 if aModule := a.validateAndroidModule(module); aModule != nil {
1081 return pred(aModule)
1082 } else {
1083 return false
1084 }
1085 },
1086 // visit
1087 func(module blueprint.Module) {
1088 visit(module.(Module))
1089 })
1090}
1091
Alex Light778127a2019-02-27 14:19:50 -08001092func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1093 a.ModuleContext.WalkDeps(visit)
1094}
1095
Colin Crossd11fcda2017-10-23 17:59:01 -07001096func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1097 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1098 childAndroidModule := a.validateAndroidModule(child)
1099 parentAndroidModule := a.validateAndroidModule(parent)
1100 if childAndroidModule != nil && parentAndroidModule != nil {
1101 return visit(childAndroidModule, parentAndroidModule)
1102 } else {
1103 return false
1104 }
1105 })
1106}
1107
Colin Cross0875c522017-11-28 17:34:01 -08001108func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1109 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1110 visit(module.(Module))
1111 })
1112}
1113
1114func (a *androidModuleContext) PrimaryModule() Module {
1115 return a.ModuleContext.PrimaryModule().(Module)
1116}
1117
1118func (a *androidModuleContext) FinalModule() Module {
1119 return a.ModuleContext.FinalModule().(Module)
1120}
1121
Colin Crossa1ad8d12016-06-01 17:09:44 -07001122func (a *androidBaseContextImpl) Target() Target {
1123 return a.target
1124}
1125
Colin Cross8b74d172016-09-13 09:59:14 -07001126func (a *androidBaseContextImpl) TargetPrimary() bool {
1127 return a.targetPrimary
1128}
1129
Colin Crossee0bc3b2018-10-02 22:01:37 -07001130func (a *androidBaseContextImpl) MultiTargets() []Target {
1131 return a.multiTargets
1132}
1133
Colin Crossf6566ed2015-03-24 11:13:38 -07001134func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001135 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001136}
1137
Colin Crossa1ad8d12016-06-01 17:09:44 -07001138func (a *androidBaseContextImpl) Os() OsType {
1139 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001140}
1141
Colin Crossf6566ed2015-03-24 11:13:38 -07001142func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001143 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001144}
1145
1146func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001147 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001148}
1149
Colin Cross0af4b842015-04-30 16:36:18 -07001150func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001151 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001152}
1153
Doug Horn21b94272019-01-16 12:06:11 -08001154func (a *androidBaseContextImpl) Fuchsia() bool {
1155 return a.target.Os == Fuchsia
1156}
1157
Colin Cross3edeee12017-04-04 12:59:48 -07001158func (a *androidBaseContextImpl) Windows() bool {
1159 return a.target.Os == Windows
1160}
1161
Colin Crossf6566ed2015-03-24 11:13:38 -07001162func (a *androidBaseContextImpl) Debug() bool {
1163 return a.debug
1164}
1165
Colin Cross1e7d3702016-08-24 15:25:47 -07001166func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001167 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001168 return true
1169 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001170 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001171}
1172
Colin Cross1332b002015-04-07 17:11:30 -07001173func (a *androidBaseContextImpl) AConfig() Config {
1174 return a.config
1175}
1176
Colin Cross9272ade2016-08-17 15:24:12 -07001177func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1178 return DeviceConfig{a.config.deviceConfig}
1179}
1180
Jiyong Park2db76922017-11-08 16:03:48 +09001181func (a *androidBaseContextImpl) Platform() bool {
1182 return a.kind == platformModule
1183}
1184
1185func (a *androidBaseContextImpl) DeviceSpecific() bool {
1186 return a.kind == deviceSpecificModule
1187}
1188
1189func (a *androidBaseContextImpl) SocSpecific() bool {
1190 return a.kind == socSpecificModule
1191}
1192
1193func (a *androidBaseContextImpl) ProductSpecific() bool {
1194 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001195}
1196
Dario Frenifd05a742018-05-29 13:28:54 +01001197func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1198 return a.kind == productServicesSpecificModule
1199}
1200
Jiyong Park5baac542018-08-28 09:55:37 +09001201// Makes this module a platform module, i.e. not specific to soc, device,
1202// product, or product_services.
1203func (a *ModuleBase) MakeAsPlatform() {
1204 a.commonProperties.Vendor = boolPtr(false)
1205 a.commonProperties.Proprietary = boolPtr(false)
1206 a.commonProperties.Soc_specific = boolPtr(false)
1207 a.commonProperties.Product_specific = boolPtr(false)
1208 a.commonProperties.Product_services_specific = boolPtr(false)
1209}
1210
Colin Cross8d8f8e22016-08-03 11:57:50 -07001211func (a *androidModuleContext) InstallInData() bool {
1212 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001213}
1214
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001215func (a *androidModuleContext) InstallInSanitizerDir() bool {
1216 return a.module.InstallInSanitizerDir()
1217}
1218
Jiyong Parkf9332f12018-02-01 00:54:12 +09001219func (a *androidModuleContext) InstallInRecovery() bool {
1220 return a.module.InstallInRecovery()
1221}
1222
Colin Cross893d8162017-04-26 17:34:03 -07001223func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1224 if a.module.base().commonProperties.SkipInstall {
1225 return true
1226 }
1227
Colin Cross3607f212018-05-07 15:28:05 -07001228 // We'll need a solution for choosing which of modules with the same name in different
1229 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1230 // list of namespaces to install in a Soong-only build.
1231 if !a.module.base().commonProperties.NamespaceExportedToMake {
1232 return true
1233 }
1234
Colin Cross893d8162017-04-26 17:34:03 -07001235 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001236 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001237 return true
1238 }
1239
Colin Cross6510f912017-11-29 00:27:14 -08001240 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001241 return true
1242 }
1243 }
1244
1245 return false
1246}
1247
Colin Cross5c517922017-08-31 12:29:17 -07001248func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001249 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001250 return a.installFile(installPath, name, srcPath, Cp, deps)
1251}
1252
1253func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1254 deps ...Path) OutputPath {
1255 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1256}
1257
1258func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1259 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001260
Dan Willemsen782a2d12015-12-21 14:55:28 -08001261 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001262 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001263
Colin Cross893d8162017-04-26 17:34:03 -07001264 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001265
Dan Willemsen322acaf2016-01-12 23:07:05 -08001266 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001267
Colin Cross89562dc2016-10-03 17:47:19 -07001268 var implicitDeps, orderOnlyDeps Paths
1269
1270 if a.Host() {
1271 // Installed host modules might be used during the build, depend directly on their
1272 // dependencies so their timestamp is updated whenever their dependency is updated
1273 implicitDeps = deps
1274 } else {
1275 orderOnlyDeps = deps
1276 }
1277
Colin Crossae887032017-10-23 17:16:14 -07001278 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001279 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001280 Description: "install " + fullInstallPath.Base(),
1281 Output: fullInstallPath,
1282 Input: srcPath,
1283 Implicits: implicitDeps,
1284 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001285 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001286 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001287
Dan Willemsen322acaf2016-01-12 23:07:05 -08001288 a.installFiles = append(a.installFiles, fullInstallPath)
1289 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001290 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001291 return fullInstallPath
1292}
1293
Colin Cross3854a602016-01-11 12:49:11 -08001294func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1295 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001296 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001297
Colin Cross893d8162017-04-26 17:34:03 -07001298 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001299
Alex Lightfb4353d2019-01-17 13:57:45 -08001300 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1301 if err != nil {
1302 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1303 }
Colin Crossae887032017-10-23 17:16:14 -07001304 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001305 Rule: Symlink,
1306 Description: "install symlink " + fullInstallPath.Base(),
1307 Output: fullInstallPath,
1308 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001309 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001310 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001311 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001312 },
1313 })
Colin Cross3854a602016-01-11 12:49:11 -08001314
Colin Cross12fc4972016-01-11 12:49:11 -08001315 a.installFiles = append(a.installFiles, fullInstallPath)
1316 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1317 }
Colin Cross3854a602016-01-11 12:49:11 -08001318 return fullInstallPath
1319}
1320
Jiyong Parkf1194352019-02-25 11:05:47 +09001321// installPath/name -> absPath where absPath might be a path that is available only at runtime
1322// (e.g. /apex/...)
1323func (a *androidModuleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1324 fullInstallPath := installPath.Join(a, name)
1325 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
1326
1327 if !a.skipInstall(fullInstallPath) {
1328 a.Build(pctx, BuildParams{
1329 Rule: Symlink,
1330 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1331 Output: fullInstallPath,
1332 Default: !a.Config().EmbeddedInMake(),
1333 Args: map[string]string{
1334 "fromPath": absPath,
1335 },
1336 })
1337
1338 a.installFiles = append(a.installFiles, fullInstallPath)
1339 }
1340 return fullInstallPath
1341}
1342
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001343func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001344 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1345}
1346
Colin Cross3f40fa42015-01-30 17:27:36 -08001347type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001348 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001349}
1350
1351func isFileInstaller(m blueprint.Module) bool {
1352 _, ok := m.(fileInstaller)
1353 return ok
1354}
1355
1356func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001357 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001358 return ok
1359}
Colin Crossfce53272015-04-08 11:21:40 -07001360
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001361func findStringInSlice(str string, slice []string) int {
1362 for i, s := range slice {
1363 if s == str {
1364 return i
Colin Crossfce53272015-04-08 11:21:40 -07001365 }
1366 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001367 return -1
1368}
1369
Colin Cross068e0fe2016-12-13 15:23:47 -08001370func SrcIsModule(s string) string {
1371 if len(s) > 1 && s[0] == ':' {
1372 return s[1:]
1373 }
1374 return ""
1375}
1376
1377type sourceDependencyTag struct {
1378 blueprint.BaseDependencyTag
1379}
1380
1381var SourceDepTag sourceDependencyTag
1382
Colin Cross366938f2017-12-11 16:29:02 -08001383// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1384// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001385//
1386// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001387func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1388 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001389 set := make(map[string]bool)
1390
Colin Cross068e0fe2016-12-13 15:23:47 -08001391 for _, s := range srcFiles {
1392 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001393 if _, found := set[m]; found {
1394 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1395 } else {
1396 set[m] = true
1397 deps = append(deps, m)
1398 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001399 }
1400 }
1401
1402 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1403}
1404
Colin Cross366938f2017-12-11 16:29:02 -08001405// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1406// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001407//
1408// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001409func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1410 if s != nil {
1411 if m := SrcIsModule(*s); m != "" {
1412 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1413 }
1414 }
1415}
1416
Colin Cross068e0fe2016-12-13 15:23:47 -08001417type SourceFileProducer interface {
1418 Srcs() Paths
1419}
1420
Colin Cross27b922f2019-03-04 22:35:41 -08001421// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1422// be tagged with `android:"path" to support automatic source module dependency resolution.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001423func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001424 return ctx.ExpandSourcesSubDir(srcFiles, excludes, "")
1425}
1426
Colin Cross27b922f2019-03-04 22:35:41 -08001427// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1428// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross366938f2017-12-11 16:29:02 -08001429func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
1430 srcFiles := ctx.ExpandSourcesSubDir([]string{srcFile}, nil, "")
1431 if len(srcFiles) == 1 {
1432 return srcFiles[0]
Jaewoong Jung62707f72018-11-16 13:26:43 -08001433 } else if len(srcFiles) == 0 {
1434 if ctx.Config().AllowMissingDependencies() {
1435 ctx.AddMissingDependencies([]string{srcFile})
1436 } else {
1437 ctx.PropertyErrorf(prop, "%s path %s does not exist", prop, srcFile)
1438 }
1439 return nil
Colin Cross366938f2017-12-11 16:29:02 -08001440 } else {
1441 ctx.PropertyErrorf(prop, "module providing %s must produce exactly one file", prop)
1442 return nil
1443 }
1444}
1445
Colin Cross2383f3b2018-02-06 14:40:13 -08001446// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
Colin Cross27b922f2019-03-04 22:35:41 -08001447// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1448// dependency resolution.
Colin Cross2383f3b2018-02-06 14:40:13 -08001449func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1450 if srcFile != nil {
1451 return OptionalPathForPath(ctx.ExpandSource(*srcFile, prop))
1452 }
1453 return OptionalPath{}
1454}
1455
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001456func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001457 prefix := PathForModuleSrc(ctx).String()
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001458
Colin Cross461b4452018-02-23 09:22:42 -08001459 var expandedExcludes []string
1460 if excludes != nil {
1461 expandedExcludes = make([]string, 0, len(excludes))
1462 }
Nan Zhang27e284d2018-02-09 21:03:53 +00001463
1464 for _, e := range excludes {
1465 if m := SrcIsModule(e); m != "" {
1466 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
1467 if module == nil {
Colin Cross1255a562019-03-07 12:31:38 -08001468 if ctx.Config().AllowMissingDependencies() {
1469 ctx.AddMissingDependencies([]string{m})
1470 } else {
1471 ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m)
1472 }
Nan Zhang27e284d2018-02-09 21:03:53 +00001473 continue
1474 }
1475 if srcProducer, ok := module.(SourceFileProducer); ok {
1476 expandedExcludes = append(expandedExcludes, srcProducer.Srcs().Strings()...)
1477 } else {
1478 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1479 }
1480 } else {
1481 expandedExcludes = append(expandedExcludes, filepath.Join(prefix, e))
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001482 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001483 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001484 expandedSrcFiles := make(Paths, 0, len(srcFiles))
Colin Cross8f101b42015-06-17 15:09:06 -07001485 for _, s := range srcFiles {
Colin Cross068e0fe2016-12-13 15:23:47 -08001486 if m := SrcIsModule(s); m != "" {
1487 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
Colin Cross0617bb82017-10-24 13:01:18 -07001488 if module == nil {
Colin Cross1255a562019-03-07 12:31:38 -08001489 if ctx.Config().AllowMissingDependencies() {
1490 ctx.AddMissingDependencies([]string{m})
1491 } else {
1492 ctx.ModuleErrorf(`missing dependency on %q, is the property annotated with android:"path"?`, m)
1493 }
Colin Cross0617bb82017-10-24 13:01:18 -07001494 continue
1495 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001496 if srcProducer, ok := module.(SourceFileProducer); ok {
Nan Zhang27e284d2018-02-09 21:03:53 +00001497 moduleSrcs := srcProducer.Srcs()
1498 for _, e := range expandedExcludes {
1499 for j, ms := range moduleSrcs {
1500 if ms.String() == e {
1501 moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...)
1502 }
1503 }
1504 }
1505 expandedSrcFiles = append(expandedSrcFiles, moduleSrcs...)
Colin Cross068e0fe2016-12-13 15:23:47 -08001506 } else {
1507 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1508 }
1509 } else if pathtools.IsGlob(s) {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001510 globbedSrcFiles := ctx.GlobFiles(filepath.Join(prefix, s), expandedExcludes)
Colin Cross05a39cb2017-10-09 13:35:19 -07001511 for i, s := range globbedSrcFiles {
1512 globbedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir)
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001513 }
Colin Cross05a39cb2017-10-09 13:35:19 -07001514 expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...)
Colin Cross8f101b42015-06-17 15:09:06 -07001515 } else {
Nan Zhang27e284d2018-02-09 21:03:53 +00001516 p := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir)
1517 j := findStringInSlice(p.String(), expandedExcludes)
1518 if j == -1 {
1519 expandedSrcFiles = append(expandedSrcFiles, p)
1520 }
1521
Colin Cross8f101b42015-06-17 15:09:06 -07001522 }
1523 }
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001524 return expandedSrcFiles
Colin Cross8f101b42015-06-17 15:09:06 -07001525}
1526
Nan Zhang6d34b302017-02-04 17:47:46 -08001527func (ctx *androidModuleContext) RequiredModuleNames() []string {
1528 return ctx.module.base().commonProperties.Required
1529}
1530
Colin Cross7f19f372016-11-01 11:10:25 -07001531func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1532 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001533 if err != nil {
1534 ctx.ModuleErrorf("glob: %s", err.Error())
1535 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001536 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001537}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001538
Nan Zhang581fd212018-01-10 16:06:12 -08001539func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001540 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001541 if err != nil {
1542 ctx.ModuleErrorf("glob: %s", err.Error())
1543 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001544 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001545}
1546
Colin Cross463a90e2015-06-17 14:20:06 -07001547func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001548 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001549}
1550
Colin Cross0875c522017-11-28 17:34:01 -08001551func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001552 return &buildTargetSingleton{}
1553}
1554
Colin Cross87d8b562017-04-25 10:01:55 -07001555func parentDir(dir string) string {
1556 dir, _ = filepath.Split(dir)
1557 return filepath.Clean(dir)
1558}
1559
Colin Cross1f8c52b2015-06-16 16:38:17 -07001560type buildTargetSingleton struct{}
1561
Colin Cross0875c522017-11-28 17:34:01 -08001562func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1563 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001564
Colin Cross0875c522017-11-28 17:34:01 -08001565 mmTarget := func(dir string) WritablePath {
1566 return PathForPhony(ctx,
1567 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001568 }
1569
Colin Cross0875c522017-11-28 17:34:01 -08001570 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001571
Colin Cross0875c522017-11-28 17:34:01 -08001572 ctx.VisitAllModules(func(module Module) {
1573 blueprintDir := module.base().blueprintDir
1574 installTarget := module.base().installTarget
1575 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001576
Colin Cross0875c522017-11-28 17:34:01 -08001577 if checkbuildTarget != nil {
1578 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1579 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1580 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001581
Colin Cross0875c522017-11-28 17:34:01 -08001582 if installTarget != nil {
1583 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001584 }
1585 })
1586
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001587 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001588 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001589 suffix = "-soong"
1590 }
1591
Colin Cross1f8c52b2015-06-16 16:38:17 -07001592 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001593 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001594 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001595 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001596 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001597 })
1598
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001599 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001600 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001601 return
1602 }
1603
Colin Cross0875c522017-11-28 17:34:01 -08001604 sortedKeys := func(m map[string]Paths) []string {
1605 s := make([]string, 0, len(m))
1606 for k := range m {
1607 s = append(s, k)
1608 }
1609 sort.Strings(s)
1610 return s
1611 }
1612
Colin Cross87d8b562017-04-25 10:01:55 -07001613 // Ensure ancestor directories are in modulesInDir
1614 dirs := sortedKeys(modulesInDir)
1615 for _, dir := range dirs {
1616 dir := parentDir(dir)
1617 for dir != "." && dir != "/" {
1618 if _, exists := modulesInDir[dir]; exists {
1619 break
1620 }
1621 modulesInDir[dir] = nil
1622 dir = parentDir(dir)
1623 }
1624 }
1625
1626 // Make directories build their direct subdirectories
1627 dirs = sortedKeys(modulesInDir)
1628 for _, dir := range dirs {
1629 p := parentDir(dir)
1630 if p != "." && p != "/" {
1631 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1632 }
1633 }
1634
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001635 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1636 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1637 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001638 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001639 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001640 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001641 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001642 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001643 // HACK: checkbuild should be an optional build, but force it
1644 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001645 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001646 })
1647 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001648
1649 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1650 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001651 ctx.VisitAllModules(func(module Module) {
1652 if module.Enabled() {
1653 os := module.Target().Os
1654 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001655 }
1656 })
1657
Colin Cross0875c522017-11-28 17:34:01 -08001658 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001659 for os, deps := range osDeps {
1660 var className string
1661
1662 switch os.Class {
1663 case Host:
1664 className = "host"
1665 case HostCross:
1666 className = "host-cross"
1667 case Device:
1668 className = "target"
1669 default:
1670 continue
1671 }
1672
Colin Cross0875c522017-11-28 17:34:01 -08001673 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001674 osClass[className] = append(osClass[className], name)
1675
Colin Cross0875c522017-11-28 17:34:01 -08001676 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001677 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001678 Output: name,
1679 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001680 })
1681 }
1682
1683 // Wrap those into host|host-cross|target phony rules
1684 osClasses := sortedKeys(osClass)
1685 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001686 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001687 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001688 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001689 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001690 })
1691 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001692}
Colin Crossd779da42015-12-17 18:00:23 -08001693
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001694// Collect information for opening IDE project files in java/jdeps.go.
1695type IDEInfo interface {
1696 IDEInfo(ideInfo *IdeInfo)
1697 BaseModuleName() string
1698}
1699
1700// Extract the base module name from the Import name.
1701// Often the Import name has a prefix "prebuilt_".
1702// Remove the prefix explicitly if needed
1703// until we find a better solution to get the Import name.
1704type IDECustomizedModuleName interface {
1705 IDECustomizedModuleName() string
1706}
1707
1708type IdeInfo struct {
1709 Deps []string `json:"dependencies,omitempty"`
1710 Srcs []string `json:"srcs,omitempty"`
1711 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1712 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1713 Jars []string `json:"jars,omitempty"`
1714 Classes []string `json:"class,omitempty"`
1715 Installed_paths []string `json:"installed,omitempty"`
1716}