blob: 674341255164f2a708895ea39809b6b53fa10568 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Alex Lightfb4353d2019-01-17 13:57:45 -080019 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080020 "path/filepath"
Colin Cross0875c522017-11-28 17:34:01 -080021 "sort"
Colin Cross6ff51382015-12-17 16:39:19 -080022 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080023 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
25 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070026 "github.com/google/blueprint/pathtools"
Colin Crossfe4bc362018-09-12 10:02:13 -070027 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080028)
29
30var (
31 DeviceSharedLibrary = "shared_library"
32 DeviceStaticLibrary = "static_library"
33 DeviceExecutable = "executable"
34 HostSharedLibrary = "host_shared_library"
35 HostStaticLibrary = "host_static_library"
36 HostExecutable = "host_executable"
37)
38
Colin Crossae887032017-10-23 17:16:14 -070039type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070040 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080041 Deps blueprint.Deps
42 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070043 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070044 Output WritablePath
45 Outputs WritablePaths
46 ImplicitOutput WritablePath
47 ImplicitOutputs WritablePaths
48 Input Path
49 Inputs Paths
50 Implicit Path
51 Implicits Paths
52 OrderOnly Paths
53 Default bool
54 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070055}
56
Colin Crossae887032017-10-23 17:16:14 -070057type ModuleBuildParams BuildParams
58
Colin Crossf6566ed2015-03-24 11:13:38 -070059type androidBaseContext interface {
Colin Crossa1ad8d12016-06-01 17:09:44 -070060 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070061 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -070062 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -070063 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070064 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070065 Host() bool
66 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070067 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -080068 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -070069 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070070 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070071 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +090072 Platform() bool
73 DeviceSpecific() bool
74 SocSpecific() bool
75 ProductSpecific() bool
Dario Frenifd05a742018-05-29 13:28:54 +010076 ProductServicesSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -070077 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -070078 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -070079}
80
Colin Cross635c3b02016-05-18 15:37:25 -070081type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -080082 BaseModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -070083 androidBaseContext
84}
85
Colin Crossaabf6792017-11-29 00:27:14 -080086// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
87// a Config instead of an interface{}.
88type BaseModuleContext interface {
89 ModuleName() string
90 ModuleDir() string
Colin Cross3d7c9822019-03-01 13:46:24 -080091 ModuleType() string
Colin Crossaabf6792017-11-29 00:27:14 -080092 Config() Config
93
94 ContainsProperty(name string) bool
95 Errorf(pos scanner.Position, fmt string, args ...interface{})
96 ModuleErrorf(fmt string, args ...interface{})
97 PropertyErrorf(property, fmt string, args ...interface{})
98 Failed() bool
99
100 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
101 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
102 // builder whenever a file matching the pattern as added or removed, without rerunning if a
103 // file that does not match the pattern is added to a searched directory.
104 GlobWithDeps(pattern string, excludes []string) ([]string, error)
105
106 Fs() pathtools.FileSystem
107 AddNinjaFileDeps(deps ...string)
108}
109
Colin Cross635c3b02016-05-18 15:37:25 -0700110type ModuleContext interface {
Colin Crossf6566ed2015-03-24 11:13:38 -0700111 androidBaseContext
Colin Crossaabf6792017-11-29 00:27:14 -0800112 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800113
Colin Crossae887032017-10-23 17:16:14 -0700114 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800115 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700116
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800118 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800119 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Colin Cross7f19f372016-11-01 11:10:25 -0700120 Glob(globPattern string, excludes []string) Paths
Nan Zhang581fd212018-01-10 16:06:12 -0800121 GlobFiles(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700122
Colin Cross5c517922017-08-31 12:29:17 -0700123 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
124 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800125 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900126 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700127 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800128
129 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700130
Colin Cross8d8f8e22016-08-03 11:57:50 -0700131 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700132 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900133 InstallInRecovery() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800134
135 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700136 HostRequiredModuleNames() []string
137 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700138
139 // android.ModuleContext methods
140 // These are duplicated instead of embedded so that can eventually be wrapped to take an
141 // android.Module instead of a blueprint.Module
142 OtherModuleName(m blueprint.Module) string
143 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
144 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
145
146 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
147 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
148
149 ModuleSubDir() string
150
Colin Cross35143d02017-11-16 00:11:20 -0800151 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700152 VisitDirectDeps(visit func(Module))
Colin Crossee6143c2017-12-30 17:54:27 -0800153 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700154 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700155 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700156 VisitDepsDepthFirst(visit func(Module))
Colin Cross6b753602018-06-21 13:03:07 -0700157 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
Colin Crossd11fcda2017-10-23 17:59:01 -0700158 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
159 WalkDeps(visit func(Module, Module) bool)
Alex Light778127a2019-02-27 14:19:50 -0800160 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700161
Colin Cross0875c522017-11-28 17:34:01 -0800162 Variable(pctx PackageContext, name, value string)
163 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700164 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
165 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800166 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700167
Colin Cross0875c522017-11-28 17:34:01 -0800168 PrimaryModule() Module
169 FinalModule() Module
170 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700171
172 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800173 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800174}
175
Colin Cross635c3b02016-05-18 15:37:25 -0700176type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800177 blueprint.Module
178
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700179 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
180 // but GenerateAndroidBuildActions also has access to Android-specific information.
181 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700182 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700183
Colin Cross1e676be2016-10-12 14:38:15 -0700184 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800185
Colin Cross635c3b02016-05-18 15:37:25 -0700186 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800187 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700188 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800189 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700190 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900191 InstallInRecovery() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800192 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900193 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900194 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700195
196 AddProperties(props ...interface{})
197 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700198
Colin Crossae887032017-10-23 17:16:14 -0700199 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800200 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800201 VariablesForTests() map[string]string
Colin Cross3f40fa42015-01-30 17:27:36 -0800202}
203
Colin Crossfc754582016-05-17 16:34:16 -0700204type nameProperties struct {
205 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800206 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700207}
208
209type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800210 // emit build rules for this module
211 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800212
Paul Duffin2e61fa62019-03-28 14:10:57 +0000213 // Controls the visibility of this module to other modules. Allowable values are one or more of
214 // these formats:
215 //
216 // ["//visibility:public"]: Anyone can use this module.
217 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
218 // this module.
219 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
220 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
221 // this module. Note that sub-packages do not have access to the rule; for example,
222 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
223 // is a special module and must be used verbatim. It represents all of the modules in the
224 // package.
225 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
226 // or other or in one of their sub-packages have access to this module. For example,
227 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
228 // to depend on this rule (but not //independent:evil)
229 // ["//project"]: This is shorthand for ["//project:__pkg__"]
230 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
231 // //project is the module's package. e.g. using [":__subpackages__"] in
232 // packages/apps/Settings/Android.bp is equivalent to
233 // //packages/apps/Settings:__subpackages__.
234 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
235 // for now. It is an error if it is used in a module.
236 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
237 // more details.
238 Visibility []string
239
Colin Cross7d5136f2015-05-11 13:39:40 -0700240 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800241 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
242 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
243 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700244 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700245
246 Target struct {
247 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700248 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700249 }
250 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700251 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700252 }
253 }
254
Colin Crossee0bc3b2018-10-02 22:01:37 -0700255 UseTargetVariants bool `blueprint:"mutated"`
256 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800257
Dan Willemsen782a2d12015-12-21 14:55:28 -0800258 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700259 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800260
Colin Cross55708f32017-03-20 13:23:34 -0700261 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700262 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700263
Jiyong Park2db76922017-11-08 16:03:48 +0900264 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
265 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
266 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700267 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700268
Jiyong Park2db76922017-11-08 16:03:48 +0900269 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
270 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
271 Soc_specific *bool
272
273 // whether this module is specific to a device, not only for SoC, but also for off-chip
274 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
275 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
276 // This implies `soc_specific:true`.
277 Device_specific *bool
278
279 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900280 // network operator, etc). When set to true, it is installed into /product (or
281 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900282 Product_specific *bool
283
Dario Frenifd05a742018-05-29 13:28:54 +0100284 // whether this module provides services owned by the OS provider to the core platform. When set
Dario Freni95cf7672018-08-17 00:57:57 +0100285 // to true, it is installed into /product_services (or /system/product_services if
286 // product_services partition does not exist).
287 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100288
Jiyong Parkf9332f12018-02-01 00:54:12 +0900289 // Whether this module is installed to recovery partition
290 Recovery *bool
291
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700292 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800293 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700294
Steven Moreland57a23d22018-04-04 15:42:19 -0700295 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800296 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700297
Chris Wolfe998306e2016-08-15 14:47:23 -0400298 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700299 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400300
Sasha Smundakb6d23052019-04-01 18:37:36 -0700301 // names of other modules to install on host if this module is installed
302 Host_required []string `android:"arch_variant"`
303
304 // names of other modules to install on target if this module is installed
305 Target_required []string `android:"arch_variant"`
306
Colin Cross5aac3622017-08-31 15:07:09 -0700307 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800308 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700309
Dan Willemsen569edc52018-11-19 09:33:29 -0800310 Dist struct {
311 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
312 // command line and any of these targets are also on the command line, or otherwise
313 // built
314 Targets []string `android:"arch_variant"`
315
316 // The name of the output artifact. This defaults to the basename of the output of
317 // the module.
318 Dest *string `android:"arch_variant"`
319
320 // The directory within the dist directory to store the artifact. Defaults to the
321 // top level directory ("").
322 Dir *string `android:"arch_variant"`
323
324 // A suffix to add to the artifact file name (before any extension).
325 Suffix *string `android:"arch_variant"`
326 } `android:"arch_variant"`
327
Colin Crossa1ad8d12016-06-01 17:09:44 -0700328 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700329 CompileTarget Target `blueprint:"mutated"`
330 CompileMultiTargets []Target `blueprint:"mutated"`
331 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800332
333 // Set by InitAndroidModule
334 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700335 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700336
337 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800338
339 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800340}
341
342type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800343 // If set to true, build a variant of the module for the host. Defaults to false.
344 Host_supported *bool
345
346 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700347 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800348}
349
Colin Crossc472d572015-03-17 15:06:21 -0700350type Multilib string
351
352const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800353 MultilibBoth Multilib = "both"
354 MultilibFirst Multilib = "first"
355 MultilibCommon Multilib = "common"
356 MultilibCommonFirst Multilib = "common_first"
357 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700358)
359
Colin Crossa1ad8d12016-06-01 17:09:44 -0700360type HostOrDeviceSupported int
361
362const (
363 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700364
365 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700366 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700367
368 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700369 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700370
371 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700372 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700373
374 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700375 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700376
377 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700378 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700379
380 // Nothing is supported. This is not exposed to the user, but used to mark a
381 // host only module as unsupported when the module type is not supported on
382 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700383 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700384)
385
Jiyong Park2db76922017-11-08 16:03:48 +0900386type moduleKind int
387
388const (
389 platformModule moduleKind = iota
390 deviceSpecificModule
391 socSpecificModule
392 productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100393 productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900394)
395
396func (k moduleKind) String() string {
397 switch k {
398 case platformModule:
399 return "platform"
400 case deviceSpecificModule:
401 return "device-specific"
402 case socSpecificModule:
403 return "soc-specific"
404 case productSpecificModule:
405 return "product-specific"
Dario Frenifd05a742018-05-29 13:28:54 +0100406 case productServicesSpecificModule:
407 return "productservices-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900408 default:
409 panic(fmt.Errorf("unknown module kind %d", k))
410 }
411}
412
Colin Cross36242852017-06-23 15:06:31 -0700413func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800414 base := m.base()
415 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700416
Colin Cross36242852017-06-23 15:06:31 -0700417 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700418 &base.nameProperties,
419 &base.commonProperties,
420 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700421 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700422 base.customizableProperties = m.GetProperties()
Colin Cross5049f022015-03-18 13:28:46 -0700423}
424
Colin Cross36242852017-06-23 15:06:31 -0700425func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
426 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700427
428 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800429 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700430 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700431 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700432 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800433
Dan Willemsen218f6562015-07-08 18:13:11 -0700434 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700435 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700436 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800437 }
438
Colin Cross36242852017-06-23 15:06:31 -0700439 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800440}
441
Colin Crossee0bc3b2018-10-02 22:01:37 -0700442func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
443 InitAndroidArchModule(m, hod, defaultMultilib)
444 m.base().commonProperties.UseTargetVariants = false
445}
446
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800447// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800448// modules. It should be included as an anonymous field in every module
449// struct definition. InitAndroidModule should then be called from the module's
450// factory function, and the return values from InitAndroidModule should be
451// returned from the factory function.
452//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800453// The ModuleBase type is responsible for implementing the GenerateBuildActions
454// method to support the blueprint.Module interface. This method will then call
455// the module's GenerateAndroidBuildActions method once for each build variant
456// that is to be built. GenerateAndroidBuildActions is passed a
457// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800458// AndroidModuleContext exposes extra functionality specific to the Android build
459// system including details about the particular build variant that is to be
460// generated.
461//
462// For example:
463//
464// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800465// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800466// )
467//
468// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800469// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800470// properties struct {
471// MyProperty string
472// }
473// }
474//
Colin Cross36242852017-06-23 15:06:31 -0700475// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800476// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700477// m.AddProperties(&m.properties)
478// android.InitAndroidModule(m)
479// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800480// }
481//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800482// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800483// // Get the CPU architecture for the current build variant.
484// variantArch := ctx.Arch()
485//
486// // ...
487// }
Colin Cross635c3b02016-05-18 15:37:25 -0700488type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800489 // Putting the curiously recurring thing pointing to the thing that contains
490 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700491 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700492 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800493
Colin Crossfc754582016-05-17 16:34:16 -0700494 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800495 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700496 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800497 hostAndDeviceProperties hostAndDeviceProperties
498 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700499 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700500 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800501
502 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700503 installFiles Paths
504 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900505 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700506
507 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
508 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800509 installTarget WritablePath
510 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700511 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700512
Colin Cross178a5092016-09-13 13:42:32 -0700513 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700514
515 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700516
517 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700518 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800519 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800520 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700521
522 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700523}
524
Colin Cross5f692ec2019-02-01 16:53:07 -0800525func (a *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
526
Colin Cross36242852017-06-23 15:06:31 -0700527func (a *ModuleBase) AddProperties(props ...interface{}) {
528 a.registerProps = append(a.registerProps, props...)
529}
530
531func (a *ModuleBase) GetProperties() []interface{} {
532 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800533}
534
Colin Crossae887032017-10-23 17:16:14 -0700535func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700536 return a.buildParams
537}
538
Colin Cross4c83e5c2019-02-25 14:54:28 -0800539func (a *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
540 return a.ruleParams
541}
542
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800543func (a *ModuleBase) VariablesForTests() map[string]string {
544 return a.variables
545}
546
Colin Crossa9d8bee2018-10-02 13:59:46 -0700547func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
548 a.prefer32 = prefer32
549}
550
Colin Crossce75d2c2016-10-06 16:12:58 -0700551// Name returns the name of the module. It may be overridden by individual module types, for
552// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700553func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800554 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700555}
556
Colin Crossce75d2c2016-10-06 16:12:58 -0700557// BaseModuleName returns the name of the module as specified in the blueprints file.
558func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800559 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700560}
561
Colin Cross635c3b02016-05-18 15:37:25 -0700562func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800563 return a
564}
565
Colin Crossee0bc3b2018-10-02 22:01:37 -0700566func (a *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700567 a.commonProperties.CompileTarget = target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700568 a.commonProperties.CompileMultiTargets = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700569 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700570}
571
Colin Crossa1ad8d12016-06-01 17:09:44 -0700572func (a *ModuleBase) Target() Target {
573 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800574}
575
Colin Cross8b74d172016-09-13 09:59:14 -0700576func (a *ModuleBase) TargetPrimary() bool {
577 return a.commonProperties.CompilePrimary
578}
579
Colin Crossee0bc3b2018-10-02 22:01:37 -0700580func (a *ModuleBase) MultiTargets() []Target {
581 return a.commonProperties.CompileMultiTargets
582}
583
Colin Crossa1ad8d12016-06-01 17:09:44 -0700584func (a *ModuleBase) Os() OsType {
585 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800586}
587
Colin Cross635c3b02016-05-18 15:37:25 -0700588func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700589 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800590}
591
Colin Cross635c3b02016-05-18 15:37:25 -0700592func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700593 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800594}
595
Dan Willemsen0b24c742016-10-04 15:13:37 -0700596func (a *ModuleBase) ArchSpecific() bool {
597 return a.commonProperties.ArchSpecific
598}
599
Colin Crossa1ad8d12016-06-01 17:09:44 -0700600func (a *ModuleBase) OsClassSupported() []OsClass {
601 switch a.commonProperties.HostOrDeviceSupported {
602 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700603 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700604 case HostSupportedNoCross:
605 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700606 case DeviceSupported:
607 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700608 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700609 var supported []OsClass
Dan Albert0981b5c2018-08-02 13:46:35 -0700610 if Bool(a.hostAndDeviceProperties.Host_supported) ||
611 (a.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
612 a.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700613 supported = append(supported, Host, HostCross)
614 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700615 if a.hostAndDeviceProperties.Device_supported == nil ||
616 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700617 supported = append(supported, Device)
618 }
619 return supported
620 default:
621 return nil
622 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800623}
624
Colin Cross635c3b02016-05-18 15:37:25 -0700625func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800626 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
627 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700628 (a.hostAndDeviceProperties.Device_supported == nil ||
629 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800630}
631
Jiyong Parkc678ad32018-04-10 13:07:10 +0900632func (a *ModuleBase) Platform() bool {
Dario Frenifd05a742018-05-29 13:28:54 +0100633 return !a.DeviceSpecific() && !a.SocSpecific() && !a.ProductSpecific() && !a.ProductServicesSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900634}
635
636func (a *ModuleBase) DeviceSpecific() bool {
637 return Bool(a.commonProperties.Device_specific)
638}
639
640func (a *ModuleBase) SocSpecific() bool {
641 return Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
642}
643
644func (a *ModuleBase) ProductSpecific() bool {
645 return Bool(a.commonProperties.Product_specific)
646}
647
Dario Frenifd05a742018-05-29 13:28:54 +0100648func (a *ModuleBase) ProductServicesSpecific() bool {
Dario Freni95cf7672018-08-17 00:57:57 +0100649 return Bool(a.commonProperties.Product_services_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100650}
651
Colin Cross635c3b02016-05-18 15:37:25 -0700652func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800653 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800654 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800655 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800656 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800657}
658
Colin Crossce75d2c2016-10-06 16:12:58 -0700659func (a *ModuleBase) SkipInstall() {
660 a.commonProperties.SkipInstall = true
661}
662
Jiyong Park374510b2018-03-19 18:23:01 +0900663func (a *ModuleBase) ExportedToMake() bool {
664 return a.commonProperties.NamespaceExportedToMake
665}
666
Colin Cross635c3b02016-05-18 15:37:25 -0700667func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700668 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800669
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700670 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700671 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800672 ctx.VisitDepsDepthFirstIf(isFileInstaller,
673 func(m blueprint.Module) {
674 fileInstaller := m.(fileInstaller)
675 files := fileInstaller.filesToInstall()
676 result = append(result, files...)
677 })
678
679 return result
680}
681
Colin Cross635c3b02016-05-18 15:37:25 -0700682func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800683 return a.installFiles
684}
685
Colin Cross635c3b02016-05-18 15:37:25 -0700686func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800687 return p.noAddressSanitizer
688}
689
Colin Cross635c3b02016-05-18 15:37:25 -0700690func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800691 return false
692}
693
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700694func (p *ModuleBase) InstallInSanitizerDir() bool {
695 return false
696}
697
Jiyong Parkf9332f12018-02-01 00:54:12 +0900698func (p *ModuleBase) InstallInRecovery() bool {
699 return Bool(p.commonProperties.Recovery)
700}
701
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900702func (a *ModuleBase) Owner() string {
703 return String(a.commonProperties.Owner)
704}
705
Jiyong Park52818fc2019-03-18 12:01:38 +0900706func (a *ModuleBase) NoticeFile() OptionalPath {
707 return a.noticeFile
708}
709
Colin Cross0875c522017-11-28 17:34:01 -0800710func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700711 allInstalledFiles := Paths{}
712 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800713 ctx.VisitAllModuleVariants(func(module Module) {
714 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700715 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
716 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800717 })
718
Colin Cross0875c522017-11-28 17:34:01 -0800719 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700720
Jeff Gaston088e29e2017-11-29 16:47:17 -0800721 namespacePrefix := ctx.Namespace().(*Namespace).id
722 if namespacePrefix != "" {
723 namespacePrefix = namespacePrefix + "-"
724 }
725
Colin Cross3f40fa42015-01-30 17:27:36 -0800726 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800727 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800728 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700729 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800730 Output: name,
731 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800732 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700733 })
734 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700735 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700736 }
737
738 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800739 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800740 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700741 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800742 Output: name,
743 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700744 })
745 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700746 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700747 }
748
749 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800750 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800751 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800752 suffix = "-soong"
753 }
754
Jeff Gaston088e29e2017-11-29 16:47:17 -0800755 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800756 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700757 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800758 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700759 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800760 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700761
762 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800763 }
764}
765
Jiyong Park2db76922017-11-08 16:03:48 +0900766func determineModuleKind(a *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
767 var socSpecific = Bool(a.commonProperties.Vendor) || Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Soc_specific)
768 var deviceSpecific = Bool(a.commonProperties.Device_specific)
769 var productSpecific = Bool(a.commonProperties.Product_specific)
Dario Freni95cf7672018-08-17 00:57:57 +0100770 var productServicesSpecific = Bool(a.commonProperties.Product_services_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900771
Dario Frenifd05a742018-05-29 13:28:54 +0100772 msg := "conflicting value set here"
773 if socSpecific && deviceSpecific {
774 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Jiyong Park2db76922017-11-08 16:03:48 +0900775 if Bool(a.commonProperties.Vendor) {
776 ctx.PropertyErrorf("vendor", msg)
777 }
778 if Bool(a.commonProperties.Proprietary) {
779 ctx.PropertyErrorf("proprietary", msg)
780 }
781 if Bool(a.commonProperties.Soc_specific) {
782 ctx.PropertyErrorf("soc_specific", msg)
783 }
784 }
785
Dario Frenifd05a742018-05-29 13:28:54 +0100786 if productSpecific && productServicesSpecific {
787 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and product_services at the same time.")
788 ctx.PropertyErrorf("product_services_specific", msg)
789 }
790
791 if (socSpecific || deviceSpecific) && (productSpecific || productServicesSpecific) {
792 if productSpecific {
793 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
794 } else {
795 ctx.PropertyErrorf("product_services_specific", "a module cannot be specific to SoC or device and product_services at the same time.")
796 }
797 if deviceSpecific {
798 ctx.PropertyErrorf("device_specific", msg)
799 } else {
800 if Bool(a.commonProperties.Vendor) {
801 ctx.PropertyErrorf("vendor", msg)
802 }
803 if Bool(a.commonProperties.Proprietary) {
804 ctx.PropertyErrorf("proprietary", msg)
805 }
806 if Bool(a.commonProperties.Soc_specific) {
807 ctx.PropertyErrorf("soc_specific", msg)
808 }
809 }
810 }
811
Jiyong Park2db76922017-11-08 16:03:48 +0900812 if productSpecific {
813 return productSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +0100814 } else if productServicesSpecific {
815 return productServicesSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900816 } else if deviceSpecific {
817 return deviceSpecificModule
818 } else if socSpecific {
819 return socSpecificModule
820 } else {
821 return platformModule
822 }
823}
824
Colin Cross635c3b02016-05-18 15:37:25 -0700825func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700826 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700827 target: a.commonProperties.CompileTarget,
828 targetPrimary: a.commonProperties.CompilePrimary,
Colin Crossee0bc3b2018-10-02 22:01:37 -0700829 multiTargets: a.commonProperties.CompileMultiTargets,
Jiyong Park2db76922017-11-08 16:03:48 +0900830 kind: determineModuleKind(a, ctx),
Colin Cross8b74d172016-09-13 09:59:14 -0700831 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800832 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800833}
834
Colin Cross0875c522017-11-28 17:34:01 -0800835func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
836 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700837 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800838 ModuleContext: blueprintCtx,
839 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
840 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700841 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800842 missingDeps: blueprintCtx.GetMissingDependencies(),
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800843 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800844 }
845
Colin Cross4c83e5c2019-02-25 14:54:28 -0800846 if ctx.config.captureBuild {
847 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
848 }
849
Colin Cross67a5c132017-05-09 13:45:28 -0700850 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
851 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800852 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
853 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700854 }
Colin Cross0875c522017-11-28 17:34:01 -0800855 if !ctx.PrimaryArch() {
856 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700857 }
858
859 ctx.Variable(pctx, "moduleDesc", desc)
860
861 s := ""
862 if len(suffix) > 0 {
863 s = " [" + strings.Join(suffix, " ") + "]"
864 }
865 ctx.Variable(pctx, "moduleDescSuffix", s)
866
Dan Willemsen569edc52018-11-19 09:33:29 -0800867 // Some common property checks for properties that will be used later in androidmk.go
868 if a.commonProperties.Dist.Dest != nil {
869 _, err := validateSafePath(*a.commonProperties.Dist.Dest)
870 if err != nil {
871 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
872 }
873 }
874 if a.commonProperties.Dist.Dir != nil {
875 _, err := validateSafePath(*a.commonProperties.Dist.Dir)
876 if err != nil {
877 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
878 }
879 }
880 if a.commonProperties.Dist.Suffix != nil {
881 if strings.Contains(*a.commonProperties.Dist.Suffix, "/") {
882 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
883 }
884 }
885
Colin Cross9b1d13d2016-09-19 15:18:11 -0700886 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800887 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700888 if ctx.Failed() {
889 return
890 }
891
Colin Cross0875c522017-11-28 17:34:01 -0800892 a.installFiles = append(a.installFiles, ctx.installFiles...)
893 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800894
Jiyong Park52818fc2019-03-18 12:01:38 +0900895 notice := proptools.StringDefault(a.commonProperties.Notice, "NOTICE")
896 if m := SrcIsModule(notice); m != "" {
897 a.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
898 } else {
899 noticePath := filepath.Join(ctx.ModuleDir(), notice)
900 a.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -0800901 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800902 }
903
Colin Cross9b1d13d2016-09-19 15:18:11 -0700904 if a == ctx.FinalModule().(Module).base() {
905 a.generateModuleTarget(ctx)
906 if ctx.Failed() {
907 return
908 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800909 }
Colin Crosscec81712017-07-13 14:43:27 -0700910
Colin Cross0875c522017-11-28 17:34:01 -0800911 a.buildParams = ctx.buildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800912 a.ruleParams = ctx.ruleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800913 a.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -0800914}
915
Colin Crossf6566ed2015-03-24 11:13:38 -0700916type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700917 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700918 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -0700919 targetPrimary bool
920 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +0900921 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -0700922 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700923}
924
Colin Cross3f40fa42015-01-30 17:27:36 -0800925type androidModuleContext struct {
926 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700927 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700928 installDeps Paths
929 installFiles Paths
930 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800931 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700932 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700933
934 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700935 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800936 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800937 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -0800938}
939
Colin Cross67a5c132017-05-09 13:45:28 -0700940func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800941 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700942 Rule: ErrorRule,
943 Description: desc,
944 Outputs: outputs,
945 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800946 Args: map[string]string{
947 "error": err.Error(),
948 },
949 })
950 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800951}
952
Colin Crossaabf6792017-11-29 00:27:14 -0800953func (a *androidModuleContext) Config() Config {
954 return a.ModuleContext.Config().(Config)
955}
956
Colin Cross0875c522017-11-28 17:34:01 -0800957func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700958 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800959}
960
Colin Cross0875c522017-11-28 17:34:01 -0800961func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700962 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700963 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800964 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800965 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700966 Outputs: params.Outputs.Strings(),
967 ImplicitOutputs: params.ImplicitOutputs.Strings(),
968 Inputs: params.Inputs.Strings(),
969 Implicits: params.Implicits.Strings(),
970 OrderOnly: params.OrderOnly.Strings(),
971 Args: params.Args,
972 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700973 }
974
Colin Cross33bfb0a2016-11-21 17:23:08 -0800975 if params.Depfile != nil {
976 bparams.Depfile = params.Depfile.String()
977 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700978 if params.Output != nil {
979 bparams.Outputs = append(bparams.Outputs, params.Output.String())
980 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700981 if params.ImplicitOutput != nil {
982 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
983 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700984 if params.Input != nil {
985 bparams.Inputs = append(bparams.Inputs, params.Input.String())
986 }
987 if params.Implicit != nil {
988 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
989 }
990
Colin Cross0b9f31f2019-02-28 11:00:01 -0800991 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
992 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
993 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
994 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
995 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
996 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -0700997
Colin Cross0875c522017-11-28 17:34:01 -0800998 return bparams
999}
1000
1001func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001002 if a.config.captureBuild {
1003 a.variables[name] = value
1004 }
1005
Colin Cross0875c522017-11-28 17:34:01 -08001006 a.ModuleContext.Variable(pctx.PackageContext, name, value)
1007}
1008
1009func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
1010 argNames ...string) blueprint.Rule {
1011
Colin Cross4c83e5c2019-02-25 14:54:28 -08001012 rule := a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
1013
1014 if a.config.captureBuild {
1015 a.ruleParams[rule] = params
1016 }
1017
1018 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001019}
1020
1021func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
1022 if a.config.captureBuild {
1023 a.buildParams = append(a.buildParams, params)
1024 }
1025
1026 bparams := convertBuildParams(params)
1027
1028 if bparams.Description != "" {
1029 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1030 }
1031
Colin Cross6ff51382015-12-17 16:39:19 -08001032 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -07001033 a.ninjaError(bparams.Description, bparams.Outputs,
1034 fmt.Errorf("module %s missing dependencies: %s\n",
1035 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -08001036 return
1037 }
1038
Colin Cross0875c522017-11-28 17:34:01 -08001039 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001040}
1041
Colin Cross6ff51382015-12-17 16:39:19 -08001042func (a *androidModuleContext) GetMissingDependencies() []string {
1043 return a.missingDeps
1044}
1045
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001046func (a *androidModuleContext) AddMissingDependencies(deps []string) {
1047 if deps != nil {
1048 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -07001049 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001050 }
1051}
1052
Colin Crossd11fcda2017-10-23 17:59:01 -07001053func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
1054 aModule, _ := module.(Module)
1055 if aModule == nil {
1056 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
1057 return nil
1058 }
1059
1060 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -08001061 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -07001062 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
1063 } else {
1064 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
1065 }
1066 return nil
1067 }
1068
1069 return aModule
1070}
1071
Jiyong Parkf2976302019-04-17 21:47:37 +09001072func (a *androidModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
1073 type dep struct {
1074 mod blueprint.Module
1075 tag blueprint.DependencyTag
1076 }
1077 var deps []dep
1078 a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
1079 if aModule, _ := m.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
1080 returnedTag := a.ModuleContext.OtherModuleDependencyTag(aModule)
1081 if tag == nil || returnedTag == tag {
1082 deps = append(deps, dep{aModule, returnedTag})
1083 }
1084 }
1085 })
1086 if len(deps) == 1 {
1087 return deps[0].mod, deps[0].tag
1088 } else if len(deps) >= 2 {
1089 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
1090 name, a.ModuleName()))
1091 } else {
1092 return nil, nil
1093 }
1094}
1095
1096func (a *androidModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1097 m, _ := a.getDirectDepInternal(name, tag)
1098 return m
1099}
1100
1101func (a *androidModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1102 return a.getDirectDepInternal(name, nil)
1103}
1104
Colin Cross35143d02017-11-16 00:11:20 -08001105func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1106 a.ModuleContext.VisitDirectDeps(visit)
1107}
1108
Colin Crossd11fcda2017-10-23 17:59:01 -07001109func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
1110 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1111 if aModule := a.validateAndroidModule(module); aModule != nil {
1112 visit(aModule)
1113 }
1114 })
1115}
1116
Colin Crossee6143c2017-12-30 17:54:27 -08001117func (a *androidModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1118 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1119 if aModule := a.validateAndroidModule(module); aModule != nil {
1120 if a.ModuleContext.OtherModuleDependencyTag(aModule) == tag {
1121 visit(aModule)
1122 }
1123 }
1124 })
1125}
1126
Colin Crossd11fcda2017-10-23 17:59:01 -07001127func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1128 a.ModuleContext.VisitDirectDepsIf(
1129 // pred
1130 func(module blueprint.Module) bool {
1131 if aModule := a.validateAndroidModule(module); aModule != nil {
1132 return pred(aModule)
1133 } else {
1134 return false
1135 }
1136 },
1137 // visit
1138 func(module blueprint.Module) {
1139 visit(module.(Module))
1140 })
1141}
1142
1143func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1144 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1145 if aModule := a.validateAndroidModule(module); aModule != nil {
1146 visit(aModule)
1147 }
1148 })
1149}
1150
1151func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1152 a.ModuleContext.VisitDepsDepthFirstIf(
1153 // pred
1154 func(module blueprint.Module) bool {
1155 if aModule := a.validateAndroidModule(module); aModule != nil {
1156 return pred(aModule)
1157 } else {
1158 return false
1159 }
1160 },
1161 // visit
1162 func(module blueprint.Module) {
1163 visit(module.(Module))
1164 })
1165}
1166
Alex Light778127a2019-02-27 14:19:50 -08001167func (a *androidModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1168 a.ModuleContext.WalkDeps(visit)
1169}
1170
Colin Crossd11fcda2017-10-23 17:59:01 -07001171func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
1172 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1173 childAndroidModule := a.validateAndroidModule(child)
1174 parentAndroidModule := a.validateAndroidModule(parent)
1175 if childAndroidModule != nil && parentAndroidModule != nil {
1176 return visit(childAndroidModule, parentAndroidModule)
1177 } else {
1178 return false
1179 }
1180 })
1181}
1182
Colin Cross0875c522017-11-28 17:34:01 -08001183func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
1184 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
1185 visit(module.(Module))
1186 })
1187}
1188
1189func (a *androidModuleContext) PrimaryModule() Module {
1190 return a.ModuleContext.PrimaryModule().(Module)
1191}
1192
1193func (a *androidModuleContext) FinalModule() Module {
1194 return a.ModuleContext.FinalModule().(Module)
1195}
1196
Colin Crossa1ad8d12016-06-01 17:09:44 -07001197func (a *androidBaseContextImpl) Target() Target {
1198 return a.target
1199}
1200
Colin Cross8b74d172016-09-13 09:59:14 -07001201func (a *androidBaseContextImpl) TargetPrimary() bool {
1202 return a.targetPrimary
1203}
1204
Colin Crossee0bc3b2018-10-02 22:01:37 -07001205func (a *androidBaseContextImpl) MultiTargets() []Target {
1206 return a.multiTargets
1207}
1208
Colin Crossf6566ed2015-03-24 11:13:38 -07001209func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001210 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001211}
1212
Colin Crossa1ad8d12016-06-01 17:09:44 -07001213func (a *androidBaseContextImpl) Os() OsType {
1214 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001215}
1216
Colin Crossf6566ed2015-03-24 11:13:38 -07001217func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001218 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001219}
1220
1221func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001222 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001223}
1224
Colin Cross0af4b842015-04-30 16:36:18 -07001225func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001226 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001227}
1228
Doug Horn21b94272019-01-16 12:06:11 -08001229func (a *androidBaseContextImpl) Fuchsia() bool {
1230 return a.target.Os == Fuchsia
1231}
1232
Colin Cross3edeee12017-04-04 12:59:48 -07001233func (a *androidBaseContextImpl) Windows() bool {
1234 return a.target.Os == Windows
1235}
1236
Colin Crossf6566ed2015-03-24 11:13:38 -07001237func (a *androidBaseContextImpl) Debug() bool {
1238 return a.debug
1239}
1240
Colin Cross1e7d3702016-08-24 15:25:47 -07001241func (a *androidBaseContextImpl) PrimaryArch() bool {
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001242 if len(a.config.Targets[a.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001243 return true
1244 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001245 return a.target.Arch.ArchType == a.config.Targets[a.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001246}
1247
Colin Cross1332b002015-04-07 17:11:30 -07001248func (a *androidBaseContextImpl) AConfig() Config {
1249 return a.config
1250}
1251
Colin Cross9272ade2016-08-17 15:24:12 -07001252func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
1253 return DeviceConfig{a.config.deviceConfig}
1254}
1255
Jiyong Park2db76922017-11-08 16:03:48 +09001256func (a *androidBaseContextImpl) Platform() bool {
1257 return a.kind == platformModule
1258}
1259
1260func (a *androidBaseContextImpl) DeviceSpecific() bool {
1261 return a.kind == deviceSpecificModule
1262}
1263
1264func (a *androidBaseContextImpl) SocSpecific() bool {
1265 return a.kind == socSpecificModule
1266}
1267
1268func (a *androidBaseContextImpl) ProductSpecific() bool {
1269 return a.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001270}
1271
Dario Frenifd05a742018-05-29 13:28:54 +01001272func (a *androidBaseContextImpl) ProductServicesSpecific() bool {
1273 return a.kind == productServicesSpecificModule
1274}
1275
Jiyong Park5baac542018-08-28 09:55:37 +09001276// Makes this module a platform module, i.e. not specific to soc, device,
1277// product, or product_services.
1278func (a *ModuleBase) MakeAsPlatform() {
1279 a.commonProperties.Vendor = boolPtr(false)
1280 a.commonProperties.Proprietary = boolPtr(false)
1281 a.commonProperties.Soc_specific = boolPtr(false)
1282 a.commonProperties.Product_specific = boolPtr(false)
1283 a.commonProperties.Product_services_specific = boolPtr(false)
1284}
1285
Colin Cross8d8f8e22016-08-03 11:57:50 -07001286func (a *androidModuleContext) InstallInData() bool {
1287 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001288}
1289
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001290func (a *androidModuleContext) InstallInSanitizerDir() bool {
1291 return a.module.InstallInSanitizerDir()
1292}
1293
Jiyong Parkf9332f12018-02-01 00:54:12 +09001294func (a *androidModuleContext) InstallInRecovery() bool {
1295 return a.module.InstallInRecovery()
1296}
1297
Colin Cross893d8162017-04-26 17:34:03 -07001298func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
1299 if a.module.base().commonProperties.SkipInstall {
1300 return true
1301 }
1302
Colin Cross3607f212018-05-07 15:28:05 -07001303 // We'll need a solution for choosing which of modules with the same name in different
1304 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1305 // list of namespaces to install in a Soong-only build.
1306 if !a.module.base().commonProperties.NamespaceExportedToMake {
1307 return true
1308 }
1309
Colin Cross893d8162017-04-26 17:34:03 -07001310 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -08001311 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -07001312 return true
1313 }
1314
Colin Cross6510f912017-11-29 00:27:14 -08001315 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001316 return true
1317 }
1318 }
1319
1320 return false
1321}
1322
Colin Cross5c517922017-08-31 12:29:17 -07001323func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001324 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -07001325 return a.installFile(installPath, name, srcPath, Cp, deps)
1326}
1327
1328func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
1329 deps ...Path) OutputPath {
1330 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
1331}
1332
1333func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
1334 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001335
Dan Willemsen782a2d12015-12-21 14:55:28 -08001336 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001337 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001338
Colin Cross893d8162017-04-26 17:34:03 -07001339 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001340
Dan Willemsen322acaf2016-01-12 23:07:05 -08001341 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001342
Colin Cross89562dc2016-10-03 17:47:19 -07001343 var implicitDeps, orderOnlyDeps Paths
1344
1345 if a.Host() {
1346 // Installed host modules might be used during the build, depend directly on their
1347 // dependencies so their timestamp is updated whenever their dependency is updated
1348 implicitDeps = deps
1349 } else {
1350 orderOnlyDeps = deps
1351 }
1352
Colin Crossae887032017-10-23 17:16:14 -07001353 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001354 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001355 Description: "install " + fullInstallPath.Base(),
1356 Output: fullInstallPath,
1357 Input: srcPath,
1358 Implicits: implicitDeps,
1359 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -08001360 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001361 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001362
Dan Willemsen322acaf2016-01-12 23:07:05 -08001363 a.installFiles = append(a.installFiles, fullInstallPath)
1364 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001365 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001366 return fullInstallPath
1367}
1368
Colin Cross3854a602016-01-11 12:49:11 -08001369func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1370 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -07001371 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001372
Colin Cross893d8162017-04-26 17:34:03 -07001373 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001374
Alex Lightfb4353d2019-01-17 13:57:45 -08001375 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1376 if err != nil {
1377 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1378 }
Colin Crossae887032017-10-23 17:16:14 -07001379 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001380 Rule: Symlink,
1381 Description: "install symlink " + fullInstallPath.Base(),
1382 Output: fullInstallPath,
1383 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -08001384 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001385 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001386 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001387 },
1388 })
Colin Cross3854a602016-01-11 12:49:11 -08001389
Colin Cross12fc4972016-01-11 12:49:11 -08001390 a.installFiles = append(a.installFiles, fullInstallPath)
1391 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1392 }
Colin Cross3854a602016-01-11 12:49:11 -08001393 return fullInstallPath
1394}
1395
Jiyong Parkf1194352019-02-25 11:05:47 +09001396// installPath/name -> absPath where absPath might be a path that is available only at runtime
1397// (e.g. /apex/...)
1398func (a *androidModuleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1399 fullInstallPath := installPath.Join(a, name)
1400 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
1401
1402 if !a.skipInstall(fullInstallPath) {
1403 a.Build(pctx, BuildParams{
1404 Rule: Symlink,
1405 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1406 Output: fullInstallPath,
1407 Default: !a.Config().EmbeddedInMake(),
1408 Args: map[string]string{
1409 "fromPath": absPath,
1410 },
1411 })
1412
1413 a.installFiles = append(a.installFiles, fullInstallPath)
1414 }
1415 return fullInstallPath
1416}
1417
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001418func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001419 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
1420}
1421
Colin Cross3f40fa42015-01-30 17:27:36 -08001422type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001423 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001424}
1425
1426func isFileInstaller(m blueprint.Module) bool {
1427 _, ok := m.(fileInstaller)
1428 return ok
1429}
1430
1431func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001432 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001433 return ok
1434}
Colin Crossfce53272015-04-08 11:21:40 -07001435
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001436func findStringInSlice(str string, slice []string) int {
1437 for i, s := range slice {
1438 if s == str {
1439 return i
Colin Crossfce53272015-04-08 11:21:40 -07001440 }
1441 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001442 return -1
1443}
1444
Colin Cross068e0fe2016-12-13 15:23:47 -08001445func SrcIsModule(s string) string {
1446 if len(s) > 1 && s[0] == ':' {
1447 return s[1:]
1448 }
1449 return ""
1450}
1451
1452type sourceDependencyTag struct {
1453 blueprint.BaseDependencyTag
1454}
1455
1456var SourceDepTag sourceDependencyTag
1457
Colin Cross366938f2017-12-11 16:29:02 -08001458// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1459// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001460//
1461// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001462func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1463 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001464 set := make(map[string]bool)
1465
Colin Cross068e0fe2016-12-13 15:23:47 -08001466 for _, s := range srcFiles {
1467 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001468 if _, found := set[m]; found {
1469 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1470 } else {
1471 set[m] = true
1472 deps = append(deps, m)
1473 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001474 }
1475 }
1476
1477 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1478}
1479
Colin Cross366938f2017-12-11 16:29:02 -08001480// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1481// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001482//
1483// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001484func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1485 if s != nil {
1486 if m := SrcIsModule(*s); m != "" {
1487 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1488 }
1489 }
1490}
1491
Colin Cross068e0fe2016-12-13 15:23:47 -08001492type SourceFileProducer interface {
1493 Srcs() Paths
1494}
1495
Colin Crossfe17f6f2019-03-28 19:30:56 -07001496type HostToolProvider interface {
1497 HostToolPath() OptionalPath
1498}
1499
Colin Cross27b922f2019-03-04 22:35:41 -08001500// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1501// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001502//
1503// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001504func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Cross8a497952019-03-05 22:25:09 -08001505 return PathsForModuleSrcExcludes(ctx, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001506}
1507
Colin Cross2fafa3e2019-03-05 12:39:51 -08001508// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1509// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001510//
1511// Deprecated: use PathForModuleSrc instead.
Colin Cross2fafa3e2019-03-05 12:39:51 -08001512func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
Colin Cross8a497952019-03-05 22:25:09 -08001513 return PathForModuleSrc(ctx, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001514}
1515
1516// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1517// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1518// dependency resolution.
1519func (ctx *androidModuleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
1520 if srcFile != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001521 return OptionalPathForPath(PathForModuleSrc(ctx, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001522 }
1523 return OptionalPath{}
1524}
1525
Nan Zhang6d34b302017-02-04 17:47:46 -08001526func (ctx *androidModuleContext) RequiredModuleNames() []string {
1527 return ctx.module.base().commonProperties.Required
1528}
1529
Sasha Smundakb6d23052019-04-01 18:37:36 -07001530func (ctx *androidModuleContext) HostRequiredModuleNames() []string {
1531 return ctx.module.base().commonProperties.Host_required
1532}
1533
1534func (ctx *androidModuleContext) TargetRequiredModuleNames() []string {
1535 return ctx.module.base().commonProperties.Target_required
1536}
1537
Colin Cross7f19f372016-11-01 11:10:25 -07001538func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1539 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001540 if err != nil {
1541 ctx.ModuleErrorf("glob: %s", err.Error())
1542 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001543 return pathsForModuleSrcFromFullPath(ctx, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001544}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001545
Nan Zhang581fd212018-01-10 16:06:12 -08001546func (ctx *androidModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Dan Willemsen540a78c2018-02-26 21:50:08 -08001547 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001548 if err != nil {
1549 ctx.ModuleErrorf("glob: %s", err.Error())
1550 }
Dan Willemsen540a78c2018-02-26 21:50:08 -08001551 return pathsForModuleSrcFromFullPath(ctx, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001552}
1553
Colin Cross463a90e2015-06-17 14:20:06 -07001554func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001555 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001556}
1557
Colin Cross0875c522017-11-28 17:34:01 -08001558func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001559 return &buildTargetSingleton{}
1560}
1561
Colin Cross87d8b562017-04-25 10:01:55 -07001562func parentDir(dir string) string {
1563 dir, _ = filepath.Split(dir)
1564 return filepath.Clean(dir)
1565}
1566
Colin Cross1f8c52b2015-06-16 16:38:17 -07001567type buildTargetSingleton struct{}
1568
Colin Cross0875c522017-11-28 17:34:01 -08001569func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1570 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001571
Colin Cross0875c522017-11-28 17:34:01 -08001572 mmTarget := func(dir string) WritablePath {
1573 return PathForPhony(ctx,
1574 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001575 }
1576
Colin Cross0875c522017-11-28 17:34:01 -08001577 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001578
Colin Cross0875c522017-11-28 17:34:01 -08001579 ctx.VisitAllModules(func(module Module) {
1580 blueprintDir := module.base().blueprintDir
1581 installTarget := module.base().installTarget
1582 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001583
Colin Cross0875c522017-11-28 17:34:01 -08001584 if checkbuildTarget != nil {
1585 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1586 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1587 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001588
Colin Cross0875c522017-11-28 17:34:01 -08001589 if installTarget != nil {
1590 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001591 }
1592 })
1593
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001594 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001595 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001596 suffix = "-soong"
1597 }
1598
Colin Cross1f8c52b2015-06-16 16:38:17 -07001599 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001600 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001601 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001602 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001603 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001604 })
1605
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001606 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001607 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001608 return
1609 }
1610
Colin Cross0875c522017-11-28 17:34:01 -08001611 sortedKeys := func(m map[string]Paths) []string {
1612 s := make([]string, 0, len(m))
1613 for k := range m {
1614 s = append(s, k)
1615 }
1616 sort.Strings(s)
1617 return s
1618 }
1619
Colin Cross87d8b562017-04-25 10:01:55 -07001620 // Ensure ancestor directories are in modulesInDir
1621 dirs := sortedKeys(modulesInDir)
1622 for _, dir := range dirs {
1623 dir := parentDir(dir)
1624 for dir != "." && dir != "/" {
1625 if _, exists := modulesInDir[dir]; exists {
1626 break
1627 }
1628 modulesInDir[dir] = nil
1629 dir = parentDir(dir)
1630 }
1631 }
1632
1633 // Make directories build their direct subdirectories
1634 dirs = sortedKeys(modulesInDir)
1635 for _, dir := range dirs {
1636 p := parentDir(dir)
1637 if p != "." && p != "/" {
1638 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1639 }
1640 }
1641
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001642 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1643 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1644 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001645 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001646 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001647 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001648 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001649 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001650 // HACK: checkbuild should be an optional build, but force it
1651 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001652 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001653 })
1654 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001655
1656 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1657 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001658 ctx.VisitAllModules(func(module Module) {
1659 if module.Enabled() {
1660 os := module.Target().Os
1661 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001662 }
1663 })
1664
Colin Cross0875c522017-11-28 17:34:01 -08001665 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001666 for os, deps := range osDeps {
1667 var className string
1668
1669 switch os.Class {
1670 case Host:
1671 className = "host"
1672 case HostCross:
1673 className = "host-cross"
1674 case Device:
1675 className = "target"
1676 default:
1677 continue
1678 }
1679
Colin Cross0875c522017-11-28 17:34:01 -08001680 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001681 osClass[className] = append(osClass[className], name)
1682
Colin Cross0875c522017-11-28 17:34:01 -08001683 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001684 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001685 Output: name,
1686 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001687 })
1688 }
1689
1690 // Wrap those into host|host-cross|target phony rules
1691 osClasses := sortedKeys(osClass)
1692 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001693 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001694 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001695 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001696 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001697 })
1698 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001699}
Colin Crossd779da42015-12-17 18:00:23 -08001700
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001701// Collect information for opening IDE project files in java/jdeps.go.
1702type IDEInfo interface {
1703 IDEInfo(ideInfo *IdeInfo)
1704 BaseModuleName() string
1705}
1706
1707// Extract the base module name from the Import name.
1708// Often the Import name has a prefix "prebuilt_".
1709// Remove the prefix explicitly if needed
1710// until we find a better solution to get the Import name.
1711type IDECustomizedModuleName interface {
1712 IDECustomizedModuleName() string
1713}
1714
1715type IdeInfo struct {
1716 Deps []string `json:"dependencies,omitempty"`
1717 Srcs []string `json:"srcs,omitempty"`
1718 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1719 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1720 Jars []string `json:"jars,omitempty"`
1721 Classes []string `json:"class,omitempty"`
1722 Installed_paths []string `json:"installed,omitempty"`
1723}