blob: 990a893a738a5adbf7c5cd187071f99fd47a2eac [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 Cross6ff51382015-12-17 16:39:19 -080021 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080022 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070023
24 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070025 "github.com/google/blueprint/pathtools"
Colin Crossfe4bc362018-09-12 10:02:13 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
29var (
30 DeviceSharedLibrary = "shared_library"
31 DeviceStaticLibrary = "static_library"
32 DeviceExecutable = "executable"
33 HostSharedLibrary = "host_shared_library"
34 HostStaticLibrary = "host_static_library"
35 HostExecutable = "host_executable"
36)
37
Colin Crossae887032017-10-23 17:16:14 -070038type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080040 Deps blueprint.Deps
41 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070043 Output WritablePath
44 Outputs WritablePaths
45 ImplicitOutput WritablePath
46 ImplicitOutputs WritablePaths
47 Input Path
48 Inputs Paths
49 Implicit Path
50 Implicits Paths
51 OrderOnly Paths
52 Default bool
53 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070054}
55
Colin Crossae887032017-10-23 17:16:14 -070056type ModuleBuildParams BuildParams
57
Colin Cross0ea8ba82019-06-06 14:33:29 -070058// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -070059// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
60// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -070061// about the current module.
62type BaseModuleContext interface {
Colin Crossdc35e212019-06-06 16:13:11 -070063 Module() Module
Colin Cross0ea8ba82019-06-06 14:33:29 -070064 ModuleName() string
65 ModuleDir() string
66 ModuleType() string
67 Config() Config
68
Colin Crossdc35e212019-06-06 16:13:11 -070069 OtherModuleName(m blueprint.Module) string
70 OtherModuleDir(m blueprint.Module) string
71 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
72 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
73 OtherModuleExists(name string) bool
74
75 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
76 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
77 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
78
79 VisitDirectDepsBlueprint(visit func(blueprint.Module))
80 VisitDirectDeps(visit func(Module))
81 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
82 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
83 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
84 VisitDepsDepthFirst(visit func(Module))
85 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
86 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
87 WalkDeps(visit func(Module, Module) bool)
88 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
89 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
90 // and returns a top-down dependency path from a start module to current child module.
91 GetWalkPath() []Module
92
Colin Cross0ea8ba82019-06-06 14:33:29 -070093 ContainsProperty(name string) bool
94 Errorf(pos scanner.Position, fmt string, args ...interface{})
95 ModuleErrorf(fmt string, args ...interface{})
96 PropertyErrorf(property, fmt string, args ...interface{})
97 Failed() bool
98
99 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
100 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
101 // builder whenever a file matching the pattern as added or removed, without rerunning if a
102 // file that does not match the pattern is added to a searched directory.
103 GlobWithDeps(pattern string, excludes []string) ([]string, error)
104
Colin Crossdc35e212019-06-06 16:13:11 -0700105 Glob(globPattern string, excludes []string) Paths
106 GlobFiles(globPattern string, excludes []string) Paths
107
Colin Cross0ea8ba82019-06-06 14:33:29 -0700108 Fs() pathtools.FileSystem
109 AddNinjaFileDeps(deps ...string)
110
Colin Crossdc35e212019-06-06 16:13:11 -0700111 AddMissingDependencies(missingDeps []string)
112
Colin Crossa1ad8d12016-06-01 17:09:44 -0700113 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700114 TargetPrimary() bool
Colin Crossee0bc3b2018-10-02 22:01:37 -0700115 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700116 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700117 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700118 Host() bool
119 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700120 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800121 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700122 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700123 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700124 PrimaryArch() bool
Jiyong Park2db76922017-11-08 16:03:48 +0900125 Platform() bool
126 DeviceSpecific() bool
127 SocSpecific() bool
128 ProductSpecific() bool
Justin Yund5f6c822019-06-25 16:47:17 +0900129 SystemExtSpecific() bool
Colin Cross1332b002015-04-07 17:11:30 -0700130 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -0700131 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -0700132}
133
Colin Cross0ea8ba82019-06-06 14:33:29 -0700134// Deprecated: use BaseModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700135type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800136 BaseModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800137}
138
Colin Cross635c3b02016-05-18 15:37:25 -0700139type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800140 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800141
Colin Crossae887032017-10-23 17:16:14 -0700142 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800143 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700144
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700145 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800146 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800147 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700148
Colin Cross5c517922017-08-31 12:29:17 -0700149 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
150 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800151 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Jiyong Parkf1194352019-02-25 11:05:47 +0900152 InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700153 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800154
Colin Cross8d8f8e22016-08-03 11:57:50 -0700155 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700156 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900157 InstallInRecovery() bool
Colin Cross607d8582019-07-29 16:44:46 -0700158 InstallBypassMake() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800159
160 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700161 HostRequiredModuleNames() []string
162 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700163
Colin Cross3f68a132017-10-23 17:10:29 -0700164 ModuleSubDir() string
165
Colin Cross0875c522017-11-28 17:34:01 -0800166 Variable(pctx PackageContext, name, value string)
167 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700168 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
169 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800170 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700171
Colin Cross0875c522017-11-28 17:34:01 -0800172 PrimaryModule() Module
173 FinalModule() Module
174 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700175
176 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800177 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800178}
179
Colin Cross635c3b02016-05-18 15:37:25 -0700180type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800181 blueprint.Module
182
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700183 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
184 // but GenerateAndroidBuildActions also has access to Android-specific information.
185 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700186 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700187
Colin Cross1e676be2016-10-12 14:38:15 -0700188 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800189
Colin Cross635c3b02016-05-18 15:37:25 -0700190 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800191 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700192 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800193 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700194 InstallInSanitizerDir() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900195 InstallInRecovery() bool
Colin Cross607d8582019-07-29 16:44:46 -0700196 InstallBypassMake() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800197 SkipInstall()
Jiyong Park374510b2018-03-19 18:23:01 +0900198 ExportedToMake() bool
Jiyong Park52818fc2019-03-18 12:01:38 +0900199 NoticeFile() OptionalPath
Colin Cross36242852017-06-23 15:06:31 -0700200
201 AddProperties(props ...interface{})
202 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700203
Colin Crossae887032017-10-23 17:16:14 -0700204 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800205 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800206 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100207
Colin Cross9a362232019-07-01 15:32:45 -0700208 // String returns a string that includes the module name and variants for printing during debugging.
209 String() string
210
Paul Duffine2453c72019-05-31 14:00:04 +0100211 // Get the qualified module id for this module.
212 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
213
214 // Get information about the properties that can contain visibility rules.
215 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100216
217 // Get the visibility rules that control the visibility of this module.
218 visibility() []string
Paul Duffine2453c72019-05-31 14:00:04 +0100219}
220
221// Qualified id for a module
222type qualifiedModuleName struct {
223 // The package (i.e. directory) in which the module is defined, without trailing /
224 pkg string
225
226 // The name of the module, empty string if package.
227 name string
228}
229
230func (q qualifiedModuleName) String() string {
231 if q.name == "" {
232 return "//" + q.pkg
233 }
234 return "//" + q.pkg + ":" + q.name
235}
236
Paul Duffine484f472019-06-20 16:38:08 +0100237func (q qualifiedModuleName) isRootPackage() bool {
238 return q.pkg == "" && q.name == ""
239}
240
Paul Duffine2453c72019-05-31 14:00:04 +0100241// Get the id for the package containing this module.
242func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
243 pkg := q.pkg
244 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100245 if pkg == "" {
246 panic(fmt.Errorf("Cannot get containing package id of root package"))
247 }
248
249 index := strings.LastIndex(pkg, "/")
250 if index == -1 {
251 pkg = ""
252 } else {
253 pkg = pkg[:index]
254 }
Paul Duffine2453c72019-05-31 14:00:04 +0100255 }
256 return newPackageId(pkg)
257}
258
259func newPackageId(pkg string) qualifiedModuleName {
260 // A qualified id for a package module has no name.
261 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800262}
263
Colin Crossfc754582016-05-17 16:34:16 -0700264type nameProperties struct {
265 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800266 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700267}
268
269type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800270 // emit build rules for this module
271 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800272
Paul Duffin2e61fa62019-03-28 14:10:57 +0000273 // Controls the visibility of this module to other modules. Allowable values are one or more of
274 // these formats:
275 //
276 // ["//visibility:public"]: Anyone can use this module.
277 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
278 // this module.
279 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
280 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
281 // this module. Note that sub-packages do not have access to the rule; for example,
282 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
283 // is a special module and must be used verbatim. It represents all of the modules in the
284 // package.
285 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
286 // or other or in one of their sub-packages have access to this module. For example,
287 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
288 // to depend on this rule (but not //independent:evil)
289 // ["//project"]: This is shorthand for ["//project:__pkg__"]
290 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
291 // //project is the module's package. e.g. using [":__subpackages__"] in
292 // packages/apps/Settings/Android.bp is equivalent to
293 // //packages/apps/Settings:__subpackages__.
294 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
295 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100296 //
297 // If a module does not specify the `visibility` property then it uses the
298 // `default_visibility` property of the `package` module in the module's package.
299 //
Paul Duffine484f472019-06-20 16:38:08 +0100300 // If a module does not specify the `visibility` property then it uses the
301 // `default_visibility` property of the `package` module in the module's package.
302 //
Paul Duffine2453c72019-05-31 14:00:04 +0100303 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100304 // it will use the `default_visibility` of its closest ancestor package for which
305 // a `default_visibility` property is specified.
306 //
307 // If no `default_visibility` property can be found then the module uses the
308 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100309 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100310 // The `visibility` property has no effect on a defaults module although it does
311 // apply to any non-defaults module that uses it. To set the visibility of a
312 // defaults module, use the `defaults_visibility` property on the defaults module;
313 // not to be confused with the `default_visibility` property on the package module.
314 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000315 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
316 // more details.
317 Visibility []string
318
Colin Cross7d5136f2015-05-11 13:39:40 -0700319 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800320 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
321 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
322 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700323 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700324
325 Target struct {
326 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700327 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700328 }
329 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700330 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700331 }
332 }
333
Colin Crossee0bc3b2018-10-02 22:01:37 -0700334 UseTargetVariants bool `blueprint:"mutated"`
335 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800336
Dan Willemsen782a2d12015-12-21 14:55:28 -0800337 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700338 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800339
Colin Cross55708f32017-03-20 13:23:34 -0700340 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700341 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700342
Jiyong Park2db76922017-11-08 16:03:48 +0900343 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
344 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
345 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700346 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700347
Jiyong Park2db76922017-11-08 16:03:48 +0900348 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
349 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
350 Soc_specific *bool
351
352 // whether this module is specific to a device, not only for SoC, but also for off-chip
353 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
354 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
355 // This implies `soc_specific:true`.
356 Device_specific *bool
357
358 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900359 // network operator, etc). When set to true, it is installed into /product (or
360 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900361 Product_specific *bool
362
Justin Yund5f6c822019-06-25 16:47:17 +0900363 // TODO(b/135957588) Product_services_specific will be removed once we clear all Android.bp
364 // files that have 'product_services_specific: true'. This will be converted to
365 // Product_speicific as a workaround.
Dario Freni95cf7672018-08-17 00:57:57 +0100366 Product_services_specific *bool
Dario Frenifd05a742018-05-29 13:28:54 +0100367
Justin Yund5f6c822019-06-25 16:47:17 +0900368 // whether this module extends system. When set to true, it is installed into /system_ext
369 // (or /system/system_ext if system_ext partition does not exist).
370 System_ext_specific *bool
371
Jiyong Parkf9332f12018-02-01 00:54:12 +0900372 // Whether this module is installed to recovery partition
373 Recovery *bool
374
dimitry1f33e402019-03-26 12:39:31 +0100375 // Whether this module is built for non-native architecures (also known as native bridge binary)
376 Native_bridge_supported *bool `android:"arch_variant"`
377
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700378 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800379 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700380
Steven Moreland57a23d22018-04-04 15:42:19 -0700381 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800382 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700383
Chris Wolfe998306e2016-08-15 14:47:23 -0400384 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700385 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400386
Sasha Smundakb6d23052019-04-01 18:37:36 -0700387 // names of other modules to install on host if this module is installed
388 Host_required []string `android:"arch_variant"`
389
390 // names of other modules to install on target if this module is installed
391 Target_required []string `android:"arch_variant"`
392
Colin Cross5aac3622017-08-31 15:07:09 -0700393 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800394 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700395
Dan Willemsen569edc52018-11-19 09:33:29 -0800396 Dist struct {
397 // copy the output of this module to the $DIST_DIR when `dist` is specified on the
398 // command line and any of these targets are also on the command line, or otherwise
399 // built
400 Targets []string `android:"arch_variant"`
401
402 // The name of the output artifact. This defaults to the basename of the output of
403 // the module.
404 Dest *string `android:"arch_variant"`
405
406 // The directory within the dist directory to store the artifact. Defaults to the
407 // top level directory ("").
408 Dir *string `android:"arch_variant"`
409
410 // A suffix to add to the artifact file name (before any extension).
411 Suffix *string `android:"arch_variant"`
412 } `android:"arch_variant"`
413
Colin Crossa1ad8d12016-06-01 17:09:44 -0700414 // Set by TargetMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700415 CompileTarget Target `blueprint:"mutated"`
416 CompileMultiTargets []Target `blueprint:"mutated"`
417 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800418
419 // Set by InitAndroidModule
420 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700421 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700422
423 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800424
425 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700426
427 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700428
429 // Name and variant strings stored by mutators to enable Module.String()
430 DebugName string `blueprint:"mutated"`
431 DebugMutators []string `blueprint:"mutated"`
432 DebugVariations []string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800433}
434
435type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800436 // If set to true, build a variant of the module for the host. Defaults to false.
437 Host_supported *bool
438
439 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700440 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800441}
442
Colin Crossc472d572015-03-17 15:06:21 -0700443type Multilib string
444
445const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800446 MultilibBoth Multilib = "both"
447 MultilibFirst Multilib = "first"
448 MultilibCommon Multilib = "common"
449 MultilibCommonFirst Multilib = "common_first"
450 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700451)
452
Colin Crossa1ad8d12016-06-01 17:09:44 -0700453type HostOrDeviceSupported int
454
455const (
456 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700457
458 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700459 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700460
461 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700462 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700463
464 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700465 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700466
467 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700468 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700469
470 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700471 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700472
473 // Nothing is supported. This is not exposed to the user, but used to mark a
474 // host only module as unsupported when the module type is not supported on
475 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700476 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700477)
478
Jiyong Park2db76922017-11-08 16:03:48 +0900479type moduleKind int
480
481const (
482 platformModule moduleKind = iota
483 deviceSpecificModule
484 socSpecificModule
485 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900486 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900487)
488
489func (k moduleKind) String() string {
490 switch k {
491 case platformModule:
492 return "platform"
493 case deviceSpecificModule:
494 return "device-specific"
495 case socSpecificModule:
496 return "soc-specific"
497 case productSpecificModule:
498 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900499 case systemExtSpecificModule:
500 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900501 default:
502 panic(fmt.Errorf("unknown module kind %d", k))
503 }
504}
505
Colin Cross36242852017-06-23 15:06:31 -0700506func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800507 base := m.base()
508 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700509
Colin Cross36242852017-06-23 15:06:31 -0700510 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700511 &base.nameProperties,
512 &base.commonProperties,
513 &base.variableProperties)
Colin Crossa3a97412019-03-18 12:24:29 -0700514 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700515 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100516
517 // The default_visibility property needs to be checked and parsed by the visibility module during
518 // its checking and parsing phases.
519 base.primaryVisibilityProperty =
520 newVisibilityProperty("visibility", &base.commonProperties.Visibility)
521 base.visibilityPropertyInfo = []visibilityProperty{base.primaryVisibilityProperty}
Colin Cross5049f022015-03-18 13:28:46 -0700522}
523
Colin Cross36242852017-06-23 15:06:31 -0700524func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
525 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700526
527 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800528 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700529 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700530 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700531 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800532
Dan Willemsen218f6562015-07-08 18:13:11 -0700533 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700534 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700535 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800536 }
537
Colin Cross36242852017-06-23 15:06:31 -0700538 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800539}
540
Colin Crossee0bc3b2018-10-02 22:01:37 -0700541func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
542 InitAndroidArchModule(m, hod, defaultMultilib)
543 m.base().commonProperties.UseTargetVariants = false
544}
545
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800546// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800547// modules. It should be included as an anonymous field in every module
548// struct definition. InitAndroidModule should then be called from the module's
549// factory function, and the return values from InitAndroidModule should be
550// returned from the factory function.
551//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800552// The ModuleBase type is responsible for implementing the GenerateBuildActions
553// method to support the blueprint.Module interface. This method will then call
554// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700555// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
556// rather than the usual blueprint.ModuleContext.
557// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800558// system including details about the particular build variant that is to be
559// generated.
560//
561// For example:
562//
563// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800564// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800565// )
566//
567// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800568// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800569// properties struct {
570// MyProperty string
571// }
572// }
573//
Colin Cross36242852017-06-23 15:06:31 -0700574// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800575// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700576// m.AddProperties(&m.properties)
577// android.InitAndroidModule(m)
578// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800579// }
580//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800581// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800582// // Get the CPU architecture for the current build variant.
583// variantArch := ctx.Arch()
584//
585// // ...
586// }
Colin Cross635c3b02016-05-18 15:37:25 -0700587type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800588 // Putting the curiously recurring thing pointing to the thing that contains
589 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700590 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700591 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800592
Colin Crossfc754582016-05-17 16:34:16 -0700593 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800594 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700595 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800596 hostAndDeviceProperties hostAndDeviceProperties
597 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700598 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700599 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800600
Paul Duffin63c6e182019-07-24 14:24:38 +0100601 // Information about all the properties on the module that contains visibility rules that need
602 // checking.
603 visibilityPropertyInfo []visibilityProperty
604
605 // The primary visibility property, may be nil, that controls access to the module.
606 primaryVisibilityProperty visibilityProperty
607
Colin Cross3f40fa42015-01-30 17:27:36 -0800608 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700609 installFiles Paths
610 checkbuildFiles Paths
Jiyong Park52818fc2019-03-18 12:01:38 +0900611 noticeFile OptionalPath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700612
613 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
614 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800615 installTarget WritablePath
616 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700617 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700618
Colin Cross178a5092016-09-13 13:42:32 -0700619 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700620
621 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700622
623 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700624 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800625 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800626 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700627
628 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700629}
630
Colin Cross4157e882019-06-06 16:57:04 -0700631func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800632
Colin Cross4157e882019-06-06 16:57:04 -0700633func (m *ModuleBase) AddProperties(props ...interface{}) {
634 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700635}
636
Colin Cross4157e882019-06-06 16:57:04 -0700637func (m *ModuleBase) GetProperties() []interface{} {
638 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800639}
640
Colin Cross4157e882019-06-06 16:57:04 -0700641func (m *ModuleBase) BuildParamsForTests() []BuildParams {
642 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700643}
644
Colin Cross4157e882019-06-06 16:57:04 -0700645func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
646 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800647}
648
Colin Cross4157e882019-06-06 16:57:04 -0700649func (m *ModuleBase) VariablesForTests() map[string]string {
650 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800651}
652
Colin Cross4157e882019-06-06 16:57:04 -0700653func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
654 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700655}
656
Colin Crossce75d2c2016-10-06 16:12:58 -0700657// Name returns the name of the module. It may be overridden by individual module types, for
658// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700659func (m *ModuleBase) Name() string {
660 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700661}
662
Colin Cross9a362232019-07-01 15:32:45 -0700663// String returns a string that includes the module name and variants for printing during debugging.
664func (m *ModuleBase) String() string {
665 sb := strings.Builder{}
666 sb.WriteString(m.commonProperties.DebugName)
667 sb.WriteString("{")
668 for i := range m.commonProperties.DebugMutators {
669 if i != 0 {
670 sb.WriteString(",")
671 }
672 sb.WriteString(m.commonProperties.DebugMutators[i])
673 sb.WriteString(":")
674 sb.WriteString(m.commonProperties.DebugVariations[i])
675 }
676 sb.WriteString("}")
677 return sb.String()
678}
679
Colin Crossce75d2c2016-10-06 16:12:58 -0700680// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700681func (m *ModuleBase) BaseModuleName() string {
682 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700683}
684
Colin Cross4157e882019-06-06 16:57:04 -0700685func (m *ModuleBase) base() *ModuleBase {
686 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800687}
688
Paul Duffine2453c72019-05-31 14:00:04 +0100689func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
690 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
691}
692
693func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100694 return m.visibilityPropertyInfo
695}
696
697func (m *ModuleBase) visibility() []string {
698 // The soong_namespace module does not initialize the primaryVisibilityProperty.
699 if m.primaryVisibilityProperty != nil {
700 return m.primaryVisibilityProperty.getStrings()
701 } else {
702 return nil
Paul Duffine2453c72019-05-31 14:00:04 +0100703 }
704}
705
Colin Cross4157e882019-06-06 16:57:04 -0700706func (m *ModuleBase) SetTarget(target Target, multiTargets []Target, primary bool) {
707 m.commonProperties.CompileTarget = target
708 m.commonProperties.CompileMultiTargets = multiTargets
709 m.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700710}
711
Colin Cross4157e882019-06-06 16:57:04 -0700712func (m *ModuleBase) Target() Target {
713 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800714}
715
Colin Cross4157e882019-06-06 16:57:04 -0700716func (m *ModuleBase) TargetPrimary() bool {
717 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700718}
719
Colin Cross4157e882019-06-06 16:57:04 -0700720func (m *ModuleBase) MultiTargets() []Target {
721 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700722}
723
Colin Cross4157e882019-06-06 16:57:04 -0700724func (m *ModuleBase) Os() OsType {
725 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800726}
727
Colin Cross4157e882019-06-06 16:57:04 -0700728func (m *ModuleBase) Host() bool {
729 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800730}
731
Colin Cross4157e882019-06-06 16:57:04 -0700732func (m *ModuleBase) Arch() Arch {
733 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800734}
735
Colin Cross4157e882019-06-06 16:57:04 -0700736func (m *ModuleBase) ArchSpecific() bool {
737 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700738}
739
Colin Cross4157e882019-06-06 16:57:04 -0700740func (m *ModuleBase) OsClassSupported() []OsClass {
741 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700742 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700743 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700744 case HostSupportedNoCross:
745 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700746 case DeviceSupported:
747 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700748 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700749 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700750 if Bool(m.hostAndDeviceProperties.Host_supported) ||
751 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
752 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700753 supported = append(supported, Host, HostCross)
754 }
Colin Cross4157e882019-06-06 16:57:04 -0700755 if m.hostAndDeviceProperties.Device_supported == nil ||
756 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700757 supported = append(supported, Device)
758 }
759 return supported
760 default:
761 return nil
762 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800763}
764
Colin Cross4157e882019-06-06 16:57:04 -0700765func (m *ModuleBase) DeviceSupported() bool {
766 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
767 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
768 (m.hostAndDeviceProperties.Device_supported == nil ||
769 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800770}
771
Colin Cross4157e882019-06-06 16:57:04 -0700772func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900773 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900774}
775
Colin Cross4157e882019-06-06 16:57:04 -0700776func (m *ModuleBase) DeviceSpecific() bool {
777 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900778}
779
Colin Cross4157e882019-06-06 16:57:04 -0700780func (m *ModuleBase) SocSpecific() bool {
781 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900782}
783
Colin Cross4157e882019-06-06 16:57:04 -0700784func (m *ModuleBase) ProductSpecific() bool {
785 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900786}
787
Justin Yund5f6c822019-06-25 16:47:17 +0900788func (m *ModuleBase) SystemExtSpecific() bool {
789 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100790}
791
Colin Cross4157e882019-06-06 16:57:04 -0700792func (m *ModuleBase) Enabled() bool {
793 if m.commonProperties.Enabled == nil {
794 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800795 }
Colin Cross4157e882019-06-06 16:57:04 -0700796 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800797}
798
Colin Cross4157e882019-06-06 16:57:04 -0700799func (m *ModuleBase) SkipInstall() {
800 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -0700801}
802
Colin Cross4157e882019-06-06 16:57:04 -0700803func (m *ModuleBase) ExportedToMake() bool {
804 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +0900805}
806
Colin Cross4157e882019-06-06 16:57:04 -0700807func (m *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700808 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800809
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700810 result := Paths{}
Colin Cross6b753602018-06-21 13:03:07 -0700811 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross3f40fa42015-01-30 17:27:36 -0800812 ctx.VisitDepsDepthFirstIf(isFileInstaller,
813 func(m blueprint.Module) {
814 fileInstaller := m.(fileInstaller)
815 files := fileInstaller.filesToInstall()
816 result = append(result, files...)
817 })
818
819 return result
820}
821
Colin Cross4157e882019-06-06 16:57:04 -0700822func (m *ModuleBase) filesToInstall() Paths {
823 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -0800824}
825
Colin Cross4157e882019-06-06 16:57:04 -0700826func (m *ModuleBase) NoAddressSanitizer() bool {
827 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -0800828}
829
Colin Cross4157e882019-06-06 16:57:04 -0700830func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800831 return false
832}
833
Colin Cross4157e882019-06-06 16:57:04 -0700834func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700835 return false
836}
837
Colin Cross4157e882019-06-06 16:57:04 -0700838func (m *ModuleBase) InstallInRecovery() bool {
839 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +0900840}
841
Colin Cross607d8582019-07-29 16:44:46 -0700842func (m *ModuleBase) InstallBypassMake() bool {
843 return false
844}
845
Colin Cross4157e882019-06-06 16:57:04 -0700846func (m *ModuleBase) Owner() string {
847 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900848}
849
Colin Cross4157e882019-06-06 16:57:04 -0700850func (m *ModuleBase) NoticeFile() OptionalPath {
851 return m.noticeFile
Jiyong Park52818fc2019-03-18 12:01:38 +0900852}
853
Colin Cross4157e882019-06-06 16:57:04 -0700854func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700855 allInstalledFiles := Paths{}
856 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800857 ctx.VisitAllModuleVariants(func(module Module) {
858 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700859 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
860 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800861 })
862
Colin Cross0875c522017-11-28 17:34:01 -0800863 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700864
Jeff Gaston088e29e2017-11-29 16:47:17 -0800865 namespacePrefix := ctx.Namespace().(*Namespace).id
866 if namespacePrefix != "" {
867 namespacePrefix = namespacePrefix + "-"
868 }
869
Colin Cross3f40fa42015-01-30 17:27:36 -0800870 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800871 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800872 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700873 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800874 Output: name,
875 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800876 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700877 })
878 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700879 m.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700880 }
881
882 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800883 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800884 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700885 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800886 Output: name,
887 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700888 })
889 deps = append(deps, name)
Colin Cross4157e882019-06-06 16:57:04 -0700890 m.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700891 }
892
893 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800894 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800895 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800896 suffix = "-soong"
897 }
898
Jeff Gaston088e29e2017-11-29 16:47:17 -0800899 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800900 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700901 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800902 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700903 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800904 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700905
Colin Cross4157e882019-06-06 16:57:04 -0700906 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800907 }
908}
909
Colin Cross4157e882019-06-06 16:57:04 -0700910func determineModuleKind(m *ModuleBase, ctx blueprint.BaseModuleContext) moduleKind {
911 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
912 var deviceSpecific = Bool(m.commonProperties.Device_specific)
913 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +0900914 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +0900915
Dario Frenifd05a742018-05-29 13:28:54 +0100916 msg := "conflicting value set here"
917 if socSpecific && deviceSpecific {
918 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -0700919 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +0900920 ctx.PropertyErrorf("vendor", msg)
921 }
Colin Cross4157e882019-06-06 16:57:04 -0700922 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +0900923 ctx.PropertyErrorf("proprietary", msg)
924 }
Colin Cross4157e882019-06-06 16:57:04 -0700925 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +0900926 ctx.PropertyErrorf("soc_specific", msg)
927 }
928 }
929
Justin Yund5f6c822019-06-25 16:47:17 +0900930 if productSpecific && systemExtSpecific {
931 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
932 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +0100933 }
934
Justin Yund5f6c822019-06-25 16:47:17 +0900935 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100936 if productSpecific {
937 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
938 } else {
Justin Yund5f6c822019-06-25 16:47:17 +0900939 ctx.PropertyErrorf("system_ext_specific", "a module cannot be specific to SoC or device and system_ext at the same time.")
Dario Frenifd05a742018-05-29 13:28:54 +0100940 }
941 if deviceSpecific {
942 ctx.PropertyErrorf("device_specific", msg)
943 } else {
Colin Cross4157e882019-06-06 16:57:04 -0700944 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +0100945 ctx.PropertyErrorf("vendor", msg)
946 }
Colin Cross4157e882019-06-06 16:57:04 -0700947 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +0100948 ctx.PropertyErrorf("proprietary", msg)
949 }
Colin Cross4157e882019-06-06 16:57:04 -0700950 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +0100951 ctx.PropertyErrorf("soc_specific", msg)
952 }
953 }
954 }
955
Jiyong Park2db76922017-11-08 16:03:48 +0900956 if productSpecific {
957 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900958 } else if systemExtSpecific {
959 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900960 } else if deviceSpecific {
961 return deviceSpecificModule
962 } else if socSpecific {
963 return socSpecificModule
964 } else {
965 return platformModule
966 }
967}
968
Colin Cross0ea8ba82019-06-06 14:33:29 -0700969func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
970 return baseModuleContext{
971 BaseModuleContext: ctx,
972 target: m.commonProperties.CompileTarget,
973 targetPrimary: m.commonProperties.CompilePrimary,
974 multiTargets: m.commonProperties.CompileMultiTargets,
975 kind: determineModuleKind(m, ctx),
976 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800977 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800978}
979
Colin Cross4157e882019-06-06 16:57:04 -0700980func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -0700981 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -0700982 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -0700983 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700984 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
985 installDeps: m.computeInstallDeps(blueprintCtx),
986 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -0700987 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -0800988 }
989
Colin Cross6c4f21f2019-06-06 15:41:36 -0700990 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
991 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
992 // TODO: This will be removed once defaults modules handle missing dependency errors
993 blueprintCtx.GetMissingDependencies()
994
Colin Crossdc35e212019-06-06 16:13:11 -0700995 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
996 // are enabled.
997 ctx.baseModuleContext.strictVisitDeps = true
998
Colin Cross4c83e5c2019-02-25 14:54:28 -0800999 if ctx.config.captureBuild {
1000 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1001 }
1002
Colin Cross67a5c132017-05-09 13:45:28 -07001003 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1004 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001005 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1006 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001007 }
Colin Cross0875c522017-11-28 17:34:01 -08001008 if !ctx.PrimaryArch() {
1009 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001010 }
1011
1012 ctx.Variable(pctx, "moduleDesc", desc)
1013
1014 s := ""
1015 if len(suffix) > 0 {
1016 s = " [" + strings.Join(suffix, " ") + "]"
1017 }
1018 ctx.Variable(pctx, "moduleDescSuffix", s)
1019
Dan Willemsen569edc52018-11-19 09:33:29 -08001020 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001021 if m.commonProperties.Dist.Dest != nil {
1022 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001023 if err != nil {
1024 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1025 }
1026 }
Colin Cross4157e882019-06-06 16:57:04 -07001027 if m.commonProperties.Dist.Dir != nil {
1028 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001029 if err != nil {
1030 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1031 }
1032 }
Colin Cross4157e882019-06-06 16:57:04 -07001033 if m.commonProperties.Dist.Suffix != nil {
1034 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001035 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1036 }
1037 }
1038
Colin Cross4157e882019-06-06 16:57:04 -07001039 if m.Enabled() {
Colin Cross4157e882019-06-06 16:57:04 -07001040 notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
1041 if module := SrcIsModule(notice); module != "" {
1042 m.noticeFile = ctx.ExpandOptionalSource(&notice, "notice")
Jiyong Park52818fc2019-03-18 12:01:38 +09001043 } else {
1044 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Colin Cross4157e882019-06-06 16:57:04 -07001045 m.noticeFile = ExistentPathForSource(ctx, noticePath)
Jaewoong Jung62707f72018-11-16 13:26:43 -08001046 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001047
1048 m.module.GenerateAndroidBuildActions(ctx)
1049 if ctx.Failed() {
1050 return
1051 }
1052
1053 m.installFiles = append(m.installFiles, ctx.installFiles...)
1054 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Colin Crossdc35e212019-06-06 16:13:11 -07001055 } else if ctx.Config().AllowMissingDependencies() {
1056 // If the module is not enabled it will not create any build rules, nothing will call
1057 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1058 // and report them as an error even when AllowMissingDependencies = true. Call
1059 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1060 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001061 }
1062
Colin Cross4157e882019-06-06 16:57:04 -07001063 if m == ctx.FinalModule().(Module).base() {
1064 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001065 if ctx.Failed() {
1066 return
1067 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001068 }
Colin Crosscec81712017-07-13 14:43:27 -07001069
Colin Cross4157e882019-06-06 16:57:04 -07001070 m.buildParams = ctx.buildParams
1071 m.ruleParams = ctx.ruleParams
1072 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001073}
1074
Colin Cross0ea8ba82019-06-06 14:33:29 -07001075type baseModuleContext struct {
1076 blueprint.BaseModuleContext
Colin Cross8b74d172016-09-13 09:59:14 -07001077 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001078 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001079 targetPrimary bool
1080 debug bool
Jiyong Park2db76922017-11-08 16:03:48 +09001081 kind moduleKind
Colin Cross8b74d172016-09-13 09:59:14 -07001082 config Config
Colin Crossdc35e212019-06-06 16:13:11 -07001083
1084 walkPath []Module
1085
1086 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001087}
1088
Colin Cross25de6c32019-06-06 14:29:25 -07001089type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001090 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001091 baseModuleContext
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001092 installDeps Paths
1093 installFiles Paths
1094 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001095 module Module
Colin Crosscec81712017-07-13 14:43:27 -07001096
1097 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001098 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001099 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001100 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001101}
1102
Colin Crossb88b3c52019-06-10 15:15:17 -07001103func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1104 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001105 Rule: ErrorRule,
1106 Description: params.Description,
1107 Output: params.Output,
1108 Outputs: params.Outputs,
1109 ImplicitOutput: params.ImplicitOutput,
1110 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001111 Args: map[string]string{
1112 "error": err.Error(),
1113 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001114 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001115}
1116
Colin Cross25de6c32019-06-06 14:29:25 -07001117func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1118 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001119}
1120
Colin Cross0875c522017-11-28 17:34:01 -08001121func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001122 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001123 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001124 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001125 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001126 Outputs: params.Outputs.Strings(),
1127 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1128 Inputs: params.Inputs.Strings(),
1129 Implicits: params.Implicits.Strings(),
1130 OrderOnly: params.OrderOnly.Strings(),
1131 Args: params.Args,
1132 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001133 }
1134
Colin Cross33bfb0a2016-11-21 17:23:08 -08001135 if params.Depfile != nil {
1136 bparams.Depfile = params.Depfile.String()
1137 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001138 if params.Output != nil {
1139 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1140 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001141 if params.ImplicitOutput != nil {
1142 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1143 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001144 if params.Input != nil {
1145 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1146 }
1147 if params.Implicit != nil {
1148 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1149 }
1150
Colin Cross0b9f31f2019-02-28 11:00:01 -08001151 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1152 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1153 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1154 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1155 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1156 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001157
Colin Cross0875c522017-11-28 17:34:01 -08001158 return bparams
1159}
1160
Colin Cross25de6c32019-06-06 14:29:25 -07001161func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1162 if m.config.captureBuild {
1163 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001164 }
1165
Colin Crossdc35e212019-06-06 16:13:11 -07001166 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001167}
1168
Colin Cross25de6c32019-06-06 14:29:25 -07001169func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001170 argNames ...string) blueprint.Rule {
1171
Colin Crossdc35e212019-06-06 16:13:11 -07001172 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001173
Colin Cross25de6c32019-06-06 14:29:25 -07001174 if m.config.captureBuild {
1175 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001176 }
1177
1178 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001179}
1180
Colin Cross25de6c32019-06-06 14:29:25 -07001181func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001182 if params.Description != "" {
1183 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1184 }
1185
1186 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1187 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1188 m.ModuleName(), strings.Join(missingDeps, ", ")))
1189 }
1190
Colin Cross25de6c32019-06-06 14:29:25 -07001191 if m.config.captureBuild {
1192 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001193 }
1194
Colin Crossdc35e212019-06-06 16:13:11 -07001195 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001196}
1197
Colin Crossdc35e212019-06-06 16:13:11 -07001198func (b *baseModuleContext) Module() Module {
1199 module, _ := b.BaseModuleContext.Module().(Module)
1200 return module
1201}
1202
1203func (b *baseModuleContext) Config() Config {
1204 return b.BaseModuleContext.Config().(Config)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001205}
1206
Colin Cross25de6c32019-06-06 14:29:25 -07001207func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001208 var missingDeps []string
1209 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001210 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001211 missingDeps = FirstUniqueStrings(missingDeps)
1212 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001213}
1214
Colin Crossdc35e212019-06-06 16:13:11 -07001215func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001216 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001217 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001218 *missingDeps = append(*missingDeps, deps...)
1219 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001220 }
1221}
1222
Colin Crossdc35e212019-06-06 16:13:11 -07001223func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001224 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001225
1226 if !strict {
1227 return aModule
1228 }
1229
Colin Cross380c69a2019-06-10 17:49:58 +00001230 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001231 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001232 return nil
1233 }
1234
1235 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001236 if b.Config().AllowMissingDependencies() {
1237 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001238 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001239 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001240 }
1241 return nil
1242 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001243 return aModule
1244}
1245
Colin Crossdc35e212019-06-06 16:13:11 -07001246func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001247 type dep struct {
1248 mod blueprint.Module
1249 tag blueprint.DependencyTag
1250 }
1251 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001252 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001253 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Crossdc35e212019-06-06 16:13:11 -07001254 returnedTag := b.BaseModuleContext.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001255 if tag == nil || returnedTag == tag {
1256 deps = append(deps, dep{aModule, returnedTag})
1257 }
1258 }
1259 })
1260 if len(deps) == 1 {
1261 return deps[0].mod, deps[0].tag
1262 } else if len(deps) >= 2 {
1263 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001264 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001265 } else {
1266 return nil, nil
1267 }
1268}
1269
Colin Crossdc35e212019-06-06 16:13:11 -07001270func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001271 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001272 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001273 if aModule, _ := module.(Module); aModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001274 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001275 deps = append(deps, aModule)
1276 }
1277 }
1278 })
1279 return deps
1280}
1281
Colin Cross25de6c32019-06-06 14:29:25 -07001282func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1283 module, _ := m.getDirectDepInternal(name, tag)
1284 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001285}
1286
Colin Crossdc35e212019-06-06 16:13:11 -07001287func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1288 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001289}
1290
Colin Crossdc35e212019-06-06 16:13:11 -07001291func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
1292 b.BaseModuleContext.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001293}
1294
Colin Crossdc35e212019-06-06 16:13:11 -07001295func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
1296 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1297 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001298 visit(aModule)
1299 }
1300 })
1301}
1302
Colin Crossdc35e212019-06-06 16:13:11 -07001303func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
1304 b.BaseModuleContext.VisitDirectDeps(func(module blueprint.Module) {
1305 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
1306 if b.BaseModuleContext.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001307 visit(aModule)
1308 }
1309 }
1310 })
1311}
1312
Colin Crossdc35e212019-06-06 16:13:11 -07001313func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
1314 b.BaseModuleContext.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001315 // pred
1316 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001317 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001318 return pred(aModule)
1319 } else {
1320 return false
1321 }
1322 },
1323 // visit
1324 func(module blueprint.Module) {
1325 visit(module.(Module))
1326 })
1327}
1328
Colin Crossdc35e212019-06-06 16:13:11 -07001329func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
1330 b.BaseModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
1331 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001332 visit(aModule)
1333 }
1334 })
1335}
1336
Colin Crossdc35e212019-06-06 16:13:11 -07001337func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
1338 b.BaseModuleContext.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001339 // pred
1340 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001341 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001342 return pred(aModule)
1343 } else {
1344 return false
1345 }
1346 },
1347 // visit
1348 func(module blueprint.Module) {
1349 visit(module.(Module))
1350 })
1351}
1352
Colin Crossdc35e212019-06-06 16:13:11 -07001353func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
1354 b.BaseModuleContext.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001355}
1356
Colin Crossdc35e212019-06-06 16:13:11 -07001357func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1358 b.walkPath = []Module{b.Module()}
1359 b.BaseModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
1360 childAndroidModule, _ := child.(Module)
1361 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001362 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001363 // record walkPath before visit
1364 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1365 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
1366 }
1367 b.walkPath = append(b.walkPath, childAndroidModule)
Colin Crossd11fcda2017-10-23 17:59:01 -07001368 return visit(childAndroidModule, parentAndroidModule)
1369 } else {
1370 return false
1371 }
1372 })
1373}
1374
Colin Crossdc35e212019-06-06 16:13:11 -07001375func (b *baseModuleContext) GetWalkPath() []Module {
1376 return b.walkPath
1377}
1378
Colin Cross25de6c32019-06-06 14:29:25 -07001379func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001380 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001381 visit(module.(Module))
1382 })
1383}
1384
Colin Cross25de6c32019-06-06 14:29:25 -07001385func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001386 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001387}
1388
Colin Cross25de6c32019-06-06 14:29:25 -07001389func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001390 return m.bp.FinalModule().(Module)
1391}
1392
1393func (m *moduleContext) ModuleSubDir() string {
1394 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001395}
1396
Colin Cross0ea8ba82019-06-06 14:33:29 -07001397func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001398 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001399}
1400
Colin Cross0ea8ba82019-06-06 14:33:29 -07001401func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001402 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001403}
1404
Colin Cross0ea8ba82019-06-06 14:33:29 -07001405func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001406 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001407}
1408
Colin Cross0ea8ba82019-06-06 14:33:29 -07001409func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001410 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001411}
1412
Colin Cross0ea8ba82019-06-06 14:33:29 -07001413func (b *baseModuleContext) Os() OsType {
Colin Cross25de6c32019-06-06 14:29:25 -07001414 return b.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001415}
1416
Colin Cross0ea8ba82019-06-06 14:33:29 -07001417func (b *baseModuleContext) Host() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001418 return b.target.Os.Class == Host || b.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001419}
1420
Colin Cross0ea8ba82019-06-06 14:33:29 -07001421func (b *baseModuleContext) Device() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001422 return b.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001423}
1424
Colin Cross0ea8ba82019-06-06 14:33:29 -07001425func (b *baseModuleContext) Darwin() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001426 return b.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001427}
1428
Colin Cross0ea8ba82019-06-06 14:33:29 -07001429func (b *baseModuleContext) Fuchsia() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001430 return b.target.Os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001431}
1432
Colin Cross0ea8ba82019-06-06 14:33:29 -07001433func (b *baseModuleContext) Windows() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001434 return b.target.Os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001435}
1436
Colin Cross0ea8ba82019-06-06 14:33:29 -07001437func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001438 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001439}
1440
Colin Cross0ea8ba82019-06-06 14:33:29 -07001441func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001442 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001443 return true
1444 }
Colin Cross25de6c32019-06-06 14:29:25 -07001445 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001446}
1447
Colin Cross0ea8ba82019-06-06 14:33:29 -07001448func (b *baseModuleContext) AConfig() Config {
Colin Cross25de6c32019-06-06 14:29:25 -07001449 return b.config
Colin Cross1332b002015-04-07 17:11:30 -07001450}
1451
Colin Cross0ea8ba82019-06-06 14:33:29 -07001452func (b *baseModuleContext) DeviceConfig() DeviceConfig {
Colin Cross25de6c32019-06-06 14:29:25 -07001453 return DeviceConfig{b.config.deviceConfig}
Colin Cross9272ade2016-08-17 15:24:12 -07001454}
1455
Colin Cross0ea8ba82019-06-06 14:33:29 -07001456func (b *baseModuleContext) Platform() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001457 return b.kind == platformModule
Jiyong Park2db76922017-11-08 16:03:48 +09001458}
1459
Colin Cross0ea8ba82019-06-06 14:33:29 -07001460func (b *baseModuleContext) DeviceSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001461 return b.kind == deviceSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001462}
1463
Colin Cross0ea8ba82019-06-06 14:33:29 -07001464func (b *baseModuleContext) SocSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001465 return b.kind == socSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001466}
1467
Colin Cross0ea8ba82019-06-06 14:33:29 -07001468func (b *baseModuleContext) ProductSpecific() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001469 return b.kind == productSpecificModule
Dan Willemsen782a2d12015-12-21 14:55:28 -08001470}
1471
Justin Yund5f6c822019-06-25 16:47:17 +09001472func (b *baseModuleContext) SystemExtSpecific() bool {
1473 return b.kind == systemExtSpecificModule
Dario Frenifd05a742018-05-29 13:28:54 +01001474}
1475
Jiyong Park5baac542018-08-28 09:55:37 +09001476// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001477// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001478func (m *ModuleBase) MakeAsPlatform() {
1479 m.commonProperties.Vendor = boolPtr(false)
1480 m.commonProperties.Proprietary = boolPtr(false)
1481 m.commonProperties.Soc_specific = boolPtr(false)
1482 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001483 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001484}
1485
Colin Cross4157e882019-06-06 16:57:04 -07001486func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1487 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001488}
1489
Colin Cross25de6c32019-06-06 14:29:25 -07001490func (m *moduleContext) InstallInData() bool {
1491 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001492}
1493
Colin Cross25de6c32019-06-06 14:29:25 -07001494func (m *moduleContext) InstallInSanitizerDir() bool {
1495 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001496}
1497
Colin Cross25de6c32019-06-06 14:29:25 -07001498func (m *moduleContext) InstallInRecovery() bool {
1499 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001500}
1501
Colin Cross607d8582019-07-29 16:44:46 -07001502func (m *moduleContext) InstallBypassMake() bool {
1503 return m.module.InstallBypassMake()
1504}
1505
Colin Cross25de6c32019-06-06 14:29:25 -07001506func (m *moduleContext) skipInstall(fullInstallPath OutputPath) bool {
1507 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001508 return true
1509 }
1510
Colin Cross3607f212018-05-07 15:28:05 -07001511 // We'll need a solution for choosing which of modules with the same name in different
1512 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1513 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001514 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001515 return true
1516 }
1517
Colin Cross25de6c32019-06-06 14:29:25 -07001518 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07001519 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07001520 return true
1521 }
1522
Colin Cross25de6c32019-06-06 14:29:25 -07001523 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07001524 return true
1525 }
1526 }
1527
1528 return false
1529}
1530
Colin Cross25de6c32019-06-06 14:29:25 -07001531func (m *moduleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -07001532 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001533 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001534}
1535
Colin Cross25de6c32019-06-06 14:29:25 -07001536func (m *moduleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001537 deps ...Path) OutputPath {
Colin Cross25de6c32019-06-06 14:29:25 -07001538 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07001539}
1540
Colin Cross25de6c32019-06-06 14:29:25 -07001541func (m *moduleContext) installFile(installPath OutputPath, name string, srcPath Path,
Colin Cross5c517922017-08-31 12:29:17 -07001542 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -07001543
Colin Cross25de6c32019-06-06 14:29:25 -07001544 fullInstallPath := installPath.Join(m, name)
1545 m.module.base().hooks.runInstallHooks(m, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08001546
Colin Cross25de6c32019-06-06 14:29:25 -07001547 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001548
Colin Cross25de6c32019-06-06 14:29:25 -07001549 deps = append(deps, m.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -07001550
Colin Cross89562dc2016-10-03 17:47:19 -07001551 var implicitDeps, orderOnlyDeps Paths
1552
Colin Cross25de6c32019-06-06 14:29:25 -07001553 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07001554 // Installed host modules might be used during the build, depend directly on their
1555 // dependencies so their timestamp is updated whenever their dependency is updated
1556 implicitDeps = deps
1557 } else {
1558 orderOnlyDeps = deps
1559 }
1560
Colin Cross25de6c32019-06-06 14:29:25 -07001561 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07001562 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07001563 Description: "install " + fullInstallPath.Base(),
1564 Output: fullInstallPath,
1565 Input: srcPath,
1566 Implicits: implicitDeps,
1567 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07001568 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08001569 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001570
Colin Cross25de6c32019-06-06 14:29:25 -07001571 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001572 }
Colin Cross25de6c32019-06-06 14:29:25 -07001573 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07001574 return fullInstallPath
1575}
1576
Colin Cross25de6c32019-06-06 14:29:25 -07001577func (m *moduleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
1578 fullInstallPath := installPath.Join(m, name)
1579 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08001580
Colin Cross25de6c32019-06-06 14:29:25 -07001581 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001582
Alex Lightfb4353d2019-01-17 13:57:45 -08001583 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
1584 if err != nil {
1585 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
1586 }
Colin Cross25de6c32019-06-06 14:29:25 -07001587 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07001588 Rule: Symlink,
1589 Description: "install symlink " + fullInstallPath.Base(),
1590 Output: fullInstallPath,
1591 OrderOnly: Paths{srcPath},
Colin Cross25de6c32019-06-06 14:29:25 -07001592 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08001593 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08001594 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08001595 },
1596 })
Colin Cross3854a602016-01-11 12:49:11 -08001597
Colin Cross25de6c32019-06-06 14:29:25 -07001598 m.installFiles = append(m.installFiles, fullInstallPath)
1599 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08001600 }
Colin Cross3854a602016-01-11 12:49:11 -08001601 return fullInstallPath
1602}
1603
Jiyong Parkf1194352019-02-25 11:05:47 +09001604// installPath/name -> absPath where absPath might be a path that is available only at runtime
1605// (e.g. /apex/...)
Colin Cross25de6c32019-06-06 14:29:25 -07001606func (m *moduleContext) InstallAbsoluteSymlink(installPath OutputPath, name string, absPath string) OutputPath {
1607 fullInstallPath := installPath.Join(m, name)
1608 m.module.base().hooks.runInstallHooks(m, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09001609
Colin Cross25de6c32019-06-06 14:29:25 -07001610 if !m.skipInstall(fullInstallPath) {
1611 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09001612 Rule: Symlink,
1613 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
1614 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07001615 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09001616 Args: map[string]string{
1617 "fromPath": absPath,
1618 },
1619 })
1620
Colin Cross25de6c32019-06-06 14:29:25 -07001621 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09001622 }
1623 return fullInstallPath
1624}
1625
Colin Cross25de6c32019-06-06 14:29:25 -07001626func (m *moduleContext) CheckbuildFile(srcPath Path) {
1627 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08001628}
1629
Colin Cross3f40fa42015-01-30 17:27:36 -08001630type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001631 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -08001632}
1633
1634func isFileInstaller(m blueprint.Module) bool {
1635 _, ok := m.(fileInstaller)
1636 return ok
1637}
1638
1639func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -07001640 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -08001641 return ok
1642}
Colin Crossfce53272015-04-08 11:21:40 -07001643
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001644func findStringInSlice(str string, slice []string) int {
1645 for i, s := range slice {
1646 if s == str {
1647 return i
Colin Crossfce53272015-04-08 11:21:40 -07001648 }
1649 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001650 return -1
1651}
1652
Colin Cross41955e82019-05-29 14:40:35 -07001653// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
1654// was not a module reference.
1655func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08001656 if len(s) > 1 && s[0] == ':' {
1657 return s[1:]
1658 }
1659 return ""
1660}
1661
Colin Cross41955e82019-05-29 14:40:35 -07001662// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
1663// module name and an empty string for the tag, or empty strings if the input was not a module reference.
1664func SrcIsModuleWithTag(s string) (module, tag string) {
1665 if len(s) > 1 && s[0] == ':' {
1666 module = s[1:]
1667 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
1668 if module[len(module)-1] == '}' {
1669 tag = module[tagStart+1 : len(module)-1]
1670 module = module[:tagStart]
1671 return module, tag
1672 }
1673 }
1674 return module, ""
1675 }
1676 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08001677}
1678
Colin Cross41955e82019-05-29 14:40:35 -07001679type sourceOrOutputDependencyTag struct {
1680 blueprint.BaseDependencyTag
1681 tag string
1682}
1683
1684func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
1685 return sourceOrOutputDependencyTag{tag: tag}
1686}
1687
1688var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08001689
Colin Cross366938f2017-12-11 16:29:02 -08001690// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1691// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001692//
1693// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08001694func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07001695 set := make(map[string]bool)
1696
Colin Cross068e0fe2016-12-13 15:23:47 -08001697 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07001698 if m, t := SrcIsModuleWithTag(s); m != "" {
1699 if _, found := set[s]; found {
1700 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07001701 } else {
Colin Cross41955e82019-05-29 14:40:35 -07001702 set[s] = true
1703 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07001704 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001705 }
1706 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001707}
1708
Colin Cross366938f2017-12-11 16:29:02 -08001709// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1710// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08001711//
1712// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08001713func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1714 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07001715 if m, t := SrcIsModuleWithTag(*s); m != "" {
1716 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08001717 }
1718 }
1719}
1720
Colin Cross41955e82019-05-29 14:40:35 -07001721// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
1722// using the ":module" syntax and provides a list of paths to be used as if they were listed in the property.
Colin Cross068e0fe2016-12-13 15:23:47 -08001723type SourceFileProducer interface {
1724 Srcs() Paths
1725}
1726
Colin Cross41955e82019-05-29 14:40:35 -07001727// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
1728// using the ":module" syntax or ":module{.tag}" syntax and provides a list of otuput files to be used as if they were
1729// listed in the property.
1730type OutputFileProducer interface {
1731 OutputFiles(tag string) (Paths, error)
1732}
1733
Colin Crossfe17f6f2019-03-28 19:30:56 -07001734type HostToolProvider interface {
1735 HostToolPath() OptionalPath
1736}
1737
Colin Cross27b922f2019-03-04 22:35:41 -08001738// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
1739// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001740//
1741// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001742func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
1743 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001744}
1745
Colin Cross2fafa3e2019-03-05 12:39:51 -08001746// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
1747// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08001748//
1749// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07001750func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
1751 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08001752}
1753
1754// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
1755// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
1756// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07001757func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08001758 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07001759 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08001760 }
1761 return OptionalPath{}
1762}
1763
Colin Cross25de6c32019-06-06 14:29:25 -07001764func (m *moduleContext) RequiredModuleNames() []string {
1765 return m.module.base().commonProperties.Required
Nan Zhang6d34b302017-02-04 17:47:46 -08001766}
1767
Colin Cross25de6c32019-06-06 14:29:25 -07001768func (m *moduleContext) HostRequiredModuleNames() []string {
1769 return m.module.base().commonProperties.Host_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001770}
1771
Colin Cross25de6c32019-06-06 14:29:25 -07001772func (m *moduleContext) TargetRequiredModuleNames() []string {
1773 return m.module.base().commonProperties.Target_required
Sasha Smundakb6d23052019-04-01 18:37:36 -07001774}
1775
Colin Crossdc35e212019-06-06 16:13:11 -07001776func (b *baseModuleContext) Glob(globPattern string, excludes []string) Paths {
1777 ret, err := b.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001778 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001779 b.ModuleErrorf("glob: %s", err.Error())
Colin Cross8f101b42015-06-17 15:09:06 -07001780 }
Colin Crossdc35e212019-06-06 16:13:11 -07001781 return pathsForModuleSrcFromFullPath(b, ret, true)
Colin Crossfce53272015-04-08 11:21:40 -07001782}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001783
Colin Crossdc35e212019-06-06 16:13:11 -07001784func (b *baseModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1785 ret, err := b.GlobWithDeps(globPattern, excludes)
Nan Zhang581fd212018-01-10 16:06:12 -08001786 if err != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001787 b.ModuleErrorf("glob: %s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -08001788 }
Colin Crossdc35e212019-06-06 16:13:11 -07001789 return pathsForModuleSrcFromFullPath(b, ret, false)
Nan Zhang581fd212018-01-10 16:06:12 -08001790}
1791
Colin Cross463a90e2015-06-17 14:20:06 -07001792func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001793 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001794}
1795
Colin Cross0875c522017-11-28 17:34:01 -08001796func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001797 return &buildTargetSingleton{}
1798}
1799
Colin Cross87d8b562017-04-25 10:01:55 -07001800func parentDir(dir string) string {
1801 dir, _ = filepath.Split(dir)
1802 return filepath.Clean(dir)
1803}
1804
Colin Cross1f8c52b2015-06-16 16:38:17 -07001805type buildTargetSingleton struct{}
1806
Colin Cross0875c522017-11-28 17:34:01 -08001807func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1808 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001809
Colin Cross0875c522017-11-28 17:34:01 -08001810 mmTarget := func(dir string) WritablePath {
1811 return PathForPhony(ctx,
1812 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001813 }
1814
Colin Cross0875c522017-11-28 17:34:01 -08001815 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001816
Colin Cross0875c522017-11-28 17:34:01 -08001817 ctx.VisitAllModules(func(module Module) {
1818 blueprintDir := module.base().blueprintDir
1819 installTarget := module.base().installTarget
1820 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001821
Colin Cross0875c522017-11-28 17:34:01 -08001822 if checkbuildTarget != nil {
1823 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1824 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1825 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001826
Colin Cross0875c522017-11-28 17:34:01 -08001827 if installTarget != nil {
1828 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001829 }
1830 })
1831
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001832 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001833 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001834 suffix = "-soong"
1835 }
1836
Colin Cross1f8c52b2015-06-16 16:38:17 -07001837 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001838 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001839 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001840 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001841 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001842 })
1843
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001844 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001845 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001846 return
1847 }
1848
Colin Cross87d8b562017-04-25 10:01:55 -07001849 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09001850 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07001851 for _, dir := range dirs {
1852 dir := parentDir(dir)
1853 for dir != "." && dir != "/" {
1854 if _, exists := modulesInDir[dir]; exists {
1855 break
1856 }
1857 modulesInDir[dir] = nil
1858 dir = parentDir(dir)
1859 }
1860 }
1861
1862 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07001863 for _, dir := range dirs {
1864 p := parentDir(dir)
1865 if p != "." && p != "/" {
1866 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1867 }
1868 }
1869
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001870 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1871 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1872 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001873 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001874 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001875 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001876 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001877 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001878 // HACK: checkbuild should be an optional build, but force it
1879 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001880 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001881 })
1882 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001883
1884 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1885 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001886 ctx.VisitAllModules(func(module Module) {
1887 if module.Enabled() {
1888 os := module.Target().Os
1889 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001890 }
1891 })
1892
Colin Cross0875c522017-11-28 17:34:01 -08001893 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001894 for os, deps := range osDeps {
1895 var className string
1896
1897 switch os.Class {
1898 case Host:
1899 className = "host"
1900 case HostCross:
1901 className = "host-cross"
1902 case Device:
1903 className = "target"
1904 default:
1905 continue
1906 }
1907
Colin Cross0875c522017-11-28 17:34:01 -08001908 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001909 osClass[className] = append(osClass[className], name)
1910
Colin Cross0875c522017-11-28 17:34:01 -08001911 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001912 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001913 Output: name,
1914 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001915 })
1916 }
1917
1918 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09001919 for _, class := range SortedStringKeys(osClass) {
Colin Cross0875c522017-11-28 17:34:01 -08001920 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001921 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001922 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001923 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001924 })
1925 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001926}
Colin Crossd779da42015-12-17 18:00:23 -08001927
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001928// Collect information for opening IDE project files in java/jdeps.go.
1929type IDEInfo interface {
1930 IDEInfo(ideInfo *IdeInfo)
1931 BaseModuleName() string
1932}
1933
1934// Extract the base module name from the Import name.
1935// Often the Import name has a prefix "prebuilt_".
1936// Remove the prefix explicitly if needed
1937// until we find a better solution to get the Import name.
1938type IDECustomizedModuleName interface {
1939 IDECustomizedModuleName() string
1940}
1941
1942type IdeInfo struct {
1943 Deps []string `json:"dependencies,omitempty"`
1944 Srcs []string `json:"srcs,omitempty"`
1945 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
1946 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
1947 Jars []string `json:"jars,omitempty"`
1948 Classes []string `json:"class,omitempty"`
1949 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08001950 SrcJars []string `json:"srcjars,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001951}