blob: 8334cc69f5d822259dc9eb241c19ad62e4584934 [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 (
Jingwen Chen73850672020-12-14 08:25:34 -050018 "android/soong/bazel"
Colin Cross6ff51382015-12-17 16:39:19 -080019 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000020 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080021 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080022 "path/filepath"
Jiyong Park1c7e9622020-05-07 16:12:13 +090023 "regexp"
Colin Cross6ff51382015-12-17 16:39:19 -080024 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080025 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070026
27 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070028 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080029)
30
31var (
32 DeviceSharedLibrary = "shared_library"
33 DeviceStaticLibrary = "static_library"
34 DeviceExecutable = "executable"
35 HostSharedLibrary = "host_shared_library"
36 HostStaticLibrary = "host_static_library"
37 HostExecutable = "host_executable"
38)
39
Colin Crossae887032017-10-23 17:16:14 -070040type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070041 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080042 Deps blueprint.Deps
43 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070044 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070045 Output WritablePath
46 Outputs WritablePaths
Jingwen Chence679d22020-09-23 04:30:02 +000047 SymlinkOutput WritablePath
48 SymlinkOutputs WritablePaths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070049 ImplicitOutput WritablePath
50 ImplicitOutputs WritablePaths
51 Input Path
52 Inputs Paths
53 Implicit Path
54 Implicits Paths
55 OrderOnly Paths
Colin Cross824f1162020-07-16 13:07:51 -070056 Validation Path
57 Validations Paths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070058 Default bool
59 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070060}
61
Colin Crossae887032017-10-23 17:16:14 -070062type ModuleBuildParams BuildParams
63
Colin Cross1184b642019-12-30 18:43:07 -080064// EarlyModuleContext provides methods that can be called early, as soon as the properties have
65// been parsed into the module and before any mutators have run.
66type EarlyModuleContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -070067 // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
68 // reference to itself.
Colin Cross1184b642019-12-30 18:43:07 -080069 Module() Module
Colin Cross9f35c3d2020-09-16 19:04:41 -070070
71 // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
72 // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
Colin Cross1184b642019-12-30 18:43:07 -080073 ModuleName() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070074
75 // ModuleDir returns the path to the directory that contains the definition of the module.
Colin Cross1184b642019-12-30 18:43:07 -080076 ModuleDir() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070077
78 // ModuleType returns the name of the module type that was used to create the module, as specified in
79 // RegisterModuleType.
Colin Cross1184b642019-12-30 18:43:07 -080080 ModuleType() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070081
82 // BlueprintFile returns the name of the blueprint file that contains the definition of this
83 // module.
Colin Cross9d34f352019-11-22 16:03:51 -080084 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080085
Colin Cross9f35c3d2020-09-16 19:04:41 -070086 // ContainsProperty returns true if the specified property name was set in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080087 ContainsProperty(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -070088
89 // Errorf reports an error at the specified position of the module definition file.
Colin Cross1184b642019-12-30 18:43:07 -080090 Errorf(pos scanner.Position, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070091
92 // ModuleErrorf reports an error at the line number of the module type in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080093 ModuleErrorf(fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070094
95 // PropertyErrorf reports an error at the line number of a property in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080096 PropertyErrorf(property, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070097
98 // Failed returns true if any errors have been reported. In most cases the module can continue with generating
99 // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
100 // has prevented the module from creating necessary data it can return early when Failed returns true.
Colin Cross1184b642019-12-30 18:43:07 -0800101 Failed() bool
102
Colin Cross9f35c3d2020-09-16 19:04:41 -0700103 // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
104 // primary builder will be rerun whenever the specified files are modified.
Colin Cross1184b642019-12-30 18:43:07 -0800105 AddNinjaFileDeps(deps ...string)
106
107 DeviceSpecific() bool
108 SocSpecific() bool
109 ProductSpecific() bool
110 SystemExtSpecific() bool
111 Platform() bool
112
113 Config() Config
114 DeviceConfig() DeviceConfig
115
116 // Deprecated: use Config()
117 AConfig() Config
118
119 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
120 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
121 // builder whenever a file matching the pattern as added or removed, without rerunning if a
122 // file that does not match the pattern is added to a searched directory.
123 GlobWithDeps(pattern string, excludes []string) ([]string, error)
124
125 Glob(globPattern string, excludes []string) Paths
126 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +0000127 IsSymlink(path Path) bool
128 Readlink(path Path) string
Colin Cross133ebef2020-08-14 17:38:45 -0700129
Colin Cross9f35c3d2020-09-16 19:04:41 -0700130 // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
131 // default SimpleNameInterface if Context.SetNameInterface was not called.
Colin Cross133ebef2020-08-14 17:38:45 -0700132 Namespace() *Namespace
Colin Cross1184b642019-12-30 18:43:07 -0800133}
134
Colin Cross0ea8ba82019-06-06 14:33:29 -0700135// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700136// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
137// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700138// about the current module.
139type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800140 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700141
Paul Duffinf88d8e02020-05-07 20:21:34 +0100142 blueprintBaseModuleContext() blueprint.BaseModuleContext
143
Colin Cross9f35c3d2020-09-16 19:04:41 -0700144 // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
145 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700146 OtherModuleName(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700147
148 // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
149 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700150 OtherModuleDir(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700151
152 // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
153 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700154 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -0700155
156 // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
157 // on the module. When called inside a Visit* method with current module being visited, and there are multiple
158 // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
Colin Crossdc35e212019-06-06 16:13:11 -0700159 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
Colin Cross9f35c3d2020-09-16 19:04:41 -0700160
161 // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
162 // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
Colin Crossdc35e212019-06-06 16:13:11 -0700163 OtherModuleExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700164
165 // OtherModuleDependencyVariantExists returns true if a module with the
166 // specified name and variant exists. The variant must match the given
167 // variations. It must also match all the non-local variations of the current
Martin Stjernholm408ffd82021-05-05 15:27:31 +0100168 // module. In other words, it checks for the module that AddVariationDependencies
Colin Cross9f35c3d2020-09-16 19:04:41 -0700169 // would add a dependency on with the same arguments.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000170 OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700171
Martin Stjernholm408ffd82021-05-05 15:27:31 +0100172 // OtherModuleFarDependencyVariantExists returns true if a module with the
173 // specified name and variant exists. The variant must match the given
174 // variations, but not the non-local variations of the current module. In
175 // other words, it checks for the module that AddFarVariationDependencies
176 // would add a dependency on with the same arguments.
177 OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool
178
Colin Cross9f35c3d2020-09-16 19:04:41 -0700179 // OtherModuleReverseDependencyVariantExists returns true if a module with the
180 // specified name exists with the same variations as the current module. In
Martin Stjernholm408ffd82021-05-05 15:27:31 +0100181 // other words, it checks for the module that AddReverseDependency would add a
Colin Cross9f35c3d2020-09-16 19:04:41 -0700182 // dependency on with the same argument.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000183 OtherModuleReverseDependencyVariantExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700184
185 // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
186 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Jiyong Park9e6c2422019-08-09 20:39:45 +0900187 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700188
Colin Crossd27e7b82020-07-02 11:38:17 -0700189 // OtherModuleProvider returns the value for a provider for the given module. If the value is
190 // not set it returns the zero value of the type of the provider, so the return value can always
191 // be type asserted to the type of the provider. The value returned may be a deep copy of the
192 // value originally passed to SetProvider.
193 OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
194
195 // OtherModuleHasProvider returns true if the provider for the given module has been set.
196 OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
197
198 // Provider returns the value for a provider for the current module. If the value is
199 // not set it returns the zero value of the type of the provider, so the return value can always
200 // be type asserted to the type of the provider. It panics if called before the appropriate
201 // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
202 // copy of the value originally passed to SetProvider.
203 Provider(provider blueprint.ProviderKey) interface{}
204
205 // HasProvider returns true if the provider for the current module has been set.
206 HasProvider(provider blueprint.ProviderKey) bool
207
208 // SetProvider sets the value for a provider for the current module. It panics if not called
209 // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
210 // is not of the appropriate type, or if the value has already been set. The value should not
211 // be modified after being passed to SetProvider.
212 SetProvider(provider blueprint.ProviderKey, value interface{})
213
Colin Crossdc35e212019-06-06 16:13:11 -0700214 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700215
216 // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
217 // none exists. It panics if the dependency does not have the specified tag. It skips any
218 // dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700219 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700220
221 // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
222 // name, or nil if none exists. If there are multiple dependencies on the same module it returns
Liz Kammer2b50ce62021-04-26 15:47:28 -0400223 // the first DependencyTag.
Colin Crossdc35e212019-06-06 16:13:11 -0700224 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
225
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400226 ModuleFromName(name string) (blueprint.Module, bool)
227
Colin Cross9f35c3d2020-09-16 19:04:41 -0700228 // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
229 // direct dependencies on the same module visit will be called multiple times on that module
230 // and OtherModuleDependencyTag will return a different tag for each.
231 //
232 // The Module passed to the visit function should not be retained outside of the visit
233 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700234 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700235
236 // VisitDirectDeps calls visit for each direct dependency. If there are multiple
237 // direct dependencies on the same module visit will be called multiple times on that module
Spandan Dasda7f3622021-08-04 20:50:04 +0000238 // and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the
239 // dependencies are not an android.Module.
Colin Cross9f35c3d2020-09-16 19:04:41 -0700240 //
241 // The Module passed to the visit function should not be retained outside of the visit
242 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700243 VisitDirectDeps(visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700244
Colin Crossdc35e212019-06-06 16:13:11 -0700245 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700246
247 // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
248 // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
249 // OtherModuleDependencyTag will return a different tag for each. It skips any
250 // dependencies that are not an android.Module.
251 //
252 // The Module passed to the visit function should not be retained outside of the visit function, it may be
253 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700254 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
255 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
256 VisitDepsDepthFirst(visit func(Module))
257 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
258 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700259
260 // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
261 // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
262 // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
263 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
264 // any dependencies that are not an android.Module.
265 //
266 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
267 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700268 WalkDeps(visit func(Module, Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700269
270 // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
271 // tree in top down order. visit may be called multiple times for the same (child, parent)
272 // pair if there are multiple direct dependencies between the child and parent with different
273 // tags. OtherModuleDependencyTag will return the tag for the currently visited
274 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
275 // to child.
276 //
277 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
278 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700279 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700280
Colin Crossdc35e212019-06-06 16:13:11 -0700281 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
282 // and returns a top-down dependency path from a start module to current child module.
283 GetWalkPath() []Module
284
Colin Cross4dfacf92020-09-16 19:22:27 -0700285 // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
286 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
287 // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
288 // only done once for all variants of a module.
289 PrimaryModule() Module
290
291 // FinalModule returns the last variant of the current module. Variants of a module are always visited in
292 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
293 // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
294 // singleton actions that are only done once for all variants of a module.
295 FinalModule() Module
296
297 // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
298 // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
299 // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
300 // data modified by the current mutator.
301 VisitAllModuleVariants(visit func(Module))
302
Paul Duffinc5192442020-03-31 11:31:36 +0100303 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
304 // and returns a top-down dependency tags path from a start module to current child module.
305 // It has one less entry than GetWalkPath() as it contains the dependency tags that
306 // exist between each adjacent pair of modules in the GetWalkPath().
307 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
308 GetTagPath() []blueprint.DependencyTag
309
Jiyong Park1c7e9622020-05-07 16:12:13 +0900310 // GetPathString is supposed to be called in visit function passed in WalkDeps()
311 // and returns a multi-line string showing the modules and dependency tags
312 // among them along the top-down dependency path from a start module to current child module.
313 // skipFirst when set to true, the output doesn't include the start module,
314 // which is already printed when this function is used along with ModuleErrorf().
315 GetPathString(skipFirst bool) string
316
Colin Crossdc35e212019-06-06 16:13:11 -0700317 AddMissingDependencies(missingDeps []string)
318
Colin Crossa1ad8d12016-06-01 17:09:44 -0700319 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700320 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000321
322 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
323 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700324 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700325 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700326 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700327 Host() bool
328 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700329 Darwin() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700330 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700331 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700332 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700333}
334
Colin Cross1184b642019-12-30 18:43:07 -0800335// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700336type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800337 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800338}
339
Colin Cross635c3b02016-05-18 15:37:25 -0700340type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800341 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800342
Colin Crossc20dc852020-11-10 12:27:45 -0800343 blueprintModuleContext() blueprint.ModuleContext
344
Colin Crossae887032017-10-23 17:16:14 -0700345 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800346 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700347
Paul Duffind5cf92e2021-07-09 17:38:55 +0100348 // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
349 // be tagged with `android:"path" to support automatic source module dependency resolution.
350 //
351 // Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700352 ExpandSources(srcFiles, excludes []string) Paths
Paul Duffind5cf92e2021-07-09 17:38:55 +0100353
354 // Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
355 // be tagged with `android:"path" to support automatic source module dependency resolution.
356 //
357 // Deprecated: use PathForModuleSrc instead.
Colin Cross366938f2017-12-11 16:29:02 -0800358 ExpandSource(srcFile, prop string) Path
Paul Duffind5cf92e2021-07-09 17:38:55 +0100359
Colin Cross2383f3b2018-02-06 14:40:13 -0800360 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700361
Colin Cross41589502020-12-01 14:00:21 -0800362 // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
363 // with the given additional dependencies. The file is marked executable after copying.
364 //
365 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
366 // installed file will be returned by PackagingSpecs() on this module or by
367 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
368 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700369 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800370
371 // InstallFile creates a rule to copy srcPath to name in the installPath directory,
372 // with the given additional dependencies.
373 //
374 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
375 // installed file will be returned by PackagingSpecs() on this module or by
376 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
377 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700378 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800379
380 // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
381 // directory.
382 //
383 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
384 // installed file will be returned by PackagingSpecs() on this module or by
385 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
386 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700387 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800388
389 // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
390 // in the installPath directory.
391 //
392 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
393 // installed file will be returned by PackagingSpecs() on this module or by
394 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
395 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700396 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800397
398 // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
399 // the rule to copy the file. This is useful to define how a module would be packaged
400 // without installing it into the global installation directories.
401 //
402 // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by
403 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
404 // for which IsInstallDepNeeded returns true.
405 PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
406
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700407 CheckbuildFile(srcPath Path)
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -0700408 TidyFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800409
Colin Cross8d8f8e22016-08-03 11:57:50 -0700410 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700411 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700412 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800413 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700414 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900415 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900416 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700417 InstallInRoot() bool
Kiyoung Kimae11c232021-07-19 11:38:04 +0900418 InstallInVendor() bool
Colin Cross607d8582019-07-29 16:44:46 -0700419 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900420 InstallForceOS() (*OsType, *ArchType)
Nan Zhang6d34b302017-02-04 17:47:46 -0800421
422 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700423 HostRequiredModuleNames() []string
424 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700425
Colin Cross3f68a132017-10-23 17:10:29 -0700426 ModuleSubDir() string
427
Colin Cross0875c522017-11-28 17:34:01 -0800428 Variable(pctx PackageContext, name, value string)
429 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700430 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
431 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800432 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700433 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
434 // phony rules or real files. Phony can be called on the same name multiple times to add
435 // additional dependencies.
436 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700437
Colin Cross9f35c3d2020-09-16 19:04:41 -0700438 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
439 // but do not exist.
Colin Cross3f68a132017-10-23 17:10:29 -0700440 GetMissingDependencies() []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800441}
442
Colin Cross635c3b02016-05-18 15:37:25 -0700443type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800444 blueprint.Module
445
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700446 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
447 // but GenerateAndroidBuildActions also has access to Android-specific information.
448 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700449 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700450
Paul Duffin44f1d842020-06-26 20:17:02 +0100451 // Add dependencies to the components of a module, i.e. modules that are created
452 // by the module and which are considered to be part of the creating module.
453 //
454 // This is called before prebuilts are renamed so as to allow a dependency to be
455 // added directly to a prebuilt child module instead of depending on a source module
456 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
457 //
458 // A dependency on a prebuilt must include the "prebuilt_" prefix.
459 ComponentDepsMutator(ctx BottomUpMutatorContext)
460
Colin Cross1e676be2016-10-12 14:38:15 -0700461 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800462
Colin Cross635c3b02016-05-18 15:37:25 -0700463 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900464 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800465 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700466 Target() Target
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000467 MultiTargets() []Target
Anton Hansson1ee62c02020-06-30 11:51:53 +0100468 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -0800469 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700470 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700471 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800472 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700473 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900474 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900475 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700476 InstallInRoot() bool
Kiyoung Kimae11c232021-07-19 11:38:04 +0900477 InstallInVendor() bool
Colin Cross607d8582019-07-29 16:44:46 -0700478 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900479 InstallForceOS() (*OsType, *ArchType)
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800480 HideFromMake()
481 IsHideFromMake() bool
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +0000482 IsSkipInstall() bool
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100483 MakeUninstallable()
Liz Kammer5ca3a622020-08-05 15:40:41 -0700484 ReplacedByPrebuilt()
485 IsReplacedByPrebuilt() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900486 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900487 InitRc() Paths
488 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800489 NoticeFiles() Paths
Justin Yun885a7de2021-06-29 20:34:53 +0900490 EffectiveLicenseFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700491
492 AddProperties(props ...interface{})
493 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700494
Liz Kammer2ada09a2021-08-11 00:17:36 -0400495 // IsConvertedByBp2build returns whether this module was converted via bp2build
496 IsConvertedByBp2build() bool
497 // Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module
498 Bp2buildTargets() []bp2buildInfo
499
Colin Crossae887032017-10-23 17:16:14 -0700500 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800501 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800502 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100503
Colin Cross9a362232019-07-01 15:32:45 -0700504 // String returns a string that includes the module name and variants for printing during debugging.
505 String() string
506
Paul Duffine2453c72019-05-31 14:00:04 +0100507 // Get the qualified module id for this module.
508 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
509
510 // Get information about the properties that can contain visibility rules.
511 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100512
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900513 RequiredModuleNames() []string
514 HostRequiredModuleNames() []string
515 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800516
Jiyong Park4dc2a1a2020-09-28 17:46:22 +0900517 FilesToInstall() InstallPaths
Jiyong Park073ea552020-11-09 14:08:34 +0900518 PackagingSpecs() []PackagingSpec
Colin Crossffe6b9d2020-12-01 15:40:06 -0800519
520 // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
521 // dependencies with dependency tags for which IsInstallDepNeeded() returns true.
522 TransitivePackagingSpecs() []PackagingSpec
Paul Duffine2453c72019-05-31 14:00:04 +0100523}
524
Jingwen Chenab60f122021-01-24 21:21:45 -0500525// BazelTargetModule is a lightweight wrapper interface around Module for
526// bp2build conversion purposes.
527//
528// In bp2build's bootstrap.Main execution, Soong runs an alternate pipeline of
529// mutators that creates BazelTargetModules from regular Module objects,
530// performing the mapping from Soong properties to Bazel rule attributes in the
531// process. This process may optionally create additional BazelTargetModules,
532// resulting in a 1:many mapping.
533//
534// bp2build.Codegen is then responsible for visiting all modules in the graph,
535// filtering for BazelTargetModules, and code-generating BUILD targets from
536// them.
Jingwen Chen73850672020-12-14 08:25:34 -0500537type BazelTargetModule interface {
538 Module
539
Liz Kammerfc46bc12021-02-19 11:06:17 -0500540 bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
541 SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties)
542
543 RuleClass() string
544 BzlLoadLocation() string
Jingwen Chen73850672020-12-14 08:25:34 -0500545}
546
Jingwen Chenab60f122021-01-24 21:21:45 -0500547// InitBazelTargetModule is a wrapper function that decorates BazelTargetModule
548// with property structs containing metadata for bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500549func InitBazelTargetModule(module BazelTargetModule) {
Liz Kammerfc46bc12021-02-19 11:06:17 -0500550 module.AddProperties(module.bazelTargetModuleProperties())
Jingwen Chen73850672020-12-14 08:25:34 -0500551 InitAndroidModule(module)
552}
553
Jingwen Chenab60f122021-01-24 21:21:45 -0500554// BazelTargetModuleBase contains the property structs with metadata for
555// bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500556type BazelTargetModuleBase struct {
557 ModuleBase
558 Properties bazel.BazelTargetModuleProperties
559}
560
Liz Kammerfc46bc12021-02-19 11:06:17 -0500561// bazelTargetModuleProperties getter.
562func (btmb *BazelTargetModuleBase) bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
Jingwen Chen73850672020-12-14 08:25:34 -0500563 return &btmb.Properties
564}
565
Liz Kammerfc46bc12021-02-19 11:06:17 -0500566// SetBazelTargetModuleProperties setter for BazelTargetModuleProperties
567func (btmb *BazelTargetModuleBase) SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) {
568 btmb.Properties = props
569}
570
571// RuleClass returns the rule class for this Bazel target
572func (b *BazelTargetModuleBase) RuleClass() string {
573 return b.bazelTargetModuleProperties().Rule_class
574}
575
576// BzlLoadLocation returns the rule class for this Bazel target
577func (b *BazelTargetModuleBase) BzlLoadLocation() string {
578 return b.bazelTargetModuleProperties().Bzl_load_location
579}
580
Paul Duffine2453c72019-05-31 14:00:04 +0100581// Qualified id for a module
582type qualifiedModuleName struct {
583 // The package (i.e. directory) in which the module is defined, without trailing /
584 pkg string
585
586 // The name of the module, empty string if package.
587 name string
588}
589
590func (q qualifiedModuleName) String() string {
591 if q.name == "" {
592 return "//" + q.pkg
593 }
594 return "//" + q.pkg + ":" + q.name
595}
596
Paul Duffine484f472019-06-20 16:38:08 +0100597func (q qualifiedModuleName) isRootPackage() bool {
598 return q.pkg == "" && q.name == ""
599}
600
Paul Duffine2453c72019-05-31 14:00:04 +0100601// Get the id for the package containing this module.
602func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
603 pkg := q.pkg
604 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100605 if pkg == "" {
606 panic(fmt.Errorf("Cannot get containing package id of root package"))
607 }
608
609 index := strings.LastIndex(pkg, "/")
610 if index == -1 {
611 pkg = ""
612 } else {
613 pkg = pkg[:index]
614 }
Paul Duffine2453c72019-05-31 14:00:04 +0100615 }
616 return newPackageId(pkg)
617}
618
619func newPackageId(pkg string) qualifiedModuleName {
620 // A qualified id for a package module has no name.
621 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800622}
623
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000624type Dist struct {
625 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
626 // command line and any of these targets are also on the command line, or otherwise
627 // built
628 Targets []string `android:"arch_variant"`
629
630 // The name of the output artifact. This defaults to the basename of the output of
631 // the module.
632 Dest *string `android:"arch_variant"`
633
634 // The directory within the dist directory to store the artifact. Defaults to the
635 // top level directory ("").
636 Dir *string `android:"arch_variant"`
637
638 // A suffix to add to the artifact file name (before any extension).
639 Suffix *string `android:"arch_variant"`
640
Paul Duffin74f05592020-11-25 16:37:46 +0000641 // A string tag to select the OutputFiles associated with the tag.
642 //
643 // If no tag is specified then it will select the default dist paths provided
644 // by the module type. If a tag of "" is specified then it will return the
645 // default output files provided by the modules, i.e. the result of calling
646 // OutputFiles("").
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000647 Tag *string `android:"arch_variant"`
648}
649
Colin Crossfc754582016-05-17 16:34:16 -0700650type nameProperties struct {
651 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800652 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700653}
654
Colin Cross08d6f8f2020-11-19 02:33:19 +0000655type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800656 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000657 //
658 // Disabling a module should only be done for those modules that cannot be built
659 // in the current environment. Modules that can build in the current environment
660 // but are not usually required (e.g. superceded by a prebuilt) should not be
661 // disabled as that will prevent them from being built by the checkbuild target
662 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800663 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800664
Paul Duffin2e61fa62019-03-28 14:10:57 +0000665 // Controls the visibility of this module to other modules. Allowable values are one or more of
666 // these formats:
667 //
668 // ["//visibility:public"]: Anyone can use this module.
669 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
670 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100671 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
672 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000673 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
674 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
675 // this module. Note that sub-packages do not have access to the rule; for example,
676 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
677 // is a special module and must be used verbatim. It represents all of the modules in the
678 // package.
679 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
680 // or other or in one of their sub-packages have access to this module. For example,
681 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
682 // to depend on this rule (but not //independent:evil)
683 // ["//project"]: This is shorthand for ["//project:__pkg__"]
684 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
685 // //project is the module's package. e.g. using [":__subpackages__"] in
686 // packages/apps/Settings/Android.bp is equivalent to
687 // //packages/apps/Settings:__subpackages__.
688 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
689 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100690 //
691 // If a module does not specify the `visibility` property then it uses the
692 // `default_visibility` property of the `package` module in the module's package.
693 //
694 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100695 // it will use the `default_visibility` of its closest ancestor package for which
696 // a `default_visibility` property is specified.
697 //
698 // If no `default_visibility` property can be found then the module uses the
699 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100700 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100701 // The `visibility` property has no effect on a defaults module although it does
702 // apply to any non-defaults module that uses it. To set the visibility of a
703 // defaults module, use the `defaults_visibility` property on the defaults module;
704 // not to be confused with the `default_visibility` property on the package module.
705 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000706 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
707 // more details.
708 Visibility []string
709
Bob Badour37af0462021-01-07 03:34:31 +0000710 // Describes the licenses applicable to this module. Must reference license modules.
711 Licenses []string
712
713 // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more.
714 Effective_licenses []string `blueprint:"mutated"`
715 // Override of module name when reporting licenses
716 Effective_package_name *string `blueprint:"mutated"`
717 // Notice files
Paul Duffinec0836a2021-05-10 22:53:30 +0100718 Effective_license_text Paths `blueprint:"mutated"`
Bob Badour37af0462021-01-07 03:34:31 +0000719 // License names
720 Effective_license_kinds []string `blueprint:"mutated"`
721 // License conditions
722 Effective_license_conditions []string `blueprint:"mutated"`
723
Colin Cross7d5136f2015-05-11 13:39:40 -0700724 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800725 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
726 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
Roland Levillain24bb2e62020-09-22 11:18:38 +0000727 // platform).
Colin Cross7d716ba2017-11-01 10:38:29 -0700728 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700729
730 Target struct {
731 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700732 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700733 }
734 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700735 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700736 }
737 }
738
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000739 // If set to true then the archMutator will create variants for each arch specific target
740 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
741 // create a variant for the architecture and will list the additional arch specific targets
742 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700743 UseTargetVariants bool `blueprint:"mutated"`
744 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800745
Dan Willemsen782a2d12015-12-21 14:55:28 -0800746 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700747 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800748
Colin Cross55708f32017-03-20 13:23:34 -0700749 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700750 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700751
Jiyong Park2db76922017-11-08 16:03:48 +0900752 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
753 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
754 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700755 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700756
Jiyong Park2db76922017-11-08 16:03:48 +0900757 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
758 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
759 Soc_specific *bool
760
761 // whether this module is specific to a device, not only for SoC, but also for off-chip
762 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
763 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
764 // This implies `soc_specific:true`.
765 Device_specific *bool
766
767 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900768 // network operator, etc). When set to true, it is installed into /product (or
769 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900770 Product_specific *bool
771
Justin Yund5f6c822019-06-25 16:47:17 +0900772 // whether this module extends system. When set to true, it is installed into /system_ext
773 // (or /system/system_ext if system_ext partition does not exist).
774 System_ext_specific *bool
775
Jiyong Parkf9332f12018-02-01 00:54:12 +0900776 // Whether this module is installed to recovery partition
777 Recovery *bool
778
Yifan Hong1b3348d2020-01-21 15:53:22 -0800779 // Whether this module is installed to ramdisk
780 Ramdisk *bool
781
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700782 // Whether this module is installed to vendor ramdisk
783 Vendor_ramdisk *bool
784
Inseob Kim08758f02021-04-08 21:13:22 +0900785 // Whether this module is installed to debug ramdisk
786 Debug_ramdisk *bool
787
Jaewoong Jung8e93aba2021-03-02 16:58:08 -0800788 // Whether this module is built for non-native architectures (also known as native bridge binary)
dimitry1f33e402019-03-26 12:39:31 +0100789 Native_bridge_supported *bool `android:"arch_variant"`
790
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700791 // init.rc files to be installed if this module is installed
Colin Cross0bab8772020-09-25 14:01:21 -0700792 Init_rc []string `android:"arch_variant,path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700793
Steven Moreland57a23d22018-04-04 15:42:19 -0700794 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800795 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700796
Chris Wolfe998306e2016-08-15 14:47:23 -0400797 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700798 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400799
Sasha Smundakb6d23052019-04-01 18:37:36 -0700800 // names of other modules to install on host if this module is installed
801 Host_required []string `android:"arch_variant"`
802
803 // names of other modules to install on target if this module is installed
804 Target_required []string `android:"arch_variant"`
805
Colin Cross5aac3622017-08-31 15:07:09 -0700806 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800807 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700808
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000809 // The OsType of artifacts that this module variant is responsible for creating.
810 //
811 // Set by osMutator
812 CompileOS OsType `blueprint:"mutated"`
813
814 // The Target of artifacts that this module variant is responsible for creating.
815 //
816 // Set by archMutator
817 CompileTarget Target `blueprint:"mutated"`
818
819 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
820 // responsible for creating.
821 //
822 // By default this is nil as, where necessary, separate variants are created for the
823 // different multilib types supported and that information is encapsulated in the
824 // CompileTarget so the module variant simply needs to create artifacts for that.
825 //
826 // However, if UseTargetVariants is set to false (e.g. by
827 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
828 // multilib targets. Instead a single variant is created for the architecture and
829 // this contains the multilib specific targets that this variant should create.
830 //
831 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700832 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000833
834 // True if the module variant's CompileTarget is the primary target
835 //
836 // Set by archMutator
837 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800838
839 // Set by InitAndroidModule
840 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700841 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700842
Paul Duffin1356d8c2020-02-25 19:26:33 +0000843 // If set to true then a CommonOS variant will be created which will have dependencies
844 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
845 // that covers all os and architecture variants.
846 //
847 // The OsType specific variants can be retrieved by calling
848 // GetOsSpecificVariantsOfCommonOSVariant
849 //
850 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
851 CreateCommonOSVariant bool `blueprint:"mutated"`
852
853 // If set to true then this variant is the CommonOS variant that has dependencies on its
854 // OsType specific variants.
855 //
856 // Set by osMutator.
857 CommonOSVariant bool `blueprint:"mutated"`
858
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800859 // When HideFromMake is set to true, no entry for this variant will be emitted in the
860 // generated Android.mk file.
861 HideFromMake bool `blueprint:"mutated"`
862
863 // When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable,
864 // ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile
865 // and don't create a rule to install the file.
Colin Crossce75d2c2016-10-06 16:12:58 -0700866 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800867
Liz Kammer5ca3a622020-08-05 15:40:41 -0700868 // Whether the module has been replaced by a prebuilt
869 ReplacedByPrebuilt bool `blueprint:"mutated"`
870
Justin Yun32f053b2020-07-31 23:07:17 +0900871 // Disabled by mutators. If set to true, it overrides Enabled property.
872 ForcedDisabled bool `blueprint:"mutated"`
873
Jeff Gaston088e29e2017-11-29 16:47:17 -0800874 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700875
876 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700877
878 // Name and variant strings stored by mutators to enable Module.String()
879 DebugName string `blueprint:"mutated"`
880 DebugMutators []string `blueprint:"mutated"`
881 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800882
Colin Crossa6845402020-11-16 15:08:19 -0800883 // ImageVariation is set by ImageMutator to specify which image this variation is for,
884 // for example "" for core or "recovery" for recovery. It will often be set to one of the
885 // constants in image.go, but can also be set to a custom value by individual module types.
Colin Cross7228ecd2019-11-18 16:00:16 -0800886 ImageVariation string `blueprint:"mutated"`
Liz Kammer2ada09a2021-08-11 00:17:36 -0400887
888 // Information about _all_ bp2build targets generated by this module. Multiple targets are
889 // supported as Soong handles some things within a single target that we may choose to split into
890 // multiple targets, e.g. renderscript, protos, yacc within a cc module.
891 Bp2buildInfo []bp2buildInfo `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800892}
893
Paul Duffined875132020-09-02 13:08:57 +0100894type distProperties struct {
895 // configuration to distribute output files from this module to the distribution
896 // directory (default: $OUT/dist, configurable with $DIST_DIR)
897 Dist Dist `android:"arch_variant"`
898
899 // a list of configurations to distribute output files from this module to the
900 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
901 Dists []Dist `android:"arch_variant"`
902}
903
Paul Duffin74f05592020-11-25 16:37:46 +0000904// The key to use in TaggedDistFiles when a Dist structure does not specify a
905// tag property. This intentionally does not use "" as the default because that
906// would mean that an empty tag would have a different meaning when used in a dist
907// structure that when used to reference a specific set of output paths using the
908// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
909const DefaultDistTag = "<default-dist-tag>"
910
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000911// A map of OutputFile tag keys to Paths, for disting purposes.
912type TaggedDistFiles map[string]Paths
913
Paul Duffin74f05592020-11-25 16:37:46 +0000914// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
915// then it will create a map, update it and then return it. If a mapping already
916// exists for the tag then the paths are appended to the end of the current list
917// of paths, ignoring any duplicates.
918func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
919 if t == nil {
920 t = make(TaggedDistFiles)
921 }
922
923 for _, distFile := range paths {
924 if distFile != nil && !t[tag].containsPath(distFile) {
925 t[tag] = append(t[tag], distFile)
926 }
927 }
928
929 return t
930}
931
932// merge merges the entries from the other TaggedDistFiles object into this one.
933// If the TaggedDistFiles is nil then it will create a new instance, merge the
934// other into it, and then return it.
935func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
936 for tag, paths := range other {
937 t = t.addPathsForTag(tag, paths...)
938 }
939
940 return t
941}
942
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000943func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000944 for _, path := range paths {
945 if path == nil {
946 panic("The path to a dist file cannot be nil.")
947 }
948 }
949
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000950 // The default OutputFile tag is the empty "" string.
Paul Duffin74f05592020-11-25 16:37:46 +0000951 return TaggedDistFiles{DefaultDistTag: paths}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000952}
953
Colin Cross3f40fa42015-01-30 17:27:36 -0800954type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800955 // If set to true, build a variant of the module for the host. Defaults to false.
956 Host_supported *bool
957
958 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700959 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800960}
961
Colin Crossc472d572015-03-17 15:06:21 -0700962type Multilib string
963
964const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800965 MultilibBoth Multilib = "both"
966 MultilibFirst Multilib = "first"
967 MultilibCommon Multilib = "common"
968 MultilibCommonFirst Multilib = "common_first"
969 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700970)
971
Colin Crossa1ad8d12016-06-01 17:09:44 -0700972type HostOrDeviceSupported int
973
974const (
Colin Cross34037c62020-11-17 13:19:17 -0800975 hostSupported = 1 << iota
976 hostCrossSupported
977 deviceSupported
978 hostDefault
979 deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700980
981 // Host and HostCross are built by default. Device is not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800982 HostSupported = hostSupported | hostCrossSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700983
984 // Host is built by default. HostCross and Device are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800985 HostSupportedNoCross = hostSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700986
987 // Device is built by default. Host and HostCross are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800988 DeviceSupported = deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700989
Liz Kammer8631cc72021-08-23 21:12:07 +0000990 // By default, _only_ device variant is built. Device variant can be disabled with `device_supported: false`
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -0700991 // Host and HostCross are disabled by default and can be enabled with `host_supported: true`
Colin Cross34037c62020-11-17 13:19:17 -0800992 HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700993
994 // Host, HostCross, and Device are built by default.
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -0700995 // Building Device can be disabled with `device_supported: false`
996 // Building Host and HostCross can be disabled with `host_supported: false`
Colin Cross34037c62020-11-17 13:19:17 -0800997 HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
998 deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700999
1000 // Nothing is supported. This is not exposed to the user, but used to mark a
1001 // host only module as unsupported when the module type is not supported on
1002 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Colin Cross34037c62020-11-17 13:19:17 -08001003 NeitherHostNorDeviceSupported = 0
Colin Crossa1ad8d12016-06-01 17:09:44 -07001004)
1005
Jiyong Park2db76922017-11-08 16:03:48 +09001006type moduleKind int
1007
1008const (
1009 platformModule moduleKind = iota
1010 deviceSpecificModule
1011 socSpecificModule
1012 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001013 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001014)
1015
1016func (k moduleKind) String() string {
1017 switch k {
1018 case platformModule:
1019 return "platform"
1020 case deviceSpecificModule:
1021 return "device-specific"
1022 case socSpecificModule:
1023 return "soc-specific"
1024 case productSpecificModule:
1025 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +09001026 case systemExtSpecificModule:
1027 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +09001028 default:
1029 panic(fmt.Errorf("unknown module kind %d", k))
1030 }
1031}
1032
Colin Cross9d34f352019-11-22 16:03:51 -08001033func initAndroidModuleBase(m Module) {
1034 m.base().module = m
1035}
1036
Colin Crossa6845402020-11-16 15:08:19 -08001037// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
1038// It adds the common properties, for example "name" and "enabled".
Colin Cross36242852017-06-23 15:06:31 -07001039func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -08001040 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001041 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -07001042
Colin Cross36242852017-06-23 15:06:31 -07001043 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -07001044 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +01001045 &base.commonProperties,
1046 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -07001047
Colin Crosseabaedd2020-02-06 17:01:55 -08001048 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -07001049
Colin Crossa3a97412019-03-18 12:24:29 -07001050 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -07001051 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +01001052
1053 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +01001054 // its checking and parsing phases so make it the primary visibility property.
1055 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Bob Badour37af0462021-01-07 03:34:31 +00001056
1057 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
1058 // its checking and parsing phases so make it the primary licenses property.
1059 setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses)
Colin Cross5049f022015-03-18 13:28:46 -07001060}
1061
Colin Crossa6845402020-11-16 15:08:19 -08001062// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
1063// It adds the common properties, for example "name" and "enabled", as well as runtime generated
1064// property structs for architecture-specific versions of generic properties tagged with
1065// `android:"arch_variant"`.
1066//
1067// InitAndroidModule should not be called if InitAndroidArchModule was called.
Colin Cross36242852017-06-23 15:06:31 -07001068func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1069 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -07001070
1071 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -08001072 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -07001073 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -07001074 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -07001075 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001076
Colin Cross34037c62020-11-17 13:19:17 -08001077 if hod&hostSupported != 0 && hod&deviceSupported != 0 {
Colin Cross36242852017-06-23 15:06:31 -07001078 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -08001079 }
1080
Colin Crossa6845402020-11-16 15:08:19 -08001081 initArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001082}
1083
Colin Crossa6845402020-11-16 15:08:19 -08001084// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1085// architecture-specific, but will only have a single variant per OS that handles all the
1086// architectures simultaneously. The list of Targets that it must handle will be available from
1087// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
1088// well as runtime generated property structs for architecture-specific versions of generic
1089// properties tagged with `android:"arch_variant"`.
1090//
1091// InitAndroidModule or InitAndroidArchModule should not be called if
1092// InitAndroidMultiTargetsArchModule was called.
Colin Crossee0bc3b2018-10-02 22:01:37 -07001093func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1094 InitAndroidArchModule(m, hod, defaultMultilib)
1095 m.base().commonProperties.UseTargetVariants = false
1096}
1097
Colin Crossa6845402020-11-16 15:08:19 -08001098// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1099// architecture-specific, but will only have a single variant per OS that handles all the
1100// architectures simultaneously, and will also have an additional CommonOS variant that has
1101// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
1102// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
1103// "enabled", as well as runtime generated property structs for architecture-specific versions of
1104// generic properties tagged with `android:"arch_variant"`.
1105//
1106// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
1107// called if InitCommonOSAndroidMultiTargetsArchModule was called.
Paul Duffin1356d8c2020-02-25 19:26:33 +00001108func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1109 InitAndroidArchModule(m, hod, defaultMultilib)
1110 m.base().commonProperties.UseTargetVariants = false
1111 m.base().commonProperties.CreateCommonOSVariant = true
1112}
1113
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001114// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -08001115// modules. It should be included as an anonymous field in every module
1116// struct definition. InitAndroidModule should then be called from the module's
1117// factory function, and the return values from InitAndroidModule should be
1118// returned from the factory function.
1119//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001120// The ModuleBase type is responsible for implementing the GenerateBuildActions
1121// method to support the blueprint.Module interface. This method will then call
1122// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -07001123// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
1124// rather than the usual blueprint.ModuleContext.
1125// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -08001126// system including details about the particular build variant that is to be
1127// generated.
1128//
1129// For example:
1130//
1131// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001132// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -08001133// )
1134//
1135// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001136// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -08001137// properties struct {
1138// MyProperty string
1139// }
1140// }
1141//
Colin Cross36242852017-06-23 15:06:31 -07001142// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001143// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -07001144// m.AddProperties(&m.properties)
1145// android.InitAndroidModule(m)
1146// return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001147// }
1148//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001149// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001150// // Get the CPU architecture for the current build variant.
1151// variantArch := ctx.Arch()
1152//
1153// // ...
1154// }
Colin Cross635c3b02016-05-18 15:37:25 -07001155type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -08001156 // Putting the curiously recurring thing pointing to the thing that contains
1157 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -07001158 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -07001159 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -08001160
Colin Crossfc754582016-05-17 16:34:16 -07001161 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -08001162 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +01001163 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -07001164 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001165 hostAndDeviceProperties hostAndDeviceProperties
1166 generalProperties []interface{}
Jingwen Chen5d864492021-02-24 07:20:12 -05001167
1168 // Arch specific versions of structs in generalProperties. The outer index
1169 // has the same order as generalProperties as initialized in
1170 // InitAndroidArchModule, and the inner index chooses the props specific to
1171 // the architecture. The interface{} value is an archPropRoot that is
1172 // filled with arch specific values by the arch mutator.
1173 archProperties [][]interface{}
1174
1175 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001176
Jingwen Chen73850672020-12-14 08:25:34 -05001177 // Properties specific to the Blueprint to BUILD migration.
1178 bazelTargetModuleProperties bazel.BazelTargetModuleProperties
1179
Paul Duffin63c6e182019-07-24 14:24:38 +01001180 // Information about all the properties on the module that contains visibility rules that need
1181 // checking.
1182 visibilityPropertyInfo []visibilityProperty
1183
1184 // The primary visibility property, may be nil, that controls access to the module.
1185 primaryVisibilityProperty visibilityProperty
1186
Bob Badour37af0462021-01-07 03:34:31 +00001187 // The primary licenses property, may be nil, records license metadata for the module.
1188 primaryLicensesProperty applicableLicensesProperty
1189
Colin Crossffe6b9d2020-12-01 15:40:06 -08001190 noAddressSanitizer bool
1191 installFiles InstallPaths
1192 installFilesDepSet *installPathsDepSet
1193 checkbuildFiles Paths
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07001194 tidyFiles Paths
Colin Crossffe6b9d2020-12-01 15:40:06 -08001195 packagingSpecs []PackagingSpec
1196 packagingSpecsDepSet *packagingSpecsDepSet
1197 noticeFiles Paths
1198 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001199
Paul Duffinaf970a22020-11-23 23:32:56 +00001200 // The files to copy to the dist as explicitly specified in the .bp file.
1201 distFiles TaggedDistFiles
1202
Colin Cross1f8c52b2015-06-16 16:38:17 -07001203 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
1204 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -08001205 installTarget WritablePath
1206 checkbuildTarget WritablePath
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07001207 tidyTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -07001208 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -07001209
Colin Cross178a5092016-09-13 13:42:32 -07001210 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -07001211
1212 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -07001213
1214 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001215 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001216 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001217 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -07001218
Inseob Kim8471cda2019-11-15 09:59:12 +09001219 initRcPaths Paths
1220 vintfFragmentsPaths Paths
Colin Cross36242852017-06-23 15:06:31 -07001221}
1222
Liz Kammer2ada09a2021-08-11 00:17:36 -04001223// A struct containing all relevant information about a Bazel target converted via bp2build.
1224type bp2buildInfo struct {
1225 Name string
1226 Dir string
1227 BazelProps bazel.BazelTargetModuleProperties
1228 Attrs interface{}
1229}
1230
1231// TargetName returns the Bazel target name of a bp2build converted target.
1232func (b bp2buildInfo) TargetName() string {
1233 return b.Name
1234}
1235
1236// TargetPackage returns the Bazel package of a bp2build converted target.
1237func (b bp2buildInfo) TargetPackage() string {
1238 return b.Dir
1239}
1240
1241// BazelRuleClass returns the Bazel rule class of a bp2build converted target.
1242func (b bp2buildInfo) BazelRuleClass() string {
1243 return b.BazelProps.Rule_class
1244}
1245
1246// BazelRuleLoadLocation returns the location of the Bazel rule of a bp2build converted target.
1247// This may be empty as native Bazel rules do not need to be loaded.
1248func (b bp2buildInfo) BazelRuleLoadLocation() string {
1249 return b.BazelProps.Bzl_load_location
1250}
1251
1252// BazelAttributes returns the Bazel attributes of a bp2build converted target.
1253func (b bp2buildInfo) BazelAttributes() interface{} {
1254 return b.Attrs
1255}
1256
1257func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) {
1258 m.commonProperties.Bp2buildInfo = append(m.commonProperties.Bp2buildInfo, info)
1259}
1260
1261// IsConvertedByBp2build returns whether this module was converted via bp2build.
1262func (m *ModuleBase) IsConvertedByBp2build() bool {
1263 return len(m.commonProperties.Bp2buildInfo) > 0
1264}
1265
1266// Bp2buildTargets returns the Bazel targets bp2build generated for this module.
1267func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo {
1268 return m.commonProperties.Bp2buildInfo
1269}
1270
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001271func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
1272 (*d)["Android"] = map[string]interface{}{}
1273}
1274
Paul Duffin44f1d842020-06-26 20:17:02 +01001275func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
1276
Colin Cross4157e882019-06-06 16:57:04 -07001277func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -08001278
Colin Cross4157e882019-06-06 16:57:04 -07001279func (m *ModuleBase) AddProperties(props ...interface{}) {
1280 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -07001281}
1282
Colin Cross4157e882019-06-06 16:57:04 -07001283func (m *ModuleBase) GetProperties() []interface{} {
1284 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -08001285}
1286
Colin Cross4157e882019-06-06 16:57:04 -07001287func (m *ModuleBase) BuildParamsForTests() []BuildParams {
1288 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -07001289}
1290
Colin Cross4157e882019-06-06 16:57:04 -07001291func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
1292 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001293}
1294
Colin Cross4157e882019-06-06 16:57:04 -07001295func (m *ModuleBase) VariablesForTests() map[string]string {
1296 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001297}
1298
Colin Crossce75d2c2016-10-06 16:12:58 -07001299// Name returns the name of the module. It may be overridden by individual module types, for
1300// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -07001301func (m *ModuleBase) Name() string {
1302 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -07001303}
1304
Colin Cross9a362232019-07-01 15:32:45 -07001305// String returns a string that includes the module name and variants for printing during debugging.
1306func (m *ModuleBase) String() string {
1307 sb := strings.Builder{}
1308 sb.WriteString(m.commonProperties.DebugName)
1309 sb.WriteString("{")
1310 for i := range m.commonProperties.DebugMutators {
1311 if i != 0 {
1312 sb.WriteString(",")
1313 }
1314 sb.WriteString(m.commonProperties.DebugMutators[i])
1315 sb.WriteString(":")
1316 sb.WriteString(m.commonProperties.DebugVariations[i])
1317 }
1318 sb.WriteString("}")
1319 return sb.String()
1320}
1321
Colin Crossce75d2c2016-10-06 16:12:58 -07001322// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001323func (m *ModuleBase) BaseModuleName() string {
1324 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001325}
1326
Colin Cross4157e882019-06-06 16:57:04 -07001327func (m *ModuleBase) base() *ModuleBase {
1328 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001329}
1330
Paul Duffine2453c72019-05-31 14:00:04 +01001331func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1332 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1333}
1334
1335func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001336 return m.visibilityPropertyInfo
1337}
1338
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001339func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001340 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001341 // Make a copy of the underlying Dists slice to protect against
1342 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001343 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1344 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001345 } else {
Paul Duffined875132020-09-02 13:08:57 +01001346 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001347 }
1348}
1349
1350func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
Paul Duffin74f05592020-11-25 16:37:46 +00001351 var distFiles TaggedDistFiles
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001352 for _, dist := range m.Dists() {
Paul Duffin74f05592020-11-25 16:37:46 +00001353 // If no tag is specified then it means to use the default dist paths so use
1354 // the special tag name which represents that.
1355 tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
1356
Paul Duffinaf970a22020-11-23 23:32:56 +00001357 if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
1358 // Call the OutputFiles(tag) method to get the paths associated with the tag.
1359 distFilesForTag, err := outputFileProducer.OutputFiles(tag)
Paul Duffin74f05592020-11-25 16:37:46 +00001360
Paul Duffinaf970a22020-11-23 23:32:56 +00001361 // If the tag was not supported and is not DefaultDistTag then it is an error.
1362 // Failing to find paths for DefaultDistTag is not an error. It just means
1363 // that the module type requires the legacy behavior.
1364 if err != nil && tag != DefaultDistTag {
1365 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1366 }
1367
1368 distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
1369 } else if tag != DefaultDistTag {
1370 // If the tag was specified then it is an error if the module does not
1371 // implement OutputFileProducer because there is no other way of accessing
1372 // the paths for the specified tag.
1373 ctx.PropertyErrorf("dist.tag",
1374 "tag %s not supported because the module does not implement OutputFileProducer", tag)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001375 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001376 }
1377
1378 return distFiles
1379}
1380
Colin Cross4157e882019-06-06 16:57:04 -07001381func (m *ModuleBase) Target() Target {
1382 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001383}
1384
Colin Cross4157e882019-06-06 16:57:04 -07001385func (m *ModuleBase) TargetPrimary() bool {
1386 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001387}
1388
Colin Cross4157e882019-06-06 16:57:04 -07001389func (m *ModuleBase) MultiTargets() []Target {
1390 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001391}
1392
Colin Cross4157e882019-06-06 16:57:04 -07001393func (m *ModuleBase) Os() OsType {
1394 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001395}
1396
Colin Cross4157e882019-06-06 16:57:04 -07001397func (m *ModuleBase) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09001398 return m.Os().Class == Host
Dan Willemsen97750522016-02-09 17:43:51 -08001399}
1400
Yo Chiangbba545e2020-06-09 16:15:37 +08001401func (m *ModuleBase) Device() bool {
1402 return m.Os().Class == Device
1403}
1404
Colin Cross4157e882019-06-06 16:57:04 -07001405func (m *ModuleBase) Arch() Arch {
1406 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001407}
1408
Colin Cross4157e882019-06-06 16:57:04 -07001409func (m *ModuleBase) ArchSpecific() bool {
1410 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001411}
1412
Paul Duffin1356d8c2020-02-25 19:26:33 +00001413// True if the current variant is a CommonOS variant, false otherwise.
1414func (m *ModuleBase) IsCommonOSVariant() bool {
1415 return m.commonProperties.CommonOSVariant
1416}
1417
Colin Cross34037c62020-11-17 13:19:17 -08001418// supportsTarget returns true if the given Target is supported by the current module.
1419func (m *ModuleBase) supportsTarget(target Target) bool {
1420 switch target.Os.Class {
1421 case Host:
1422 if target.HostCross {
1423 return m.HostCrossSupported()
1424 } else {
1425 return m.HostSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001426 }
Colin Cross34037c62020-11-17 13:19:17 -08001427 case Device:
1428 return m.DeviceSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001429 default:
Jiyong Park1613e552020-09-14 19:43:17 +09001430 return false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001431 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001432}
1433
Colin Cross34037c62020-11-17 13:19:17 -08001434// DeviceSupported returns true if the current module is supported and enabled for device targets,
1435// i.e. the factory method set the HostOrDeviceSupported value to include device support and
1436// the device support is enabled by default or enabled by the device_supported property.
Colin Cross4157e882019-06-06 16:57:04 -07001437func (m *ModuleBase) DeviceSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001438 hod := m.commonProperties.HostOrDeviceSupported
1439 // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
1440 // value has the deviceDefault bit set.
1441 deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
1442 return hod&deviceSupported != 0 && deviceEnabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001443}
1444
Colin Cross34037c62020-11-17 13:19:17 -08001445// HostSupported returns true if the current module is supported and enabled for host targets,
1446// i.e. the factory method set the HostOrDeviceSupported value to include host support and
1447// the host support is enabled by default or enabled by the host_supported property.
Paul Duffine44358f2019-11-26 18:04:12 +00001448func (m *ModuleBase) HostSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001449 hod := m.commonProperties.HostOrDeviceSupported
1450 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1451 // value has the hostDefault bit set.
1452 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1453 return hod&hostSupported != 0 && hostEnabled
1454}
1455
1456// HostCrossSupported returns true if the current module is supported and enabled for host cross
1457// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
1458// support and the host cross support is enabled by default or enabled by the
1459// host_supported property.
1460func (m *ModuleBase) HostCrossSupported() bool {
1461 hod := m.commonProperties.HostOrDeviceSupported
1462 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1463 // value has the hostDefault bit set.
1464 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1465 return hod&hostCrossSupported != 0 && hostEnabled
Paul Duffine44358f2019-11-26 18:04:12 +00001466}
1467
Colin Cross4157e882019-06-06 16:57:04 -07001468func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001469 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001470}
1471
Colin Cross4157e882019-06-06 16:57:04 -07001472func (m *ModuleBase) DeviceSpecific() bool {
1473 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001474}
1475
Colin Cross4157e882019-06-06 16:57:04 -07001476func (m *ModuleBase) SocSpecific() bool {
1477 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001478}
1479
Colin Cross4157e882019-06-06 16:57:04 -07001480func (m *ModuleBase) ProductSpecific() bool {
1481 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001482}
1483
Justin Yund5f6c822019-06-25 16:47:17 +09001484func (m *ModuleBase) SystemExtSpecific() bool {
1485 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001486}
1487
Colin Crossc2d24052020-05-13 11:05:02 -07001488// RequiresStableAPIs returns true if the module will be installed to a partition that may
1489// be updated separately from the system image.
1490func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1491 return m.SocSpecific() || m.DeviceSpecific() ||
1492 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1493}
1494
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001495func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1496 partition := "system"
1497 if m.SocSpecific() {
1498 // A SoC-specific module could be on the vendor partition at
1499 // "vendor" or the system partition at "system/vendor".
1500 if config.VendorPath() == "vendor" {
1501 partition = "vendor"
1502 }
1503 } else if m.DeviceSpecific() {
1504 // A device-specific module could be on the odm partition at
1505 // "odm", the vendor partition at "vendor/odm", or the system
1506 // partition at "system/vendor/odm".
1507 if config.OdmPath() == "odm" {
1508 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001509 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001510 partition = "vendor"
1511 }
1512 } else if m.ProductSpecific() {
1513 // A product-specific module could be on the product partition
1514 // at "product" or the system partition at "system/product".
1515 if config.ProductPath() == "product" {
1516 partition = "product"
1517 }
1518 } else if m.SystemExtSpecific() {
1519 // A system_ext-specific module could be on the system_ext
1520 // partition at "system_ext" or the system partition at
1521 // "system/system_ext".
1522 if config.SystemExtPath() == "system_ext" {
1523 partition = "system_ext"
1524 }
1525 }
1526 return partition
1527}
1528
Colin Cross4157e882019-06-06 16:57:04 -07001529func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001530 if m.commonProperties.ForcedDisabled {
1531 return false
1532 }
Colin Cross08d6f8f2020-11-19 02:33:19 +00001533 if m.commonProperties.Enabled == nil {
1534 return !m.Os().DefaultDisabled
1535 }
1536 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001537}
1538
Inseob Kimeec88e12020-01-22 11:11:29 +09001539func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001540 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001541}
1542
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001543// HideFromMake marks this variant so that it is not emitted in the generated Android.mk file.
1544func (m *ModuleBase) HideFromMake() {
1545 m.commonProperties.HideFromMake = true
1546}
1547
1548// IsHideFromMake returns true if HideFromMake was previously called.
1549func (m *ModuleBase) IsHideFromMake() bool {
1550 return m.commonProperties.HideFromMake == true
1551}
1552
1553// SkipInstall marks this variant to not create install rules when ctx.Install* are called.
Colin Cross4157e882019-06-06 16:57:04 -07001554func (m *ModuleBase) SkipInstall() {
1555 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001556}
1557
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +00001558// IsSkipInstall returns true if this variant is marked to not create install
1559// rules when ctx.Install* are called.
1560func (m *ModuleBase) IsSkipInstall() bool {
1561 return m.commonProperties.SkipInstall
1562}
1563
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001564// Similar to HideFromMake, but if the AndroidMk entry would set
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001565// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1566// rather than leaving it out altogether. That happens in cases where it would
1567// have other side effects, in particular when it adds a NOTICE file target,
1568// which other install targets might depend on.
1569func (m *ModuleBase) MakeUninstallable() {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001570 m.HideFromMake()
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001571}
1572
Liz Kammer5ca3a622020-08-05 15:40:41 -07001573func (m *ModuleBase) ReplacedByPrebuilt() {
1574 m.commonProperties.ReplacedByPrebuilt = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001575 m.HideFromMake()
Liz Kammer5ca3a622020-08-05 15:40:41 -07001576}
1577
1578func (m *ModuleBase) IsReplacedByPrebuilt() bool {
1579 return m.commonProperties.ReplacedByPrebuilt
1580}
1581
Colin Cross4157e882019-06-06 16:57:04 -07001582func (m *ModuleBase) ExportedToMake() bool {
1583 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001584}
1585
Justin Yun885a7de2021-06-29 20:34:53 +09001586func (m *ModuleBase) EffectiveLicenseFiles() Paths {
1587 return m.commonProperties.Effective_license_text
1588}
1589
Colin Crosse9fe2942020-11-10 18:12:15 -08001590// computeInstallDeps finds the installed paths of all dependencies that have a dependency
1591// tag that is annotated as needing installation via the IsInstallDepNeeded method.
Colin Crossffe6b9d2020-12-01 15:40:06 -08001592func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) {
Colin Cross5d583952020-11-24 16:21:24 -08001593 var installDeps []*installPathsDepSet
Colin Crossffe6b9d2020-12-01 15:40:06 -08001594 var packagingSpecs []*packagingSpecsDepSet
Colin Cross5d583952020-11-24 16:21:24 -08001595 ctx.VisitDirectDeps(func(dep Module) {
Jooyung Han8707cd72021-07-23 02:49:46 +09001596 if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) && !dep.IsHideFromMake() && !dep.IsSkipInstall() {
Colin Cross5d583952020-11-24 16:21:24 -08001597 installDeps = append(installDeps, dep.base().installFilesDepSet)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001598 packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet)
Colin Cross897266e2020-02-13 13:22:08 -08001599 }
1600 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001601
Colin Crossffe6b9d2020-12-01 15:40:06 -08001602 return installDeps, packagingSpecs
Colin Cross3f40fa42015-01-30 17:27:36 -08001603}
1604
Jiyong Park4dc2a1a2020-09-28 17:46:22 +09001605func (m *ModuleBase) FilesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001606 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001607}
1608
Jiyong Park073ea552020-11-09 14:08:34 +09001609func (m *ModuleBase) PackagingSpecs() []PackagingSpec {
1610 return m.packagingSpecs
1611}
1612
Colin Crossffe6b9d2020-12-01 15:40:06 -08001613func (m *ModuleBase) TransitivePackagingSpecs() []PackagingSpec {
1614 return m.packagingSpecsDepSet.ToList()
1615}
1616
Colin Cross4157e882019-06-06 16:57:04 -07001617func (m *ModuleBase) NoAddressSanitizer() bool {
1618 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001619}
1620
Colin Cross4157e882019-06-06 16:57:04 -07001621func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001622 return false
1623}
1624
Jaewoong Jung0949f312019-09-11 10:25:18 -07001625func (m *ModuleBase) InstallInTestcases() bool {
1626 return false
1627}
1628
Colin Cross4157e882019-06-06 16:57:04 -07001629func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001630 return false
1631}
1632
Yifan Hong1b3348d2020-01-21 15:53:22 -08001633func (m *ModuleBase) InstallInRamdisk() bool {
1634 return Bool(m.commonProperties.Ramdisk)
1635}
1636
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001637func (m *ModuleBase) InstallInVendorRamdisk() bool {
1638 return Bool(m.commonProperties.Vendor_ramdisk)
1639}
1640
Inseob Kim08758f02021-04-08 21:13:22 +09001641func (m *ModuleBase) InstallInDebugRamdisk() bool {
1642 return Bool(m.commonProperties.Debug_ramdisk)
1643}
1644
Colin Cross4157e882019-06-06 16:57:04 -07001645func (m *ModuleBase) InstallInRecovery() bool {
1646 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001647}
1648
Kiyoung Kimae11c232021-07-19 11:38:04 +09001649func (m *ModuleBase) InstallInVendor() bool {
1650 return Bool(m.commonProperties.Vendor)
1651}
1652
Colin Cross90ba5f42019-10-02 11:10:58 -07001653func (m *ModuleBase) InstallInRoot() bool {
1654 return false
1655}
1656
Colin Cross607d8582019-07-29 16:44:46 -07001657func (m *ModuleBase) InstallBypassMake() bool {
1658 return false
1659}
1660
Jiyong Park87788b52020-09-01 12:37:45 +09001661func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
1662 return nil, nil
Colin Cross6e359402020-02-10 15:29:54 -08001663}
1664
Colin Cross4157e882019-06-06 16:57:04 -07001665func (m *ModuleBase) Owner() string {
1666 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001667}
1668
Bob Badoura75b0572020-02-18 20:21:55 -08001669func (m *ModuleBase) NoticeFiles() Paths {
1670 return m.noticeFiles
Jiyong Park52818fc2019-03-18 12:01:38 +09001671}
1672
Colin Cross7228ecd2019-11-18 16:00:16 -08001673func (m *ModuleBase) setImageVariation(variant string) {
1674 m.commonProperties.ImageVariation = variant
1675}
1676
1677func (m *ModuleBase) ImageVariation() blueprint.Variation {
1678 return blueprint.Variation{
1679 Mutator: "image",
1680 Variation: m.base().commonProperties.ImageVariation,
1681 }
1682}
1683
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001684func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1685 for i, v := range m.commonProperties.DebugMutators {
1686 if v == mutator {
1687 return m.commonProperties.DebugVariations[i]
1688 }
1689 }
1690
1691 return ""
1692}
1693
Yifan Hong1b3348d2020-01-21 15:53:22 -08001694func (m *ModuleBase) InRamdisk() bool {
1695 return m.base().commonProperties.ImageVariation == RamdiskVariation
1696}
1697
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001698func (m *ModuleBase) InVendorRamdisk() bool {
1699 return m.base().commonProperties.ImageVariation == VendorRamdiskVariation
1700}
1701
Inseob Kim08758f02021-04-08 21:13:22 +09001702func (m *ModuleBase) InDebugRamdisk() bool {
1703 return m.base().commonProperties.ImageVariation == DebugRamdiskVariation
1704}
1705
Colin Cross7228ecd2019-11-18 16:00:16 -08001706func (m *ModuleBase) InRecovery() bool {
1707 return m.base().commonProperties.ImageVariation == RecoveryVariation
1708}
1709
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001710func (m *ModuleBase) RequiredModuleNames() []string {
1711 return m.base().commonProperties.Required
1712}
1713
1714func (m *ModuleBase) HostRequiredModuleNames() []string {
1715 return m.base().commonProperties.Host_required
1716}
1717
1718func (m *ModuleBase) TargetRequiredModuleNames() []string {
1719 return m.base().commonProperties.Target_required
1720}
1721
Inseob Kim8471cda2019-11-15 09:59:12 +09001722func (m *ModuleBase) InitRc() Paths {
1723 return append(Paths{}, m.initRcPaths...)
1724}
1725
1726func (m *ModuleBase) VintfFragments() Paths {
1727 return append(Paths{}, m.vintfFragmentsPaths...)
1728}
1729
Colin Cross4157e882019-06-06 16:57:04 -07001730func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001731 var allInstalledFiles InstallPaths
1732 var allCheckbuildFiles Paths
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07001733 var allTidyFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001734 ctx.VisitAllModuleVariants(func(module Module) {
1735 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001736 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1737 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07001738 allTidyFiles = append(allTidyFiles, a.tidyFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001739 })
1740
Colin Cross0875c522017-11-28 17:34:01 -08001741 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001742
Colin Cross133ebef2020-08-14 17:38:45 -07001743 namespacePrefix := ctx.Namespace().id
Jeff Gaston088e29e2017-11-29 16:47:17 -08001744 if namespacePrefix != "" {
1745 namespacePrefix = namespacePrefix + "-"
1746 }
1747
Colin Cross3f40fa42015-01-30 17:27:36 -08001748 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001749 name := namespacePrefix + ctx.ModuleName() + "-install"
1750 ctx.Phony(name, allInstalledFiles.Paths()...)
1751 m.installTarget = PathForPhony(ctx, name)
1752 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001753 }
1754
1755 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001756 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1757 ctx.Phony(name, allCheckbuildFiles...)
1758 m.checkbuildTarget = PathForPhony(ctx, name)
1759 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001760 }
1761
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07001762 if len(allTidyFiles) > 0 {
1763 name := namespacePrefix + ctx.ModuleName() + "-tidy"
1764 ctx.Phony(name, allTidyFiles...)
1765 m.tidyTarget = PathForPhony(ctx, name)
1766 deps = append(deps, m.tidyTarget)
1767 }
1768
Colin Cross9454bfa2015-03-17 13:24:18 -07001769 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001770 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05001771 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001772 suffix = "-soong"
1773 }
1774
Colin Crossc3d87d32020-06-04 13:25:17 -07001775 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001776
Colin Cross4157e882019-06-06 16:57:04 -07001777 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001778 }
1779}
1780
Colin Crossc34d2322020-01-03 15:23:27 -08001781func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001782 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1783 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1784 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001785 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001786
Dario Frenifd05a742018-05-29 13:28:54 +01001787 msg := "conflicting value set here"
1788 if socSpecific && deviceSpecific {
1789 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001790 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001791 ctx.PropertyErrorf("vendor", msg)
1792 }
Colin Cross4157e882019-06-06 16:57:04 -07001793 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001794 ctx.PropertyErrorf("proprietary", msg)
1795 }
Colin Cross4157e882019-06-06 16:57:04 -07001796 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001797 ctx.PropertyErrorf("soc_specific", msg)
1798 }
1799 }
1800
Justin Yund5f6c822019-06-25 16:47:17 +09001801 if productSpecific && systemExtSpecific {
1802 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1803 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001804 }
1805
Justin Yund5f6c822019-06-25 16:47:17 +09001806 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001807 if productSpecific {
1808 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1809 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001810 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 +01001811 }
1812 if deviceSpecific {
1813 ctx.PropertyErrorf("device_specific", msg)
1814 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001815 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001816 ctx.PropertyErrorf("vendor", msg)
1817 }
Colin Cross4157e882019-06-06 16:57:04 -07001818 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001819 ctx.PropertyErrorf("proprietary", msg)
1820 }
Colin Cross4157e882019-06-06 16:57:04 -07001821 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001822 ctx.PropertyErrorf("soc_specific", msg)
1823 }
1824 }
1825 }
1826
Jiyong Park2db76922017-11-08 16:03:48 +09001827 if productSpecific {
1828 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001829 } else if systemExtSpecific {
1830 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001831 } else if deviceSpecific {
1832 return deviceSpecificModule
1833 } else if socSpecific {
1834 return socSpecificModule
1835 } else {
1836 return platformModule
1837 }
1838}
1839
Colin Crossc34d2322020-01-03 15:23:27 -08001840func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001841 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001842 EarlyModuleContext: ctx,
1843 kind: determineModuleKind(m, ctx),
1844 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001845 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001846}
1847
Colin Cross1184b642019-12-30 18:43:07 -08001848func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1849 return baseModuleContext{
1850 bp: ctx,
1851 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1852 os: m.commonProperties.CompileOS,
1853 target: m.commonProperties.CompileTarget,
1854 targetPrimary: m.commonProperties.CompilePrimary,
1855 multiTargets: m.commonProperties.CompileMultiTargets,
1856 }
1857}
1858
Colin Cross4157e882019-06-06 16:57:04 -07001859func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001860 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001861 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001862 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001863 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
Colin Cross0ea8ba82019-06-06 14:33:29 -07001864 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001865 }
1866
Colin Crossffe6b9d2020-12-01 15:40:06 -08001867 dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
Colin Cross5d583952020-11-24 16:21:24 -08001868 // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
1869 // of installed files of this module. It will be replaced by a depset including the installed
1870 // files of this module at the end for use by modules that depend on this one.
1871 m.installFilesDepSet = newInstallPathsDepSet(nil, dependencyInstallFiles)
1872
Colin Cross6c4f21f2019-06-06 15:41:36 -07001873 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1874 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1875 // TODO: This will be removed once defaults modules handle missing dependency errors
1876 blueprintCtx.GetMissingDependencies()
1877
Colin Crossdc35e212019-06-06 16:13:11 -07001878 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001879 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1880 // (because the dependencies are added before the modules are disabled). The
1881 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1882 // ignored.
1883 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001884
Colin Cross4c83e5c2019-02-25 14:54:28 -08001885 if ctx.config.captureBuild {
1886 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1887 }
1888
Colin Cross67a5c132017-05-09 13:45:28 -07001889 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1890 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001891 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1892 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001893 }
Colin Cross0875c522017-11-28 17:34:01 -08001894 if !ctx.PrimaryArch() {
1895 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001896 }
Colin Cross56a83212020-09-15 18:30:11 -07001897 if apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo); !apexInfo.IsForPlatform() {
1898 suffix = append(suffix, apexInfo.ApexVariationName)
Dan Willemsenb13a9482020-02-14 11:25:54 -08001899 }
Colin Cross67a5c132017-05-09 13:45:28 -07001900
1901 ctx.Variable(pctx, "moduleDesc", desc)
1902
1903 s := ""
1904 if len(suffix) > 0 {
1905 s = " [" + strings.Join(suffix, " ") + "]"
1906 }
1907 ctx.Variable(pctx, "moduleDescSuffix", s)
1908
Dan Willemsen569edc52018-11-19 09:33:29 -08001909 // Some common property checks for properties that will be used later in androidmk.go
Paul Duffin89968e32020-11-23 18:17:03 +00001910 checkDistProperties(ctx, "dist", &m.distProperties.Dist)
1911 for i, _ := range m.distProperties.Dists {
1912 checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
Dan Willemsen569edc52018-11-19 09:33:29 -08001913 }
1914
Colin Cross4157e882019-06-06 16:57:04 -07001915 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001916 // ensure all direct android.Module deps are enabled
1917 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01001918 if m, ok := bm.(Module); ok {
1919 ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps)
Jooyung Hand48f3c32019-08-23 11:18:57 +09001920 }
1921 })
1922
Bob Badoura75b0572020-02-18 20:21:55 -08001923 m.noticeFiles = make([]Path, 0)
1924 optPath := OptionalPath{}
1925 notice := proptools.StringDefault(m.commonProperties.Notice, "")
Colin Cross4157e882019-06-06 16:57:04 -07001926 if module := SrcIsModule(notice); module != "" {
Bob Badoura75b0572020-02-18 20:21:55 -08001927 optPath = ctx.ExpandOptionalSource(&notice, "notice")
1928 } else if notice != "" {
Jiyong Park52818fc2019-03-18 12:01:38 +09001929 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Bob Badoura75b0572020-02-18 20:21:55 -08001930 optPath = ExistentPathForSource(ctx, noticePath)
1931 }
1932 if optPath.Valid() {
1933 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1934 } else {
1935 for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} {
1936 noticePath := filepath.Join(ctx.ModuleDir(), notice)
1937 optPath = ExistentPathForSource(ctx, noticePath)
1938 if optPath.Valid() {
1939 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1940 }
1941 }
Jaewoong Jung62707f72018-11-16 13:26:43 -08001942 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001943
Bob Badour37af0462021-01-07 03:34:31 +00001944 licensesPropertyFlattener(ctx)
1945 if ctx.Failed() {
1946 return
1947 }
1948
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001949 m.module.GenerateAndroidBuildActions(ctx)
1950 if ctx.Failed() {
1951 return
1952 }
1953
Jiyong Park4d861072021-03-03 20:02:42 +09001954 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1955 rcDir := PathForModuleInstall(ctx, "etc", "init")
1956 for _, src := range m.initRcPaths {
1957 ctx.PackageFile(rcDir, filepath.Base(src.String()), src)
1958 }
1959
1960 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
1961 vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest")
1962 for _, src := range m.vintfFragmentsPaths {
1963 ctx.PackageFile(vintfDir, filepath.Base(src.String()), src)
1964 }
1965
Paul Duffinaf970a22020-11-23 23:32:56 +00001966 // Create the set of tagged dist files after calling GenerateAndroidBuildActions
1967 // as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the
1968 // output paths being set which must be done before or during
1969 // GenerateAndroidBuildActions.
1970 m.distFiles = m.GenerateTaggedDistFiles(ctx)
1971 if ctx.Failed() {
1972 return
1973 }
1974
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001975 m.installFiles = append(m.installFiles, ctx.installFiles...)
1976 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07001977 m.tidyFiles = append(m.tidyFiles, ctx.tidyFiles...)
Jiyong Park073ea552020-11-09 14:08:34 +09001978 m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
Colin Crossc3d87d32020-06-04 13:25:17 -07001979 for k, v := range ctx.phonies {
1980 m.phonies[k] = append(m.phonies[k], v...)
1981 }
Colin Crossdc35e212019-06-06 16:13:11 -07001982 } else if ctx.Config().AllowMissingDependencies() {
1983 // If the module is not enabled it will not create any build rules, nothing will call
1984 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1985 // and report them as an error even when AllowMissingDependencies = true. Call
1986 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1987 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001988 }
1989
Colin Cross4157e882019-06-06 16:57:04 -07001990 if m == ctx.FinalModule().(Module).base() {
1991 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001992 if ctx.Failed() {
1993 return
1994 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001995 }
Colin Crosscec81712017-07-13 14:43:27 -07001996
Colin Cross5d583952020-11-24 16:21:24 -08001997 m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001998 m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
Colin Cross5d583952020-11-24 16:21:24 -08001999
Colin Cross4157e882019-06-06 16:57:04 -07002000 m.buildParams = ctx.buildParams
2001 m.ruleParams = ctx.ruleParams
2002 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08002003}
2004
Paul Duffin89968e32020-11-23 18:17:03 +00002005// Check the supplied dist structure to make sure that it is valid.
2006//
2007// property - the base property, e.g. dist or dists[1], which is combined with the
2008// name of the nested property to produce the full property, e.g. dist.dest or
2009// dists[1].dir.
2010func checkDistProperties(ctx *moduleContext, property string, dist *Dist) {
2011 if dist.Dest != nil {
2012 _, err := validateSafePath(*dist.Dest)
2013 if err != nil {
2014 ctx.PropertyErrorf(property+".dest", "%s", err.Error())
2015 }
2016 }
2017 if dist.Dir != nil {
2018 _, err := validateSafePath(*dist.Dir)
2019 if err != nil {
2020 ctx.PropertyErrorf(property+".dir", "%s", err.Error())
2021 }
2022 }
2023 if dist.Suffix != nil {
2024 if strings.Contains(*dist.Suffix, "/") {
2025 ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.")
2026 }
2027 }
2028
2029}
2030
Colin Cross1184b642019-12-30 18:43:07 -08002031type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08002032 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08002033
2034 kind moduleKind
2035 config Config
2036}
2037
2038func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
Liz Kammera830f3a2020-11-10 10:50:34 -08002039 return Glob(e, globPattern, excludes)
Colin Cross1184b642019-12-30 18:43:07 -08002040}
2041
2042func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Liz Kammera830f3a2020-11-10 10:50:34 -08002043 return GlobFiles(e, globPattern, excludes)
Colin Cross1184b642019-12-30 18:43:07 -08002044}
2045
Colin Cross988414c2020-01-11 01:11:46 +00002046func (b *earlyModuleContext) IsSymlink(path Path) bool {
2047 fileInfo, err := b.config.fs.Lstat(path.String())
2048 if err != nil {
2049 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
2050 }
2051 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
2052}
2053
2054func (b *earlyModuleContext) Readlink(path Path) string {
2055 dest, err := b.config.fs.Readlink(path.String())
2056 if err != nil {
2057 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
2058 }
2059 return dest
2060}
2061
Colin Cross1184b642019-12-30 18:43:07 -08002062func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08002063 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08002064 return module
2065}
2066
2067func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08002068 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08002069}
2070
2071func (e *earlyModuleContext) AConfig() Config {
2072 return e.config
2073}
2074
2075func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
2076 return DeviceConfig{e.config.deviceConfig}
2077}
2078
2079func (e *earlyModuleContext) Platform() bool {
2080 return e.kind == platformModule
2081}
2082
2083func (e *earlyModuleContext) DeviceSpecific() bool {
2084 return e.kind == deviceSpecificModule
2085}
2086
2087func (e *earlyModuleContext) SocSpecific() bool {
2088 return e.kind == socSpecificModule
2089}
2090
2091func (e *earlyModuleContext) ProductSpecific() bool {
2092 return e.kind == productSpecificModule
2093}
2094
2095func (e *earlyModuleContext) SystemExtSpecific() bool {
2096 return e.kind == systemExtSpecificModule
2097}
2098
Colin Cross133ebef2020-08-14 17:38:45 -07002099func (e *earlyModuleContext) Namespace() *Namespace {
2100 return e.EarlyModuleContext.Namespace().(*Namespace)
2101}
2102
Colin Cross1184b642019-12-30 18:43:07 -08002103type baseModuleContext struct {
2104 bp blueprint.BaseModuleContext
2105 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08002106 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07002107 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07002108 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07002109 targetPrimary bool
2110 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07002111
2112 walkPath []Module
Paul Duffinc5192442020-03-31 11:31:36 +01002113 tagPath []blueprint.DependencyTag
Colin Crossdc35e212019-06-06 16:13:11 -07002114
2115 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Chris Parsons5a34ffb2021-07-21 14:34:58 -04002116
2117 bazelConversionMode bool
Colin Crossf6566ed2015-03-24 11:13:38 -07002118}
2119
Chris Parsons5a34ffb2021-07-21 14:34:58 -04002120func (b *baseModuleContext) BazelConversionMode() bool {
2121 return b.bazelConversionMode
2122}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002123func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
2124 return b.bp.OtherModuleName(m)
2125}
2126func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08002127func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Hancd87c692020-02-26 02:05:18 +09002128 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08002129}
2130func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
2131 return b.bp.OtherModuleDependencyTag(m)
2132}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002133func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00002134func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
2135 return b.bp.OtherModuleDependencyVariantExists(variations, name)
2136}
Martin Stjernholm408ffd82021-05-05 15:27:31 +01002137func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool {
2138 return b.bp.OtherModuleFarDependencyVariantExists(variations, name)
2139}
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00002140func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
2141 return b.bp.OtherModuleReverseDependencyVariantExists(name)
2142}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002143func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
2144 return b.bp.OtherModuleType(m)
2145}
Colin Crossd27e7b82020-07-02 11:38:17 -07002146func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
2147 return b.bp.OtherModuleProvider(m, provider)
2148}
2149func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
2150 return b.bp.OtherModuleHasProvider(m, provider)
2151}
2152func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
2153 return b.bp.Provider(provider)
2154}
2155func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
2156 return b.bp.HasProvider(provider)
2157}
2158func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
2159 b.bp.SetProvider(provider, value)
2160}
Colin Cross1184b642019-12-30 18:43:07 -08002161
2162func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2163 return b.bp.GetDirectDepWithTag(name, tag)
2164}
2165
Paul Duffinf88d8e02020-05-07 20:21:34 +01002166func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
2167 return b.bp
2168}
2169
Colin Cross25de6c32019-06-06 14:29:25 -07002170type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07002171 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07002172 baseModuleContext
Jiyong Park073ea552020-11-09 14:08:34 +09002173 packagingSpecs []PackagingSpec
Colin Cross897266e2020-02-13 13:22:08 -08002174 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002175 checkbuildFiles Paths
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002176 tidyFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07002177 module Module
Colin Crossc3d87d32020-06-04 13:25:17 -07002178 phonies map[string]Paths
Colin Crosscec81712017-07-13 14:43:27 -07002179
2180 // For tests
Colin Crossae887032017-10-23 17:16:14 -07002181 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08002182 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08002183 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08002184}
2185
Colin Crossb88b3c52019-06-10 15:15:17 -07002186func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
2187 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07002188 Rule: ErrorRule,
2189 Description: params.Description,
2190 Output: params.Output,
2191 Outputs: params.Outputs,
2192 ImplicitOutput: params.ImplicitOutput,
2193 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08002194 Args: map[string]string{
2195 "error": err.Error(),
2196 },
Colin Crossb88b3c52019-06-10 15:15:17 -07002197 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002198}
2199
Colin Cross25de6c32019-06-06 14:29:25 -07002200func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
2201 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08002202}
2203
Jingwen Chence679d22020-09-23 04:30:02 +00002204func validateBuildParams(params blueprint.BuildParams) error {
2205 // Validate that the symlink outputs are declared outputs or implicit outputs
2206 allOutputs := map[string]bool{}
2207 for _, output := range params.Outputs {
2208 allOutputs[output] = true
2209 }
2210 for _, output := range params.ImplicitOutputs {
2211 allOutputs[output] = true
2212 }
2213 for _, symlinkOutput := range params.SymlinkOutputs {
2214 if !allOutputs[symlinkOutput] {
2215 return fmt.Errorf(
2216 "Symlink output %s is not a declared output or implicit output",
2217 symlinkOutput)
2218 }
2219 }
2220 return nil
2221}
2222
2223// Convert build parameters from their concrete Android types into their string representations,
2224// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
Colin Cross0875c522017-11-28 17:34:01 -08002225func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002226 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002227 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08002228 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08002229 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002230 Outputs: params.Outputs.Strings(),
2231 ImplicitOutputs: params.ImplicitOutputs.Strings(),
Jingwen Chence679d22020-09-23 04:30:02 +00002232 SymlinkOutputs: params.SymlinkOutputs.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002233 Inputs: params.Inputs.Strings(),
2234 Implicits: params.Implicits.Strings(),
2235 OrderOnly: params.OrderOnly.Strings(),
Colin Cross824f1162020-07-16 13:07:51 -07002236 Validations: params.Validations.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002237 Args: params.Args,
2238 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002239 }
2240
Colin Cross33bfb0a2016-11-21 17:23:08 -08002241 if params.Depfile != nil {
2242 bparams.Depfile = params.Depfile.String()
2243 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002244 if params.Output != nil {
2245 bparams.Outputs = append(bparams.Outputs, params.Output.String())
2246 }
Jingwen Chence679d22020-09-23 04:30:02 +00002247 if params.SymlinkOutput != nil {
2248 bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String())
2249 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002250 if params.ImplicitOutput != nil {
2251 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
2252 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002253 if params.Input != nil {
2254 bparams.Inputs = append(bparams.Inputs, params.Input.String())
2255 }
2256 if params.Implicit != nil {
2257 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
2258 }
Colin Cross824f1162020-07-16 13:07:51 -07002259 if params.Validation != nil {
2260 bparams.Validations = append(bparams.Validations, params.Validation.String())
2261 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002262
Colin Cross0b9f31f2019-02-28 11:00:01 -08002263 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
2264 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
Jingwen Chence679d22020-09-23 04:30:02 +00002265 bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs)
Colin Cross0b9f31f2019-02-28 11:00:01 -08002266 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
2267 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
2268 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
Colin Cross824f1162020-07-16 13:07:51 -07002269 bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
2270 bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
Colin Crossfe4bc362018-09-12 10:02:13 -07002271
Colin Cross0875c522017-11-28 17:34:01 -08002272 return bparams
2273}
2274
Colin Cross25de6c32019-06-06 14:29:25 -07002275func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
2276 if m.config.captureBuild {
2277 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08002278 }
2279
Colin Crossdc35e212019-06-06 16:13:11 -07002280 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08002281}
2282
Colin Cross25de6c32019-06-06 14:29:25 -07002283func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08002284 argNames ...string) blueprint.Rule {
2285
Ramy Medhat944839a2020-03-31 22:14:52 -04002286 if m.config.UseRemoteBuild() {
2287 if params.Pool == nil {
2288 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
2289 // jobs to the local parallelism value
2290 params.Pool = localPool
2291 } else if params.Pool == remotePool {
2292 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
2293 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
2294 // parallelism.
2295 params.Pool = nil
2296 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07002297 }
2298
Colin Crossdc35e212019-06-06 16:13:11 -07002299 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08002300
Colin Cross25de6c32019-06-06 14:29:25 -07002301 if m.config.captureBuild {
2302 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08002303 }
2304
2305 return rule
Colin Cross0875c522017-11-28 17:34:01 -08002306}
2307
Colin Cross25de6c32019-06-06 14:29:25 -07002308func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07002309 if params.Description != "" {
2310 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
2311 }
2312
2313 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
2314 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
2315 m.ModuleName(), strings.Join(missingDeps, ", ")))
2316 }
2317
Colin Cross25de6c32019-06-06 14:29:25 -07002318 if m.config.captureBuild {
2319 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08002320 }
2321
Jingwen Chence679d22020-09-23 04:30:02 +00002322 bparams := convertBuildParams(params)
2323 err := validateBuildParams(bparams)
2324 if err != nil {
2325 m.ModuleErrorf(
2326 "%s: build parameter validation failed: %s",
2327 m.ModuleName(),
2328 err.Error())
2329 }
2330 m.bp.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002331}
Colin Crossc3d87d32020-06-04 13:25:17 -07002332
2333func (m *moduleContext) Phony(name string, deps ...Path) {
2334 addPhony(m.config, name, deps...)
2335}
2336
Colin Cross25de6c32019-06-06 14:29:25 -07002337func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07002338 var missingDeps []string
2339 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07002340 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07002341 missingDeps = FirstUniqueStrings(missingDeps)
2342 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08002343}
2344
Colin Crossdc35e212019-06-06 16:13:11 -07002345func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002346 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002347 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07002348 *missingDeps = append(*missingDeps, deps...)
2349 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002350 }
2351}
2352
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002353type AllowDisabledModuleDependency interface {
2354 blueprint.DependencyTag
2355 AllowDisabledModuleDependency(target Module) bool
2356}
2357
2358func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07002359 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07002360
2361 if !strict {
2362 return aModule
2363 }
2364
Colin Cross380c69a2019-06-10 17:49:58 +00002365 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002366 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00002367 return nil
2368 }
2369
2370 if !aModule.Enabled() {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002371 if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) {
2372 if b.Config().AllowMissingDependencies() {
2373 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
2374 } else {
2375 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
2376 }
Colin Cross380c69a2019-06-10 17:49:58 +00002377 }
2378 return nil
2379 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002380 return aModule
2381}
2382
Liz Kammer2b50ce62021-04-26 15:47:28 -04002383type dep struct {
2384 mod blueprint.Module
2385 tag blueprint.DependencyTag
2386}
2387
2388func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep {
Jiyong Parkf2976302019-04-17 21:47:37 +09002389 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07002390 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Liz Kammer356f7d42021-01-26 09:18:53 -05002391 if aModule, _ := module.(Module); aModule != nil {
2392 if aModule.base().BaseModuleName() == name {
2393 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
2394 if tag == nil || returnedTag == tag {
2395 deps = append(deps, dep{aModule, returnedTag})
2396 }
2397 }
2398 } else if b.bp.OtherModuleName(module) == name {
2399 returnedTag := b.bp.OtherModuleDependencyTag(module)
Jiyong Parkf2976302019-04-17 21:47:37 +09002400 if tag == nil || returnedTag == tag {
Liz Kammer356f7d42021-01-26 09:18:53 -05002401 deps = append(deps, dep{module, returnedTag})
Jiyong Parkf2976302019-04-17 21:47:37 +09002402 }
2403 }
2404 })
Liz Kammer2b50ce62021-04-26 15:47:28 -04002405 return deps
2406}
2407
2408func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
2409 deps := b.getDirectDepsInternal(name, tag)
Jiyong Parkf2976302019-04-17 21:47:37 +09002410 if len(deps) == 1 {
2411 return deps[0].mod, deps[0].tag
2412 } else if len(deps) >= 2 {
2413 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07002414 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09002415 } else {
2416 return nil, nil
2417 }
2418}
2419
Liz Kammer2b50ce62021-04-26 15:47:28 -04002420func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module, blueprint.DependencyTag) {
2421 foundDeps := b.getDirectDepsInternal(name, nil)
2422 deps := map[blueprint.Module]bool{}
2423 for _, dep := range foundDeps {
2424 deps[dep.mod] = true
2425 }
2426 if len(deps) == 1 {
2427 return foundDeps[0].mod, foundDeps[0].tag
2428 } else if len(deps) >= 2 {
2429 // this could happen if two dependencies have the same name in different namespaces
2430 // TODO(b/186554727): this should not occur if namespaces are handled within
2431 // getDirectDepsInternal.
2432 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
2433 name, b.ModuleName()))
2434 } else {
2435 return nil, nil
2436 }
2437}
2438
Colin Crossdc35e212019-06-06 16:13:11 -07002439func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07002440 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07002441 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07002442 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002443 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07002444 deps = append(deps, aModule)
2445 }
2446 }
2447 })
2448 return deps
2449}
2450
Colin Cross25de6c32019-06-06 14:29:25 -07002451func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2452 module, _ := m.getDirectDepInternal(name, tag)
2453 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09002454}
2455
Liz Kammer2b50ce62021-04-26 15:47:28 -04002456// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
2457// name, or nil if none exists. If there are multiple dependencies on the same module it returns the
2458// first DependencyTag.
Colin Crossdc35e212019-06-06 16:13:11 -07002459func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
Liz Kammer2b50ce62021-04-26 15:47:28 -04002460 return b.getDirectDepFirstTag(name)
Jiyong Parkf2976302019-04-17 21:47:37 +09002461}
2462
Chris Parsons5a34ffb2021-07-21 14:34:58 -04002463func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) {
2464 if !b.BazelConversionMode() {
2465 panic("cannot call ModuleFromName if not in bazel conversion mode")
2466 }
Chris Parsonsa66c0b52021-07-23 11:02:07 -04002467 if moduleName, _ := SrcIsModuleWithTag(name); moduleName != "" {
Chris Parsons5a34ffb2021-07-21 14:34:58 -04002468 return b.bp.ModuleFromName(moduleName)
2469 } else {
2470 return b.bp.ModuleFromName(name)
2471 }
2472}
2473
Colin Crossdc35e212019-06-06 16:13:11 -07002474func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002475 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08002476}
2477
Colin Crossdc35e212019-06-06 16:13:11 -07002478func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002479 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002480 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002481 visit(aModule)
2482 }
2483 })
2484}
2485
Colin Crossdc35e212019-06-06 16:13:11 -07002486func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002487 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002488 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002489 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08002490 visit(aModule)
2491 }
2492 }
2493 })
2494}
2495
Colin Crossdc35e212019-06-06 16:13:11 -07002496func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002497 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002498 // pred
2499 func(module blueprint.Module) bool {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002500 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002501 return pred(aModule)
2502 } else {
2503 return false
2504 }
2505 },
2506 // visit
2507 func(module blueprint.Module) {
2508 visit(module.(Module))
2509 })
2510}
2511
Colin Crossdc35e212019-06-06 16:13:11 -07002512func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002513 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002514 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002515 visit(aModule)
2516 }
2517 })
2518}
2519
Colin Crossdc35e212019-06-06 16:13:11 -07002520func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002521 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002522 // pred
2523 func(module blueprint.Module) bool {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002524 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002525 return pred(aModule)
2526 } else {
2527 return false
2528 }
2529 },
2530 // visit
2531 func(module blueprint.Module) {
2532 visit(module.(Module))
2533 })
2534}
2535
Colin Crossdc35e212019-06-06 16:13:11 -07002536func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08002537 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08002538}
2539
Colin Crossdc35e212019-06-06 16:13:11 -07002540func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
2541 b.walkPath = []Module{b.Module()}
Paul Duffinc5192442020-03-31 11:31:36 +01002542 b.tagPath = []blueprint.DependencyTag{}
Colin Cross1184b642019-12-30 18:43:07 -08002543 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002544 childAndroidModule, _ := child.(Module)
2545 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07002546 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002547 // record walkPath before visit
2548 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
2549 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
Paul Duffinc5192442020-03-31 11:31:36 +01002550 b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
Colin Crossdc35e212019-06-06 16:13:11 -07002551 }
2552 b.walkPath = append(b.walkPath, childAndroidModule)
Paul Duffinc5192442020-03-31 11:31:36 +01002553 b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07002554 return visit(childAndroidModule, parentAndroidModule)
2555 } else {
2556 return false
2557 }
2558 })
2559}
2560
Colin Crossdc35e212019-06-06 16:13:11 -07002561func (b *baseModuleContext) GetWalkPath() []Module {
2562 return b.walkPath
2563}
2564
Paul Duffinc5192442020-03-31 11:31:36 +01002565func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
2566 return b.tagPath
2567}
2568
Colin Cross4dfacf92020-09-16 19:22:27 -07002569func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
2570 b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
2571 visit(module.(Module))
2572 })
2573}
2574
2575func (b *baseModuleContext) PrimaryModule() Module {
2576 return b.bp.PrimaryModule().(Module)
2577}
2578
2579func (b *baseModuleContext) FinalModule() Module {
2580 return b.bp.FinalModule().(Module)
2581}
2582
Bob Badour07065cd2021-02-05 19:59:11 -08002583// IsMetaDependencyTag returns true for cross-cutting metadata dependencies.
2584func IsMetaDependencyTag(tag blueprint.DependencyTag) bool {
2585 if tag == licenseKindTag {
2586 return true
2587 } else if tag == licensesTag {
2588 return true
2589 }
2590 return false
2591}
2592
Jiyong Park1c7e9622020-05-07 16:12:13 +09002593// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
2594// a dependency tag.
Colin Cross6e511a92020-07-27 21:26:48 -07002595var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002596
2597// PrettyPrintTag returns string representation of the tag, but prefers
2598// custom String() method if available.
2599func PrettyPrintTag(tag blueprint.DependencyTag) string {
2600 // Use tag's custom String() method if available.
2601 if stringer, ok := tag.(fmt.Stringer); ok {
2602 return stringer.String()
2603 }
2604
2605 // Otherwise, get a default string representation of the tag's struct.
Colin Cross6e511a92020-07-27 21:26:48 -07002606 tagString := fmt.Sprintf("%T: %+v", tag, tag)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002607
2608 // Remove the boilerplate from BaseDependencyTag as it adds no value.
2609 tagString = tagCleaner.ReplaceAllString(tagString, "")
2610 return tagString
2611}
2612
2613func (b *baseModuleContext) GetPathString(skipFirst bool) string {
2614 sb := strings.Builder{}
2615 tagPath := b.GetTagPath()
2616 walkPath := b.GetWalkPath()
2617 if !skipFirst {
2618 sb.WriteString(walkPath[0].String())
2619 }
2620 for i, m := range walkPath[1:] {
2621 sb.WriteString("\n")
2622 sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
2623 sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
2624 }
2625 return sb.String()
2626}
2627
Colin Crossdc35e212019-06-06 16:13:11 -07002628func (m *moduleContext) ModuleSubDir() string {
2629 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08002630}
2631
Colin Cross0ea8ba82019-06-06 14:33:29 -07002632func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002633 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07002634}
2635
Colin Cross0ea8ba82019-06-06 14:33:29 -07002636func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002637 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07002638}
2639
Colin Cross0ea8ba82019-06-06 14:33:29 -07002640func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002641 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07002642}
2643
Colin Cross0ea8ba82019-06-06 14:33:29 -07002644func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07002645 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08002646}
2647
Colin Cross0ea8ba82019-06-06 14:33:29 -07002648func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002649 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08002650}
2651
Colin Cross0ea8ba82019-06-06 14:33:29 -07002652func (b *baseModuleContext) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09002653 return b.os.Class == Host
Colin Crossf6566ed2015-03-24 11:13:38 -07002654}
2655
Colin Cross0ea8ba82019-06-06 14:33:29 -07002656func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002657 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07002658}
2659
Colin Cross0ea8ba82019-06-06 14:33:29 -07002660func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002661 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07002662}
2663
Colin Cross0ea8ba82019-06-06 14:33:29 -07002664func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002665 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07002666}
2667
Colin Cross0ea8ba82019-06-06 14:33:29 -07002668func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002669 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07002670}
2671
Colin Cross0ea8ba82019-06-06 14:33:29 -07002672func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002673 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07002674 return true
2675 }
Colin Cross25de6c32019-06-06 14:29:25 -07002676 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07002677}
2678
Jiyong Park5baac542018-08-28 09:55:37 +09002679// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09002680// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07002681func (m *ModuleBase) MakeAsPlatform() {
2682 m.commonProperties.Vendor = boolPtr(false)
2683 m.commonProperties.Proprietary = boolPtr(false)
2684 m.commonProperties.Soc_specific = boolPtr(false)
2685 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09002686 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09002687}
2688
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002689func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09002690 m.commonProperties.Vendor = boolPtr(false)
2691 m.commonProperties.Proprietary = boolPtr(false)
2692 m.commonProperties.Soc_specific = boolPtr(false)
2693 m.commonProperties.Product_specific = boolPtr(false)
2694 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002695}
2696
Jooyung Han344d5432019-08-23 11:17:39 +09002697// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
2698func (m *ModuleBase) IsNativeBridgeSupported() bool {
2699 return proptools.Bool(m.commonProperties.Native_bridge_supported)
2700}
2701
Colin Cross25de6c32019-06-06 14:29:25 -07002702func (m *moduleContext) InstallInData() bool {
2703 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08002704}
2705
Jaewoong Jung0949f312019-09-11 10:25:18 -07002706func (m *moduleContext) InstallInTestcases() bool {
2707 return m.module.InstallInTestcases()
2708}
2709
Colin Cross25de6c32019-06-06 14:29:25 -07002710func (m *moduleContext) InstallInSanitizerDir() bool {
2711 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002712}
2713
Yifan Hong1b3348d2020-01-21 15:53:22 -08002714func (m *moduleContext) InstallInRamdisk() bool {
2715 return m.module.InstallInRamdisk()
2716}
2717
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002718func (m *moduleContext) InstallInVendorRamdisk() bool {
2719 return m.module.InstallInVendorRamdisk()
2720}
2721
Inseob Kim08758f02021-04-08 21:13:22 +09002722func (m *moduleContext) InstallInDebugRamdisk() bool {
2723 return m.module.InstallInDebugRamdisk()
2724}
2725
Colin Cross25de6c32019-06-06 14:29:25 -07002726func (m *moduleContext) InstallInRecovery() bool {
2727 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002728}
2729
Colin Cross90ba5f42019-10-02 11:10:58 -07002730func (m *moduleContext) InstallInRoot() bool {
2731 return m.module.InstallInRoot()
2732}
2733
Colin Cross607d8582019-07-29 16:44:46 -07002734func (m *moduleContext) InstallBypassMake() bool {
2735 return m.module.InstallBypassMake()
2736}
2737
Jiyong Park87788b52020-09-01 12:37:45 +09002738func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
Colin Cross6e359402020-02-10 15:29:54 -08002739 return m.module.InstallForceOS()
2740}
2741
Kiyoung Kimae11c232021-07-19 11:38:04 +09002742func (m *moduleContext) InstallInVendor() bool {
2743 return m.module.InstallInVendor()
2744}
2745
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002746func (m *moduleContext) skipInstall() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002747 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07002748 return true
2749 }
2750
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002751 if m.module.base().commonProperties.HideFromMake {
2752 return true
2753 }
2754
Colin Cross3607f212018-05-07 15:28:05 -07002755 // We'll need a solution for choosing which of modules with the same name in different
2756 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
2757 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07002758 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07002759 return true
2760 }
2761
Colin Cross25de6c32019-06-06 14:29:25 -07002762 if m.Device() {
Jingwen Chencda22c92020-11-23 00:22:30 -05002763 if m.Config().KatiEnabled() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07002764 return true
2765 }
Colin Cross893d8162017-04-26 17:34:03 -07002766 }
2767
2768 return false
2769}
2770
Colin Cross70dda7e2019-10-01 22:05:35 -07002771func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
2772 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002773 return m.installFile(installPath, name, srcPath, deps, false)
Colin Cross5c517922017-08-31 12:29:17 -07002774}
2775
Colin Cross70dda7e2019-10-01 22:05:35 -07002776func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
2777 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002778 return m.installFile(installPath, name, srcPath, deps, true)
Colin Cross5c517922017-08-31 12:29:17 -07002779}
2780
Colin Cross41589502020-12-01 14:00:21 -08002781func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec {
2782 fullInstallPath := installPath.Join(m, name)
2783 return m.packageFile(fullInstallPath, srcPath, false)
2784}
2785
2786func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
2787 spec := PackagingSpec{
2788 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2789 srcPath: srcPath,
2790 symlinkTarget: "",
2791 executable: executable,
2792 }
2793 m.packagingSpecs = append(m.packagingSpecs, spec)
2794 return spec
2795}
2796
Jiyong Park073ea552020-11-09 14:08:34 +09002797func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07002798
Colin Cross25de6c32019-06-06 14:29:25 -07002799 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002800 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08002801
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002802 if !m.skipInstall() {
Colin Cross5d583952020-11-24 16:21:24 -08002803 deps = append(deps, m.module.base().installFilesDepSet.ToList().Paths()...)
Colin Cross35cec122015-04-02 14:37:16 -07002804
Colin Cross89562dc2016-10-03 17:47:19 -07002805 var implicitDeps, orderOnlyDeps Paths
2806
Colin Cross25de6c32019-06-06 14:29:25 -07002807 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07002808 // Installed host modules might be used during the build, depend directly on their
2809 // dependencies so their timestamp is updated whenever their dependency is updated
2810 implicitDeps = deps
2811 } else {
2812 orderOnlyDeps = deps
2813 }
2814
Jiyong Park073ea552020-11-09 14:08:34 +09002815 rule := Cp
2816 if executable {
2817 rule = CpExecutable
2818 }
2819
Colin Cross25de6c32019-06-06 14:29:25 -07002820 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07002821 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07002822 Description: "install " + fullInstallPath.Base(),
2823 Output: fullInstallPath,
2824 Input: srcPath,
2825 Implicits: implicitDeps,
2826 OrderOnly: orderOnlyDeps,
Jingwen Chencda22c92020-11-23 00:22:30 -05002827 Default: !m.Config().KatiEnabled(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08002828 })
Colin Cross3f40fa42015-01-30 17:27:36 -08002829
Colin Cross25de6c32019-06-06 14:29:25 -07002830 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08002831 }
Jiyong Park073ea552020-11-09 14:08:34 +09002832
Colin Cross41589502020-12-01 14:00:21 -08002833 m.packageFile(fullInstallPath, srcPath, executable)
Jiyong Park073ea552020-11-09 14:08:34 +09002834
Colin Cross25de6c32019-06-06 14:29:25 -07002835 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002836
Colin Cross35cec122015-04-02 14:37:16 -07002837 return fullInstallPath
2838}
2839
Colin Cross70dda7e2019-10-01 22:05:35 -07002840func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002841 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002842 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08002843
Jiyong Park073ea552020-11-09 14:08:34 +09002844 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
2845 if err != nil {
2846 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
2847 }
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002848 if !m.skipInstall() {
Colin Crossce75d2c2016-10-06 16:12:58 -07002849
Colin Cross25de6c32019-06-06 14:29:25 -07002850 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07002851 Rule: Symlink,
2852 Description: "install symlink " + fullInstallPath.Base(),
2853 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08002854 Input: srcPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002855 Default: !m.Config().KatiEnabled(),
Colin Cross12fc4972016-01-11 12:49:11 -08002856 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08002857 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08002858 },
2859 })
Colin Cross3854a602016-01-11 12:49:11 -08002860
Colin Cross25de6c32019-06-06 14:29:25 -07002861 m.installFiles = append(m.installFiles, fullInstallPath)
2862 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08002863 }
Jiyong Park073ea552020-11-09 14:08:34 +09002864
2865 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2866 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2867 srcPath: nil,
2868 symlinkTarget: relPath,
2869 executable: false,
2870 })
2871
Colin Cross3854a602016-01-11 12:49:11 -08002872 return fullInstallPath
2873}
2874
Jiyong Parkf1194352019-02-25 11:05:47 +09002875// installPath/name -> absPath where absPath might be a path that is available only at runtime
2876// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07002877func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002878 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002879 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09002880
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002881 if !m.skipInstall() {
Colin Cross25de6c32019-06-06 14:29:25 -07002882 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09002883 Rule: Symlink,
2884 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
2885 Output: fullInstallPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002886 Default: !m.Config().KatiEnabled(),
Jiyong Parkf1194352019-02-25 11:05:47 +09002887 Args: map[string]string{
2888 "fromPath": absPath,
2889 },
2890 })
2891
Colin Cross25de6c32019-06-06 14:29:25 -07002892 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09002893 }
Jiyong Park073ea552020-11-09 14:08:34 +09002894
2895 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2896 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2897 srcPath: nil,
2898 symlinkTarget: absPath,
2899 executable: false,
2900 })
2901
Jiyong Parkf1194352019-02-25 11:05:47 +09002902 return fullInstallPath
2903}
2904
Colin Cross25de6c32019-06-06 14:29:25 -07002905func (m *moduleContext) CheckbuildFile(srcPath Path) {
2906 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08002907}
2908
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07002909func (m *moduleContext) TidyFile(srcPath Path) {
2910 m.tidyFiles = append(m.tidyFiles, srcPath)
2911}
2912
Colin Crossc20dc852020-11-10 12:27:45 -08002913func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
2914 return m.bp
2915}
2916
Paul Duffine6ba0722021-07-12 20:12:12 +01002917// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name"
2918// into the module name, or empty string if the input was not a module reference.
Colin Cross41955e82019-05-29 14:40:35 -07002919func SrcIsModule(s string) (module string) {
Paul Duffine6ba0722021-07-12 20:12:12 +01002920 if len(s) > 1 {
2921 if s[0] == ':' {
2922 module = s[1:]
2923 if !isUnqualifiedModuleName(module) {
2924 // The module name should be unqualified but is not so do not treat it as a module.
2925 module = ""
2926 }
2927 } else if s[0] == '/' && s[1] == '/' {
2928 module = s
2929 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002930 }
Paul Duffine6ba0722021-07-12 20:12:12 +01002931 return module
Colin Cross068e0fe2016-12-13 15:23:47 -08002932}
2933
Yi-Yo Chiangba9ea322021-07-15 17:18:21 +08002934// SrcIsModuleWithTag decodes module references in the format ":unqualified-name{.tag}" or
2935// "//namespace:name{.tag}" into the module name and tag, ":unqualified-name" or "//namespace:name"
2936// into the module name and an empty string for the tag, or empty strings if the input was not a
2937// module reference.
Colin Cross41955e82019-05-29 14:40:35 -07002938func SrcIsModuleWithTag(s string) (module, tag string) {
Paul Duffine6ba0722021-07-12 20:12:12 +01002939 if len(s) > 1 {
2940 if s[0] == ':' {
2941 module = s[1:]
2942 } else if s[0] == '/' && s[1] == '/' {
2943 module = s
2944 }
2945
2946 if module != "" {
2947 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2948 if module[len(module)-1] == '}' {
2949 tag = module[tagStart+1 : len(module)-1]
2950 module = module[:tagStart]
2951 }
2952 }
2953
2954 if s[0] == ':' && !isUnqualifiedModuleName(module) {
2955 // The module name should be unqualified but is not so do not treat it as a module.
2956 module = ""
2957 tag = ""
Colin Cross41955e82019-05-29 14:40:35 -07002958 }
2959 }
Colin Cross41955e82019-05-29 14:40:35 -07002960 }
Paul Duffine6ba0722021-07-12 20:12:12 +01002961
2962 return module, tag
2963}
2964
2965// isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e.
2966// does not contain any /.
2967func isUnqualifiedModuleName(module string) bool {
2968 return strings.IndexByte(module, '/') == -1
Colin Cross068e0fe2016-12-13 15:23:47 -08002969}
2970
Paul Duffin40131a32021-07-09 17:10:35 +01002971// sourceOrOutputDependencyTag is the dependency tag added automatically by pathDepsMutator for any
2972// module reference in a property annotated with `android:"path"` or passed to ExtractSourceDeps
2973// or ExtractSourcesDeps.
2974//
2975// If uniquely identifies the dependency that was added as it contains both the module name used to
2976// add the dependency as well as the tag. That makes it very simple to find the matching dependency
2977// in GetModuleFromPathDep as all it needs to do is find the dependency whose tag matches the tag
2978// used to add it. It does not need to check that the module name as returned by one of
2979// Module.Name(), BaseModuleContext.OtherModuleName() or ModuleBase.BaseModuleName() matches the
2980// name supplied in the tag. That means it does not need to handle differences in module names
2981// caused by prebuilt_ prefix, or fully qualified module names.
Colin Cross41955e82019-05-29 14:40:35 -07002982type sourceOrOutputDependencyTag struct {
2983 blueprint.BaseDependencyTag
Paul Duffin40131a32021-07-09 17:10:35 +01002984
2985 // The name of the module.
2986 moduleName string
2987
2988 // The tag that will be passed to the module's OutputFileProducer.OutputFiles(tag) method.
Colin Cross41955e82019-05-29 14:40:35 -07002989 tag string
2990}
2991
Paul Duffin40131a32021-07-09 17:10:35 +01002992func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag {
2993 return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag}
Colin Cross41955e82019-05-29 14:40:35 -07002994}
2995
Paul Duffind5cf92e2021-07-09 17:38:55 +01002996// IsSourceDepTag returns true if the supplied blueprint.DependencyTag is one that was used to add
2997// dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for properties
2998// tagged with `android:"path"`.
2999func IsSourceDepTag(depTag blueprint.DependencyTag) bool {
3000 _, ok := depTag.(sourceOrOutputDependencyTag)
3001 return ok
3002}
3003
3004// IsSourceDepTagWithOutputTag returns true if the supplied blueprint.DependencyTag is one that was
3005// used to add dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for
3006// properties tagged with `android:"path"` AND it was added using a module reference of
3007// :moduleName{outputTag}.
3008func IsSourceDepTagWithOutputTag(depTag blueprint.DependencyTag, outputTag string) bool {
3009 t, ok := depTag.(sourceOrOutputDependencyTag)
3010 return ok && t.tag == outputTag
3011}
3012
Colin Cross366938f2017-12-11 16:29:02 -08003013// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
3014// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08003015//
3016// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08003017func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07003018 set := make(map[string]bool)
3019
Colin Cross068e0fe2016-12-13 15:23:47 -08003020 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07003021 if m, t := SrcIsModuleWithTag(s); m != "" {
3022 if _, found := set[s]; found {
3023 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07003024 } else {
Colin Cross41955e82019-05-29 14:40:35 -07003025 set[s] = true
Paul Duffin40131a32021-07-09 17:10:35 +01003026 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07003027 }
Colin Cross068e0fe2016-12-13 15:23:47 -08003028 }
3029 }
Colin Cross068e0fe2016-12-13 15:23:47 -08003030}
3031
Colin Cross366938f2017-12-11 16:29:02 -08003032// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
3033// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08003034//
3035// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08003036func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
3037 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07003038 if m, t := SrcIsModuleWithTag(*s); m != "" {
Paul Duffin40131a32021-07-09 17:10:35 +01003039 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
Colin Cross366938f2017-12-11 16:29:02 -08003040 }
3041 }
3042}
3043
Colin Cross41955e82019-05-29 14:40:35 -07003044// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
3045// 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 -08003046type SourceFileProducer interface {
3047 Srcs() Paths
3048}
3049
Colin Cross41955e82019-05-29 14:40:35 -07003050// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00003051// 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 -07003052// listed in the property.
3053type OutputFileProducer interface {
3054 OutputFiles(tag string) (Paths, error)
3055}
3056
Colin Cross5e708052019-08-06 13:59:50 -07003057// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
3058// module produced zero paths, it reports errors to the ctx and returns nil.
3059func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
3060 paths, err := outputFilesForModule(ctx, module, tag)
3061 if err != nil {
3062 reportPathError(ctx, err)
3063 return nil
3064 }
3065 return paths
3066}
3067
3068// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
3069// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
3070func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
3071 paths, err := outputFilesForModule(ctx, module, tag)
3072 if err != nil {
3073 reportPathError(ctx, err)
3074 return nil
3075 }
3076 if len(paths) > 1 {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01003077 ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
Colin Cross5e708052019-08-06 13:59:50 -07003078 pathContextName(ctx, module))
3079 return nil
3080 }
3081 return paths[0]
3082}
3083
3084func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
3085 if outputFileProducer, ok := module.(OutputFileProducer); ok {
3086 paths, err := outputFileProducer.OutputFiles(tag)
3087 if err != nil {
3088 return nil, fmt.Errorf("failed to get output file from module %q: %s",
3089 pathContextName(ctx, module), err.Error())
3090 }
3091 if len(paths) == 0 {
3092 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
3093 }
3094 return paths, nil
Colin Cross74b1e2b2020-11-22 20:23:02 -08003095 } else if sourceFileProducer, ok := module.(SourceFileProducer); ok {
3096 if tag != "" {
3097 return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag)
3098 }
3099 paths := sourceFileProducer.Srcs()
3100 if len(paths) == 0 {
3101 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
3102 }
3103 return paths, nil
Colin Cross5e708052019-08-06 13:59:50 -07003104 } else {
3105 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
3106 }
3107}
3108
Colin Cross41589502020-12-01 14:00:21 -08003109// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to
3110// specify that they can be used as a tool by a genrule module.
Colin Crossfe17f6f2019-03-28 19:30:56 -07003111type HostToolProvider interface {
Colin Crossba9e4032020-11-24 16:32:22 -08003112 Module
Colin Cross41589502020-12-01 14:00:21 -08003113 // HostToolPath returns the path to the host tool for the module if it is one, or an invalid
3114 // OptionalPath.
Colin Crossfe17f6f2019-03-28 19:30:56 -07003115 HostToolPath() OptionalPath
3116}
3117
Colin Cross27b922f2019-03-04 22:35:41 -08003118// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
3119// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08003120//
3121// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07003122func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
3123 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07003124}
3125
Colin Cross2fafa3e2019-03-05 12:39:51 -08003126// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
3127// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08003128//
3129// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07003130func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
3131 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08003132}
3133
3134// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
3135// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
3136// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07003137func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08003138 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07003139 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08003140 }
3141 return OptionalPath{}
3142}
3143
Colin Cross25de6c32019-06-06 14:29:25 -07003144func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09003145 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08003146}
3147
Colin Cross25de6c32019-06-06 14:29:25 -07003148func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09003149 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07003150}
3151
Colin Cross25de6c32019-06-06 14:29:25 -07003152func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09003153 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07003154}
3155
Colin Cross463a90e2015-06-17 14:20:06 -07003156func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07003157 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07003158}
3159
Colin Cross0875c522017-11-28 17:34:01 -08003160func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07003161 return &buildTargetSingleton{}
3162}
3163
Colin Cross87d8b562017-04-25 10:01:55 -07003164func parentDir(dir string) string {
3165 dir, _ = filepath.Split(dir)
3166 return filepath.Clean(dir)
3167}
3168
Colin Cross1f8c52b2015-06-16 16:38:17 -07003169type buildTargetSingleton struct{}
3170
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003171func addAncestors(ctx SingletonContext, dirMap map[string]Paths, mmName func(string) string) []string {
3172 // Ensure ancestor directories are in dirMap
3173 // Make directories build their direct subdirectories
3174 dirs := SortedStringKeys(dirMap)
3175 for _, dir := range dirs {
3176 dir := parentDir(dir)
3177 for dir != "." && dir != "/" {
3178 if _, exists := dirMap[dir]; exists {
3179 break
3180 }
3181 dirMap[dir] = nil
3182 dir = parentDir(dir)
3183 }
3184 }
3185 dirs = SortedStringKeys(dirMap)
3186 for _, dir := range dirs {
3187 p := parentDir(dir)
3188 if p != "." && p != "/" {
3189 dirMap[p] = append(dirMap[p], PathForPhony(ctx, mmName(dir)))
3190 }
3191 }
3192 return SortedStringKeys(dirMap)
3193}
3194
Colin Cross0875c522017-11-28 17:34:01 -08003195func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
3196 var checkbuildDeps Paths
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003197 var tidyDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07003198
Colin Crossc3d87d32020-06-04 13:25:17 -07003199 mmTarget := func(dir string) string {
3200 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07003201 }
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003202 mmTidyTarget := func(dir string) string {
3203 return "tidy-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
3204 }
Colin Cross87d8b562017-04-25 10:01:55 -07003205
Colin Cross0875c522017-11-28 17:34:01 -08003206 modulesInDir := make(map[string]Paths)
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003207 tidyModulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003208
Colin Cross0875c522017-11-28 17:34:01 -08003209 ctx.VisitAllModules(func(module Module) {
3210 blueprintDir := module.base().blueprintDir
3211 installTarget := module.base().installTarget
3212 checkbuildTarget := module.base().checkbuildTarget
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003213 tidyTarget := module.base().tidyTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07003214
Colin Cross0875c522017-11-28 17:34:01 -08003215 if checkbuildTarget != nil {
3216 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
3217 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
3218 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003219
Colin Cross0875c522017-11-28 17:34:01 -08003220 if installTarget != nil {
3221 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003222 }
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003223
3224 if tidyTarget != nil {
3225 tidyDeps = append(tidyDeps, tidyTarget)
3226 // tidyTarget is in modulesInDir so it will be built with "mm".
3227 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], tidyTarget)
3228 // tidyModulesInDir contains tidyTarget but not checkbuildTarget
3229 // or installTarget, so tidy targets in a directory can be built
3230 // without other checkbuild or install targets.
3231 tidyModulesInDir[blueprintDir] = append(tidyModulesInDir[blueprintDir], tidyTarget)
3232 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003233 })
3234
Dan Willemsen5ba07e82015-12-11 13:51:06 -08003235 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05003236 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08003237 suffix = "-soong"
3238 }
3239
Colin Cross1f8c52b2015-06-16 16:38:17 -07003240 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07003241 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003242
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003243 // Create a top-level tidy target that depends on all modules
3244 ctx.Phony("tidy"+suffix, tidyDeps...)
3245
3246 dirs := addAncestors(ctx, tidyModulesInDir, mmTidyTarget)
3247
3248 // Kati does not generate tidy-* phony targets yet.
3249 // Create a tidy-<directory> target that depends on all subdirectories
3250 // and modules in the directory.
3251 for _, dir := range dirs {
3252 ctx.Phony(mmTidyTarget(dir), tidyModulesInDir[dir]...)
3253 }
3254
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003255 // Make will generate the MODULES-IN-* targets
Jingwen Chencda22c92020-11-23 00:22:30 -05003256 if ctx.Config().KatiEnabled() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003257 return
3258 }
3259
Chih-Hung Hsiehd0f82fe2021-09-05 20:15:38 -07003260 dirs = addAncestors(ctx, modulesInDir, mmTarget)
Colin Cross87d8b562017-04-25 10:01:55 -07003261
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003262 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
3263 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
3264 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07003265 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07003266 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003267 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07003268
3269 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
Jiyong Park1613e552020-09-14 19:43:17 +09003270 type osAndCross struct {
3271 os OsType
3272 hostCross bool
3273 }
3274 osDeps := map[osAndCross]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08003275 ctx.VisitAllModules(func(module Module) {
3276 if module.Enabled() {
Jiyong Park1613e552020-09-14 19:43:17 +09003277 key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
3278 osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003279 }
3280 })
3281
Colin Cross0875c522017-11-28 17:34:01 -08003282 osClass := make(map[string]Paths)
Jiyong Park1613e552020-09-14 19:43:17 +09003283 for key, deps := range osDeps {
Dan Willemsen61d88b82017-09-20 17:29:08 -07003284 var className string
3285
Jiyong Park1613e552020-09-14 19:43:17 +09003286 switch key.os.Class {
Dan Willemsen61d88b82017-09-20 17:29:08 -07003287 case Host:
Jiyong Park1613e552020-09-14 19:43:17 +09003288 if key.hostCross {
3289 className = "host-cross"
3290 } else {
3291 className = "host"
3292 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07003293 case Device:
3294 className = "target"
3295 default:
3296 continue
3297 }
3298
Jiyong Park1613e552020-09-14 19:43:17 +09003299 name := className + "-" + key.os.Name
Colin Crossc3d87d32020-06-04 13:25:17 -07003300 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07003301
Colin Crossc3d87d32020-06-04 13:25:17 -07003302 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003303 }
3304
3305 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09003306 for _, class := range SortedStringKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07003307 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003308 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003309}
Colin Crossd779da42015-12-17 18:00:23 -08003310
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003311// Collect information for opening IDE project files in java/jdeps.go.
3312type IDEInfo interface {
3313 IDEInfo(ideInfo *IdeInfo)
3314 BaseModuleName() string
3315}
3316
3317// Extract the base module name from the Import name.
3318// Often the Import name has a prefix "prebuilt_".
3319// Remove the prefix explicitly if needed
3320// until we find a better solution to get the Import name.
3321type IDECustomizedModuleName interface {
3322 IDECustomizedModuleName() string
3323}
3324
3325type IdeInfo struct {
3326 Deps []string `json:"dependencies,omitempty"`
3327 Srcs []string `json:"srcs,omitempty"`
3328 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
3329 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
3330 Jars []string `json:"jars,omitempty"`
3331 Classes []string `json:"class,omitempty"`
3332 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08003333 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08003334 Paths []string `json:"path,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003335}
Paul Duffinf88d8e02020-05-07 20:21:34 +01003336
3337func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
3338 bpctx := ctx.blueprintBaseModuleContext()
3339 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
3340}
Colin Cross5d583952020-11-24 16:21:24 -08003341
3342// installPathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
3343// topological order.
3344type installPathsDepSet struct {
3345 depSet
3346}
3347
3348// newInstallPathsDepSet returns an immutable packagingSpecsDepSet with the given direct and
3349// transitive contents.
3350func newInstallPathsDepSet(direct InstallPaths, transitive []*installPathsDepSet) *installPathsDepSet {
3351 return &installPathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
3352}
3353
3354// ToList returns the installPathsDepSet flattened to a list in topological order.
3355func (d *installPathsDepSet) ToList() InstallPaths {
3356 if d == nil {
3357 return nil
3358 }
3359 return d.depSet.ToList().(InstallPaths)
3360}