blob: 8baf799c3ae1bdbb3a630922f6f8d979a681d838 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Jingwen Chen73850672020-12-14 08:25:34 -050018 "android/soong/bazel"
Colin Cross6ff51382015-12-17 16:39:19 -080019 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000020 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080021 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080022 "path/filepath"
Jiyong Park1c7e9622020-05-07 16:12:13 +090023 "regexp"
Colin Cross6ff51382015-12-17 16:39:19 -080024 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080025 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070026
27 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070028 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080029)
30
31var (
32 DeviceSharedLibrary = "shared_library"
33 DeviceStaticLibrary = "static_library"
34 DeviceExecutable = "executable"
35 HostSharedLibrary = "host_shared_library"
36 HostStaticLibrary = "host_static_library"
37 HostExecutable = "host_executable"
38)
39
Colin Crossae887032017-10-23 17:16:14 -070040type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070041 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080042 Deps blueprint.Deps
43 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070044 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070045 Output WritablePath
46 Outputs WritablePaths
Jingwen Chence679d22020-09-23 04:30:02 +000047 SymlinkOutput WritablePath
48 SymlinkOutputs WritablePaths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070049 ImplicitOutput WritablePath
50 ImplicitOutputs WritablePaths
51 Input Path
52 Inputs Paths
53 Implicit Path
54 Implicits Paths
55 OrderOnly Paths
Colin Cross824f1162020-07-16 13:07:51 -070056 Validation Path
57 Validations Paths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070058 Default bool
59 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070060}
61
Colin Crossae887032017-10-23 17:16:14 -070062type ModuleBuildParams BuildParams
63
Colin Cross1184b642019-12-30 18:43:07 -080064// EarlyModuleContext provides methods that can be called early, as soon as the properties have
65// been parsed into the module and before any mutators have run.
66type EarlyModuleContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -070067 // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
68 // reference to itself.
Colin Cross1184b642019-12-30 18:43:07 -080069 Module() Module
Colin Cross9f35c3d2020-09-16 19:04:41 -070070
71 // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
72 // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
Colin Cross1184b642019-12-30 18:43:07 -080073 ModuleName() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070074
75 // ModuleDir returns the path to the directory that contains the definition of the module.
Colin Cross1184b642019-12-30 18:43:07 -080076 ModuleDir() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070077
78 // ModuleType returns the name of the module type that was used to create the module, as specified in
79 // RegisterModuleType.
Colin Cross1184b642019-12-30 18:43:07 -080080 ModuleType() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070081
82 // BlueprintFile returns the name of the blueprint file that contains the definition of this
83 // module.
Colin Cross9d34f352019-11-22 16:03:51 -080084 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080085
Colin Cross9f35c3d2020-09-16 19:04:41 -070086 // ContainsProperty returns true if the specified property name was set in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080087 ContainsProperty(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -070088
89 // Errorf reports an error at the specified position of the module definition file.
Colin Cross1184b642019-12-30 18:43:07 -080090 Errorf(pos scanner.Position, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070091
92 // ModuleErrorf reports an error at the line number of the module type in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080093 ModuleErrorf(fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070094
95 // PropertyErrorf reports an error at the line number of a property in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080096 PropertyErrorf(property, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070097
98 // Failed returns true if any errors have been reported. In most cases the module can continue with generating
99 // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
100 // has prevented the module from creating necessary data it can return early when Failed returns true.
Colin Cross1184b642019-12-30 18:43:07 -0800101 Failed() bool
102
Colin Cross9f35c3d2020-09-16 19:04:41 -0700103 // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
104 // primary builder will be rerun whenever the specified files are modified.
Colin Cross1184b642019-12-30 18:43:07 -0800105 AddNinjaFileDeps(deps ...string)
106
107 DeviceSpecific() bool
108 SocSpecific() bool
109 ProductSpecific() bool
110 SystemExtSpecific() bool
111 Platform() bool
112
113 Config() Config
114 DeviceConfig() DeviceConfig
115
116 // Deprecated: use Config()
117 AConfig() Config
118
119 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
120 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
121 // builder whenever a file matching the pattern as added or removed, without rerunning if a
122 // file that does not match the pattern is added to a searched directory.
123 GlobWithDeps(pattern string, excludes []string) ([]string, error)
124
125 Glob(globPattern string, excludes []string) Paths
126 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +0000127 IsSymlink(path Path) bool
128 Readlink(path Path) string
Colin Cross133ebef2020-08-14 17:38:45 -0700129
Colin Cross9f35c3d2020-09-16 19:04:41 -0700130 // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
131 // default SimpleNameInterface if Context.SetNameInterface was not called.
Colin Cross133ebef2020-08-14 17:38:45 -0700132 Namespace() *Namespace
Colin Cross1184b642019-12-30 18:43:07 -0800133}
134
Colin Cross0ea8ba82019-06-06 14:33:29 -0700135// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700136// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
137// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700138// about the current module.
139type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800140 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700141
Paul Duffinf88d8e02020-05-07 20:21:34 +0100142 blueprintBaseModuleContext() blueprint.BaseModuleContext
143
Colin Cross9f35c3d2020-09-16 19:04:41 -0700144 // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
145 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700146 OtherModuleName(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700147
148 // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
149 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700150 OtherModuleDir(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700151
152 // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
153 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700154 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -0700155
156 // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
157 // on the module. When called inside a Visit* method with current module being visited, and there are multiple
158 // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
Colin Crossdc35e212019-06-06 16:13:11 -0700159 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
Colin Cross9f35c3d2020-09-16 19:04:41 -0700160
161 // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
162 // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
Colin Crossdc35e212019-06-06 16:13:11 -0700163 OtherModuleExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700164
165 // OtherModuleDependencyVariantExists returns true if a module with the
166 // specified name and variant exists. The variant must match the given
167 // variations. It must also match all the non-local variations of the current
Martin Stjernholm408ffd82021-05-05 15:27:31 +0100168 // module. In other words, it checks for the module that AddVariationDependencies
Colin Cross9f35c3d2020-09-16 19:04:41 -0700169 // would add a dependency on with the same arguments.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000170 OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700171
Martin Stjernholm408ffd82021-05-05 15:27:31 +0100172 // OtherModuleFarDependencyVariantExists returns true if a module with the
173 // specified name and variant exists. The variant must match the given
174 // variations, but not the non-local variations of the current module. In
175 // other words, it checks for the module that AddFarVariationDependencies
176 // would add a dependency on with the same arguments.
177 OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool
178
Colin Cross9f35c3d2020-09-16 19:04:41 -0700179 // OtherModuleReverseDependencyVariantExists returns true if a module with the
180 // specified name exists with the same variations as the current module. In
Martin Stjernholm408ffd82021-05-05 15:27:31 +0100181 // other words, it checks for the module that AddReverseDependency would add a
Colin Cross9f35c3d2020-09-16 19:04:41 -0700182 // dependency on with the same argument.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000183 OtherModuleReverseDependencyVariantExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700184
185 // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
186 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Jiyong Park9e6c2422019-08-09 20:39:45 +0900187 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700188
Colin Crossd27e7b82020-07-02 11:38:17 -0700189 // OtherModuleProvider returns the value for a provider for the given module. If the value is
190 // not set it returns the zero value of the type of the provider, so the return value can always
191 // be type asserted to the type of the provider. The value returned may be a deep copy of the
192 // value originally passed to SetProvider.
193 OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
194
195 // OtherModuleHasProvider returns true if the provider for the given module has been set.
196 OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
197
198 // Provider returns the value for a provider for the current module. If the value is
199 // not set it returns the zero value of the type of the provider, so the return value can always
200 // be type asserted to the type of the provider. It panics if called before the appropriate
201 // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
202 // copy of the value originally passed to SetProvider.
203 Provider(provider blueprint.ProviderKey) interface{}
204
205 // HasProvider returns true if the provider for the current module has been set.
206 HasProvider(provider blueprint.ProviderKey) bool
207
208 // SetProvider sets the value for a provider for the current module. It panics if not called
209 // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
210 // is not of the appropriate type, or if the value has already been set. The value should not
211 // be modified after being passed to SetProvider.
212 SetProvider(provider blueprint.ProviderKey, value interface{})
213
Colin Crossdc35e212019-06-06 16:13:11 -0700214 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700215
216 // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
217 // none exists. It panics if the dependency does not have the specified tag. It skips any
218 // dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700219 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700220
221 // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
222 // name, or nil if none exists. If there are multiple dependencies on the same module it returns
Liz Kammer2b50ce62021-04-26 15:47:28 -0400223 // the first DependencyTag.
Colin Crossdc35e212019-06-06 16:13:11 -0700224 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
225
Colin Cross9f35c3d2020-09-16 19:04:41 -0700226 // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
227 // direct dependencies on the same module visit will be called multiple times on that module
228 // and OtherModuleDependencyTag will return a different tag for each.
229 //
230 // The Module passed to the visit function should not be retained outside of the visit
231 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700232 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700233
234 // VisitDirectDeps calls visit for each direct dependency. If there are multiple
235 // direct dependencies on the same module visit will be called multiple times on that module
236 // and OtherModuleDependencyTag will return a different tag for each. It skips any
237 // dependencies that are not an android.Module.
238 //
239 // The Module passed to the visit function should not be retained outside of the visit
240 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700241 VisitDirectDeps(visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700242
Colin Crossdc35e212019-06-06 16:13:11 -0700243 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700244
245 // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
246 // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
247 // OtherModuleDependencyTag will return a different tag for each. It skips any
248 // dependencies that are not an android.Module.
249 //
250 // The Module passed to the visit function should not be retained outside of the visit function, it may be
251 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700252 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
253 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
254 VisitDepsDepthFirst(visit func(Module))
255 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
256 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700257
258 // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
259 // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
260 // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
261 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
262 // any dependencies that are not an android.Module.
263 //
264 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
265 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700266 WalkDeps(visit func(Module, Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700267
268 // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
269 // tree in top down order. visit may be called multiple times for the same (child, parent)
270 // pair if there are multiple direct dependencies between the child and parent with different
271 // tags. OtherModuleDependencyTag will return the tag for the currently visited
272 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
273 // to child.
274 //
275 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
276 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700277 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700278
Colin Crossdc35e212019-06-06 16:13:11 -0700279 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
280 // and returns a top-down dependency path from a start module to current child module.
281 GetWalkPath() []Module
282
Colin Cross4dfacf92020-09-16 19:22:27 -0700283 // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
284 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
285 // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
286 // only done once for all variants of a module.
287 PrimaryModule() Module
288
289 // FinalModule returns the last variant of the current module. Variants of a module are always visited in
290 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
291 // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
292 // singleton actions that are only done once for all variants of a module.
293 FinalModule() Module
294
295 // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
296 // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
297 // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
298 // data modified by the current mutator.
299 VisitAllModuleVariants(visit func(Module))
300
Paul Duffinc5192442020-03-31 11:31:36 +0100301 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
302 // and returns a top-down dependency tags path from a start module to current child module.
303 // It has one less entry than GetWalkPath() as it contains the dependency tags that
304 // exist between each adjacent pair of modules in the GetWalkPath().
305 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
306 GetTagPath() []blueprint.DependencyTag
307
Jiyong Park1c7e9622020-05-07 16:12:13 +0900308 // GetPathString is supposed to be called in visit function passed in WalkDeps()
309 // and returns a multi-line string showing the modules and dependency tags
310 // among them along the top-down dependency path from a start module to current child module.
311 // skipFirst when set to true, the output doesn't include the start module,
312 // which is already printed when this function is used along with ModuleErrorf().
313 GetPathString(skipFirst bool) string
314
Colin Crossdc35e212019-06-06 16:13:11 -0700315 AddMissingDependencies(missingDeps []string)
316
Colin Crossa1ad8d12016-06-01 17:09:44 -0700317 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700318 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000319
320 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
321 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700322 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700323 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700324 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700325 Host() bool
326 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700327 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800328 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700329 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700330 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700331 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700332}
333
Colin Cross1184b642019-12-30 18:43:07 -0800334// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700335type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800336 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800337}
338
Colin Cross635c3b02016-05-18 15:37:25 -0700339type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800340 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800341
Colin Crossc20dc852020-11-10 12:27:45 -0800342 blueprintModuleContext() blueprint.ModuleContext
343
Colin Crossae887032017-10-23 17:16:14 -0700344 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800345 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700346
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700347 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800348 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800349 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700350
Colin Cross41589502020-12-01 14:00:21 -0800351 // InstallExecutable creates a rule to copy srcPath to name in the installPath directory,
352 // with the given additional dependencies. The file is marked executable after copying.
353 //
354 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
355 // installed file will be returned by PackagingSpecs() on this module or by
356 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
357 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700358 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800359
360 // InstallFile creates a rule to copy srcPath to name in the installPath directory,
361 // with the given additional dependencies.
362 //
363 // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the
364 // installed file will be returned by PackagingSpecs() on this module or by
365 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
366 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700367 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800368
369 // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath
370 // directory.
371 //
372 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
373 // installed file will be returned by PackagingSpecs() on this module or by
374 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
375 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700376 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800377
378 // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name
379 // in the installPath directory.
380 //
381 // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the
382 // installed file will be returned by PackagingSpecs() on this module or by
383 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
384 // for which IsInstallDepNeeded returns true.
Colin Cross70dda7e2019-10-01 22:05:35 -0700385 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Colin Cross41589502020-12-01 14:00:21 -0800386
387 // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating
388 // the rule to copy the file. This is useful to define how a module would be packaged
389 // without installing it into the global installation directories.
390 //
391 // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by
392 // TransitivePackagingSpecs() on modules that depend on this module through dependency tags
393 // for which IsInstallDepNeeded returns true.
394 PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec
395
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700396 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800397
Colin Cross8d8f8e22016-08-03 11:57:50 -0700398 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700399 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700400 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800401 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700402 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900403 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900404 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700405 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700406 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900407 InstallForceOS() (*OsType, *ArchType)
Nan Zhang6d34b302017-02-04 17:47:46 -0800408
409 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700410 HostRequiredModuleNames() []string
411 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700412
Colin Cross3f68a132017-10-23 17:10:29 -0700413 ModuleSubDir() string
414
Colin Cross0875c522017-11-28 17:34:01 -0800415 Variable(pctx PackageContext, name, value string)
416 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700417 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
418 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800419 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700420 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
421 // phony rules or real files. Phony can be called on the same name multiple times to add
422 // additional dependencies.
423 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700424
Colin Cross9f35c3d2020-09-16 19:04:41 -0700425 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
426 // but do not exist.
Colin Cross3f68a132017-10-23 17:10:29 -0700427 GetMissingDependencies() []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800428}
429
Colin Cross635c3b02016-05-18 15:37:25 -0700430type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800431 blueprint.Module
432
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700433 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
434 // but GenerateAndroidBuildActions also has access to Android-specific information.
435 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700436 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700437
Paul Duffin44f1d842020-06-26 20:17:02 +0100438 // Add dependencies to the components of a module, i.e. modules that are created
439 // by the module and which are considered to be part of the creating module.
440 //
441 // This is called before prebuilts are renamed so as to allow a dependency to be
442 // added directly to a prebuilt child module instead of depending on a source module
443 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
444 //
445 // A dependency on a prebuilt must include the "prebuilt_" prefix.
446 ComponentDepsMutator(ctx BottomUpMutatorContext)
447
Colin Cross1e676be2016-10-12 14:38:15 -0700448 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800449
Colin Cross635c3b02016-05-18 15:37:25 -0700450 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900451 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800452 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700453 Target() Target
Paul Duffinc04fb9e2021-03-01 12:25:10 +0000454 MultiTargets() []Target
Anton Hansson1ee62c02020-06-30 11:51:53 +0100455 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -0800456 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700457 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700458 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800459 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700460 InstallInVendorRamdisk() bool
Inseob Kim08758f02021-04-08 21:13:22 +0900461 InstallInDebugRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900462 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700463 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700464 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900465 InstallForceOS() (*OsType, *ArchType)
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800466 HideFromMake()
467 IsHideFromMake() bool
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +0000468 IsSkipInstall() bool
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100469 MakeUninstallable()
Liz Kammer5ca3a622020-08-05 15:40:41 -0700470 ReplacedByPrebuilt()
471 IsReplacedByPrebuilt() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900472 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900473 InitRc() Paths
474 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800475 NoticeFiles() Paths
Justin Yun885a7de2021-06-29 20:34:53 +0900476 EffectiveLicenseFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700477
478 AddProperties(props ...interface{})
479 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700480
Colin Crossae887032017-10-23 17:16:14 -0700481 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800482 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800483 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100484
Colin Cross9a362232019-07-01 15:32:45 -0700485 // String returns a string that includes the module name and variants for printing during debugging.
486 String() string
487
Paul Duffine2453c72019-05-31 14:00:04 +0100488 // Get the qualified module id for this module.
489 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
490
491 // Get information about the properties that can contain visibility rules.
492 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100493
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900494 RequiredModuleNames() []string
495 HostRequiredModuleNames() []string
496 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800497
Jiyong Park4dc2a1a2020-09-28 17:46:22 +0900498 FilesToInstall() InstallPaths
Jiyong Park073ea552020-11-09 14:08:34 +0900499 PackagingSpecs() []PackagingSpec
Colin Crossffe6b9d2020-12-01 15:40:06 -0800500
501 // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
502 // dependencies with dependency tags for which IsInstallDepNeeded() returns true.
503 TransitivePackagingSpecs() []PackagingSpec
Paul Duffine2453c72019-05-31 14:00:04 +0100504}
505
Jingwen Chenab60f122021-01-24 21:21:45 -0500506// BazelTargetModule is a lightweight wrapper interface around Module for
507// bp2build conversion purposes.
508//
509// In bp2build's bootstrap.Main execution, Soong runs an alternate pipeline of
510// mutators that creates BazelTargetModules from regular Module objects,
511// performing the mapping from Soong properties to Bazel rule attributes in the
512// process. This process may optionally create additional BazelTargetModules,
513// resulting in a 1:many mapping.
514//
515// bp2build.Codegen is then responsible for visiting all modules in the graph,
516// filtering for BazelTargetModules, and code-generating BUILD targets from
517// them.
Jingwen Chen73850672020-12-14 08:25:34 -0500518type BazelTargetModule interface {
519 Module
520
Liz Kammerfc46bc12021-02-19 11:06:17 -0500521 bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
522 SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties)
523
524 RuleClass() string
525 BzlLoadLocation() string
Jingwen Chen73850672020-12-14 08:25:34 -0500526}
527
Jingwen Chenab60f122021-01-24 21:21:45 -0500528// InitBazelTargetModule is a wrapper function that decorates BazelTargetModule
529// with property structs containing metadata for bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500530func InitBazelTargetModule(module BazelTargetModule) {
Liz Kammerfc46bc12021-02-19 11:06:17 -0500531 module.AddProperties(module.bazelTargetModuleProperties())
Jingwen Chen73850672020-12-14 08:25:34 -0500532 InitAndroidModule(module)
533}
534
Jingwen Chenab60f122021-01-24 21:21:45 -0500535// BazelTargetModuleBase contains the property structs with metadata for
536// bp2build conversion.
Jingwen Chen73850672020-12-14 08:25:34 -0500537type BazelTargetModuleBase struct {
538 ModuleBase
539 Properties bazel.BazelTargetModuleProperties
540}
541
Liz Kammerfc46bc12021-02-19 11:06:17 -0500542// bazelTargetModuleProperties getter.
543func (btmb *BazelTargetModuleBase) bazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
Jingwen Chen73850672020-12-14 08:25:34 -0500544 return &btmb.Properties
545}
546
Liz Kammerfc46bc12021-02-19 11:06:17 -0500547// SetBazelTargetModuleProperties setter for BazelTargetModuleProperties
548func (btmb *BazelTargetModuleBase) SetBazelTargetModuleProperties(props bazel.BazelTargetModuleProperties) {
549 btmb.Properties = props
550}
551
552// RuleClass returns the rule class for this Bazel target
553func (b *BazelTargetModuleBase) RuleClass() string {
554 return b.bazelTargetModuleProperties().Rule_class
555}
556
557// BzlLoadLocation returns the rule class for this Bazel target
558func (b *BazelTargetModuleBase) BzlLoadLocation() string {
559 return b.bazelTargetModuleProperties().Bzl_load_location
560}
561
Paul Duffine2453c72019-05-31 14:00:04 +0100562// Qualified id for a module
563type qualifiedModuleName struct {
564 // The package (i.e. directory) in which the module is defined, without trailing /
565 pkg string
566
567 // The name of the module, empty string if package.
568 name string
569}
570
571func (q qualifiedModuleName) String() string {
572 if q.name == "" {
573 return "//" + q.pkg
574 }
575 return "//" + q.pkg + ":" + q.name
576}
577
Paul Duffine484f472019-06-20 16:38:08 +0100578func (q qualifiedModuleName) isRootPackage() bool {
579 return q.pkg == "" && q.name == ""
580}
581
Paul Duffine2453c72019-05-31 14:00:04 +0100582// Get the id for the package containing this module.
583func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
584 pkg := q.pkg
585 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100586 if pkg == "" {
587 panic(fmt.Errorf("Cannot get containing package id of root package"))
588 }
589
590 index := strings.LastIndex(pkg, "/")
591 if index == -1 {
592 pkg = ""
593 } else {
594 pkg = pkg[:index]
595 }
Paul Duffine2453c72019-05-31 14:00:04 +0100596 }
597 return newPackageId(pkg)
598}
599
600func newPackageId(pkg string) qualifiedModuleName {
601 // A qualified id for a package module has no name.
602 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800603}
604
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000605type Dist struct {
606 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
607 // command line and any of these targets are also on the command line, or otherwise
608 // built
609 Targets []string `android:"arch_variant"`
610
611 // The name of the output artifact. This defaults to the basename of the output of
612 // the module.
613 Dest *string `android:"arch_variant"`
614
615 // The directory within the dist directory to store the artifact. Defaults to the
616 // top level directory ("").
617 Dir *string `android:"arch_variant"`
618
619 // A suffix to add to the artifact file name (before any extension).
620 Suffix *string `android:"arch_variant"`
621
Paul Duffin74f05592020-11-25 16:37:46 +0000622 // A string tag to select the OutputFiles associated with the tag.
623 //
624 // If no tag is specified then it will select the default dist paths provided
625 // by the module type. If a tag of "" is specified then it will return the
626 // default output files provided by the modules, i.e. the result of calling
627 // OutputFiles("").
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000628 Tag *string `android:"arch_variant"`
629}
630
Colin Crossfc754582016-05-17 16:34:16 -0700631type nameProperties struct {
632 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800633 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700634}
635
Colin Cross08d6f8f2020-11-19 02:33:19 +0000636type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800637 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000638 //
639 // Disabling a module should only be done for those modules that cannot be built
640 // in the current environment. Modules that can build in the current environment
641 // but are not usually required (e.g. superceded by a prebuilt) should not be
642 // disabled as that will prevent them from being built by the checkbuild target
643 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800644 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800645
Paul Duffin2e61fa62019-03-28 14:10:57 +0000646 // Controls the visibility of this module to other modules. Allowable values are one or more of
647 // these formats:
648 //
649 // ["//visibility:public"]: Anyone can use this module.
650 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
651 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100652 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
653 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000654 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
655 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
656 // this module. Note that sub-packages do not have access to the rule; for example,
657 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
658 // is a special module and must be used verbatim. It represents all of the modules in the
659 // package.
660 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
661 // or other or in one of their sub-packages have access to this module. For example,
662 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
663 // to depend on this rule (but not //independent:evil)
664 // ["//project"]: This is shorthand for ["//project:__pkg__"]
665 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
666 // //project is the module's package. e.g. using [":__subpackages__"] in
667 // packages/apps/Settings/Android.bp is equivalent to
668 // //packages/apps/Settings:__subpackages__.
669 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
670 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100671 //
672 // If a module does not specify the `visibility` property then it uses the
673 // `default_visibility` property of the `package` module in the module's package.
674 //
675 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100676 // it will use the `default_visibility` of its closest ancestor package for which
677 // a `default_visibility` property is specified.
678 //
679 // If no `default_visibility` property can be found then the module uses the
680 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100681 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100682 // The `visibility` property has no effect on a defaults module although it does
683 // apply to any non-defaults module that uses it. To set the visibility of a
684 // defaults module, use the `defaults_visibility` property on the defaults module;
685 // not to be confused with the `default_visibility` property on the package module.
686 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000687 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
688 // more details.
689 Visibility []string
690
Bob Badour37af0462021-01-07 03:34:31 +0000691 // Describes the licenses applicable to this module. Must reference license modules.
692 Licenses []string
693
694 // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more.
695 Effective_licenses []string `blueprint:"mutated"`
696 // Override of module name when reporting licenses
697 Effective_package_name *string `blueprint:"mutated"`
698 // Notice files
Paul Duffinec0836a2021-05-10 22:53:30 +0100699 Effective_license_text Paths `blueprint:"mutated"`
Bob Badour37af0462021-01-07 03:34:31 +0000700 // License names
701 Effective_license_kinds []string `blueprint:"mutated"`
702 // License conditions
703 Effective_license_conditions []string `blueprint:"mutated"`
704
Colin Cross7d5136f2015-05-11 13:39:40 -0700705 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800706 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
707 // 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 +0000708 // platform).
Colin Cross7d716ba2017-11-01 10:38:29 -0700709 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700710
711 Target struct {
712 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700713 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700714 }
715 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700716 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700717 }
718 }
719
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000720 // If set to true then the archMutator will create variants for each arch specific target
721 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
722 // create a variant for the architecture and will list the additional arch specific targets
723 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700724 UseTargetVariants bool `blueprint:"mutated"`
725 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800726
Dan Willemsen782a2d12015-12-21 14:55:28 -0800727 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700728 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800729
Colin Cross55708f32017-03-20 13:23:34 -0700730 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700731 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700732
Jiyong Park2db76922017-11-08 16:03:48 +0900733 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
734 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
735 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700736 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700737
Jiyong Park2db76922017-11-08 16:03:48 +0900738 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
739 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
740 Soc_specific *bool
741
742 // whether this module is specific to a device, not only for SoC, but also for off-chip
743 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
744 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
745 // This implies `soc_specific:true`.
746 Device_specific *bool
747
748 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900749 // network operator, etc). When set to true, it is installed into /product (or
750 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900751 Product_specific *bool
752
Justin Yund5f6c822019-06-25 16:47:17 +0900753 // whether this module extends system. When set to true, it is installed into /system_ext
754 // (or /system/system_ext if system_ext partition does not exist).
755 System_ext_specific *bool
756
Jiyong Parkf9332f12018-02-01 00:54:12 +0900757 // Whether this module is installed to recovery partition
758 Recovery *bool
759
Yifan Hong1b3348d2020-01-21 15:53:22 -0800760 // Whether this module is installed to ramdisk
761 Ramdisk *bool
762
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700763 // Whether this module is installed to vendor ramdisk
764 Vendor_ramdisk *bool
765
Inseob Kim08758f02021-04-08 21:13:22 +0900766 // Whether this module is installed to debug ramdisk
767 Debug_ramdisk *bool
768
Jaewoong Jung8e93aba2021-03-02 16:58:08 -0800769 // Whether this module is built for non-native architectures (also known as native bridge binary)
dimitry1f33e402019-03-26 12:39:31 +0100770 Native_bridge_supported *bool `android:"arch_variant"`
771
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700772 // init.rc files to be installed if this module is installed
Colin Cross0bab8772020-09-25 14:01:21 -0700773 Init_rc []string `android:"arch_variant,path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700774
Steven Moreland57a23d22018-04-04 15:42:19 -0700775 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800776 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700777
Chris Wolfe998306e2016-08-15 14:47:23 -0400778 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700779 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400780
Sasha Smundakb6d23052019-04-01 18:37:36 -0700781 // names of other modules to install on host if this module is installed
782 Host_required []string `android:"arch_variant"`
783
784 // names of other modules to install on target if this module is installed
785 Target_required []string `android:"arch_variant"`
786
Colin Cross5aac3622017-08-31 15:07:09 -0700787 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800788 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700789
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000790 // The OsType of artifacts that this module variant is responsible for creating.
791 //
792 // Set by osMutator
793 CompileOS OsType `blueprint:"mutated"`
794
795 // The Target of artifacts that this module variant is responsible for creating.
796 //
797 // Set by archMutator
798 CompileTarget Target `blueprint:"mutated"`
799
800 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
801 // responsible for creating.
802 //
803 // By default this is nil as, where necessary, separate variants are created for the
804 // different multilib types supported and that information is encapsulated in the
805 // CompileTarget so the module variant simply needs to create artifacts for that.
806 //
807 // However, if UseTargetVariants is set to false (e.g. by
808 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
809 // multilib targets. Instead a single variant is created for the architecture and
810 // this contains the multilib specific targets that this variant should create.
811 //
812 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700813 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000814
815 // True if the module variant's CompileTarget is the primary target
816 //
817 // Set by archMutator
818 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800819
820 // Set by InitAndroidModule
821 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700822 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700823
Paul Duffin1356d8c2020-02-25 19:26:33 +0000824 // If set to true then a CommonOS variant will be created which will have dependencies
825 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
826 // that covers all os and architecture variants.
827 //
828 // The OsType specific variants can be retrieved by calling
829 // GetOsSpecificVariantsOfCommonOSVariant
830 //
831 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
832 CreateCommonOSVariant bool `blueprint:"mutated"`
833
834 // If set to true then this variant is the CommonOS variant that has dependencies on its
835 // OsType specific variants.
836 //
837 // Set by osMutator.
838 CommonOSVariant bool `blueprint:"mutated"`
839
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800840 // When HideFromMake is set to true, no entry for this variant will be emitted in the
841 // generated Android.mk file.
842 HideFromMake bool `blueprint:"mutated"`
843
844 // When SkipInstall is set to true, calls to ctx.InstallFile, ctx.InstallExecutable,
845 // ctx.InstallSymlink and ctx.InstallAbsoluteSymlink act like calls to ctx.PackageFile
846 // and don't create a rule to install the file.
Colin Crossce75d2c2016-10-06 16:12:58 -0700847 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800848
Liz Kammer5ca3a622020-08-05 15:40:41 -0700849 // Whether the module has been replaced by a prebuilt
850 ReplacedByPrebuilt bool `blueprint:"mutated"`
851
Justin Yun32f053b2020-07-31 23:07:17 +0900852 // Disabled by mutators. If set to true, it overrides Enabled property.
853 ForcedDisabled bool `blueprint:"mutated"`
854
Jeff Gaston088e29e2017-11-29 16:47:17 -0800855 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700856
857 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700858
859 // Name and variant strings stored by mutators to enable Module.String()
860 DebugName string `blueprint:"mutated"`
861 DebugMutators []string `blueprint:"mutated"`
862 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800863
Colin Crossa6845402020-11-16 15:08:19 -0800864 // ImageVariation is set by ImageMutator to specify which image this variation is for,
865 // for example "" for core or "recovery" for recovery. It will often be set to one of the
866 // constants in image.go, but can also be set to a custom value by individual module types.
Colin Cross7228ecd2019-11-18 16:00:16 -0800867 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800868}
869
Paul Duffined875132020-09-02 13:08:57 +0100870type distProperties struct {
871 // configuration to distribute output files from this module to the distribution
872 // directory (default: $OUT/dist, configurable with $DIST_DIR)
873 Dist Dist `android:"arch_variant"`
874
875 // a list of configurations to distribute output files from this module to the
876 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
877 Dists []Dist `android:"arch_variant"`
878}
879
Paul Duffin74f05592020-11-25 16:37:46 +0000880// The key to use in TaggedDistFiles when a Dist structure does not specify a
881// tag property. This intentionally does not use "" as the default because that
882// would mean that an empty tag would have a different meaning when used in a dist
883// structure that when used to reference a specific set of output paths using the
884// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
885const DefaultDistTag = "<default-dist-tag>"
886
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000887// A map of OutputFile tag keys to Paths, for disting purposes.
888type TaggedDistFiles map[string]Paths
889
Paul Duffin74f05592020-11-25 16:37:46 +0000890// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
891// then it will create a map, update it and then return it. If a mapping already
892// exists for the tag then the paths are appended to the end of the current list
893// of paths, ignoring any duplicates.
894func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
895 if t == nil {
896 t = make(TaggedDistFiles)
897 }
898
899 for _, distFile := range paths {
900 if distFile != nil && !t[tag].containsPath(distFile) {
901 t[tag] = append(t[tag], distFile)
902 }
903 }
904
905 return t
906}
907
908// merge merges the entries from the other TaggedDistFiles object into this one.
909// If the TaggedDistFiles is nil then it will create a new instance, merge the
910// other into it, and then return it.
911func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
912 for tag, paths := range other {
913 t = t.addPathsForTag(tag, paths...)
914 }
915
916 return t
917}
918
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000919func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000920 for _, path := range paths {
921 if path == nil {
922 panic("The path to a dist file cannot be nil.")
923 }
924 }
925
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000926 // The default OutputFile tag is the empty "" string.
Paul Duffin74f05592020-11-25 16:37:46 +0000927 return TaggedDistFiles{DefaultDistTag: paths}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000928}
929
Colin Cross3f40fa42015-01-30 17:27:36 -0800930type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800931 // If set to true, build a variant of the module for the host. Defaults to false.
932 Host_supported *bool
933
934 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700935 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800936}
937
Colin Crossc472d572015-03-17 15:06:21 -0700938type Multilib string
939
940const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800941 MultilibBoth Multilib = "both"
942 MultilibFirst Multilib = "first"
943 MultilibCommon Multilib = "common"
944 MultilibCommonFirst Multilib = "common_first"
945 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700946)
947
Colin Crossa1ad8d12016-06-01 17:09:44 -0700948type HostOrDeviceSupported int
949
950const (
Colin Cross34037c62020-11-17 13:19:17 -0800951 hostSupported = 1 << iota
952 hostCrossSupported
953 deviceSupported
954 hostDefault
955 deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700956
957 // Host and HostCross are built by default. Device is not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800958 HostSupported = hostSupported | hostCrossSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700959
960 // Host is built by default. HostCross and Device are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800961 HostSupportedNoCross = hostSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700962
963 // Device is built by default. Host and HostCross are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800964 DeviceSupported = deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700965
966 // Device is built by default. Host and HostCross are supported.
Colin Cross34037c62020-11-17 13:19:17 -0800967 HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700968
969 // Host, HostCross, and Device are built by default.
Colin Cross34037c62020-11-17 13:19:17 -0800970 HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
971 deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700972
973 // Nothing is supported. This is not exposed to the user, but used to mark a
974 // host only module as unsupported when the module type is not supported on
975 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Colin Cross34037c62020-11-17 13:19:17 -0800976 NeitherHostNorDeviceSupported = 0
Colin Crossa1ad8d12016-06-01 17:09:44 -0700977)
978
Jiyong Park2db76922017-11-08 16:03:48 +0900979type moduleKind int
980
981const (
982 platformModule moduleKind = iota
983 deviceSpecificModule
984 socSpecificModule
985 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900986 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900987)
988
989func (k moduleKind) String() string {
990 switch k {
991 case platformModule:
992 return "platform"
993 case deviceSpecificModule:
994 return "device-specific"
995 case socSpecificModule:
996 return "soc-specific"
997 case productSpecificModule:
998 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900999 case systemExtSpecificModule:
1000 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +09001001 default:
1002 panic(fmt.Errorf("unknown module kind %d", k))
1003 }
1004}
1005
Colin Cross9d34f352019-11-22 16:03:51 -08001006func initAndroidModuleBase(m Module) {
1007 m.base().module = m
1008}
1009
Colin Crossa6845402020-11-16 15:08:19 -08001010// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
1011// It adds the common properties, for example "name" and "enabled".
Colin Cross36242852017-06-23 15:06:31 -07001012func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -08001013 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001014 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -07001015
Colin Cross36242852017-06-23 15:06:31 -07001016 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -07001017 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +01001018 &base.commonProperties,
1019 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -07001020
Colin Crosseabaedd2020-02-06 17:01:55 -08001021 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -07001022
Colin Crossa3a97412019-03-18 12:24:29 -07001023 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -07001024 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +01001025
1026 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +01001027 // its checking and parsing phases so make it the primary visibility property.
1028 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Bob Badour37af0462021-01-07 03:34:31 +00001029
1030 // The default_applicable_licenses property needs to be checked and parsed by the licenses module during
1031 // its checking and parsing phases so make it the primary licenses property.
1032 setPrimaryLicensesProperty(m, "licenses", &base.commonProperties.Licenses)
Colin Cross5049f022015-03-18 13:28:46 -07001033}
1034
Colin Crossa6845402020-11-16 15:08:19 -08001035// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
1036// It adds the common properties, for example "name" and "enabled", as well as runtime generated
1037// property structs for architecture-specific versions of generic properties tagged with
1038// `android:"arch_variant"`.
1039//
1040// InitAndroidModule should not be called if InitAndroidArchModule was called.
Colin Cross36242852017-06-23 15:06:31 -07001041func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1042 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -07001043
1044 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -08001045 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -07001046 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -07001047 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -07001048 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001049
Colin Cross34037c62020-11-17 13:19:17 -08001050 if hod&hostSupported != 0 && hod&deviceSupported != 0 {
Colin Cross36242852017-06-23 15:06:31 -07001051 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -08001052 }
1053
Colin Crossa6845402020-11-16 15:08:19 -08001054 initArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -08001055}
1056
Colin Crossa6845402020-11-16 15:08:19 -08001057// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1058// architecture-specific, but will only have a single variant per OS that handles all the
1059// architectures simultaneously. The list of Targets that it must handle will be available from
1060// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
1061// well as runtime generated property structs for architecture-specific versions of generic
1062// properties tagged with `android:"arch_variant"`.
1063//
1064// InitAndroidModule or InitAndroidArchModule should not be called if
1065// InitAndroidMultiTargetsArchModule was called.
Colin Crossee0bc3b2018-10-02 22:01:37 -07001066func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1067 InitAndroidArchModule(m, hod, defaultMultilib)
1068 m.base().commonProperties.UseTargetVariants = false
1069}
1070
Colin Crossa6845402020-11-16 15:08:19 -08001071// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
1072// architecture-specific, but will only have a single variant per OS that handles all the
1073// architectures simultaneously, and will also have an additional CommonOS variant that has
1074// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
1075// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
1076// "enabled", as well as runtime generated property structs for architecture-specific versions of
1077// generic properties tagged with `android:"arch_variant"`.
1078//
1079// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
1080// called if InitCommonOSAndroidMultiTargetsArchModule was called.
Paul Duffin1356d8c2020-02-25 19:26:33 +00001081func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
1082 InitAndroidArchModule(m, hod, defaultMultilib)
1083 m.base().commonProperties.UseTargetVariants = false
1084 m.base().commonProperties.CreateCommonOSVariant = true
1085}
1086
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001087// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -08001088// modules. It should be included as an anonymous field in every module
1089// struct definition. InitAndroidModule should then be called from the module's
1090// factory function, and the return values from InitAndroidModule should be
1091// returned from the factory function.
1092//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001093// The ModuleBase type is responsible for implementing the GenerateBuildActions
1094// method to support the blueprint.Module interface. This method will then call
1095// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -07001096// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
1097// rather than the usual blueprint.ModuleContext.
1098// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -08001099// system including details about the particular build variant that is to be
1100// generated.
1101//
1102// For example:
1103//
1104// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001105// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -08001106// )
1107//
1108// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001109// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -08001110// properties struct {
1111// MyProperty string
1112// }
1113// }
1114//
Colin Cross36242852017-06-23 15:06:31 -07001115// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001116// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -07001117// m.AddProperties(&m.properties)
1118// android.InitAndroidModule(m)
1119// return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001120// }
1121//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -08001122// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001123// // Get the CPU architecture for the current build variant.
1124// variantArch := ctx.Arch()
1125//
1126// // ...
1127// }
Colin Cross635c3b02016-05-18 15:37:25 -07001128type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -08001129 // Putting the curiously recurring thing pointing to the thing that contains
1130 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -07001131 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -07001132 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -08001133
Colin Crossfc754582016-05-17 16:34:16 -07001134 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -08001135 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +01001136 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -07001137 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001138 hostAndDeviceProperties hostAndDeviceProperties
1139 generalProperties []interface{}
Jingwen Chen5d864492021-02-24 07:20:12 -05001140
1141 // Arch specific versions of structs in generalProperties. The outer index
1142 // has the same order as generalProperties as initialized in
1143 // InitAndroidArchModule, and the inner index chooses the props specific to
1144 // the architecture. The interface{} value is an archPropRoot that is
1145 // filled with arch specific values by the arch mutator.
1146 archProperties [][]interface{}
1147
1148 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001149
Jingwen Chen73850672020-12-14 08:25:34 -05001150 // Properties specific to the Blueprint to BUILD migration.
1151 bazelTargetModuleProperties bazel.BazelTargetModuleProperties
1152
Paul Duffin63c6e182019-07-24 14:24:38 +01001153 // Information about all the properties on the module that contains visibility rules that need
1154 // checking.
1155 visibilityPropertyInfo []visibilityProperty
1156
1157 // The primary visibility property, may be nil, that controls access to the module.
1158 primaryVisibilityProperty visibilityProperty
1159
Bob Badour37af0462021-01-07 03:34:31 +00001160 // The primary licenses property, may be nil, records license metadata for the module.
1161 primaryLicensesProperty applicableLicensesProperty
1162
Colin Crossffe6b9d2020-12-01 15:40:06 -08001163 noAddressSanitizer bool
1164 installFiles InstallPaths
1165 installFilesDepSet *installPathsDepSet
1166 checkbuildFiles Paths
1167 packagingSpecs []PackagingSpec
1168 packagingSpecsDepSet *packagingSpecsDepSet
1169 noticeFiles Paths
1170 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001171
Paul Duffinaf970a22020-11-23 23:32:56 +00001172 // The files to copy to the dist as explicitly specified in the .bp file.
1173 distFiles TaggedDistFiles
1174
Colin Cross1f8c52b2015-06-16 16:38:17 -07001175 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
1176 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -08001177 installTarget WritablePath
1178 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -07001179 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -07001180
Colin Cross178a5092016-09-13 13:42:32 -07001181 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -07001182
1183 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -07001184
1185 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001186 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001187 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001188 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -07001189
Inseob Kim8471cda2019-11-15 09:59:12 +09001190 initRcPaths Paths
1191 vintfFragmentsPaths Paths
Colin Cross36242852017-06-23 15:06:31 -07001192}
1193
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001194func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
1195 (*d)["Android"] = map[string]interface{}{}
1196}
1197
Paul Duffin44f1d842020-06-26 20:17:02 +01001198func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
1199
Colin Cross4157e882019-06-06 16:57:04 -07001200func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -08001201
Colin Cross4157e882019-06-06 16:57:04 -07001202func (m *ModuleBase) AddProperties(props ...interface{}) {
1203 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -07001204}
1205
Colin Cross4157e882019-06-06 16:57:04 -07001206func (m *ModuleBase) GetProperties() []interface{} {
1207 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -08001208}
1209
Colin Cross4157e882019-06-06 16:57:04 -07001210func (m *ModuleBase) BuildParamsForTests() []BuildParams {
1211 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -07001212}
1213
Colin Cross4157e882019-06-06 16:57:04 -07001214func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
1215 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001216}
1217
Colin Cross4157e882019-06-06 16:57:04 -07001218func (m *ModuleBase) VariablesForTests() map[string]string {
1219 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001220}
1221
Colin Crossce75d2c2016-10-06 16:12:58 -07001222// Name returns the name of the module. It may be overridden by individual module types, for
1223// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -07001224func (m *ModuleBase) Name() string {
1225 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -07001226}
1227
Colin Cross9a362232019-07-01 15:32:45 -07001228// String returns a string that includes the module name and variants for printing during debugging.
1229func (m *ModuleBase) String() string {
1230 sb := strings.Builder{}
1231 sb.WriteString(m.commonProperties.DebugName)
1232 sb.WriteString("{")
1233 for i := range m.commonProperties.DebugMutators {
1234 if i != 0 {
1235 sb.WriteString(",")
1236 }
1237 sb.WriteString(m.commonProperties.DebugMutators[i])
1238 sb.WriteString(":")
1239 sb.WriteString(m.commonProperties.DebugVariations[i])
1240 }
1241 sb.WriteString("}")
1242 return sb.String()
1243}
1244
Colin Crossce75d2c2016-10-06 16:12:58 -07001245// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001246func (m *ModuleBase) BaseModuleName() string {
1247 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001248}
1249
Colin Cross4157e882019-06-06 16:57:04 -07001250func (m *ModuleBase) base() *ModuleBase {
1251 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001252}
1253
Paul Duffine2453c72019-05-31 14:00:04 +01001254func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1255 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1256}
1257
1258func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001259 return m.visibilityPropertyInfo
1260}
1261
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001262func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001263 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001264 // Make a copy of the underlying Dists slice to protect against
1265 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001266 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1267 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001268 } else {
Paul Duffined875132020-09-02 13:08:57 +01001269 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001270 }
1271}
1272
1273func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
Paul Duffin74f05592020-11-25 16:37:46 +00001274 var distFiles TaggedDistFiles
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001275 for _, dist := range m.Dists() {
Paul Duffin74f05592020-11-25 16:37:46 +00001276 // If no tag is specified then it means to use the default dist paths so use
1277 // the special tag name which represents that.
1278 tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
1279
Paul Duffinaf970a22020-11-23 23:32:56 +00001280 if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
1281 // Call the OutputFiles(tag) method to get the paths associated with the tag.
1282 distFilesForTag, err := outputFileProducer.OutputFiles(tag)
Paul Duffin74f05592020-11-25 16:37:46 +00001283
Paul Duffinaf970a22020-11-23 23:32:56 +00001284 // If the tag was not supported and is not DefaultDistTag then it is an error.
1285 // Failing to find paths for DefaultDistTag is not an error. It just means
1286 // that the module type requires the legacy behavior.
1287 if err != nil && tag != DefaultDistTag {
1288 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1289 }
1290
1291 distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
1292 } else if tag != DefaultDistTag {
1293 // If the tag was specified then it is an error if the module does not
1294 // implement OutputFileProducer because there is no other way of accessing
1295 // the paths for the specified tag.
1296 ctx.PropertyErrorf("dist.tag",
1297 "tag %s not supported because the module does not implement OutputFileProducer", tag)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001298 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001299 }
1300
1301 return distFiles
1302}
1303
Colin Cross4157e882019-06-06 16:57:04 -07001304func (m *ModuleBase) Target() Target {
1305 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001306}
1307
Colin Cross4157e882019-06-06 16:57:04 -07001308func (m *ModuleBase) TargetPrimary() bool {
1309 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001310}
1311
Colin Cross4157e882019-06-06 16:57:04 -07001312func (m *ModuleBase) MultiTargets() []Target {
1313 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001314}
1315
Colin Cross4157e882019-06-06 16:57:04 -07001316func (m *ModuleBase) Os() OsType {
1317 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001318}
1319
Colin Cross4157e882019-06-06 16:57:04 -07001320func (m *ModuleBase) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09001321 return m.Os().Class == Host
Dan Willemsen97750522016-02-09 17:43:51 -08001322}
1323
Yo Chiangbba545e2020-06-09 16:15:37 +08001324func (m *ModuleBase) Device() bool {
1325 return m.Os().Class == Device
1326}
1327
Colin Cross4157e882019-06-06 16:57:04 -07001328func (m *ModuleBase) Arch() Arch {
1329 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001330}
1331
Colin Cross4157e882019-06-06 16:57:04 -07001332func (m *ModuleBase) ArchSpecific() bool {
1333 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001334}
1335
Paul Duffin1356d8c2020-02-25 19:26:33 +00001336// True if the current variant is a CommonOS variant, false otherwise.
1337func (m *ModuleBase) IsCommonOSVariant() bool {
1338 return m.commonProperties.CommonOSVariant
1339}
1340
Colin Cross34037c62020-11-17 13:19:17 -08001341// supportsTarget returns true if the given Target is supported by the current module.
1342func (m *ModuleBase) supportsTarget(target Target) bool {
1343 switch target.Os.Class {
1344 case Host:
1345 if target.HostCross {
1346 return m.HostCrossSupported()
1347 } else {
1348 return m.HostSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001349 }
Colin Cross34037c62020-11-17 13:19:17 -08001350 case Device:
1351 return m.DeviceSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001352 default:
Jiyong Park1613e552020-09-14 19:43:17 +09001353 return false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001354 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001355}
1356
Colin Cross34037c62020-11-17 13:19:17 -08001357// DeviceSupported returns true if the current module is supported and enabled for device targets,
1358// i.e. the factory method set the HostOrDeviceSupported value to include device support and
1359// the device support is enabled by default or enabled by the device_supported property.
Colin Cross4157e882019-06-06 16:57:04 -07001360func (m *ModuleBase) DeviceSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001361 hod := m.commonProperties.HostOrDeviceSupported
1362 // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
1363 // value has the deviceDefault bit set.
1364 deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
1365 return hod&deviceSupported != 0 && deviceEnabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001366}
1367
Colin Cross34037c62020-11-17 13:19:17 -08001368// HostSupported returns true if the current module is supported and enabled for host targets,
1369// i.e. the factory method set the HostOrDeviceSupported value to include host support and
1370// the host support is enabled by default or enabled by the host_supported property.
Paul Duffine44358f2019-11-26 18:04:12 +00001371func (m *ModuleBase) HostSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001372 hod := m.commonProperties.HostOrDeviceSupported
1373 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1374 // value has the hostDefault bit set.
1375 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1376 return hod&hostSupported != 0 && hostEnabled
1377}
1378
1379// HostCrossSupported returns true if the current module is supported and enabled for host cross
1380// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
1381// support and the host cross support is enabled by default or enabled by the
1382// host_supported property.
1383func (m *ModuleBase) HostCrossSupported() bool {
1384 hod := m.commonProperties.HostOrDeviceSupported
1385 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1386 // value has the hostDefault bit set.
1387 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1388 return hod&hostCrossSupported != 0 && hostEnabled
Paul Duffine44358f2019-11-26 18:04:12 +00001389}
1390
Colin Cross4157e882019-06-06 16:57:04 -07001391func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001392 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001393}
1394
Colin Cross4157e882019-06-06 16:57:04 -07001395func (m *ModuleBase) DeviceSpecific() bool {
1396 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001397}
1398
Colin Cross4157e882019-06-06 16:57:04 -07001399func (m *ModuleBase) SocSpecific() bool {
1400 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001401}
1402
Colin Cross4157e882019-06-06 16:57:04 -07001403func (m *ModuleBase) ProductSpecific() bool {
1404 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001405}
1406
Justin Yund5f6c822019-06-25 16:47:17 +09001407func (m *ModuleBase) SystemExtSpecific() bool {
1408 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001409}
1410
Colin Crossc2d24052020-05-13 11:05:02 -07001411// RequiresStableAPIs returns true if the module will be installed to a partition that may
1412// be updated separately from the system image.
1413func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1414 return m.SocSpecific() || m.DeviceSpecific() ||
1415 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1416}
1417
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001418func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1419 partition := "system"
1420 if m.SocSpecific() {
1421 // A SoC-specific module could be on the vendor partition at
1422 // "vendor" or the system partition at "system/vendor".
1423 if config.VendorPath() == "vendor" {
1424 partition = "vendor"
1425 }
1426 } else if m.DeviceSpecific() {
1427 // A device-specific module could be on the odm partition at
1428 // "odm", the vendor partition at "vendor/odm", or the system
1429 // partition at "system/vendor/odm".
1430 if config.OdmPath() == "odm" {
1431 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001432 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001433 partition = "vendor"
1434 }
1435 } else if m.ProductSpecific() {
1436 // A product-specific module could be on the product partition
1437 // at "product" or the system partition at "system/product".
1438 if config.ProductPath() == "product" {
1439 partition = "product"
1440 }
1441 } else if m.SystemExtSpecific() {
1442 // A system_ext-specific module could be on the system_ext
1443 // partition at "system_ext" or the system partition at
1444 // "system/system_ext".
1445 if config.SystemExtPath() == "system_ext" {
1446 partition = "system_ext"
1447 }
1448 }
1449 return partition
1450}
1451
Colin Cross4157e882019-06-06 16:57:04 -07001452func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001453 if m.commonProperties.ForcedDisabled {
1454 return false
1455 }
Colin Cross08d6f8f2020-11-19 02:33:19 +00001456 if m.commonProperties.Enabled == nil {
1457 return !m.Os().DefaultDisabled
1458 }
1459 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001460}
1461
Inseob Kimeec88e12020-01-22 11:11:29 +09001462func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001463 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001464}
1465
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001466// HideFromMake marks this variant so that it is not emitted in the generated Android.mk file.
1467func (m *ModuleBase) HideFromMake() {
1468 m.commonProperties.HideFromMake = true
1469}
1470
1471// IsHideFromMake returns true if HideFromMake was previously called.
1472func (m *ModuleBase) IsHideFromMake() bool {
1473 return m.commonProperties.HideFromMake == true
1474}
1475
1476// SkipInstall marks this variant to not create install rules when ctx.Install* are called.
Colin Cross4157e882019-06-06 16:57:04 -07001477func (m *ModuleBase) SkipInstall() {
1478 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001479}
1480
Martin Stjernholm9e7f45e2020-12-23 03:50:30 +00001481// IsSkipInstall returns true if this variant is marked to not create install
1482// rules when ctx.Install* are called.
1483func (m *ModuleBase) IsSkipInstall() bool {
1484 return m.commonProperties.SkipInstall
1485}
1486
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001487// Similar to HideFromMake, but if the AndroidMk entry would set
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001488// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1489// rather than leaving it out altogether. That happens in cases where it would
1490// have other side effects, in particular when it adds a NOTICE file target,
1491// which other install targets might depend on.
1492func (m *ModuleBase) MakeUninstallable() {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001493 m.HideFromMake()
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001494}
1495
Liz Kammer5ca3a622020-08-05 15:40:41 -07001496func (m *ModuleBase) ReplacedByPrebuilt() {
1497 m.commonProperties.ReplacedByPrebuilt = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001498 m.HideFromMake()
Liz Kammer5ca3a622020-08-05 15:40:41 -07001499}
1500
1501func (m *ModuleBase) IsReplacedByPrebuilt() bool {
1502 return m.commonProperties.ReplacedByPrebuilt
1503}
1504
Colin Cross4157e882019-06-06 16:57:04 -07001505func (m *ModuleBase) ExportedToMake() bool {
1506 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001507}
1508
Justin Yun885a7de2021-06-29 20:34:53 +09001509func (m *ModuleBase) EffectiveLicenseFiles() Paths {
1510 return m.commonProperties.Effective_license_text
1511}
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 Stjernholm0e4cceb2021-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 Stjernholm408ffd82021-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 Stjernholm0e4cceb2021-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 Stjernholm0e4cceb2021-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 Stjernholm0e4cceb2021-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 Stjernholm0e4cceb2021-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 Stjernholm0e4cceb2021-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 Stjernholm0e4cceb2021-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 Stjernholm0e4cceb2021-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}