blob: f80f37eab8a096c60ee39603231a1bbbc36dd91e [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"
Colin Cross988414c2020-01-11 01:11:46 +000019 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080020 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "path/filepath"
Jiyong Park1c7e9622020-05-07 16:12:13 +090022 "regexp"
Colin Cross6ff51382015-12-17 16:39:19 -080023 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080024 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070025
26 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070027 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080028)
29
30var (
31 DeviceSharedLibrary = "shared_library"
32 DeviceStaticLibrary = "static_library"
33 DeviceExecutable = "executable"
34 HostSharedLibrary = "host_shared_library"
35 HostStaticLibrary = "host_static_library"
36 HostExecutable = "host_executable"
37)
38
Colin Crossae887032017-10-23 17:16:14 -070039type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070040 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080041 Deps blueprint.Deps
42 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070043 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070044 Output WritablePath
45 Outputs WritablePaths
46 ImplicitOutput WritablePath
47 ImplicitOutputs WritablePaths
48 Input Path
49 Inputs Paths
50 Implicit Path
51 Implicits Paths
52 OrderOnly Paths
53 Default bool
54 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070055}
56
Colin Crossae887032017-10-23 17:16:14 -070057type ModuleBuildParams BuildParams
58
Colin Cross1184b642019-12-30 18:43:07 -080059// EarlyModuleContext provides methods that can be called early, as soon as the properties have
60// been parsed into the module and before any mutators have run.
61type EarlyModuleContext interface {
62 Module() Module
63 ModuleName() string
64 ModuleDir() string
65 ModuleType() string
Colin Cross9d34f352019-11-22 16:03:51 -080066 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080067
68 ContainsProperty(name string) bool
69 Errorf(pos scanner.Position, fmt string, args ...interface{})
70 ModuleErrorf(fmt string, args ...interface{})
71 PropertyErrorf(property, fmt string, args ...interface{})
72 Failed() bool
73
74 AddNinjaFileDeps(deps ...string)
75
76 DeviceSpecific() bool
77 SocSpecific() bool
78 ProductSpecific() bool
79 SystemExtSpecific() bool
80 Platform() bool
81
82 Config() Config
83 DeviceConfig() DeviceConfig
84
85 // Deprecated: use Config()
86 AConfig() Config
87
88 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
89 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
90 // builder whenever a file matching the pattern as added or removed, without rerunning if a
91 // file that does not match the pattern is added to a searched directory.
92 GlobWithDeps(pattern string, excludes []string) ([]string, error)
93
94 Glob(globPattern string, excludes []string) Paths
95 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +000096 IsSymlink(path Path) bool
97 Readlink(path Path) string
Colin Cross1184b642019-12-30 18:43:07 -080098}
99
Colin Cross0ea8ba82019-06-06 14:33:29 -0700100// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700101// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
102// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700103// about the current module.
104type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800105 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700106
Paul Duffinf88d8e02020-05-07 20:21:34 +0100107 blueprintBaseModuleContext() blueprint.BaseModuleContext
108
Colin Crossdc35e212019-06-06 16:13:11 -0700109 OtherModuleName(m blueprint.Module) string
110 OtherModuleDir(m blueprint.Module) string
111 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
112 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
113 OtherModuleExists(name string) bool
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000114 OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
115 OtherModuleReverseDependencyVariantExists(name string) bool
Jiyong Park9e6c2422019-08-09 20:39:45 +0900116 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700117
118 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
119 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
120 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
121
122 VisitDirectDepsBlueprint(visit func(blueprint.Module))
123 VisitDirectDeps(visit func(Module))
124 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
125 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
126 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
127 VisitDepsDepthFirst(visit func(Module))
128 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
129 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
130 WalkDeps(visit func(Module, Module) bool)
131 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
132 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
133 // and returns a top-down dependency path from a start module to current child module.
134 GetWalkPath() []Module
135
Paul Duffinc5192442020-03-31 11:31:36 +0100136 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
137 // and returns a top-down dependency tags path from a start module to current child module.
138 // It has one less entry than GetWalkPath() as it contains the dependency tags that
139 // exist between each adjacent pair of modules in the GetWalkPath().
140 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
141 GetTagPath() []blueprint.DependencyTag
142
Jiyong Park1c7e9622020-05-07 16:12:13 +0900143 // GetPathString is supposed to be called in visit function passed in WalkDeps()
144 // and returns a multi-line string showing the modules and dependency tags
145 // among them along the top-down dependency path from a start module to current child module.
146 // skipFirst when set to true, the output doesn't include the start module,
147 // which is already printed when this function is used along with ModuleErrorf().
148 GetPathString(skipFirst bool) string
149
Colin Crossdc35e212019-06-06 16:13:11 -0700150 AddMissingDependencies(missingDeps []string)
151
Colin Crossa1ad8d12016-06-01 17:09:44 -0700152 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700153 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000154
155 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
156 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700157 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700158 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700159 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700160 Host() bool
161 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700162 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800163 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700164 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700165 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700166 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700167}
168
Colin Cross1184b642019-12-30 18:43:07 -0800169// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700170type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800171 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800172}
173
Colin Cross635c3b02016-05-18 15:37:25 -0700174type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800175 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800176
Colin Crossae887032017-10-23 17:16:14 -0700177 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800178 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700179
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700180 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800181 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800182 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700183
Colin Cross70dda7e2019-10-01 22:05:35 -0700184 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
185 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
186 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
187 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700188 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800189
Colin Cross8d8f8e22016-08-03 11:57:50 -0700190 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700191 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700192 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800193 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900194 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700195 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700196 InstallBypassMake() bool
Colin Cross6e359402020-02-10 15:29:54 -0800197 InstallForceOS() *OsType
Nan Zhang6d34b302017-02-04 17:47:46 -0800198
199 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700200 HostRequiredModuleNames() []string
201 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700202
Colin Cross3f68a132017-10-23 17:10:29 -0700203 ModuleSubDir() string
204
Colin Cross0875c522017-11-28 17:34:01 -0800205 Variable(pctx PackageContext, name, value string)
206 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700207 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
208 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800209 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700210 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
211 // phony rules or real files. Phony can be called on the same name multiple times to add
212 // additional dependencies.
213 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700214
Colin Cross0875c522017-11-28 17:34:01 -0800215 PrimaryModule() Module
216 FinalModule() Module
217 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700218
219 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800220 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800221}
222
Colin Cross635c3b02016-05-18 15:37:25 -0700223type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800224 blueprint.Module
225
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700226 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
227 // but GenerateAndroidBuildActions also has access to Android-specific information.
228 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700229 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700230
Paul Duffin44f1d842020-06-26 20:17:02 +0100231 // Add dependencies to the components of a module, i.e. modules that are created
232 // by the module and which are considered to be part of the creating module.
233 //
234 // This is called before prebuilts are renamed so as to allow a dependency to be
235 // added directly to a prebuilt child module instead of depending on a source module
236 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
237 //
238 // A dependency on a prebuilt must include the "prebuilt_" prefix.
239 ComponentDepsMutator(ctx BottomUpMutatorContext)
240
Colin Cross1e676be2016-10-12 14:38:15 -0700241 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800242
Colin Cross635c3b02016-05-18 15:37:25 -0700243 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900244 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800245 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700246 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800247 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700248 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700249 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800250 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900251 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700252 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700253 InstallBypassMake() bool
Colin Cross6e359402020-02-10 15:29:54 -0800254 InstallForceOS() *OsType
Colin Crossa2f296f2016-11-29 15:16:18 -0800255 SkipInstall()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000256 IsSkipInstall() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900257 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900258 InitRc() Paths
259 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800260 NoticeFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700261
262 AddProperties(props ...interface{})
263 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700264
Colin Crossae887032017-10-23 17:16:14 -0700265 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800266 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800267 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100268
Colin Cross9a362232019-07-01 15:32:45 -0700269 // String returns a string that includes the module name and variants for printing during debugging.
270 String() string
271
Paul Duffine2453c72019-05-31 14:00:04 +0100272 // Get the qualified module id for this module.
273 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
274
275 // Get information about the properties that can contain visibility rules.
276 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100277
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900278 RequiredModuleNames() []string
279 HostRequiredModuleNames() []string
280 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800281
282 filesToInstall() InstallPaths
Paul Duffine2453c72019-05-31 14:00:04 +0100283}
284
285// Qualified id for a module
286type qualifiedModuleName struct {
287 // The package (i.e. directory) in which the module is defined, without trailing /
288 pkg string
289
290 // The name of the module, empty string if package.
291 name string
292}
293
294func (q qualifiedModuleName) String() string {
295 if q.name == "" {
296 return "//" + q.pkg
297 }
298 return "//" + q.pkg + ":" + q.name
299}
300
Paul Duffine484f472019-06-20 16:38:08 +0100301func (q qualifiedModuleName) isRootPackage() bool {
302 return q.pkg == "" && q.name == ""
303}
304
Paul Duffine2453c72019-05-31 14:00:04 +0100305// Get the id for the package containing this module.
306func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
307 pkg := q.pkg
308 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100309 if pkg == "" {
310 panic(fmt.Errorf("Cannot get containing package id of root package"))
311 }
312
313 index := strings.LastIndex(pkg, "/")
314 if index == -1 {
315 pkg = ""
316 } else {
317 pkg = pkg[:index]
318 }
Paul Duffine2453c72019-05-31 14:00:04 +0100319 }
320 return newPackageId(pkg)
321}
322
323func newPackageId(pkg string) qualifiedModuleName {
324 // A qualified id for a package module has no name.
325 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800326}
327
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000328type Dist struct {
329 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
330 // command line and any of these targets are also on the command line, or otherwise
331 // built
332 Targets []string `android:"arch_variant"`
333
334 // The name of the output artifact. This defaults to the basename of the output of
335 // the module.
336 Dest *string `android:"arch_variant"`
337
338 // The directory within the dist directory to store the artifact. Defaults to the
339 // top level directory ("").
340 Dir *string `android:"arch_variant"`
341
342 // A suffix to add to the artifact file name (before any extension).
343 Suffix *string `android:"arch_variant"`
344
345 // A string tag to select the OutputFiles associated with the tag. Defaults to the
346 // the empty "" string.
347 Tag *string `android:"arch_variant"`
348}
349
Colin Crossfc754582016-05-17 16:34:16 -0700350type nameProperties struct {
351 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800352 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700353}
354
355type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800356 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000357 //
358 // Disabling a module should only be done for those modules that cannot be built
359 // in the current environment. Modules that can build in the current environment
360 // but are not usually required (e.g. superceded by a prebuilt) should not be
361 // disabled as that will prevent them from being built by the checkbuild target
362 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800363 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800364
Paul Duffin2e61fa62019-03-28 14:10:57 +0000365 // Controls the visibility of this module to other modules. Allowable values are one or more of
366 // these formats:
367 //
368 // ["//visibility:public"]: Anyone can use this module.
369 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
370 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100371 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
372 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000373 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
374 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
375 // this module. Note that sub-packages do not have access to the rule; for example,
376 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
377 // is a special module and must be used verbatim. It represents all of the modules in the
378 // package.
379 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
380 // or other or in one of their sub-packages have access to this module. For example,
381 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
382 // to depend on this rule (but not //independent:evil)
383 // ["//project"]: This is shorthand for ["//project:__pkg__"]
384 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
385 // //project is the module's package. e.g. using [":__subpackages__"] in
386 // packages/apps/Settings/Android.bp is equivalent to
387 // //packages/apps/Settings:__subpackages__.
388 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
389 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100390 //
391 // If a module does not specify the `visibility` property then it uses the
392 // `default_visibility` property of the `package` module in the module's package.
393 //
394 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100395 // it will use the `default_visibility` of its closest ancestor package for which
396 // a `default_visibility` property is specified.
397 //
398 // If no `default_visibility` property can be found then the module uses the
399 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100400 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100401 // The `visibility` property has no effect on a defaults module although it does
402 // apply to any non-defaults module that uses it. To set the visibility of a
403 // defaults module, use the `defaults_visibility` property on the defaults module;
404 // not to be confused with the `default_visibility` property on the package module.
405 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000406 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
407 // more details.
408 Visibility []string
409
Colin Cross7d5136f2015-05-11 13:39:40 -0700410 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800411 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
412 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
413 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700414 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700415
416 Target struct {
417 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700418 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700419 }
420 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700421 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700422 }
423 }
424
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000425 // If set to true then the archMutator will create variants for each arch specific target
426 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
427 // create a variant for the architecture and will list the additional arch specific targets
428 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700429 UseTargetVariants bool `blueprint:"mutated"`
430 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800431
Dan Willemsen782a2d12015-12-21 14:55:28 -0800432 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700433 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800434
Colin Cross55708f32017-03-20 13:23:34 -0700435 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700436 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700437
Jiyong Park2db76922017-11-08 16:03:48 +0900438 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
439 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
440 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700441 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700442
Jiyong Park2db76922017-11-08 16:03:48 +0900443 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
444 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
445 Soc_specific *bool
446
447 // whether this module is specific to a device, not only for SoC, but also for off-chip
448 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
449 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
450 // This implies `soc_specific:true`.
451 Device_specific *bool
452
453 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900454 // network operator, etc). When set to true, it is installed into /product (or
455 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900456 Product_specific *bool
457
Justin Yund5f6c822019-06-25 16:47:17 +0900458 // whether this module extends system. When set to true, it is installed into /system_ext
459 // (or /system/system_ext if system_ext partition does not exist).
460 System_ext_specific *bool
461
Jiyong Parkf9332f12018-02-01 00:54:12 +0900462 // Whether this module is installed to recovery partition
463 Recovery *bool
464
Yifan Hong1b3348d2020-01-21 15:53:22 -0800465 // Whether this module is installed to ramdisk
466 Ramdisk *bool
467
dimitry1f33e402019-03-26 12:39:31 +0100468 // Whether this module is built for non-native architecures (also known as native bridge binary)
469 Native_bridge_supported *bool `android:"arch_variant"`
470
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700471 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800472 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700473
Steven Moreland57a23d22018-04-04 15:42:19 -0700474 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800475 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700476
Chris Wolfe998306e2016-08-15 14:47:23 -0400477 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700478 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400479
Sasha Smundakb6d23052019-04-01 18:37:36 -0700480 // names of other modules to install on host if this module is installed
481 Host_required []string `android:"arch_variant"`
482
483 // names of other modules to install on target if this module is installed
484 Target_required []string `android:"arch_variant"`
485
Colin Cross5aac3622017-08-31 15:07:09 -0700486 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800487 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700488
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000489 // configuration to distribute output files from this module to the distribution
490 // directory (default: $OUT/dist, configurable with $DIST_DIR)
491 Dist Dist `android:"arch_variant"`
Dan Willemsen569edc52018-11-19 09:33:29 -0800492
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000493 // a list of configurations to distribute output files from this module to the
494 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
495 Dists []Dist `android:"arch_variant"`
Dan Willemsen569edc52018-11-19 09:33:29 -0800496
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000497 // The OsType of artifacts that this module variant is responsible for creating.
498 //
499 // Set by osMutator
500 CompileOS OsType `blueprint:"mutated"`
501
502 // The Target of artifacts that this module variant is responsible for creating.
503 //
504 // Set by archMutator
505 CompileTarget Target `blueprint:"mutated"`
506
507 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
508 // responsible for creating.
509 //
510 // By default this is nil as, where necessary, separate variants are created for the
511 // different multilib types supported and that information is encapsulated in the
512 // CompileTarget so the module variant simply needs to create artifacts for that.
513 //
514 // However, if UseTargetVariants is set to false (e.g. by
515 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
516 // multilib targets. Instead a single variant is created for the architecture and
517 // this contains the multilib specific targets that this variant should create.
518 //
519 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700520 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000521
522 // True if the module variant's CompileTarget is the primary target
523 //
524 // Set by archMutator
525 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800526
527 // Set by InitAndroidModule
528 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700529 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700530
Paul Duffin1356d8c2020-02-25 19:26:33 +0000531 // If set to true then a CommonOS variant will be created which will have dependencies
532 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
533 // that covers all os and architecture variants.
534 //
535 // The OsType specific variants can be retrieved by calling
536 // GetOsSpecificVariantsOfCommonOSVariant
537 //
538 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
539 CreateCommonOSVariant bool `blueprint:"mutated"`
540
541 // If set to true then this variant is the CommonOS variant that has dependencies on its
542 // OsType specific variants.
543 //
544 // Set by osMutator.
545 CommonOSVariant bool `blueprint:"mutated"`
546
Colin Crossce75d2c2016-10-06 16:12:58 -0700547 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800548
549 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700550
551 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700552
553 // Name and variant strings stored by mutators to enable Module.String()
554 DebugName string `blueprint:"mutated"`
555 DebugMutators []string `blueprint:"mutated"`
556 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800557
558 // set by ImageMutator
559 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800560}
561
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000562// A map of OutputFile tag keys to Paths, for disting purposes.
563type TaggedDistFiles map[string]Paths
564
565func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
566 // The default OutputFile tag is the empty "" string.
567 return TaggedDistFiles{"": paths}
568}
569
Colin Cross3f40fa42015-01-30 17:27:36 -0800570type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800571 // If set to true, build a variant of the module for the host. Defaults to false.
572 Host_supported *bool
573
574 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700575 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800576}
577
Colin Crossc472d572015-03-17 15:06:21 -0700578type Multilib string
579
580const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800581 MultilibBoth Multilib = "both"
582 MultilibFirst Multilib = "first"
583 MultilibCommon Multilib = "common"
584 MultilibCommonFirst Multilib = "common_first"
585 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700586)
587
Colin Crossa1ad8d12016-06-01 17:09:44 -0700588type HostOrDeviceSupported int
589
590const (
591 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700592
593 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700594 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700595
596 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700597 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700598
599 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700600 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700601
602 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700603 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700604
605 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700606 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700607
608 // Nothing is supported. This is not exposed to the user, but used to mark a
609 // host only module as unsupported when the module type is not supported on
610 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700611 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700612)
613
Jiyong Park2db76922017-11-08 16:03:48 +0900614type moduleKind int
615
616const (
617 platformModule moduleKind = iota
618 deviceSpecificModule
619 socSpecificModule
620 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900621 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900622)
623
624func (k moduleKind) String() string {
625 switch k {
626 case platformModule:
627 return "platform"
628 case deviceSpecificModule:
629 return "device-specific"
630 case socSpecificModule:
631 return "soc-specific"
632 case productSpecificModule:
633 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900634 case systemExtSpecificModule:
635 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900636 default:
637 panic(fmt.Errorf("unknown module kind %d", k))
638 }
639}
640
Colin Cross9d34f352019-11-22 16:03:51 -0800641func initAndroidModuleBase(m Module) {
642 m.base().module = m
643}
644
Colin Cross36242852017-06-23 15:06:31 -0700645func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800646 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800647 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700648
Colin Cross36242852017-06-23 15:06:31 -0700649 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700650 &base.nameProperties,
Colin Cross18c46802019-09-24 22:19:02 -0700651 &base.commonProperties)
652
Colin Crosseabaedd2020-02-06 17:01:55 -0800653 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700654
Colin Crossa3a97412019-03-18 12:24:29 -0700655 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700656 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100657
658 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +0100659 // its checking and parsing phases so make it the primary visibility property.
660 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Colin Cross5049f022015-03-18 13:28:46 -0700661}
662
Colin Cross36242852017-06-23 15:06:31 -0700663func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
664 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700665
666 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800667 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700668 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700669 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700670 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800671
Dan Willemsen218f6562015-07-08 18:13:11 -0700672 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700673 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700674 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800675 }
676
Colin Cross36242852017-06-23 15:06:31 -0700677 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800678}
679
Colin Crossee0bc3b2018-10-02 22:01:37 -0700680func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
681 InitAndroidArchModule(m, hod, defaultMultilib)
682 m.base().commonProperties.UseTargetVariants = false
683}
684
Paul Duffin1356d8c2020-02-25 19:26:33 +0000685// As InitAndroidMultiTargetsArchModule except it creates an additional CommonOS variant that
686// has dependencies on all the OsType specific variants.
687func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
688 InitAndroidArchModule(m, hod, defaultMultilib)
689 m.base().commonProperties.UseTargetVariants = false
690 m.base().commonProperties.CreateCommonOSVariant = true
691}
692
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800693// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800694// modules. It should be included as an anonymous field in every module
695// struct definition. InitAndroidModule should then be called from the module's
696// factory function, and the return values from InitAndroidModule should be
697// returned from the factory function.
698//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800699// The ModuleBase type is responsible for implementing the GenerateBuildActions
700// method to support the blueprint.Module interface. This method will then call
701// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700702// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
703// rather than the usual blueprint.ModuleContext.
704// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800705// system including details about the particular build variant that is to be
706// generated.
707//
708// For example:
709//
710// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800711// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800712// )
713//
714// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800715// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800716// properties struct {
717// MyProperty string
718// }
719// }
720//
Colin Cross36242852017-06-23 15:06:31 -0700721// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800722// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700723// m.AddProperties(&m.properties)
724// android.InitAndroidModule(m)
725// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800726// }
727//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800728// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800729// // Get the CPU architecture for the current build variant.
730// variantArch := ctx.Arch()
731//
732// // ...
733// }
Colin Cross635c3b02016-05-18 15:37:25 -0700734type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800735 // Putting the curiously recurring thing pointing to the thing that contains
736 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700737 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700738 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800739
Colin Crossfc754582016-05-17 16:34:16 -0700740 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800741 commonProperties commonProperties
Colin Cross18c46802019-09-24 22:19:02 -0700742 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800743 hostAndDeviceProperties hostAndDeviceProperties
744 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700745 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700746 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800747
Paul Duffin63c6e182019-07-24 14:24:38 +0100748 // Information about all the properties on the module that contains visibility rules that need
749 // checking.
750 visibilityPropertyInfo []visibilityProperty
751
752 // The primary visibility property, may be nil, that controls access to the module.
753 primaryVisibilityProperty visibilityProperty
754
Colin Cross3f40fa42015-01-30 17:27:36 -0800755 noAddressSanitizer bool
Colin Cross897266e2020-02-13 13:22:08 -0800756 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700757 checkbuildFiles Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800758 noticeFiles Paths
Colin Crossc3d87d32020-06-04 13:25:17 -0700759 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -0700760
761 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
762 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800763 installTarget WritablePath
764 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700765 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700766
Colin Cross178a5092016-09-13 13:42:32 -0700767 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700768
769 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700770
771 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700772 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800773 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800774 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700775
Inseob Kim8471cda2019-11-15 09:59:12 +0900776 initRcPaths Paths
777 vintfFragmentsPaths Paths
778
Colin Crossa9d8bee2018-10-02 13:59:46 -0700779 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700780}
781
Paul Duffin44f1d842020-06-26 20:17:02 +0100782func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
783
Colin Cross4157e882019-06-06 16:57:04 -0700784func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800785
Colin Cross4157e882019-06-06 16:57:04 -0700786func (m *ModuleBase) AddProperties(props ...interface{}) {
787 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700788}
789
Colin Cross4157e882019-06-06 16:57:04 -0700790func (m *ModuleBase) GetProperties() []interface{} {
791 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800792}
793
Colin Cross4157e882019-06-06 16:57:04 -0700794func (m *ModuleBase) BuildParamsForTests() []BuildParams {
795 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700796}
797
Colin Cross4157e882019-06-06 16:57:04 -0700798func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
799 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800800}
801
Colin Cross4157e882019-06-06 16:57:04 -0700802func (m *ModuleBase) VariablesForTests() map[string]string {
803 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800804}
805
Colin Cross4157e882019-06-06 16:57:04 -0700806func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
807 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700808}
809
Colin Crossce75d2c2016-10-06 16:12:58 -0700810// Name returns the name of the module. It may be overridden by individual module types, for
811// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700812func (m *ModuleBase) Name() string {
813 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700814}
815
Colin Cross9a362232019-07-01 15:32:45 -0700816// String returns a string that includes the module name and variants for printing during debugging.
817func (m *ModuleBase) String() string {
818 sb := strings.Builder{}
819 sb.WriteString(m.commonProperties.DebugName)
820 sb.WriteString("{")
821 for i := range m.commonProperties.DebugMutators {
822 if i != 0 {
823 sb.WriteString(",")
824 }
825 sb.WriteString(m.commonProperties.DebugMutators[i])
826 sb.WriteString(":")
827 sb.WriteString(m.commonProperties.DebugVariations[i])
828 }
829 sb.WriteString("}")
830 return sb.String()
831}
832
Colin Crossce75d2c2016-10-06 16:12:58 -0700833// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -0700834func (m *ModuleBase) BaseModuleName() string {
835 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700836}
837
Colin Cross4157e882019-06-06 16:57:04 -0700838func (m *ModuleBase) base() *ModuleBase {
839 return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800840}
841
Paul Duffine2453c72019-05-31 14:00:04 +0100842func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
843 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
844}
845
846func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +0100847 return m.visibilityPropertyInfo
848}
849
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000850func (m *ModuleBase) Dists() []Dist {
851 if len(m.commonProperties.Dist.Targets) > 0 {
852 // Make a copy of the underlying Dists slice to protect against
853 // backing array modifications with repeated calls to this method.
854 distsCopy := append([]Dist(nil), m.commonProperties.Dists...)
855 return append(distsCopy, m.commonProperties.Dist)
856 } else {
857 return m.commonProperties.Dists
858 }
859}
860
861func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
862 distFiles := make(TaggedDistFiles)
863 for _, dist := range m.Dists() {
864 var tag string
865 var distFilesForTag Paths
866 if dist.Tag == nil {
867 tag = ""
868 } else {
869 tag = *dist.Tag
870 }
871 distFilesForTag, err := m.base().module.(OutputFileProducer).OutputFiles(tag)
872 if err != nil {
873 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
874 }
875 for _, distFile := range distFilesForTag {
876 if distFile != nil && !distFiles[tag].containsPath(distFile) {
877 distFiles[tag] = append(distFiles[tag], distFile)
878 }
879 }
880 }
881
882 return distFiles
883}
884
Colin Cross4157e882019-06-06 16:57:04 -0700885func (m *ModuleBase) Target() Target {
886 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800887}
888
Colin Cross4157e882019-06-06 16:57:04 -0700889func (m *ModuleBase) TargetPrimary() bool {
890 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -0700891}
892
Colin Cross4157e882019-06-06 16:57:04 -0700893func (m *ModuleBase) MultiTargets() []Target {
894 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -0700895}
896
Colin Cross4157e882019-06-06 16:57:04 -0700897func (m *ModuleBase) Os() OsType {
898 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800899}
900
Colin Cross4157e882019-06-06 16:57:04 -0700901func (m *ModuleBase) Host() bool {
902 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800903}
904
Yo Chiangbba545e2020-06-09 16:15:37 +0800905func (m *ModuleBase) Device() bool {
906 return m.Os().Class == Device
907}
908
Colin Cross4157e882019-06-06 16:57:04 -0700909func (m *ModuleBase) Arch() Arch {
910 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800911}
912
Colin Cross4157e882019-06-06 16:57:04 -0700913func (m *ModuleBase) ArchSpecific() bool {
914 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -0700915}
916
Paul Duffin1356d8c2020-02-25 19:26:33 +0000917// True if the current variant is a CommonOS variant, false otherwise.
918func (m *ModuleBase) IsCommonOSVariant() bool {
919 return m.commonProperties.CommonOSVariant
920}
921
Colin Cross4157e882019-06-06 16:57:04 -0700922func (m *ModuleBase) OsClassSupported() []OsClass {
923 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700924 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700925 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700926 case HostSupportedNoCross:
927 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700928 case DeviceSupported:
929 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -0700930 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700931 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -0700932 if Bool(m.hostAndDeviceProperties.Host_supported) ||
933 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
934 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700935 supported = append(supported, Host, HostCross)
936 }
Colin Cross4157e882019-06-06 16:57:04 -0700937 if m.hostAndDeviceProperties.Device_supported == nil ||
938 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700939 supported = append(supported, Device)
940 }
941 return supported
942 default:
943 return nil
944 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800945}
946
Colin Cross4157e882019-06-06 16:57:04 -0700947func (m *ModuleBase) DeviceSupported() bool {
948 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
949 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
950 (m.hostAndDeviceProperties.Device_supported == nil ||
951 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800952}
953
Paul Duffine44358f2019-11-26 18:04:12 +0000954func (m *ModuleBase) HostSupported() bool {
955 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
956 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
957 (m.hostAndDeviceProperties.Host_supported != nil &&
958 *m.hostAndDeviceProperties.Host_supported)
959}
960
Colin Cross4157e882019-06-06 16:57:04 -0700961func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +0900962 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900963}
964
Colin Cross4157e882019-06-06 16:57:04 -0700965func (m *ModuleBase) DeviceSpecific() bool {
966 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900967}
968
Colin Cross4157e882019-06-06 16:57:04 -0700969func (m *ModuleBase) SocSpecific() bool {
970 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900971}
972
Colin Cross4157e882019-06-06 16:57:04 -0700973func (m *ModuleBase) ProductSpecific() bool {
974 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900975}
976
Justin Yund5f6c822019-06-25 16:47:17 +0900977func (m *ModuleBase) SystemExtSpecific() bool {
978 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +0100979}
980
Colin Crossc2d24052020-05-13 11:05:02 -0700981// RequiresStableAPIs returns true if the module will be installed to a partition that may
982// be updated separately from the system image.
983func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
984 return m.SocSpecific() || m.DeviceSpecific() ||
985 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
986}
987
Bill Peckhamfff3f8a2020-03-20 18:33:20 -0700988func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
989 partition := "system"
990 if m.SocSpecific() {
991 // A SoC-specific module could be on the vendor partition at
992 // "vendor" or the system partition at "system/vendor".
993 if config.VendorPath() == "vendor" {
994 partition = "vendor"
995 }
996 } else if m.DeviceSpecific() {
997 // A device-specific module could be on the odm partition at
998 // "odm", the vendor partition at "vendor/odm", or the system
999 // partition at "system/vendor/odm".
1000 if config.OdmPath() == "odm" {
1001 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001002 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001003 partition = "vendor"
1004 }
1005 } else if m.ProductSpecific() {
1006 // A product-specific module could be on the product partition
1007 // at "product" or the system partition at "system/product".
1008 if config.ProductPath() == "product" {
1009 partition = "product"
1010 }
1011 } else if m.SystemExtSpecific() {
1012 // A system_ext-specific module could be on the system_ext
1013 // partition at "system_ext" or the system partition at
1014 // "system/system_ext".
1015 if config.SystemExtPath() == "system_ext" {
1016 partition = "system_ext"
1017 }
1018 }
1019 return partition
1020}
1021
Colin Cross4157e882019-06-06 16:57:04 -07001022func (m *ModuleBase) Enabled() bool {
1023 if m.commonProperties.Enabled == nil {
1024 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -08001025 }
Colin Cross4157e882019-06-06 16:57:04 -07001026 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001027}
1028
Inseob Kimeec88e12020-01-22 11:11:29 +09001029func (m *ModuleBase) Disable() {
1030 m.commonProperties.Enabled = proptools.BoolPtr(false)
1031}
1032
Colin Cross4157e882019-06-06 16:57:04 -07001033func (m *ModuleBase) SkipInstall() {
1034 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001035}
1036
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00001037func (m *ModuleBase) IsSkipInstall() bool {
1038 return m.commonProperties.SkipInstall == true
1039}
1040
Colin Cross4157e882019-06-06 16:57:04 -07001041func (m *ModuleBase) ExportedToMake() bool {
1042 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001043}
1044
Colin Cross897266e2020-02-13 13:22:08 -08001045func (m *ModuleBase) computeInstallDeps(ctx blueprint.ModuleContext) InstallPaths {
Colin Cross3f40fa42015-01-30 17:27:36 -08001046
Colin Cross897266e2020-02-13 13:22:08 -08001047 var result InstallPaths
Colin Cross6b753602018-06-21 13:03:07 -07001048 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross897266e2020-02-13 13:22:08 -08001049 ctx.VisitDepsDepthFirst(func(m blueprint.Module) {
1050 if a, ok := m.(Module); ok {
1051 result = append(result, a.filesToInstall()...)
1052 }
1053 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001054
1055 return result
1056}
1057
Colin Cross897266e2020-02-13 13:22:08 -08001058func (m *ModuleBase) filesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001059 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001060}
1061
Colin Cross4157e882019-06-06 16:57:04 -07001062func (m *ModuleBase) NoAddressSanitizer() bool {
1063 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001064}
1065
Colin Cross4157e882019-06-06 16:57:04 -07001066func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001067 return false
1068}
1069
Jaewoong Jung0949f312019-09-11 10:25:18 -07001070func (m *ModuleBase) InstallInTestcases() bool {
1071 return false
1072}
1073
Colin Cross4157e882019-06-06 16:57:04 -07001074func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001075 return false
1076}
1077
Yifan Hong1b3348d2020-01-21 15:53:22 -08001078func (m *ModuleBase) InstallInRamdisk() bool {
1079 return Bool(m.commonProperties.Ramdisk)
1080}
1081
Colin Cross4157e882019-06-06 16:57:04 -07001082func (m *ModuleBase) InstallInRecovery() bool {
1083 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001084}
1085
Colin Cross90ba5f42019-10-02 11:10:58 -07001086func (m *ModuleBase) InstallInRoot() bool {
1087 return false
1088}
1089
Colin Cross607d8582019-07-29 16:44:46 -07001090func (m *ModuleBase) InstallBypassMake() bool {
1091 return false
1092}
1093
Colin Cross6e359402020-02-10 15:29:54 -08001094func (m *ModuleBase) InstallForceOS() *OsType {
1095 return nil
1096}
1097
Colin Cross4157e882019-06-06 16:57:04 -07001098func (m *ModuleBase) Owner() string {
1099 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001100}
1101
Bob Badoura75b0572020-02-18 20:21:55 -08001102func (m *ModuleBase) NoticeFiles() Paths {
1103 return m.noticeFiles
Jiyong Park52818fc2019-03-18 12:01:38 +09001104}
1105
Colin Cross7228ecd2019-11-18 16:00:16 -08001106func (m *ModuleBase) setImageVariation(variant string) {
1107 m.commonProperties.ImageVariation = variant
1108}
1109
1110func (m *ModuleBase) ImageVariation() blueprint.Variation {
1111 return blueprint.Variation{
1112 Mutator: "image",
1113 Variation: m.base().commonProperties.ImageVariation,
1114 }
1115}
1116
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001117func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1118 for i, v := range m.commonProperties.DebugMutators {
1119 if v == mutator {
1120 return m.commonProperties.DebugVariations[i]
1121 }
1122 }
1123
1124 return ""
1125}
1126
Yifan Hong1b3348d2020-01-21 15:53:22 -08001127func (m *ModuleBase) InRamdisk() bool {
1128 return m.base().commonProperties.ImageVariation == RamdiskVariation
1129}
1130
Colin Cross7228ecd2019-11-18 16:00:16 -08001131func (m *ModuleBase) InRecovery() bool {
1132 return m.base().commonProperties.ImageVariation == RecoveryVariation
1133}
1134
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001135func (m *ModuleBase) RequiredModuleNames() []string {
1136 return m.base().commonProperties.Required
1137}
1138
1139func (m *ModuleBase) HostRequiredModuleNames() []string {
1140 return m.base().commonProperties.Host_required
1141}
1142
1143func (m *ModuleBase) TargetRequiredModuleNames() []string {
1144 return m.base().commonProperties.Target_required
1145}
1146
Inseob Kim8471cda2019-11-15 09:59:12 +09001147func (m *ModuleBase) InitRc() Paths {
1148 return append(Paths{}, m.initRcPaths...)
1149}
1150
1151func (m *ModuleBase) VintfFragments() Paths {
1152 return append(Paths{}, m.vintfFragmentsPaths...)
1153}
1154
Colin Cross4157e882019-06-06 16:57:04 -07001155func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001156 var allInstalledFiles InstallPaths
1157 var allCheckbuildFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001158 ctx.VisitAllModuleVariants(func(module Module) {
1159 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001160 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1161 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001162 })
1163
Colin Cross0875c522017-11-28 17:34:01 -08001164 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001165
Jeff Gaston088e29e2017-11-29 16:47:17 -08001166 namespacePrefix := ctx.Namespace().(*Namespace).id
1167 if namespacePrefix != "" {
1168 namespacePrefix = namespacePrefix + "-"
1169 }
1170
Colin Cross3f40fa42015-01-30 17:27:36 -08001171 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001172 name := namespacePrefix + ctx.ModuleName() + "-install"
1173 ctx.Phony(name, allInstalledFiles.Paths()...)
1174 m.installTarget = PathForPhony(ctx, name)
1175 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001176 }
1177
1178 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001179 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1180 ctx.Phony(name, allCheckbuildFiles...)
1181 m.checkbuildTarget = PathForPhony(ctx, name)
1182 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001183 }
1184
1185 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001186 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001187 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001188 suffix = "-soong"
1189 }
1190
Colin Crossc3d87d32020-06-04 13:25:17 -07001191 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001192
Colin Cross4157e882019-06-06 16:57:04 -07001193 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001194 }
1195}
1196
Colin Crossc34d2322020-01-03 15:23:27 -08001197func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001198 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1199 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1200 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001201 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001202
Dario Frenifd05a742018-05-29 13:28:54 +01001203 msg := "conflicting value set here"
1204 if socSpecific && deviceSpecific {
1205 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001206 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001207 ctx.PropertyErrorf("vendor", msg)
1208 }
Colin Cross4157e882019-06-06 16:57:04 -07001209 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001210 ctx.PropertyErrorf("proprietary", msg)
1211 }
Colin Cross4157e882019-06-06 16:57:04 -07001212 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001213 ctx.PropertyErrorf("soc_specific", msg)
1214 }
1215 }
1216
Justin Yund5f6c822019-06-25 16:47:17 +09001217 if productSpecific && systemExtSpecific {
1218 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1219 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001220 }
1221
Justin Yund5f6c822019-06-25 16:47:17 +09001222 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001223 if productSpecific {
1224 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1225 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001226 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 +01001227 }
1228 if deviceSpecific {
1229 ctx.PropertyErrorf("device_specific", msg)
1230 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001231 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001232 ctx.PropertyErrorf("vendor", msg)
1233 }
Colin Cross4157e882019-06-06 16:57:04 -07001234 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001235 ctx.PropertyErrorf("proprietary", msg)
1236 }
Colin Cross4157e882019-06-06 16:57:04 -07001237 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001238 ctx.PropertyErrorf("soc_specific", msg)
1239 }
1240 }
1241 }
1242
Jiyong Park2db76922017-11-08 16:03:48 +09001243 if productSpecific {
1244 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001245 } else if systemExtSpecific {
1246 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001247 } else if deviceSpecific {
1248 return deviceSpecificModule
1249 } else if socSpecific {
1250 return socSpecificModule
1251 } else {
1252 return platformModule
1253 }
1254}
1255
Colin Crossc34d2322020-01-03 15:23:27 -08001256func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001257 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001258 EarlyModuleContext: ctx,
1259 kind: determineModuleKind(m, ctx),
1260 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001261 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001262}
1263
Colin Cross1184b642019-12-30 18:43:07 -08001264func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1265 return baseModuleContext{
1266 bp: ctx,
1267 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1268 os: m.commonProperties.CompileOS,
1269 target: m.commonProperties.CompileTarget,
1270 targetPrimary: m.commonProperties.CompilePrimary,
1271 multiTargets: m.commonProperties.CompileMultiTargets,
1272 }
1273}
1274
Colin Cross4157e882019-06-06 16:57:04 -07001275func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001276 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001277 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001278 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001279 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1280 installDeps: m.computeInstallDeps(blueprintCtx),
1281 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001282 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001283 }
1284
Colin Cross6c4f21f2019-06-06 15:41:36 -07001285 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1286 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1287 // TODO: This will be removed once defaults modules handle missing dependency errors
1288 blueprintCtx.GetMissingDependencies()
1289
Colin Crossdc35e212019-06-06 16:13:11 -07001290 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001291 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1292 // (because the dependencies are added before the modules are disabled). The
1293 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1294 // ignored.
1295 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001296
Colin Cross4c83e5c2019-02-25 14:54:28 -08001297 if ctx.config.captureBuild {
1298 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1299 }
1300
Colin Cross67a5c132017-05-09 13:45:28 -07001301 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1302 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001303 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1304 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001305 }
Colin Cross0875c522017-11-28 17:34:01 -08001306 if !ctx.PrimaryArch() {
1307 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001308 }
Dan Willemsenb13a9482020-02-14 11:25:54 -08001309 if apex, ok := m.module.(ApexModule); ok && !apex.IsForPlatform() {
1310 suffix = append(suffix, apex.ApexName())
1311 }
Colin Cross67a5c132017-05-09 13:45:28 -07001312
1313 ctx.Variable(pctx, "moduleDesc", desc)
1314
1315 s := ""
1316 if len(suffix) > 0 {
1317 s = " [" + strings.Join(suffix, " ") + "]"
1318 }
1319 ctx.Variable(pctx, "moduleDescSuffix", s)
1320
Dan Willemsen569edc52018-11-19 09:33:29 -08001321 // Some common property checks for properties that will be used later in androidmk.go
Colin Cross4157e882019-06-06 16:57:04 -07001322 if m.commonProperties.Dist.Dest != nil {
1323 _, err := validateSafePath(*m.commonProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001324 if err != nil {
1325 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1326 }
1327 }
Colin Cross4157e882019-06-06 16:57:04 -07001328 if m.commonProperties.Dist.Dir != nil {
1329 _, err := validateSafePath(*m.commonProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001330 if err != nil {
1331 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1332 }
1333 }
Colin Cross4157e882019-06-06 16:57:04 -07001334 if m.commonProperties.Dist.Suffix != nil {
1335 if strings.Contains(*m.commonProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001336 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1337 }
1338 }
1339
Colin Cross4157e882019-06-06 16:57:04 -07001340 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001341 // ensure all direct android.Module deps are enabled
1342 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1343 if _, ok := bm.(Module); ok {
1344 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1345 }
1346 })
1347
Bob Badoura75b0572020-02-18 20:21:55 -08001348 m.noticeFiles = make([]Path, 0)
1349 optPath := OptionalPath{}
1350 notice := proptools.StringDefault(m.commonProperties.Notice, "")
Colin Cross4157e882019-06-06 16:57:04 -07001351 if module := SrcIsModule(notice); module != "" {
Bob Badoura75b0572020-02-18 20:21:55 -08001352 optPath = ctx.ExpandOptionalSource(&notice, "notice")
1353 } else if notice != "" {
Jiyong Park52818fc2019-03-18 12:01:38 +09001354 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Bob Badoura75b0572020-02-18 20:21:55 -08001355 optPath = ExistentPathForSource(ctx, noticePath)
1356 }
1357 if optPath.Valid() {
1358 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1359 } else {
1360 for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} {
1361 noticePath := filepath.Join(ctx.ModuleDir(), notice)
1362 optPath = ExistentPathForSource(ctx, noticePath)
1363 if optPath.Valid() {
1364 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1365 }
1366 }
Jaewoong Jung62707f72018-11-16 13:26:43 -08001367 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001368
1369 m.module.GenerateAndroidBuildActions(ctx)
1370 if ctx.Failed() {
1371 return
1372 }
1373
1374 m.installFiles = append(m.installFiles, ctx.installFiles...)
1375 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Inseob Kim8471cda2019-11-15 09:59:12 +09001376 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1377 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
Colin Crossc3d87d32020-06-04 13:25:17 -07001378 for k, v := range ctx.phonies {
1379 m.phonies[k] = append(m.phonies[k], v...)
1380 }
Colin Crossdc35e212019-06-06 16:13:11 -07001381 } else if ctx.Config().AllowMissingDependencies() {
1382 // If the module is not enabled it will not create any build rules, nothing will call
1383 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1384 // and report them as an error even when AllowMissingDependencies = true. Call
1385 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1386 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001387 }
1388
Colin Cross4157e882019-06-06 16:57:04 -07001389 if m == ctx.FinalModule().(Module).base() {
1390 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001391 if ctx.Failed() {
1392 return
1393 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001394 }
Colin Crosscec81712017-07-13 14:43:27 -07001395
Colin Cross4157e882019-06-06 16:57:04 -07001396 m.buildParams = ctx.buildParams
1397 m.ruleParams = ctx.ruleParams
1398 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001399}
1400
Colin Cross1184b642019-12-30 18:43:07 -08001401type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001402 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001403
1404 kind moduleKind
1405 config Config
1406}
1407
1408func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1409 ret, err := e.GlobWithDeps(globPattern, excludes)
1410 if err != nil {
1411 e.ModuleErrorf("glob: %s", err.Error())
1412 }
1413 return pathsForModuleSrcFromFullPath(e, ret, true)
1414}
1415
1416func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1417 ret, err := e.GlobWithDeps(globPattern, excludes)
1418 if err != nil {
1419 e.ModuleErrorf("glob: %s", err.Error())
1420 }
1421 return pathsForModuleSrcFromFullPath(e, ret, false)
1422}
1423
Colin Cross988414c2020-01-11 01:11:46 +00001424func (b *earlyModuleContext) IsSymlink(path Path) bool {
1425 fileInfo, err := b.config.fs.Lstat(path.String())
1426 if err != nil {
1427 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1428 }
1429 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1430}
1431
1432func (b *earlyModuleContext) Readlink(path Path) string {
1433 dest, err := b.config.fs.Readlink(path.String())
1434 if err != nil {
1435 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1436 }
1437 return dest
1438}
1439
Colin Cross1184b642019-12-30 18:43:07 -08001440func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001441 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001442 return module
1443}
1444
1445func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001446 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001447}
1448
1449func (e *earlyModuleContext) AConfig() Config {
1450 return e.config
1451}
1452
1453func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1454 return DeviceConfig{e.config.deviceConfig}
1455}
1456
1457func (e *earlyModuleContext) Platform() bool {
1458 return e.kind == platformModule
1459}
1460
1461func (e *earlyModuleContext) DeviceSpecific() bool {
1462 return e.kind == deviceSpecificModule
1463}
1464
1465func (e *earlyModuleContext) SocSpecific() bool {
1466 return e.kind == socSpecificModule
1467}
1468
1469func (e *earlyModuleContext) ProductSpecific() bool {
1470 return e.kind == productSpecificModule
1471}
1472
1473func (e *earlyModuleContext) SystemExtSpecific() bool {
1474 return e.kind == systemExtSpecificModule
1475}
1476
1477type baseModuleContext struct {
1478 bp blueprint.BaseModuleContext
1479 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001480 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001481 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001482 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001483 targetPrimary bool
1484 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001485
1486 walkPath []Module
Paul Duffinc5192442020-03-31 11:31:36 +01001487 tagPath []blueprint.DependencyTag
Colin Crossdc35e212019-06-06 16:13:11 -07001488
1489 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001490}
1491
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001492func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
1493 return b.bp.OtherModuleName(m)
1494}
1495func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08001496func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Hancd87c692020-02-26 02:05:18 +09001497 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08001498}
1499func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1500 return b.bp.OtherModuleDependencyTag(m)
1501}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001502func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00001503func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
1504 return b.bp.OtherModuleDependencyVariantExists(variations, name)
1505}
1506func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
1507 return b.bp.OtherModuleReverseDependencyVariantExists(name)
1508}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001509func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
1510 return b.bp.OtherModuleType(m)
1511}
Colin Cross1184b642019-12-30 18:43:07 -08001512
1513func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1514 return b.bp.GetDirectDepWithTag(name, tag)
1515}
1516
Paul Duffinf88d8e02020-05-07 20:21:34 +01001517func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
1518 return b.bp
1519}
1520
Colin Cross25de6c32019-06-06 14:29:25 -07001521type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001522 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001523 baseModuleContext
Colin Cross897266e2020-02-13 13:22:08 -08001524 installDeps InstallPaths
1525 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001526 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001527 module Module
Colin Crossc3d87d32020-06-04 13:25:17 -07001528 phonies map[string]Paths
Colin Crosscec81712017-07-13 14:43:27 -07001529
1530 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001531 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001532 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001533 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001534}
1535
Colin Crossb88b3c52019-06-10 15:15:17 -07001536func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1537 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001538 Rule: ErrorRule,
1539 Description: params.Description,
1540 Output: params.Output,
1541 Outputs: params.Outputs,
1542 ImplicitOutput: params.ImplicitOutput,
1543 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001544 Args: map[string]string{
1545 "error": err.Error(),
1546 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001547 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001548}
1549
Colin Cross25de6c32019-06-06 14:29:25 -07001550func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1551 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001552}
1553
Colin Cross0875c522017-11-28 17:34:01 -08001554func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001555 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001556 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001557 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001558 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001559 Outputs: params.Outputs.Strings(),
1560 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1561 Inputs: params.Inputs.Strings(),
1562 Implicits: params.Implicits.Strings(),
1563 OrderOnly: params.OrderOnly.Strings(),
1564 Args: params.Args,
1565 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001566 }
1567
Colin Cross33bfb0a2016-11-21 17:23:08 -08001568 if params.Depfile != nil {
1569 bparams.Depfile = params.Depfile.String()
1570 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001571 if params.Output != nil {
1572 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1573 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001574 if params.ImplicitOutput != nil {
1575 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1576 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001577 if params.Input != nil {
1578 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1579 }
1580 if params.Implicit != nil {
1581 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1582 }
1583
Colin Cross0b9f31f2019-02-28 11:00:01 -08001584 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1585 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1586 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1587 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1588 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
1589 bparams.Depfile = proptools.NinjaEscapeList([]string{bparams.Depfile})[0]
Colin Crossfe4bc362018-09-12 10:02:13 -07001590
Colin Cross0875c522017-11-28 17:34:01 -08001591 return bparams
1592}
1593
Colin Cross25de6c32019-06-06 14:29:25 -07001594func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1595 if m.config.captureBuild {
1596 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001597 }
1598
Colin Crossdc35e212019-06-06 16:13:11 -07001599 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001600}
1601
Colin Cross25de6c32019-06-06 14:29:25 -07001602func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001603 argNames ...string) blueprint.Rule {
1604
Ramy Medhat944839a2020-03-31 22:14:52 -04001605 if m.config.UseRemoteBuild() {
1606 if params.Pool == nil {
1607 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1608 // jobs to the local parallelism value
1609 params.Pool = localPool
1610 } else if params.Pool == remotePool {
1611 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
1612 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
1613 // parallelism.
1614 params.Pool = nil
1615 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07001616 }
1617
Colin Crossdc35e212019-06-06 16:13:11 -07001618 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001619
Colin Cross25de6c32019-06-06 14:29:25 -07001620 if m.config.captureBuild {
1621 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001622 }
1623
1624 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001625}
1626
Colin Cross25de6c32019-06-06 14:29:25 -07001627func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001628 if params.Description != "" {
1629 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1630 }
1631
1632 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1633 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1634 m.ModuleName(), strings.Join(missingDeps, ", ")))
1635 }
1636
Colin Cross25de6c32019-06-06 14:29:25 -07001637 if m.config.captureBuild {
1638 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001639 }
1640
Colin Crossdc35e212019-06-06 16:13:11 -07001641 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001642}
Colin Crossc3d87d32020-06-04 13:25:17 -07001643
1644func (m *moduleContext) Phony(name string, deps ...Path) {
1645 addPhony(m.config, name, deps...)
1646}
1647
Colin Cross25de6c32019-06-06 14:29:25 -07001648func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001649 var missingDeps []string
1650 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001651 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001652 missingDeps = FirstUniqueStrings(missingDeps)
1653 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001654}
1655
Colin Crossdc35e212019-06-06 16:13:11 -07001656func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001657 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001658 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001659 *missingDeps = append(*missingDeps, deps...)
1660 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001661 }
1662}
1663
Colin Crossdc35e212019-06-06 16:13:11 -07001664func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001665 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001666
1667 if !strict {
1668 return aModule
1669 }
1670
Colin Cross380c69a2019-06-10 17:49:58 +00001671 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001672 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001673 return nil
1674 }
1675
1676 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001677 if b.Config().AllowMissingDependencies() {
1678 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001679 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001680 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001681 }
1682 return nil
1683 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001684 return aModule
1685}
1686
Colin Crossdc35e212019-06-06 16:13:11 -07001687func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001688 type dep struct {
1689 mod blueprint.Module
1690 tag blueprint.DependencyTag
1691 }
1692 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001693 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001694 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001695 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001696 if tag == nil || returnedTag == tag {
1697 deps = append(deps, dep{aModule, returnedTag})
1698 }
1699 }
1700 })
1701 if len(deps) == 1 {
1702 return deps[0].mod, deps[0].tag
1703 } else if len(deps) >= 2 {
1704 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001705 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001706 } else {
1707 return nil, nil
1708 }
1709}
1710
Colin Crossdc35e212019-06-06 16:13:11 -07001711func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001712 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001713 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001714 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001715 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001716 deps = append(deps, aModule)
1717 }
1718 }
1719 })
1720 return deps
1721}
1722
Colin Cross25de6c32019-06-06 14:29:25 -07001723func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1724 module, _ := m.getDirectDepInternal(name, tag)
1725 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001726}
1727
Colin Crossdc35e212019-06-06 16:13:11 -07001728func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1729 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001730}
1731
Colin Crossdc35e212019-06-06 16:13:11 -07001732func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001733 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001734}
1735
Colin Crossdc35e212019-06-06 16:13:11 -07001736func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001737 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001738 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001739 visit(aModule)
1740 }
1741 })
1742}
1743
Colin Crossdc35e212019-06-06 16:13:11 -07001744func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001745 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001746 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001747 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001748 visit(aModule)
1749 }
1750 }
1751 })
1752}
1753
Colin Crossdc35e212019-06-06 16:13:11 -07001754func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001755 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001756 // pred
1757 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001758 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001759 return pred(aModule)
1760 } else {
1761 return false
1762 }
1763 },
1764 // visit
1765 func(module blueprint.Module) {
1766 visit(module.(Module))
1767 })
1768}
1769
Colin Crossdc35e212019-06-06 16:13:11 -07001770func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001771 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001772 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001773 visit(aModule)
1774 }
1775 })
1776}
1777
Colin Crossdc35e212019-06-06 16:13:11 -07001778func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001779 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001780 // pred
1781 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001782 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001783 return pred(aModule)
1784 } else {
1785 return false
1786 }
1787 },
1788 // visit
1789 func(module blueprint.Module) {
1790 visit(module.(Module))
1791 })
1792}
1793
Colin Crossdc35e212019-06-06 16:13:11 -07001794func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001795 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001796}
1797
Colin Crossdc35e212019-06-06 16:13:11 -07001798func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
1799 b.walkPath = []Module{b.Module()}
Paul Duffinc5192442020-03-31 11:31:36 +01001800 b.tagPath = []blueprint.DependencyTag{}
Colin Cross1184b642019-12-30 18:43:07 -08001801 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001802 childAndroidModule, _ := child.(Module)
1803 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07001804 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001805 // record walkPath before visit
1806 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
1807 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
Paul Duffinc5192442020-03-31 11:31:36 +01001808 b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
Colin Crossdc35e212019-06-06 16:13:11 -07001809 }
1810 b.walkPath = append(b.walkPath, childAndroidModule)
Paul Duffinc5192442020-03-31 11:31:36 +01001811 b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07001812 return visit(childAndroidModule, parentAndroidModule)
1813 } else {
1814 return false
1815 }
1816 })
1817}
1818
Colin Crossdc35e212019-06-06 16:13:11 -07001819func (b *baseModuleContext) GetWalkPath() []Module {
1820 return b.walkPath
1821}
1822
Paul Duffinc5192442020-03-31 11:31:36 +01001823func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
1824 return b.tagPath
1825}
1826
Jiyong Park1c7e9622020-05-07 16:12:13 +09001827// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
1828// a dependency tag.
1829var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:blueprint.BaseDependencyTag{}\E(, )?`)
1830
1831// PrettyPrintTag returns string representation of the tag, but prefers
1832// custom String() method if available.
1833func PrettyPrintTag(tag blueprint.DependencyTag) string {
1834 // Use tag's custom String() method if available.
1835 if stringer, ok := tag.(fmt.Stringer); ok {
1836 return stringer.String()
1837 }
1838
1839 // Otherwise, get a default string representation of the tag's struct.
1840 tagString := fmt.Sprintf("%#v", tag)
1841
1842 // Remove the boilerplate from BaseDependencyTag as it adds no value.
1843 tagString = tagCleaner.ReplaceAllString(tagString, "")
1844 return tagString
1845}
1846
1847func (b *baseModuleContext) GetPathString(skipFirst bool) string {
1848 sb := strings.Builder{}
1849 tagPath := b.GetTagPath()
1850 walkPath := b.GetWalkPath()
1851 if !skipFirst {
1852 sb.WriteString(walkPath[0].String())
1853 }
1854 for i, m := range walkPath[1:] {
1855 sb.WriteString("\n")
1856 sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
1857 sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
1858 }
1859 return sb.String()
1860}
1861
Colin Cross25de6c32019-06-06 14:29:25 -07001862func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
Colin Crossdc35e212019-06-06 16:13:11 -07001863 m.bp.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross0875c522017-11-28 17:34:01 -08001864 visit(module.(Module))
1865 })
1866}
1867
Colin Cross25de6c32019-06-06 14:29:25 -07001868func (m *moduleContext) PrimaryModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001869 return m.bp.PrimaryModule().(Module)
Colin Cross0875c522017-11-28 17:34:01 -08001870}
1871
Colin Cross25de6c32019-06-06 14:29:25 -07001872func (m *moduleContext) FinalModule() Module {
Colin Crossdc35e212019-06-06 16:13:11 -07001873 return m.bp.FinalModule().(Module)
1874}
1875
1876func (m *moduleContext) ModuleSubDir() string {
1877 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08001878}
1879
Colin Cross0ea8ba82019-06-06 14:33:29 -07001880func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001881 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07001882}
1883
Colin Cross0ea8ba82019-06-06 14:33:29 -07001884func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001885 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001886}
1887
Colin Cross0ea8ba82019-06-06 14:33:29 -07001888func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07001889 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001890}
1891
Colin Cross0ea8ba82019-06-06 14:33:29 -07001892func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07001893 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08001894}
1895
Colin Cross0ea8ba82019-06-06 14:33:29 -07001896func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001897 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08001898}
1899
Colin Cross0ea8ba82019-06-06 14:33:29 -07001900func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001901 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07001902}
1903
Colin Cross0ea8ba82019-06-06 14:33:29 -07001904func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001905 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07001906}
1907
Colin Cross0ea8ba82019-06-06 14:33:29 -07001908func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001909 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07001910}
1911
Colin Cross0ea8ba82019-06-06 14:33:29 -07001912func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001913 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08001914}
1915
Colin Cross0ea8ba82019-06-06 14:33:29 -07001916func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08001917 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07001918}
1919
Colin Cross0ea8ba82019-06-06 14:33:29 -07001920func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001921 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07001922}
1923
Colin Cross0ea8ba82019-06-06 14:33:29 -07001924func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001925 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07001926 return true
1927 }
Colin Cross25de6c32019-06-06 14:29:25 -07001928 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07001929}
1930
Jiyong Park5baac542018-08-28 09:55:37 +09001931// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09001932// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07001933func (m *ModuleBase) MakeAsPlatform() {
1934 m.commonProperties.Vendor = boolPtr(false)
1935 m.commonProperties.Proprietary = boolPtr(false)
1936 m.commonProperties.Soc_specific = boolPtr(false)
1937 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09001938 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09001939}
1940
Colin Cross4157e882019-06-06 16:57:04 -07001941func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
1942 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02001943}
1944
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001945func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09001946 m.commonProperties.Vendor = boolPtr(false)
1947 m.commonProperties.Proprietary = boolPtr(false)
1948 m.commonProperties.Soc_specific = boolPtr(false)
1949 m.commonProperties.Product_specific = boolPtr(false)
1950 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09001951}
1952
Jooyung Han344d5432019-08-23 11:17:39 +09001953// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
1954func (m *ModuleBase) IsNativeBridgeSupported() bool {
1955 return proptools.Bool(m.commonProperties.Native_bridge_supported)
1956}
1957
Colin Cross25de6c32019-06-06 14:29:25 -07001958func (m *moduleContext) InstallInData() bool {
1959 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08001960}
1961
Jaewoong Jung0949f312019-09-11 10:25:18 -07001962func (m *moduleContext) InstallInTestcases() bool {
1963 return m.module.InstallInTestcases()
1964}
1965
Colin Cross25de6c32019-06-06 14:29:25 -07001966func (m *moduleContext) InstallInSanitizerDir() bool {
1967 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001968}
1969
Yifan Hong1b3348d2020-01-21 15:53:22 -08001970func (m *moduleContext) InstallInRamdisk() bool {
1971 return m.module.InstallInRamdisk()
1972}
1973
Colin Cross25de6c32019-06-06 14:29:25 -07001974func (m *moduleContext) InstallInRecovery() bool {
1975 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001976}
1977
Colin Cross90ba5f42019-10-02 11:10:58 -07001978func (m *moduleContext) InstallInRoot() bool {
1979 return m.module.InstallInRoot()
1980}
1981
Colin Cross607d8582019-07-29 16:44:46 -07001982func (m *moduleContext) InstallBypassMake() bool {
1983 return m.module.InstallBypassMake()
1984}
1985
Colin Cross6e359402020-02-10 15:29:54 -08001986func (m *moduleContext) InstallForceOS() *OsType {
1987 return m.module.InstallForceOS()
1988}
1989
Colin Cross70dda7e2019-10-01 22:05:35 -07001990func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07001991 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07001992 return true
1993 }
1994
Colin Cross3607f212018-05-07 15:28:05 -07001995 // We'll need a solution for choosing which of modules with the same name in different
1996 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
1997 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07001998 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07001999 return true
2000 }
2001
Colin Cross25de6c32019-06-06 14:29:25 -07002002 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07002003 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07002004 return true
2005 }
2006
Colin Cross25de6c32019-06-06 14:29:25 -07002007 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07002008 return true
2009 }
2010 }
2011
2012 return false
2013}
2014
Colin Cross70dda7e2019-10-01 22:05:35 -07002015func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
2016 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002017 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07002018}
2019
Colin Cross70dda7e2019-10-01 22:05:35 -07002020func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
2021 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002022 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07002023}
2024
Colin Cross70dda7e2019-10-01 22:05:35 -07002025func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
2026 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07002027
Colin Cross25de6c32019-06-06 14:29:25 -07002028 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002029 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08002030
Colin Cross25de6c32019-06-06 14:29:25 -07002031 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07002032
Colin Cross897266e2020-02-13 13:22:08 -08002033 deps = append(deps, m.installDeps.Paths()...)
Colin Cross35cec122015-04-02 14:37:16 -07002034
Colin Cross89562dc2016-10-03 17:47:19 -07002035 var implicitDeps, orderOnlyDeps Paths
2036
Colin Cross25de6c32019-06-06 14:29:25 -07002037 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07002038 // Installed host modules might be used during the build, depend directly on their
2039 // dependencies so their timestamp is updated whenever their dependency is updated
2040 implicitDeps = deps
2041 } else {
2042 orderOnlyDeps = deps
2043 }
2044
Colin Cross25de6c32019-06-06 14:29:25 -07002045 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07002046 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07002047 Description: "install " + fullInstallPath.Base(),
2048 Output: fullInstallPath,
2049 Input: srcPath,
2050 Implicits: implicitDeps,
2051 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07002052 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08002053 })
Colin Cross3f40fa42015-01-30 17:27:36 -08002054
Colin Cross25de6c32019-06-06 14:29:25 -07002055 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08002056 }
Colin Cross25de6c32019-06-06 14:29:25 -07002057 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07002058 return fullInstallPath
2059}
2060
Colin Cross70dda7e2019-10-01 22:05:35 -07002061func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002062 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002063 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08002064
Colin Cross25de6c32019-06-06 14:29:25 -07002065 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07002066
Alex Lightfb4353d2019-01-17 13:57:45 -08002067 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
2068 if err != nil {
2069 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
2070 }
Colin Cross25de6c32019-06-06 14:29:25 -07002071 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07002072 Rule: Symlink,
2073 Description: "install symlink " + fullInstallPath.Base(),
2074 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08002075 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07002076 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08002077 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08002078 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08002079 },
2080 })
Colin Cross3854a602016-01-11 12:49:11 -08002081
Colin Cross25de6c32019-06-06 14:29:25 -07002082 m.installFiles = append(m.installFiles, fullInstallPath)
2083 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08002084 }
Colin Cross3854a602016-01-11 12:49:11 -08002085 return fullInstallPath
2086}
2087
Jiyong Parkf1194352019-02-25 11:05:47 +09002088// installPath/name -> absPath where absPath might be a path that is available only at runtime
2089// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07002090func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002091 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002092 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09002093
Colin Cross25de6c32019-06-06 14:29:25 -07002094 if !m.skipInstall(fullInstallPath) {
2095 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09002096 Rule: Symlink,
2097 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
2098 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07002099 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09002100 Args: map[string]string{
2101 "fromPath": absPath,
2102 },
2103 })
2104
Colin Cross25de6c32019-06-06 14:29:25 -07002105 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09002106 }
2107 return fullInstallPath
2108}
2109
Colin Cross25de6c32019-06-06 14:29:25 -07002110func (m *moduleContext) CheckbuildFile(srcPath Path) {
2111 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08002112}
2113
Colin Cross41955e82019-05-29 14:40:35 -07002114// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
2115// was not a module reference.
2116func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08002117 if len(s) > 1 && s[0] == ':' {
2118 return s[1:]
2119 }
2120 return ""
2121}
2122
Colin Cross41955e82019-05-29 14:40:35 -07002123// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
2124// module name and an empty string for the tag, or empty strings if the input was not a module reference.
2125func SrcIsModuleWithTag(s string) (module, tag string) {
2126 if len(s) > 1 && s[0] == ':' {
2127 module = s[1:]
2128 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2129 if module[len(module)-1] == '}' {
2130 tag = module[tagStart+1 : len(module)-1]
2131 module = module[:tagStart]
2132 return module, tag
2133 }
2134 }
2135 return module, ""
2136 }
2137 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08002138}
2139
Colin Cross41955e82019-05-29 14:40:35 -07002140type sourceOrOutputDependencyTag struct {
2141 blueprint.BaseDependencyTag
2142 tag string
2143}
2144
2145func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
2146 return sourceOrOutputDependencyTag{tag: tag}
2147}
2148
2149var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08002150
Colin Cross366938f2017-12-11 16:29:02 -08002151// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
2152// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002153//
2154// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08002155func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07002156 set := make(map[string]bool)
2157
Colin Cross068e0fe2016-12-13 15:23:47 -08002158 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07002159 if m, t := SrcIsModuleWithTag(s); m != "" {
2160 if _, found := set[s]; found {
2161 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07002162 } else {
Colin Cross41955e82019-05-29 14:40:35 -07002163 set[s] = true
2164 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07002165 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002166 }
2167 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002168}
2169
Colin Cross366938f2017-12-11 16:29:02 -08002170// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
2171// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002172//
2173// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08002174func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
2175 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07002176 if m, t := SrcIsModuleWithTag(*s); m != "" {
2177 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08002178 }
2179 }
2180}
2181
Colin Cross41955e82019-05-29 14:40:35 -07002182// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
2183// 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 -08002184type SourceFileProducer interface {
2185 Srcs() Paths
2186}
2187
Colin Cross41955e82019-05-29 14:40:35 -07002188// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002189// using the ":module" syntax or ":module{.tag}" syntax and provides a list of output files to be used as if they were
Colin Cross41955e82019-05-29 14:40:35 -07002190// listed in the property.
2191type OutputFileProducer interface {
2192 OutputFiles(tag string) (Paths, error)
2193}
2194
Colin Cross5e708052019-08-06 13:59:50 -07002195// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2196// module produced zero paths, it reports errors to the ctx and returns nil.
2197func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2198 paths, err := outputFilesForModule(ctx, module, tag)
2199 if err != nil {
2200 reportPathError(ctx, err)
2201 return nil
2202 }
2203 return paths
2204}
2205
2206// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2207// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2208func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2209 paths, err := outputFilesForModule(ctx, module, tag)
2210 if err != nil {
2211 reportPathError(ctx, err)
2212 return nil
2213 }
2214 if len(paths) > 1 {
2215 reportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
2216 pathContextName(ctx, module))
2217 return nil
2218 }
2219 return paths[0]
2220}
2221
2222func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2223 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2224 paths, err := outputFileProducer.OutputFiles(tag)
2225 if err != nil {
2226 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2227 pathContextName(ctx, module), err.Error())
2228 }
2229 if len(paths) == 0 {
2230 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2231 }
2232 return paths, nil
2233 } else {
2234 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2235 }
2236}
2237
Colin Crossfe17f6f2019-03-28 19:30:56 -07002238type HostToolProvider interface {
2239 HostToolPath() OptionalPath
2240}
2241
Colin Cross27b922f2019-03-04 22:35:41 -08002242// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2243// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002244//
2245// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002246func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2247 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002248}
2249
Colin Cross2fafa3e2019-03-05 12:39:51 -08002250// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2251// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002252//
2253// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002254func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2255 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002256}
2257
2258// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2259// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2260// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002261func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002262 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002263 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002264 }
2265 return OptionalPath{}
2266}
2267
Colin Cross25de6c32019-06-06 14:29:25 -07002268func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002269 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002270}
2271
Colin Cross25de6c32019-06-06 14:29:25 -07002272func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002273 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002274}
2275
Colin Cross25de6c32019-06-06 14:29:25 -07002276func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002277 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002278}
2279
Colin Cross463a90e2015-06-17 14:20:06 -07002280func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002281 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002282}
2283
Colin Cross0875c522017-11-28 17:34:01 -08002284func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002285 return &buildTargetSingleton{}
2286}
2287
Colin Cross87d8b562017-04-25 10:01:55 -07002288func parentDir(dir string) string {
2289 dir, _ = filepath.Split(dir)
2290 return filepath.Clean(dir)
2291}
2292
Colin Cross1f8c52b2015-06-16 16:38:17 -07002293type buildTargetSingleton struct{}
2294
Colin Cross0875c522017-11-28 17:34:01 -08002295func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2296 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002297
Colin Crossc3d87d32020-06-04 13:25:17 -07002298 mmTarget := func(dir string) string {
2299 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07002300 }
2301
Colin Cross0875c522017-11-28 17:34:01 -08002302 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002303
Colin Cross0875c522017-11-28 17:34:01 -08002304 ctx.VisitAllModules(func(module Module) {
2305 blueprintDir := module.base().blueprintDir
2306 installTarget := module.base().installTarget
2307 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002308
Colin Cross0875c522017-11-28 17:34:01 -08002309 if checkbuildTarget != nil {
2310 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2311 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2312 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002313
Colin Cross0875c522017-11-28 17:34:01 -08002314 if installTarget != nil {
2315 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002316 }
2317 })
2318
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002319 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002320 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002321 suffix = "-soong"
2322 }
2323
Colin Cross1f8c52b2015-06-16 16:38:17 -07002324 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07002325 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002326
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002327 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002328 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002329 return
2330 }
2331
Colin Cross87d8b562017-04-25 10:01:55 -07002332 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002333 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002334 for _, dir := range dirs {
2335 dir := parentDir(dir)
2336 for dir != "." && dir != "/" {
2337 if _, exists := modulesInDir[dir]; exists {
2338 break
2339 }
2340 modulesInDir[dir] = nil
2341 dir = parentDir(dir)
2342 }
2343 }
2344
2345 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002346 for _, dir := range dirs {
2347 p := parentDir(dir)
2348 if p != "." && p != "/" {
Colin Crossc3d87d32020-06-04 13:25:17 -07002349 modulesInDir[p] = append(modulesInDir[p], PathForPhony(ctx, mmTarget(dir)))
Colin Cross87d8b562017-04-25 10:01:55 -07002350 }
2351 }
2352
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002353 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2354 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2355 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002356 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07002357 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002358 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002359
2360 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2361 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002362 ctx.VisitAllModules(func(module Module) {
2363 if module.Enabled() {
2364 os := module.Target().Os
2365 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002366 }
2367 })
2368
Colin Cross0875c522017-11-28 17:34:01 -08002369 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002370 for os, deps := range osDeps {
2371 var className string
2372
2373 switch os.Class {
2374 case Host:
2375 className = "host"
2376 case HostCross:
2377 className = "host-cross"
2378 case Device:
2379 className = "target"
2380 default:
2381 continue
2382 }
2383
Colin Crossc3d87d32020-06-04 13:25:17 -07002384 name := className + "-" + os.Name
2385 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07002386
Colin Crossc3d87d32020-06-04 13:25:17 -07002387 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002388 }
2389
2390 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002391 for _, class := range SortedStringKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07002392 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002393 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002394}
Colin Crossd779da42015-12-17 18:00:23 -08002395
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002396// Collect information for opening IDE project files in java/jdeps.go.
2397type IDEInfo interface {
2398 IDEInfo(ideInfo *IdeInfo)
2399 BaseModuleName() string
2400}
2401
2402// Extract the base module name from the Import name.
2403// Often the Import name has a prefix "prebuilt_".
2404// Remove the prefix explicitly if needed
2405// until we find a better solution to get the Import name.
2406type IDECustomizedModuleName interface {
2407 IDECustomizedModuleName() string
2408}
2409
2410type IdeInfo struct {
2411 Deps []string `json:"dependencies,omitempty"`
2412 Srcs []string `json:"srcs,omitempty"`
2413 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2414 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2415 Jars []string `json:"jars,omitempty"`
2416 Classes []string `json:"class,omitempty"`
2417 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002418 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08002419 Paths []string `json:"path,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002420}
Paul Duffinf88d8e02020-05-07 20:21:34 +01002421
2422func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
2423 bpctx := ctx.blueprintBaseModuleContext()
2424 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
2425}