blob: f745a4ab46b941e5a29d0077c94366a56f54c12b [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
Colin Cross9f35c3d2020-09-16 19:04:41 -0700226 // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
227 // direct dependencies on the same module visit will be called multiple times on that module
228 // and OtherModuleDependencyTag will return a different tag for each.
229 //
230 // The Module passed to the visit function should not be retained outside of the visit
231 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700232 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700233
234 // VisitDirectDeps calls visit for each direct dependency. If there are multiple
235 // direct dependencies on the same module visit will be called multiple times on that module
236 // and OtherModuleDependencyTag will return a different tag for each. It skips any
237 // dependencies that are not an android.Module.
238 //
239 // The Module passed to the visit function should not be retained outside of the visit
240 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700241 VisitDirectDeps(visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700242
Colin Crossdc35e212019-06-06 16:13:11 -0700243 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700244
245 // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
246 // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
247 // OtherModuleDependencyTag will return a different tag for each. It skips any
248 // dependencies that are not an android.Module.
249 //
250 // The Module passed to the visit function should not be retained outside of the visit function, it may be
251 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700252 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
253 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
254 VisitDepsDepthFirst(visit func(Module))
255 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
256 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700257
258 // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
259 // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
260 // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
261 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
262 // any dependencies that are not an android.Module.
263 //
264 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
265 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700266 WalkDeps(visit func(Module, Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700267
268 // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
269 // tree in top down order. visit may be called multiple times for the same (child, parent)
270 // pair if there are multiple direct dependencies between the child and parent with different
271 // tags. OtherModuleDependencyTag will return the tag for the currently visited
272 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
273 // to child.
274 //
275 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
276 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700277 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700278
Colin Crossdc35e212019-06-06 16:13:11 -0700279 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
280 // and returns a top-down dependency path from a start module to current child module.
281 GetWalkPath() []Module
282
Colin Cross4dfacf92020-09-16 19:22:27 -0700283 // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
284 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
285 // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
286 // only done once for all variants of a module.
287 PrimaryModule() Module
288
289 // FinalModule returns the last variant of the current module. Variants of a module are always visited in
290 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
291 // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
292 // singleton actions that are only done once for all variants of a module.
293 FinalModule() Module
294
295 // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
296 // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
297 // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
298 // data modified by the current mutator.
299 VisitAllModuleVariants(visit func(Module))
300
Paul Duffinc5192442020-03-31 11:31:36 +0100301 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
302 // and returns a top-down dependency tags path from a start module to current child module.
303 // It has one less entry than GetWalkPath() as it contains the dependency tags that
304 // exist between each adjacent pair of modules in the GetWalkPath().
305 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
306 GetTagPath() []blueprint.DependencyTag
307
Jiyong Park1c7e9622020-05-07 16:12:13 +0900308 // GetPathString is supposed to be called in visit function passed in WalkDeps()
309 // and returns a multi-line string showing the modules and dependency tags
310 // among them along the top-down dependency path from a start module to current child module.
311 // skipFirst when set to true, the output doesn't include the start module,
312 // which is already printed when this function is used along with ModuleErrorf().
313 GetPathString(skipFirst bool) string
314
Colin Crossdc35e212019-06-06 16:13:11 -0700315 AddMissingDependencies(missingDeps []string)
316
Colin Crossa1ad8d12016-06-01 17:09:44 -0700317 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700318 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000319
320 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
321 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700322 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700323 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700324 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700325 Host() bool
326 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700327 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800328 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700329 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700330 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700331 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700332}
333
Colin Cross1184b642019-12-30 18:43:07 -0800334// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700335type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800336 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800337}
338
Colin Cross635c3b02016-05-18 15:37:25 -0700339type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800340 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800341
Colin Crossc20dc852020-11-10 12:27:45 -0800342 blueprintModuleContext() blueprint.ModuleContext
343
Colin Crossae887032017-10-23 17:16:14 -0700344 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800345 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700346
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700347 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800348 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800349 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700350
Colin Cross41589502020-12-01 14:00:21 -0800351 // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
352 // with the given additional dependencies. The file is marked executable after copying.
353 //
354 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
355 // installed file will be returned by PackagingSpecs() on this module or by
356 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
357 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700358 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800359
360 // InstallFile creates a rule to copy srcPath to name in the installPath directory,
361 // with the given additional dependencies.
362 //
363 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
364 // installed file will be returned by PackagingSpecs() on this module or by
365 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
366 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700367 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800368
369 // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
370 // directory.
371 //
372 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
373 // installed file will be returned by PackagingSpecs() on this module or by
374 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
375 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700376 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800377
378 // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
379 // in the installPath directory.
380 //
381 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
382 // installed file will be returned by PackagingSpecs() on this module or by
383 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
384 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700385 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800386
387 // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
388 // the rule to copy the file. This is useful to define how a module would be packaged
389 // without installing it into the global installation directories.
390 //
391 // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by
392 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
393 // for which IsInstallDepNeeded returns true.
394 PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
395
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700396 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800397
Colin Cross8d8f8e22016-08-03 11:57:50 -0700398 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700399 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700400 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800401 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700402 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900403 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900404 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700405 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700406 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900407 InstallForceOS() (*OsType, *ArchType)
Nan Zhang6d34b302017-02-04 17:47:46 -0800408
409 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700410 HostRequiredModuleNames() []string
411 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700412
Colin Cross3f68a132017-10-23 17:10:29 -0700413 ModuleSubDir() string
414
Colin Cross0875c522017-11-28 17:34:01 -0800415 Variable(pctx PackageContext, name, value string)
416 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700417 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
418 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800419 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700420 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
421 // phony rules or real files. Phony can be called on the same name multiple times to add
422 // additional dependencies.
423 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700424
Colin Cross9f35c3d2020-09-16 19:04:41 -0700425 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
426 // but do not exist.
Colin Cross3f68a132017-10-23 17:10:29 -0700427 GetMissingDependencies() []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800428}
429
Colin Cross635c3b02016-05-18 15:37:25 -0700430type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800431 blueprint.Module
432
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700433 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
434 // but GenerateAndroidBuildActions also has access to Android-specific information.
435 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700436 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700437
Paul Duffin44f1d842020-06-26 20:17:02 +0100438 // Add dependencies to the components of a module, i.e. modules that are created
439 // by the module and which are considered to be part of the creating module.
440 //
441 // This is called before prebuilts are renamed so as to allow a dependency to be
442 // added directly to a prebuilt child module instead of depending on a source module
443 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
444 //
445 // A dependency on a prebuilt must include the "prebuilt_" prefix.
446 ComponentDepsMutator(ctx BottomUpMutatorContext)
447
Colin Cross1e676be2016-10-12 14:38:15 -0700448 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800449
Colin Cross635c3b02016-05-18 15:37:25 -0700450 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900451 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800452 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700453 Target() Target
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000454 MultiTargets() []Target
Anton Hansson1ee62c02020-06-30 11:51:53 +0100455 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -0800456 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700457 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700458 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800459 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700460 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900461 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900462 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700463 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700464 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900465 InstallForceOS() (*OsType, *ArchType)
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800466 HideFromMake()
467 IsHideFromMake() bool
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +0000468 IsSkipInstall() bool
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100469 MakeUninstallable()
Liz Kammer5ca3a622020-08-05 15:40:41 -0700470 ReplacedByPrebuilt()
471 IsReplacedByPrebuilt() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900472 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900473 InitRc() Paths
474 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800475 NoticeFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700476
477 AddProperties(props ...interface{})
478 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700479
Colin Crossae887032017-10-23 17:16:14 -0700480 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800481 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800482 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100483
Colin Cross9a362232019-07-01 15:32:45 -0700484 // String returns a string that includes the module name and variants for printing during debugging.
485 String() string
486
Paul Duffine2453c72019-05-31 14:00:04 +0100487 // Get the qualified module id for this module.
488 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
489
490 // Get information about the properties that can contain visibility rules.
491 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100492
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900493 RequiredModuleNames() []string
494 HostRequiredModuleNames() []string
495 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800496
Jiyong Park4dc2a1a2020-09-28 17:46:22 +0900497 FilesToInstall() InstallPaths
Jiyong Park073ea552020-11-09 14:08:34 +0900498 PackagingSpecs() []PackagingSpec
Colin Crossffe6b9d2020-12-01 15:40:06 -0800499
500 // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
501 // dependencies with dependency tags for which IsInstallDepNeeded() returns true.
502 TransitivePackagingSpecs() []PackagingSpec
Paul Duffine2453c72019-05-31 14:00:04 +0100503}
504
Jingwen Chenab60f122021-01-24 21:21:45 -0500505// BazelTargetModule is a lightweight wrapper interface around Module for
506// bp2build conversion purposes.
507//
508// In bp2build's bootstrap.Main execution, Soong runs an alternate pipeline of
509// mutators that creates BazelTargetModules from regular Module objects,
510// performing the mapping from Soong properties to Bazel rule attributes in the
511// process. This process may optionally create additional BazelTargetModules,
512// resulting in a 1:many mapping.
513//
514// bp2build.Codegen is then responsible for visiting all modules in the graph,
515// filtering for BazelTargetModules, and code-generating BUILD targets from
516// them.
Jingwen Chen73850672020-12-14 08:25:34 -0500517type BazelTargetModule interface {
518 Module
519
Liz Kammerfc46bc12021-02-19 11:06:17 -0500520 bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
521 SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties)
522
523 RuleClass() string
524 BzlLoadLocation() string
Jingwen Chen73850672020-12-14 08:25:34 -0500525}
526
Jingwen Chenab60f122021-01-24 21:21:45 -0500527// InitBazelTargetModule is a wrapper function that decorates BazelTargetModule
528// with property structs containing metadata for bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500529func InitBazelTargetModule(module BazelTargetModule) {
Liz Kammerfc46bc12021-02-19 11:06:17 -0500530 module.AddProperties(module.bazelTargetModuleProperties())
Jingwen Chen73850672020-12-14 08:25:34 -0500531 InitAndroidModule(module)
532}
533
Jingwen Chenab60f122021-01-24 21:21:45 -0500534// BazelTargetModuleBase contains the property structs with metadata for
535// bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500536type BazelTargetModuleBase struct {
537 ModuleBase
538 Properties bazel.BazelTargetModuleProperties
539}
540
Liz Kammerfc46bc12021-02-19 11:06:17 -0500541// bazelTargetModuleProperties getter.
542func (btmb *BazelTargetModuleBase) bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
Jingwen Chen73850672020-12-14 08:25:34 -0500543 return &btmb.Properties
544}
545
Liz Kammerfc46bc12021-02-19 11:06:17 -0500546// SetBazelTargetModuleProperties setter for BazelTargetModuleProperties
547func (btmb *BazelTargetModuleBase) SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) {
548 btmb.Properties = props
549}
550
551// RuleClass returns the rule class for this Bazel target
552func (b *BazelTargetModuleBase) RuleClass() string {
553 return b.bazelTargetModuleProperties().Rule_class
554}
555
556// BzlLoadLocation returns the rule class for this Bazel target
557func (b *BazelTargetModuleBase) BzlLoadLocation() string {
558 return b.bazelTargetModuleProperties().Bzl_load_location
559}
560
Paul Duffine2453c72019-05-31 14:00:04 +0100561// Qualified id for a module
562type qualifiedModuleName struct {
563 // The package (i.e. directory) in which the module is defined, without trailing /
564 pkg string
565
566 // The name of the module, empty string if package.
567 name string
568}
569
570func (q qualifiedModuleName) String() string {
571 if q.name == "" {
572 return "//" + q.pkg
573 }
574 return "//" + q.pkg + ":" + q.name
575}
576
Paul Duffine484f472019-06-20 16:38:08 +0100577func (q qualifiedModuleName) isRootPackage() bool {
578 return q.pkg == "" && q.name == ""
579}
580
Paul Duffine2453c72019-05-31 14:00:04 +0100581// Get the id for the package containing this module.
582func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
583 pkg := q.pkg
584 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100585 if pkg == "" {
586 panic(fmt.Errorf("Cannot get containing package id of root package"))
587 }
588
589 index := strings.LastIndex(pkg, "/")
590 if index == -1 {
591 pkg = ""
592 } else {
593 pkg = pkg[:index]
594 }
Paul Duffine2453c72019-05-31 14:00:04 +0100595 }
596 return newPackageId(pkg)
597}
598
599func newPackageId(pkg string) qualifiedModuleName {
600 // A qualified id for a package module has no name.
601 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800602}
603
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000604type Dist struct {
605 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
606 // command line and any of these targets are also on the command line, or otherwise
607 // built
608 Targets []string `android:"arch_variant"`
609
610 // The name of the output artifact. This defaults to the basename of the output of
611 // the module.
612 Dest *string `android:"arch_variant"`
613
614 // The directory within the dist directory to store the artifact. Defaults to the
615 // top level directory ("").
616 Dir *string `android:"arch_variant"`
617
618 // A suffix to add to the artifact file name (before any extension).
619 Suffix *string `android:"arch_variant"`
620
Paul Duffin74f05592020-11-25 16:37:46 +0000621 // A string tag to select the OutputFiles associated with the tag.
622 //
623 // If no tag is specified then it will select the default dist paths provided
624 // by the module type. If a tag of "" is specified then it will return the
625 // default output files provided by the modules, i.e. the result of calling
626 // OutputFiles("").
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000627 Tag *string `android:"arch_variant"`
628}
629
Colin Crossfc754582016-05-17 16:34:16 -0700630type nameProperties struct {
631 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800632 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700633}
634
Colin Cross08d6f8f2020-11-19 02:33:19 +0000635type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800636 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000637 //
638 // Disabling a module should only be done for those modules that cannot be built
639 // in the current environment. Modules that can build in the current environment
640 // but are not usually required (e.g. superceded by a prebuilt) should not be
641 // disabled as that will prevent them from being built by the checkbuild target
642 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800643 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800644
Paul Duffin2e61fa62019-03-28 14:10:57 +0000645 // Controls the visibility of this module to other modules. Allowable values are one or more of
646 // these formats:
647 //
648 // ["//visibility:public"]: Anyone can use this module.
649 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
650 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100651 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
652 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000653 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
654 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
655 // this module. Note that sub-packages do not have access to the rule; for example,
656 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
657 // is a special module and must be used verbatim. It represents all of the modules in the
658 // package.
659 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
660 // or other or in one of their sub-packages have access to this module. For example,
661 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
662 // to depend on this rule (but not //independent:evil)
663 // ["//project"]: This is shorthand for ["//project:__pkg__"]
664 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
665 // //project is the module's package. e.g. using [":__subpackages__"] in
666 // packages/apps/Settings/Android.bp is equivalent to
667 // //packages/apps/Settings:__subpackages__.
668 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
669 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100670 //
671 // If a module does not specify the `visibility` property then it uses the
672 // `default_visibility` property of the `package` module in the module's package.
673 //
674 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100675 // it will use the `default_visibility` of its closest ancestor package for which
676 // a `default_visibility` property is specified.
677 //
678 // If no `default_visibility` property can be found then the module uses the
679 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100680 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100681 // The `visibility` property has no effect on a defaults module although it does
682 // apply to any non-defaults module that uses it. To set the visibility of a
683 // defaults module, use the `defaults_visibility` property on the defaults module;
684 // not to be confused with the `default_visibility` property on the package module.
685 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000686 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
687 // more details.
688 Visibility []string
689
Bob Badour37af0462021-01-07 03:34:31 +0000690 // Describes the licenses applicable to this module. Must reference license modules.
691 Licenses []string
692
693 // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more.
694 Effective_licenses []string `blueprint:"mutated"`
695 // Override of module name when reporting licenses
696 Effective_package_name *string `blueprint:"mutated"`
697 // Notice files
Paul Duffinec0836a2021-05-10 22:53:30 +0100698 Effective_license_text Paths `blueprint:"mutated"`
Bob Badour37af0462021-01-07 03:34:31 +0000699 // License names
700 Effective_license_kinds []string `blueprint:"mutated"`
701 // License conditions
702 Effective_license_conditions []string `blueprint:"mutated"`
703
Colin Cross7d5136f2015-05-11 13:39:40 -0700704 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800705 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
706 // 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 +0000707 // platform).
Colin Cross7d716ba2017-11-01 10:38:29 -0700708 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700709
710 Target struct {
711 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700712 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700713 }
714 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700715 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700716 }
717 }
718
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000719 // If set to true then the archMutator will create variants for each arch specific target
720 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
721 // create a variant for the architecture and will list the additional arch specific targets
722 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700723 UseTargetVariants bool `blueprint:"mutated"`
724 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800725
Dan Willemsen782a2d12015-12-21 14:55:28 -0800726 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700727 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800728
Colin Cross55708f32017-03-20 13:23:34 -0700729 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700730 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700731
Jiyong Park2db76922017-11-08 16:03:48 +0900732 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
733 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
734 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700735 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700736
Jiyong Park2db76922017-11-08 16:03:48 +0900737 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
738 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
739 Soc_specific *bool
740
741 // whether this module is specific to a device, not only for SoC, but also for off-chip
742 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
743 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
744 // This implies `soc_specific:true`.
745 Device_specific *bool
746
747 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900748 // network operator, etc). When set to true, it is installed into /product (or
749 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900750 Product_specific *bool
751
Justin Yund5f6c822019-06-25 16:47:17 +0900752 // whether this module extends system. When set to true, it is installed into /system_ext
753 // (or /system/system_ext if system_ext partition does not exist).
754 System_ext_specific *bool
755
Jiyong Parkf9332f12018-02-01 00:54:12 +0900756 // Whether this module is installed to recovery partition
757 Recovery *bool
758
Yifan Hong1b3348d2020-01-21 15:53:22 -0800759 // Whether this module is installed to ramdisk
760 Ramdisk *bool
761
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700762 // Whether this module is installed to vendor ramdisk
763 Vendor_ramdisk *bool
764
Inseob Kim08758f02021-04-08 21:13:22 +0900765 // Whether this module is installed to debug ramdisk
766 Debug_ramdisk *bool
767
Jaewoong Jung8e93aba2021-03-02 16:58:08 -0800768 // Whether this module is built for non-native architectures (also known as native bridge binary)
dimitry1f33e402019-03-26 12:39:31 +0100769 Native_bridge_supported *bool `android:"arch_variant"`
770
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700771 // init.rc files to be installed if this module is installed
Colin Cross0bab8772020-09-25 14:01:21 -0700772 Init_rc []string `android:"arch_variant,path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700773
Steven Moreland57a23d22018-04-04 15:42:19 -0700774 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800775 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700776
Chris Wolfe998306e2016-08-15 14:47:23 -0400777 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700778 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400779
Sasha Smundakb6d23052019-04-01 18:37:36 -0700780 // names of other modules to install on host if this module is installed
781 Host_required []string `android:"arch_variant"`
782
783 // names of other modules to install on target if this module is installed
784 Target_required []string `android:"arch_variant"`
785
Colin Cross5aac3622017-08-31 15:07:09 -0700786 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800787 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700788
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000789 // The OsType of artifacts that this module variant is responsible for creating.
790 //
791 // Set by osMutator
792 CompileOS OsType `blueprint:"mutated"`
793
794 // The Target of artifacts that this module variant is responsible for creating.
795 //
796 // Set by archMutator
797 CompileTarget Target `blueprint:"mutated"`
798
799 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
800 // responsible for creating.
801 //
802 // By default this is nil as, where necessary, separate variants are created for the
803 // different multilib types supported and that information is encapsulated in the
804 // CompileTarget so the module variant simply needs to create artifacts for that.
805 //
806 // However, if UseTargetVariants is set to false (e.g. by
807 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
808 // multilib targets. Instead a single variant is created for the architecture and
809 // this contains the multilib specific targets that this variant should create.
810 //
811 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700812 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000813
814 // True if the module variant's CompileTarget is the primary target
815 //
816 // Set by archMutator
817 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800818
819 // Set by InitAndroidModule
820 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700821 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700822
Paul Duffin1356d8c2020-02-25 19:26:33 +0000823 // If set to true then a CommonOS variant will be created which will have dependencies
824 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
825 // that covers all os and architecture variants.
826 //
827 // The OsType specific variants can be retrieved by calling
828 // GetOsSpecificVariantsOfCommonOSVariant
829 //
830 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
831 CreateCommonOSVariant bool `blueprint:"mutated"`
832
833 // If set to true then this variant is the CommonOS variant that has dependencies on its
834 // OsType specific variants.
835 //
836 // Set by osMutator.
837 CommonOSVariant bool `blueprint:"mutated"`
838
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800839 // When HideFromMake is set to true, no entry for this variant will be emitted in the
840 // generated Android.mk file.
841 HideFromMake bool `blueprint:"mutated"`
842
843 // When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable,
844 // ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile
845 // and don't create a rule to install the file.
Colin Crossce75d2c2016-10-06 16:12:58 -0700846 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800847
Liz Kammer5ca3a622020-08-05 15:40:41 -0700848 // Whether the module has been replaced by a prebuilt
849 ReplacedByPrebuilt bool `blueprint:"mutated"`
850
Justin Yun32f053b2020-07-31 23:07:17 +0900851 // Disabled by mutators. If set to true, it overrides Enabled property.
852 ForcedDisabled bool `blueprint:"mutated"`
853
Jeff Gaston088e29e2017-11-29 16:47:17 -0800854 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700855
856 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700857
858 // Name and variant strings stored by mutators to enable Module.String()
859 DebugName string `blueprint:"mutated"`
860 DebugMutators []string `blueprint:"mutated"`
861 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800862
Colin Crossa6845402020-11-16 15:08:19 -0800863 // ImageVariation is set by ImageMutator to specify which image this variation is for,
864 // for example "" for core or "recovery" for recovery. It will often be set to one of the
865 // constants in image.go, but can also be set to a custom value by individual module types.
Colin Cross7228ecd2019-11-18 16:00:16 -0800866 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800867}
868
Paul Duffined875132020-09-02 13:08:57 +0100869type distProperties struct {
870 // configuration to distribute output files from this module to the distribution
871 // directory (default: $OUT/dist, configurable with $DIST_DIR)
872 Dist Dist `android:"arch_variant"`
873
874 // a list of configurations to distribute output files from this module to the
875 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
876 Dists []Dist `android:"arch_variant"`
877}
878
Paul Duffin74f05592020-11-25 16:37:46 +0000879// The key to use in TaggedDistFiles when a Dist structure does not specify a
880// tag property. This intentionally does not use "" as the default because that
881// would mean that an empty tag would have a different meaning when used in a dist
882// structure that when used to reference a specific set of output paths using the
883// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
884const DefaultDistTag = "<default-dist-tag>"
885
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000886// A map of OutputFile tag keys to Paths, for disting purposes.
887type TaggedDistFiles map[string]Paths
888
Paul Duffin74f05592020-11-25 16:37:46 +0000889// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
890// then it will create a map, update it and then return it. If a mapping already
891// exists for the tag then the paths are appended to the end of the current list
892// of paths, ignoring any duplicates.
893func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
894 if t == nil {
895 t = make(TaggedDistFiles)
896 }
897
898 for _, distFile := range paths {
899 if distFile != nil && !t[tag].containsPath(distFile) {
900 t[tag] = append(t[tag], distFile)
901 }
902 }
903
904 return t
905}
906
907// merge merges the entries from the other TaggedDistFiles object into this one.
908// If the TaggedDistFiles is nil then it will create a new instance, merge the
909// other into it, and then return it.
910func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
911 for tag, paths := range other {
912 t = t.addPathsForTag(tag, paths...)
913 }
914
915 return t
916}
917
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000918func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000919 for _, path := range paths {
920 if path == nil {
921 panic("The path to a dist file cannot be nil.")
922 }
923 }
924
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000925 // The default OutputFile tag is the empty "" string.
Paul Duffin74f05592020-11-25 16:37:46 +0000926 return TaggedDistFiles{DefaultDistTag: paths}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000927}
928
Colin Cross3f40fa42015-01-30 17:27:36 -0800929type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800930 // If set to true, build a variant of the module for the host. Defaults to false.
931 Host_supported *bool
932
933 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700934 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800935}
936
Colin Crossc472d572015-03-17 15:06:21 -0700937type Multilib string
938
939const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800940 MultilibBoth Multilib = "both"
941 MultilibFirst Multilib = "first"
942 MultilibCommon Multilib = "common"
943 MultilibCommonFirst Multilib = "common_first"
944 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700945)
946
Colin Crossa1ad8d12016-06-01 17:09:44 -0700947type HostOrDeviceSupported int
948
949const (
Colin Cross34037c62020-11-17 13:19:17 -0800950 hostSupported = 1 << iota
951 hostCrossSupported
952 deviceSupported
953 hostDefault
954 deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700955
956 // Host and HostCross are built by default. Device is not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800957 HostSupported = hostSupported | hostCrossSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700958
959 // Host is built by default. HostCross and Device are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800960 HostSupportedNoCross = hostSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700961
962 // Device is built by default. Host and HostCross are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800963 DeviceSupported = deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700964
965 // Device is built by default. Host and HostCross are supported.
Colin Cross34037c62020-11-17 13:19:17 -0800966 HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700967
968 // Host, HostCross, and Device are built by default.
Colin Cross34037c62020-11-17 13:19:17 -0800969 HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
970 deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700971
972 // Nothing is supported. This is not exposed to the user, but used to mark a
973 // host only module as unsupported when the module type is not supported on
974 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Colin Cross34037c62020-11-17 13:19:17 -0800975 NeitherHostNorDeviceSupported = 0
Colin Crossa1ad8d12016-06-01 17:09:44 -0700976)
977
Jiyong Park2db76922017-11-08 16:03:48 +0900978type moduleKind int
979
980const (
981 platformModule moduleKind = iota
982 deviceSpecificModule
983 socSpecificModule
984 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900985 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900986)
987
988func (k moduleKind) String() string {
989 switch k {
990 case platformModule:
991 return "platform"
992 case deviceSpecificModule:
993 return "device-specific"
994 case socSpecificModule:
995 return "soc-specific"
996 case productSpecificModule:
997 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900998 case systemExtSpecificModule:
999 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +09001000 default:
1001 panic(fmt.Errorf("unknown module kind %d", k))
1002 }
1003}
1004
Colin Cross9d34f352019-11-22 16:03:51 -08001005func initAndroidModuleBase(m Module) {
1006 m.base().module = m
1007}
1008
Colin Crossa6845402020-11-16 15:08:19 -08001009// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
1010// It adds the common properties, for example "name" and "enabled".
Colin Cross36242852017-06-23 15:06:31 -07001011func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -08001012 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001013 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -07001014
Colin Cross36242852017-06-23 15:06:31 -07001015 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -07001016 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +01001017 &base.commonProperties,
1018 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -07001019
Colin Crosseabaedd2020-02-06 17:01:55 -08001020 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -07001021
Colin Crossa3a97412019-03-18 12:24:29 -07001022 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -07001023 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +01001024
1025 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +01001026 // its checking and parsing phases so make it the primary visibility property.
1027 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Bob Badour37af0462021-01-07 03:34:31 +00001028
1029 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
1030 // its checking and parsing phases so make it the primary licenses property.
1031 setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses)
Colin Cross5049f022015-03-18 13:28:46 -07001032}
1033
Colin Crossa6845402020-11-16 15:08:19 -08001034// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
1035// It adds the common properties, for example "name" and "enabled", as well as runtime generated
1036// property structs for architecture-specific versions of generic properties tagged with
1037// `android:"arch_variant"`.
1038//
1039// InitAndroidModule should not be called if InitAndroidArchModule was called.
Colin Cross36242852017-06-23 15:06:31 -07001040func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1041 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -07001042
1043 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -08001044 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -07001045 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -07001046 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -07001047 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001048
Colin Cross34037c62020-11-17 13:19:17 -08001049 if hod&hostSupported != 0 && hod&deviceSupported != 0 {
Colin Cross36242852017-06-23 15:06:31 -07001050 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -08001051 }
1052
Colin Crossa6845402020-11-16 15:08:19 -08001053 initArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001054}
1055
Colin Crossa6845402020-11-16 15:08:19 -08001056// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1057// architecture-specific, but will only have a single variant per OS that handles all the
1058// architectures simultaneously. The list of Targets that it must handle will be available from
1059// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
1060// well as runtime generated property structs for architecture-specific versions of generic
1061// properties tagged with `android:"arch_variant"`.
1062//
1063// InitAndroidModule or InitAndroidArchModule should not be called if
1064// InitAndroidMultiTargetsArchModule was called.
Colin Crossee0bc3b2018-10-02 22:01:37 -07001065func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1066 InitAndroidArchModule(m, hod, defaultMultilib)
1067 m.base().commonProperties.UseTargetVariants = false
1068}
1069
Colin Crossa6845402020-11-16 15:08:19 -08001070// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1071// architecture-specific, but will only have a single variant per OS that handles all the
1072// architectures simultaneously, and will also have an additional CommonOS variant that has
1073// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
1074// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
1075// "enabled", as well as runtime generated property structs for architecture-specific versions of
1076// generic properties tagged with `android:"arch_variant"`.
1077//
1078// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
1079// called if InitCommonOSAndroidMultiTargetsArchModule was called.
Paul Duffin1356d8c2020-02-25 19:26:33 +00001080func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1081 InitAndroidArchModule(m, hod, defaultMultilib)
1082 m.base().commonProperties.UseTargetVariants = false
1083 m.base().commonProperties.CreateCommonOSVariant = true
1084}
1085
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001086// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -08001087// modules. It should be included as an anonymous field in every module
1088// struct definition. InitAndroidModule should then be called from the module's
1089// factory function, and the return values from InitAndroidModule should be
1090// returned from the factory function.
1091//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001092// The ModuleBase type is responsible for implementing the GenerateBuildActions
1093// method to support the blueprint.Module interface. This method will then call
1094// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -07001095// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
1096// rather than the usual blueprint.ModuleContext.
1097// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -08001098// system including details about the particular build variant that is to be
1099// generated.
1100//
1101// For example:
1102//
1103// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001104// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -08001105// )
1106//
1107// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001108// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -08001109// properties struct {
1110// MyProperty string
1111// }
1112// }
1113//
Colin Cross36242852017-06-23 15:06:31 -07001114// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001115// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -07001116// m.AddProperties(&m.properties)
1117// android.InitAndroidModule(m)
1118// return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001119// }
1120//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001121// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001122// // Get the CPU architecture for the current build variant.
1123// variantArch := ctx.Arch()
1124//
1125// // ...
1126// }
Colin Cross635c3b02016-05-18 15:37:25 -07001127type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -08001128 // Putting the curiously recurring thing pointing to the thing that contains
1129 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -07001130 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -07001131 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -08001132
Colin Crossfc754582016-05-17 16:34:16 -07001133 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -08001134 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +01001135 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -07001136 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001137 hostAndDeviceProperties hostAndDeviceProperties
1138 generalProperties []interface{}
Jingwen Chen5d864492021-02-24 07:20:12 -05001139
1140 // Arch specific versions of structs in generalProperties. The outer index
1141 // has the same order as generalProperties as initialized in
1142 // InitAndroidArchModule, and the inner index chooses the props specific to
1143 // the architecture. The interface{} value is an archPropRoot that is
1144 // filled with arch specific values by the arch mutator.
1145 archProperties [][]interface{}
1146
1147 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001148
Jingwen Chen73850672020-12-14 08:25:34 -05001149 // Properties specific to the Blueprint to BUILD migration.
1150 bazelTargetModuleProperties bazel.BazelTargetModuleProperties
1151
Paul Duffin63c6e182019-07-24 14:24:38 +01001152 // Information about all the properties on the module that contains visibility rules that need
1153 // checking.
1154 visibilityPropertyInfo []visibilityProperty
1155
1156 // The primary visibility property, may be nil, that controls access to the module.
1157 primaryVisibilityProperty visibilityProperty
1158
Bob Badour37af0462021-01-07 03:34:31 +00001159 // The primary licenses property, may be nil, records license metadata for the module.
1160 primaryLicensesProperty applicableLicensesProperty
1161
Colin Crossffe6b9d2020-12-01 15:40:06 -08001162 noAddressSanitizer bool
1163 installFiles InstallPaths
1164 installFilesDepSet *installPathsDepSet
1165 checkbuildFiles Paths
1166 packagingSpecs []PackagingSpec
1167 packagingSpecsDepSet *packagingSpecsDepSet
1168 noticeFiles Paths
1169 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001170
Paul Duffinaf970a22020-11-23 23:32:56 +00001171 // The files to copy to the dist as explicitly specified in the .bp file.
1172 distFiles TaggedDistFiles
1173
Colin Cross1f8c52b2015-06-16 16:38:17 -07001174 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
1175 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -08001176 installTarget WritablePath
1177 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -07001178 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -07001179
Colin Cross178a5092016-09-13 13:42:32 -07001180 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -07001181
1182 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -07001183
1184 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001185 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001186 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001187 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -07001188
Inseob Kim8471cda2019-11-15 09:59:12 +09001189 initRcPaths Paths
1190 vintfFragmentsPaths Paths
Colin Cross36242852017-06-23 15:06:31 -07001191}
1192
Paul Duffin44f1d842020-06-26 20:17:02 +01001193func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
1194
Colin Cross4157e882019-06-06 16:57:04 -07001195func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -08001196
Colin Cross4157e882019-06-06 16:57:04 -07001197func (m *ModuleBase) AddProperties(props ...interface{}) {
1198 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -07001199}
1200
Colin Cross4157e882019-06-06 16:57:04 -07001201func (m *ModuleBase) GetProperties() []interface{} {
1202 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -08001203}
1204
Colin Cross4157e882019-06-06 16:57:04 -07001205func (m *ModuleBase) BuildParamsForTests() []BuildParams {
1206 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -07001207}
1208
Colin Cross4157e882019-06-06 16:57:04 -07001209func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
1210 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001211}
1212
Colin Cross4157e882019-06-06 16:57:04 -07001213func (m *ModuleBase) VariablesForTests() map[string]string {
1214 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001215}
1216
Colin Crossce75d2c2016-10-06 16:12:58 -07001217// Name returns the name of the module. It may be overridden by individual module types, for
1218// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -07001219func (m *ModuleBase) Name() string {
1220 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -07001221}
1222
Colin Cross9a362232019-07-01 15:32:45 -07001223// String returns a string that includes the module name and variants for printing during debugging.
1224func (m *ModuleBase) String() string {
1225 sb := strings.Builder{}
1226 sb.WriteString(m.commonProperties.DebugName)
1227 sb.WriteString("{")
1228 for i := range m.commonProperties.DebugMutators {
1229 if i != 0 {
1230 sb.WriteString(",")
1231 }
1232 sb.WriteString(m.commonProperties.DebugMutators[i])
1233 sb.WriteString(":")
1234 sb.WriteString(m.commonProperties.DebugVariations[i])
1235 }
1236 sb.WriteString("}")
1237 return sb.String()
1238}
1239
Colin Crossce75d2c2016-10-06 16:12:58 -07001240// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001241func (m *ModuleBase) BaseModuleName() string {
1242 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001243}
1244
Colin Cross4157e882019-06-06 16:57:04 -07001245func (m *ModuleBase) base() *ModuleBase {
1246 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001247}
1248
Paul Duffine2453c72019-05-31 14:00:04 +01001249func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1250 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1251}
1252
1253func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001254 return m.visibilityPropertyInfo
1255}
1256
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001257func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001258 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001259 // Make a copy of the underlying Dists slice to protect against
1260 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001261 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1262 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001263 } else {
Paul Duffined875132020-09-02 13:08:57 +01001264 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001265 }
1266}
1267
1268func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
Paul Duffin74f05592020-11-25 16:37:46 +00001269 var distFiles TaggedDistFiles
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001270 for _, dist := range m.Dists() {
Paul Duffin74f05592020-11-25 16:37:46 +00001271 // If no tag is specified then it means to use the default dist paths so use
1272 // the special tag name which represents that.
1273 tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
1274
Paul Duffinaf970a22020-11-23 23:32:56 +00001275 if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
1276 // Call the OutputFiles(tag) method to get the paths associated with the tag.
1277 distFilesForTag, err := outputFileProducer.OutputFiles(tag)
Paul Duffin74f05592020-11-25 16:37:46 +00001278
Paul Duffinaf970a22020-11-23 23:32:56 +00001279 // If the tag was not supported and is not DefaultDistTag then it is an error.
1280 // Failing to find paths for DefaultDistTag is not an error. It just means
1281 // that the module type requires the legacy behavior.
1282 if err != nil && tag != DefaultDistTag {
1283 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1284 }
1285
1286 distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
1287 } else if tag != DefaultDistTag {
1288 // If the tag was specified then it is an error if the module does not
1289 // implement OutputFileProducer because there is no other way of accessing
1290 // the paths for the specified tag.
1291 ctx.PropertyErrorf("dist.tag",
1292 "tag %s not supported because the module does not implement OutputFileProducer", tag)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001293 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001294 }
1295
1296 return distFiles
1297}
1298
Colin Cross4157e882019-06-06 16:57:04 -07001299func (m *ModuleBase) Target() Target {
1300 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001301}
1302
Colin Cross4157e882019-06-06 16:57:04 -07001303func (m *ModuleBase) TargetPrimary() bool {
1304 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001305}
1306
Colin Cross4157e882019-06-06 16:57:04 -07001307func (m *ModuleBase) MultiTargets() []Target {
1308 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001309}
1310
Colin Cross4157e882019-06-06 16:57:04 -07001311func (m *ModuleBase) Os() OsType {
1312 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001313}
1314
Colin Cross4157e882019-06-06 16:57:04 -07001315func (m *ModuleBase) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09001316 return m.Os().Class == Host
Dan Willemsen97750522016-02-09 17:43:51 -08001317}
1318
Yo Chiangbba545e2020-06-09 16:15:37 +08001319func (m *ModuleBase) Device() bool {
1320 return m.Os().Class == Device
1321}
1322
Colin Cross4157e882019-06-06 16:57:04 -07001323func (m *ModuleBase) Arch() Arch {
1324 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001325}
1326
Colin Cross4157e882019-06-06 16:57:04 -07001327func (m *ModuleBase) ArchSpecific() bool {
1328 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001329}
1330
Paul Duffin1356d8c2020-02-25 19:26:33 +00001331// True if the current variant is a CommonOS variant, false otherwise.
1332func (m *ModuleBase) IsCommonOSVariant() bool {
1333 return m.commonProperties.CommonOSVariant
1334}
1335
Colin Cross34037c62020-11-17 13:19:17 -08001336// supportsTarget returns true if the given Target is supported by the current module.
1337func (m *ModuleBase) supportsTarget(target Target) bool {
1338 switch target.Os.Class {
1339 case Host:
1340 if target.HostCross {
1341 return m.HostCrossSupported()
1342 } else {
1343 return m.HostSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001344 }
Colin Cross34037c62020-11-17 13:19:17 -08001345 case Device:
1346 return m.DeviceSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001347 default:
Jiyong Park1613e552020-09-14 19:43:17 +09001348 return false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001349 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001350}
1351
Colin Cross34037c62020-11-17 13:19:17 -08001352// DeviceSupported returns true if the current module is supported and enabled for device targets,
1353// i.e. the factory method set the HostOrDeviceSupported value to include device support and
1354// the device support is enabled by default or enabled by the device_supported property.
Colin Cross4157e882019-06-06 16:57:04 -07001355func (m *ModuleBase) DeviceSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001356 hod := m.commonProperties.HostOrDeviceSupported
1357 // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
1358 // value has the deviceDefault bit set.
1359 deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
1360 return hod&deviceSupported != 0 && deviceEnabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001361}
1362
Colin Cross34037c62020-11-17 13:19:17 -08001363// HostSupported returns true if the current module is supported and enabled for host targets,
1364// i.e. the factory method set the HostOrDeviceSupported value to include host support and
1365// the host support is enabled by default or enabled by the host_supported property.
Paul Duffine44358f2019-11-26 18:04:12 +00001366func (m *ModuleBase) HostSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001367 hod := m.commonProperties.HostOrDeviceSupported
1368 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1369 // value has the hostDefault bit set.
1370 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1371 return hod&hostSupported != 0 && hostEnabled
1372}
1373
1374// HostCrossSupported returns true if the current module is supported and enabled for host cross
1375// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
1376// support and the host cross support is enabled by default or enabled by the
1377// host_supported property.
1378func (m *ModuleBase) HostCrossSupported() bool {
1379 hod := m.commonProperties.HostOrDeviceSupported
1380 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1381 // value has the hostDefault bit set.
1382 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1383 return hod&hostCrossSupported != 0 && hostEnabled
Paul Duffine44358f2019-11-26 18:04:12 +00001384}
1385
Colin Cross4157e882019-06-06 16:57:04 -07001386func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001387 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001388}
1389
Colin Cross4157e882019-06-06 16:57:04 -07001390func (m *ModuleBase) DeviceSpecific() bool {
1391 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001392}
1393
Colin Cross4157e882019-06-06 16:57:04 -07001394func (m *ModuleBase) SocSpecific() bool {
1395 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001396}
1397
Colin Cross4157e882019-06-06 16:57:04 -07001398func (m *ModuleBase) ProductSpecific() bool {
1399 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001400}
1401
Justin Yund5f6c822019-06-25 16:47:17 +09001402func (m *ModuleBase) SystemExtSpecific() bool {
1403 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001404}
1405
Colin Crossc2d24052020-05-13 11:05:02 -07001406// RequiresStableAPIs returns true if the module will be installed to a partition that may
1407// be updated separately from the system image.
1408func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1409 return m.SocSpecific() || m.DeviceSpecific() ||
1410 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1411}
1412
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001413func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1414 partition := "system"
1415 if m.SocSpecific() {
1416 // A SoC-specific module could be on the vendor partition at
1417 // "vendor" or the system partition at "system/vendor".
1418 if config.VendorPath() == "vendor" {
1419 partition = "vendor"
1420 }
1421 } else if m.DeviceSpecific() {
1422 // A device-specific module could be on the odm partition at
1423 // "odm", the vendor partition at "vendor/odm", or the system
1424 // partition at "system/vendor/odm".
1425 if config.OdmPath() == "odm" {
1426 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001427 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001428 partition = "vendor"
1429 }
1430 } else if m.ProductSpecific() {
1431 // A product-specific module could be on the product partition
1432 // at "product" or the system partition at "system/product".
1433 if config.ProductPath() == "product" {
1434 partition = "product"
1435 }
1436 } else if m.SystemExtSpecific() {
1437 // A system_ext-specific module could be on the system_ext
1438 // partition at "system_ext" or the system partition at
1439 // "system/system_ext".
1440 if config.SystemExtPath() == "system_ext" {
1441 partition = "system_ext"
1442 }
1443 }
1444 return partition
1445}
1446
Colin Cross4157e882019-06-06 16:57:04 -07001447func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001448 if m.commonProperties.ForcedDisabled {
1449 return false
1450 }
Colin Cross08d6f8f2020-11-19 02:33:19 +00001451 if m.commonProperties.Enabled == nil {
1452 return !m.Os().DefaultDisabled
1453 }
1454 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001455}
1456
Inseob Kimeec88e12020-01-22 11:11:29 +09001457func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001458 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001459}
1460
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001461// HideFromMake marks this variant so that it is not emitted in the generated Android.mk file.
1462func (m *ModuleBase) HideFromMake() {
1463 m.commonProperties.HideFromMake = true
1464}
1465
1466// IsHideFromMake returns true if HideFromMake was previously called.
1467func (m *ModuleBase) IsHideFromMake() bool {
1468 return m.commonProperties.HideFromMake == true
1469}
1470
1471// SkipInstall marks this variant to not create install rules when ctx.Install* are called.
Colin Cross4157e882019-06-06 16:57:04 -07001472func (m *ModuleBase) SkipInstall() {
1473 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001474}
1475
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +00001476// IsSkipInstall returns true if this variant is marked to not create install
1477// rules when ctx.Install* are called.
1478func (m *ModuleBase) IsSkipInstall() bool {
1479 return m.commonProperties.SkipInstall
1480}
1481
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001482// Similar to HideFromMake, but if the AndroidMk entry would set
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001483// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1484// rather than leaving it out altogether. That happens in cases where it would
1485// have other side effects, in particular when it adds a NOTICE file target,
1486// which other install targets might depend on.
1487func (m *ModuleBase) MakeUninstallable() {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001488 m.HideFromMake()
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001489}
1490
Liz Kammer5ca3a622020-08-05 15:40:41 -07001491func (m *ModuleBase) ReplacedByPrebuilt() {
1492 m.commonProperties.ReplacedByPrebuilt = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001493 m.HideFromMake()
Liz Kammer5ca3a622020-08-05 15:40:41 -07001494}
1495
1496func (m *ModuleBase) IsReplacedByPrebuilt() bool {
1497 return m.commonProperties.ReplacedByPrebuilt
1498}
1499
Colin Cross4157e882019-06-06 16:57:04 -07001500func (m *ModuleBase) ExportedToMake() bool {
1501 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001502}
1503
Colin Crosse9fe2942020-11-10 18:12:15 -08001504// computeInstallDeps finds the installed paths of all dependencies that have a dependency
1505// tag that is annotated as needing installation via the IsInstallDepNeeded method.
Colin Crossffe6b9d2020-12-01 15:40:06 -08001506func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) {
Colin Cross5d583952020-11-24 16:21:24 -08001507 var installDeps []*installPathsDepSet
Colin Crossffe6b9d2020-12-01 15:40:06 -08001508 var packagingSpecs []*packagingSpecsDepSet
Colin Cross5d583952020-11-24 16:21:24 -08001509 ctx.VisitDirectDeps(func(dep Module) {
Jooyung Han77f7c442021-05-12 03:53:32 +09001510 if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) && !dep.IsHideFromMake() {
Colin Cross5d583952020-11-24 16:21:24 -08001511 installDeps = append(installDeps, dep.base().installFilesDepSet)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001512 packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet)
Colin Cross897266e2020-02-13 13:22:08 -08001513 }
1514 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001515
Colin Crossffe6b9d2020-12-01 15:40:06 -08001516 return installDeps, packagingSpecs
Colin Cross3f40fa42015-01-30 17:27:36 -08001517}
1518
Jiyong Park4dc2a1a2020-09-28 17:46:22 +09001519func (m *ModuleBase) FilesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001520 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001521}
1522
Jiyong Park073ea552020-11-09 14:08:34 +09001523func (m *ModuleBase) PackagingSpecs() []PackagingSpec {
1524 return m.packagingSpecs
1525}
1526
Colin Crossffe6b9d2020-12-01 15:40:06 -08001527func (m *ModuleBase) TransitivePackagingSpecs() []PackagingSpec {
1528 return m.packagingSpecsDepSet.ToList()
1529}
1530
Colin Cross4157e882019-06-06 16:57:04 -07001531func (m *ModuleBase) NoAddressSanitizer() bool {
1532 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001533}
1534
Colin Cross4157e882019-06-06 16:57:04 -07001535func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001536 return false
1537}
1538
Jaewoong Jung0949f312019-09-11 10:25:18 -07001539func (m *ModuleBase) InstallInTestcases() bool {
1540 return false
1541}
1542
Colin Cross4157e882019-06-06 16:57:04 -07001543func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001544 return false
1545}
1546
Yifan Hong1b3348d2020-01-21 15:53:22 -08001547func (m *ModuleBase) InstallInRamdisk() bool {
1548 return Bool(m.commonProperties.Ramdisk)
1549}
1550
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001551func (m *ModuleBase) InstallInVendorRamdisk() bool {
1552 return Bool(m.commonProperties.Vendor_ramdisk)
1553}
1554
Inseob Kim08758f02021-04-08 21:13:22 +09001555func (m *ModuleBase) InstallInDebugRamdisk() bool {
1556 return Bool(m.commonProperties.Debug_ramdisk)
1557}
1558
Colin Cross4157e882019-06-06 16:57:04 -07001559func (m *ModuleBase) InstallInRecovery() bool {
1560 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001561}
1562
Colin Cross90ba5f42019-10-02 11:10:58 -07001563func (m *ModuleBase) InstallInRoot() bool {
1564 return false
1565}
1566
Colin Cross607d8582019-07-29 16:44:46 -07001567func (m *ModuleBase) InstallBypassMake() bool {
1568 return false
1569}
1570
Jiyong Park87788b52020-09-01 12:37:45 +09001571func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
1572 return nil, nil
Colin Cross6e359402020-02-10 15:29:54 -08001573}
1574
Colin Cross4157e882019-06-06 16:57:04 -07001575func (m *ModuleBase) Owner() string {
1576 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001577}
1578
Bob Badoura75b0572020-02-18 20:21:55 -08001579func (m *ModuleBase) NoticeFiles() Paths {
1580 return m.noticeFiles
Jiyong Park52818fc2019-03-18 12:01:38 +09001581}
1582
Colin Cross7228ecd2019-11-18 16:00:16 -08001583func (m *ModuleBase) setImageVariation(variant string) {
1584 m.commonProperties.ImageVariation = variant
1585}
1586
1587func (m *ModuleBase) ImageVariation() blueprint.Variation {
1588 return blueprint.Variation{
1589 Mutator: "image",
1590 Variation: m.base().commonProperties.ImageVariation,
1591 }
1592}
1593
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001594func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1595 for i, v := range m.commonProperties.DebugMutators {
1596 if v == mutator {
1597 return m.commonProperties.DebugVariations[i]
1598 }
1599 }
1600
1601 return ""
1602}
1603
Yifan Hong1b3348d2020-01-21 15:53:22 -08001604func (m *ModuleBase) InRamdisk() bool {
1605 return m.base().commonProperties.ImageVariation == RamdiskVariation
1606}
1607
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001608func (m *ModuleBase) InVendorRamdisk() bool {
1609 return m.base().commonProperties.ImageVariation == VendorRamdiskVariation
1610}
1611
Inseob Kim08758f02021-04-08 21:13:22 +09001612func (m *ModuleBase) InDebugRamdisk() bool {
1613 return m.base().commonProperties.ImageVariation == DebugRamdiskVariation
1614}
1615
Colin Cross7228ecd2019-11-18 16:00:16 -08001616func (m *ModuleBase) InRecovery() bool {
1617 return m.base().commonProperties.ImageVariation == RecoveryVariation
1618}
1619
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001620func (m *ModuleBase) RequiredModuleNames() []string {
1621 return m.base().commonProperties.Required
1622}
1623
1624func (m *ModuleBase) HostRequiredModuleNames() []string {
1625 return m.base().commonProperties.Host_required
1626}
1627
1628func (m *ModuleBase) TargetRequiredModuleNames() []string {
1629 return m.base().commonProperties.Target_required
1630}
1631
Inseob Kim8471cda2019-11-15 09:59:12 +09001632func (m *ModuleBase) InitRc() Paths {
1633 return append(Paths{}, m.initRcPaths...)
1634}
1635
1636func (m *ModuleBase) VintfFragments() Paths {
1637 return append(Paths{}, m.vintfFragmentsPaths...)
1638}
1639
Colin Cross4157e882019-06-06 16:57:04 -07001640func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001641 var allInstalledFiles InstallPaths
1642 var allCheckbuildFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001643 ctx.VisitAllModuleVariants(func(module Module) {
1644 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001645 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1646 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001647 })
1648
Colin Cross0875c522017-11-28 17:34:01 -08001649 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001650
Colin Cross133ebef2020-08-14 17:38:45 -07001651 namespacePrefix := ctx.Namespace().id
Jeff Gaston088e29e2017-11-29 16:47:17 -08001652 if namespacePrefix != "" {
1653 namespacePrefix = namespacePrefix + "-"
1654 }
1655
Colin Cross3f40fa42015-01-30 17:27:36 -08001656 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001657 name := namespacePrefix + ctx.ModuleName() + "-install"
1658 ctx.Phony(name, allInstalledFiles.Paths()...)
1659 m.installTarget = PathForPhony(ctx, name)
1660 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001661 }
1662
1663 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001664 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1665 ctx.Phony(name, allCheckbuildFiles...)
1666 m.checkbuildTarget = PathForPhony(ctx, name)
1667 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001668 }
1669
1670 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001671 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05001672 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001673 suffix = "-soong"
1674 }
1675
Colin Crossc3d87d32020-06-04 13:25:17 -07001676 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001677
Colin Cross4157e882019-06-06 16:57:04 -07001678 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001679 }
1680}
1681
Colin Crossc34d2322020-01-03 15:23:27 -08001682func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001683 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1684 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1685 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001686 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001687
Dario Frenifd05a742018-05-29 13:28:54 +01001688 msg := "conflicting value set here"
1689 if socSpecific && deviceSpecific {
1690 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001691 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001692 ctx.PropertyErrorf("vendor", msg)
1693 }
Colin Cross4157e882019-06-06 16:57:04 -07001694 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001695 ctx.PropertyErrorf("proprietary", msg)
1696 }
Colin Cross4157e882019-06-06 16:57:04 -07001697 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001698 ctx.PropertyErrorf("soc_specific", msg)
1699 }
1700 }
1701
Justin Yund5f6c822019-06-25 16:47:17 +09001702 if productSpecific && systemExtSpecific {
1703 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1704 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001705 }
1706
Justin Yund5f6c822019-06-25 16:47:17 +09001707 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001708 if productSpecific {
1709 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1710 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001711 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 +01001712 }
1713 if deviceSpecific {
1714 ctx.PropertyErrorf("device_specific", msg)
1715 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001716 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001717 ctx.PropertyErrorf("vendor", msg)
1718 }
Colin Cross4157e882019-06-06 16:57:04 -07001719 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001720 ctx.PropertyErrorf("proprietary", msg)
1721 }
Colin Cross4157e882019-06-06 16:57:04 -07001722 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001723 ctx.PropertyErrorf("soc_specific", msg)
1724 }
1725 }
1726 }
1727
Jiyong Park2db76922017-11-08 16:03:48 +09001728 if productSpecific {
1729 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001730 } else if systemExtSpecific {
1731 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001732 } else if deviceSpecific {
1733 return deviceSpecificModule
1734 } else if socSpecific {
1735 return socSpecificModule
1736 } else {
1737 return platformModule
1738 }
1739}
1740
Colin Crossc34d2322020-01-03 15:23:27 -08001741func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001742 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001743 EarlyModuleContext: ctx,
1744 kind: determineModuleKind(m, ctx),
1745 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001746 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001747}
1748
Colin Cross1184b642019-12-30 18:43:07 -08001749func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1750 return baseModuleContext{
1751 bp: ctx,
1752 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1753 os: m.commonProperties.CompileOS,
1754 target: m.commonProperties.CompileTarget,
1755 targetPrimary: m.commonProperties.CompilePrimary,
1756 multiTargets: m.commonProperties.CompileMultiTargets,
1757 }
1758}
1759
Colin Cross4157e882019-06-06 16:57:04 -07001760func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001761 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001762 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001763 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001764 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
Colin Cross0ea8ba82019-06-06 14:33:29 -07001765 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001766 }
1767
Colin Crossffe6b9d2020-12-01 15:40:06 -08001768 dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
Colin Cross5d583952020-11-24 16:21:24 -08001769 // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
1770 // of installed files of this module. It will be replaced by a depset including the installed
1771 // files of this module at the end for use by modules that depend on this one.
1772 m.installFilesDepSet = newInstallPathsDepSet(nil, dependencyInstallFiles)
1773
Colin Cross6c4f21f2019-06-06 15:41:36 -07001774 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1775 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1776 // TODO: This will be removed once defaults modules handle missing dependency errors
1777 blueprintCtx.GetMissingDependencies()
1778
Colin Crossdc35e212019-06-06 16:13:11 -07001779 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001780 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1781 // (because the dependencies are added before the modules are disabled). The
1782 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1783 // ignored.
1784 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001785
Colin Cross4c83e5c2019-02-25 14:54:28 -08001786 if ctx.config.captureBuild {
1787 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1788 }
1789
Colin Cross67a5c132017-05-09 13:45:28 -07001790 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1791 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001792 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1793 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001794 }
Colin Cross0875c522017-11-28 17:34:01 -08001795 if !ctx.PrimaryArch() {
1796 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001797 }
Colin Cross56a83212020-09-15 18:30:11 -07001798 if apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo); !apexInfo.IsForPlatform() {
1799 suffix = append(suffix, apexInfo.ApexVariationName)
Dan Willemsenb13a9482020-02-14 11:25:54 -08001800 }
Colin Cross67a5c132017-05-09 13:45:28 -07001801
1802 ctx.Variable(pctx, "moduleDesc", desc)
1803
1804 s := ""
1805 if len(suffix) > 0 {
1806 s = " [" + strings.Join(suffix, " ") + "]"
1807 }
1808 ctx.Variable(pctx, "moduleDescSuffix", s)
1809
Dan Willemsen569edc52018-11-19 09:33:29 -08001810 // Some common property checks for properties that will be used later in androidmk.go
Paul Duffin89968e32020-11-23 18:17:03 +00001811 checkDistProperties(ctx, "dist", &m.distProperties.Dist)
1812 for i, _ := range m.distProperties.Dists {
1813 checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
Dan Willemsen569edc52018-11-19 09:33:29 -08001814 }
1815
Colin Cross4157e882019-06-06 16:57:04 -07001816 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001817 // ensure all direct android.Module deps are enabled
1818 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01001819 if m, ok := bm.(Module); ok {
1820 ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps)
Jooyung Hand48f3c32019-08-23 11:18:57 +09001821 }
1822 })
1823
Bob Badoura75b0572020-02-18 20:21:55 -08001824 m.noticeFiles = make([]Path, 0)
1825 optPath := OptionalPath{}
1826 notice := proptools.StringDefault(m.commonProperties.Notice, "")
Colin Cross4157e882019-06-06 16:57:04 -07001827 if module := SrcIsModule(notice); module != "" {
Bob Badoura75b0572020-02-18 20:21:55 -08001828 optPath = ctx.ExpandOptionalSource(&notice, "notice")
1829 } else if notice != "" {
Jiyong Park52818fc2019-03-18 12:01:38 +09001830 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Bob Badoura75b0572020-02-18 20:21:55 -08001831 optPath = ExistentPathForSource(ctx, noticePath)
1832 }
1833 if optPath.Valid() {
1834 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1835 } else {
1836 for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} {
1837 noticePath := filepath.Join(ctx.ModuleDir(), notice)
1838 optPath = ExistentPathForSource(ctx, noticePath)
1839 if optPath.Valid() {
1840 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1841 }
1842 }
Jaewoong Jung62707f72018-11-16 13:26:43 -08001843 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001844
Bob Badour37af0462021-01-07 03:34:31 +00001845 licensesPropertyFlattener(ctx)
1846 if ctx.Failed() {
1847 return
1848 }
1849
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001850 m.module.GenerateAndroidBuildActions(ctx)
1851 if ctx.Failed() {
1852 return
1853 }
1854
Jiyong Park4d861072021-03-03 20:02:42 +09001855 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1856 rcDir := PathForModuleInstall(ctx, "etc", "init")
1857 for _, src := range m.initRcPaths {
1858 ctx.PackageFile(rcDir, filepath.Base(src.String()), src)
1859 }
1860
1861 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
1862 vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest")
1863 for _, src := range m.vintfFragmentsPaths {
1864 ctx.PackageFile(vintfDir, filepath.Base(src.String()), src)
1865 }
1866
Paul Duffinaf970a22020-11-23 23:32:56 +00001867 // Create the set of tagged dist files after calling GenerateAndroidBuildActions
1868 // as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the
1869 // output paths being set which must be done before or during
1870 // GenerateAndroidBuildActions.
1871 m.distFiles = m.GenerateTaggedDistFiles(ctx)
1872 if ctx.Failed() {
1873 return
1874 }
1875
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001876 m.installFiles = append(m.installFiles, ctx.installFiles...)
1877 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jiyong Park073ea552020-11-09 14:08:34 +09001878 m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
Colin Crossc3d87d32020-06-04 13:25:17 -07001879 for k, v := range ctx.phonies {
1880 m.phonies[k] = append(m.phonies[k], v...)
1881 }
Colin Crossdc35e212019-06-06 16:13:11 -07001882 } else if ctx.Config().AllowMissingDependencies() {
1883 // If the module is not enabled it will not create any build rules, nothing will call
1884 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1885 // and report them as an error even when AllowMissingDependencies = true. Call
1886 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1887 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001888 }
1889
Colin Cross4157e882019-06-06 16:57:04 -07001890 if m == ctx.FinalModule().(Module).base() {
1891 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001892 if ctx.Failed() {
1893 return
1894 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001895 }
Colin Crosscec81712017-07-13 14:43:27 -07001896
Colin Cross5d583952020-11-24 16:21:24 -08001897 m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001898 m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
Colin Cross5d583952020-11-24 16:21:24 -08001899
Colin Cross4157e882019-06-06 16:57:04 -07001900 m.buildParams = ctx.buildParams
1901 m.ruleParams = ctx.ruleParams
1902 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001903}
1904
Paul Duffin89968e32020-11-23 18:17:03 +00001905// Check the supplied dist structure to make sure that it is valid.
1906//
1907// property - the base property, e.g. dist or dists[1], which is combined with the
1908// name of the nested property to produce the full property, e.g. dist.dest or
1909// dists[1].dir.
1910func checkDistProperties(ctx *moduleContext, property string, dist *Dist) {
1911 if dist.Dest != nil {
1912 _, err := validateSafePath(*dist.Dest)
1913 if err != nil {
1914 ctx.PropertyErrorf(property+".dest", "%s", err.Error())
1915 }
1916 }
1917 if dist.Dir != nil {
1918 _, err := validateSafePath(*dist.Dir)
1919 if err != nil {
1920 ctx.PropertyErrorf(property+".dir", "%s", err.Error())
1921 }
1922 }
1923 if dist.Suffix != nil {
1924 if strings.Contains(*dist.Suffix, "/") {
1925 ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.")
1926 }
1927 }
1928
1929}
1930
Colin Cross1184b642019-12-30 18:43:07 -08001931type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001932 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001933
1934 kind moduleKind
1935 config Config
1936}
1937
1938func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
Liz Kammera830f3a2020-11-10 10:50:34 -08001939 return Glob(e, globPattern, excludes)
Colin Cross1184b642019-12-30 18:43:07 -08001940}
1941
1942func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Liz Kammera830f3a2020-11-10 10:50:34 -08001943 return GlobFiles(e, globPattern, excludes)
Colin Cross1184b642019-12-30 18:43:07 -08001944}
1945
Colin Cross988414c2020-01-11 01:11:46 +00001946func (b *earlyModuleContext) IsSymlink(path Path) bool {
1947 fileInfo, err := b.config.fs.Lstat(path.String())
1948 if err != nil {
1949 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1950 }
1951 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1952}
1953
1954func (b *earlyModuleContext) Readlink(path Path) string {
1955 dest, err := b.config.fs.Readlink(path.String())
1956 if err != nil {
1957 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1958 }
1959 return dest
1960}
1961
Colin Cross1184b642019-12-30 18:43:07 -08001962func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001963 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001964 return module
1965}
1966
1967func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001968 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001969}
1970
1971func (e *earlyModuleContext) AConfig() Config {
1972 return e.config
1973}
1974
1975func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1976 return DeviceConfig{e.config.deviceConfig}
1977}
1978
1979func (e *earlyModuleContext) Platform() bool {
1980 return e.kind == platformModule
1981}
1982
1983func (e *earlyModuleContext) DeviceSpecific() bool {
1984 return e.kind == deviceSpecificModule
1985}
1986
1987func (e *earlyModuleContext) SocSpecific() bool {
1988 return e.kind == socSpecificModule
1989}
1990
1991func (e *earlyModuleContext) ProductSpecific() bool {
1992 return e.kind == productSpecificModule
1993}
1994
1995func (e *earlyModuleContext) SystemExtSpecific() bool {
1996 return e.kind == systemExtSpecificModule
1997}
1998
Colin Cross133ebef2020-08-14 17:38:45 -07001999func (e *earlyModuleContext) Namespace() *Namespace {
2000 return e.EarlyModuleContext.Namespace().(*Namespace)
2001}
2002
Colin Cross1184b642019-12-30 18:43:07 -08002003type baseModuleContext struct {
2004 bp blueprint.BaseModuleContext
2005 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08002006 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07002007 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07002008 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07002009 targetPrimary bool
2010 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07002011
2012 walkPath []Module
Paul Duffinc5192442020-03-31 11:31:36 +01002013 tagPath []blueprint.DependencyTag
Colin Crossdc35e212019-06-06 16:13:11 -07002014
2015 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07002016}
2017
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002018func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
2019 return b.bp.OtherModuleName(m)
2020}
2021func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08002022func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Hancd87c692020-02-26 02:05:18 +09002023 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08002024}
2025func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
2026 return b.bp.OtherModuleDependencyTag(m)
2027}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002028func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00002029func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
2030 return b.bp.OtherModuleDependencyVariantExists(variations, name)
2031}
Martin Stjernholm408ffd82021-05-05 15:27:31 +01002032func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool {
2033 return b.bp.OtherModuleFarDependencyVariantExists(variations, name)
2034}
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00002035func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
2036 return b.bp.OtherModuleReverseDependencyVariantExists(name)
2037}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002038func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
2039 return b.bp.OtherModuleType(m)
2040}
Colin Crossd27e7b82020-07-02 11:38:17 -07002041func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
2042 return b.bp.OtherModuleProvider(m, provider)
2043}
2044func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
2045 return b.bp.OtherModuleHasProvider(m, provider)
2046}
2047func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
2048 return b.bp.Provider(provider)
2049}
2050func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
2051 return b.bp.HasProvider(provider)
2052}
2053func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
2054 b.bp.SetProvider(provider, value)
2055}
Colin Cross1184b642019-12-30 18:43:07 -08002056
2057func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2058 return b.bp.GetDirectDepWithTag(name, tag)
2059}
2060
Paul Duffinf88d8e02020-05-07 20:21:34 +01002061func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
2062 return b.bp
2063}
2064
Colin Cross25de6c32019-06-06 14:29:25 -07002065type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07002066 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07002067 baseModuleContext
Jiyong Park073ea552020-11-09 14:08:34 +09002068 packagingSpecs []PackagingSpec
Colin Cross897266e2020-02-13 13:22:08 -08002069 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002070 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07002071 module Module
Colin Crossc3d87d32020-06-04 13:25:17 -07002072 phonies map[string]Paths
Colin Crosscec81712017-07-13 14:43:27 -07002073
2074 // For tests
Colin Crossae887032017-10-23 17:16:14 -07002075 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08002076 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08002077 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08002078}
2079
Colin Crossb88b3c52019-06-10 15:15:17 -07002080func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
2081 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07002082 Rule: ErrorRule,
2083 Description: params.Description,
2084 Output: params.Output,
2085 Outputs: params.Outputs,
2086 ImplicitOutput: params.ImplicitOutput,
2087 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08002088 Args: map[string]string{
2089 "error": err.Error(),
2090 },
Colin Crossb88b3c52019-06-10 15:15:17 -07002091 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002092}
2093
Colin Cross25de6c32019-06-06 14:29:25 -07002094func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
2095 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08002096}
2097
Jingwen Chence679d22020-09-23 04:30:02 +00002098func validateBuildParams(params blueprint.BuildParams) error {
2099 // Validate that the symlink outputs are declared outputs or implicit outputs
2100 allOutputs := map[string]bool{}
2101 for _, output := range params.Outputs {
2102 allOutputs[output] = true
2103 }
2104 for _, output := range params.ImplicitOutputs {
2105 allOutputs[output] = true
2106 }
2107 for _, symlinkOutput := range params.SymlinkOutputs {
2108 if !allOutputs[symlinkOutput] {
2109 return fmt.Errorf(
2110 "Symlink output %s is not a declared output or implicit output",
2111 symlinkOutput)
2112 }
2113 }
2114 return nil
2115}
2116
2117// Convert build parameters from their concrete Android types into their string representations,
2118// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
Colin Cross0875c522017-11-28 17:34:01 -08002119func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002120 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002121 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08002122 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08002123 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002124 Outputs: params.Outputs.Strings(),
2125 ImplicitOutputs: params.ImplicitOutputs.Strings(),
Jingwen Chence679d22020-09-23 04:30:02 +00002126 SymlinkOutputs: params.SymlinkOutputs.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002127 Inputs: params.Inputs.Strings(),
2128 Implicits: params.Implicits.Strings(),
2129 OrderOnly: params.OrderOnly.Strings(),
Colin Cross824f1162020-07-16 13:07:51 -07002130 Validations: params.Validations.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002131 Args: params.Args,
2132 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002133 }
2134
Colin Cross33bfb0a2016-11-21 17:23:08 -08002135 if params.Depfile != nil {
2136 bparams.Depfile = params.Depfile.String()
2137 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002138 if params.Output != nil {
2139 bparams.Outputs = append(bparams.Outputs, params.Output.String())
2140 }
Jingwen Chence679d22020-09-23 04:30:02 +00002141 if params.SymlinkOutput != nil {
2142 bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String())
2143 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002144 if params.ImplicitOutput != nil {
2145 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
2146 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002147 if params.Input != nil {
2148 bparams.Inputs = append(bparams.Inputs, params.Input.String())
2149 }
2150 if params.Implicit != nil {
2151 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
2152 }
Colin Cross824f1162020-07-16 13:07:51 -07002153 if params.Validation != nil {
2154 bparams.Validations = append(bparams.Validations, params.Validation.String())
2155 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002156
Colin Cross0b9f31f2019-02-28 11:00:01 -08002157 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
2158 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
Jingwen Chence679d22020-09-23 04:30:02 +00002159 bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs)
Colin Cross0b9f31f2019-02-28 11:00:01 -08002160 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
2161 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
2162 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
Colin Cross824f1162020-07-16 13:07:51 -07002163 bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
2164 bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
Colin Crossfe4bc362018-09-12 10:02:13 -07002165
Colin Cross0875c522017-11-28 17:34:01 -08002166 return bparams
2167}
2168
Colin Cross25de6c32019-06-06 14:29:25 -07002169func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
2170 if m.config.captureBuild {
2171 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08002172 }
2173
Colin Crossdc35e212019-06-06 16:13:11 -07002174 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08002175}
2176
Colin Cross25de6c32019-06-06 14:29:25 -07002177func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08002178 argNames ...string) blueprint.Rule {
2179
Ramy Medhat944839a2020-03-31 22:14:52 -04002180 if m.config.UseRemoteBuild() {
2181 if params.Pool == nil {
2182 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
2183 // jobs to the local parallelism value
2184 params.Pool = localPool
2185 } else if params.Pool == remotePool {
2186 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
2187 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
2188 // parallelism.
2189 params.Pool = nil
2190 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07002191 }
2192
Colin Crossdc35e212019-06-06 16:13:11 -07002193 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08002194
Colin Cross25de6c32019-06-06 14:29:25 -07002195 if m.config.captureBuild {
2196 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08002197 }
2198
2199 return rule
Colin Cross0875c522017-11-28 17:34:01 -08002200}
2201
Colin Cross25de6c32019-06-06 14:29:25 -07002202func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07002203 if params.Description != "" {
2204 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
2205 }
2206
2207 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
2208 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
2209 m.ModuleName(), strings.Join(missingDeps, ", ")))
2210 }
2211
Colin Cross25de6c32019-06-06 14:29:25 -07002212 if m.config.captureBuild {
2213 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08002214 }
2215
Jingwen Chence679d22020-09-23 04:30:02 +00002216 bparams := convertBuildParams(params)
2217 err := validateBuildParams(bparams)
2218 if err != nil {
2219 m.ModuleErrorf(
2220 "%s: build parameter validation failed: %s",
2221 m.ModuleName(),
2222 err.Error())
2223 }
2224 m.bp.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002225}
Colin Crossc3d87d32020-06-04 13:25:17 -07002226
2227func (m *moduleContext) Phony(name string, deps ...Path) {
2228 addPhony(m.config, name, deps...)
2229}
2230
Colin Cross25de6c32019-06-06 14:29:25 -07002231func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07002232 var missingDeps []string
2233 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07002234 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07002235 missingDeps = FirstUniqueStrings(missingDeps)
2236 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08002237}
2238
Colin Crossdc35e212019-06-06 16:13:11 -07002239func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002240 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002241 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07002242 *missingDeps = append(*missingDeps, deps...)
2243 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002244 }
2245}
2246
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002247type AllowDisabledModuleDependency interface {
2248 blueprint.DependencyTag
2249 AllowDisabledModuleDependency(target Module) bool
2250}
2251
2252func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07002253 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07002254
2255 if !strict {
2256 return aModule
2257 }
2258
Colin Cross380c69a2019-06-10 17:49:58 +00002259 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002260 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00002261 return nil
2262 }
2263
2264 if !aModule.Enabled() {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002265 if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) {
2266 if b.Config().AllowMissingDependencies() {
2267 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
2268 } else {
2269 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
2270 }
Colin Cross380c69a2019-06-10 17:49:58 +00002271 }
2272 return nil
2273 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002274 return aModule
2275}
2276
Liz Kammer2b50ce62021-04-26 15:47:28 -04002277type dep struct {
2278 mod blueprint.Module
2279 tag blueprint.DependencyTag
2280}
2281
2282func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep {
Jiyong Parkf2976302019-04-17 21:47:37 +09002283 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07002284 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Liz Kammer356f7d42021-01-26 09:18:53 -05002285 if aModule, _ := module.(Module); aModule != nil {
2286 if aModule.base().BaseModuleName() == name {
2287 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
2288 if tag == nil || returnedTag == tag {
2289 deps = append(deps, dep{aModule, returnedTag})
2290 }
2291 }
2292 } else if b.bp.OtherModuleName(module) == name {
2293 returnedTag := b.bp.OtherModuleDependencyTag(module)
Jiyong Parkf2976302019-04-17 21:47:37 +09002294 if tag == nil || returnedTag == tag {
Liz Kammer356f7d42021-01-26 09:18:53 -05002295 deps = append(deps, dep{module, returnedTag})
Jiyong Parkf2976302019-04-17 21:47:37 +09002296 }
2297 }
2298 })
Liz Kammer2b50ce62021-04-26 15:47:28 -04002299 return deps
2300}
2301
2302func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
2303 deps := b.getDirectDepsInternal(name, tag)
Jiyong Parkf2976302019-04-17 21:47:37 +09002304 if len(deps) == 1 {
2305 return deps[0].mod, deps[0].tag
2306 } else if len(deps) >= 2 {
2307 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07002308 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09002309 } else {
2310 return nil, nil
2311 }
2312}
2313
Liz Kammer2b50ce62021-04-26 15:47:28 -04002314func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module, blueprint.DependencyTag) {
2315 foundDeps := b.getDirectDepsInternal(name, nil)
2316 deps := map[blueprint.Module]bool{}
2317 for _, dep := range foundDeps {
2318 deps[dep.mod] = true
2319 }
2320 if len(deps) == 1 {
2321 return foundDeps[0].mod, foundDeps[0].tag
2322 } else if len(deps) >= 2 {
2323 // this could happen if two dependencies have the same name in different namespaces
2324 // TODO(b/186554727): this should not occur if namespaces are handled within
2325 // getDirectDepsInternal.
2326 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
2327 name, b.ModuleName()))
2328 } else {
2329 return nil, nil
2330 }
2331}
2332
Colin Crossdc35e212019-06-06 16:13:11 -07002333func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07002334 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07002335 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07002336 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002337 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07002338 deps = append(deps, aModule)
2339 }
2340 }
2341 })
2342 return deps
2343}
2344
Colin Cross25de6c32019-06-06 14:29:25 -07002345func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2346 module, _ := m.getDirectDepInternal(name, tag)
2347 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09002348}
2349
Liz Kammer2b50ce62021-04-26 15:47:28 -04002350// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
2351// name, or nil if none exists. If there are multiple dependencies on the same module it returns the
2352// first DependencyTag.
Colin Crossdc35e212019-06-06 16:13:11 -07002353func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
Liz Kammer2b50ce62021-04-26 15:47:28 -04002354 return b.getDirectDepFirstTag(name)
Jiyong Parkf2976302019-04-17 21:47:37 +09002355}
2356
Colin Crossdc35e212019-06-06 16:13:11 -07002357func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002358 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08002359}
2360
Colin Crossdc35e212019-06-06 16:13:11 -07002361func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002362 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002363 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002364 visit(aModule)
2365 }
2366 })
2367}
2368
Colin Crossdc35e212019-06-06 16:13:11 -07002369func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002370 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002371 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002372 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08002373 visit(aModule)
2374 }
2375 }
2376 })
2377}
2378
Colin Crossdc35e212019-06-06 16:13:11 -07002379func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002380 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002381 // pred
2382 func(module blueprint.Module) bool {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002383 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002384 return pred(aModule)
2385 } else {
2386 return false
2387 }
2388 },
2389 // visit
2390 func(module blueprint.Module) {
2391 visit(module.(Module))
2392 })
2393}
2394
Colin Crossdc35e212019-06-06 16:13:11 -07002395func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002396 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002397 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002398 visit(aModule)
2399 }
2400 })
2401}
2402
Colin Crossdc35e212019-06-06 16:13:11 -07002403func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002404 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002405 // pred
2406 func(module blueprint.Module) bool {
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +01002407 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002408 return pred(aModule)
2409 } else {
2410 return false
2411 }
2412 },
2413 // visit
2414 func(module blueprint.Module) {
2415 visit(module.(Module))
2416 })
2417}
2418
Colin Crossdc35e212019-06-06 16:13:11 -07002419func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08002420 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08002421}
2422
Colin Crossdc35e212019-06-06 16:13:11 -07002423func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
2424 b.walkPath = []Module{b.Module()}
Paul Duffinc5192442020-03-31 11:31:36 +01002425 b.tagPath = []blueprint.DependencyTag{}
Colin Cross1184b642019-12-30 18:43:07 -08002426 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002427 childAndroidModule, _ := child.(Module)
2428 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07002429 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002430 // record walkPath before visit
2431 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
2432 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
Paul Duffinc5192442020-03-31 11:31:36 +01002433 b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
Colin Crossdc35e212019-06-06 16:13:11 -07002434 }
2435 b.walkPath = append(b.walkPath, childAndroidModule)
Paul Duffinc5192442020-03-31 11:31:36 +01002436 b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07002437 return visit(childAndroidModule, parentAndroidModule)
2438 } else {
2439 return false
2440 }
2441 })
2442}
2443
Colin Crossdc35e212019-06-06 16:13:11 -07002444func (b *baseModuleContext) GetWalkPath() []Module {
2445 return b.walkPath
2446}
2447
Paul Duffinc5192442020-03-31 11:31:36 +01002448func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
2449 return b.tagPath
2450}
2451
Colin Cross4dfacf92020-09-16 19:22:27 -07002452func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
2453 b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
2454 visit(module.(Module))
2455 })
2456}
2457
2458func (b *baseModuleContext) PrimaryModule() Module {
2459 return b.bp.PrimaryModule().(Module)
2460}
2461
2462func (b *baseModuleContext) FinalModule() Module {
2463 return b.bp.FinalModule().(Module)
2464}
2465
Bob Badour07065cd2021-02-05 19:59:11 -08002466// IsMetaDependencyTag returns true for cross-cutting metadata dependencies.
2467func IsMetaDependencyTag(tag blueprint.DependencyTag) bool {
2468 if tag == licenseKindTag {
2469 return true
2470 } else if tag == licensesTag {
2471 return true
2472 }
2473 return false
2474}
2475
Jiyong Park1c7e9622020-05-07 16:12:13 +09002476// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
2477// a dependency tag.
Colin Cross6e511a92020-07-27 21:26:48 -07002478var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002479
2480// PrettyPrintTag returns string representation of the tag, but prefers
2481// custom String() method if available.
2482func PrettyPrintTag(tag blueprint.DependencyTag) string {
2483 // Use tag's custom String() method if available.
2484 if stringer, ok := tag.(fmt.Stringer); ok {
2485 return stringer.String()
2486 }
2487
2488 // Otherwise, get a default string representation of the tag's struct.
Colin Cross6e511a92020-07-27 21:26:48 -07002489 tagString := fmt.Sprintf("%T: %+v", tag, tag)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002490
2491 // Remove the boilerplate from BaseDependencyTag as it adds no value.
2492 tagString = tagCleaner.ReplaceAllString(tagString, "")
2493 return tagString
2494}
2495
2496func (b *baseModuleContext) GetPathString(skipFirst bool) string {
2497 sb := strings.Builder{}
2498 tagPath := b.GetTagPath()
2499 walkPath := b.GetWalkPath()
2500 if !skipFirst {
2501 sb.WriteString(walkPath[0].String())
2502 }
2503 for i, m := range walkPath[1:] {
2504 sb.WriteString("\n")
2505 sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
2506 sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
2507 }
2508 return sb.String()
2509}
2510
Colin Crossdc35e212019-06-06 16:13:11 -07002511func (m *moduleContext) ModuleSubDir() string {
2512 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08002513}
2514
Colin Cross0ea8ba82019-06-06 14:33:29 -07002515func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002516 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07002517}
2518
Colin Cross0ea8ba82019-06-06 14:33:29 -07002519func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002520 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07002521}
2522
Colin Cross0ea8ba82019-06-06 14:33:29 -07002523func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002524 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07002525}
2526
Colin Cross0ea8ba82019-06-06 14:33:29 -07002527func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07002528 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08002529}
2530
Colin Cross0ea8ba82019-06-06 14:33:29 -07002531func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002532 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08002533}
2534
Colin Cross0ea8ba82019-06-06 14:33:29 -07002535func (b *baseModuleContext) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09002536 return b.os.Class == Host
Colin Crossf6566ed2015-03-24 11:13:38 -07002537}
2538
Colin Cross0ea8ba82019-06-06 14:33:29 -07002539func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002540 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07002541}
2542
Colin Cross0ea8ba82019-06-06 14:33:29 -07002543func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002544 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07002545}
2546
Colin Cross0ea8ba82019-06-06 14:33:29 -07002547func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002548 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08002549}
2550
Colin Cross0ea8ba82019-06-06 14:33:29 -07002551func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002552 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07002553}
2554
Colin Cross0ea8ba82019-06-06 14:33:29 -07002555func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002556 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07002557}
2558
Colin Cross0ea8ba82019-06-06 14:33:29 -07002559func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002560 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07002561 return true
2562 }
Colin Cross25de6c32019-06-06 14:29:25 -07002563 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07002564}
2565
Jiyong Park5baac542018-08-28 09:55:37 +09002566// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09002567// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07002568func (m *ModuleBase) MakeAsPlatform() {
2569 m.commonProperties.Vendor = boolPtr(false)
2570 m.commonProperties.Proprietary = boolPtr(false)
2571 m.commonProperties.Soc_specific = boolPtr(false)
2572 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09002573 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09002574}
2575
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002576func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09002577 m.commonProperties.Vendor = boolPtr(false)
2578 m.commonProperties.Proprietary = boolPtr(false)
2579 m.commonProperties.Soc_specific = boolPtr(false)
2580 m.commonProperties.Product_specific = boolPtr(false)
2581 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002582}
2583
Jooyung Han344d5432019-08-23 11:17:39 +09002584// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
2585func (m *ModuleBase) IsNativeBridgeSupported() bool {
2586 return proptools.Bool(m.commonProperties.Native_bridge_supported)
2587}
2588
Colin Cross25de6c32019-06-06 14:29:25 -07002589func (m *moduleContext) InstallInData() bool {
2590 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08002591}
2592
Jaewoong Jung0949f312019-09-11 10:25:18 -07002593func (m *moduleContext) InstallInTestcases() bool {
2594 return m.module.InstallInTestcases()
2595}
2596
Colin Cross25de6c32019-06-06 14:29:25 -07002597func (m *moduleContext) InstallInSanitizerDir() bool {
2598 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002599}
2600
Yifan Hong1b3348d2020-01-21 15:53:22 -08002601func (m *moduleContext) InstallInRamdisk() bool {
2602 return m.module.InstallInRamdisk()
2603}
2604
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002605func (m *moduleContext) InstallInVendorRamdisk() bool {
2606 return m.module.InstallInVendorRamdisk()
2607}
2608
Inseob Kim08758f02021-04-08 21:13:22 +09002609func (m *moduleContext) InstallInDebugRamdisk() bool {
2610 return m.module.InstallInDebugRamdisk()
2611}
2612
Colin Cross25de6c32019-06-06 14:29:25 -07002613func (m *moduleContext) InstallInRecovery() bool {
2614 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002615}
2616
Colin Cross90ba5f42019-10-02 11:10:58 -07002617func (m *moduleContext) InstallInRoot() bool {
2618 return m.module.InstallInRoot()
2619}
2620
Colin Cross607d8582019-07-29 16:44:46 -07002621func (m *moduleContext) InstallBypassMake() bool {
2622 return m.module.InstallBypassMake()
2623}
2624
Jiyong Park87788b52020-09-01 12:37:45 +09002625func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
Colin Cross6e359402020-02-10 15:29:54 -08002626 return m.module.InstallForceOS()
2627}
2628
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002629func (m *moduleContext) skipInstall() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002630 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07002631 return true
2632 }
2633
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002634 if m.module.base().commonProperties.HideFromMake {
2635 return true
2636 }
2637
Colin Cross3607f212018-05-07 15:28:05 -07002638 // We'll need a solution for choosing which of modules with the same name in different
2639 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
2640 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07002641 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07002642 return true
2643 }
2644
Colin Cross25de6c32019-06-06 14:29:25 -07002645 if m.Device() {
Jingwen Chencda22c92020-11-23 00:22:30 -05002646 if m.Config().KatiEnabled() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07002647 return true
2648 }
Colin Cross893d8162017-04-26 17:34:03 -07002649 }
2650
2651 return false
2652}
2653
Colin Cross70dda7e2019-10-01 22:05:35 -07002654func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
2655 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002656 return m.installFile(installPath, name, srcPath, deps, false)
Colin Cross5c517922017-08-31 12:29:17 -07002657}
2658
Colin Cross70dda7e2019-10-01 22:05:35 -07002659func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
2660 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002661 return m.installFile(installPath, name, srcPath, deps, true)
Colin Cross5c517922017-08-31 12:29:17 -07002662}
2663
Colin Cross41589502020-12-01 14:00:21 -08002664func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec {
2665 fullInstallPath := installPath.Join(m, name)
2666 return m.packageFile(fullInstallPath, srcPath, false)
2667}
2668
2669func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
2670 spec := PackagingSpec{
2671 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2672 srcPath: srcPath,
2673 symlinkTarget: "",
2674 executable: executable,
2675 }
2676 m.packagingSpecs = append(m.packagingSpecs, spec)
2677 return spec
2678}
2679
Jiyong Park073ea552020-11-09 14:08:34 +09002680func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07002681
Colin Cross25de6c32019-06-06 14:29:25 -07002682 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002683 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08002684
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002685 if !m.skipInstall() {
Colin Cross5d583952020-11-24 16:21:24 -08002686 deps = append(deps, m.module.base().installFilesDepSet.ToList().Paths()...)
Colin Cross35cec122015-04-02 14:37:16 -07002687
Colin Cross89562dc2016-10-03 17:47:19 -07002688 var implicitDeps, orderOnlyDeps Paths
2689
Colin Cross25de6c32019-06-06 14:29:25 -07002690 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07002691 // Installed host modules might be used during the build, depend directly on their
2692 // dependencies so their timestamp is updated whenever their dependency is updated
2693 implicitDeps = deps
2694 } else {
2695 orderOnlyDeps = deps
2696 }
2697
Jiyong Park073ea552020-11-09 14:08:34 +09002698 rule := Cp
2699 if executable {
2700 rule = CpExecutable
2701 }
2702
Colin Cross25de6c32019-06-06 14:29:25 -07002703 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07002704 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07002705 Description: "install " + fullInstallPath.Base(),
2706 Output: fullInstallPath,
2707 Input: srcPath,
2708 Implicits: implicitDeps,
2709 OrderOnly: orderOnlyDeps,
Jingwen Chencda22c92020-11-23 00:22:30 -05002710 Default: !m.Config().KatiEnabled(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08002711 })
Colin Cross3f40fa42015-01-30 17:27:36 -08002712
Colin Cross25de6c32019-06-06 14:29:25 -07002713 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08002714 }
Jiyong Park073ea552020-11-09 14:08:34 +09002715
Colin Cross41589502020-12-01 14:00:21 -08002716 m.packageFile(fullInstallPath, srcPath, executable)
Jiyong Park073ea552020-11-09 14:08:34 +09002717
Colin Cross25de6c32019-06-06 14:29:25 -07002718 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002719
Colin Cross35cec122015-04-02 14:37:16 -07002720 return fullInstallPath
2721}
2722
Colin Cross70dda7e2019-10-01 22:05:35 -07002723func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002724 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002725 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08002726
Jiyong Park073ea552020-11-09 14:08:34 +09002727 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
2728 if err != nil {
2729 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
2730 }
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002731 if !m.skipInstall() {
Colin Crossce75d2c2016-10-06 16:12:58 -07002732
Colin Cross25de6c32019-06-06 14:29:25 -07002733 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07002734 Rule: Symlink,
2735 Description: "install symlink " + fullInstallPath.Base(),
2736 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08002737 Input: srcPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002738 Default: !m.Config().KatiEnabled(),
Colin Cross12fc4972016-01-11 12:49:11 -08002739 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08002740 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08002741 },
2742 })
Colin Cross3854a602016-01-11 12:49:11 -08002743
Colin Cross25de6c32019-06-06 14:29:25 -07002744 m.installFiles = append(m.installFiles, fullInstallPath)
2745 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08002746 }
Jiyong Park073ea552020-11-09 14:08:34 +09002747
2748 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2749 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2750 srcPath: nil,
2751 symlinkTarget: relPath,
2752 executable: false,
2753 })
2754
Colin Cross3854a602016-01-11 12:49:11 -08002755 return fullInstallPath
2756}
2757
Jiyong Parkf1194352019-02-25 11:05:47 +09002758// installPath/name -> absPath where absPath might be a path that is available only at runtime
2759// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07002760func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002761 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002762 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09002763
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002764 if !m.skipInstall() {
Colin Cross25de6c32019-06-06 14:29:25 -07002765 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09002766 Rule: Symlink,
2767 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
2768 Output: fullInstallPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002769 Default: !m.Config().KatiEnabled(),
Jiyong Parkf1194352019-02-25 11:05:47 +09002770 Args: map[string]string{
2771 "fromPath": absPath,
2772 },
2773 })
2774
Colin Cross25de6c32019-06-06 14:29:25 -07002775 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09002776 }
Jiyong Park073ea552020-11-09 14:08:34 +09002777
2778 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2779 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2780 srcPath: nil,
2781 symlinkTarget: absPath,
2782 executable: false,
2783 })
2784
Jiyong Parkf1194352019-02-25 11:05:47 +09002785 return fullInstallPath
2786}
2787
Colin Cross25de6c32019-06-06 14:29:25 -07002788func (m *moduleContext) CheckbuildFile(srcPath Path) {
2789 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08002790}
2791
Colin Crossc20dc852020-11-10 12:27:45 -08002792func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
2793 return m.bp
2794}
2795
Colin Cross41955e82019-05-29 14:40:35 -07002796// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
2797// was not a module reference.
2798func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08002799 if len(s) > 1 && s[0] == ':' {
2800 return s[1:]
2801 }
2802 return ""
2803}
2804
Colin Cross41955e82019-05-29 14:40:35 -07002805// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
2806// module name and an empty string for the tag, or empty strings if the input was not a module reference.
2807func SrcIsModuleWithTag(s string) (module, tag string) {
2808 if len(s) > 1 && s[0] == ':' {
2809 module = s[1:]
2810 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2811 if module[len(module)-1] == '}' {
2812 tag = module[tagStart+1 : len(module)-1]
2813 module = module[:tagStart]
2814 return module, tag
2815 }
2816 }
2817 return module, ""
2818 }
2819 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08002820}
2821
Colin Cross41955e82019-05-29 14:40:35 -07002822type sourceOrOutputDependencyTag struct {
2823 blueprint.BaseDependencyTag
2824 tag string
2825}
2826
2827func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
2828 return sourceOrOutputDependencyTag{tag: tag}
2829}
2830
2831var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08002832
Colin Cross366938f2017-12-11 16:29:02 -08002833// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
2834// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002835//
2836// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08002837func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07002838 set := make(map[string]bool)
2839
Colin Cross068e0fe2016-12-13 15:23:47 -08002840 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07002841 if m, t := SrcIsModuleWithTag(s); m != "" {
2842 if _, found := set[s]; found {
2843 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07002844 } else {
Colin Cross41955e82019-05-29 14:40:35 -07002845 set[s] = true
2846 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07002847 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002848 }
2849 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002850}
2851
Colin Cross366938f2017-12-11 16:29:02 -08002852// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
2853// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002854//
2855// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08002856func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
2857 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07002858 if m, t := SrcIsModuleWithTag(*s); m != "" {
2859 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08002860 }
2861 }
2862}
2863
Colin Cross41955e82019-05-29 14:40:35 -07002864// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
2865// 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 -08002866type SourceFileProducer interface {
2867 Srcs() Paths
2868}
2869
Colin Cross41955e82019-05-29 14:40:35 -07002870// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002871// 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 -07002872// listed in the property.
2873type OutputFileProducer interface {
2874 OutputFiles(tag string) (Paths, error)
2875}
2876
Colin Cross5e708052019-08-06 13:59:50 -07002877// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2878// module produced zero paths, it reports errors to the ctx and returns nil.
2879func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2880 paths, err := outputFilesForModule(ctx, module, tag)
2881 if err != nil {
2882 reportPathError(ctx, err)
2883 return nil
2884 }
2885 return paths
2886}
2887
2888// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2889// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2890func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2891 paths, err := outputFilesForModule(ctx, module, tag)
2892 if err != nil {
2893 reportPathError(ctx, err)
2894 return nil
2895 }
2896 if len(paths) > 1 {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01002897 ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
Colin Cross5e708052019-08-06 13:59:50 -07002898 pathContextName(ctx, module))
2899 return nil
2900 }
2901 return paths[0]
2902}
2903
2904func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2905 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2906 paths, err := outputFileProducer.OutputFiles(tag)
2907 if err != nil {
2908 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2909 pathContextName(ctx, module), err.Error())
2910 }
2911 if len(paths) == 0 {
2912 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2913 }
2914 return paths, nil
Colin Cross74b1e2b2020-11-22 20:23:02 -08002915 } else if sourceFileProducer, ok := module.(SourceFileProducer); ok {
2916 if tag != "" {
2917 return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag)
2918 }
2919 paths := sourceFileProducer.Srcs()
2920 if len(paths) == 0 {
2921 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2922 }
2923 return paths, nil
Colin Cross5e708052019-08-06 13:59:50 -07002924 } else {
2925 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2926 }
2927}
2928
Colin Cross41589502020-12-01 14:00:21 -08002929// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to
2930// specify that they can be used as a tool by a genrule module.
Colin Crossfe17f6f2019-03-28 19:30:56 -07002931type HostToolProvider interface {
Colin Crossba9e4032020-11-24 16:32:22 -08002932 Module
Colin Cross41589502020-12-01 14:00:21 -08002933 // HostToolPath returns the path to the host tool for the module if it is one, or an invalid
2934 // OptionalPath.
Colin Crossfe17f6f2019-03-28 19:30:56 -07002935 HostToolPath() OptionalPath
2936}
2937
Colin Cross27b922f2019-03-04 22:35:41 -08002938// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2939// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002940//
2941// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002942func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2943 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002944}
2945
Colin Cross2fafa3e2019-03-05 12:39:51 -08002946// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2947// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002948//
2949// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002950func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2951 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002952}
2953
2954// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2955// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2956// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002957func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002958 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002959 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002960 }
2961 return OptionalPath{}
2962}
2963
Colin Cross25de6c32019-06-06 14:29:25 -07002964func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002965 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002966}
2967
Colin Cross25de6c32019-06-06 14:29:25 -07002968func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002969 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002970}
2971
Colin Cross25de6c32019-06-06 14:29:25 -07002972func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002973 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002974}
2975
Colin Cross463a90e2015-06-17 14:20:06 -07002976func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002977 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002978}
2979
Colin Cross0875c522017-11-28 17:34:01 -08002980func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002981 return &buildTargetSingleton{}
2982}
2983
Colin Cross87d8b562017-04-25 10:01:55 -07002984func parentDir(dir string) string {
2985 dir, _ = filepath.Split(dir)
2986 return filepath.Clean(dir)
2987}
2988
Colin Cross1f8c52b2015-06-16 16:38:17 -07002989type buildTargetSingleton struct{}
2990
Colin Cross0875c522017-11-28 17:34:01 -08002991func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2992 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002993
Colin Crossc3d87d32020-06-04 13:25:17 -07002994 mmTarget := func(dir string) string {
2995 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07002996 }
2997
Colin Cross0875c522017-11-28 17:34:01 -08002998 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002999
Colin Cross0875c522017-11-28 17:34:01 -08003000 ctx.VisitAllModules(func(module Module) {
3001 blueprintDir := module.base().blueprintDir
3002 installTarget := module.base().installTarget
3003 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07003004
Colin Cross0875c522017-11-28 17:34:01 -08003005 if checkbuildTarget != nil {
3006 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
3007 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
3008 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003009
Colin Cross0875c522017-11-28 17:34:01 -08003010 if installTarget != nil {
3011 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003012 }
3013 })
3014
Dan Willemsen5ba07e82015-12-11 13:51:06 -08003015 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05003016 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08003017 suffix = "-soong"
3018 }
3019
Colin Cross1f8c52b2015-06-16 16:38:17 -07003020 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07003021 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003022
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003023 // Make will generate the MODULES-IN-* targets
Jingwen Chencda22c92020-11-23 00:22:30 -05003024 if ctx.Config().KatiEnabled() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003025 return
3026 }
3027
Colin Cross87d8b562017-04-25 10:01:55 -07003028 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09003029 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07003030 for _, dir := range dirs {
3031 dir := parentDir(dir)
3032 for dir != "." && dir != "/" {
3033 if _, exists := modulesInDir[dir]; exists {
3034 break
3035 }
3036 modulesInDir[dir] = nil
3037 dir = parentDir(dir)
3038 }
3039 }
3040
3041 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07003042 for _, dir := range dirs {
3043 p := parentDir(dir)
3044 if p != "." && p != "/" {
Colin Crossc3d87d32020-06-04 13:25:17 -07003045 modulesInDir[p] = append(modulesInDir[p], PathForPhony(ctx, mmTarget(dir)))
Colin Cross87d8b562017-04-25 10:01:55 -07003046 }
3047 }
3048
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003049 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
3050 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
3051 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07003052 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07003053 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003054 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07003055
3056 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
Jiyong Park1613e552020-09-14 19:43:17 +09003057 type osAndCross struct {
3058 os OsType
3059 hostCross bool
3060 }
3061 osDeps := map[osAndCross]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08003062 ctx.VisitAllModules(func(module Module) {
3063 if module.Enabled() {
Jiyong Park1613e552020-09-14 19:43:17 +09003064 key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
3065 osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003066 }
3067 })
3068
Colin Cross0875c522017-11-28 17:34:01 -08003069 osClass := make(map[string]Paths)
Jiyong Park1613e552020-09-14 19:43:17 +09003070 for key, deps := range osDeps {
Dan Willemsen61d88b82017-09-20 17:29:08 -07003071 var className string
3072
Jiyong Park1613e552020-09-14 19:43:17 +09003073 switch key.os.Class {
Dan Willemsen61d88b82017-09-20 17:29:08 -07003074 case Host:
Jiyong Park1613e552020-09-14 19:43:17 +09003075 if key.hostCross {
3076 className = "host-cross"
3077 } else {
3078 className = "host"
3079 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07003080 case Device:
3081 className = "target"
3082 default:
3083 continue
3084 }
3085
Jiyong Park1613e552020-09-14 19:43:17 +09003086 name := className + "-" + key.os.Name
Colin Crossc3d87d32020-06-04 13:25:17 -07003087 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07003088
Colin Crossc3d87d32020-06-04 13:25:17 -07003089 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003090 }
3091
3092 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09003093 for _, class := range SortedStringKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07003094 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003095 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003096}
Colin Crossd779da42015-12-17 18:00:23 -08003097
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003098// Collect information for opening IDE project files in java/jdeps.go.
3099type IDEInfo interface {
3100 IDEInfo(ideInfo *IdeInfo)
3101 BaseModuleName() string
3102}
3103
3104// Extract the base module name from the Import name.
3105// Often the Import name has a prefix "prebuilt_".
3106// Remove the prefix explicitly if needed
3107// until we find a better solution to get the Import name.
3108type IDECustomizedModuleName interface {
3109 IDECustomizedModuleName() string
3110}
3111
3112type IdeInfo struct {
3113 Deps []string `json:"dependencies,omitempty"`
3114 Srcs []string `json:"srcs,omitempty"`
3115 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
3116 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
3117 Jars []string `json:"jars,omitempty"`
3118 Classes []string `json:"class,omitempty"`
3119 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08003120 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08003121 Paths []string `json:"path,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003122}
Paul Duffinf88d8e02020-05-07 20:21:34 +01003123
3124func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
3125 bpctx := ctx.blueprintBaseModuleContext()
3126 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
3127}
Colin Cross5d583952020-11-24 16:21:24 -08003128
3129// installPathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
3130// topological order.
3131type installPathsDepSet struct {
3132 depSet
3133}
3134
3135// newInstallPathsDepSet returns an immutable packagingSpecsDepSet with the given direct and
3136// transitive contents.
3137func newInstallPathsDepSet(direct InstallPaths, transitive []*installPathsDepSet) *installPathsDepSet {
3138 return &installPathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
3139}
3140
3141// ToList returns the installPathsDepSet flattened to a list in topological order.
3142func (d *installPathsDepSet) ToList() InstallPaths {
3143 if d == nil {
3144 return nil
3145 }
3146 return d.depSet.ToList().(InstallPaths)
3147}