blob: 35491ca5a464caf251aa14ee28f7ca4b186b928d [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross6ff51382015-12-17 16:39:19 -080018 "fmt"
Colin Cross988414c2020-01-11 01:11:46 +000019 "os"
Alex Lightfb4353d2019-01-17 13:57:45 -080020 "path"
Colin Cross3f40fa42015-01-30 17:27:36 -080021 "path/filepath"
Jiyong Park1c7e9622020-05-07 16:12:13 +090022 "regexp"
Colin Cross6ff51382015-12-17 16:39:19 -080023 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080024 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070025
26 "github.com/google/blueprint"
Colin Crossfe4bc362018-09-12 10:02:13 -070027 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080028)
29
30var (
31 DeviceSharedLibrary = "shared_library"
32 DeviceStaticLibrary = "static_library"
33 DeviceExecutable = "executable"
34 HostSharedLibrary = "host_shared_library"
35 HostStaticLibrary = "host_static_library"
36 HostExecutable = "host_executable"
37)
38
Colin Crossae887032017-10-23 17:16:14 -070039type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070040 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080041 Deps blueprint.Deps
42 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070043 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070044 Output WritablePath
45 Outputs WritablePaths
46 ImplicitOutput WritablePath
47 ImplicitOutputs WritablePaths
48 Input Path
49 Inputs Paths
50 Implicit Path
51 Implicits Paths
52 OrderOnly Paths
Colin Cross824f1162020-07-16 13:07:51 -070053 Validation Path
54 Validations Paths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070055 Default bool
56 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070057}
58
Colin Crossae887032017-10-23 17:16:14 -070059type ModuleBuildParams BuildParams
60
Colin Cross1184b642019-12-30 18:43:07 -080061// EarlyModuleContext provides methods that can be called early, as soon as the properties have
62// been parsed into the module and before any mutators have run.
63type EarlyModuleContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -070064 // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
65 // reference to itself.
Colin Cross1184b642019-12-30 18:43:07 -080066 Module() Module
Colin Cross9f35c3d2020-09-16 19:04:41 -070067
68 // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
69 // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
Colin Cross1184b642019-12-30 18:43:07 -080070 ModuleName() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070071
72 // ModuleDir returns the path to the directory that contains the definition of the module.
Colin Cross1184b642019-12-30 18:43:07 -080073 ModuleDir() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070074
75 // ModuleType returns the name of the module type that was used to create the module, as specified in
76 // RegisterModuleType.
Colin Cross1184b642019-12-30 18:43:07 -080077 ModuleType() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070078
79 // BlueprintFile returns the name of the blueprint file that contains the definition of this
80 // module.
Colin Cross9d34f352019-11-22 16:03:51 -080081 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080082
Colin Cross9f35c3d2020-09-16 19:04:41 -070083 // ContainsProperty returns true if the specified property name was set in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080084 ContainsProperty(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -070085
86 // Errorf reports an error at the specified position of the module definition file.
Colin Cross1184b642019-12-30 18:43:07 -080087 Errorf(pos scanner.Position, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070088
89 // ModuleErrorf reports an error at the line number of the module type in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080090 ModuleErrorf(fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070091
92 // PropertyErrorf reports an error at the line number of a property in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080093 PropertyErrorf(property, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070094
95 // Failed returns true if any errors have been reported. In most cases the module can continue with generating
96 // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
97 // has prevented the module from creating necessary data it can return early when Failed returns true.
Colin Cross1184b642019-12-30 18:43:07 -080098 Failed() bool
99
Colin Cross9f35c3d2020-09-16 19:04:41 -0700100 // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
101 // primary builder will be rerun whenever the specified files are modified.
Colin Cross1184b642019-12-30 18:43:07 -0800102 AddNinjaFileDeps(deps ...string)
103
104 DeviceSpecific() bool
105 SocSpecific() bool
106 ProductSpecific() bool
107 SystemExtSpecific() bool
108 Platform() bool
109
110 Config() Config
111 DeviceConfig() DeviceConfig
112
113 // Deprecated: use Config()
114 AConfig() Config
115
116 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
117 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
118 // builder whenever a file matching the pattern as added or removed, without rerunning if a
119 // file that does not match the pattern is added to a searched directory.
120 GlobWithDeps(pattern string, excludes []string) ([]string, error)
121
122 Glob(globPattern string, excludes []string) Paths
123 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +0000124 IsSymlink(path Path) bool
125 Readlink(path Path) string
Colin Cross133ebef2020-08-14 17:38:45 -0700126
Colin Cross9f35c3d2020-09-16 19:04:41 -0700127 // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
128 // default SimpleNameInterface if Context.SetNameInterface was not called.
Colin Cross133ebef2020-08-14 17:38:45 -0700129 Namespace() *Namespace
Colin Cross1184b642019-12-30 18:43:07 -0800130}
131
Colin Cross0ea8ba82019-06-06 14:33:29 -0700132// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700133// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
134// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700135// about the current module.
136type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800137 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700138
Paul Duffinf88d8e02020-05-07 20:21:34 +0100139 blueprintBaseModuleContext() blueprint.BaseModuleContext
140
Colin Cross9f35c3d2020-09-16 19:04:41 -0700141 // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
142 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700143 OtherModuleName(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700144
145 // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
146 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700147 OtherModuleDir(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700148
149 // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
150 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700151 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -0700152
153 // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
154 // on the module. When called inside a Visit* method with current module being visited, and there are multiple
155 // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
Colin Crossdc35e212019-06-06 16:13:11 -0700156 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
Colin Cross9f35c3d2020-09-16 19:04:41 -0700157
158 // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
159 // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
Colin Crossdc35e212019-06-06 16:13:11 -0700160 OtherModuleExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700161
162 // OtherModuleDependencyVariantExists returns true if a module with the
163 // specified name and variant exists. The variant must match the given
164 // variations. It must also match all the non-local variations of the current
165 // module. In other words, it checks for the module AddVariationDependencies
166 // would add a dependency on with the same arguments.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000167 OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700168
169 // OtherModuleReverseDependencyVariantExists returns true if a module with the
170 // specified name exists with the same variations as the current module. In
171 // other words, it checks for the module AddReverseDependency would add a
172 // dependency on with the same argument.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000173 OtherModuleReverseDependencyVariantExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700174
175 // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
176 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Jiyong Park9e6c2422019-08-09 20:39:45 +0900177 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700178
Colin Crossd27e7b82020-07-02 11:38:17 -0700179 // OtherModuleProvider returns the value for a provider for the given module. If the value is
180 // not set it returns the zero value of the type of the provider, so the return value can always
181 // be type asserted to the type of the provider. The value returned may be a deep copy of the
182 // value originally passed to SetProvider.
183 OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
184
185 // OtherModuleHasProvider returns true if the provider for the given module has been set.
186 OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
187
188 // Provider returns the value for a provider for the current module. If the value is
189 // not set it returns the zero value of the type of the provider, so the return value can always
190 // be type asserted to the type of the provider. It panics if called before the appropriate
191 // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
192 // copy of the value originally passed to SetProvider.
193 Provider(provider blueprint.ProviderKey) interface{}
194
195 // HasProvider returns true if the provider for the current module has been set.
196 HasProvider(provider blueprint.ProviderKey) bool
197
198 // SetProvider sets the value for a provider for the current module. It panics if not called
199 // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
200 // is not of the appropriate type, or if the value has already been set. The value should not
201 // be modified after being passed to SetProvider.
202 SetProvider(provider blueprint.ProviderKey, value interface{})
203
Colin Crossdc35e212019-06-06 16:13:11 -0700204 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700205
206 // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
207 // none exists. It panics if the dependency does not have the specified tag. It skips any
208 // dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700209 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700210
211 // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
212 // name, or nil if none exists. If there are multiple dependencies on the same module it returns
213 // the first DependencyTag. It skips any dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700214 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
215
Colin Cross9f35c3d2020-09-16 19:04:41 -0700216 // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
217 // direct dependencies on the same module visit will be called multiple times on that module
218 // and OtherModuleDependencyTag will return a different tag for each.
219 //
220 // The Module passed to the visit function should not be retained outside of the visit
221 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700222 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700223
224 // VisitDirectDeps calls visit for each direct dependency. If there are multiple
225 // direct dependencies on the same module visit will be called multiple times on that module
226 // and OtherModuleDependencyTag will return a different tag for each. It skips any
227 // dependencies that are not an android.Module.
228 //
229 // The Module passed to the visit function should not be retained outside of the visit
230 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700231 VisitDirectDeps(visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700232
Colin Crossdc35e212019-06-06 16:13:11 -0700233 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700234
235 // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
236 // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
237 // OtherModuleDependencyTag will return a different tag for each. It skips any
238 // dependencies that are not an android.Module.
239 //
240 // The Module passed to the visit function should not be retained outside of the visit function, it may be
241 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700242 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
243 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
244 VisitDepsDepthFirst(visit func(Module))
245 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
246 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700247
248 // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
249 // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
250 // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
251 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
252 // any dependencies that are not an android.Module.
253 //
254 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
255 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700256 WalkDeps(visit func(Module, Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700257
258 // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
259 // tree in top down order. visit may be called multiple times for the same (child, parent)
260 // pair if there are multiple direct dependencies between the child and parent with different
261 // tags. OtherModuleDependencyTag will return the tag for the currently visited
262 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
263 // to child.
264 //
265 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
266 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700267 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700268
Colin Crossdc35e212019-06-06 16:13:11 -0700269 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
270 // and returns a top-down dependency path from a start module to current child module.
271 GetWalkPath() []Module
272
Colin Cross4dfacf92020-09-16 19:22:27 -0700273 // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
274 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
275 // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
276 // only done once for all variants of a module.
277 PrimaryModule() Module
278
279 // FinalModule returns the last variant of the current module. Variants of a module are always visited in
280 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
281 // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
282 // singleton actions that are only done once for all variants of a module.
283 FinalModule() Module
284
285 // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
286 // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
287 // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
288 // data modified by the current mutator.
289 VisitAllModuleVariants(visit func(Module))
290
Paul Duffinc5192442020-03-31 11:31:36 +0100291 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
292 // and returns a top-down dependency tags path from a start module to current child module.
293 // It has one less entry than GetWalkPath() as it contains the dependency tags that
294 // exist between each adjacent pair of modules in the GetWalkPath().
295 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
296 GetTagPath() []blueprint.DependencyTag
297
Jiyong Park1c7e9622020-05-07 16:12:13 +0900298 // GetPathString is supposed to be called in visit function passed in WalkDeps()
299 // and returns a multi-line string showing the modules and dependency tags
300 // among them along the top-down dependency path from a start module to current child module.
301 // skipFirst when set to true, the output doesn't include the start module,
302 // which is already printed when this function is used along with ModuleErrorf().
303 GetPathString(skipFirst bool) string
304
Colin Crossdc35e212019-06-06 16:13:11 -0700305 AddMissingDependencies(missingDeps []string)
306
Colin Crossa1ad8d12016-06-01 17:09:44 -0700307 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700308 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000309
310 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
311 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700312 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700313 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700314 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700315 Host() bool
316 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700317 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800318 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700319 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700320 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700321 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700322}
323
Colin Cross1184b642019-12-30 18:43:07 -0800324// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700325type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800326 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800327}
328
Colin Cross635c3b02016-05-18 15:37:25 -0700329type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800330 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800331
Colin Crossae887032017-10-23 17:16:14 -0700332 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800333 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700334
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700335 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800336 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800337 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700338
Colin Cross70dda7e2019-10-01 22:05:35 -0700339 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
340 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
341 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
342 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700343 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800344
Colin Cross8d8f8e22016-08-03 11:57:50 -0700345 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700346 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700347 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800348 InstallInRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900349 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700350 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700351 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900352 InstallForceOS() (*OsType, *ArchType)
Nan Zhang6d34b302017-02-04 17:47:46 -0800353
354 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700355 HostRequiredModuleNames() []string
356 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700357
Colin Cross3f68a132017-10-23 17:10:29 -0700358 ModuleSubDir() string
359
Colin Cross0875c522017-11-28 17:34:01 -0800360 Variable(pctx PackageContext, name, value string)
361 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700362 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
363 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800364 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700365 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
366 // phony rules or real files. Phony can be called on the same name multiple times to add
367 // additional dependencies.
368 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700369
Colin Cross9f35c3d2020-09-16 19:04:41 -0700370 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
371 // but do not exist.
Colin Cross3f68a132017-10-23 17:10:29 -0700372 GetMissingDependencies() []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800373}
374
Colin Cross635c3b02016-05-18 15:37:25 -0700375type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800376 blueprint.Module
377
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700378 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
379 // but GenerateAndroidBuildActions also has access to Android-specific information.
380 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700381 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700382
Paul Duffin44f1d842020-06-26 20:17:02 +0100383 // Add dependencies to the components of a module, i.e. modules that are created
384 // by the module and which are considered to be part of the creating module.
385 //
386 // This is called before prebuilts are renamed so as to allow a dependency to be
387 // added directly to a prebuilt child module instead of depending on a source module
388 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
389 //
390 // A dependency on a prebuilt must include the "prebuilt_" prefix.
391 ComponentDepsMutator(ctx BottomUpMutatorContext)
392
Colin Cross1e676be2016-10-12 14:38:15 -0700393 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800394
Colin Cross635c3b02016-05-18 15:37:25 -0700395 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900396 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800397 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700398 Target() Target
Anton Hansson1ee62c02020-06-30 11:51:53 +0100399 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -0800400 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700401 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700402 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800403 InstallInRamdisk() 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)
Colin Crossa2f296f2016-11-29 15:16:18 -0800408 SkipInstall()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000409 IsSkipInstall() bool
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100410 MakeUninstallable()
Jiyong Park374510b2018-03-19 18:23:01 +0900411 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900412 InitRc() Paths
413 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800414 NoticeFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700415
416 AddProperties(props ...interface{})
417 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700418
Colin Crossae887032017-10-23 17:16:14 -0700419 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800420 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800421 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100422
Colin Cross9a362232019-07-01 15:32:45 -0700423 // String returns a string that includes the module name and variants for printing during debugging.
424 String() string
425
Paul Duffine2453c72019-05-31 14:00:04 +0100426 // Get the qualified module id for this module.
427 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
428
429 // Get information about the properties that can contain visibility rules.
430 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100431
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900432 RequiredModuleNames() []string
433 HostRequiredModuleNames() []string
434 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800435
436 filesToInstall() InstallPaths
Paul Duffine2453c72019-05-31 14:00:04 +0100437}
438
439// Qualified id for a module
440type qualifiedModuleName struct {
441 // The package (i.e. directory) in which the module is defined, without trailing /
442 pkg string
443
444 // The name of the module, empty string if package.
445 name string
446}
447
448func (q qualifiedModuleName) String() string {
449 if q.name == "" {
450 return "//" + q.pkg
451 }
452 return "//" + q.pkg + ":" + q.name
453}
454
Paul Duffine484f472019-06-20 16:38:08 +0100455func (q qualifiedModuleName) isRootPackage() bool {
456 return q.pkg == "" && q.name == ""
457}
458
Paul Duffine2453c72019-05-31 14:00:04 +0100459// Get the id for the package containing this module.
460func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
461 pkg := q.pkg
462 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100463 if pkg == "" {
464 panic(fmt.Errorf("Cannot get containing package id of root package"))
465 }
466
467 index := strings.LastIndex(pkg, "/")
468 if index == -1 {
469 pkg = ""
470 } else {
471 pkg = pkg[:index]
472 }
Paul Duffine2453c72019-05-31 14:00:04 +0100473 }
474 return newPackageId(pkg)
475}
476
477func newPackageId(pkg string) qualifiedModuleName {
478 // A qualified id for a package module has no name.
479 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800480}
481
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000482type Dist struct {
483 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
484 // command line and any of these targets are also on the command line, or otherwise
485 // built
486 Targets []string `android:"arch_variant"`
487
488 // The name of the output artifact. This defaults to the basename of the output of
489 // the module.
490 Dest *string `android:"arch_variant"`
491
492 // The directory within the dist directory to store the artifact. Defaults to the
493 // top level directory ("").
494 Dir *string `android:"arch_variant"`
495
496 // A suffix to add to the artifact file name (before any extension).
497 Suffix *string `android:"arch_variant"`
498
499 // A string tag to select the OutputFiles associated with the tag. Defaults to the
500 // the empty "" string.
501 Tag *string `android:"arch_variant"`
502}
503
Colin Crossfc754582016-05-17 16:34:16 -0700504type nameProperties struct {
505 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800506 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700507}
508
509type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800510 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000511 //
512 // Disabling a module should only be done for those modules that cannot be built
513 // in the current environment. Modules that can build in the current environment
514 // but are not usually required (e.g. superceded by a prebuilt) should not be
515 // disabled as that will prevent them from being built by the checkbuild target
516 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800517 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800518
Paul Duffin2e61fa62019-03-28 14:10:57 +0000519 // Controls the visibility of this module to other modules. Allowable values are one or more of
520 // these formats:
521 //
522 // ["//visibility:public"]: Anyone can use this module.
523 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
524 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100525 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
526 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000527 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
528 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
529 // this module. Note that sub-packages do not have access to the rule; for example,
530 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
531 // is a special module and must be used verbatim. It represents all of the modules in the
532 // package.
533 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
534 // or other or in one of their sub-packages have access to this module. For example,
535 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
536 // to depend on this rule (but not //independent:evil)
537 // ["//project"]: This is shorthand for ["//project:__pkg__"]
538 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
539 // //project is the module's package. e.g. using [":__subpackages__"] in
540 // packages/apps/Settings/Android.bp is equivalent to
541 // //packages/apps/Settings:__subpackages__.
542 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
543 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100544 //
545 // If a module does not specify the `visibility` property then it uses the
546 // `default_visibility` property of the `package` module in the module's package.
547 //
548 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100549 // it will use the `default_visibility` of its closest ancestor package for which
550 // a `default_visibility` property is specified.
551 //
552 // If no `default_visibility` property can be found then the module uses the
553 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100554 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100555 // The `visibility` property has no effect on a defaults module although it does
556 // apply to any non-defaults module that uses it. To set the visibility of a
557 // defaults module, use the `defaults_visibility` property on the defaults module;
558 // not to be confused with the `default_visibility` property on the package module.
559 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000560 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
561 // more details.
562 Visibility []string
563
Colin Cross7d5136f2015-05-11 13:39:40 -0700564 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800565 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
566 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
567 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700568 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700569
570 Target struct {
571 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700572 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700573 }
574 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700575 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700576 }
577 }
578
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000579 // If set to true then the archMutator will create variants for each arch specific target
580 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
581 // create a variant for the architecture and will list the additional arch specific targets
582 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700583 UseTargetVariants bool `blueprint:"mutated"`
584 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800585
Dan Willemsen782a2d12015-12-21 14:55:28 -0800586 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700587 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800588
Colin Cross55708f32017-03-20 13:23:34 -0700589 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700590 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700591
Jiyong Park2db76922017-11-08 16:03:48 +0900592 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
593 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
594 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700595 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700596
Jiyong Park2db76922017-11-08 16:03:48 +0900597 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
598 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
599 Soc_specific *bool
600
601 // whether this module is specific to a device, not only for SoC, but also for off-chip
602 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
603 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
604 // This implies `soc_specific:true`.
605 Device_specific *bool
606
607 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900608 // network operator, etc). When set to true, it is installed into /product (or
609 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900610 Product_specific *bool
611
Justin Yund5f6c822019-06-25 16:47:17 +0900612 // whether this module extends system. When set to true, it is installed into /system_ext
613 // (or /system/system_ext if system_ext partition does not exist).
614 System_ext_specific *bool
615
Jiyong Parkf9332f12018-02-01 00:54:12 +0900616 // Whether this module is installed to recovery partition
617 Recovery *bool
618
Yifan Hong1b3348d2020-01-21 15:53:22 -0800619 // Whether this module is installed to ramdisk
620 Ramdisk *bool
621
dimitry1f33e402019-03-26 12:39:31 +0100622 // Whether this module is built for non-native architecures (also known as native bridge binary)
623 Native_bridge_supported *bool `android:"arch_variant"`
624
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700625 // init.rc files to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800626 Init_rc []string `android:"path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700627
Steven Moreland57a23d22018-04-04 15:42:19 -0700628 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800629 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700630
Chris Wolfe998306e2016-08-15 14:47:23 -0400631 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700632 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400633
Sasha Smundakb6d23052019-04-01 18:37:36 -0700634 // names of other modules to install on host if this module is installed
635 Host_required []string `android:"arch_variant"`
636
637 // names of other modules to install on target if this module is installed
638 Target_required []string `android:"arch_variant"`
639
Colin Cross5aac3622017-08-31 15:07:09 -0700640 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800641 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700642
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000643 // The OsType of artifacts that this module variant is responsible for creating.
644 //
645 // Set by osMutator
646 CompileOS OsType `blueprint:"mutated"`
647
648 // The Target of artifacts that this module variant is responsible for creating.
649 //
650 // Set by archMutator
651 CompileTarget Target `blueprint:"mutated"`
652
653 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
654 // responsible for creating.
655 //
656 // By default this is nil as, where necessary, separate variants are created for the
657 // different multilib types supported and that information is encapsulated in the
658 // CompileTarget so the module variant simply needs to create artifacts for that.
659 //
660 // However, if UseTargetVariants is set to false (e.g. by
661 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
662 // multilib targets. Instead a single variant is created for the architecture and
663 // this contains the multilib specific targets that this variant should create.
664 //
665 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700666 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000667
668 // True if the module variant's CompileTarget is the primary target
669 //
670 // Set by archMutator
671 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800672
673 // Set by InitAndroidModule
674 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700675 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700676
Paul Duffin1356d8c2020-02-25 19:26:33 +0000677 // If set to true then a CommonOS variant will be created which will have dependencies
678 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
679 // that covers all os and architecture variants.
680 //
681 // The OsType specific variants can be retrieved by calling
682 // GetOsSpecificVariantsOfCommonOSVariant
683 //
684 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
685 CreateCommonOSVariant bool `blueprint:"mutated"`
686
687 // If set to true then this variant is the CommonOS variant that has dependencies on its
688 // OsType specific variants.
689 //
690 // Set by osMutator.
691 CommonOSVariant bool `blueprint:"mutated"`
692
Colin Crossce75d2c2016-10-06 16:12:58 -0700693 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800694
Justin Yun32f053b2020-07-31 23:07:17 +0900695 // Disabled by mutators. If set to true, it overrides Enabled property.
696 ForcedDisabled bool `blueprint:"mutated"`
697
Jeff Gaston088e29e2017-11-29 16:47:17 -0800698 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700699
700 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700701
702 // Name and variant strings stored by mutators to enable Module.String()
703 DebugName string `blueprint:"mutated"`
704 DebugMutators []string `blueprint:"mutated"`
705 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800706
707 // set by ImageMutator
708 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800709}
710
Paul Duffined875132020-09-02 13:08:57 +0100711type distProperties struct {
712 // configuration to distribute output files from this module to the distribution
713 // directory (default: $OUT/dist, configurable with $DIST_DIR)
714 Dist Dist `android:"arch_variant"`
715
716 // a list of configurations to distribute output files from this module to the
717 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
718 Dists []Dist `android:"arch_variant"`
719}
720
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000721// A map of OutputFile tag keys to Paths, for disting purposes.
722type TaggedDistFiles map[string]Paths
723
724func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000725 for _, path := range paths {
726 if path == nil {
727 panic("The path to a dist file cannot be nil.")
728 }
729 }
730
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000731 // The default OutputFile tag is the empty "" string.
732 return TaggedDistFiles{"": paths}
733}
734
Colin Cross3f40fa42015-01-30 17:27:36 -0800735type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800736 // If set to true, build a variant of the module for the host. Defaults to false.
737 Host_supported *bool
738
739 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700740 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800741}
742
Colin Crossc472d572015-03-17 15:06:21 -0700743type Multilib string
744
745const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800746 MultilibBoth Multilib = "both"
747 MultilibFirst Multilib = "first"
748 MultilibCommon Multilib = "common"
749 MultilibCommonFirst Multilib = "common_first"
750 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700751)
752
Colin Crossa1ad8d12016-06-01 17:09:44 -0700753type HostOrDeviceSupported int
754
755const (
756 _ HostOrDeviceSupported = iota
Dan Albert0981b5c2018-08-02 13:46:35 -0700757
758 // Host and HostCross are built by default. Device is not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700759 HostSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700760
761 // Host is built by default. HostCross and Device are not supported.
Dan Albertc6345fb2016-10-20 01:36:11 -0700762 HostSupportedNoCross
Dan Albert0981b5c2018-08-02 13:46:35 -0700763
764 // Device is built by default. Host and HostCross are not supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700765 DeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700766
767 // Device is built by default. Host and HostCross are supported.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700768 HostAndDeviceSupported
Dan Albert0981b5c2018-08-02 13:46:35 -0700769
770 // Host, HostCross, and Device are built by default.
Colin Crossa1ad8d12016-06-01 17:09:44 -0700771 HostAndDeviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700772
773 // Nothing is supported. This is not exposed to the user, but used to mark a
774 // host only module as unsupported when the module type is not supported on
775 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Dan Willemsen0b24c742016-10-04 15:13:37 -0700776 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700777)
778
Jiyong Park2db76922017-11-08 16:03:48 +0900779type moduleKind int
780
781const (
782 platformModule moduleKind = iota
783 deviceSpecificModule
784 socSpecificModule
785 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900786 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900787)
788
789func (k moduleKind) String() string {
790 switch k {
791 case platformModule:
792 return "platform"
793 case deviceSpecificModule:
794 return "device-specific"
795 case socSpecificModule:
796 return "soc-specific"
797 case productSpecificModule:
798 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900799 case systemExtSpecificModule:
800 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900801 default:
802 panic(fmt.Errorf("unknown module kind %d", k))
803 }
804}
805
Colin Cross9d34f352019-11-22 16:03:51 -0800806func initAndroidModuleBase(m Module) {
807 m.base().module = m
808}
809
Colin Cross36242852017-06-23 15:06:31 -0700810func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800811 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800812 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700813
Colin Cross36242852017-06-23 15:06:31 -0700814 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700815 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +0100816 &base.commonProperties,
817 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -0700818
Colin Crosseabaedd2020-02-06 17:01:55 -0800819 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700820
Colin Crossa3a97412019-03-18 12:24:29 -0700821 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700822 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100823
824 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +0100825 // its checking and parsing phases so make it the primary visibility property.
826 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Colin Cross5049f022015-03-18 13:28:46 -0700827}
828
Colin Cross36242852017-06-23 15:06:31 -0700829func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
830 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700831
832 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800833 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700834 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700835 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700836 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800837
Dan Willemsen218f6562015-07-08 18:13:11 -0700838 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700839 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700840 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800841 }
842
Colin Cross36242852017-06-23 15:06:31 -0700843 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800844}
845
Colin Crossee0bc3b2018-10-02 22:01:37 -0700846func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
847 InitAndroidArchModule(m, hod, defaultMultilib)
848 m.base().commonProperties.UseTargetVariants = false
849}
850
Paul Duffin1356d8c2020-02-25 19:26:33 +0000851// As InitAndroidMultiTargetsArchModule except it creates an additional CommonOS variant that
852// has dependencies on all the OsType specific variants.
853func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
854 InitAndroidArchModule(m, hod, defaultMultilib)
855 m.base().commonProperties.UseTargetVariants = false
856 m.base().commonProperties.CreateCommonOSVariant = true
857}
858
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800859// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800860// modules. It should be included as an anonymous field in every module
861// struct definition. InitAndroidModule should then be called from the module's
862// factory function, and the return values from InitAndroidModule should be
863// returned from the factory function.
864//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800865// The ModuleBase type is responsible for implementing the GenerateBuildActions
866// method to support the blueprint.Module interface. This method will then call
867// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700868// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
869// rather than the usual blueprint.ModuleContext.
870// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800871// system including details about the particular build variant that is to be
872// generated.
873//
874// For example:
875//
876// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800877// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800878// )
879//
880// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800881// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800882// properties struct {
883// MyProperty string
884// }
885// }
886//
Colin Cross36242852017-06-23 15:06:31 -0700887// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800888// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700889// m.AddProperties(&m.properties)
890// android.InitAndroidModule(m)
891// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800892// }
893//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800894// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800895// // Get the CPU architecture for the current build variant.
896// variantArch := ctx.Arch()
897//
898// // ...
899// }
Colin Cross635c3b02016-05-18 15:37:25 -0700900type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800901 // Putting the curiously recurring thing pointing to the thing that contains
902 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700903 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700904 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800905
Colin Crossfc754582016-05-17 16:34:16 -0700906 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800907 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +0100908 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -0700909 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800910 hostAndDeviceProperties hostAndDeviceProperties
911 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -0700912 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700913 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800914
Paul Duffin63c6e182019-07-24 14:24:38 +0100915 // Information about all the properties on the module that contains visibility rules that need
916 // checking.
917 visibilityPropertyInfo []visibilityProperty
918
919 // The primary visibility property, may be nil, that controls access to the module.
920 primaryVisibilityProperty visibilityProperty
921
Colin Cross3f40fa42015-01-30 17:27:36 -0800922 noAddressSanitizer bool
Colin Cross897266e2020-02-13 13:22:08 -0800923 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700924 checkbuildFiles Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800925 noticeFiles Paths
Colin Crossc3d87d32020-06-04 13:25:17 -0700926 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -0700927
928 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
929 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800930 installTarget WritablePath
931 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700932 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700933
Colin Cross178a5092016-09-13 13:42:32 -0700934 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700935
936 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700937
938 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700939 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800940 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800941 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -0700942
Inseob Kim8471cda2019-11-15 09:59:12 +0900943 initRcPaths Paths
944 vintfFragmentsPaths Paths
945
Colin Crossa9d8bee2018-10-02 13:59:46 -0700946 prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
Colin Cross36242852017-06-23 15:06:31 -0700947}
948
Paul Duffin44f1d842020-06-26 20:17:02 +0100949func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
950
Colin Cross4157e882019-06-06 16:57:04 -0700951func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -0800952
Colin Cross4157e882019-06-06 16:57:04 -0700953func (m *ModuleBase) AddProperties(props ...interface{}) {
954 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -0700955}
956
Colin Cross4157e882019-06-06 16:57:04 -0700957func (m *ModuleBase) GetProperties() []interface{} {
958 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800959}
960
Colin Cross4157e882019-06-06 16:57:04 -0700961func (m *ModuleBase) BuildParamsForTests() []BuildParams {
962 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -0700963}
964
Colin Cross4157e882019-06-06 16:57:04 -0700965func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
966 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800967}
968
Colin Cross4157e882019-06-06 16:57:04 -0700969func (m *ModuleBase) VariablesForTests() map[string]string {
970 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800971}
972
Colin Cross4157e882019-06-06 16:57:04 -0700973func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
974 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -0700975}
976
Colin Crossce75d2c2016-10-06 16:12:58 -0700977// Name returns the name of the module. It may be overridden by individual module types, for
978// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -0700979func (m *ModuleBase) Name() string {
980 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700981}
982
Colin Cross9a362232019-07-01 15:32:45 -0700983// String returns a string that includes the module name and variants for printing during debugging.
984func (m *ModuleBase) String() string {
985 sb := strings.Builder{}
986 sb.WriteString(m.commonProperties.DebugName)
987 sb.WriteString("{")
988 for i := range m.commonProperties.DebugMutators {
989 if i != 0 {
990 sb.WriteString(",")
991 }
992 sb.WriteString(m.commonProperties.DebugMutators[i])
993 sb.WriteString(":")
994 sb.WriteString(m.commonProperties.DebugVariations[i])
995 }
996 sb.WriteString("}")
997 return sb.String()
998}
999
Colin Crossce75d2c2016-10-06 16:12:58 -07001000// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001001func (m *ModuleBase) BaseModuleName() string {
1002 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001003}
1004
Colin Cross4157e882019-06-06 16:57:04 -07001005func (m *ModuleBase) base() *ModuleBase {
1006 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001007}
1008
Paul Duffine2453c72019-05-31 14:00:04 +01001009func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1010 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1011}
1012
1013func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001014 return m.visibilityPropertyInfo
1015}
1016
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001017func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001018 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001019 // Make a copy of the underlying Dists slice to protect against
1020 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001021 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1022 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001023 } else {
Paul Duffined875132020-09-02 13:08:57 +01001024 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001025 }
1026}
1027
1028func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
1029 distFiles := make(TaggedDistFiles)
1030 for _, dist := range m.Dists() {
1031 var tag string
1032 var distFilesForTag Paths
1033 if dist.Tag == nil {
1034 tag = ""
1035 } else {
1036 tag = *dist.Tag
1037 }
1038 distFilesForTag, err := m.base().module.(OutputFileProducer).OutputFiles(tag)
1039 if err != nil {
1040 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1041 }
1042 for _, distFile := range distFilesForTag {
1043 if distFile != nil && !distFiles[tag].containsPath(distFile) {
1044 distFiles[tag] = append(distFiles[tag], distFile)
1045 }
1046 }
1047 }
1048
1049 return distFiles
1050}
1051
Colin Cross4157e882019-06-06 16:57:04 -07001052func (m *ModuleBase) Target() Target {
1053 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001054}
1055
Colin Cross4157e882019-06-06 16:57:04 -07001056func (m *ModuleBase) TargetPrimary() bool {
1057 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001058}
1059
Colin Cross4157e882019-06-06 16:57:04 -07001060func (m *ModuleBase) MultiTargets() []Target {
1061 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001062}
1063
Colin Cross4157e882019-06-06 16:57:04 -07001064func (m *ModuleBase) Os() OsType {
1065 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001066}
1067
Colin Cross4157e882019-06-06 16:57:04 -07001068func (m *ModuleBase) Host() bool {
1069 return m.Os().Class == Host || m.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -08001070}
1071
Yo Chiangbba545e2020-06-09 16:15:37 +08001072func (m *ModuleBase) Device() bool {
1073 return m.Os().Class == Device
1074}
1075
Colin Cross4157e882019-06-06 16:57:04 -07001076func (m *ModuleBase) Arch() Arch {
1077 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001078}
1079
Colin Cross4157e882019-06-06 16:57:04 -07001080func (m *ModuleBase) ArchSpecific() bool {
1081 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001082}
1083
Paul Duffin1356d8c2020-02-25 19:26:33 +00001084// True if the current variant is a CommonOS variant, false otherwise.
1085func (m *ModuleBase) IsCommonOSVariant() bool {
1086 return m.commonProperties.CommonOSVariant
1087}
1088
Colin Cross4157e882019-06-06 16:57:04 -07001089func (m *ModuleBase) OsClassSupported() []OsClass {
1090 switch m.commonProperties.HostOrDeviceSupported {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001091 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -07001092 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -07001093 case HostSupportedNoCross:
1094 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -07001095 case DeviceSupported:
1096 return []OsClass{Device}
Dan Albert0981b5c2018-08-02 13:46:35 -07001097 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Crossa1ad8d12016-06-01 17:09:44 -07001098 var supported []OsClass
Colin Cross4157e882019-06-06 16:57:04 -07001099 if Bool(m.hostAndDeviceProperties.Host_supported) ||
1100 (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
1101 m.hostAndDeviceProperties.Host_supported == nil) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001102 supported = append(supported, Host, HostCross)
1103 }
Colin Cross4157e882019-06-06 16:57:04 -07001104 if m.hostAndDeviceProperties.Device_supported == nil ||
1105 *m.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001106 supported = append(supported, Device)
1107 }
1108 return supported
1109 default:
1110 return nil
1111 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001112}
1113
Colin Cross4157e882019-06-06 16:57:04 -07001114func (m *ModuleBase) DeviceSupported() bool {
1115 return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
1116 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
1117 (m.hostAndDeviceProperties.Device_supported == nil ||
1118 *m.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -08001119}
1120
Paul Duffine44358f2019-11-26 18:04:12 +00001121func (m *ModuleBase) HostSupported() bool {
1122 return m.commonProperties.HostOrDeviceSupported == HostSupported ||
1123 m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
1124 (m.hostAndDeviceProperties.Host_supported != nil &&
1125 *m.hostAndDeviceProperties.Host_supported)
1126}
1127
Colin Cross4157e882019-06-06 16:57:04 -07001128func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001129 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001130}
1131
Colin Cross4157e882019-06-06 16:57:04 -07001132func (m *ModuleBase) DeviceSpecific() bool {
1133 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001134}
1135
Colin Cross4157e882019-06-06 16:57:04 -07001136func (m *ModuleBase) SocSpecific() bool {
1137 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001138}
1139
Colin Cross4157e882019-06-06 16:57:04 -07001140func (m *ModuleBase) ProductSpecific() bool {
1141 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001142}
1143
Justin Yund5f6c822019-06-25 16:47:17 +09001144func (m *ModuleBase) SystemExtSpecific() bool {
1145 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001146}
1147
Colin Crossc2d24052020-05-13 11:05:02 -07001148// RequiresStableAPIs returns true if the module will be installed to a partition that may
1149// be updated separately from the system image.
1150func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1151 return m.SocSpecific() || m.DeviceSpecific() ||
1152 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1153}
1154
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001155func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1156 partition := "system"
1157 if m.SocSpecific() {
1158 // A SoC-specific module could be on the vendor partition at
1159 // "vendor" or the system partition at "system/vendor".
1160 if config.VendorPath() == "vendor" {
1161 partition = "vendor"
1162 }
1163 } else if m.DeviceSpecific() {
1164 // A device-specific module could be on the odm partition at
1165 // "odm", the vendor partition at "vendor/odm", or the system
1166 // partition at "system/vendor/odm".
1167 if config.OdmPath() == "odm" {
1168 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001169 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001170 partition = "vendor"
1171 }
1172 } else if m.ProductSpecific() {
1173 // A product-specific module could be on the product partition
1174 // at "product" or the system partition at "system/product".
1175 if config.ProductPath() == "product" {
1176 partition = "product"
1177 }
1178 } else if m.SystemExtSpecific() {
1179 // A system_ext-specific module could be on the system_ext
1180 // partition at "system_ext" or the system partition at
1181 // "system/system_ext".
1182 if config.SystemExtPath() == "system_ext" {
1183 partition = "system_ext"
1184 }
1185 }
1186 return partition
1187}
1188
Colin Cross4157e882019-06-06 16:57:04 -07001189func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001190 if m.commonProperties.ForcedDisabled {
1191 return false
1192 }
Colin Cross4157e882019-06-06 16:57:04 -07001193 if m.commonProperties.Enabled == nil {
1194 return !m.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -08001195 }
Colin Cross4157e882019-06-06 16:57:04 -07001196 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001197}
1198
Inseob Kimeec88e12020-01-22 11:11:29 +09001199func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001200 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001201}
1202
Colin Cross4157e882019-06-06 16:57:04 -07001203func (m *ModuleBase) SkipInstall() {
1204 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001205}
1206
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00001207func (m *ModuleBase) IsSkipInstall() bool {
1208 return m.commonProperties.SkipInstall == true
1209}
1210
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001211// Similar to SkipInstall, but if the AndroidMk entry would set
1212// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1213// rather than leaving it out altogether. That happens in cases where it would
1214// have other side effects, in particular when it adds a NOTICE file target,
1215// which other install targets might depend on.
1216func (m *ModuleBase) MakeUninstallable() {
1217 m.SkipInstall()
1218}
1219
Colin Cross4157e882019-06-06 16:57:04 -07001220func (m *ModuleBase) ExportedToMake() bool {
1221 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001222}
1223
Colin Cross897266e2020-02-13 13:22:08 -08001224func (m *ModuleBase) computeInstallDeps(ctx blueprint.ModuleContext) InstallPaths {
Colin Cross3f40fa42015-01-30 17:27:36 -08001225
Colin Cross897266e2020-02-13 13:22:08 -08001226 var result InstallPaths
Colin Cross6b753602018-06-21 13:03:07 -07001227 // TODO(ccross): we need to use WalkDeps and have some way to know which dependencies require installation
Colin Cross897266e2020-02-13 13:22:08 -08001228 ctx.VisitDepsDepthFirst(func(m blueprint.Module) {
1229 if a, ok := m.(Module); ok {
1230 result = append(result, a.filesToInstall()...)
1231 }
1232 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001233
1234 return result
1235}
1236
Colin Cross897266e2020-02-13 13:22:08 -08001237func (m *ModuleBase) filesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001238 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001239}
1240
Colin Cross4157e882019-06-06 16:57:04 -07001241func (m *ModuleBase) NoAddressSanitizer() bool {
1242 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001243}
1244
Colin Cross4157e882019-06-06 16:57:04 -07001245func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001246 return false
1247}
1248
Jaewoong Jung0949f312019-09-11 10:25:18 -07001249func (m *ModuleBase) InstallInTestcases() bool {
1250 return false
1251}
1252
Colin Cross4157e882019-06-06 16:57:04 -07001253func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001254 return false
1255}
1256
Yifan Hong1b3348d2020-01-21 15:53:22 -08001257func (m *ModuleBase) InstallInRamdisk() bool {
1258 return Bool(m.commonProperties.Ramdisk)
1259}
1260
Colin Cross4157e882019-06-06 16:57:04 -07001261func (m *ModuleBase) InstallInRecovery() bool {
1262 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001263}
1264
Colin Cross90ba5f42019-10-02 11:10:58 -07001265func (m *ModuleBase) InstallInRoot() bool {
1266 return false
1267}
1268
Colin Cross607d8582019-07-29 16:44:46 -07001269func (m *ModuleBase) InstallBypassMake() bool {
1270 return false
1271}
1272
Jiyong Park87788b52020-09-01 12:37:45 +09001273func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
1274 return nil, nil
Colin Cross6e359402020-02-10 15:29:54 -08001275}
1276
Colin Cross4157e882019-06-06 16:57:04 -07001277func (m *ModuleBase) Owner() string {
1278 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001279}
1280
Bob Badoura75b0572020-02-18 20:21:55 -08001281func (m *ModuleBase) NoticeFiles() Paths {
1282 return m.noticeFiles
Jiyong Park52818fc2019-03-18 12:01:38 +09001283}
1284
Colin Cross7228ecd2019-11-18 16:00:16 -08001285func (m *ModuleBase) setImageVariation(variant string) {
1286 m.commonProperties.ImageVariation = variant
1287}
1288
1289func (m *ModuleBase) ImageVariation() blueprint.Variation {
1290 return blueprint.Variation{
1291 Mutator: "image",
1292 Variation: m.base().commonProperties.ImageVariation,
1293 }
1294}
1295
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001296func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1297 for i, v := range m.commonProperties.DebugMutators {
1298 if v == mutator {
1299 return m.commonProperties.DebugVariations[i]
1300 }
1301 }
1302
1303 return ""
1304}
1305
Yifan Hong1b3348d2020-01-21 15:53:22 -08001306func (m *ModuleBase) InRamdisk() bool {
1307 return m.base().commonProperties.ImageVariation == RamdiskVariation
1308}
1309
Colin Cross7228ecd2019-11-18 16:00:16 -08001310func (m *ModuleBase) InRecovery() bool {
1311 return m.base().commonProperties.ImageVariation == RecoveryVariation
1312}
1313
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001314func (m *ModuleBase) RequiredModuleNames() []string {
1315 return m.base().commonProperties.Required
1316}
1317
1318func (m *ModuleBase) HostRequiredModuleNames() []string {
1319 return m.base().commonProperties.Host_required
1320}
1321
1322func (m *ModuleBase) TargetRequiredModuleNames() []string {
1323 return m.base().commonProperties.Target_required
1324}
1325
Inseob Kim8471cda2019-11-15 09:59:12 +09001326func (m *ModuleBase) InitRc() Paths {
1327 return append(Paths{}, m.initRcPaths...)
1328}
1329
1330func (m *ModuleBase) VintfFragments() Paths {
1331 return append(Paths{}, m.vintfFragmentsPaths...)
1332}
1333
Colin Cross4157e882019-06-06 16:57:04 -07001334func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001335 var allInstalledFiles InstallPaths
1336 var allCheckbuildFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001337 ctx.VisitAllModuleVariants(func(module Module) {
1338 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001339 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1340 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001341 })
1342
Colin Cross0875c522017-11-28 17:34:01 -08001343 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001344
Colin Cross133ebef2020-08-14 17:38:45 -07001345 namespacePrefix := ctx.Namespace().id
Jeff Gaston088e29e2017-11-29 16:47:17 -08001346 if namespacePrefix != "" {
1347 namespacePrefix = namespacePrefix + "-"
1348 }
1349
Colin Cross3f40fa42015-01-30 17:27:36 -08001350 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001351 name := namespacePrefix + ctx.ModuleName() + "-install"
1352 ctx.Phony(name, allInstalledFiles.Paths()...)
1353 m.installTarget = PathForPhony(ctx, name)
1354 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001355 }
1356
1357 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001358 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1359 ctx.Phony(name, allCheckbuildFiles...)
1360 m.checkbuildTarget = PathForPhony(ctx, name)
1361 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001362 }
1363
1364 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001365 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001366 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001367 suffix = "-soong"
1368 }
1369
Colin Crossc3d87d32020-06-04 13:25:17 -07001370 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001371
Colin Cross4157e882019-06-06 16:57:04 -07001372 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001373 }
1374}
1375
Colin Crossc34d2322020-01-03 15:23:27 -08001376func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001377 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1378 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1379 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001380 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001381
Dario Frenifd05a742018-05-29 13:28:54 +01001382 msg := "conflicting value set here"
1383 if socSpecific && deviceSpecific {
1384 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001385 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001386 ctx.PropertyErrorf("vendor", msg)
1387 }
Colin Cross4157e882019-06-06 16:57:04 -07001388 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001389 ctx.PropertyErrorf("proprietary", msg)
1390 }
Colin Cross4157e882019-06-06 16:57:04 -07001391 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001392 ctx.PropertyErrorf("soc_specific", msg)
1393 }
1394 }
1395
Justin Yund5f6c822019-06-25 16:47:17 +09001396 if productSpecific && systemExtSpecific {
1397 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1398 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001399 }
1400
Justin Yund5f6c822019-06-25 16:47:17 +09001401 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001402 if productSpecific {
1403 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1404 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001405 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 +01001406 }
1407 if deviceSpecific {
1408 ctx.PropertyErrorf("device_specific", msg)
1409 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001410 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001411 ctx.PropertyErrorf("vendor", msg)
1412 }
Colin Cross4157e882019-06-06 16:57:04 -07001413 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001414 ctx.PropertyErrorf("proprietary", msg)
1415 }
Colin Cross4157e882019-06-06 16:57:04 -07001416 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001417 ctx.PropertyErrorf("soc_specific", msg)
1418 }
1419 }
1420 }
1421
Jiyong Park2db76922017-11-08 16:03:48 +09001422 if productSpecific {
1423 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001424 } else if systemExtSpecific {
1425 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001426 } else if deviceSpecific {
1427 return deviceSpecificModule
1428 } else if socSpecific {
1429 return socSpecificModule
1430 } else {
1431 return platformModule
1432 }
1433}
1434
Colin Crossc34d2322020-01-03 15:23:27 -08001435func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001436 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001437 EarlyModuleContext: ctx,
1438 kind: determineModuleKind(m, ctx),
1439 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001440 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001441}
1442
Colin Cross1184b642019-12-30 18:43:07 -08001443func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1444 return baseModuleContext{
1445 bp: ctx,
1446 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1447 os: m.commonProperties.CompileOS,
1448 target: m.commonProperties.CompileTarget,
1449 targetPrimary: m.commonProperties.CompilePrimary,
1450 multiTargets: m.commonProperties.CompileMultiTargets,
1451 }
1452}
1453
Colin Cross4157e882019-06-06 16:57:04 -07001454func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001455 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001456 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001457 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001458 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
1459 installDeps: m.computeInstallDeps(blueprintCtx),
1460 installFiles: m.installFiles,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001461 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001462 }
1463
Colin Cross6c4f21f2019-06-06 15:41:36 -07001464 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1465 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1466 // TODO: This will be removed once defaults modules handle missing dependency errors
1467 blueprintCtx.GetMissingDependencies()
1468
Colin Crossdc35e212019-06-06 16:13:11 -07001469 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001470 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1471 // (because the dependencies are added before the modules are disabled). The
1472 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1473 // ignored.
1474 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001475
Colin Cross4c83e5c2019-02-25 14:54:28 -08001476 if ctx.config.captureBuild {
1477 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1478 }
1479
Colin Cross67a5c132017-05-09 13:45:28 -07001480 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1481 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001482 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1483 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001484 }
Colin Cross0875c522017-11-28 17:34:01 -08001485 if !ctx.PrimaryArch() {
1486 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001487 }
Dan Willemsenb13a9482020-02-14 11:25:54 -08001488 if apex, ok := m.module.(ApexModule); ok && !apex.IsForPlatform() {
Colin Crosse07f2312020-08-13 11:24:56 -07001489 suffix = append(suffix, apex.ApexVariationName())
Dan Willemsenb13a9482020-02-14 11:25:54 -08001490 }
Colin Cross67a5c132017-05-09 13:45:28 -07001491
1492 ctx.Variable(pctx, "moduleDesc", desc)
1493
1494 s := ""
1495 if len(suffix) > 0 {
1496 s = " [" + strings.Join(suffix, " ") + "]"
1497 }
1498 ctx.Variable(pctx, "moduleDescSuffix", s)
1499
Dan Willemsen569edc52018-11-19 09:33:29 -08001500 // Some common property checks for properties that will be used later in androidmk.go
Paul Duffined875132020-09-02 13:08:57 +01001501 if m.distProperties.Dist.Dest != nil {
1502 _, err := validateSafePath(*m.distProperties.Dist.Dest)
Dan Willemsen569edc52018-11-19 09:33:29 -08001503 if err != nil {
1504 ctx.PropertyErrorf("dist.dest", "%s", err.Error())
1505 }
1506 }
Paul Duffined875132020-09-02 13:08:57 +01001507 if m.distProperties.Dist.Dir != nil {
1508 _, err := validateSafePath(*m.distProperties.Dist.Dir)
Dan Willemsen569edc52018-11-19 09:33:29 -08001509 if err != nil {
1510 ctx.PropertyErrorf("dist.dir", "%s", err.Error())
1511 }
1512 }
Paul Duffined875132020-09-02 13:08:57 +01001513 if m.distProperties.Dist.Suffix != nil {
1514 if strings.Contains(*m.distProperties.Dist.Suffix, "/") {
Dan Willemsen569edc52018-11-19 09:33:29 -08001515 ctx.PropertyErrorf("dist.suffix", "Suffix may not contain a '/' character.")
1516 }
1517 }
1518
Colin Cross4157e882019-06-06 16:57:04 -07001519 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001520 // ensure all direct android.Module deps are enabled
1521 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1522 if _, ok := bm.(Module); ok {
1523 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1524 }
1525 })
1526
Bob Badoura75b0572020-02-18 20:21:55 -08001527 m.noticeFiles = make([]Path, 0)
1528 optPath := OptionalPath{}
1529 notice := proptools.StringDefault(m.commonProperties.Notice, "")
Colin Cross4157e882019-06-06 16:57:04 -07001530 if module := SrcIsModule(notice); module != "" {
Bob Badoura75b0572020-02-18 20:21:55 -08001531 optPath = ctx.ExpandOptionalSource(&notice, "notice")
1532 } else if notice != "" {
Jiyong Park52818fc2019-03-18 12:01:38 +09001533 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Bob Badoura75b0572020-02-18 20:21:55 -08001534 optPath = ExistentPathForSource(ctx, noticePath)
1535 }
1536 if optPath.Valid() {
1537 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1538 } else {
1539 for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} {
1540 noticePath := filepath.Join(ctx.ModuleDir(), notice)
1541 optPath = ExistentPathForSource(ctx, noticePath)
1542 if optPath.Valid() {
1543 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1544 }
1545 }
Jaewoong Jung62707f72018-11-16 13:26:43 -08001546 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001547
1548 m.module.GenerateAndroidBuildActions(ctx)
1549 if ctx.Failed() {
1550 return
1551 }
1552
1553 m.installFiles = append(m.installFiles, ctx.installFiles...)
1554 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Inseob Kim8471cda2019-11-15 09:59:12 +09001555 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1556 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
Colin Crossc3d87d32020-06-04 13:25:17 -07001557 for k, v := range ctx.phonies {
1558 m.phonies[k] = append(m.phonies[k], v...)
1559 }
Colin Crossdc35e212019-06-06 16:13:11 -07001560 } else if ctx.Config().AllowMissingDependencies() {
1561 // If the module is not enabled it will not create any build rules, nothing will call
1562 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1563 // and report them as an error even when AllowMissingDependencies = true. Call
1564 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1565 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001566 }
1567
Colin Cross4157e882019-06-06 16:57:04 -07001568 if m == ctx.FinalModule().(Module).base() {
1569 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001570 if ctx.Failed() {
1571 return
1572 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001573 }
Colin Crosscec81712017-07-13 14:43:27 -07001574
Colin Cross4157e882019-06-06 16:57:04 -07001575 m.buildParams = ctx.buildParams
1576 m.ruleParams = ctx.ruleParams
1577 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001578}
1579
Colin Cross1184b642019-12-30 18:43:07 -08001580type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001581 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001582
1583 kind moduleKind
1584 config Config
1585}
1586
1587func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1588 ret, err := e.GlobWithDeps(globPattern, excludes)
1589 if err != nil {
1590 e.ModuleErrorf("glob: %s", err.Error())
1591 }
1592 return pathsForModuleSrcFromFullPath(e, ret, true)
1593}
1594
1595func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1596 ret, err := e.GlobWithDeps(globPattern, excludes)
1597 if err != nil {
1598 e.ModuleErrorf("glob: %s", err.Error())
1599 }
1600 return pathsForModuleSrcFromFullPath(e, ret, false)
1601}
1602
Colin Cross988414c2020-01-11 01:11:46 +00001603func (b *earlyModuleContext) IsSymlink(path Path) bool {
1604 fileInfo, err := b.config.fs.Lstat(path.String())
1605 if err != nil {
1606 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1607 }
1608 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1609}
1610
1611func (b *earlyModuleContext) Readlink(path Path) string {
1612 dest, err := b.config.fs.Readlink(path.String())
1613 if err != nil {
1614 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1615 }
1616 return dest
1617}
1618
Colin Cross1184b642019-12-30 18:43:07 -08001619func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001620 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001621 return module
1622}
1623
1624func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001625 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001626}
1627
1628func (e *earlyModuleContext) AConfig() Config {
1629 return e.config
1630}
1631
1632func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1633 return DeviceConfig{e.config.deviceConfig}
1634}
1635
1636func (e *earlyModuleContext) Platform() bool {
1637 return e.kind == platformModule
1638}
1639
1640func (e *earlyModuleContext) DeviceSpecific() bool {
1641 return e.kind == deviceSpecificModule
1642}
1643
1644func (e *earlyModuleContext) SocSpecific() bool {
1645 return e.kind == socSpecificModule
1646}
1647
1648func (e *earlyModuleContext) ProductSpecific() bool {
1649 return e.kind == productSpecificModule
1650}
1651
1652func (e *earlyModuleContext) SystemExtSpecific() bool {
1653 return e.kind == systemExtSpecificModule
1654}
1655
Colin Cross133ebef2020-08-14 17:38:45 -07001656func (e *earlyModuleContext) Namespace() *Namespace {
1657 return e.EarlyModuleContext.Namespace().(*Namespace)
1658}
1659
Colin Cross1184b642019-12-30 18:43:07 -08001660type baseModuleContext struct {
1661 bp blueprint.BaseModuleContext
1662 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001663 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001664 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001665 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001666 targetPrimary bool
1667 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001668
1669 walkPath []Module
Paul Duffinc5192442020-03-31 11:31:36 +01001670 tagPath []blueprint.DependencyTag
Colin Crossdc35e212019-06-06 16:13:11 -07001671
1672 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001673}
1674
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001675func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
1676 return b.bp.OtherModuleName(m)
1677}
1678func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08001679func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Hancd87c692020-02-26 02:05:18 +09001680 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08001681}
1682func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1683 return b.bp.OtherModuleDependencyTag(m)
1684}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001685func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00001686func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
1687 return b.bp.OtherModuleDependencyVariantExists(variations, name)
1688}
1689func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
1690 return b.bp.OtherModuleReverseDependencyVariantExists(name)
1691}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001692func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
1693 return b.bp.OtherModuleType(m)
1694}
Colin Crossd27e7b82020-07-02 11:38:17 -07001695func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
1696 return b.bp.OtherModuleProvider(m, provider)
1697}
1698func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
1699 return b.bp.OtherModuleHasProvider(m, provider)
1700}
1701func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
1702 return b.bp.Provider(provider)
1703}
1704func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
1705 return b.bp.HasProvider(provider)
1706}
1707func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
1708 b.bp.SetProvider(provider, value)
1709}
Colin Cross1184b642019-12-30 18:43:07 -08001710
1711func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1712 return b.bp.GetDirectDepWithTag(name, tag)
1713}
1714
Paul Duffinf88d8e02020-05-07 20:21:34 +01001715func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
1716 return b.bp
1717}
1718
Colin Cross25de6c32019-06-06 14:29:25 -07001719type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001720 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001721 baseModuleContext
Colin Cross897266e2020-02-13 13:22:08 -08001722 installDeps InstallPaths
1723 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001724 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001725 module Module
Colin Crossc3d87d32020-06-04 13:25:17 -07001726 phonies map[string]Paths
Colin Crosscec81712017-07-13 14:43:27 -07001727
1728 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001729 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001730 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001731 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001732}
1733
Colin Crossb88b3c52019-06-10 15:15:17 -07001734func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1735 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001736 Rule: ErrorRule,
1737 Description: params.Description,
1738 Output: params.Output,
1739 Outputs: params.Outputs,
1740 ImplicitOutput: params.ImplicitOutput,
1741 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001742 Args: map[string]string{
1743 "error": err.Error(),
1744 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001745 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001746}
1747
Colin Cross25de6c32019-06-06 14:29:25 -07001748func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1749 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001750}
1751
Colin Cross0875c522017-11-28 17:34:01 -08001752func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001753 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001754 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001755 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001756 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001757 Outputs: params.Outputs.Strings(),
1758 ImplicitOutputs: params.ImplicitOutputs.Strings(),
1759 Inputs: params.Inputs.Strings(),
1760 Implicits: params.Implicits.Strings(),
1761 OrderOnly: params.OrderOnly.Strings(),
Colin Cross824f1162020-07-16 13:07:51 -07001762 Validations: params.Validations.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001763 Args: params.Args,
1764 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001765 }
1766
Colin Cross33bfb0a2016-11-21 17:23:08 -08001767 if params.Depfile != nil {
1768 bparams.Depfile = params.Depfile.String()
1769 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001770 if params.Output != nil {
1771 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1772 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001773 if params.ImplicitOutput != nil {
1774 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1775 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001776 if params.Input != nil {
1777 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1778 }
1779 if params.Implicit != nil {
1780 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1781 }
Colin Cross824f1162020-07-16 13:07:51 -07001782 if params.Validation != nil {
1783 bparams.Validations = append(bparams.Validations, params.Validation.String())
1784 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001785
Colin Cross0b9f31f2019-02-28 11:00:01 -08001786 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1787 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
1788 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1789 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1790 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
Colin Cross824f1162020-07-16 13:07:51 -07001791 bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
1792 bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
Colin Crossfe4bc362018-09-12 10:02:13 -07001793
Colin Cross0875c522017-11-28 17:34:01 -08001794 return bparams
1795}
1796
Colin Cross25de6c32019-06-06 14:29:25 -07001797func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1798 if m.config.captureBuild {
1799 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001800 }
1801
Colin Crossdc35e212019-06-06 16:13:11 -07001802 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08001803}
1804
Colin Cross25de6c32019-06-06 14:29:25 -07001805func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08001806 argNames ...string) blueprint.Rule {
1807
Ramy Medhat944839a2020-03-31 22:14:52 -04001808 if m.config.UseRemoteBuild() {
1809 if params.Pool == nil {
1810 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
1811 // jobs to the local parallelism value
1812 params.Pool = localPool
1813 } else if params.Pool == remotePool {
1814 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
1815 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
1816 // parallelism.
1817 params.Pool = nil
1818 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07001819 }
1820
Colin Crossdc35e212019-06-06 16:13:11 -07001821 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08001822
Colin Cross25de6c32019-06-06 14:29:25 -07001823 if m.config.captureBuild {
1824 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08001825 }
1826
1827 return rule
Colin Cross0875c522017-11-28 17:34:01 -08001828}
1829
Colin Cross25de6c32019-06-06 14:29:25 -07001830func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07001831 if params.Description != "" {
1832 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
1833 }
1834
1835 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
1836 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
1837 m.ModuleName(), strings.Join(missingDeps, ", ")))
1838 }
1839
Colin Cross25de6c32019-06-06 14:29:25 -07001840 if m.config.captureBuild {
1841 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08001842 }
1843
Colin Crossdc35e212019-06-06 16:13:11 -07001844 m.bp.Build(pctx.PackageContext, convertBuildParams(params))
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001845}
Colin Crossc3d87d32020-06-04 13:25:17 -07001846
1847func (m *moduleContext) Phony(name string, deps ...Path) {
1848 addPhony(m.config, name, deps...)
1849}
1850
Colin Cross25de6c32019-06-06 14:29:25 -07001851func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07001852 var missingDeps []string
1853 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07001854 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07001855 missingDeps = FirstUniqueStrings(missingDeps)
1856 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08001857}
1858
Colin Crossdc35e212019-06-06 16:13:11 -07001859func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001860 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001861 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07001862 *missingDeps = append(*missingDeps, deps...)
1863 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08001864 }
1865}
1866
Colin Crossdc35e212019-06-06 16:13:11 -07001867func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07001868 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07001869
1870 if !strict {
1871 return aModule
1872 }
1873
Colin Cross380c69a2019-06-10 17:49:58 +00001874 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07001875 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00001876 return nil
1877 }
1878
1879 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07001880 if b.Config().AllowMissingDependencies() {
1881 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00001882 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07001883 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00001884 }
1885 return nil
1886 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001887 return aModule
1888}
1889
Colin Crossdc35e212019-06-06 16:13:11 -07001890func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09001891 type dep struct {
1892 mod blueprint.Module
1893 tag blueprint.DependencyTag
1894 }
1895 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07001896 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001897 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08001898 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09001899 if tag == nil || returnedTag == tag {
1900 deps = append(deps, dep{aModule, returnedTag})
1901 }
1902 }
1903 })
1904 if len(deps) == 1 {
1905 return deps[0].mod, deps[0].tag
1906 } else if len(deps) >= 2 {
1907 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07001908 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09001909 } else {
1910 return nil, nil
1911 }
1912}
1913
Colin Crossdc35e212019-06-06 16:13:11 -07001914func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07001915 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07001916 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07001917 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001918 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07001919 deps = append(deps, aModule)
1920 }
1921 }
1922 })
1923 return deps
1924}
1925
Colin Cross25de6c32019-06-06 14:29:25 -07001926func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1927 module, _ := m.getDirectDepInternal(name, tag)
1928 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09001929}
1930
Colin Crossdc35e212019-06-06 16:13:11 -07001931func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
1932 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09001933}
1934
Colin Crossdc35e212019-06-06 16:13:11 -07001935func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001936 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08001937}
1938
Colin Crossdc35e212019-06-06 16:13:11 -07001939func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001940 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001941 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001942 visit(aModule)
1943 }
1944 })
1945}
1946
Colin Crossdc35e212019-06-06 16:13:11 -07001947func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001948 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001949 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08001950 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08001951 visit(aModule)
1952 }
1953 }
1954 })
1955}
1956
Colin Crossdc35e212019-06-06 16:13:11 -07001957func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001958 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001959 // pred
1960 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001961 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001962 return pred(aModule)
1963 } else {
1964 return false
1965 }
1966 },
1967 // visit
1968 func(module blueprint.Module) {
1969 visit(module.(Module))
1970 })
1971}
1972
Colin Crossdc35e212019-06-06 16:13:11 -07001973func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001974 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07001975 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001976 visit(aModule)
1977 }
1978 })
1979}
1980
Colin Crossdc35e212019-06-06 16:13:11 -07001981func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08001982 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07001983 // pred
1984 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07001985 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07001986 return pred(aModule)
1987 } else {
1988 return false
1989 }
1990 },
1991 // visit
1992 func(module blueprint.Module) {
1993 visit(module.(Module))
1994 })
1995}
1996
Colin Crossdc35e212019-06-06 16:13:11 -07001997func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08001998 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08001999}
2000
Colin Crossdc35e212019-06-06 16:13:11 -07002001func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
2002 b.walkPath = []Module{b.Module()}
Paul Duffinc5192442020-03-31 11:31:36 +01002003 b.tagPath = []blueprint.DependencyTag{}
Colin Cross1184b642019-12-30 18:43:07 -08002004 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002005 childAndroidModule, _ := child.(Module)
2006 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07002007 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002008 // record walkPath before visit
2009 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
2010 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
Paul Duffinc5192442020-03-31 11:31:36 +01002011 b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
Colin Crossdc35e212019-06-06 16:13:11 -07002012 }
2013 b.walkPath = append(b.walkPath, childAndroidModule)
Paul Duffinc5192442020-03-31 11:31:36 +01002014 b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07002015 return visit(childAndroidModule, parentAndroidModule)
2016 } else {
2017 return false
2018 }
2019 })
2020}
2021
Colin Crossdc35e212019-06-06 16:13:11 -07002022func (b *baseModuleContext) GetWalkPath() []Module {
2023 return b.walkPath
2024}
2025
Paul Duffinc5192442020-03-31 11:31:36 +01002026func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
2027 return b.tagPath
2028}
2029
Colin Cross4dfacf92020-09-16 19:22:27 -07002030func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
2031 b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
2032 visit(module.(Module))
2033 })
2034}
2035
2036func (b *baseModuleContext) PrimaryModule() Module {
2037 return b.bp.PrimaryModule().(Module)
2038}
2039
2040func (b *baseModuleContext) FinalModule() Module {
2041 return b.bp.FinalModule().(Module)
2042}
2043
Jiyong Park1c7e9622020-05-07 16:12:13 +09002044// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
2045// a dependency tag.
Colin Cross6e511a92020-07-27 21:26:48 -07002046var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002047
2048// PrettyPrintTag returns string representation of the tag, but prefers
2049// custom String() method if available.
2050func PrettyPrintTag(tag blueprint.DependencyTag) string {
2051 // Use tag's custom String() method if available.
2052 if stringer, ok := tag.(fmt.Stringer); ok {
2053 return stringer.String()
2054 }
2055
2056 // Otherwise, get a default string representation of the tag's struct.
Colin Cross6e511a92020-07-27 21:26:48 -07002057 tagString := fmt.Sprintf("%T: %+v", tag, tag)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002058
2059 // Remove the boilerplate from BaseDependencyTag as it adds no value.
2060 tagString = tagCleaner.ReplaceAllString(tagString, "")
2061 return tagString
2062}
2063
2064func (b *baseModuleContext) GetPathString(skipFirst bool) string {
2065 sb := strings.Builder{}
2066 tagPath := b.GetTagPath()
2067 walkPath := b.GetWalkPath()
2068 if !skipFirst {
2069 sb.WriteString(walkPath[0].String())
2070 }
2071 for i, m := range walkPath[1:] {
2072 sb.WriteString("\n")
2073 sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
2074 sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
2075 }
2076 return sb.String()
2077}
2078
Colin Crossdc35e212019-06-06 16:13:11 -07002079func (m *moduleContext) ModuleSubDir() string {
2080 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08002081}
2082
Colin Cross0ea8ba82019-06-06 14:33:29 -07002083func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002084 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07002085}
2086
Colin Cross0ea8ba82019-06-06 14:33:29 -07002087func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002088 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07002089}
2090
Colin Cross0ea8ba82019-06-06 14:33:29 -07002091func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002092 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07002093}
2094
Colin Cross0ea8ba82019-06-06 14:33:29 -07002095func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07002096 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08002097}
2098
Colin Cross0ea8ba82019-06-06 14:33:29 -07002099func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002100 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08002101}
2102
Colin Cross0ea8ba82019-06-06 14:33:29 -07002103func (b *baseModuleContext) Host() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002104 return b.os.Class == Host || b.os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -07002105}
2106
Colin Cross0ea8ba82019-06-06 14:33:29 -07002107func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002108 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07002109}
2110
Colin Cross0ea8ba82019-06-06 14:33:29 -07002111func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002112 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07002113}
2114
Colin Cross0ea8ba82019-06-06 14:33:29 -07002115func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002116 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08002117}
2118
Colin Cross0ea8ba82019-06-06 14:33:29 -07002119func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002120 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07002121}
2122
Colin Cross0ea8ba82019-06-06 14:33:29 -07002123func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002124 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07002125}
2126
Colin Cross0ea8ba82019-06-06 14:33:29 -07002127func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002128 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07002129 return true
2130 }
Colin Cross25de6c32019-06-06 14:29:25 -07002131 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07002132}
2133
Jiyong Park5baac542018-08-28 09:55:37 +09002134// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09002135// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07002136func (m *ModuleBase) MakeAsPlatform() {
2137 m.commonProperties.Vendor = boolPtr(false)
2138 m.commonProperties.Proprietary = boolPtr(false)
2139 m.commonProperties.Soc_specific = boolPtr(false)
2140 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09002141 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09002142}
2143
Colin Cross4157e882019-06-06 16:57:04 -07002144func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
2145 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02002146}
2147
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002148func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09002149 m.commonProperties.Vendor = boolPtr(false)
2150 m.commonProperties.Proprietary = boolPtr(false)
2151 m.commonProperties.Soc_specific = boolPtr(false)
2152 m.commonProperties.Product_specific = boolPtr(false)
2153 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002154}
2155
Jooyung Han344d5432019-08-23 11:17:39 +09002156// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
2157func (m *ModuleBase) IsNativeBridgeSupported() bool {
2158 return proptools.Bool(m.commonProperties.Native_bridge_supported)
2159}
2160
Colin Cross25de6c32019-06-06 14:29:25 -07002161func (m *moduleContext) InstallInData() bool {
2162 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08002163}
2164
Jaewoong Jung0949f312019-09-11 10:25:18 -07002165func (m *moduleContext) InstallInTestcases() bool {
2166 return m.module.InstallInTestcases()
2167}
2168
Colin Cross25de6c32019-06-06 14:29:25 -07002169func (m *moduleContext) InstallInSanitizerDir() bool {
2170 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002171}
2172
Yifan Hong1b3348d2020-01-21 15:53:22 -08002173func (m *moduleContext) InstallInRamdisk() bool {
2174 return m.module.InstallInRamdisk()
2175}
2176
Colin Cross25de6c32019-06-06 14:29:25 -07002177func (m *moduleContext) InstallInRecovery() bool {
2178 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002179}
2180
Colin Cross90ba5f42019-10-02 11:10:58 -07002181func (m *moduleContext) InstallInRoot() bool {
2182 return m.module.InstallInRoot()
2183}
2184
Colin Cross607d8582019-07-29 16:44:46 -07002185func (m *moduleContext) InstallBypassMake() bool {
2186 return m.module.InstallBypassMake()
2187}
2188
Jiyong Park87788b52020-09-01 12:37:45 +09002189func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
Colin Cross6e359402020-02-10 15:29:54 -08002190 return m.module.InstallForceOS()
2191}
2192
Colin Cross70dda7e2019-10-01 22:05:35 -07002193func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002194 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07002195 return true
2196 }
2197
Colin Cross3607f212018-05-07 15:28:05 -07002198 // We'll need a solution for choosing which of modules with the same name in different
2199 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
2200 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07002201 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07002202 return true
2203 }
2204
Colin Cross25de6c32019-06-06 14:29:25 -07002205 if m.Device() {
Colin Cross607d8582019-07-29 16:44:46 -07002206 if m.Config().EmbeddedInMake() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07002207 return true
2208 }
2209
Colin Cross25de6c32019-06-06 14:29:25 -07002210 if m.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -07002211 return true
2212 }
2213 }
2214
2215 return false
2216}
2217
Colin Cross70dda7e2019-10-01 22:05:35 -07002218func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
2219 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002220 return m.installFile(installPath, name, srcPath, Cp, deps)
Colin Cross5c517922017-08-31 12:29:17 -07002221}
2222
Colin Cross70dda7e2019-10-01 22:05:35 -07002223func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
2224 deps ...Path) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002225 return m.installFile(installPath, name, srcPath, CpExecutable, deps)
Colin Cross5c517922017-08-31 12:29:17 -07002226}
2227
Colin Cross70dda7e2019-10-01 22:05:35 -07002228func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path,
2229 rule blueprint.Rule, deps []Path) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07002230
Colin Cross25de6c32019-06-06 14:29:25 -07002231 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002232 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08002233
Colin Cross25de6c32019-06-06 14:29:25 -07002234 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07002235
Colin Cross897266e2020-02-13 13:22:08 -08002236 deps = append(deps, m.installDeps.Paths()...)
Colin Cross35cec122015-04-02 14:37:16 -07002237
Colin Cross89562dc2016-10-03 17:47:19 -07002238 var implicitDeps, orderOnlyDeps Paths
2239
Colin Cross25de6c32019-06-06 14:29:25 -07002240 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07002241 // Installed host modules might be used during the build, depend directly on their
2242 // dependencies so their timestamp is updated whenever their dependency is updated
2243 implicitDeps = deps
2244 } else {
2245 orderOnlyDeps = deps
2246 }
2247
Colin Cross25de6c32019-06-06 14:29:25 -07002248 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07002249 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07002250 Description: "install " + fullInstallPath.Base(),
2251 Output: fullInstallPath,
2252 Input: srcPath,
2253 Implicits: implicitDeps,
2254 OrderOnly: orderOnlyDeps,
Colin Cross25de6c32019-06-06 14:29:25 -07002255 Default: !m.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08002256 })
Colin Cross3f40fa42015-01-30 17:27:36 -08002257
Colin Cross25de6c32019-06-06 14:29:25 -07002258 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08002259 }
Colin Cross25de6c32019-06-06 14:29:25 -07002260 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07002261 return fullInstallPath
2262}
2263
Colin Cross70dda7e2019-10-01 22:05:35 -07002264func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002265 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002266 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08002267
Colin Cross25de6c32019-06-06 14:29:25 -07002268 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07002269
Alex Lightfb4353d2019-01-17 13:57:45 -08002270 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
2271 if err != nil {
2272 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
2273 }
Colin Cross25de6c32019-06-06 14:29:25 -07002274 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07002275 Rule: Symlink,
2276 Description: "install symlink " + fullInstallPath.Base(),
2277 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08002278 Input: srcPath,
Colin Cross25de6c32019-06-06 14:29:25 -07002279 Default: !m.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -08002280 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08002281 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08002282 },
2283 })
Colin Cross3854a602016-01-11 12:49:11 -08002284
Colin Cross25de6c32019-06-06 14:29:25 -07002285 m.installFiles = append(m.installFiles, fullInstallPath)
2286 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08002287 }
Colin Cross3854a602016-01-11 12:49:11 -08002288 return fullInstallPath
2289}
2290
Jiyong Parkf1194352019-02-25 11:05:47 +09002291// installPath/name -> absPath where absPath might be a path that is available only at runtime
2292// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07002293func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002294 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002295 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09002296
Colin Cross25de6c32019-06-06 14:29:25 -07002297 if !m.skipInstall(fullInstallPath) {
2298 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09002299 Rule: Symlink,
2300 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
2301 Output: fullInstallPath,
Colin Cross25de6c32019-06-06 14:29:25 -07002302 Default: !m.Config().EmbeddedInMake(),
Jiyong Parkf1194352019-02-25 11:05:47 +09002303 Args: map[string]string{
2304 "fromPath": absPath,
2305 },
2306 })
2307
Colin Cross25de6c32019-06-06 14:29:25 -07002308 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09002309 }
2310 return fullInstallPath
2311}
2312
Colin Cross25de6c32019-06-06 14:29:25 -07002313func (m *moduleContext) CheckbuildFile(srcPath Path) {
2314 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08002315}
2316
Colin Cross41955e82019-05-29 14:40:35 -07002317// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
2318// was not a module reference.
2319func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08002320 if len(s) > 1 && s[0] == ':' {
2321 return s[1:]
2322 }
2323 return ""
2324}
2325
Colin Cross41955e82019-05-29 14:40:35 -07002326// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
2327// module name and an empty string for the tag, or empty strings if the input was not a module reference.
2328func SrcIsModuleWithTag(s string) (module, tag string) {
2329 if len(s) > 1 && s[0] == ':' {
2330 module = s[1:]
2331 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2332 if module[len(module)-1] == '}' {
2333 tag = module[tagStart+1 : len(module)-1]
2334 module = module[:tagStart]
2335 return module, tag
2336 }
2337 }
2338 return module, ""
2339 }
2340 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08002341}
2342
Colin Cross41955e82019-05-29 14:40:35 -07002343type sourceOrOutputDependencyTag struct {
2344 blueprint.BaseDependencyTag
2345 tag string
2346}
2347
2348func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
2349 return sourceOrOutputDependencyTag{tag: tag}
2350}
2351
2352var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08002353
Colin Cross366938f2017-12-11 16:29:02 -08002354// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
2355// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002356//
2357// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08002358func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07002359 set := make(map[string]bool)
2360
Colin Cross068e0fe2016-12-13 15:23:47 -08002361 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07002362 if m, t := SrcIsModuleWithTag(s); m != "" {
2363 if _, found := set[s]; found {
2364 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07002365 } else {
Colin Cross41955e82019-05-29 14:40:35 -07002366 set[s] = true
2367 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07002368 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002369 }
2370 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002371}
2372
Colin Cross366938f2017-12-11 16:29:02 -08002373// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
2374// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002375//
2376// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08002377func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
2378 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07002379 if m, t := SrcIsModuleWithTag(*s); m != "" {
2380 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08002381 }
2382 }
2383}
2384
Colin Cross41955e82019-05-29 14:40:35 -07002385// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
2386// 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 -08002387type SourceFileProducer interface {
2388 Srcs() Paths
2389}
2390
Colin Cross41955e82019-05-29 14:40:35 -07002391// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002392// 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 -07002393// listed in the property.
2394type OutputFileProducer interface {
2395 OutputFiles(tag string) (Paths, error)
2396}
2397
Colin Cross5e708052019-08-06 13:59:50 -07002398// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2399// module produced zero paths, it reports errors to the ctx and returns nil.
2400func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2401 paths, err := outputFilesForModule(ctx, module, tag)
2402 if err != nil {
2403 reportPathError(ctx, err)
2404 return nil
2405 }
2406 return paths
2407}
2408
2409// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2410// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2411func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2412 paths, err := outputFilesForModule(ctx, module, tag)
2413 if err != nil {
2414 reportPathError(ctx, err)
2415 return nil
2416 }
2417 if len(paths) > 1 {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01002418 ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
Colin Cross5e708052019-08-06 13:59:50 -07002419 pathContextName(ctx, module))
2420 return nil
2421 }
2422 return paths[0]
2423}
2424
2425func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2426 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2427 paths, err := outputFileProducer.OutputFiles(tag)
2428 if err != nil {
2429 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2430 pathContextName(ctx, module), err.Error())
2431 }
2432 if len(paths) == 0 {
2433 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2434 }
2435 return paths, nil
2436 } else {
2437 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2438 }
2439}
2440
Colin Crossfe17f6f2019-03-28 19:30:56 -07002441type HostToolProvider interface {
2442 HostToolPath() OptionalPath
2443}
2444
Colin Cross27b922f2019-03-04 22:35:41 -08002445// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2446// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002447//
2448// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002449func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2450 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002451}
2452
Colin Cross2fafa3e2019-03-05 12:39:51 -08002453// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2454// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002455//
2456// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002457func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2458 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002459}
2460
2461// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2462// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2463// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002464func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002465 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002466 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002467 }
2468 return OptionalPath{}
2469}
2470
Colin Cross25de6c32019-06-06 14:29:25 -07002471func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002472 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002473}
2474
Colin Cross25de6c32019-06-06 14:29:25 -07002475func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002476 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002477}
2478
Colin Cross25de6c32019-06-06 14:29:25 -07002479func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002480 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002481}
2482
Colin Cross463a90e2015-06-17 14:20:06 -07002483func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002484 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002485}
2486
Colin Cross0875c522017-11-28 17:34:01 -08002487func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002488 return &buildTargetSingleton{}
2489}
2490
Colin Cross87d8b562017-04-25 10:01:55 -07002491func parentDir(dir string) string {
2492 dir, _ = filepath.Split(dir)
2493 return filepath.Clean(dir)
2494}
2495
Colin Cross1f8c52b2015-06-16 16:38:17 -07002496type buildTargetSingleton struct{}
2497
Colin Cross0875c522017-11-28 17:34:01 -08002498func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2499 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002500
Colin Crossc3d87d32020-06-04 13:25:17 -07002501 mmTarget := func(dir string) string {
2502 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07002503 }
2504
Colin Cross0875c522017-11-28 17:34:01 -08002505 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002506
Colin Cross0875c522017-11-28 17:34:01 -08002507 ctx.VisitAllModules(func(module Module) {
2508 blueprintDir := module.base().blueprintDir
2509 installTarget := module.base().installTarget
2510 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002511
Colin Cross0875c522017-11-28 17:34:01 -08002512 if checkbuildTarget != nil {
2513 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2514 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2515 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002516
Colin Cross0875c522017-11-28 17:34:01 -08002517 if installTarget != nil {
2518 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002519 }
2520 })
2521
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002522 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08002523 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002524 suffix = "-soong"
2525 }
2526
Colin Cross1f8c52b2015-06-16 16:38:17 -07002527 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07002528 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002529
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002530 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08002531 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002532 return
2533 }
2534
Colin Cross87d8b562017-04-25 10:01:55 -07002535 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002536 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002537 for _, dir := range dirs {
2538 dir := parentDir(dir)
2539 for dir != "." && dir != "/" {
2540 if _, exists := modulesInDir[dir]; exists {
2541 break
2542 }
2543 modulesInDir[dir] = nil
2544 dir = parentDir(dir)
2545 }
2546 }
2547
2548 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002549 for _, dir := range dirs {
2550 p := parentDir(dir)
2551 if p != "." && p != "/" {
Colin Crossc3d87d32020-06-04 13:25:17 -07002552 modulesInDir[p] = append(modulesInDir[p], PathForPhony(ctx, mmTarget(dir)))
Colin Cross87d8b562017-04-25 10:01:55 -07002553 }
2554 }
2555
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002556 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2557 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2558 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002559 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07002560 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002561 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002562
2563 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
2564 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002565 ctx.VisitAllModules(func(module Module) {
2566 if module.Enabled() {
2567 os := module.Target().Os
2568 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002569 }
2570 })
2571
Colin Cross0875c522017-11-28 17:34:01 -08002572 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002573 for os, deps := range osDeps {
2574 var className string
2575
2576 switch os.Class {
2577 case Host:
2578 className = "host"
2579 case HostCross:
2580 className = "host-cross"
2581 case Device:
2582 className = "target"
2583 default:
2584 continue
2585 }
2586
Colin Crossc3d87d32020-06-04 13:25:17 -07002587 name := className + "-" + os.Name
2588 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07002589
Colin Crossc3d87d32020-06-04 13:25:17 -07002590 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002591 }
2592
2593 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002594 for _, class := range SortedStringKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07002595 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002596 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002597}
Colin Crossd779da42015-12-17 18:00:23 -08002598
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002599// Collect information for opening IDE project files in java/jdeps.go.
2600type IDEInfo interface {
2601 IDEInfo(ideInfo *IdeInfo)
2602 BaseModuleName() string
2603}
2604
2605// Extract the base module name from the Import name.
2606// Often the Import name has a prefix "prebuilt_".
2607// Remove the prefix explicitly if needed
2608// until we find a better solution to get the Import name.
2609type IDECustomizedModuleName interface {
2610 IDECustomizedModuleName() string
2611}
2612
2613type IdeInfo struct {
2614 Deps []string `json:"dependencies,omitempty"`
2615 Srcs []string `json:"srcs,omitempty"`
2616 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2617 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2618 Jars []string `json:"jars,omitempty"`
2619 Classes []string `json:"class,omitempty"`
2620 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002621 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08002622 Paths []string `json:"path,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002623}
Paul Duffinf88d8e02020-05-07 20:21:34 +01002624
2625func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
2626 bpctx := ctx.blueprintBaseModuleContext()
2627 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
2628}