blob: 786f79d57f32184a5cb5732437c57c28786a909d [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000019 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080020 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "path/filepath"
Jiyong Park1c7e9622020-05-07 16:12:13 +090022 "regexp"
Colin Cross6ff51382015-12-17 16:39:19 -080023 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080024 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070025
Paul Duffin3e7d3ca2021-09-09 16:37:49 +010026 "android/soong/bazel"
27
Colin Crossf6566ed2015-03-24 11:13:38 -070028 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070029 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080030)
31
32var (
33 DeviceSharedLibrary = "shared_library"
34 DeviceStaticLibrary = "static_library"
35 DeviceExecutable = "executable"
36 HostSharedLibrary = "host_shared_library"
37 HostStaticLibrary = "host_static_library"
38 HostExecutable = "host_executable"
39)
40
Colin Crossae887032017-10-23 17:16:14 -070041type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070042 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080043 Deps blueprint.Deps
44 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070045 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070046 Output WritablePath
47 Outputs WritablePaths
Jingwen Chence679d22020-09-23 04:30:02 +000048 SymlinkOutput WritablePath
49 SymlinkOutputs WritablePaths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070050 ImplicitOutput WritablePath
51 ImplicitOutputs WritablePaths
52 Input Path
53 Inputs Paths
54 Implicit Path
55 Implicits Paths
56 OrderOnly Paths
Colin Cross824f1162020-07-16 13:07:51 -070057 Validation Path
58 Validations Paths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070059 Default bool
60 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070061}
62
Colin Crossae887032017-10-23 17:16:14 -070063type ModuleBuildParams BuildParams
64
Colin Cross1184b642019-12-30 18:43:07 -080065// EarlyModuleContext provides methods that can be called early, as soon as the properties have
66// been parsed into the module and before any mutators have run.
67type EarlyModuleContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -070068 // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
69 // reference to itself.
Colin Cross1184b642019-12-30 18:43:07 -080070 Module() Module
Colin Cross9f35c3d2020-09-16 19:04:41 -070071
72 // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
73 // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
Colin Cross1184b642019-12-30 18:43:07 -080074 ModuleName() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070075
76 // ModuleDir returns the path to the directory that contains the definition of the module.
Colin Cross1184b642019-12-30 18:43:07 -080077 ModuleDir() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070078
79 // ModuleType returns the name of the module type that was used to create the module, as specified in
80 // RegisterModuleType.
Colin Cross1184b642019-12-30 18:43:07 -080081 ModuleType() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070082
83 // BlueprintFile returns the name of the blueprint file that contains the definition of this
84 // module.
Colin Cross9d34f352019-11-22 16:03:51 -080085 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080086
Colin Cross9f35c3d2020-09-16 19:04:41 -070087 // ContainsProperty returns true if the specified property name was set in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080088 ContainsProperty(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -070089
90 // Errorf reports an error at the specified position of the module definition file.
Colin Cross1184b642019-12-30 18:43:07 -080091 Errorf(pos scanner.Position, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070092
93 // ModuleErrorf reports an error at the line number of the module type in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080094 ModuleErrorf(fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070095
96 // PropertyErrorf reports an error at the line number of a property in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080097 PropertyErrorf(property, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070098
99 // Failed returns true if any errors have been reported. In most cases the module can continue with generating
100 // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
101 // has prevented the module from creating necessary data it can return early when Failed returns true.
Colin Cross1184b642019-12-30 18:43:07 -0800102 Failed() bool
103
Colin Cross9f35c3d2020-09-16 19:04:41 -0700104 // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
105 // primary builder will be rerun whenever the specified files are modified.
Colin Cross1184b642019-12-30 18:43:07 -0800106 AddNinjaFileDeps(deps ...string)
107
108 DeviceSpecific() bool
109 SocSpecific() bool
110 ProductSpecific() bool
111 SystemExtSpecific() bool
112 Platform() bool
113
114 Config() Config
115 DeviceConfig() DeviceConfig
116
117 // Deprecated: use Config()
118 AConfig() Config
119
120 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
121 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
122 // builder whenever a file matching the pattern as added or removed, without rerunning if a
123 // file that does not match the pattern is added to a searched directory.
124 GlobWithDeps(pattern string, excludes []string) ([]string, error)
125
126 Glob(globPattern string, excludes []string) Paths
127 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +0000128 IsSymlink(path Path) bool
129 Readlink(path Path) string
Colin Cross133ebef2020-08-14 17:38:45 -0700130
Colin Cross9f35c3d2020-09-16 19:04:41 -0700131 // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
132 // default SimpleNameInterface if Context.SetNameInterface was not called.
Colin Cross133ebef2020-08-14 17:38:45 -0700133 Namespace() *Namespace
Colin Cross1184b642019-12-30 18:43:07 -0800134}
135
Colin Cross0ea8ba82019-06-06 14:33:29 -0700136// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700137// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
138// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700139// about the current module.
140type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800141 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700142
Paul Duffinf88d8e02020-05-07 20:21:34 +0100143 blueprintBaseModuleContext() blueprint.BaseModuleContext
144
Colin Cross9f35c3d2020-09-16 19:04:41 -0700145 // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
146 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700147 OtherModuleName(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700148
149 // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
150 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700151 OtherModuleDir(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700152
153 // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
154 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700155 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -0700156
157 // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
158 // on the module. When called inside a Visit* method with current module being visited, and there are multiple
159 // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
Colin Crossdc35e212019-06-06 16:13:11 -0700160 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
Colin Cross9f35c3d2020-09-16 19:04:41 -0700161
162 // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
163 // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
Colin Crossdc35e212019-06-06 16:13:11 -0700164 OtherModuleExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700165
166 // OtherModuleDependencyVariantExists returns true if a module with the
167 // specified name and variant exists. The variant must match the given
168 // variations. It must also match all the non-local variations of the current
Martin Stjernholma4665622021-05-05 15:27:31 +0100169 // module. In other words, it checks for the module that AddVariationDependencies
Colin Cross9f35c3d2020-09-16 19:04:41 -0700170 // would add a dependency on with the same arguments.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000171 OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700172
Martin Stjernholma4665622021-05-05 15:27:31 +0100173 // OtherModuleFarDependencyVariantExists returns true if a module with the
174 // specified name and variant exists. The variant must match the given
175 // variations, but not the non-local variations of the current module. In
176 // other words, it checks for the module that AddFarVariationDependencies
177 // would add a dependency on with the same arguments.
178 OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool
179
Colin Cross9f35c3d2020-09-16 19:04:41 -0700180 // OtherModuleReverseDependencyVariantExists returns true if a module with the
181 // specified name exists with the same variations as the current module. In
Martin Stjernholma4665622021-05-05 15:27:31 +0100182 // other words, it checks for the module that AddReverseDependency would add a
Colin Cross9f35c3d2020-09-16 19:04:41 -0700183 // dependency on with the same argument.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000184 OtherModuleReverseDependencyVariantExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700185
186 // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
187 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Jiyong Park9e6c2422019-08-09 20:39:45 +0900188 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700189
Colin Crossd27e7b82020-07-02 11:38:17 -0700190 // OtherModuleProvider returns the value for a provider for the given module. If the value is
191 // not set it returns the zero value of the type of the provider, so the return value can always
192 // be type asserted to the type of the provider. The value returned may be a deep copy of the
193 // value originally passed to SetProvider.
194 OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
195
196 // OtherModuleHasProvider returns true if the provider for the given module has been set.
197 OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
198
199 // Provider returns the value for a provider for the current module. If the value is
200 // not set it returns the zero value of the type of the provider, so the return value can always
201 // be type asserted to the type of the provider. It panics if called before the appropriate
202 // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
203 // copy of the value originally passed to SetProvider.
204 Provider(provider blueprint.ProviderKey) interface{}
205
206 // HasProvider returns true if the provider for the current module has been set.
207 HasProvider(provider blueprint.ProviderKey) bool
208
209 // SetProvider sets the value for a provider for the current module. It panics if not called
210 // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
211 // is not of the appropriate type, or if the value has already been set. The value should not
212 // be modified after being passed to SetProvider.
213 SetProvider(provider blueprint.ProviderKey, value interface{})
214
Colin Crossdc35e212019-06-06 16:13:11 -0700215 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700216
217 // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
218 // none exists. It panics if the dependency does not have the specified tag. It skips any
219 // dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700220 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700221
222 // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
223 // name, or nil if none exists. If there are multiple dependencies on the same module it returns
Liz Kammer2b50ce62021-04-26 15:47:28 -0400224 // the first DependencyTag.
Colin Crossdc35e212019-06-06 16:13:11 -0700225 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
226
Colin Cross9f35c3d2020-09-16 19:04:41 -0700227 // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
228 // direct dependencies on the same module visit will be called multiple times on that module
229 // and OtherModuleDependencyTag will return a different tag for each.
230 //
231 // The Module passed to the visit function should not be retained outside of the visit
232 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700233 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700234
235 // VisitDirectDeps calls visit for each direct dependency. If there are multiple
236 // direct dependencies on the same module visit will be called multiple times on that module
237 // and OtherModuleDependencyTag will return a different tag for each. It skips any
238 // dependencies that are not an android.Module.
239 //
240 // The Module passed to the visit function should not be retained outside of the visit
241 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700242 VisitDirectDeps(visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700243
Colin Crossdc35e212019-06-06 16:13:11 -0700244 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700245
246 // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
247 // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
248 // OtherModuleDependencyTag will return a different tag for each. It skips any
249 // dependencies that are not an android.Module.
250 //
251 // The Module passed to the visit function should not be retained outside of the visit function, it may be
252 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700253 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
254 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
255 VisitDepsDepthFirst(visit func(Module))
256 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
257 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700258
259 // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
260 // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
261 // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
262 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
263 // any dependencies that are not an android.Module.
264 //
265 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
266 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700267 WalkDeps(visit func(Module, Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700268
269 // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
270 // tree in top down order. visit may be called multiple times for the same (child, parent)
271 // pair if there are multiple direct dependencies between the child and parent with different
272 // tags. OtherModuleDependencyTag will return the tag for the currently visited
273 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
274 // to child.
275 //
276 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
277 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700278 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700279
Colin Crossdc35e212019-06-06 16:13:11 -0700280 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
281 // and returns a top-down dependency path from a start module to current child module.
282 GetWalkPath() []Module
283
Colin Cross4dfacf92020-09-16 19:22:27 -0700284 // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
285 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
286 // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
287 // only done once for all variants of a module.
288 PrimaryModule() Module
289
290 // FinalModule returns the last variant of the current module. Variants of a module are always visited in
291 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
292 // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
293 // singleton actions that are only done once for all variants of a module.
294 FinalModule() Module
295
296 // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
297 // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
298 // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
299 // data modified by the current mutator.
300 VisitAllModuleVariants(visit func(Module))
301
Paul Duffinc5192442020-03-31 11:31:36 +0100302 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
303 // and returns a top-down dependency tags path from a start module to current child module.
304 // It has one less entry than GetWalkPath() as it contains the dependency tags that
305 // exist between each adjacent pair of modules in the GetWalkPath().
306 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
307 GetTagPath() []blueprint.DependencyTag
308
Jiyong Park1c7e9622020-05-07 16:12:13 +0900309 // GetPathString is supposed to be called in visit function passed in WalkDeps()
310 // and returns a multi-line string showing the modules and dependency tags
311 // among them along the top-down dependency path from a start module to current child module.
312 // skipFirst when set to true, the output doesn't include the start module,
313 // which is already printed when this function is used along with ModuleErrorf().
314 GetPathString(skipFirst bool) string
315
Colin Crossdc35e212019-06-06 16:13:11 -0700316 AddMissingDependencies(missingDeps []string)
317
Colin Crossa1ad8d12016-06-01 17:09:44 -0700318 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700319 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000320
321 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
322 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700323 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700324 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700325 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700326 Host() bool
327 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700328 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800329 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700330 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700331 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700332 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700333}
334
Colin Cross1184b642019-12-30 18:43:07 -0800335// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700336type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800337 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800338}
339
Colin Cross635c3b02016-05-18 15:37:25 -0700340type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800341 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800342
Colin Crossc20dc852020-11-10 12:27:45 -0800343 blueprintModuleContext() blueprint.ModuleContext
344
Colin Crossae887032017-10-23 17:16:14 -0700345 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800346 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700347
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700348 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800349 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800350 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700351
Colin Cross41589502020-12-01 14:00:21 -0800352 // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
353 // with the given additional dependencies. The file is marked executable after copying.
354 //
355 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
356 // installed file will be returned by PackagingSpecs() on this module or by
357 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
358 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700359 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800360
361 // InstallFile creates a rule to copy srcPath to name in the installPath directory,
362 // with the given additional dependencies.
363 //
364 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
365 // installed file will be returned by PackagingSpecs() on this module or by
366 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
367 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700368 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800369
370 // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
371 // directory.
372 //
373 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
374 // installed file will be returned by PackagingSpecs() on this module or by
375 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
376 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700377 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800378
379 // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
380 // in the installPath directory.
381 //
382 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
383 // installed file will be returned by PackagingSpecs() on this module or by
384 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
385 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700386 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800387
388 // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
389 // the rule to copy the file. This is useful to define how a module would be packaged
390 // without installing it into the global installation directories.
391 //
392 // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by
393 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
394 // for which IsInstallDepNeeded returns true.
395 PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
396
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700397 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800398
Colin Cross8d8f8e22016-08-03 11:57:50 -0700399 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700400 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700401 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800402 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700403 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900404 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900405 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700406 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700407 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900408 InstallForceOS() (*OsType, *ArchType)
Nan Zhang6d34b302017-02-04 17:47:46 -0800409
410 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700411 HostRequiredModuleNames() []string
412 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700413
Colin Cross3f68a132017-10-23 17:10:29 -0700414 ModuleSubDir() string
415
Colin Cross0875c522017-11-28 17:34:01 -0800416 Variable(pctx PackageContext, name, value string)
417 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700418 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
419 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800420 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700421 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
422 // phony rules or real files. Phony can be called on the same name multiple times to add
423 // additional dependencies.
424 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700425
Colin Cross9f35c3d2020-09-16 19:04:41 -0700426 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
427 // but do not exist.
Colin Cross3f68a132017-10-23 17:10:29 -0700428 GetMissingDependencies() []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800429}
430
Colin Cross635c3b02016-05-18 15:37:25 -0700431type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800432 blueprint.Module
433
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700434 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
435 // but GenerateAndroidBuildActions also has access to Android-specific information.
436 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700437 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700438
Paul Duffin44f1d842020-06-26 20:17:02 +0100439 // Add dependencies to the components of a module, i.e. modules that are created
440 // by the module and which are considered to be part of the creating module.
441 //
442 // This is called before prebuilts are renamed so as to allow a dependency to be
443 // added directly to a prebuilt child module instead of depending on a source module
444 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
445 //
446 // A dependency on a prebuilt must include the "prebuilt_" prefix.
447 ComponentDepsMutator(ctx BottomUpMutatorContext)
448
Colin Cross1e676be2016-10-12 14:38:15 -0700449 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800450
Colin Cross635c3b02016-05-18 15:37:25 -0700451 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900452 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800453 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700454 Target() Target
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000455 MultiTargets() []Target
Paul Duffin3e7d3ca2021-09-09 16:37:49 +0100456
457 // ImageVariation returns the image variation of this module.
458 //
459 // The returned structure has its Mutator field set to "image" and its Variation field set to the
460 // image variation, e.g. recovery, ramdisk, etc.. The Variation field is "" for host modules and
461 // device modules that have no image variation.
462 ImageVariation() blueprint.Variation
463
Anton Hansson1ee62c02020-06-30 11:51:53 +0100464 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -0800465 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700466 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700467 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800468 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700469 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900470 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900471 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700472 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700473 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900474 InstallForceOS() (*OsType, *ArchType)
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800475 HideFromMake()
476 IsHideFromMake() bool
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +0000477 IsSkipInstall() bool
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100478 MakeUninstallable()
Liz Kammer5ca3a622020-08-05 15:40:41 -0700479 ReplacedByPrebuilt()
480 IsReplacedByPrebuilt() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900481 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900482 InitRc() Paths
483 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800484 NoticeFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700485
486 AddProperties(props ...interface{})
487 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700488
Colin Crossae887032017-10-23 17:16:14 -0700489 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800490 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800491 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100492
Colin Cross9a362232019-07-01 15:32:45 -0700493 // String returns a string that includes the module name and variants for printing during debugging.
494 String() string
495
Paul Duffine2453c72019-05-31 14:00:04 +0100496 // Get the qualified module id for this module.
497 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
498
499 // Get information about the properties that can contain visibility rules.
500 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100501
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900502 RequiredModuleNames() []string
503 HostRequiredModuleNames() []string
504 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800505
Jiyong Park4dc2a1a2020-09-28 17:46:22 +0900506 FilesToInstall() InstallPaths
Jiyong Park073ea552020-11-09 14:08:34 +0900507 PackagingSpecs() []PackagingSpec
Colin Crossffe6b9d2020-12-01 15:40:06 -0800508
509 // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
510 // dependencies with dependency tags for which IsInstallDepNeeded() returns true.
511 TransitivePackagingSpecs() []PackagingSpec
Paul Duffine2453c72019-05-31 14:00:04 +0100512}
513
Jingwen Chenab60f122021-01-24 21:21:45 -0500514// BazelTargetModule is a lightweight wrapper interface around Module for
515// bp2build conversion purposes.
516//
517// In bp2build's bootstrap.Main execution, Soong runs an alternate pipeline of
518// mutators that creates BazelTargetModules from regular Module objects,
519// performing the mapping from Soong properties to Bazel rule attributes in the
520// process. This process may optionally create additional BazelTargetModules,
521// resulting in a 1:many mapping.
522//
523// bp2build.Codegen is then responsible for visiting all modules in the graph,
524// filtering for BazelTargetModules, and code-generating BUILD targets from
525// them.
Jingwen Chen73850672020-12-14 08:25:34 -0500526type BazelTargetModule interface {
527 Module
528
Liz Kammerfc46bc12021-02-19 11:06:17 -0500529 bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
530 SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties)
531
532 RuleClass() string
533 BzlLoadLocation() string
Jingwen Chen73850672020-12-14 08:25:34 -0500534}
535
Jingwen Chenab60f122021-01-24 21:21:45 -0500536// InitBazelTargetModule is a wrapper function that decorates BazelTargetModule
537// with property structs containing metadata for bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500538func InitBazelTargetModule(module BazelTargetModule) {
Liz Kammerfc46bc12021-02-19 11:06:17 -0500539 module.AddProperties(module.bazelTargetModuleProperties())
Jingwen Chen73850672020-12-14 08:25:34 -0500540 InitAndroidModule(module)
541}
542
Jingwen Chenab60f122021-01-24 21:21:45 -0500543// BazelTargetModuleBase contains the property structs with metadata for
544// bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500545type BazelTargetModuleBase struct {
546 ModuleBase
547 Properties bazel.BazelTargetModuleProperties
548}
549
Liz Kammerfc46bc12021-02-19 11:06:17 -0500550// bazelTargetModuleProperties getter.
551func (btmb *BazelTargetModuleBase) bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
Jingwen Chen73850672020-12-14 08:25:34 -0500552 return &btmb.Properties
553}
554
Liz Kammerfc46bc12021-02-19 11:06:17 -0500555// SetBazelTargetModuleProperties setter for BazelTargetModuleProperties
556func (btmb *BazelTargetModuleBase) SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) {
557 btmb.Properties = props
558}
559
560// RuleClass returns the rule class for this Bazel target
561func (b *BazelTargetModuleBase) RuleClass() string {
562 return b.bazelTargetModuleProperties().Rule_class
563}
564
565// BzlLoadLocation returns the rule class for this Bazel target
566func (b *BazelTargetModuleBase) BzlLoadLocation() string {
567 return b.bazelTargetModuleProperties().Bzl_load_location
568}
569
Paul Duffine2453c72019-05-31 14:00:04 +0100570// Qualified id for a module
571type qualifiedModuleName struct {
572 // The package (i.e. directory) in which the module is defined, without trailing /
573 pkg string
574
575 // The name of the module, empty string if package.
576 name string
577}
578
579func (q qualifiedModuleName) String() string {
580 if q.name == "" {
581 return "//" + q.pkg
582 }
583 return "//" + q.pkg + ":" + q.name
584}
585
Paul Duffine484f472019-06-20 16:38:08 +0100586func (q qualifiedModuleName) isRootPackage() bool {
587 return q.pkg == "" && q.name == ""
588}
589
Paul Duffine2453c72019-05-31 14:00:04 +0100590// Get the id for the package containing this module.
591func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
592 pkg := q.pkg
593 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100594 if pkg == "" {
595 panic(fmt.Errorf("Cannot get containing package id of root package"))
596 }
597
598 index := strings.LastIndex(pkg, "/")
599 if index == -1 {
600 pkg = ""
601 } else {
602 pkg = pkg[:index]
603 }
Paul Duffine2453c72019-05-31 14:00:04 +0100604 }
605 return newPackageId(pkg)
606}
607
608func newPackageId(pkg string) qualifiedModuleName {
609 // A qualified id for a package module has no name.
610 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800611}
612
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000613type Dist struct {
614 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
615 // command line and any of these targets are also on the command line, or otherwise
616 // built
617 Targets []string `android:"arch_variant"`
618
619 // The name of the output artifact. This defaults to the basename of the output of
620 // the module.
621 Dest *string `android:"arch_variant"`
622
623 // The directory within the dist directory to store the artifact. Defaults to the
624 // top level directory ("").
625 Dir *string `android:"arch_variant"`
626
627 // A suffix to add to the artifact file name (before any extension).
628 Suffix *string `android:"arch_variant"`
629
Paul Duffin74f05592020-11-25 16:37:46 +0000630 // A string tag to select the OutputFiles associated with the tag.
631 //
632 // If no tag is specified then it will select the default dist paths provided
633 // by the module type. If a tag of "" is specified then it will return the
634 // default output files provided by the modules, i.e. the result of calling
635 // OutputFiles("").
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000636 Tag *string `android:"arch_variant"`
637}
638
Colin Crossfc754582016-05-17 16:34:16 -0700639type nameProperties struct {
640 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800641 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700642}
643
Colin Cross08d6f8f2020-11-19 02:33:19 +0000644type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800645 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000646 //
647 // Disabling a module should only be done for those modules that cannot be built
648 // in the current environment. Modules that can build in the current environment
649 // but are not usually required (e.g. superceded by a prebuilt) should not be
650 // disabled as that will prevent them from being built by the checkbuild target
651 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800652 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800653
Paul Duffin2e61fa62019-03-28 14:10:57 +0000654 // Controls the visibility of this module to other modules. Allowable values are one or more of
655 // these formats:
656 //
657 // ["//visibility:public"]: Anyone can use this module.
658 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
659 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100660 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
661 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000662 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
663 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
664 // this module. Note that sub-packages do not have access to the rule; for example,
665 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
666 // is a special module and must be used verbatim. It represents all of the modules in the
667 // package.
668 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
669 // or other or in one of their sub-packages have access to this module. For example,
670 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
671 // to depend on this rule (but not //independent:evil)
672 // ["//project"]: This is shorthand for ["//project:__pkg__"]
673 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
674 // //project is the module's package. e.g. using [":__subpackages__"] in
675 // packages/apps/Settings/Android.bp is equivalent to
676 // //packages/apps/Settings:__subpackages__.
677 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
678 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100679 //
680 // If a module does not specify the `visibility` property then it uses the
681 // `default_visibility` property of the `package` module in the module's package.
682 //
683 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100684 // it will use the `default_visibility` of its closest ancestor package for which
685 // a `default_visibility` property is specified.
686 //
687 // If no `default_visibility` property can be found then the module uses the
688 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100689 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100690 // The `visibility` property has no effect on a defaults module although it does
691 // apply to any non-defaults module that uses it. To set the visibility of a
692 // defaults module, use the `defaults_visibility` property on the defaults module;
693 // not to be confused with the `default_visibility` property on the package module.
694 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000695 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
696 // more details.
697 Visibility []string
698
Bob Badour37af0462021-01-07 03:34:31 +0000699 // Describes the licenses applicable to this module. Must reference license modules.
700 Licenses []string
701
702 // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more.
703 Effective_licenses []string `blueprint:"mutated"`
704 // Override of module name when reporting licenses
705 Effective_package_name *string `blueprint:"mutated"`
706 // Notice files
Paul Duffinec0836a2021-05-10 22:53:30 +0100707 Effective_license_text Paths `blueprint:"mutated"`
Bob Badour37af0462021-01-07 03:34:31 +0000708 // License names
709 Effective_license_kinds []string `blueprint:"mutated"`
710 // License conditions
711 Effective_license_conditions []string `blueprint:"mutated"`
712
Colin Cross7d5136f2015-05-11 13:39:40 -0700713 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800714 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
715 // 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 +0000716 // platform).
Colin Cross7d716ba2017-11-01 10:38:29 -0700717 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700718
719 Target struct {
720 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700721 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700722 }
723 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700724 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700725 }
726 }
727
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000728 // If set to true then the archMutator will create variants for each arch specific target
729 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
730 // create a variant for the architecture and will list the additional arch specific targets
731 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700732 UseTargetVariants bool `blueprint:"mutated"`
733 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800734
Dan Willemsen782a2d12015-12-21 14:55:28 -0800735 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700736 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800737
Colin Cross55708f32017-03-20 13:23:34 -0700738 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700739 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700740
Jiyong Park2db76922017-11-08 16:03:48 +0900741 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
742 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
743 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700744 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700745
Jiyong Park2db76922017-11-08 16:03:48 +0900746 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
747 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
748 Soc_specific *bool
749
750 // whether this module is specific to a device, not only for SoC, but also for off-chip
751 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
752 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
753 // This implies `soc_specific:true`.
754 Device_specific *bool
755
756 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900757 // network operator, etc). When set to true, it is installed into /product (or
758 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900759 Product_specific *bool
760
Justin Yund5f6c822019-06-25 16:47:17 +0900761 // whether this module extends system. When set to true, it is installed into /system_ext
762 // (or /system/system_ext if system_ext partition does not exist).
763 System_ext_specific *bool
764
Jiyong Parkf9332f12018-02-01 00:54:12 +0900765 // Whether this module is installed to recovery partition
766 Recovery *bool
767
Yifan Hong1b3348d2020-01-21 15:53:22 -0800768 // Whether this module is installed to ramdisk
769 Ramdisk *bool
770
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700771 // Whether this module is installed to vendor ramdisk
772 Vendor_ramdisk *bool
773
Inseob Kim08758f02021-04-08 21:13:22 +0900774 // Whether this module is installed to debug ramdisk
775 Debug_ramdisk *bool
776
Jaewoong Jung8e93aba2021-03-02 16:58:08 -0800777 // Whether this module is built for non-native architectures (also known as native bridge binary)
dimitry1f33e402019-03-26 12:39:31 +0100778 Native_bridge_supported *bool `android:"arch_variant"`
779
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700780 // init.rc files to be installed if this module is installed
Colin Cross0bab8772020-09-25 14:01:21 -0700781 Init_rc []string `android:"arch_variant,path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700782
Steven Moreland57a23d22018-04-04 15:42:19 -0700783 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800784 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700785
Chris Wolfe998306e2016-08-15 14:47:23 -0400786 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700787 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400788
Sasha Smundakb6d23052019-04-01 18:37:36 -0700789 // names of other modules to install on host if this module is installed
790 Host_required []string `android:"arch_variant"`
791
792 // names of other modules to install on target if this module is installed
793 Target_required []string `android:"arch_variant"`
794
Colin Cross5aac3622017-08-31 15:07:09 -0700795 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800796 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700797
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000798 // The OsType of artifacts that this module variant is responsible for creating.
799 //
800 // Set by osMutator
801 CompileOS OsType `blueprint:"mutated"`
802
803 // The Target of artifacts that this module variant is responsible for creating.
804 //
805 // Set by archMutator
806 CompileTarget Target `blueprint:"mutated"`
807
808 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
809 // responsible for creating.
810 //
811 // By default this is nil as, where necessary, separate variants are created for the
812 // different multilib types supported and that information is encapsulated in the
813 // CompileTarget so the module variant simply needs to create artifacts for that.
814 //
815 // However, if UseTargetVariants is set to false (e.g. by
816 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
817 // multilib targets. Instead a single variant is created for the architecture and
818 // this contains the multilib specific targets that this variant should create.
819 //
820 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700821 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000822
823 // True if the module variant's CompileTarget is the primary target
824 //
825 // Set by archMutator
826 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800827
828 // Set by InitAndroidModule
829 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700830 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700831
Paul Duffin1356d8c2020-02-25 19:26:33 +0000832 // If set to true then a CommonOS variant will be created which will have dependencies
833 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
834 // that covers all os and architecture variants.
835 //
836 // The OsType specific variants can be retrieved by calling
837 // GetOsSpecificVariantsOfCommonOSVariant
838 //
839 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
840 CreateCommonOSVariant bool `blueprint:"mutated"`
841
842 // If set to true then this variant is the CommonOS variant that has dependencies on its
843 // OsType specific variants.
844 //
845 // Set by osMutator.
846 CommonOSVariant bool `blueprint:"mutated"`
847
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800848 // When HideFromMake is set to true, no entry for this variant will be emitted in the
849 // generated Android.mk file.
850 HideFromMake bool `blueprint:"mutated"`
851
852 // When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable,
853 // ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile
854 // and don't create a rule to install the file.
Colin Crossce75d2c2016-10-06 16:12:58 -0700855 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800856
Liz Kammer5ca3a622020-08-05 15:40:41 -0700857 // Whether the module has been replaced by a prebuilt
858 ReplacedByPrebuilt bool `blueprint:"mutated"`
859
Justin Yun32f053b2020-07-31 23:07:17 +0900860 // Disabled by mutators. If set to true, it overrides Enabled property.
861 ForcedDisabled bool `blueprint:"mutated"`
862
Jeff Gaston088e29e2017-11-29 16:47:17 -0800863 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700864
865 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700866
867 // Name and variant strings stored by mutators to enable Module.String()
868 DebugName string `blueprint:"mutated"`
869 DebugMutators []string `blueprint:"mutated"`
870 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800871
Colin Crossa6845402020-11-16 15:08:19 -0800872 // ImageVariation is set by ImageMutator to specify which image this variation is for,
873 // for example "" for core or "recovery" for recovery. It will often be set to one of the
874 // constants in image.go, but can also be set to a custom value by individual module types.
Colin Cross7228ecd2019-11-18 16:00:16 -0800875 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800876}
877
Paul Duffined875132020-09-02 13:08:57 +0100878type distProperties struct {
879 // configuration to distribute output files from this module to the distribution
880 // directory (default: $OUT/dist, configurable with $DIST_DIR)
881 Dist Dist `android:"arch_variant"`
882
883 // a list of configurations to distribute output files from this module to the
884 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
885 Dists []Dist `android:"arch_variant"`
886}
887
Paul Duffin74f05592020-11-25 16:37:46 +0000888// The key to use in TaggedDistFiles when a Dist structure does not specify a
889// tag property. This intentionally does not use "" as the default because that
890// would mean that an empty tag would have a different meaning when used in a dist
891// structure that when used to reference a specific set of output paths using the
892// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
893const DefaultDistTag = "<default-dist-tag>"
894
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000895// A map of OutputFile tag keys to Paths, for disting purposes.
896type TaggedDistFiles map[string]Paths
897
Paul Duffin74f05592020-11-25 16:37:46 +0000898// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
899// then it will create a map, update it and then return it. If a mapping already
900// exists for the tag then the paths are appended to the end of the current list
901// of paths, ignoring any duplicates.
902func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
903 if t == nil {
904 t = make(TaggedDistFiles)
905 }
906
907 for _, distFile := range paths {
908 if distFile != nil && !t[tag].containsPath(distFile) {
909 t[tag] = append(t[tag], distFile)
910 }
911 }
912
913 return t
914}
915
916// merge merges the entries from the other TaggedDistFiles object into this one.
917// If the TaggedDistFiles is nil then it will create a new instance, merge the
918// other into it, and then return it.
919func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
920 for tag, paths := range other {
921 t = t.addPathsForTag(tag, paths...)
922 }
923
924 return t
925}
926
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000927func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000928 for _, path := range paths {
929 if path == nil {
930 panic("The path to a dist file cannot be nil.")
931 }
932 }
933
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000934 // The default OutputFile tag is the empty "" string.
Paul Duffin74f05592020-11-25 16:37:46 +0000935 return TaggedDistFiles{DefaultDistTag: paths}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000936}
937
Colin Cross3f40fa42015-01-30 17:27:36 -0800938type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800939 // If set to true, build a variant of the module for the host. Defaults to false.
940 Host_supported *bool
941
942 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700943 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800944}
945
Colin Crossc472d572015-03-17 15:06:21 -0700946type Multilib string
947
948const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800949 MultilibBoth Multilib = "both"
950 MultilibFirst Multilib = "first"
951 MultilibCommon Multilib = "common"
952 MultilibCommonFirst Multilib = "common_first"
953 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700954)
955
Colin Crossa1ad8d12016-06-01 17:09:44 -0700956type HostOrDeviceSupported int
957
958const (
Colin Cross34037c62020-11-17 13:19:17 -0800959 hostSupported = 1 << iota
960 hostCrossSupported
961 deviceSupported
962 hostDefault
963 deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700964
965 // Host and HostCross are built by default. Device is not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800966 HostSupported = hostSupported | hostCrossSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700967
968 // Host is built by default. HostCross and Device are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800969 HostSupportedNoCross = hostSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700970
971 // Device is built by default. Host and HostCross are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800972 DeviceSupported = deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700973
974 // Device is built by default. Host and HostCross are supported.
Colin Cross34037c62020-11-17 13:19:17 -0800975 HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700976
977 // Host, HostCross, and Device are built by default.
Colin Cross34037c62020-11-17 13:19:17 -0800978 HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
979 deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700980
981 // Nothing is supported. This is not exposed to the user, but used to mark a
982 // host only module as unsupported when the module type is not supported on
983 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Colin Cross34037c62020-11-17 13:19:17 -0800984 NeitherHostNorDeviceSupported = 0
Colin Crossa1ad8d12016-06-01 17:09:44 -0700985)
986
Jiyong Park2db76922017-11-08 16:03:48 +0900987type moduleKind int
988
989const (
990 platformModule moduleKind = iota
991 deviceSpecificModule
992 socSpecificModule
993 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900994 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900995)
996
997func (k moduleKind) String() string {
998 switch k {
999 case platformModule:
1000 return "platform"
1001 case deviceSpecificModule:
1002 return "device-specific"
1003 case socSpecificModule:
1004 return "soc-specific"
1005 case productSpecificModule:
1006 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +09001007 case systemExtSpecificModule:
1008 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +09001009 default:
1010 panic(fmt.Errorf("unknown module kind %d", k))
1011 }
1012}
1013
Colin Cross9d34f352019-11-22 16:03:51 -08001014func initAndroidModuleBase(m Module) {
1015 m.base().module = m
1016}
1017
Colin Crossa6845402020-11-16 15:08:19 -08001018// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
1019// It adds the common properties, for example "name" and "enabled".
Colin Cross36242852017-06-23 15:06:31 -07001020func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -08001021 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001022 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -07001023
Colin Cross36242852017-06-23 15:06:31 -07001024 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -07001025 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +01001026 &base.commonProperties,
1027 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -07001028
Colin Crosseabaedd2020-02-06 17:01:55 -08001029 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -07001030
Colin Crossa3a97412019-03-18 12:24:29 -07001031 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -07001032 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +01001033
1034 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +01001035 // its checking and parsing phases so make it the primary visibility property.
1036 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Bob Badour37af0462021-01-07 03:34:31 +00001037
1038 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
1039 // its checking and parsing phases so make it the primary licenses property.
1040 setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses)
Colin Cross5049f022015-03-18 13:28:46 -07001041}
1042
Colin Crossa6845402020-11-16 15:08:19 -08001043// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
1044// It adds the common properties, for example "name" and "enabled", as well as runtime generated
1045// property structs for architecture-specific versions of generic properties tagged with
1046// `android:"arch_variant"`.
1047//
1048// InitAndroidModule should not be called if InitAndroidArchModule was called.
Colin Cross36242852017-06-23 15:06:31 -07001049func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1050 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -07001051
1052 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -08001053 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -07001054 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -07001055 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -07001056 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001057
Colin Cross34037c62020-11-17 13:19:17 -08001058 if hod&hostSupported != 0 && hod&deviceSupported != 0 {
Colin Cross36242852017-06-23 15:06:31 -07001059 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -08001060 }
1061
Colin Crossa6845402020-11-16 15:08:19 -08001062 initArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001063}
1064
Colin Crossa6845402020-11-16 15:08:19 -08001065// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1066// architecture-specific, but will only have a single variant per OS that handles all the
1067// architectures simultaneously. The list of Targets that it must handle will be available from
1068// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
1069// well as runtime generated property structs for architecture-specific versions of generic
1070// properties tagged with `android:"arch_variant"`.
1071//
1072// InitAndroidModule or InitAndroidArchModule should not be called if
1073// InitAndroidMultiTargetsArchModule was called.
Colin Crossee0bc3b2018-10-02 22:01:37 -07001074func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1075 InitAndroidArchModule(m, hod, defaultMultilib)
1076 m.base().commonProperties.UseTargetVariants = false
1077}
1078
Colin Crossa6845402020-11-16 15:08:19 -08001079// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1080// architecture-specific, but will only have a single variant per OS that handles all the
1081// architectures simultaneously, and will also have an additional CommonOS variant that has
1082// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
1083// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
1084// "enabled", as well as runtime generated property structs for architecture-specific versions of
1085// generic properties tagged with `android:"arch_variant"`.
1086//
1087// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
1088// called if InitCommonOSAndroidMultiTargetsArchModule was called.
Paul Duffin1356d8c2020-02-25 19:26:33 +00001089func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1090 InitAndroidArchModule(m, hod, defaultMultilib)
1091 m.base().commonProperties.UseTargetVariants = false
1092 m.base().commonProperties.CreateCommonOSVariant = true
1093}
1094
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001095// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -08001096// modules. It should be included as an anonymous field in every module
1097// struct definition. InitAndroidModule should then be called from the module's
1098// factory function, and the return values from InitAndroidModule should be
1099// returned from the factory function.
1100//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001101// The ModuleBase type is responsible for implementing the GenerateBuildActions
1102// method to support the blueprint.Module interface. This method will then call
1103// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -07001104// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
1105// rather than the usual blueprint.ModuleContext.
1106// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -08001107// system including details about the particular build variant that is to be
1108// generated.
1109//
1110// For example:
1111//
1112// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001113// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -08001114// )
1115//
1116// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001117// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -08001118// properties struct {
1119// MyProperty string
1120// }
1121// }
1122//
Colin Cross36242852017-06-23 15:06:31 -07001123// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001124// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -07001125// m.AddProperties(&m.properties)
1126// android.InitAndroidModule(m)
1127// return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001128// }
1129//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001130// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001131// // Get the CPU architecture for the current build variant.
1132// variantArch := ctx.Arch()
1133//
1134// // ...
1135// }
Colin Cross635c3b02016-05-18 15:37:25 -07001136type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -08001137 // Putting the curiously recurring thing pointing to the thing that contains
1138 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -07001139 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -07001140 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -08001141
Colin Crossfc754582016-05-17 16:34:16 -07001142 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -08001143 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +01001144 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -07001145 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001146 hostAndDeviceProperties hostAndDeviceProperties
1147 generalProperties []interface{}
Jingwen Chen5d864492021-02-24 07:20:12 -05001148
1149 // Arch specific versions of structs in generalProperties. The outer index
1150 // has the same order as generalProperties as initialized in
1151 // InitAndroidArchModule, and the inner index chooses the props specific to
1152 // the architecture. The interface{} value is an archPropRoot that is
1153 // filled with arch specific values by the arch mutator.
1154 archProperties [][]interface{}
1155
1156 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001157
Jingwen Chen73850672020-12-14 08:25:34 -05001158 // Properties specific to the Blueprint to BUILD migration.
1159 bazelTargetModuleProperties bazel.BazelTargetModuleProperties
1160
Paul Duffin63c6e182019-07-24 14:24:38 +01001161 // Information about all the properties on the module that contains visibility rules that need
1162 // checking.
1163 visibilityPropertyInfo []visibilityProperty
1164
1165 // The primary visibility property, may be nil, that controls access to the module.
1166 primaryVisibilityProperty visibilityProperty
1167
Bob Badour37af0462021-01-07 03:34:31 +00001168 // The primary licenses property, may be nil, records license metadata for the module.
1169 primaryLicensesProperty applicableLicensesProperty
1170
Colin Crossffe6b9d2020-12-01 15:40:06 -08001171 noAddressSanitizer bool
1172 installFiles InstallPaths
1173 installFilesDepSet *installPathsDepSet
1174 checkbuildFiles Paths
1175 packagingSpecs []PackagingSpec
1176 packagingSpecsDepSet *packagingSpecsDepSet
1177 noticeFiles Paths
1178 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001179
Paul Duffinaf970a22020-11-23 23:32:56 +00001180 // The files to copy to the dist as explicitly specified in the .bp file.
1181 distFiles TaggedDistFiles
1182
Colin Cross1f8c52b2015-06-16 16:38:17 -07001183 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
1184 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -08001185 installTarget WritablePath
1186 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -07001187 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -07001188
Colin Cross178a5092016-09-13 13:42:32 -07001189 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -07001190
1191 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -07001192
1193 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001194 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001195 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001196 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -07001197
Inseob Kim8471cda2019-11-15 09:59:12 +09001198 initRcPaths Paths
1199 vintfFragmentsPaths Paths
Colin Cross36242852017-06-23 15:06:31 -07001200}
1201
Paul Duffin44f1d842020-06-26 20:17:02 +01001202func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
1203
Colin Cross4157e882019-06-06 16:57:04 -07001204func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -08001205
Colin Cross4157e882019-06-06 16:57:04 -07001206func (m *ModuleBase) AddProperties(props ...interface{}) {
1207 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -07001208}
1209
Colin Cross4157e882019-06-06 16:57:04 -07001210func (m *ModuleBase) GetProperties() []interface{} {
1211 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -08001212}
1213
Colin Cross4157e882019-06-06 16:57:04 -07001214func (m *ModuleBase) BuildParamsForTests() []BuildParams {
1215 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -07001216}
1217
Colin Cross4157e882019-06-06 16:57:04 -07001218func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
1219 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001220}
1221
Colin Cross4157e882019-06-06 16:57:04 -07001222func (m *ModuleBase) VariablesForTests() map[string]string {
1223 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001224}
1225
Colin Crossce75d2c2016-10-06 16:12:58 -07001226// Name returns the name of the module. It may be overridden by individual module types, for
1227// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -07001228func (m *ModuleBase) Name() string {
1229 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -07001230}
1231
Colin Cross9a362232019-07-01 15:32:45 -07001232// String returns a string that includes the module name and variants for printing during debugging.
1233func (m *ModuleBase) String() string {
1234 sb := strings.Builder{}
1235 sb.WriteString(m.commonProperties.DebugName)
1236 sb.WriteString("{")
1237 for i := range m.commonProperties.DebugMutators {
1238 if i != 0 {
1239 sb.WriteString(",")
1240 }
1241 sb.WriteString(m.commonProperties.DebugMutators[i])
1242 sb.WriteString(":")
1243 sb.WriteString(m.commonProperties.DebugVariations[i])
1244 }
1245 sb.WriteString("}")
1246 return sb.String()
1247}
1248
Colin Crossce75d2c2016-10-06 16:12:58 -07001249// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001250func (m *ModuleBase) BaseModuleName() string {
1251 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001252}
1253
Colin Cross4157e882019-06-06 16:57:04 -07001254func (m *ModuleBase) base() *ModuleBase {
1255 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001256}
1257
Paul Duffine2453c72019-05-31 14:00:04 +01001258func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1259 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1260}
1261
1262func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001263 return m.visibilityPropertyInfo
1264}
1265
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001266func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001267 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001268 // Make a copy of the underlying Dists slice to protect against
1269 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001270 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1271 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001272 } else {
Paul Duffined875132020-09-02 13:08:57 +01001273 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001274 }
1275}
1276
1277func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
Paul Duffin74f05592020-11-25 16:37:46 +00001278 var distFiles TaggedDistFiles
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001279 for _, dist := range m.Dists() {
Paul Duffin74f05592020-11-25 16:37:46 +00001280 // If no tag is specified then it means to use the default dist paths so use
1281 // the special tag name which represents that.
1282 tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
1283
Paul Duffinaf970a22020-11-23 23:32:56 +00001284 if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
1285 // Call the OutputFiles(tag) method to get the paths associated with the tag.
1286 distFilesForTag, err := outputFileProducer.OutputFiles(tag)
Paul Duffin74f05592020-11-25 16:37:46 +00001287
Paul Duffinaf970a22020-11-23 23:32:56 +00001288 // If the tag was not supported and is not DefaultDistTag then it is an error.
1289 // Failing to find paths for DefaultDistTag is not an error. It just means
1290 // that the module type requires the legacy behavior.
1291 if err != nil && tag != DefaultDistTag {
1292 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1293 }
1294
1295 distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
1296 } else if tag != DefaultDistTag {
1297 // If the tag was specified then it is an error if the module does not
1298 // implement OutputFileProducer because there is no other way of accessing
1299 // the paths for the specified tag.
1300 ctx.PropertyErrorf("dist.tag",
1301 "tag %s not supported because the module does not implement OutputFileProducer", tag)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001302 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001303 }
1304
1305 return distFiles
1306}
1307
Colin Cross4157e882019-06-06 16:57:04 -07001308func (m *ModuleBase) Target() Target {
1309 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001310}
1311
Colin Cross4157e882019-06-06 16:57:04 -07001312func (m *ModuleBase) TargetPrimary() bool {
1313 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001314}
1315
Colin Cross4157e882019-06-06 16:57:04 -07001316func (m *ModuleBase) MultiTargets() []Target {
1317 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001318}
1319
Colin Cross4157e882019-06-06 16:57:04 -07001320func (m *ModuleBase) Os() OsType {
1321 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001322}
1323
Colin Cross4157e882019-06-06 16:57:04 -07001324func (m *ModuleBase) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09001325 return m.Os().Class == Host
Dan Willemsen97750522016-02-09 17:43:51 -08001326}
1327
Yo Chiangbba545e2020-06-09 16:15:37 +08001328func (m *ModuleBase) Device() bool {
1329 return m.Os().Class == Device
1330}
1331
Colin Cross4157e882019-06-06 16:57:04 -07001332func (m *ModuleBase) Arch() Arch {
1333 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001334}
1335
Colin Cross4157e882019-06-06 16:57:04 -07001336func (m *ModuleBase) ArchSpecific() bool {
1337 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001338}
1339
Paul Duffin1356d8c2020-02-25 19:26:33 +00001340// True if the current variant is a CommonOS variant, false otherwise.
1341func (m *ModuleBase) IsCommonOSVariant() bool {
1342 return m.commonProperties.CommonOSVariant
1343}
1344
Colin Cross34037c62020-11-17 13:19:17 -08001345// supportsTarget returns true if the given Target is supported by the current module.
1346func (m *ModuleBase) supportsTarget(target Target) bool {
1347 switch target.Os.Class {
1348 case Host:
1349 if target.HostCross {
1350 return m.HostCrossSupported()
1351 } else {
1352 return m.HostSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001353 }
Colin Cross34037c62020-11-17 13:19:17 -08001354 case Device:
1355 return m.DeviceSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001356 default:
Jiyong Park1613e552020-09-14 19:43:17 +09001357 return false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001358 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001359}
1360
Colin Cross34037c62020-11-17 13:19:17 -08001361// DeviceSupported returns true if the current module is supported and enabled for device targets,
1362// i.e. the factory method set the HostOrDeviceSupported value to include device support and
1363// the device support is enabled by default or enabled by the device_supported property.
Colin Cross4157e882019-06-06 16:57:04 -07001364func (m *ModuleBase) DeviceSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001365 hod := m.commonProperties.HostOrDeviceSupported
1366 // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
1367 // value has the deviceDefault bit set.
1368 deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
1369 return hod&deviceSupported != 0 && deviceEnabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001370}
1371
Colin Cross34037c62020-11-17 13:19:17 -08001372// HostSupported returns true if the current module is supported and enabled for host targets,
1373// i.e. the factory method set the HostOrDeviceSupported value to include host support and
1374// the host support is enabled by default or enabled by the host_supported property.
Paul Duffine44358f2019-11-26 18:04:12 +00001375func (m *ModuleBase) HostSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001376 hod := m.commonProperties.HostOrDeviceSupported
1377 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1378 // value has the hostDefault bit set.
1379 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1380 return hod&hostSupported != 0 && hostEnabled
1381}
1382
1383// HostCrossSupported returns true if the current module is supported and enabled for host cross
1384// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
1385// support and the host cross support is enabled by default or enabled by the
1386// host_supported property.
1387func (m *ModuleBase) HostCrossSupported() bool {
1388 hod := m.commonProperties.HostOrDeviceSupported
1389 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1390 // value has the hostDefault bit set.
1391 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1392 return hod&hostCrossSupported != 0 && hostEnabled
Paul Duffine44358f2019-11-26 18:04:12 +00001393}
1394
Colin Cross4157e882019-06-06 16:57:04 -07001395func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001396 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001397}
1398
Colin Cross4157e882019-06-06 16:57:04 -07001399func (m *ModuleBase) DeviceSpecific() bool {
1400 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001401}
1402
Colin Cross4157e882019-06-06 16:57:04 -07001403func (m *ModuleBase) SocSpecific() bool {
1404 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001405}
1406
Colin Cross4157e882019-06-06 16:57:04 -07001407func (m *ModuleBase) ProductSpecific() bool {
1408 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001409}
1410
Justin Yund5f6c822019-06-25 16:47:17 +09001411func (m *ModuleBase) SystemExtSpecific() bool {
1412 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001413}
1414
Colin Crossc2d24052020-05-13 11:05:02 -07001415// RequiresStableAPIs returns true if the module will be installed to a partition that may
1416// be updated separately from the system image.
1417func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1418 return m.SocSpecific() || m.DeviceSpecific() ||
1419 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1420}
1421
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001422func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1423 partition := "system"
1424 if m.SocSpecific() {
1425 // A SoC-specific module could be on the vendor partition at
1426 // "vendor" or the system partition at "system/vendor".
1427 if config.VendorPath() == "vendor" {
1428 partition = "vendor"
1429 }
1430 } else if m.DeviceSpecific() {
1431 // A device-specific module could be on the odm partition at
1432 // "odm", the vendor partition at "vendor/odm", or the system
1433 // partition at "system/vendor/odm".
1434 if config.OdmPath() == "odm" {
1435 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001436 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001437 partition = "vendor"
1438 }
1439 } else if m.ProductSpecific() {
1440 // A product-specific module could be on the product partition
1441 // at "product" or the system partition at "system/product".
1442 if config.ProductPath() == "product" {
1443 partition = "product"
1444 }
1445 } else if m.SystemExtSpecific() {
1446 // A system_ext-specific module could be on the system_ext
1447 // partition at "system_ext" or the system partition at
1448 // "system/system_ext".
1449 if config.SystemExtPath() == "system_ext" {
1450 partition = "system_ext"
1451 }
1452 }
1453 return partition
1454}
1455
Colin Cross4157e882019-06-06 16:57:04 -07001456func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001457 if m.commonProperties.ForcedDisabled {
1458 return false
1459 }
Colin Cross08d6f8f2020-11-19 02:33:19 +00001460 if m.commonProperties.Enabled == nil {
1461 return !m.Os().DefaultDisabled
1462 }
1463 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001464}
1465
Inseob Kimeec88e12020-01-22 11:11:29 +09001466func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001467 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001468}
1469
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001470// HideFromMake marks this variant so that it is not emitted in the generated Android.mk file.
1471func (m *ModuleBase) HideFromMake() {
1472 m.commonProperties.HideFromMake = true
1473}
1474
1475// IsHideFromMake returns true if HideFromMake was previously called.
1476func (m *ModuleBase) IsHideFromMake() bool {
1477 return m.commonProperties.HideFromMake == true
1478}
1479
1480// SkipInstall marks this variant to not create install rules when ctx.Install* are called.
Colin Cross4157e882019-06-06 16:57:04 -07001481func (m *ModuleBase) SkipInstall() {
1482 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001483}
1484
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +00001485// IsSkipInstall returns true if this variant is marked to not create install
1486// rules when ctx.Install* are called.
1487func (m *ModuleBase) IsSkipInstall() bool {
1488 return m.commonProperties.SkipInstall
1489}
1490
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001491// Similar to HideFromMake, but if the AndroidMk entry would set
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001492// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1493// rather than leaving it out altogether. That happens in cases where it would
1494// have other side effects, in particular when it adds a NOTICE file target,
1495// which other install targets might depend on.
1496func (m *ModuleBase) MakeUninstallable() {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001497 m.HideFromMake()
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001498}
1499
Liz Kammer5ca3a622020-08-05 15:40:41 -07001500func (m *ModuleBase) ReplacedByPrebuilt() {
1501 m.commonProperties.ReplacedByPrebuilt = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001502 m.HideFromMake()
Liz Kammer5ca3a622020-08-05 15:40:41 -07001503}
1504
1505func (m *ModuleBase) IsReplacedByPrebuilt() bool {
1506 return m.commonProperties.ReplacedByPrebuilt
1507}
1508
Colin Cross4157e882019-06-06 16:57:04 -07001509func (m *ModuleBase) ExportedToMake() bool {
1510 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001511}
1512
Colin Crosse9fe2942020-11-10 18:12:15 -08001513// computeInstallDeps finds the installed paths of all dependencies that have a dependency
1514// tag that is annotated as needing installation via the IsInstallDepNeeded method.
Colin Crossffe6b9d2020-12-01 15:40:06 -08001515func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) {
Colin Cross5d583952020-11-24 16:21:24 -08001516 var installDeps []*installPathsDepSet
Colin Crossffe6b9d2020-12-01 15:40:06 -08001517 var packagingSpecs []*packagingSpecsDepSet
Colin Cross5d583952020-11-24 16:21:24 -08001518 ctx.VisitDirectDeps(func(dep Module) {
Jooyung Han77f7c442021-05-12 03:53:32 +09001519 if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) && !dep.IsHideFromMake() {
Colin Cross5d583952020-11-24 16:21:24 -08001520 installDeps = append(installDeps, dep.base().installFilesDepSet)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001521 packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet)
Colin Cross897266e2020-02-13 13:22:08 -08001522 }
1523 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001524
Colin Crossffe6b9d2020-12-01 15:40:06 -08001525 return installDeps, packagingSpecs
Colin Cross3f40fa42015-01-30 17:27:36 -08001526}
1527
Jiyong Park4dc2a1a2020-09-28 17:46:22 +09001528func (m *ModuleBase) FilesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001529 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001530}
1531
Jiyong Park073ea552020-11-09 14:08:34 +09001532func (m *ModuleBase) PackagingSpecs() []PackagingSpec {
1533 return m.packagingSpecs
1534}
1535
Colin Crossffe6b9d2020-12-01 15:40:06 -08001536func (m *ModuleBase) TransitivePackagingSpecs() []PackagingSpec {
1537 return m.packagingSpecsDepSet.ToList()
1538}
1539
Colin Cross4157e882019-06-06 16:57:04 -07001540func (m *ModuleBase) NoAddressSanitizer() bool {
1541 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001542}
1543
Colin Cross4157e882019-06-06 16:57:04 -07001544func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001545 return false
1546}
1547
Jaewoong Jung0949f312019-09-11 10:25:18 -07001548func (m *ModuleBase) InstallInTestcases() bool {
1549 return false
1550}
1551
Colin Cross4157e882019-06-06 16:57:04 -07001552func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001553 return false
1554}
1555
Yifan Hong1b3348d2020-01-21 15:53:22 -08001556func (m *ModuleBase) InstallInRamdisk() bool {
1557 return Bool(m.commonProperties.Ramdisk)
1558}
1559
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001560func (m *ModuleBase) InstallInVendorRamdisk() bool {
1561 return Bool(m.commonProperties.Vendor_ramdisk)
1562}
1563
Inseob Kim08758f02021-04-08 21:13:22 +09001564func (m *ModuleBase) InstallInDebugRamdisk() bool {
1565 return Bool(m.commonProperties.Debug_ramdisk)
1566}
1567
Colin Cross4157e882019-06-06 16:57:04 -07001568func (m *ModuleBase) InstallInRecovery() bool {
1569 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001570}
1571
Colin Cross90ba5f42019-10-02 11:10:58 -07001572func (m *ModuleBase) InstallInRoot() bool {
1573 return false
1574}
1575
Colin Cross607d8582019-07-29 16:44:46 -07001576func (m *ModuleBase) InstallBypassMake() bool {
1577 return false
1578}
1579
Jiyong Park87788b52020-09-01 12:37:45 +09001580func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
1581 return nil, nil
Colin Cross6e359402020-02-10 15:29:54 -08001582}
1583
Colin Cross4157e882019-06-06 16:57:04 -07001584func (m *ModuleBase) Owner() string {
1585 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001586}
1587
Bob Badoura75b0572020-02-18 20:21:55 -08001588func (m *ModuleBase) NoticeFiles() Paths {
1589 return m.noticeFiles
Jiyong Park52818fc2019-03-18 12:01:38 +09001590}
1591
Colin Cross7228ecd2019-11-18 16:00:16 -08001592func (m *ModuleBase) setImageVariation(variant string) {
1593 m.commonProperties.ImageVariation = variant
1594}
1595
1596func (m *ModuleBase) ImageVariation() blueprint.Variation {
1597 return blueprint.Variation{
1598 Mutator: "image",
1599 Variation: m.base().commonProperties.ImageVariation,
1600 }
1601}
1602
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001603func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1604 for i, v := range m.commonProperties.DebugMutators {
1605 if v == mutator {
1606 return m.commonProperties.DebugVariations[i]
1607 }
1608 }
1609
1610 return ""
1611}
1612
Yifan Hong1b3348d2020-01-21 15:53:22 -08001613func (m *ModuleBase) InRamdisk() bool {
1614 return m.base().commonProperties.ImageVariation == RamdiskVariation
1615}
1616
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001617func (m *ModuleBase) InVendorRamdisk() bool {
1618 return m.base().commonProperties.ImageVariation == VendorRamdiskVariation
1619}
1620
Inseob Kim08758f02021-04-08 21:13:22 +09001621func (m *ModuleBase) InDebugRamdisk() bool {
1622 return m.base().commonProperties.ImageVariation == DebugRamdiskVariation
1623}
1624
Colin Cross7228ecd2019-11-18 16:00:16 -08001625func (m *ModuleBase) InRecovery() bool {
1626 return m.base().commonProperties.ImageVariation == RecoveryVariation
1627}
1628
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001629func (m *ModuleBase) RequiredModuleNames() []string {
1630 return m.base().commonProperties.Required
1631}
1632
1633func (m *ModuleBase) HostRequiredModuleNames() []string {
1634 return m.base().commonProperties.Host_required
1635}
1636
1637func (m *ModuleBase) TargetRequiredModuleNames() []string {
1638 return m.base().commonProperties.Target_required
1639}
1640
Inseob Kim8471cda2019-11-15 09:59:12 +09001641func (m *ModuleBase) InitRc() Paths {
1642 return append(Paths{}, m.initRcPaths...)
1643}
1644
1645func (m *ModuleBase) VintfFragments() Paths {
1646 return append(Paths{}, m.vintfFragmentsPaths...)
1647}
1648
Colin Cross4157e882019-06-06 16:57:04 -07001649func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001650 var allInstalledFiles InstallPaths
1651 var allCheckbuildFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001652 ctx.VisitAllModuleVariants(func(module Module) {
1653 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001654 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1655 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001656 })
1657
Colin Cross0875c522017-11-28 17:34:01 -08001658 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001659
Colin Cross133ebef2020-08-14 17:38:45 -07001660 namespacePrefix := ctx.Namespace().id
Jeff Gaston088e29e2017-11-29 16:47:17 -08001661 if namespacePrefix != "" {
1662 namespacePrefix = namespacePrefix + "-"
1663 }
1664
Colin Cross3f40fa42015-01-30 17:27:36 -08001665 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001666 name := namespacePrefix + ctx.ModuleName() + "-install"
1667 ctx.Phony(name, allInstalledFiles.Paths()...)
1668 m.installTarget = PathForPhony(ctx, name)
1669 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001670 }
1671
1672 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001673 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1674 ctx.Phony(name, allCheckbuildFiles...)
1675 m.checkbuildTarget = PathForPhony(ctx, name)
1676 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001677 }
1678
1679 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001680 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05001681 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001682 suffix = "-soong"
1683 }
1684
Colin Crossc3d87d32020-06-04 13:25:17 -07001685 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001686
Colin Cross4157e882019-06-06 16:57:04 -07001687 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001688 }
1689}
1690
Colin Crossc34d2322020-01-03 15:23:27 -08001691func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001692 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1693 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1694 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001695 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001696
Dario Frenifd05a742018-05-29 13:28:54 +01001697 msg := "conflicting value set here"
1698 if socSpecific && deviceSpecific {
1699 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001700 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001701 ctx.PropertyErrorf("vendor", msg)
1702 }
Colin Cross4157e882019-06-06 16:57:04 -07001703 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001704 ctx.PropertyErrorf("proprietary", msg)
1705 }
Colin Cross4157e882019-06-06 16:57:04 -07001706 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001707 ctx.PropertyErrorf("soc_specific", msg)
1708 }
1709 }
1710
Justin Yund5f6c822019-06-25 16:47:17 +09001711 if productSpecific && systemExtSpecific {
1712 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1713 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001714 }
1715
Justin Yund5f6c822019-06-25 16:47:17 +09001716 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001717 if productSpecific {
1718 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1719 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001720 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 +01001721 }
1722 if deviceSpecific {
1723 ctx.PropertyErrorf("device_specific", msg)
1724 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001725 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001726 ctx.PropertyErrorf("vendor", msg)
1727 }
Colin Cross4157e882019-06-06 16:57:04 -07001728 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001729 ctx.PropertyErrorf("proprietary", msg)
1730 }
Colin Cross4157e882019-06-06 16:57:04 -07001731 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001732 ctx.PropertyErrorf("soc_specific", msg)
1733 }
1734 }
1735 }
1736
Jiyong Park2db76922017-11-08 16:03:48 +09001737 if productSpecific {
1738 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001739 } else if systemExtSpecific {
1740 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001741 } else if deviceSpecific {
1742 return deviceSpecificModule
1743 } else if socSpecific {
1744 return socSpecificModule
1745 } else {
1746 return platformModule
1747 }
1748}
1749
Colin Crossc34d2322020-01-03 15:23:27 -08001750func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001751 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001752 EarlyModuleContext: ctx,
1753 kind: determineModuleKind(m, ctx),
1754 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001755 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001756}
1757
Colin Cross1184b642019-12-30 18:43:07 -08001758func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1759 return baseModuleContext{
1760 bp: ctx,
1761 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1762 os: m.commonProperties.CompileOS,
1763 target: m.commonProperties.CompileTarget,
1764 targetPrimary: m.commonProperties.CompilePrimary,
1765 multiTargets: m.commonProperties.CompileMultiTargets,
1766 }
1767}
1768
Colin Cross4157e882019-06-06 16:57:04 -07001769func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001770 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001771 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001772 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001773 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
Colin Cross0ea8ba82019-06-06 14:33:29 -07001774 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001775 }
1776
Colin Crossffe6b9d2020-12-01 15:40:06 -08001777 dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
Colin Cross5d583952020-11-24 16:21:24 -08001778 // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
1779 // of installed files of this module. It will be replaced by a depset including the installed
1780 // files of this module at the end for use by modules that depend on this one.
1781 m.installFilesDepSet = newInstallPathsDepSet(nil, dependencyInstallFiles)
1782
Colin Cross6c4f21f2019-06-06 15:41:36 -07001783 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1784 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1785 // TODO: This will be removed once defaults modules handle missing dependency errors
1786 blueprintCtx.GetMissingDependencies()
1787
Colin Crossdc35e212019-06-06 16:13:11 -07001788 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001789 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1790 // (because the dependencies are added before the modules are disabled). The
1791 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1792 // ignored.
1793 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001794
Colin Cross4c83e5c2019-02-25 14:54:28 -08001795 if ctx.config.captureBuild {
1796 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1797 }
1798
Colin Cross67a5c132017-05-09 13:45:28 -07001799 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1800 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001801 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1802 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001803 }
Colin Cross0875c522017-11-28 17:34:01 -08001804 if !ctx.PrimaryArch() {
1805 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001806 }
Colin Cross56a83212020-09-15 18:30:11 -07001807 if apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo); !apexInfo.IsForPlatform() {
1808 suffix = append(suffix, apexInfo.ApexVariationName)
Dan Willemsenb13a9482020-02-14 11:25:54 -08001809 }
Colin Cross67a5c132017-05-09 13:45:28 -07001810
1811 ctx.Variable(pctx, "moduleDesc", desc)
1812
1813 s := ""
1814 if len(suffix) > 0 {
1815 s = " [" + strings.Join(suffix, " ") + "]"
1816 }
1817 ctx.Variable(pctx, "moduleDescSuffix", s)
1818
Dan Willemsen569edc52018-11-19 09:33:29 -08001819 // Some common property checks for properties that will be used later in androidmk.go
Paul Duffin89968e32020-11-23 18:17:03 +00001820 checkDistProperties(ctx, "dist", &m.distProperties.Dist)
1821 for i, _ := range m.distProperties.Dists {
1822 checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
Dan Willemsen569edc52018-11-19 09:33:29 -08001823 }
1824
Colin Cross4157e882019-06-06 16:57:04 -07001825 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001826 // ensure all direct android.Module deps are enabled
1827 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01001828 if m, ok := bm.(Module); ok {
1829 ctx.validateAndroidModule(bm, ctx.OtherModuleDependencyTag(m), ctx.baseModuleContext.strictVisitDeps)
Jooyung Hand48f3c32019-08-23 11:18:57 +09001830 }
1831 })
1832
Bob Badoura75b0572020-02-18 20:21:55 -08001833 m.noticeFiles = make([]Path, 0)
1834 optPath := OptionalPath{}
1835 notice := proptools.StringDefault(m.commonProperties.Notice, "")
Colin Cross4157e882019-06-06 16:57:04 -07001836 if module := SrcIsModule(notice); module != "" {
Bob Badoura75b0572020-02-18 20:21:55 -08001837 optPath = ctx.ExpandOptionalSource(&notice, "notice")
1838 } else if notice != "" {
Jiyong Park52818fc2019-03-18 12:01:38 +09001839 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Bob Badoura75b0572020-02-18 20:21:55 -08001840 optPath = ExistentPathForSource(ctx, noticePath)
1841 }
1842 if optPath.Valid() {
1843 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1844 } else {
1845 for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} {
1846 noticePath := filepath.Join(ctx.ModuleDir(), notice)
1847 optPath = ExistentPathForSource(ctx, noticePath)
1848 if optPath.Valid() {
1849 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1850 }
1851 }
Jaewoong Jung62707f72018-11-16 13:26:43 -08001852 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001853
Bob Badour37af0462021-01-07 03:34:31 +00001854 licensesPropertyFlattener(ctx)
1855 if ctx.Failed() {
1856 return
1857 }
1858
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001859 m.module.GenerateAndroidBuildActions(ctx)
1860 if ctx.Failed() {
1861 return
1862 }
1863
Jiyong Park4d861072021-03-03 20:02:42 +09001864 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1865 rcDir := PathForModuleInstall(ctx, "etc", "init")
1866 for _, src := range m.initRcPaths {
1867 ctx.PackageFile(rcDir, filepath.Base(src.String()), src)
1868 }
1869
1870 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
1871 vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest")
1872 for _, src := range m.vintfFragmentsPaths {
1873 ctx.PackageFile(vintfDir, filepath.Base(src.String()), src)
1874 }
1875
Paul Duffinaf970a22020-11-23 23:32:56 +00001876 // Create the set of tagged dist files after calling GenerateAndroidBuildActions
1877 // as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the
1878 // output paths being set which must be done before or during
1879 // GenerateAndroidBuildActions.
1880 m.distFiles = m.GenerateTaggedDistFiles(ctx)
1881 if ctx.Failed() {
1882 return
1883 }
1884
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001885 m.installFiles = append(m.installFiles, ctx.installFiles...)
1886 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jiyong Park073ea552020-11-09 14:08:34 +09001887 m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
Colin Crossc3d87d32020-06-04 13:25:17 -07001888 for k, v := range ctx.phonies {
1889 m.phonies[k] = append(m.phonies[k], v...)
1890 }
Colin Crossdc35e212019-06-06 16:13:11 -07001891 } else if ctx.Config().AllowMissingDependencies() {
1892 // If the module is not enabled it will not create any build rules, nothing will call
1893 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1894 // and report them as an error even when AllowMissingDependencies = true. Call
1895 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1896 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001897 }
1898
Colin Cross4157e882019-06-06 16:57:04 -07001899 if m == ctx.FinalModule().(Module).base() {
1900 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001901 if ctx.Failed() {
1902 return
1903 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001904 }
Colin Crosscec81712017-07-13 14:43:27 -07001905
Colin Cross5d583952020-11-24 16:21:24 -08001906 m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001907 m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
Colin Cross5d583952020-11-24 16:21:24 -08001908
Colin Cross4157e882019-06-06 16:57:04 -07001909 m.buildParams = ctx.buildParams
1910 m.ruleParams = ctx.ruleParams
1911 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001912}
1913
Paul Duffin89968e32020-11-23 18:17:03 +00001914// Check the supplied dist structure to make sure that it is valid.
1915//
1916// property - the base property, e.g. dist or dists[1], which is combined with the
1917// name of the nested property to produce the full property, e.g. dist.dest or
1918// dists[1].dir.
1919func checkDistProperties(ctx *moduleContext, property string, dist *Dist) {
1920 if dist.Dest != nil {
1921 _, err := validateSafePath(*dist.Dest)
1922 if err != nil {
1923 ctx.PropertyErrorf(property+".dest", "%s", err.Error())
1924 }
1925 }
1926 if dist.Dir != nil {
1927 _, err := validateSafePath(*dist.Dir)
1928 if err != nil {
1929 ctx.PropertyErrorf(property+".dir", "%s", err.Error())
1930 }
1931 }
1932 if dist.Suffix != nil {
1933 if strings.Contains(*dist.Suffix, "/") {
1934 ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.")
1935 }
1936 }
1937
1938}
1939
Colin Cross1184b642019-12-30 18:43:07 -08001940type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001941 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001942
1943 kind moduleKind
1944 config Config
1945}
1946
1947func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
Liz Kammera830f3a2020-11-10 10:50:34 -08001948 return Glob(e, globPattern, excludes)
Colin Cross1184b642019-12-30 18:43:07 -08001949}
1950
1951func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
Liz Kammera830f3a2020-11-10 10:50:34 -08001952 return GlobFiles(e, globPattern, excludes)
Colin Cross1184b642019-12-30 18:43:07 -08001953}
1954
Colin Cross988414c2020-01-11 01:11:46 +00001955func (b *earlyModuleContext) IsSymlink(path Path) bool {
1956 fileInfo, err := b.config.fs.Lstat(path.String())
1957 if err != nil {
1958 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1959 }
1960 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1961}
1962
1963func (b *earlyModuleContext) Readlink(path Path) string {
1964 dest, err := b.config.fs.Readlink(path.String())
1965 if err != nil {
1966 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1967 }
1968 return dest
1969}
1970
Colin Cross1184b642019-12-30 18:43:07 -08001971func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001972 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001973 return module
1974}
1975
1976func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001977 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001978}
1979
1980func (e *earlyModuleContext) AConfig() Config {
1981 return e.config
1982}
1983
1984func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1985 return DeviceConfig{e.config.deviceConfig}
1986}
1987
1988func (e *earlyModuleContext) Platform() bool {
1989 return e.kind == platformModule
1990}
1991
1992func (e *earlyModuleContext) DeviceSpecific() bool {
1993 return e.kind == deviceSpecificModule
1994}
1995
1996func (e *earlyModuleContext) SocSpecific() bool {
1997 return e.kind == socSpecificModule
1998}
1999
2000func (e *earlyModuleContext) ProductSpecific() bool {
2001 return e.kind == productSpecificModule
2002}
2003
2004func (e *earlyModuleContext) SystemExtSpecific() bool {
2005 return e.kind == systemExtSpecificModule
2006}
2007
Colin Cross133ebef2020-08-14 17:38:45 -07002008func (e *earlyModuleContext) Namespace() *Namespace {
2009 return e.EarlyModuleContext.Namespace().(*Namespace)
2010}
2011
Colin Cross1184b642019-12-30 18:43:07 -08002012type baseModuleContext struct {
2013 bp blueprint.BaseModuleContext
2014 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08002015 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07002016 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07002017 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07002018 targetPrimary bool
2019 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07002020
2021 walkPath []Module
Paul Duffinc5192442020-03-31 11:31:36 +01002022 tagPath []blueprint.DependencyTag
Colin Crossdc35e212019-06-06 16:13:11 -07002023
2024 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07002025}
2026
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002027func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
2028 return b.bp.OtherModuleName(m)
2029}
2030func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08002031func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Hancd87c692020-02-26 02:05:18 +09002032 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08002033}
2034func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
2035 return b.bp.OtherModuleDependencyTag(m)
2036}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002037func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00002038func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
2039 return b.bp.OtherModuleDependencyVariantExists(variations, name)
2040}
Martin Stjernholma4665622021-05-05 15:27:31 +01002041func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool {
2042 return b.bp.OtherModuleFarDependencyVariantExists(variations, name)
2043}
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00002044func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
2045 return b.bp.OtherModuleReverseDependencyVariantExists(name)
2046}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00002047func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
2048 return b.bp.OtherModuleType(m)
2049}
Colin Crossd27e7b82020-07-02 11:38:17 -07002050func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
2051 return b.bp.OtherModuleProvider(m, provider)
2052}
2053func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
2054 return b.bp.OtherModuleHasProvider(m, provider)
2055}
2056func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
2057 return b.bp.Provider(provider)
2058}
2059func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
2060 return b.bp.HasProvider(provider)
2061}
2062func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
2063 b.bp.SetProvider(provider, value)
2064}
Colin Cross1184b642019-12-30 18:43:07 -08002065
2066func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2067 return b.bp.GetDirectDepWithTag(name, tag)
2068}
2069
Paul Duffinf88d8e02020-05-07 20:21:34 +01002070func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
2071 return b.bp
2072}
2073
Colin Cross25de6c32019-06-06 14:29:25 -07002074type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07002075 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07002076 baseModuleContext
Jiyong Park073ea552020-11-09 14:08:34 +09002077 packagingSpecs []PackagingSpec
Colin Cross897266e2020-02-13 13:22:08 -08002078 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002079 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07002080 module Module
Colin Crossc3d87d32020-06-04 13:25:17 -07002081 phonies map[string]Paths
Colin Crosscec81712017-07-13 14:43:27 -07002082
2083 // For tests
Colin Crossae887032017-10-23 17:16:14 -07002084 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08002085 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08002086 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08002087}
2088
Colin Crossb88b3c52019-06-10 15:15:17 -07002089func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
2090 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07002091 Rule: ErrorRule,
2092 Description: params.Description,
2093 Output: params.Output,
2094 Outputs: params.Outputs,
2095 ImplicitOutput: params.ImplicitOutput,
2096 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08002097 Args: map[string]string{
2098 "error": err.Error(),
2099 },
Colin Crossb88b3c52019-06-10 15:15:17 -07002100 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002101}
2102
Colin Cross25de6c32019-06-06 14:29:25 -07002103func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
2104 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08002105}
2106
Jingwen Chence679d22020-09-23 04:30:02 +00002107func validateBuildParams(params blueprint.BuildParams) error {
2108 // Validate that the symlink outputs are declared outputs or implicit outputs
2109 allOutputs := map[string]bool{}
2110 for _, output := range params.Outputs {
2111 allOutputs[output] = true
2112 }
2113 for _, output := range params.ImplicitOutputs {
2114 allOutputs[output] = true
2115 }
2116 for _, symlinkOutput := range params.SymlinkOutputs {
2117 if !allOutputs[symlinkOutput] {
2118 return fmt.Errorf(
2119 "Symlink output %s is not a declared output or implicit output",
2120 symlinkOutput)
2121 }
2122 }
2123 return nil
2124}
2125
2126// Convert build parameters from their concrete Android types into their string representations,
2127// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
Colin Cross0875c522017-11-28 17:34:01 -08002128func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002129 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002130 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08002131 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08002132 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002133 Outputs: params.Outputs.Strings(),
2134 ImplicitOutputs: params.ImplicitOutputs.Strings(),
Jingwen Chence679d22020-09-23 04:30:02 +00002135 SymlinkOutputs: params.SymlinkOutputs.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002136 Inputs: params.Inputs.Strings(),
2137 Implicits: params.Implicits.Strings(),
2138 OrderOnly: params.OrderOnly.Strings(),
Colin Cross824f1162020-07-16 13:07:51 -07002139 Validations: params.Validations.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002140 Args: params.Args,
2141 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002142 }
2143
Colin Cross33bfb0a2016-11-21 17:23:08 -08002144 if params.Depfile != nil {
2145 bparams.Depfile = params.Depfile.String()
2146 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002147 if params.Output != nil {
2148 bparams.Outputs = append(bparams.Outputs, params.Output.String())
2149 }
Jingwen Chence679d22020-09-23 04:30:02 +00002150 if params.SymlinkOutput != nil {
2151 bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String())
2152 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07002153 if params.ImplicitOutput != nil {
2154 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
2155 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002156 if params.Input != nil {
2157 bparams.Inputs = append(bparams.Inputs, params.Input.String())
2158 }
2159 if params.Implicit != nil {
2160 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
2161 }
Colin Cross824f1162020-07-16 13:07:51 -07002162 if params.Validation != nil {
2163 bparams.Validations = append(bparams.Validations, params.Validation.String())
2164 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002165
Colin Cross0b9f31f2019-02-28 11:00:01 -08002166 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
2167 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
Jingwen Chence679d22020-09-23 04:30:02 +00002168 bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs)
Colin Cross0b9f31f2019-02-28 11:00:01 -08002169 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
2170 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
2171 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
Colin Cross824f1162020-07-16 13:07:51 -07002172 bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
2173 bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
Colin Crossfe4bc362018-09-12 10:02:13 -07002174
Colin Cross0875c522017-11-28 17:34:01 -08002175 return bparams
2176}
2177
Colin Cross25de6c32019-06-06 14:29:25 -07002178func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
2179 if m.config.captureBuild {
2180 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08002181 }
2182
Colin Crossdc35e212019-06-06 16:13:11 -07002183 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08002184}
2185
Colin Cross25de6c32019-06-06 14:29:25 -07002186func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08002187 argNames ...string) blueprint.Rule {
2188
Ramy Medhat944839a2020-03-31 22:14:52 -04002189 if m.config.UseRemoteBuild() {
2190 if params.Pool == nil {
2191 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
2192 // jobs to the local parallelism value
2193 params.Pool = localPool
2194 } else if params.Pool == remotePool {
2195 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
2196 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
2197 // parallelism.
2198 params.Pool = nil
2199 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07002200 }
2201
Colin Crossdc35e212019-06-06 16:13:11 -07002202 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08002203
Colin Cross25de6c32019-06-06 14:29:25 -07002204 if m.config.captureBuild {
2205 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08002206 }
2207
2208 return rule
Colin Cross0875c522017-11-28 17:34:01 -08002209}
2210
Colin Cross25de6c32019-06-06 14:29:25 -07002211func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07002212 if params.Description != "" {
2213 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
2214 }
2215
2216 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
2217 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
2218 m.ModuleName(), strings.Join(missingDeps, ", ")))
2219 }
2220
Colin Cross25de6c32019-06-06 14:29:25 -07002221 if m.config.captureBuild {
2222 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08002223 }
2224
Jingwen Chence679d22020-09-23 04:30:02 +00002225 bparams := convertBuildParams(params)
2226 err := validateBuildParams(bparams)
2227 if err != nil {
2228 m.ModuleErrorf(
2229 "%s: build parameter validation failed: %s",
2230 m.ModuleName(),
2231 err.Error())
2232 }
2233 m.bp.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002234}
Colin Crossc3d87d32020-06-04 13:25:17 -07002235
2236func (m *moduleContext) Phony(name string, deps ...Path) {
2237 addPhony(m.config, name, deps...)
2238}
2239
Colin Cross25de6c32019-06-06 14:29:25 -07002240func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07002241 var missingDeps []string
2242 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07002243 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07002244 missingDeps = FirstUniqueStrings(missingDeps)
2245 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08002246}
2247
Colin Crossdc35e212019-06-06 16:13:11 -07002248func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002249 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002250 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07002251 *missingDeps = append(*missingDeps, deps...)
2252 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002253 }
2254}
2255
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002256type AllowDisabledModuleDependency interface {
2257 blueprint.DependencyTag
2258 AllowDisabledModuleDependency(target Module) bool
2259}
2260
2261func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07002262 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07002263
2264 if !strict {
2265 return aModule
2266 }
2267
Colin Cross380c69a2019-06-10 17:49:58 +00002268 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002269 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00002270 return nil
2271 }
2272
2273 if !aModule.Enabled() {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002274 if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) {
2275 if b.Config().AllowMissingDependencies() {
2276 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
2277 } else {
2278 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
2279 }
Colin Cross380c69a2019-06-10 17:49:58 +00002280 }
2281 return nil
2282 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002283 return aModule
2284}
2285
Liz Kammer2b50ce62021-04-26 15:47:28 -04002286type dep struct {
2287 mod blueprint.Module
2288 tag blueprint.DependencyTag
2289}
2290
2291func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []dep {
Jiyong Parkf2976302019-04-17 21:47:37 +09002292 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07002293 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Liz Kammer356f7d42021-01-26 09:18:53 -05002294 if aModule, _ := module.(Module); aModule != nil {
2295 if aModule.base().BaseModuleName() == name {
2296 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
2297 if tag == nil || returnedTag == tag {
2298 deps = append(deps, dep{aModule, returnedTag})
2299 }
2300 }
2301 } else if b.bp.OtherModuleName(module) == name {
2302 returnedTag := b.bp.OtherModuleDependencyTag(module)
Jiyong Parkf2976302019-04-17 21:47:37 +09002303 if tag == nil || returnedTag == tag {
Liz Kammer356f7d42021-01-26 09:18:53 -05002304 deps = append(deps, dep{module, returnedTag})
Jiyong Parkf2976302019-04-17 21:47:37 +09002305 }
2306 }
2307 })
Liz Kammer2b50ce62021-04-26 15:47:28 -04002308 return deps
2309}
2310
2311func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
2312 deps := b.getDirectDepsInternal(name, tag)
Jiyong Parkf2976302019-04-17 21:47:37 +09002313 if len(deps) == 1 {
2314 return deps[0].mod, deps[0].tag
2315 } else if len(deps) >= 2 {
2316 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07002317 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09002318 } else {
2319 return nil, nil
2320 }
2321}
2322
Liz Kammer2b50ce62021-04-26 15:47:28 -04002323func (b *baseModuleContext) getDirectDepFirstTag(name string) (blueprint.Module, blueprint.DependencyTag) {
2324 foundDeps := b.getDirectDepsInternal(name, nil)
2325 deps := map[blueprint.Module]bool{}
2326 for _, dep := range foundDeps {
2327 deps[dep.mod] = true
2328 }
2329 if len(deps) == 1 {
2330 return foundDeps[0].mod, foundDeps[0].tag
2331 } else if len(deps) >= 2 {
2332 // this could happen if two dependencies have the same name in different namespaces
2333 // TODO(b/186554727): this should not occur if namespaces are handled within
2334 // getDirectDepsInternal.
2335 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
2336 name, b.ModuleName()))
2337 } else {
2338 return nil, nil
2339 }
2340}
2341
Colin Crossdc35e212019-06-06 16:13:11 -07002342func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07002343 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07002344 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07002345 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002346 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07002347 deps = append(deps, aModule)
2348 }
2349 }
2350 })
2351 return deps
2352}
2353
Colin Cross25de6c32019-06-06 14:29:25 -07002354func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2355 module, _ := m.getDirectDepInternal(name, tag)
2356 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09002357}
2358
Liz Kammer2b50ce62021-04-26 15:47:28 -04002359// GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
2360// name, or nil if none exists. If there are multiple dependencies on the same module it returns the
2361// first DependencyTag.
Colin Crossdc35e212019-06-06 16:13:11 -07002362func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
Liz Kammer2b50ce62021-04-26 15:47:28 -04002363 return b.getDirectDepFirstTag(name)
Jiyong Parkf2976302019-04-17 21:47:37 +09002364}
2365
Colin Crossdc35e212019-06-06 16:13:11 -07002366func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002367 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08002368}
2369
Colin Crossdc35e212019-06-06 16:13:11 -07002370func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002371 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002372 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002373 visit(aModule)
2374 }
2375 })
2376}
2377
Colin Crossdc35e212019-06-06 16:13:11 -07002378func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002379 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002380 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002381 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08002382 visit(aModule)
2383 }
2384 }
2385 })
2386}
2387
Colin Crossdc35e212019-06-06 16:13:11 -07002388func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002389 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002390 // pred
2391 func(module blueprint.Module) bool {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002392 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002393 return pred(aModule)
2394 } else {
2395 return false
2396 }
2397 },
2398 // visit
2399 func(module blueprint.Module) {
2400 visit(module.(Module))
2401 })
2402}
2403
Colin Crossdc35e212019-06-06 16:13:11 -07002404func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002405 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002406 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002407 visit(aModule)
2408 }
2409 })
2410}
2411
Colin Crossdc35e212019-06-06 16:13:11 -07002412func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002413 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002414 // pred
2415 func(module blueprint.Module) bool {
Martin Stjernholmcae43e12021-05-13 02:38:35 +01002416 if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002417 return pred(aModule)
2418 } else {
2419 return false
2420 }
2421 },
2422 // visit
2423 func(module blueprint.Module) {
2424 visit(module.(Module))
2425 })
2426}
2427
Colin Crossdc35e212019-06-06 16:13:11 -07002428func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08002429 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08002430}
2431
Colin Crossdc35e212019-06-06 16:13:11 -07002432func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
2433 b.walkPath = []Module{b.Module()}
Paul Duffinc5192442020-03-31 11:31:36 +01002434 b.tagPath = []blueprint.DependencyTag{}
Colin Cross1184b642019-12-30 18:43:07 -08002435 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002436 childAndroidModule, _ := child.(Module)
2437 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07002438 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002439 // record walkPath before visit
2440 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
2441 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
Paul Duffinc5192442020-03-31 11:31:36 +01002442 b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
Colin Crossdc35e212019-06-06 16:13:11 -07002443 }
2444 b.walkPath = append(b.walkPath, childAndroidModule)
Paul Duffinc5192442020-03-31 11:31:36 +01002445 b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07002446 return visit(childAndroidModule, parentAndroidModule)
2447 } else {
2448 return false
2449 }
2450 })
2451}
2452
Colin Crossdc35e212019-06-06 16:13:11 -07002453func (b *baseModuleContext) GetWalkPath() []Module {
2454 return b.walkPath
2455}
2456
Paul Duffinc5192442020-03-31 11:31:36 +01002457func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
2458 return b.tagPath
2459}
2460
Colin Cross4dfacf92020-09-16 19:22:27 -07002461func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
2462 b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
2463 visit(module.(Module))
2464 })
2465}
2466
2467func (b *baseModuleContext) PrimaryModule() Module {
2468 return b.bp.PrimaryModule().(Module)
2469}
2470
2471func (b *baseModuleContext) FinalModule() Module {
2472 return b.bp.FinalModule().(Module)
2473}
2474
Bob Badour07065cd2021-02-05 19:59:11 -08002475// IsMetaDependencyTag returns true for cross-cutting metadata dependencies.
2476func IsMetaDependencyTag(tag blueprint.DependencyTag) bool {
2477 if tag == licenseKindTag {
2478 return true
2479 } else if tag == licensesTag {
2480 return true
2481 }
2482 return false
2483}
2484
Jiyong Park1c7e9622020-05-07 16:12:13 +09002485// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
2486// a dependency tag.
Colin Cross6e511a92020-07-27 21:26:48 -07002487var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002488
2489// PrettyPrintTag returns string representation of the tag, but prefers
2490// custom String() method if available.
2491func PrettyPrintTag(tag blueprint.DependencyTag) string {
2492 // Use tag's custom String() method if available.
2493 if stringer, ok := tag.(fmt.Stringer); ok {
2494 return stringer.String()
2495 }
2496
2497 // Otherwise, get a default string representation of the tag's struct.
Colin Cross6e511a92020-07-27 21:26:48 -07002498 tagString := fmt.Sprintf("%T: %+v", tag, tag)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002499
2500 // Remove the boilerplate from BaseDependencyTag as it adds no value.
2501 tagString = tagCleaner.ReplaceAllString(tagString, "")
2502 return tagString
2503}
2504
2505func (b *baseModuleContext) GetPathString(skipFirst bool) string {
2506 sb := strings.Builder{}
2507 tagPath := b.GetTagPath()
2508 walkPath := b.GetWalkPath()
2509 if !skipFirst {
2510 sb.WriteString(walkPath[0].String())
2511 }
2512 for i, m := range walkPath[1:] {
2513 sb.WriteString("\n")
2514 sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
2515 sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
2516 }
2517 return sb.String()
2518}
2519
Colin Crossdc35e212019-06-06 16:13:11 -07002520func (m *moduleContext) ModuleSubDir() string {
2521 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08002522}
2523
Colin Cross0ea8ba82019-06-06 14:33:29 -07002524func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002525 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07002526}
2527
Colin Cross0ea8ba82019-06-06 14:33:29 -07002528func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002529 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07002530}
2531
Colin Cross0ea8ba82019-06-06 14:33:29 -07002532func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002533 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07002534}
2535
Colin Cross0ea8ba82019-06-06 14:33:29 -07002536func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07002537 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08002538}
2539
Colin Cross0ea8ba82019-06-06 14:33:29 -07002540func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002541 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08002542}
2543
Colin Cross0ea8ba82019-06-06 14:33:29 -07002544func (b *baseModuleContext) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09002545 return b.os.Class == Host
Colin Crossf6566ed2015-03-24 11:13:38 -07002546}
2547
Colin Cross0ea8ba82019-06-06 14:33:29 -07002548func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002549 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07002550}
2551
Colin Cross0ea8ba82019-06-06 14:33:29 -07002552func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002553 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07002554}
2555
Colin Cross0ea8ba82019-06-06 14:33:29 -07002556func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002557 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08002558}
2559
Colin Cross0ea8ba82019-06-06 14:33:29 -07002560func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002561 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07002562}
2563
Colin Cross0ea8ba82019-06-06 14:33:29 -07002564func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002565 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07002566}
2567
Colin Cross0ea8ba82019-06-06 14:33:29 -07002568func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002569 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07002570 return true
2571 }
Colin Cross25de6c32019-06-06 14:29:25 -07002572 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07002573}
2574
Jiyong Park5baac542018-08-28 09:55:37 +09002575// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09002576// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07002577func (m *ModuleBase) MakeAsPlatform() {
2578 m.commonProperties.Vendor = boolPtr(false)
2579 m.commonProperties.Proprietary = boolPtr(false)
2580 m.commonProperties.Soc_specific = boolPtr(false)
2581 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09002582 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09002583}
2584
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002585func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09002586 m.commonProperties.Vendor = boolPtr(false)
2587 m.commonProperties.Proprietary = boolPtr(false)
2588 m.commonProperties.Soc_specific = boolPtr(false)
2589 m.commonProperties.Product_specific = boolPtr(false)
2590 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002591}
2592
Jooyung Han344d5432019-08-23 11:17:39 +09002593// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
2594func (m *ModuleBase) IsNativeBridgeSupported() bool {
2595 return proptools.Bool(m.commonProperties.Native_bridge_supported)
2596}
2597
Colin Cross25de6c32019-06-06 14:29:25 -07002598func (m *moduleContext) InstallInData() bool {
2599 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08002600}
2601
Jaewoong Jung0949f312019-09-11 10:25:18 -07002602func (m *moduleContext) InstallInTestcases() bool {
2603 return m.module.InstallInTestcases()
2604}
2605
Colin Cross25de6c32019-06-06 14:29:25 -07002606func (m *moduleContext) InstallInSanitizerDir() bool {
2607 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002608}
2609
Yifan Hong1b3348d2020-01-21 15:53:22 -08002610func (m *moduleContext) InstallInRamdisk() bool {
2611 return m.module.InstallInRamdisk()
2612}
2613
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002614func (m *moduleContext) InstallInVendorRamdisk() bool {
2615 return m.module.InstallInVendorRamdisk()
2616}
2617
Inseob Kim08758f02021-04-08 21:13:22 +09002618func (m *moduleContext) InstallInDebugRamdisk() bool {
2619 return m.module.InstallInDebugRamdisk()
2620}
2621
Colin Cross25de6c32019-06-06 14:29:25 -07002622func (m *moduleContext) InstallInRecovery() bool {
2623 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002624}
2625
Colin Cross90ba5f42019-10-02 11:10:58 -07002626func (m *moduleContext) InstallInRoot() bool {
2627 return m.module.InstallInRoot()
2628}
2629
Colin Cross607d8582019-07-29 16:44:46 -07002630func (m *moduleContext) InstallBypassMake() bool {
2631 return m.module.InstallBypassMake()
2632}
2633
Jiyong Park87788b52020-09-01 12:37:45 +09002634func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
Colin Cross6e359402020-02-10 15:29:54 -08002635 return m.module.InstallForceOS()
2636}
2637
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002638func (m *moduleContext) skipInstall() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002639 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07002640 return true
2641 }
2642
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002643 if m.module.base().commonProperties.HideFromMake {
2644 return true
2645 }
2646
Colin Cross3607f212018-05-07 15:28:05 -07002647 // We'll need a solution for choosing which of modules with the same name in different
2648 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
2649 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07002650 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07002651 return true
2652 }
2653
Colin Cross25de6c32019-06-06 14:29:25 -07002654 if m.Device() {
Jingwen Chencda22c92020-11-23 00:22:30 -05002655 if m.Config().KatiEnabled() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07002656 return true
2657 }
Colin Cross893d8162017-04-26 17:34:03 -07002658 }
2659
2660 return false
2661}
2662
Colin Cross70dda7e2019-10-01 22:05:35 -07002663func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
2664 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002665 return m.installFile(installPath, name, srcPath, deps, false)
Colin Cross5c517922017-08-31 12:29:17 -07002666}
2667
Colin Cross70dda7e2019-10-01 22:05:35 -07002668func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
2669 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002670 return m.installFile(installPath, name, srcPath, deps, true)
Colin Cross5c517922017-08-31 12:29:17 -07002671}
2672
Colin Cross41589502020-12-01 14:00:21 -08002673func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec {
2674 fullInstallPath := installPath.Join(m, name)
2675 return m.packageFile(fullInstallPath, srcPath, false)
2676}
2677
2678func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec {
2679 spec := PackagingSpec{
2680 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2681 srcPath: srcPath,
2682 symlinkTarget: "",
2683 executable: executable,
2684 }
2685 m.packagingSpecs = append(m.packagingSpecs, spec)
2686 return spec
2687}
2688
Jiyong Park073ea552020-11-09 14:08:34 +09002689func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07002690
Colin Cross25de6c32019-06-06 14:29:25 -07002691 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002692 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08002693
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002694 if !m.skipInstall() {
Colin Cross5d583952020-11-24 16:21:24 -08002695 deps = append(deps, m.module.base().installFilesDepSet.ToList().Paths()...)
Colin Cross35cec122015-04-02 14:37:16 -07002696
Colin Cross89562dc2016-10-03 17:47:19 -07002697 var implicitDeps, orderOnlyDeps Paths
2698
Colin Cross25de6c32019-06-06 14:29:25 -07002699 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07002700 // Installed host modules might be used during the build, depend directly on their
2701 // dependencies so their timestamp is updated whenever their dependency is updated
2702 implicitDeps = deps
2703 } else {
2704 orderOnlyDeps = deps
2705 }
2706
Jiyong Park073ea552020-11-09 14:08:34 +09002707 rule := Cp
2708 if executable {
2709 rule = CpExecutable
2710 }
2711
Colin Cross25de6c32019-06-06 14:29:25 -07002712 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07002713 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07002714 Description: "install " + fullInstallPath.Base(),
2715 Output: fullInstallPath,
2716 Input: srcPath,
2717 Implicits: implicitDeps,
2718 OrderOnly: orderOnlyDeps,
Jingwen Chencda22c92020-11-23 00:22:30 -05002719 Default: !m.Config().KatiEnabled(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08002720 })
Colin Cross3f40fa42015-01-30 17:27:36 -08002721
Colin Cross25de6c32019-06-06 14:29:25 -07002722 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08002723 }
Jiyong Park073ea552020-11-09 14:08:34 +09002724
Colin Cross41589502020-12-01 14:00:21 -08002725 m.packageFile(fullInstallPath, srcPath, executable)
Jiyong Park073ea552020-11-09 14:08:34 +09002726
Colin Cross25de6c32019-06-06 14:29:25 -07002727 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002728
Colin Cross35cec122015-04-02 14:37:16 -07002729 return fullInstallPath
2730}
2731
Colin Cross70dda7e2019-10-01 22:05:35 -07002732func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002733 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002734 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08002735
Jiyong Park073ea552020-11-09 14:08:34 +09002736 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
2737 if err != nil {
2738 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
2739 }
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002740 if !m.skipInstall() {
Colin Crossce75d2c2016-10-06 16:12:58 -07002741
Colin Cross25de6c32019-06-06 14:29:25 -07002742 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07002743 Rule: Symlink,
2744 Description: "install symlink " + fullInstallPath.Base(),
2745 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08002746 Input: srcPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002747 Default: !m.Config().KatiEnabled(),
Colin Cross12fc4972016-01-11 12:49:11 -08002748 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08002749 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08002750 },
2751 })
Colin Cross3854a602016-01-11 12:49:11 -08002752
Colin Cross25de6c32019-06-06 14:29:25 -07002753 m.installFiles = append(m.installFiles, fullInstallPath)
2754 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08002755 }
Jiyong Park073ea552020-11-09 14:08:34 +09002756
2757 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2758 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2759 srcPath: nil,
2760 symlinkTarget: relPath,
2761 executable: false,
2762 })
2763
Colin Cross3854a602016-01-11 12:49:11 -08002764 return fullInstallPath
2765}
2766
Jiyong Parkf1194352019-02-25 11:05:47 +09002767// installPath/name -> absPath where absPath might be a path that is available only at runtime
2768// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07002769func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002770 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002771 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09002772
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002773 if !m.skipInstall() {
Colin Cross25de6c32019-06-06 14:29:25 -07002774 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09002775 Rule: Symlink,
2776 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
2777 Output: fullInstallPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002778 Default: !m.Config().KatiEnabled(),
Jiyong Parkf1194352019-02-25 11:05:47 +09002779 Args: map[string]string{
2780 "fromPath": absPath,
2781 },
2782 })
2783
Colin Cross25de6c32019-06-06 14:29:25 -07002784 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09002785 }
Jiyong Park073ea552020-11-09 14:08:34 +09002786
2787 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2788 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2789 srcPath: nil,
2790 symlinkTarget: absPath,
2791 executable: false,
2792 })
2793
Jiyong Parkf1194352019-02-25 11:05:47 +09002794 return fullInstallPath
2795}
2796
Colin Cross25de6c32019-06-06 14:29:25 -07002797func (m *moduleContext) CheckbuildFile(srcPath Path) {
2798 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08002799}
2800
Colin Crossc20dc852020-11-10 12:27:45 -08002801func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
2802 return m.bp
2803}
2804
Colin Cross41955e82019-05-29 14:40:35 -07002805// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
2806// was not a module reference.
2807func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08002808 if len(s) > 1 && s[0] == ':' {
2809 return s[1:]
2810 }
2811 return ""
2812}
2813
Colin Cross41955e82019-05-29 14:40:35 -07002814// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
2815// module name and an empty string for the tag, or empty strings if the input was not a module reference.
2816func SrcIsModuleWithTag(s string) (module, tag string) {
2817 if len(s) > 1 && s[0] == ':' {
2818 module = s[1:]
2819 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2820 if module[len(module)-1] == '}' {
2821 tag = module[tagStart+1 : len(module)-1]
2822 module = module[:tagStart]
2823 return module, tag
2824 }
2825 }
2826 return module, ""
2827 }
2828 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08002829}
2830
Colin Cross41955e82019-05-29 14:40:35 -07002831type sourceOrOutputDependencyTag struct {
2832 blueprint.BaseDependencyTag
2833 tag string
2834}
2835
2836func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
2837 return sourceOrOutputDependencyTag{tag: tag}
2838}
2839
2840var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08002841
Colin Cross366938f2017-12-11 16:29:02 -08002842// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
2843// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002844//
2845// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08002846func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07002847 set := make(map[string]bool)
2848
Colin Cross068e0fe2016-12-13 15:23:47 -08002849 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07002850 if m, t := SrcIsModuleWithTag(s); m != "" {
2851 if _, found := set[s]; found {
2852 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07002853 } else {
Colin Cross41955e82019-05-29 14:40:35 -07002854 set[s] = true
2855 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07002856 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002857 }
2858 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002859}
2860
Colin Cross366938f2017-12-11 16:29:02 -08002861// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
2862// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002863//
2864// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08002865func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
2866 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07002867 if m, t := SrcIsModuleWithTag(*s); m != "" {
2868 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08002869 }
2870 }
2871}
2872
Colin Cross41955e82019-05-29 14:40:35 -07002873// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
2874// 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 -08002875type SourceFileProducer interface {
2876 Srcs() Paths
2877}
2878
Colin Cross41955e82019-05-29 14:40:35 -07002879// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002880// 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 -07002881// listed in the property.
2882type OutputFileProducer interface {
2883 OutputFiles(tag string) (Paths, error)
2884}
2885
Colin Cross5e708052019-08-06 13:59:50 -07002886// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2887// module produced zero paths, it reports errors to the ctx and returns nil.
2888func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2889 paths, err := outputFilesForModule(ctx, module, tag)
2890 if err != nil {
2891 reportPathError(ctx, err)
2892 return nil
2893 }
2894 return paths
2895}
2896
2897// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2898// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2899func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2900 paths, err := outputFilesForModule(ctx, module, tag)
2901 if err != nil {
2902 reportPathError(ctx, err)
2903 return nil
2904 }
2905 if len(paths) > 1 {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01002906 ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
Colin Cross5e708052019-08-06 13:59:50 -07002907 pathContextName(ctx, module))
2908 return nil
2909 }
2910 return paths[0]
2911}
2912
2913func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2914 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2915 paths, err := outputFileProducer.OutputFiles(tag)
2916 if err != nil {
2917 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2918 pathContextName(ctx, module), err.Error())
2919 }
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 Cross74b1e2b2020-11-22 20:23:02 -08002924 } else if sourceFileProducer, ok := module.(SourceFileProducer); ok {
2925 if tag != "" {
2926 return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag)
2927 }
2928 paths := sourceFileProducer.Srcs()
2929 if len(paths) == 0 {
2930 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2931 }
2932 return paths, nil
Colin Cross5e708052019-08-06 13:59:50 -07002933 } else {
2934 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2935 }
2936}
2937
Colin Cross41589502020-12-01 14:00:21 -08002938// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to
2939// specify that they can be used as a tool by a genrule module.
Colin Crossfe17f6f2019-03-28 19:30:56 -07002940type HostToolProvider interface {
Colin Crossba9e4032020-11-24 16:32:22 -08002941 Module
Colin Cross41589502020-12-01 14:00:21 -08002942 // HostToolPath returns the path to the host tool for the module if it is one, or an invalid
2943 // OptionalPath.
Colin Crossfe17f6f2019-03-28 19:30:56 -07002944 HostToolPath() OptionalPath
2945}
2946
Colin Cross27b922f2019-03-04 22:35:41 -08002947// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2948// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002949//
2950// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002951func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2952 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002953}
2954
Colin Cross2fafa3e2019-03-05 12:39:51 -08002955// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2956// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002957//
2958// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002959func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2960 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002961}
2962
2963// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2964// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2965// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002966func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002967 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002968 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002969 }
2970 return OptionalPath{}
2971}
2972
Colin Cross25de6c32019-06-06 14:29:25 -07002973func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002974 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002975}
2976
Colin Cross25de6c32019-06-06 14:29:25 -07002977func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002978 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002979}
2980
Colin Cross25de6c32019-06-06 14:29:25 -07002981func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002982 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002983}
2984
Colin Cross463a90e2015-06-17 14:20:06 -07002985func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002986 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002987}
2988
Colin Cross0875c522017-11-28 17:34:01 -08002989func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002990 return &buildTargetSingleton{}
2991}
2992
Colin Cross87d8b562017-04-25 10:01:55 -07002993func parentDir(dir string) string {
2994 dir, _ = filepath.Split(dir)
2995 return filepath.Clean(dir)
2996}
2997
Colin Cross1f8c52b2015-06-16 16:38:17 -07002998type buildTargetSingleton struct{}
2999
Colin Cross0875c522017-11-28 17:34:01 -08003000func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
3001 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07003002
Colin Crossc3d87d32020-06-04 13:25:17 -07003003 mmTarget := func(dir string) string {
3004 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07003005 }
3006
Colin Cross0875c522017-11-28 17:34:01 -08003007 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003008
Colin Cross0875c522017-11-28 17:34:01 -08003009 ctx.VisitAllModules(func(module Module) {
3010 blueprintDir := module.base().blueprintDir
3011 installTarget := module.base().installTarget
3012 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07003013
Colin Cross0875c522017-11-28 17:34:01 -08003014 if checkbuildTarget != nil {
3015 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
3016 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
3017 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003018
Colin Cross0875c522017-11-28 17:34:01 -08003019 if installTarget != nil {
3020 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003021 }
3022 })
3023
Dan Willemsen5ba07e82015-12-11 13:51:06 -08003024 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05003025 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08003026 suffix = "-soong"
3027 }
3028
Colin Cross1f8c52b2015-06-16 16:38:17 -07003029 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07003030 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003031
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003032 // Make will generate the MODULES-IN-* targets
Jingwen Chencda22c92020-11-23 00:22:30 -05003033 if ctx.Config().KatiEnabled() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003034 return
3035 }
3036
Colin Cross87d8b562017-04-25 10:01:55 -07003037 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09003038 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07003039 for _, dir := range dirs {
3040 dir := parentDir(dir)
3041 for dir != "." && dir != "/" {
3042 if _, exists := modulesInDir[dir]; exists {
3043 break
3044 }
3045 modulesInDir[dir] = nil
3046 dir = parentDir(dir)
3047 }
3048 }
3049
3050 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07003051 for _, dir := range dirs {
3052 p := parentDir(dir)
3053 if p != "." && p != "/" {
Colin Crossc3d87d32020-06-04 13:25:17 -07003054 modulesInDir[p] = append(modulesInDir[p], PathForPhony(ctx, mmTarget(dir)))
Colin Cross87d8b562017-04-25 10:01:55 -07003055 }
3056 }
3057
Dan Willemsend2e95fb2017-09-20 14:30:50 -07003058 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
3059 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
3060 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07003061 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07003062 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07003063 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07003064
3065 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
Jiyong Park1613e552020-09-14 19:43:17 +09003066 type osAndCross struct {
3067 os OsType
3068 hostCross bool
3069 }
3070 osDeps := map[osAndCross]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08003071 ctx.VisitAllModules(func(module Module) {
3072 if module.Enabled() {
Jiyong Park1613e552020-09-14 19:43:17 +09003073 key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
3074 osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003075 }
3076 })
3077
Colin Cross0875c522017-11-28 17:34:01 -08003078 osClass := make(map[string]Paths)
Jiyong Park1613e552020-09-14 19:43:17 +09003079 for key, deps := range osDeps {
Dan Willemsen61d88b82017-09-20 17:29:08 -07003080 var className string
3081
Jiyong Park1613e552020-09-14 19:43:17 +09003082 switch key.os.Class {
Dan Willemsen61d88b82017-09-20 17:29:08 -07003083 case Host:
Jiyong Park1613e552020-09-14 19:43:17 +09003084 if key.hostCross {
3085 className = "host-cross"
3086 } else {
3087 className = "host"
3088 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07003089 case Device:
3090 className = "target"
3091 default:
3092 continue
3093 }
3094
Jiyong Park1613e552020-09-14 19:43:17 +09003095 name := className + "-" + key.os.Name
Colin Crossc3d87d32020-06-04 13:25:17 -07003096 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07003097
Colin Crossc3d87d32020-06-04 13:25:17 -07003098 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003099 }
3100
3101 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09003102 for _, class := range SortedStringKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07003103 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07003104 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07003105}
Colin Crossd779da42015-12-17 18:00:23 -08003106
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003107// Collect information for opening IDE project files in java/jdeps.go.
3108type IDEInfo interface {
3109 IDEInfo(ideInfo *IdeInfo)
3110 BaseModuleName() string
3111}
3112
3113// Extract the base module name from the Import name.
3114// Often the Import name has a prefix "prebuilt_".
3115// Remove the prefix explicitly if needed
3116// until we find a better solution to get the Import name.
3117type IDECustomizedModuleName interface {
3118 IDECustomizedModuleName() string
3119}
3120
3121type IdeInfo struct {
3122 Deps []string `json:"dependencies,omitempty"`
3123 Srcs []string `json:"srcs,omitempty"`
3124 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
3125 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
3126 Jars []string `json:"jars,omitempty"`
3127 Classes []string `json:"class,omitempty"`
3128 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08003129 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08003130 Paths []string `json:"path,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003131}
Paul Duffinf88d8e02020-05-07 20:21:34 +01003132
3133func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
3134 bpctx := ctx.blueprintBaseModuleContext()
3135 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
3136}
Colin Cross5d583952020-11-24 16:21:24 -08003137
3138// installPathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
3139// topological order.
3140type installPathsDepSet struct {
3141 depSet
3142}
3143
3144// newInstallPathsDepSet returns an immutable packagingSpecsDepSet with the given direct and
3145// transitive contents.
3146func newInstallPathsDepSet(direct InstallPaths, transitive []*installPathsDepSet) *installPathsDepSet {
3147 return &installPathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
3148}
3149
3150// ToList returns the installPathsDepSet flattened to a list in topological order.
3151func (d *installPathsDepSet) ToList() InstallPaths {
3152 if d == nil {
3153 return nil
3154 }
3155 return d.depSet.ToList().(InstallPaths)
3156}