blob: f805acdf5a84a61ec3601d8c92f41239f76bc77f [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
Jingwen Chence679d22020-09-23 04:30:02 +000046 SymlinkOutput WritablePath
47 SymlinkOutputs WritablePaths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070048 ImplicitOutput WritablePath
49 ImplicitOutputs WritablePaths
50 Input Path
51 Inputs Paths
52 Implicit Path
53 Implicits Paths
54 OrderOnly Paths
Colin Cross824f1162020-07-16 13:07:51 -070055 Validation Path
56 Validations Paths
Dan Willemsen9f3c5742016-11-03 14:28:31 -070057 Default bool
58 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070059}
60
Colin Crossae887032017-10-23 17:16:14 -070061type ModuleBuildParams BuildParams
62
Colin Cross1184b642019-12-30 18:43:07 -080063// EarlyModuleContext provides methods that can be called early, as soon as the properties have
64// been parsed into the module and before any mutators have run.
65type EarlyModuleContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -070066 // Module returns the current module as a Module. It should rarely be necessary, as the module already has a
67 // reference to itself.
Colin Cross1184b642019-12-30 18:43:07 -080068 Module() Module
Colin Cross9f35c3d2020-09-16 19:04:41 -070069
70 // ModuleName returns the name of the module. This is generally the value that was returned by Module.Name() when
71 // the module was created, but may have been modified by calls to BaseMutatorContext.Rename.
Colin Cross1184b642019-12-30 18:43:07 -080072 ModuleName() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070073
74 // ModuleDir returns the path to the directory that contains the definition of the module.
Colin Cross1184b642019-12-30 18:43:07 -080075 ModuleDir() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070076
77 // ModuleType returns the name of the module type that was used to create the module, as specified in
78 // RegisterModuleType.
Colin Cross1184b642019-12-30 18:43:07 -080079 ModuleType() string
Colin Cross9f35c3d2020-09-16 19:04:41 -070080
81 // BlueprintFile returns the name of the blueprint file that contains the definition of this
82 // module.
Colin Cross9d34f352019-11-22 16:03:51 -080083 BlueprintsFile() string
Colin Cross1184b642019-12-30 18:43:07 -080084
Colin Cross9f35c3d2020-09-16 19:04:41 -070085 // ContainsProperty returns true if the specified property name was set in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080086 ContainsProperty(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -070087
88 // Errorf reports an error at the specified position of the module definition file.
Colin Cross1184b642019-12-30 18:43:07 -080089 Errorf(pos scanner.Position, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070090
91 // ModuleErrorf reports an error at the line number of the module type in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080092 ModuleErrorf(fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070093
94 // PropertyErrorf reports an error at the line number of a property in the module definition.
Colin Cross1184b642019-12-30 18:43:07 -080095 PropertyErrorf(property, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -070096
97 // Failed returns true if any errors have been reported. In most cases the module can continue with generating
98 // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
99 // has prevented the module from creating necessary data it can return early when Failed returns true.
Colin Cross1184b642019-12-30 18:43:07 -0800100 Failed() bool
101
Colin Cross9f35c3d2020-09-16 19:04:41 -0700102 // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The
103 // primary builder will be rerun whenever the specified files are modified.
Colin Cross1184b642019-12-30 18:43:07 -0800104 AddNinjaFileDeps(deps ...string)
105
106 DeviceSpecific() bool
107 SocSpecific() bool
108 ProductSpecific() bool
109 SystemExtSpecific() bool
110 Platform() bool
111
112 Config() Config
113 DeviceConfig() DeviceConfig
114
115 // Deprecated: use Config()
116 AConfig() Config
117
118 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
119 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
120 // builder whenever a file matching the pattern as added or removed, without rerunning if a
121 // file that does not match the pattern is added to a searched directory.
122 GlobWithDeps(pattern string, excludes []string) ([]string, error)
123
124 Glob(globPattern string, excludes []string) Paths
125 GlobFiles(globPattern string, excludes []string) Paths
Colin Cross988414c2020-01-11 01:11:46 +0000126 IsSymlink(path Path) bool
127 Readlink(path Path) string
Colin Cross133ebef2020-08-14 17:38:45 -0700128
Colin Cross9f35c3d2020-09-16 19:04:41 -0700129 // Namespace returns the Namespace object provided by the NameInterface set by Context.SetNameInterface, or the
130 // default SimpleNameInterface if Context.SetNameInterface was not called.
Colin Cross133ebef2020-08-14 17:38:45 -0700131 Namespace() *Namespace
Colin Cross1184b642019-12-30 18:43:07 -0800132}
133
Colin Cross0ea8ba82019-06-06 14:33:29 -0700134// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
Colin Crossdc35e212019-06-06 16:13:11 -0700135// a Config instead of an interface{}, and some methods have been wrapped to use an android.Module
136// instead of a blueprint.Module, plus some extra methods that return Android-specific information
Colin Cross0ea8ba82019-06-06 14:33:29 -0700137// about the current module.
138type BaseModuleContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800139 EarlyModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700140
Paul Duffinf88d8e02020-05-07 20:21:34 +0100141 blueprintBaseModuleContext() blueprint.BaseModuleContext
142
Colin Cross9f35c3d2020-09-16 19:04:41 -0700143 // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
144 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700145 OtherModuleName(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700146
147 // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information.
148 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700149 OtherModuleDir(m blueprint.Module) string
Colin Cross9f35c3d2020-09-16 19:04:41 -0700150
151 // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information.
152 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Colin Crossdc35e212019-06-06 16:13:11 -0700153 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
Colin Cross9f35c3d2020-09-16 19:04:41 -0700154
155 // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency
156 // on the module. When called inside a Visit* method with current module being visited, and there are multiple
157 // dependencies on the module being visited, it returns the dependency tag used for the current dependency.
Colin Crossdc35e212019-06-06 16:13:11 -0700158 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
Colin Cross9f35c3d2020-09-16 19:04:41 -0700159
160 // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface
161 // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
Colin Crossdc35e212019-06-06 16:13:11 -0700162 OtherModuleExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700163
164 // OtherModuleDependencyVariantExists returns true if a module with the
165 // specified name and variant exists. The variant must match the given
166 // variations. It must also match all the non-local variations of the current
167 // module. In other words, it checks for the module AddVariationDependencies
168 // would add a dependency on with the same arguments.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000169 OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700170
171 // OtherModuleReverseDependencyVariantExists returns true if a module with the
172 // specified name exists with the same variations as the current module. In
173 // other words, it checks for the module AddReverseDependency would add a
174 // dependency on with the same argument.
Martin Stjernholm009a9dc2020-03-05 17:34:13 +0000175 OtherModuleReverseDependencyVariantExists(name string) bool
Colin Cross9f35c3d2020-09-16 19:04:41 -0700176
177 // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information.
178 // It is intended for use inside the visit functions of Visit* and WalkDeps.
Jiyong Park9e6c2422019-08-09 20:39:45 +0900179 OtherModuleType(m blueprint.Module) string
Colin Crossdc35e212019-06-06 16:13:11 -0700180
Colin Crossd27e7b82020-07-02 11:38:17 -0700181 // OtherModuleProvider returns the value for a provider for the given module. If the value is
182 // not set it returns the zero value of the type of the provider, so the return value can always
183 // be type asserted to the type of the provider. The value returned may be a deep copy of the
184 // value originally passed to SetProvider.
185 OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{}
186
187 // OtherModuleHasProvider returns true if the provider for the given module has been set.
188 OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool
189
190 // Provider returns the value for a provider for the current module. If the value is
191 // not set it returns the zero value of the type of the provider, so the return value can always
192 // be type asserted to the type of the provider. It panics if called before the appropriate
193 // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
194 // copy of the value originally passed to SetProvider.
195 Provider(provider blueprint.ProviderKey) interface{}
196
197 // HasProvider returns true if the provider for the current module has been set.
198 HasProvider(provider blueprint.ProviderKey) bool
199
200 // SetProvider sets the value for a provider for the current module. It panics if not called
201 // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
202 // is not of the appropriate type, or if the value has already been set. The value should not
203 // be modified after being passed to SetProvider.
204 SetProvider(provider blueprint.ProviderKey, value interface{})
205
Colin Crossdc35e212019-06-06 16:13:11 -0700206 GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700207
208 // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if
209 // none exists. It panics if the dependency does not have the specified tag. It skips any
210 // dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700211 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700212
213 // GetDirectDep returns the Module and DependencyTag for the direct dependency with the specified
214 // name, or nil if none exists. If there are multiple dependencies on the same module it returns
215 // the first DependencyTag. It skips any dependencies that are not an android.Module.
Colin Crossdc35e212019-06-06 16:13:11 -0700216 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
217
Colin Cross9f35c3d2020-09-16 19:04:41 -0700218 // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple
219 // direct dependencies on the same module visit will be called multiple times on that module
220 // and OtherModuleDependencyTag will return a different tag for each.
221 //
222 // The Module passed to the visit function should not be retained outside of the visit
223 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700224 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700225
226 // VisitDirectDeps calls visit for each direct dependency. If there are multiple
227 // direct dependencies on the same module visit will be called multiple times on that module
228 // and OtherModuleDependencyTag will return a different tag for each. It skips any
229 // dependencies that are not an android.Module.
230 //
231 // The Module passed to the visit function should not be retained outside of the visit
232 // function, it may be invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700233 VisitDirectDeps(visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700234
Colin Crossdc35e212019-06-06 16:13:11 -0700235 VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700236
237 // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are
238 // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and
239 // OtherModuleDependencyTag will return a different tag for each. It skips any
240 // dependencies that are not an android.Module.
241 //
242 // The Module passed to the visit function should not be retained outside of the visit function, it may be
243 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700244 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
245 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
246 VisitDepsDepthFirst(visit func(Module))
247 // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
248 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Cross9f35c3d2020-09-16 19:04:41 -0700249
250 // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may
251 // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the
252 // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited
253 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips
254 // any dependencies that are not an android.Module.
255 //
256 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
257 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700258 WalkDeps(visit func(Module, Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700259
260 // WalkDepsBlueprint calls visit for each transitive dependency, traversing the dependency
261 // tree in top down order. visit may be called multiple times for the same (child, parent)
262 // pair if there are multiple direct dependencies between the child and parent with different
263 // tags. OtherModuleDependencyTag will return the tag for the currently visited
264 // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down
265 // to child.
266 //
267 // The Modules passed to the visit function should not be retained outside of the visit function, they may be
268 // invalidated by future mutators.
Colin Crossdc35e212019-06-06 16:13:11 -0700269 WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700270
Colin Crossdc35e212019-06-06 16:13:11 -0700271 // GetWalkPath is supposed to be called in visit function passed in WalkDeps()
272 // and returns a top-down dependency path from a start module to current child module.
273 GetWalkPath() []Module
274
Colin Cross4dfacf92020-09-16 19:22:27 -0700275 // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
276 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
277 // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
278 // only done once for all variants of a module.
279 PrimaryModule() Module
280
281 // FinalModule returns the last variant of the current module. Variants of a module are always visited in
282 // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
283 // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
284 // singleton actions that are only done once for all variants of a module.
285 FinalModule() Module
286
287 // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
288 // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
289 // from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
290 // data modified by the current mutator.
291 VisitAllModuleVariants(visit func(Module))
292
Paul Duffinc5192442020-03-31 11:31:36 +0100293 // GetTagPath is supposed to be called in visit function passed in WalkDeps()
294 // and returns a top-down dependency tags path from a start module to current child module.
295 // It has one less entry than GetWalkPath() as it contains the dependency tags that
296 // exist between each adjacent pair of modules in the GetWalkPath().
297 // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1]
298 GetTagPath() []blueprint.DependencyTag
299
Jiyong Park1c7e9622020-05-07 16:12:13 +0900300 // GetPathString is supposed to be called in visit function passed in WalkDeps()
301 // and returns a multi-line string showing the modules and dependency tags
302 // among them along the top-down dependency path from a start module to current child module.
303 // skipFirst when set to true, the output doesn't include the start module,
304 // which is already printed when this function is used along with ModuleErrorf().
305 GetPathString(skipFirst bool) string
306
Colin Crossdc35e212019-06-06 16:13:11 -0700307 AddMissingDependencies(missingDeps []string)
308
Colin Crossa1ad8d12016-06-01 17:09:44 -0700309 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -0700310 TargetPrimary() bool
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000311
312 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
313 // responsible for creating.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700314 MultiTargets() []Target
Colin Crossf6566ed2015-03-24 11:13:38 -0700315 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -0700316 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -0700317 Host() bool
318 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -0700319 Darwin() bool
Doug Horn21b94272019-01-16 12:06:11 -0800320 Fuchsia() bool
Colin Cross3edeee12017-04-04 12:59:48 -0700321 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700322 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -0700323 PrimaryArch() bool
Colin Crossf6566ed2015-03-24 11:13:38 -0700324}
325
Colin Cross1184b642019-12-30 18:43:07 -0800326// Deprecated: use EarlyModuleContext instead
Colin Cross635c3b02016-05-18 15:37:25 -0700327type BaseContext interface {
Colin Cross1184b642019-12-30 18:43:07 -0800328 EarlyModuleContext
Colin Crossaabf6792017-11-29 00:27:14 -0800329}
330
Colin Cross635c3b02016-05-18 15:37:25 -0700331type ModuleContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -0800332 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800333
Colin Crossc20dc852020-11-10 12:27:45 -0800334 blueprintModuleContext() blueprint.ModuleContext
335
Colin Crossae887032017-10-23 17:16:14 -0700336 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800337 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700338
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700339 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800340 ExpandSource(srcFile, prop string) Path
Colin Cross2383f3b2018-02-06 14:40:13 -0800341 ExpandOptionalSource(srcFile *string, prop string) OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700342
Colin Cross70dda7e2019-10-01 22:05:35 -0700343 InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
344 InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath
345 InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath
346 InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700347 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800348
Colin Cross8d8f8e22016-08-03 11:57:50 -0700349 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700350 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700351 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800352 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700353 InstallInVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900354 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700355 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700356 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900357 InstallForceOS() (*OsType, *ArchType)
Nan Zhang6d34b302017-02-04 17:47:46 -0800358
359 RequiredModuleNames() []string
Sasha Smundakb6d23052019-04-01 18:37:36 -0700360 HostRequiredModuleNames() []string
361 TargetRequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700362
Colin Cross3f68a132017-10-23 17:10:29 -0700363 ModuleSubDir() string
364
Colin Cross0875c522017-11-28 17:34:01 -0800365 Variable(pctx PackageContext, name, value string)
366 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700367 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
368 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800369 Build(pctx PackageContext, params BuildParams)
Colin Crossc3d87d32020-06-04 13:25:17 -0700370 // Phony creates a Make-style phony rule, a rule with no commands that can depend on other
371 // phony rules or real files. Phony can be called on the same name multiple times to add
372 // additional dependencies.
373 Phony(phony string, deps ...Path)
Colin Cross3f68a132017-10-23 17:10:29 -0700374
Colin Cross9f35c3d2020-09-16 19:04:41 -0700375 // GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
376 // but do not exist.
Colin Cross3f68a132017-10-23 17:10:29 -0700377 GetMissingDependencies() []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800378}
379
Colin Cross635c3b02016-05-18 15:37:25 -0700380type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800381 blueprint.Module
382
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700383 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
384 // but GenerateAndroidBuildActions also has access to Android-specific information.
385 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700386 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700387
Paul Duffin44f1d842020-06-26 20:17:02 +0100388 // Add dependencies to the components of a module, i.e. modules that are created
389 // by the module and which are considered to be part of the creating module.
390 //
391 // This is called before prebuilts are renamed so as to allow a dependency to be
392 // added directly to a prebuilt child module instead of depending on a source module
393 // and relying on prebuilt processing to switch to the prebuilt module if preferred.
394 //
395 // A dependency on a prebuilt must include the "prebuilt_" prefix.
396 ComponentDepsMutator(ctx BottomUpMutatorContext)
397
Colin Cross1e676be2016-10-12 14:38:15 -0700398 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800399
Colin Cross635c3b02016-05-18 15:37:25 -0700400 base() *ModuleBase
Inseob Kimeec88e12020-01-22 11:11:29 +0900401 Disable()
Dan Willemsen0effe062015-11-30 16:06:01 -0800402 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700403 Target() Target
Anton Hansson1ee62c02020-06-30 11:51:53 +0100404 Owner() string
Dan Willemsen782a2d12015-12-21 14:55:28 -0800405 InstallInData() bool
Jaewoong Jung0949f312019-09-11 10:25:18 -0700406 InstallInTestcases() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700407 InstallInSanitizerDir() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800408 InstallInRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700409 InstallInVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900410 InstallInRecovery() bool
Colin Cross90ba5f42019-10-02 11:10:58 -0700411 InstallInRoot() bool
Colin Cross607d8582019-07-29 16:44:46 -0700412 InstallBypassMake() bool
Jiyong Park87788b52020-09-01 12:37:45 +0900413 InstallForceOS() (*OsType, *ArchType)
Colin Crossa2f296f2016-11-29 15:16:18 -0800414 SkipInstall()
Ulya Trafimovichb28cc372020-01-13 15:18:16 +0000415 IsSkipInstall() bool
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100416 MakeUninstallable()
Liz Kammer5ca3a622020-08-05 15:40:41 -0700417 ReplacedByPrebuilt()
418 IsReplacedByPrebuilt() bool
Jiyong Park374510b2018-03-19 18:23:01 +0900419 ExportedToMake() bool
Inseob Kim8471cda2019-11-15 09:59:12 +0900420 InitRc() Paths
421 VintfFragments() Paths
Bob Badoura75b0572020-02-18 20:21:55 -0800422 NoticeFiles() Paths
Colin Cross36242852017-06-23 15:06:31 -0700423
424 AddProperties(props ...interface{})
425 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700426
Colin Crossae887032017-10-23 17:16:14 -0700427 BuildParamsForTests() []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -0800428 RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800429 VariablesForTests() map[string]string
Paul Duffine2453c72019-05-31 14:00:04 +0100430
Colin Cross9a362232019-07-01 15:32:45 -0700431 // String returns a string that includes the module name and variants for printing during debugging.
432 String() string
433
Paul Duffine2453c72019-05-31 14:00:04 +0100434 // Get the qualified module id for this module.
435 qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName
436
437 // Get information about the properties that can contain visibility rules.
438 visibilityProperties() []visibilityProperty
Paul Duffin63c6e182019-07-24 14:24:38 +0100439
Jiyong Park6a8cf5f2019-12-30 16:31:09 +0900440 RequiredModuleNames() []string
441 HostRequiredModuleNames() []string
442 TargetRequiredModuleNames() []string
Colin Cross897266e2020-02-13 13:22:08 -0800443
Jiyong Park4dc2a1a2020-09-28 17:46:22 +0900444 FilesToInstall() InstallPaths
Jiyong Park073ea552020-11-09 14:08:34 +0900445 PackagingSpecs() []PackagingSpec
Colin Crossffe6b9d2020-12-01 15:40:06 -0800446
447 // TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
448 // dependencies with dependency tags for which IsInstallDepNeeded() returns true.
449 TransitivePackagingSpecs() []PackagingSpec
Paul Duffine2453c72019-05-31 14:00:04 +0100450}
451
452// Qualified id for a module
453type qualifiedModuleName struct {
454 // The package (i.e. directory) in which the module is defined, without trailing /
455 pkg string
456
457 // The name of the module, empty string if package.
458 name string
459}
460
461func (q qualifiedModuleName) String() string {
462 if q.name == "" {
463 return "//" + q.pkg
464 }
465 return "//" + q.pkg + ":" + q.name
466}
467
Paul Duffine484f472019-06-20 16:38:08 +0100468func (q qualifiedModuleName) isRootPackage() bool {
469 return q.pkg == "" && q.name == ""
470}
471
Paul Duffine2453c72019-05-31 14:00:04 +0100472// Get the id for the package containing this module.
473func (q qualifiedModuleName) getContainingPackageId() qualifiedModuleName {
474 pkg := q.pkg
475 if q.name == "" {
Paul Duffine484f472019-06-20 16:38:08 +0100476 if pkg == "" {
477 panic(fmt.Errorf("Cannot get containing package id of root package"))
478 }
479
480 index := strings.LastIndex(pkg, "/")
481 if index == -1 {
482 pkg = ""
483 } else {
484 pkg = pkg[:index]
485 }
Paul Duffine2453c72019-05-31 14:00:04 +0100486 }
487 return newPackageId(pkg)
488}
489
490func newPackageId(pkg string) qualifiedModuleName {
491 // A qualified id for a package module has no name.
492 return qualifiedModuleName{pkg: pkg, name: ""}
Colin Cross3f40fa42015-01-30 17:27:36 -0800493}
494
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000495type Dist struct {
496 // Copy the output of this module to the $DIST_DIR when `dist` is specified on the
497 // command line and any of these targets are also on the command line, or otherwise
498 // built
499 Targets []string `android:"arch_variant"`
500
501 // The name of the output artifact. This defaults to the basename of the output of
502 // the module.
503 Dest *string `android:"arch_variant"`
504
505 // The directory within the dist directory to store the artifact. Defaults to the
506 // top level directory ("").
507 Dir *string `android:"arch_variant"`
508
509 // A suffix to add to the artifact file name (before any extension).
510 Suffix *string `android:"arch_variant"`
511
Paul Duffin74f05592020-11-25 16:37:46 +0000512 // A string tag to select the OutputFiles associated with the tag.
513 //
514 // If no tag is specified then it will select the default dist paths provided
515 // by the module type. If a tag of "" is specified then it will return the
516 // default output files provided by the modules, i.e. the result of calling
517 // OutputFiles("").
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000518 Tag *string `android:"arch_variant"`
519}
520
Colin Crossfc754582016-05-17 16:34:16 -0700521type nameProperties struct {
522 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800523 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700524}
525
Colin Cross08d6f8f2020-11-19 02:33:19 +0000526type commonProperties struct {
Dan Willemsen0effe062015-11-30 16:06:01 -0800527 // emit build rules for this module
Paul Duffin54d9bb72020-02-12 10:20:56 +0000528 //
529 // Disabling a module should only be done for those modules that cannot be built
530 // in the current environment. Modules that can build in the current environment
531 // but are not usually required (e.g. superceded by a prebuilt) should not be
532 // disabled as that will prevent them from being built by the checkbuild target
533 // and so prevent early detection of changes that have broken those modules.
Dan Willemsen0effe062015-11-30 16:06:01 -0800534 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800535
Paul Duffin2e61fa62019-03-28 14:10:57 +0000536 // Controls the visibility of this module to other modules. Allowable values are one or more of
537 // these formats:
538 //
539 // ["//visibility:public"]: Anyone can use this module.
540 // ["//visibility:private"]: Only rules in the module's package (not its subpackages) can use
541 // this module.
Paul Duffin51084ff2020-05-05 19:19:22 +0100542 // ["//visibility:override"]: Discards any rules inherited from defaults or a creating module.
543 // Can only be used at the beginning of a list of visibility rules.
Paul Duffin2e61fa62019-03-28 14:10:57 +0000544 // ["//some/package:__pkg__", "//other/package:__pkg__"]: Only modules in some/package and
545 // other/package (defined in some/package/*.bp and other/package/*.bp) have access to
546 // this module. Note that sub-packages do not have access to the rule; for example,
547 // //some/package/foo:bar or //other/package/testing:bla wouldn't have access. __pkg__
548 // is a special module and must be used verbatim. It represents all of the modules in the
549 // package.
550 // ["//project:__subpackages__", "//other:__subpackages__"]: Only modules in packages project
551 // or other or in one of their sub-packages have access to this module. For example,
552 // //project:rule, //project/library:lib or //other/testing/internal:munge are allowed
553 // to depend on this rule (but not //independent:evil)
554 // ["//project"]: This is shorthand for ["//project:__pkg__"]
555 // [":__subpackages__"]: This is shorthand for ["//project:__subpackages__"] where
556 // //project is the module's package. e.g. using [":__subpackages__"] in
557 // packages/apps/Settings/Android.bp is equivalent to
558 // //packages/apps/Settings:__subpackages__.
559 // ["//visibility:legacy_public"]: The default visibility, behaves as //visibility:public
560 // for now. It is an error if it is used in a module.
Paul Duffine2453c72019-05-31 14:00:04 +0100561 //
562 // If a module does not specify the `visibility` property then it uses the
563 // `default_visibility` property of the `package` module in the module's package.
564 //
565 // If the `default_visibility` property is not set for the module's package then
Paul Duffine484f472019-06-20 16:38:08 +0100566 // it will use the `default_visibility` of its closest ancestor package for which
567 // a `default_visibility` property is specified.
568 //
569 // If no `default_visibility` property can be found then the module uses the
570 // global default of `//visibility:legacy_public`.
Paul Duffine2453c72019-05-31 14:00:04 +0100571 //
Paul Duffin95d53b52019-07-24 13:45:05 +0100572 // The `visibility` property has no effect on a defaults module although it does
573 // apply to any non-defaults module that uses it. To set the visibility of a
574 // defaults module, use the `defaults_visibility` property on the defaults module;
575 // not to be confused with the `default_visibility` property on the package module.
576 //
Paul Duffin2e61fa62019-03-28 14:10:57 +0000577 // See https://android.googlesource.com/platform/build/soong/+/master/README.md#visibility for
578 // more details.
579 Visibility []string
580
Colin Cross7d5136f2015-05-11 13:39:40 -0700581 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800582 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
583 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
Roland Levillain24bb2e62020-09-22 11:18:38 +0000584 // platform).
Colin Cross7d716ba2017-11-01 10:38:29 -0700585 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700586
587 Target struct {
588 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700589 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700590 }
591 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700592 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700593 }
594 }
595
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000596 // If set to true then the archMutator will create variants for each arch specific target
597 // (e.g. 32/64) that the module is required to produce. If set to false then it will only
598 // create a variant for the architecture and will list the additional arch specific targets
599 // that the variant needs to produce in the CompileMultiTargets property.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700600 UseTargetVariants bool `blueprint:"mutated"`
601 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800602
Dan Willemsen782a2d12015-12-21 14:55:28 -0800603 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700604 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800605
Colin Cross55708f32017-03-20 13:23:34 -0700606 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700607 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700608
Jiyong Park2db76922017-11-08 16:03:48 +0900609 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
610 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
611 // Use `soc_specific` instead for better meaning.
Colin Cross7d716ba2017-11-01 10:38:29 -0700612 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700613
Jiyong Park2db76922017-11-08 16:03:48 +0900614 // whether this module is specific to an SoC (System-On-a-Chip). When set to true,
615 // it is installed into /vendor (or /system/vendor if vendor partition does not exist).
616 Soc_specific *bool
617
618 // whether this module is specific to a device, not only for SoC, but also for off-chip
619 // peripherals. When set to true, it is installed into /odm (or /vendor/odm if odm partition
620 // does not exist, or /system/vendor/odm if both odm and vendor partitions do not exist).
621 // This implies `soc_specific:true`.
622 Device_specific *bool
623
624 // whether this module is specific to a software configuration of a product (e.g. country,
Jaekyun Seok5cfbfbb2018-01-10 19:00:15 +0900625 // network operator, etc). When set to true, it is installed into /product (or
626 // /system/product if product partition does not exist).
Jiyong Park2db76922017-11-08 16:03:48 +0900627 Product_specific *bool
628
Justin Yund5f6c822019-06-25 16:47:17 +0900629 // whether this module extends system. When set to true, it is installed into /system_ext
630 // (or /system/system_ext if system_ext partition does not exist).
631 System_ext_specific *bool
632
Jiyong Parkf9332f12018-02-01 00:54:12 +0900633 // Whether this module is installed to recovery partition
634 Recovery *bool
635
Yifan Hong1b3348d2020-01-21 15:53:22 -0800636 // Whether this module is installed to ramdisk
637 Ramdisk *bool
638
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700639 // Whether this module is installed to vendor ramdisk
640 Vendor_ramdisk *bool
641
dimitry1f33e402019-03-26 12:39:31 +0100642 // Whether this module is built for non-native architecures (also known as native bridge binary)
643 Native_bridge_supported *bool `android:"arch_variant"`
644
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700645 // init.rc files to be installed if this module is installed
Colin Cross0bab8772020-09-25 14:01:21 -0700646 Init_rc []string `android:"arch_variant,path"`
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700647
Steven Moreland57a23d22018-04-04 15:42:19 -0700648 // VINTF manifest fragments to be installed if this module is installed
Colin Cross27b922f2019-03-04 22:35:41 -0800649 Vintf_fragments []string `android:"path"`
Steven Moreland57a23d22018-04-04 15:42:19 -0700650
Chris Wolfe998306e2016-08-15 14:47:23 -0400651 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700652 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400653
Sasha Smundakb6d23052019-04-01 18:37:36 -0700654 // names of other modules to install on host if this module is installed
655 Host_required []string `android:"arch_variant"`
656
657 // names of other modules to install on target if this module is installed
658 Target_required []string `android:"arch_variant"`
659
Colin Cross5aac3622017-08-31 15:07:09 -0700660 // relative path to a file to include in the list of notices for the device
Colin Cross27b922f2019-03-04 22:35:41 -0800661 Notice *string `android:"path"`
Colin Cross5aac3622017-08-31 15:07:09 -0700662
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000663 // The OsType of artifacts that this module variant is responsible for creating.
664 //
665 // Set by osMutator
666 CompileOS OsType `blueprint:"mutated"`
667
668 // The Target of artifacts that this module variant is responsible for creating.
669 //
670 // Set by archMutator
671 CompileTarget Target `blueprint:"mutated"`
672
673 // The additional arch specific targets (e.g. 32/64 bit) that this module variant is
674 // responsible for creating.
675 //
676 // By default this is nil as, where necessary, separate variants are created for the
677 // different multilib types supported and that information is encapsulated in the
678 // CompileTarget so the module variant simply needs to create artifacts for that.
679 //
680 // However, if UseTargetVariants is set to false (e.g. by
681 // InitAndroidMultiTargetsArchModule) then no separate variants are created for the
682 // multilib targets. Instead a single variant is created for the architecture and
683 // this contains the multilib specific targets that this variant should create.
684 //
685 // Set by archMutator
Colin Crossee0bc3b2018-10-02 22:01:37 -0700686 CompileMultiTargets []Target `blueprint:"mutated"`
Paul Duffinca7f0ef2020-02-25 15:50:49 +0000687
688 // True if the module variant's CompileTarget is the primary target
689 //
690 // Set by archMutator
691 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800692
693 // Set by InitAndroidModule
694 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700695 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700696
Paul Duffin1356d8c2020-02-25 19:26:33 +0000697 // If set to true then a CommonOS variant will be created which will have dependencies
698 // on all its OsType specific variants. Used by sdk/module_exports to create a snapshot
699 // that covers all os and architecture variants.
700 //
701 // The OsType specific variants can be retrieved by calling
702 // GetOsSpecificVariantsOfCommonOSVariant
703 //
704 // Set at module initialization time by calling InitCommonOSAndroidMultiTargetsArchModule
705 CreateCommonOSVariant bool `blueprint:"mutated"`
706
707 // If set to true then this variant is the CommonOS variant that has dependencies on its
708 // OsType specific variants.
709 //
710 // Set by osMutator.
711 CommonOSVariant bool `blueprint:"mutated"`
712
Colin Crossce75d2c2016-10-06 16:12:58 -0700713 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800714
Liz Kammer5ca3a622020-08-05 15:40:41 -0700715 // Whether the module has been replaced by a prebuilt
716 ReplacedByPrebuilt bool `blueprint:"mutated"`
717
Justin Yun32f053b2020-07-31 23:07:17 +0900718 // Disabled by mutators. If set to true, it overrides Enabled property.
719 ForcedDisabled bool `blueprint:"mutated"`
720
Jeff Gaston088e29e2017-11-29 16:47:17 -0800721 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross6c4f21f2019-06-06 15:41:36 -0700722
723 MissingDeps []string `blueprint:"mutated"`
Colin Cross9a362232019-07-01 15:32:45 -0700724
725 // Name and variant strings stored by mutators to enable Module.String()
726 DebugName string `blueprint:"mutated"`
727 DebugMutators []string `blueprint:"mutated"`
728 DebugVariations []string `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800729
Colin Crossa6845402020-11-16 15:08:19 -0800730 // ImageVariation is set by ImageMutator to specify which image this variation is for,
731 // for example "" for core or "recovery" for recovery. It will often be set to one of the
732 // constants in image.go, but can also be set to a custom value by individual module types.
Colin Cross7228ecd2019-11-18 16:00:16 -0800733 ImageVariation string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800734}
735
Paul Duffined875132020-09-02 13:08:57 +0100736type distProperties struct {
737 // configuration to distribute output files from this module to the distribution
738 // directory (default: $OUT/dist, configurable with $DIST_DIR)
739 Dist Dist `android:"arch_variant"`
740
741 // a list of configurations to distribute output files from this module to the
742 // distribution directory (default: $OUT/dist, configurable with $DIST_DIR)
743 Dists []Dist `android:"arch_variant"`
744}
745
Paul Duffin74f05592020-11-25 16:37:46 +0000746// The key to use in TaggedDistFiles when a Dist structure does not specify a
747// tag property. This intentionally does not use "" as the default because that
748// would mean that an empty tag would have a different meaning when used in a dist
749// structure that when used to reference a specific set of output paths using the
750// :module{tag} syntax, which passes tag to the OutputFiles(tag) method.
751const DefaultDistTag = "<default-dist-tag>"
752
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000753// A map of OutputFile tag keys to Paths, for disting purposes.
754type TaggedDistFiles map[string]Paths
755
Paul Duffin74f05592020-11-25 16:37:46 +0000756// addPathsForTag adds a mapping from the tag to the paths. If the map is nil
757// then it will create a map, update it and then return it. If a mapping already
758// exists for the tag then the paths are appended to the end of the current list
759// of paths, ignoring any duplicates.
760func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles {
761 if t == nil {
762 t = make(TaggedDistFiles)
763 }
764
765 for _, distFile := range paths {
766 if distFile != nil && !t[tag].containsPath(distFile) {
767 t[tag] = append(t[tag], distFile)
768 }
769 }
770
771 return t
772}
773
774// merge merges the entries from the other TaggedDistFiles object into this one.
775// If the TaggedDistFiles is nil then it will create a new instance, merge the
776// other into it, and then return it.
777func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles {
778 for tag, paths := range other {
779 t = t.addPathsForTag(tag, paths...)
780 }
781
782 return t
783}
784
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000785func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles {
Jingwen Chen7b27ca72020-07-24 09:13:49 +0000786 for _, path := range paths {
787 if path == nil {
788 panic("The path to a dist file cannot be nil.")
789 }
790 }
791
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000792 // The default OutputFile tag is the empty "" string.
Paul Duffin74f05592020-11-25 16:37:46 +0000793 return TaggedDistFiles{DefaultDistTag: paths}
Jingwen Chen40fd90a2020-06-15 05:24:19 +0000794}
795
Colin Cross3f40fa42015-01-30 17:27:36 -0800796type hostAndDeviceProperties struct {
Colin Cross4e81d702018-11-09 10:36:55 -0800797 // If set to true, build a variant of the module for the host. Defaults to false.
798 Host_supported *bool
799
800 // If set to true, build a variant of the module for the device. Defaults to true.
Colin Crossa4190c12016-07-12 13:11:25 -0700801 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800802}
803
Colin Crossc472d572015-03-17 15:06:21 -0700804type Multilib string
805
806const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800807 MultilibBoth Multilib = "both"
808 MultilibFirst Multilib = "first"
809 MultilibCommon Multilib = "common"
810 MultilibCommonFirst Multilib = "common_first"
811 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700812)
813
Colin Crossa1ad8d12016-06-01 17:09:44 -0700814type HostOrDeviceSupported int
815
816const (
Colin Cross34037c62020-11-17 13:19:17 -0800817 hostSupported = 1 << iota
818 hostCrossSupported
819 deviceSupported
820 hostDefault
821 deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700822
823 // Host and HostCross are built by default. Device is not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800824 HostSupported = hostSupported | hostCrossSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700825
826 // Host is built by default. HostCross and Device are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800827 HostSupportedNoCross = hostSupported | hostDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700828
829 // Device is built by default. Host and HostCross are not supported.
Colin Cross34037c62020-11-17 13:19:17 -0800830 DeviceSupported = deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700831
832 // Device is built by default. Host and HostCross are supported.
Colin Cross34037c62020-11-17 13:19:17 -0800833 HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700834
835 // Host, HostCross, and Device are built by default.
Colin Cross34037c62020-11-17 13:19:17 -0800836 HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
837 deviceSupported | deviceDefault
Dan Albert0981b5c2018-08-02 13:46:35 -0700838
839 // Nothing is supported. This is not exposed to the user, but used to mark a
840 // host only module as unsupported when the module type is not supported on
841 // the host OS. E.g. benchmarks are supported on Linux but not Darwin.
Colin Cross34037c62020-11-17 13:19:17 -0800842 NeitherHostNorDeviceSupported = 0
Colin Crossa1ad8d12016-06-01 17:09:44 -0700843)
844
Jiyong Park2db76922017-11-08 16:03:48 +0900845type moduleKind int
846
847const (
848 platformModule moduleKind = iota
849 deviceSpecificModule
850 socSpecificModule
851 productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +0900852 systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +0900853)
854
855func (k moduleKind) String() string {
856 switch k {
857 case platformModule:
858 return "platform"
859 case deviceSpecificModule:
860 return "device-specific"
861 case socSpecificModule:
862 return "soc-specific"
863 case productSpecificModule:
864 return "product-specific"
Justin Yund5f6c822019-06-25 16:47:17 +0900865 case systemExtSpecificModule:
866 return "systemext-specific"
Jiyong Park2db76922017-11-08 16:03:48 +0900867 default:
868 panic(fmt.Errorf("unknown module kind %d", k))
869 }
870}
871
Colin Cross9d34f352019-11-22 16:03:51 -0800872func initAndroidModuleBase(m Module) {
873 m.base().module = m
874}
875
Colin Crossa6845402020-11-16 15:08:19 -0800876// InitAndroidModule initializes the Module as an Android module that is not architecture-specific.
877// It adds the common properties, for example "name" and "enabled".
Colin Cross36242852017-06-23 15:06:31 -0700878func InitAndroidModule(m Module) {
Colin Cross9d34f352019-11-22 16:03:51 -0800879 initAndroidModuleBase(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800880 base := m.base()
Colin Cross5049f022015-03-18 13:28:46 -0700881
Colin Cross36242852017-06-23 15:06:31 -0700882 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700883 &base.nameProperties,
Paul Duffined875132020-09-02 13:08:57 +0100884 &base.commonProperties,
885 &base.distProperties)
Colin Cross18c46802019-09-24 22:19:02 -0700886
Colin Crosseabaedd2020-02-06 17:01:55 -0800887 initProductVariableModule(m)
Colin Cross18c46802019-09-24 22:19:02 -0700888
Colin Crossa3a97412019-03-18 12:24:29 -0700889 base.generalProperties = m.GetProperties()
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -0700890 base.customizableProperties = m.GetProperties()
Paul Duffin63c6e182019-07-24 14:24:38 +0100891
892 // The default_visibility property needs to be checked and parsed by the visibility module during
Paul Duffin5ec73ec2020-05-01 17:52:01 +0100893 // its checking and parsing phases so make it the primary visibility property.
894 setPrimaryVisibilityProperty(m, "visibility", &base.commonProperties.Visibility)
Colin Cross5049f022015-03-18 13:28:46 -0700895}
896
Colin Crossa6845402020-11-16 15:08:19 -0800897// InitAndroidArchModule initializes the Module as an Android module that is architecture-specific.
898// It adds the common properties, for example "name" and "enabled", as well as runtime generated
899// property structs for architecture-specific versions of generic properties tagged with
900// `android:"arch_variant"`.
901//
902// InitAndroidModule should not be called if InitAndroidArchModule was called.
Colin Cross36242852017-06-23 15:06:31 -0700903func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
904 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700905
906 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800907 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700908 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700909 base.commonProperties.ArchSpecific = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700910 base.commonProperties.UseTargetVariants = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800911
Colin Cross34037c62020-11-17 13:19:17 -0800912 if hod&hostSupported != 0 && hod&deviceSupported != 0 {
Colin Cross36242852017-06-23 15:06:31 -0700913 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800914 }
915
Colin Crossa6845402020-11-16 15:08:19 -0800916 initArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800917}
918
Colin Crossa6845402020-11-16 15:08:19 -0800919// InitAndroidMultiTargetsArchModule initializes the Module as an Android module that is
920// architecture-specific, but will only have a single variant per OS that handles all the
921// architectures simultaneously. The list of Targets that it must handle will be available from
922// ModuleContext.MultiTargets. It adds the common properties, for example "name" and "enabled", as
923// well as runtime generated property structs for architecture-specific versions of generic
924// properties tagged with `android:"arch_variant"`.
925//
926// InitAndroidModule or InitAndroidArchModule should not be called if
927// InitAndroidMultiTargetsArchModule was called.
Colin Crossee0bc3b2018-10-02 22:01:37 -0700928func InitAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
929 InitAndroidArchModule(m, hod, defaultMultilib)
930 m.base().commonProperties.UseTargetVariants = false
931}
932
Colin Crossa6845402020-11-16 15:08:19 -0800933// InitCommonOSAndroidMultiTargetsArchModule initializes the Module as an Android module that is
934// architecture-specific, but will only have a single variant per OS that handles all the
935// architectures simultaneously, and will also have an additional CommonOS variant that has
936// dependencies on all the OS-specific variants. The list of Targets that it must handle will be
937// available from ModuleContext.MultiTargets. It adds the common properties, for example "name" and
938// "enabled", as well as runtime generated property structs for architecture-specific versions of
939// generic properties tagged with `android:"arch_variant"`.
940//
941// InitAndroidModule, InitAndroidArchModule or InitAndroidMultiTargetsArchModule should not be
942// called if InitCommonOSAndroidMultiTargetsArchModule was called.
Paul Duffin1356d8c2020-02-25 19:26:33 +0000943func InitCommonOSAndroidMultiTargetsArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
944 InitAndroidArchModule(m, hod, defaultMultilib)
945 m.base().commonProperties.UseTargetVariants = false
946 m.base().commonProperties.CreateCommonOSVariant = true
947}
948
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800949// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800950// modules. It should be included as an anonymous field in every module
951// struct definition. InitAndroidModule should then be called from the module's
952// factory function, and the return values from InitAndroidModule should be
953// returned from the factory function.
954//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800955// The ModuleBase type is responsible for implementing the GenerateBuildActions
956// method to support the blueprint.Module interface. This method will then call
957// the module's GenerateAndroidBuildActions method once for each build variant
Colin Cross25de6c32019-06-06 14:29:25 -0700958// that is to be built. GenerateAndroidBuildActions is passed a ModuleContext
959// rather than the usual blueprint.ModuleContext.
960// ModuleContext exposes extra functionality specific to the Android build
Colin Cross3f40fa42015-01-30 17:27:36 -0800961// system including details about the particular build variant that is to be
962// generated.
963//
964// For example:
965//
966// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800967// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800968// )
969//
970// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800971// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800972// properties struct {
973// MyProperty string
974// }
975// }
976//
Colin Cross36242852017-06-23 15:06:31 -0700977// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800978// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700979// m.AddProperties(&m.properties)
980// android.InitAndroidModule(m)
981// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800982// }
983//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800984// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800985// // Get the CPU architecture for the current build variant.
986// variantArch := ctx.Arch()
987//
988// // ...
989// }
Colin Cross635c3b02016-05-18 15:37:25 -0700990type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800991 // Putting the curiously recurring thing pointing to the thing that contains
992 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700993 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700994 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800995
Colin Crossfc754582016-05-17 16:34:16 -0700996 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800997 commonProperties commonProperties
Paul Duffined875132020-09-02 13:08:57 +0100998 distProperties distProperties
Colin Cross18c46802019-09-24 22:19:02 -0700999 variableProperties interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001000 hostAndDeviceProperties hostAndDeviceProperties
1001 generalProperties []interface{}
Colin Crossc17727d2018-10-24 12:42:09 -07001002 archProperties [][]interface{}
Colin Crossa120ec12016-08-19 16:07:38 -07001003 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -08001004
Paul Duffin63c6e182019-07-24 14:24:38 +01001005 // Information about all the properties on the module that contains visibility rules that need
1006 // checking.
1007 visibilityPropertyInfo []visibilityProperty
1008
1009 // The primary visibility property, may be nil, that controls access to the module.
1010 primaryVisibilityProperty visibilityProperty
1011
Colin Crossffe6b9d2020-12-01 15:40:06 -08001012 noAddressSanitizer bool
1013 installFiles InstallPaths
1014 installFilesDepSet *installPathsDepSet
1015 checkbuildFiles Paths
1016 packagingSpecs []PackagingSpec
1017 packagingSpecsDepSet *packagingSpecsDepSet
1018 noticeFiles Paths
1019 phonies map[string]Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001020
Paul Duffinaf970a22020-11-23 23:32:56 +00001021 // The files to copy to the dist as explicitly specified in the .bp file.
1022 distFiles TaggedDistFiles
1023
Colin Cross1f8c52b2015-06-16 16:38:17 -07001024 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
1025 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -08001026 installTarget WritablePath
1027 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -07001028 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -07001029
Colin Cross178a5092016-09-13 13:42:32 -07001030 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -07001031
1032 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -07001033
1034 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001035 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001036 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001037 variables map[string]string
Colin Crossa9d8bee2018-10-02 13:59:46 -07001038
Inseob Kim8471cda2019-11-15 09:59:12 +09001039 initRcPaths Paths
1040 vintfFragmentsPaths Paths
1041
Jiyong Park1613e552020-09-14 19:43:17 +09001042 prefer32 func(ctx BaseModuleContext, base *ModuleBase, os OsType) bool
Colin Cross36242852017-06-23 15:06:31 -07001043}
1044
Paul Duffin44f1d842020-06-26 20:17:02 +01001045func (m *ModuleBase) ComponentDepsMutator(BottomUpMutatorContext) {}
1046
Colin Cross4157e882019-06-06 16:57:04 -07001047func (m *ModuleBase) DepsMutator(BottomUpMutatorContext) {}
Colin Cross5f692ec2019-02-01 16:53:07 -08001048
Colin Cross4157e882019-06-06 16:57:04 -07001049func (m *ModuleBase) AddProperties(props ...interface{}) {
1050 m.registerProps = append(m.registerProps, props...)
Colin Cross36242852017-06-23 15:06:31 -07001051}
1052
Colin Cross4157e882019-06-06 16:57:04 -07001053func (m *ModuleBase) GetProperties() []interface{} {
1054 return m.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -08001055}
1056
Colin Cross4157e882019-06-06 16:57:04 -07001057func (m *ModuleBase) BuildParamsForTests() []BuildParams {
1058 return m.buildParams
Colin Crosscec81712017-07-13 14:43:27 -07001059}
1060
Colin Cross4157e882019-06-06 16:57:04 -07001061func (m *ModuleBase) RuleParamsForTests() map[blueprint.Rule]blueprint.RuleParams {
1062 return m.ruleParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001063}
1064
Colin Cross4157e882019-06-06 16:57:04 -07001065func (m *ModuleBase) VariablesForTests() map[string]string {
1066 return m.variables
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001067}
1068
Jiyong Park1613e552020-09-14 19:43:17 +09001069func (m *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, os OsType) bool) {
Colin Cross4157e882019-06-06 16:57:04 -07001070 m.prefer32 = prefer32
Colin Crossa9d8bee2018-10-02 13:59:46 -07001071}
1072
Colin Crossce75d2c2016-10-06 16:12:58 -07001073// Name returns the name of the module. It may be overridden by individual module types, for
1074// example prebuilts will prepend prebuilt_ to the name.
Colin Cross4157e882019-06-06 16:57:04 -07001075func (m *ModuleBase) Name() string {
1076 return String(m.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -07001077}
1078
Colin Cross9a362232019-07-01 15:32:45 -07001079// String returns a string that includes the module name and variants for printing during debugging.
1080func (m *ModuleBase) String() string {
1081 sb := strings.Builder{}
1082 sb.WriteString(m.commonProperties.DebugName)
1083 sb.WriteString("{")
1084 for i := range m.commonProperties.DebugMutators {
1085 if i != 0 {
1086 sb.WriteString(",")
1087 }
1088 sb.WriteString(m.commonProperties.DebugMutators[i])
1089 sb.WriteString(":")
1090 sb.WriteString(m.commonProperties.DebugVariations[i])
1091 }
1092 sb.WriteString("}")
1093 return sb.String()
1094}
1095
Colin Crossce75d2c2016-10-06 16:12:58 -07001096// BaseModuleName returns the name of the module as specified in the blueprints file.
Colin Cross4157e882019-06-06 16:57:04 -07001097func (m *ModuleBase) BaseModuleName() string {
1098 return String(m.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -07001099}
1100
Colin Cross4157e882019-06-06 16:57:04 -07001101func (m *ModuleBase) base() *ModuleBase {
1102 return m
Colin Cross3f40fa42015-01-30 17:27:36 -08001103}
1104
Paul Duffine2453c72019-05-31 14:00:04 +01001105func (m *ModuleBase) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName {
1106 return qualifiedModuleName{pkg: ctx.ModuleDir(), name: ctx.ModuleName()}
1107}
1108
1109func (m *ModuleBase) visibilityProperties() []visibilityProperty {
Paul Duffin63c6e182019-07-24 14:24:38 +01001110 return m.visibilityPropertyInfo
1111}
1112
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001113func (m *ModuleBase) Dists() []Dist {
Paul Duffined875132020-09-02 13:08:57 +01001114 if len(m.distProperties.Dist.Targets) > 0 {
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001115 // Make a copy of the underlying Dists slice to protect against
1116 // backing array modifications with repeated calls to this method.
Paul Duffined875132020-09-02 13:08:57 +01001117 distsCopy := append([]Dist(nil), m.distProperties.Dists...)
1118 return append(distsCopy, m.distProperties.Dist)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001119 } else {
Paul Duffined875132020-09-02 13:08:57 +01001120 return m.distProperties.Dists
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001121 }
1122}
1123
1124func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles {
Paul Duffin74f05592020-11-25 16:37:46 +00001125 var distFiles TaggedDistFiles
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001126 for _, dist := range m.Dists() {
Paul Duffin74f05592020-11-25 16:37:46 +00001127 // If no tag is specified then it means to use the default dist paths so use
1128 // the special tag name which represents that.
1129 tag := proptools.StringDefault(dist.Tag, DefaultDistTag)
1130
Paul Duffinaf970a22020-11-23 23:32:56 +00001131 if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
1132 // Call the OutputFiles(tag) method to get the paths associated with the tag.
1133 distFilesForTag, err := outputFileProducer.OutputFiles(tag)
Paul Duffin74f05592020-11-25 16:37:46 +00001134
Paul Duffinaf970a22020-11-23 23:32:56 +00001135 // If the tag was not supported and is not DefaultDistTag then it is an error.
1136 // Failing to find paths for DefaultDistTag is not an error. It just means
1137 // that the module type requires the legacy behavior.
1138 if err != nil && tag != DefaultDistTag {
1139 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1140 }
1141
1142 distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
1143 } else if tag != DefaultDistTag {
1144 // If the tag was specified then it is an error if the module does not
1145 // implement OutputFileProducer because there is no other way of accessing
1146 // the paths for the specified tag.
1147 ctx.PropertyErrorf("dist.tag",
1148 "tag %s not supported because the module does not implement OutputFileProducer", tag)
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001149 }
Jingwen Chen40fd90a2020-06-15 05:24:19 +00001150 }
1151
1152 return distFiles
1153}
1154
Colin Cross4157e882019-06-06 16:57:04 -07001155func (m *ModuleBase) Target() Target {
1156 return m.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -08001157}
1158
Colin Cross4157e882019-06-06 16:57:04 -07001159func (m *ModuleBase) TargetPrimary() bool {
1160 return m.commonProperties.CompilePrimary
Colin Cross8b74d172016-09-13 09:59:14 -07001161}
1162
Colin Cross4157e882019-06-06 16:57:04 -07001163func (m *ModuleBase) MultiTargets() []Target {
1164 return m.commonProperties.CompileMultiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07001165}
1166
Colin Cross4157e882019-06-06 16:57:04 -07001167func (m *ModuleBase) Os() OsType {
1168 return m.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -08001169}
1170
Colin Cross4157e882019-06-06 16:57:04 -07001171func (m *ModuleBase) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09001172 return m.Os().Class == Host
Dan Willemsen97750522016-02-09 17:43:51 -08001173}
1174
Yo Chiangbba545e2020-06-09 16:15:37 +08001175func (m *ModuleBase) Device() bool {
1176 return m.Os().Class == Device
1177}
1178
Colin Cross4157e882019-06-06 16:57:04 -07001179func (m *ModuleBase) Arch() Arch {
1180 return m.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -08001181}
1182
Colin Cross4157e882019-06-06 16:57:04 -07001183func (m *ModuleBase) ArchSpecific() bool {
1184 return m.commonProperties.ArchSpecific
Dan Willemsen0b24c742016-10-04 15:13:37 -07001185}
1186
Paul Duffin1356d8c2020-02-25 19:26:33 +00001187// True if the current variant is a CommonOS variant, false otherwise.
1188func (m *ModuleBase) IsCommonOSVariant() bool {
1189 return m.commonProperties.CommonOSVariant
1190}
1191
Colin Cross34037c62020-11-17 13:19:17 -08001192// supportsTarget returns true if the given Target is supported by the current module.
1193func (m *ModuleBase) supportsTarget(target Target) bool {
1194 switch target.Os.Class {
1195 case Host:
1196 if target.HostCross {
1197 return m.HostCrossSupported()
1198 } else {
1199 return m.HostSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001200 }
Colin Cross34037c62020-11-17 13:19:17 -08001201 case Device:
1202 return m.DeviceSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -07001203 default:
Jiyong Park1613e552020-09-14 19:43:17 +09001204 return false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001205 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001206}
1207
Colin Cross34037c62020-11-17 13:19:17 -08001208// DeviceSupported returns true if the current module is supported and enabled for device targets,
1209// i.e. the factory method set the HostOrDeviceSupported value to include device support and
1210// the device support is enabled by default or enabled by the device_supported property.
Colin Cross4157e882019-06-06 16:57:04 -07001211func (m *ModuleBase) DeviceSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001212 hod := m.commonProperties.HostOrDeviceSupported
1213 // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
1214 // value has the deviceDefault bit set.
1215 deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
1216 return hod&deviceSupported != 0 && deviceEnabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001217}
1218
Colin Cross34037c62020-11-17 13:19:17 -08001219// HostSupported returns true if the current module is supported and enabled for host targets,
1220// i.e. the factory method set the HostOrDeviceSupported value to include host support and
1221// the host support is enabled by default or enabled by the host_supported property.
Paul Duffine44358f2019-11-26 18:04:12 +00001222func (m *ModuleBase) HostSupported() bool {
Colin Cross34037c62020-11-17 13:19:17 -08001223 hod := m.commonProperties.HostOrDeviceSupported
1224 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1225 // value has the hostDefault bit set.
1226 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1227 return hod&hostSupported != 0 && hostEnabled
1228}
1229
1230// HostCrossSupported returns true if the current module is supported and enabled for host cross
1231// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
1232// support and the host cross support is enabled by default or enabled by the
1233// host_supported property.
1234func (m *ModuleBase) HostCrossSupported() bool {
1235 hod := m.commonProperties.HostOrDeviceSupported
1236 // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
1237 // value has the hostDefault bit set.
1238 hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
1239 return hod&hostCrossSupported != 0 && hostEnabled
Paul Duffine44358f2019-11-26 18:04:12 +00001240}
1241
Colin Cross4157e882019-06-06 16:57:04 -07001242func (m *ModuleBase) Platform() bool {
Justin Yund5f6c822019-06-25 16:47:17 +09001243 return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific()
Jiyong Parkc678ad32018-04-10 13:07:10 +09001244}
1245
Colin Cross4157e882019-06-06 16:57:04 -07001246func (m *ModuleBase) DeviceSpecific() bool {
1247 return Bool(m.commonProperties.Device_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001248}
1249
Colin Cross4157e882019-06-06 16:57:04 -07001250func (m *ModuleBase) SocSpecific() bool {
1251 return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001252}
1253
Colin Cross4157e882019-06-06 16:57:04 -07001254func (m *ModuleBase) ProductSpecific() bool {
1255 return Bool(m.commonProperties.Product_specific)
Jiyong Parkc678ad32018-04-10 13:07:10 +09001256}
1257
Justin Yund5f6c822019-06-25 16:47:17 +09001258func (m *ModuleBase) SystemExtSpecific() bool {
1259 return Bool(m.commonProperties.System_ext_specific)
Dario Frenifd05a742018-05-29 13:28:54 +01001260}
1261
Colin Crossc2d24052020-05-13 11:05:02 -07001262// RequiresStableAPIs returns true if the module will be installed to a partition that may
1263// be updated separately from the system image.
1264func (m *ModuleBase) RequiresStableAPIs(ctx BaseModuleContext) bool {
1265 return m.SocSpecific() || m.DeviceSpecific() ||
1266 (m.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface())
1267}
1268
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001269func (m *ModuleBase) PartitionTag(config DeviceConfig) string {
1270 partition := "system"
1271 if m.SocSpecific() {
1272 // A SoC-specific module could be on the vendor partition at
1273 // "vendor" or the system partition at "system/vendor".
1274 if config.VendorPath() == "vendor" {
1275 partition = "vendor"
1276 }
1277 } else if m.DeviceSpecific() {
1278 // A device-specific module could be on the odm partition at
1279 // "odm", the vendor partition at "vendor/odm", or the system
1280 // partition at "system/vendor/odm".
1281 if config.OdmPath() == "odm" {
1282 partition = "odm"
Ramy Medhat944839a2020-03-31 22:14:52 -04001283 } else if strings.HasPrefix(config.OdmPath(), "vendor/") {
Bill Peckhamfff3f8a2020-03-20 18:33:20 -07001284 partition = "vendor"
1285 }
1286 } else if m.ProductSpecific() {
1287 // A product-specific module could be on the product partition
1288 // at "product" or the system partition at "system/product".
1289 if config.ProductPath() == "product" {
1290 partition = "product"
1291 }
1292 } else if m.SystemExtSpecific() {
1293 // A system_ext-specific module could be on the system_ext
1294 // partition at "system_ext" or the system partition at
1295 // "system/system_ext".
1296 if config.SystemExtPath() == "system_ext" {
1297 partition = "system_ext"
1298 }
1299 }
1300 return partition
1301}
1302
Colin Cross4157e882019-06-06 16:57:04 -07001303func (m *ModuleBase) Enabled() bool {
Justin Yun32f053b2020-07-31 23:07:17 +09001304 if m.commonProperties.ForcedDisabled {
1305 return false
1306 }
Colin Cross08d6f8f2020-11-19 02:33:19 +00001307 if m.commonProperties.Enabled == nil {
1308 return !m.Os().DefaultDisabled
1309 }
1310 return *m.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -08001311}
1312
Inseob Kimeec88e12020-01-22 11:11:29 +09001313func (m *ModuleBase) Disable() {
Justin Yun32f053b2020-07-31 23:07:17 +09001314 m.commonProperties.ForcedDisabled = true
Inseob Kimeec88e12020-01-22 11:11:29 +09001315}
1316
Colin Cross4157e882019-06-06 16:57:04 -07001317func (m *ModuleBase) SkipInstall() {
1318 m.commonProperties.SkipInstall = true
Colin Crossce75d2c2016-10-06 16:12:58 -07001319}
1320
Ulya Trafimovichb28cc372020-01-13 15:18:16 +00001321func (m *ModuleBase) IsSkipInstall() bool {
1322 return m.commonProperties.SkipInstall == true
1323}
1324
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01001325// Similar to SkipInstall, but if the AndroidMk entry would set
1326// LOCAL_UNINSTALLABLE_MODULE then this variant may still output that entry
1327// rather than leaving it out altogether. That happens in cases where it would
1328// have other side effects, in particular when it adds a NOTICE file target,
1329// which other install targets might depend on.
1330func (m *ModuleBase) MakeUninstallable() {
1331 m.SkipInstall()
1332}
1333
Liz Kammer5ca3a622020-08-05 15:40:41 -07001334func (m *ModuleBase) ReplacedByPrebuilt() {
1335 m.commonProperties.ReplacedByPrebuilt = true
1336 m.SkipInstall()
1337}
1338
1339func (m *ModuleBase) IsReplacedByPrebuilt() bool {
1340 return m.commonProperties.ReplacedByPrebuilt
1341}
1342
Colin Cross4157e882019-06-06 16:57:04 -07001343func (m *ModuleBase) ExportedToMake() bool {
1344 return m.commonProperties.NamespaceExportedToMake
Jiyong Park374510b2018-03-19 18:23:01 +09001345}
1346
Colin Crosse9fe2942020-11-10 18:12:15 -08001347// computeInstallDeps finds the installed paths of all dependencies that have a dependency
1348// tag that is annotated as needing installation via the IsInstallDepNeeded method.
Colin Crossffe6b9d2020-12-01 15:40:06 -08001349func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*installPathsDepSet, []*packagingSpecsDepSet) {
Colin Cross5d583952020-11-24 16:21:24 -08001350 var installDeps []*installPathsDepSet
Colin Crossffe6b9d2020-12-01 15:40:06 -08001351 var packagingSpecs []*packagingSpecsDepSet
Colin Cross5d583952020-11-24 16:21:24 -08001352 ctx.VisitDirectDeps(func(dep Module) {
1353 if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) {
1354 installDeps = append(installDeps, dep.base().installFilesDepSet)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001355 packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet)
Colin Cross897266e2020-02-13 13:22:08 -08001356 }
1357 })
Colin Cross3f40fa42015-01-30 17:27:36 -08001358
Colin Crossffe6b9d2020-12-01 15:40:06 -08001359 return installDeps, packagingSpecs
Colin Cross3f40fa42015-01-30 17:27:36 -08001360}
1361
Jiyong Park4dc2a1a2020-09-28 17:46:22 +09001362func (m *ModuleBase) FilesToInstall() InstallPaths {
Colin Cross4157e882019-06-06 16:57:04 -07001363 return m.installFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001364}
1365
Jiyong Park073ea552020-11-09 14:08:34 +09001366func (m *ModuleBase) PackagingSpecs() []PackagingSpec {
1367 return m.packagingSpecs
1368}
1369
Colin Crossffe6b9d2020-12-01 15:40:06 -08001370func (m *ModuleBase) TransitivePackagingSpecs() []PackagingSpec {
1371 return m.packagingSpecsDepSet.ToList()
1372}
1373
Colin Cross4157e882019-06-06 16:57:04 -07001374func (m *ModuleBase) NoAddressSanitizer() bool {
1375 return m.noAddressSanitizer
Colin Cross3f40fa42015-01-30 17:27:36 -08001376}
1377
Colin Cross4157e882019-06-06 16:57:04 -07001378func (m *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -08001379 return false
1380}
1381
Jaewoong Jung0949f312019-09-11 10:25:18 -07001382func (m *ModuleBase) InstallInTestcases() bool {
1383 return false
1384}
1385
Colin Cross4157e882019-06-06 16:57:04 -07001386func (m *ModuleBase) InstallInSanitizerDir() bool {
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001387 return false
1388}
1389
Yifan Hong1b3348d2020-01-21 15:53:22 -08001390func (m *ModuleBase) InstallInRamdisk() bool {
1391 return Bool(m.commonProperties.Ramdisk)
1392}
1393
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001394func (m *ModuleBase) InstallInVendorRamdisk() bool {
1395 return Bool(m.commonProperties.Vendor_ramdisk)
1396}
1397
Colin Cross4157e882019-06-06 16:57:04 -07001398func (m *ModuleBase) InstallInRecovery() bool {
1399 return Bool(m.commonProperties.Recovery)
Jiyong Parkf9332f12018-02-01 00:54:12 +09001400}
1401
Colin Cross90ba5f42019-10-02 11:10:58 -07001402func (m *ModuleBase) InstallInRoot() bool {
1403 return false
1404}
1405
Colin Cross607d8582019-07-29 16:44:46 -07001406func (m *ModuleBase) InstallBypassMake() bool {
1407 return false
1408}
1409
Jiyong Park87788b52020-09-01 12:37:45 +09001410func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) {
1411 return nil, nil
Colin Cross6e359402020-02-10 15:29:54 -08001412}
1413
Colin Cross4157e882019-06-06 16:57:04 -07001414func (m *ModuleBase) Owner() string {
1415 return String(m.commonProperties.Owner)
Sundong Ahn4fd04bb2018-08-31 18:01:37 +09001416}
1417
Bob Badoura75b0572020-02-18 20:21:55 -08001418func (m *ModuleBase) NoticeFiles() Paths {
1419 return m.noticeFiles
Jiyong Park52818fc2019-03-18 12:01:38 +09001420}
1421
Colin Cross7228ecd2019-11-18 16:00:16 -08001422func (m *ModuleBase) setImageVariation(variant string) {
1423 m.commonProperties.ImageVariation = variant
1424}
1425
1426func (m *ModuleBase) ImageVariation() blueprint.Variation {
1427 return blueprint.Variation{
1428 Mutator: "image",
1429 Variation: m.base().commonProperties.ImageVariation,
1430 }
1431}
1432
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001433func (m *ModuleBase) getVariationByMutatorName(mutator string) string {
1434 for i, v := range m.commonProperties.DebugMutators {
1435 if v == mutator {
1436 return m.commonProperties.DebugVariations[i]
1437 }
1438 }
1439
1440 return ""
1441}
1442
Yifan Hong1b3348d2020-01-21 15:53:22 -08001443func (m *ModuleBase) InRamdisk() bool {
1444 return m.base().commonProperties.ImageVariation == RamdiskVariation
1445}
1446
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001447func (m *ModuleBase) InVendorRamdisk() bool {
1448 return m.base().commonProperties.ImageVariation == VendorRamdiskVariation
1449}
1450
Colin Cross7228ecd2019-11-18 16:00:16 -08001451func (m *ModuleBase) InRecovery() bool {
1452 return m.base().commonProperties.ImageVariation == RecoveryVariation
1453}
1454
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09001455func (m *ModuleBase) RequiredModuleNames() []string {
1456 return m.base().commonProperties.Required
1457}
1458
1459func (m *ModuleBase) HostRequiredModuleNames() []string {
1460 return m.base().commonProperties.Host_required
1461}
1462
1463func (m *ModuleBase) TargetRequiredModuleNames() []string {
1464 return m.base().commonProperties.Target_required
1465}
1466
Inseob Kim8471cda2019-11-15 09:59:12 +09001467func (m *ModuleBase) InitRc() Paths {
1468 return append(Paths{}, m.initRcPaths...)
1469}
1470
1471func (m *ModuleBase) VintfFragments() Paths {
1472 return append(Paths{}, m.vintfFragmentsPaths...)
1473}
1474
Colin Cross4157e882019-06-06 16:57:04 -07001475func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Colin Cross897266e2020-02-13 13:22:08 -08001476 var allInstalledFiles InstallPaths
1477 var allCheckbuildFiles Paths
Colin Cross0875c522017-11-28 17:34:01 -08001478 ctx.VisitAllModuleVariants(func(module Module) {
1479 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -07001480 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
1481 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001482 })
1483
Colin Cross0875c522017-11-28 17:34:01 -08001484 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -07001485
Colin Cross133ebef2020-08-14 17:38:45 -07001486 namespacePrefix := ctx.Namespace().id
Jeff Gaston088e29e2017-11-29 16:47:17 -08001487 if namespacePrefix != "" {
1488 namespacePrefix = namespacePrefix + "-"
1489 }
1490
Colin Cross3f40fa42015-01-30 17:27:36 -08001491 if len(allInstalledFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001492 name := namespacePrefix + ctx.ModuleName() + "-install"
1493 ctx.Phony(name, allInstalledFiles.Paths()...)
1494 m.installTarget = PathForPhony(ctx, name)
1495 deps = append(deps, m.installTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001496 }
1497
1498 if len(allCheckbuildFiles) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07001499 name := namespacePrefix + ctx.ModuleName() + "-checkbuild"
1500 ctx.Phony(name, allCheckbuildFiles...)
1501 m.checkbuildTarget = PathForPhony(ctx, name)
1502 deps = append(deps, m.checkbuildTarget)
Colin Cross9454bfa2015-03-17 13:24:18 -07001503 }
1504
1505 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001506 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05001507 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001508 suffix = "-soong"
1509 }
1510
Colin Crossc3d87d32020-06-04 13:25:17 -07001511 ctx.Phony(namespacePrefix+ctx.ModuleName()+suffix, deps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001512
Colin Cross4157e882019-06-06 16:57:04 -07001513 m.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -08001514 }
1515}
1516
Colin Crossc34d2322020-01-03 15:23:27 -08001517func determineModuleKind(m *ModuleBase, ctx blueprint.EarlyModuleContext) moduleKind {
Colin Cross4157e882019-06-06 16:57:04 -07001518 var socSpecific = Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Proprietary) || Bool(m.commonProperties.Soc_specific)
1519 var deviceSpecific = Bool(m.commonProperties.Device_specific)
1520 var productSpecific = Bool(m.commonProperties.Product_specific)
Justin Yund5f6c822019-06-25 16:47:17 +09001521 var systemExtSpecific = Bool(m.commonProperties.System_ext_specific)
Jiyong Park2db76922017-11-08 16:03:48 +09001522
Dario Frenifd05a742018-05-29 13:28:54 +01001523 msg := "conflicting value set here"
1524 if socSpecific && deviceSpecific {
1525 ctx.PropertyErrorf("device_specific", "a module cannot be specific to SoC and device at the same time.")
Colin Cross4157e882019-06-06 16:57:04 -07001526 if Bool(m.commonProperties.Vendor) {
Jiyong Park2db76922017-11-08 16:03:48 +09001527 ctx.PropertyErrorf("vendor", msg)
1528 }
Colin Cross4157e882019-06-06 16:57:04 -07001529 if Bool(m.commonProperties.Proprietary) {
Jiyong Park2db76922017-11-08 16:03:48 +09001530 ctx.PropertyErrorf("proprietary", msg)
1531 }
Colin Cross4157e882019-06-06 16:57:04 -07001532 if Bool(m.commonProperties.Soc_specific) {
Jiyong Park2db76922017-11-08 16:03:48 +09001533 ctx.PropertyErrorf("soc_specific", msg)
1534 }
1535 }
1536
Justin Yund5f6c822019-06-25 16:47:17 +09001537 if productSpecific && systemExtSpecific {
1538 ctx.PropertyErrorf("product_specific", "a module cannot be specific to product and system_ext at the same time.")
1539 ctx.PropertyErrorf("system_ext_specific", msg)
Dario Frenifd05a742018-05-29 13:28:54 +01001540 }
1541
Justin Yund5f6c822019-06-25 16:47:17 +09001542 if (socSpecific || deviceSpecific) && (productSpecific || systemExtSpecific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001543 if productSpecific {
1544 ctx.PropertyErrorf("product_specific", "a module cannot be specific to SoC or device and product at the same time.")
1545 } else {
Justin Yund5f6c822019-06-25 16:47:17 +09001546 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 +01001547 }
1548 if deviceSpecific {
1549 ctx.PropertyErrorf("device_specific", msg)
1550 } else {
Colin Cross4157e882019-06-06 16:57:04 -07001551 if Bool(m.commonProperties.Vendor) {
Dario Frenifd05a742018-05-29 13:28:54 +01001552 ctx.PropertyErrorf("vendor", msg)
1553 }
Colin Cross4157e882019-06-06 16:57:04 -07001554 if Bool(m.commonProperties.Proprietary) {
Dario Frenifd05a742018-05-29 13:28:54 +01001555 ctx.PropertyErrorf("proprietary", msg)
1556 }
Colin Cross4157e882019-06-06 16:57:04 -07001557 if Bool(m.commonProperties.Soc_specific) {
Dario Frenifd05a742018-05-29 13:28:54 +01001558 ctx.PropertyErrorf("soc_specific", msg)
1559 }
1560 }
1561 }
1562
Jiyong Park2db76922017-11-08 16:03:48 +09001563 if productSpecific {
1564 return productSpecificModule
Justin Yund5f6c822019-06-25 16:47:17 +09001565 } else if systemExtSpecific {
1566 return systemExtSpecificModule
Jiyong Park2db76922017-11-08 16:03:48 +09001567 } else if deviceSpecific {
1568 return deviceSpecificModule
1569 } else if socSpecific {
1570 return socSpecificModule
1571 } else {
1572 return platformModule
1573 }
1574}
1575
Colin Crossc34d2322020-01-03 15:23:27 -08001576func (m *ModuleBase) earlyModuleContextFactory(ctx blueprint.EarlyModuleContext) earlyModuleContext {
Colin Cross1184b642019-12-30 18:43:07 -08001577 return earlyModuleContext{
Colin Crossc34d2322020-01-03 15:23:27 -08001578 EarlyModuleContext: ctx,
1579 kind: determineModuleKind(m, ctx),
1580 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -08001581 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001582}
1583
Colin Cross1184b642019-12-30 18:43:07 -08001584func (m *ModuleBase) baseModuleContextFactory(ctx blueprint.BaseModuleContext) baseModuleContext {
1585 return baseModuleContext{
1586 bp: ctx,
1587 earlyModuleContext: m.earlyModuleContextFactory(ctx),
1588 os: m.commonProperties.CompileOS,
1589 target: m.commonProperties.CompileTarget,
1590 targetPrimary: m.commonProperties.CompilePrimary,
1591 multiTargets: m.commonProperties.CompileMultiTargets,
1592 }
1593}
1594
Colin Cross4157e882019-06-06 16:57:04 -07001595func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
Colin Cross25de6c32019-06-06 14:29:25 -07001596 ctx := &moduleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001597 module: m.module,
Colin Crossdc35e212019-06-06 16:13:11 -07001598 bp: blueprintCtx,
Colin Cross0ea8ba82019-06-06 14:33:29 -07001599 baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
Colin Cross0ea8ba82019-06-06 14:33:29 -07001600 variables: make(map[string]string),
Colin Cross3f40fa42015-01-30 17:27:36 -08001601 }
1602
Colin Crossffe6b9d2020-12-01 15:40:06 -08001603 dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
Colin Cross5d583952020-11-24 16:21:24 -08001604 // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
1605 // of installed files of this module. It will be replaced by a depset including the installed
1606 // files of this module at the end for use by modules that depend on this one.
1607 m.installFilesDepSet = newInstallPathsDepSet(nil, dependencyInstallFiles)
1608
Colin Cross6c4f21f2019-06-06 15:41:36 -07001609 // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never
1610 // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true.
1611 // TODO: This will be removed once defaults modules handle missing dependency errors
1612 blueprintCtx.GetMissingDependencies()
1613
Colin Crossdc35e212019-06-06 16:13:11 -07001614 // For the final GenerateAndroidBuildActions pass, require that all visited dependencies Soong modules and
Paul Duffin1356d8c2020-02-25 19:26:33 +00001615 // are enabled. Unless the module is a CommonOS variant which may have dependencies on disabled variants
1616 // (because the dependencies are added before the modules are disabled). The
1617 // GetOsSpecificVariantsOfCommonOSVariant(...) method will ensure that the disabled variants are
1618 // ignored.
1619 ctx.baseModuleContext.strictVisitDeps = !m.IsCommonOSVariant()
Colin Crossdc35e212019-06-06 16:13:11 -07001620
Colin Cross4c83e5c2019-02-25 14:54:28 -08001621 if ctx.config.captureBuild {
1622 ctx.ruleParams = make(map[blueprint.Rule]blueprint.RuleParams)
1623 }
1624
Colin Cross67a5c132017-05-09 13:45:28 -07001625 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
1626 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -08001627 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
1628 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -07001629 }
Colin Cross0875c522017-11-28 17:34:01 -08001630 if !ctx.PrimaryArch() {
1631 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -07001632 }
Colin Cross56a83212020-09-15 18:30:11 -07001633 if apexInfo := ctx.Provider(ApexInfoProvider).(ApexInfo); !apexInfo.IsForPlatform() {
1634 suffix = append(suffix, apexInfo.ApexVariationName)
Dan Willemsenb13a9482020-02-14 11:25:54 -08001635 }
Colin Cross67a5c132017-05-09 13:45:28 -07001636
1637 ctx.Variable(pctx, "moduleDesc", desc)
1638
1639 s := ""
1640 if len(suffix) > 0 {
1641 s = " [" + strings.Join(suffix, " ") + "]"
1642 }
1643 ctx.Variable(pctx, "moduleDescSuffix", s)
1644
Dan Willemsen569edc52018-11-19 09:33:29 -08001645 // Some common property checks for properties that will be used later in androidmk.go
Paul Duffin89968e32020-11-23 18:17:03 +00001646 checkDistProperties(ctx, "dist", &m.distProperties.Dist)
1647 for i, _ := range m.distProperties.Dists {
1648 checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
Dan Willemsen569edc52018-11-19 09:33:29 -08001649 }
1650
Colin Cross4157e882019-06-06 16:57:04 -07001651 if m.Enabled() {
Jooyung Hand48f3c32019-08-23 11:18:57 +09001652 // ensure all direct android.Module deps are enabled
1653 ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
1654 if _, ok := bm.(Module); ok {
1655 ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
1656 }
1657 })
1658
Bob Badoura75b0572020-02-18 20:21:55 -08001659 m.noticeFiles = make([]Path, 0)
1660 optPath := OptionalPath{}
1661 notice := proptools.StringDefault(m.commonProperties.Notice, "")
Colin Cross4157e882019-06-06 16:57:04 -07001662 if module := SrcIsModule(notice); module != "" {
Bob Badoura75b0572020-02-18 20:21:55 -08001663 optPath = ctx.ExpandOptionalSource(&notice, "notice")
1664 } else if notice != "" {
Jiyong Park52818fc2019-03-18 12:01:38 +09001665 noticePath := filepath.Join(ctx.ModuleDir(), notice)
Bob Badoura75b0572020-02-18 20:21:55 -08001666 optPath = ExistentPathForSource(ctx, noticePath)
1667 }
1668 if optPath.Valid() {
1669 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1670 } else {
1671 for _, notice = range []string{"LICENSE", "LICENCE", "NOTICE"} {
1672 noticePath := filepath.Join(ctx.ModuleDir(), notice)
1673 optPath = ExistentPathForSource(ctx, noticePath)
1674 if optPath.Valid() {
1675 m.noticeFiles = append(m.noticeFiles, optPath.Path())
1676 }
1677 }
Jaewoong Jung62707f72018-11-16 13:26:43 -08001678 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001679
1680 m.module.GenerateAndroidBuildActions(ctx)
1681 if ctx.Failed() {
1682 return
1683 }
1684
Paul Duffinaf970a22020-11-23 23:32:56 +00001685 // Create the set of tagged dist files after calling GenerateAndroidBuildActions
1686 // as GenerateTaggedDistFiles() calls OutputFiles(tag) and so relies on the
1687 // output paths being set which must be done before or during
1688 // GenerateAndroidBuildActions.
1689 m.distFiles = m.GenerateTaggedDistFiles(ctx)
1690 if ctx.Failed() {
1691 return
1692 }
1693
Jaewoong Jung5b425e22019-06-17 17:40:56 -07001694 m.installFiles = append(m.installFiles, ctx.installFiles...)
1695 m.checkbuildFiles = append(m.checkbuildFiles, ctx.checkbuildFiles...)
Jiyong Park073ea552020-11-09 14:08:34 +09001696 m.packagingSpecs = append(m.packagingSpecs, ctx.packagingSpecs...)
Inseob Kim8471cda2019-11-15 09:59:12 +09001697 m.initRcPaths = PathsForModuleSrc(ctx, m.commonProperties.Init_rc)
1698 m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments)
Colin Crossc3d87d32020-06-04 13:25:17 -07001699 for k, v := range ctx.phonies {
1700 m.phonies[k] = append(m.phonies[k], v...)
1701 }
Colin Crossdc35e212019-06-06 16:13:11 -07001702 } else if ctx.Config().AllowMissingDependencies() {
1703 // If the module is not enabled it will not create any build rules, nothing will call
1704 // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled
1705 // and report them as an error even when AllowMissingDependencies = true. Call
1706 // ctx.GetMissingDependencies() here to tell blueprint not to handle them.
1707 ctx.GetMissingDependencies()
Colin Cross3f40fa42015-01-30 17:27:36 -08001708 }
1709
Colin Cross4157e882019-06-06 16:57:04 -07001710 if m == ctx.FinalModule().(Module).base() {
1711 m.generateModuleTarget(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -07001712 if ctx.Failed() {
1713 return
1714 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001715 }
Colin Crosscec81712017-07-13 14:43:27 -07001716
Colin Cross5d583952020-11-24 16:21:24 -08001717 m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
Colin Crossffe6b9d2020-12-01 15:40:06 -08001718 m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
Colin Cross5d583952020-11-24 16:21:24 -08001719
Colin Cross4157e882019-06-06 16:57:04 -07001720 m.buildParams = ctx.buildParams
1721 m.ruleParams = ctx.ruleParams
1722 m.variables = ctx.variables
Colin Cross3f40fa42015-01-30 17:27:36 -08001723}
1724
Paul Duffin89968e32020-11-23 18:17:03 +00001725// Check the supplied dist structure to make sure that it is valid.
1726//
1727// property - the base property, e.g. dist or dists[1], which is combined with the
1728// name of the nested property to produce the full property, e.g. dist.dest or
1729// dists[1].dir.
1730func checkDistProperties(ctx *moduleContext, property string, dist *Dist) {
1731 if dist.Dest != nil {
1732 _, err := validateSafePath(*dist.Dest)
1733 if err != nil {
1734 ctx.PropertyErrorf(property+".dest", "%s", err.Error())
1735 }
1736 }
1737 if dist.Dir != nil {
1738 _, err := validateSafePath(*dist.Dir)
1739 if err != nil {
1740 ctx.PropertyErrorf(property+".dir", "%s", err.Error())
1741 }
1742 }
1743 if dist.Suffix != nil {
1744 if strings.Contains(*dist.Suffix, "/") {
1745 ctx.PropertyErrorf(property+".suffix", "Suffix may not contain a '/' character.")
1746 }
1747 }
1748
1749}
1750
Colin Cross1184b642019-12-30 18:43:07 -08001751type earlyModuleContext struct {
Colin Crossc34d2322020-01-03 15:23:27 -08001752 blueprint.EarlyModuleContext
Colin Cross1184b642019-12-30 18:43:07 -08001753
1754 kind moduleKind
1755 config Config
1756}
1757
1758func (e *earlyModuleContext) Glob(globPattern string, excludes []string) Paths {
1759 ret, err := e.GlobWithDeps(globPattern, excludes)
1760 if err != nil {
1761 e.ModuleErrorf("glob: %s", err.Error())
1762 }
1763 return pathsForModuleSrcFromFullPath(e, ret, true)
1764}
1765
1766func (e *earlyModuleContext) GlobFiles(globPattern string, excludes []string) Paths {
1767 ret, err := e.GlobWithDeps(globPattern, excludes)
1768 if err != nil {
1769 e.ModuleErrorf("glob: %s", err.Error())
1770 }
1771 return pathsForModuleSrcFromFullPath(e, ret, false)
1772}
1773
Colin Cross988414c2020-01-11 01:11:46 +00001774func (b *earlyModuleContext) IsSymlink(path Path) bool {
1775 fileInfo, err := b.config.fs.Lstat(path.String())
1776 if err != nil {
1777 b.ModuleErrorf("os.Lstat(%q) failed: %s", path.String(), err)
1778 }
1779 return fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink
1780}
1781
1782func (b *earlyModuleContext) Readlink(path Path) string {
1783 dest, err := b.config.fs.Readlink(path.String())
1784 if err != nil {
1785 b.ModuleErrorf("os.Readlink(%q) failed: %s", path.String(), err)
1786 }
1787 return dest
1788}
1789
Colin Cross1184b642019-12-30 18:43:07 -08001790func (e *earlyModuleContext) Module() Module {
Colin Crossc34d2322020-01-03 15:23:27 -08001791 module, _ := e.EarlyModuleContext.Module().(Module)
Colin Cross1184b642019-12-30 18:43:07 -08001792 return module
1793}
1794
1795func (e *earlyModuleContext) Config() Config {
Colin Crossc34d2322020-01-03 15:23:27 -08001796 return e.EarlyModuleContext.Config().(Config)
Colin Cross1184b642019-12-30 18:43:07 -08001797}
1798
1799func (e *earlyModuleContext) AConfig() Config {
1800 return e.config
1801}
1802
1803func (e *earlyModuleContext) DeviceConfig() DeviceConfig {
1804 return DeviceConfig{e.config.deviceConfig}
1805}
1806
1807func (e *earlyModuleContext) Platform() bool {
1808 return e.kind == platformModule
1809}
1810
1811func (e *earlyModuleContext) DeviceSpecific() bool {
1812 return e.kind == deviceSpecificModule
1813}
1814
1815func (e *earlyModuleContext) SocSpecific() bool {
1816 return e.kind == socSpecificModule
1817}
1818
1819func (e *earlyModuleContext) ProductSpecific() bool {
1820 return e.kind == productSpecificModule
1821}
1822
1823func (e *earlyModuleContext) SystemExtSpecific() bool {
1824 return e.kind == systemExtSpecificModule
1825}
1826
Colin Cross133ebef2020-08-14 17:38:45 -07001827func (e *earlyModuleContext) Namespace() *Namespace {
1828 return e.EarlyModuleContext.Namespace().(*Namespace)
1829}
1830
Colin Cross1184b642019-12-30 18:43:07 -08001831type baseModuleContext struct {
1832 bp blueprint.BaseModuleContext
1833 earlyModuleContext
Colin Crossfb0c16e2019-11-20 17:12:35 -08001834 os OsType
Colin Cross8b74d172016-09-13 09:59:14 -07001835 target Target
Colin Crossee0bc3b2018-10-02 22:01:37 -07001836 multiTargets []Target
Colin Cross8b74d172016-09-13 09:59:14 -07001837 targetPrimary bool
1838 debug bool
Colin Crossdc35e212019-06-06 16:13:11 -07001839
1840 walkPath []Module
Paul Duffinc5192442020-03-31 11:31:36 +01001841 tagPath []blueprint.DependencyTag
Colin Crossdc35e212019-06-06 16:13:11 -07001842
1843 strictVisitDeps bool // If true, enforce that all dependencies are enabled
Colin Crossf6566ed2015-03-24 11:13:38 -07001844}
1845
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001846func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string {
1847 return b.bp.OtherModuleName(m)
1848}
1849func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { return b.bp.OtherModuleDir(m) }
Colin Cross1184b642019-12-30 18:43:07 -08001850func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) {
Jooyung Hancd87c692020-02-26 02:05:18 +09001851 b.bp.OtherModuleErrorf(m, fmt, args...)
Colin Cross1184b642019-12-30 18:43:07 -08001852}
1853func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag {
1854 return b.bp.OtherModuleDependencyTag(m)
1855}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001856func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
Martin Stjernholm009a9dc2020-03-05 17:34:13 +00001857func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
1858 return b.bp.OtherModuleDependencyVariantExists(variations, name)
1859}
1860func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
1861 return b.bp.OtherModuleReverseDependencyVariantExists(name)
1862}
Paul Duffinca7f0ef2020-02-25 15:50:49 +00001863func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
1864 return b.bp.OtherModuleType(m)
1865}
Colin Crossd27e7b82020-07-02 11:38:17 -07001866func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} {
1867 return b.bp.OtherModuleProvider(m, provider)
1868}
1869func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool {
1870 return b.bp.OtherModuleHasProvider(m, provider)
1871}
1872func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} {
1873 return b.bp.Provider(provider)
1874}
1875func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool {
1876 return b.bp.HasProvider(provider)
1877}
1878func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) {
1879 b.bp.SetProvider(provider, value)
1880}
Colin Cross1184b642019-12-30 18:43:07 -08001881
1882func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
1883 return b.bp.GetDirectDepWithTag(name, tag)
1884}
1885
Paul Duffinf88d8e02020-05-07 20:21:34 +01001886func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext {
1887 return b.bp
1888}
1889
Colin Cross25de6c32019-06-06 14:29:25 -07001890type moduleContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -07001891 bp blueprint.ModuleContext
Colin Cross0ea8ba82019-06-06 14:33:29 -07001892 baseModuleContext
Jiyong Park073ea552020-11-09 14:08:34 +09001893 packagingSpecs []PackagingSpec
Colin Cross897266e2020-02-13 13:22:08 -08001894 installFiles InstallPaths
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001895 checkbuildFiles Paths
Colin Cross8d8f8e22016-08-03 11:57:50 -07001896 module Module
Colin Crossc3d87d32020-06-04 13:25:17 -07001897 phonies map[string]Paths
Colin Crosscec81712017-07-13 14:43:27 -07001898
1899 // For tests
Colin Crossae887032017-10-23 17:16:14 -07001900 buildParams []BuildParams
Colin Cross4c83e5c2019-02-25 14:54:28 -08001901 ruleParams map[blueprint.Rule]blueprint.RuleParams
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001902 variables map[string]string
Colin Cross6ff51382015-12-17 16:39:19 -08001903}
1904
Colin Crossb88b3c52019-06-10 15:15:17 -07001905func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
1906 return pctx, BuildParams{
Colin Cross4b69c492019-06-07 13:06:06 -07001907 Rule: ErrorRule,
1908 Description: params.Description,
1909 Output: params.Output,
1910 Outputs: params.Outputs,
1911 ImplicitOutput: params.ImplicitOutput,
1912 ImplicitOutputs: params.ImplicitOutputs,
Colin Cross6ff51382015-12-17 16:39:19 -08001913 Args: map[string]string{
1914 "error": err.Error(),
1915 },
Colin Crossb88b3c52019-06-10 15:15:17 -07001916 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001917}
1918
Colin Cross25de6c32019-06-06 14:29:25 -07001919func (m *moduleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
1920 m.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -08001921}
1922
Jingwen Chence679d22020-09-23 04:30:02 +00001923func validateBuildParams(params blueprint.BuildParams) error {
1924 // Validate that the symlink outputs are declared outputs or implicit outputs
1925 allOutputs := map[string]bool{}
1926 for _, output := range params.Outputs {
1927 allOutputs[output] = true
1928 }
1929 for _, output := range params.ImplicitOutputs {
1930 allOutputs[output] = true
1931 }
1932 for _, symlinkOutput := range params.SymlinkOutputs {
1933 if !allOutputs[symlinkOutput] {
1934 return fmt.Errorf(
1935 "Symlink output %s is not a declared output or implicit output",
1936 symlinkOutput)
1937 }
1938 }
1939 return nil
1940}
1941
1942// Convert build parameters from their concrete Android types into their string representations,
1943// and combine the singular and plural fields of the same type (e.g. Output and Outputs).
Colin Cross0875c522017-11-28 17:34:01 -08001944func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001945 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001946 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -08001947 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -08001948 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001949 Outputs: params.Outputs.Strings(),
1950 ImplicitOutputs: params.ImplicitOutputs.Strings(),
Jingwen Chence679d22020-09-23 04:30:02 +00001951 SymlinkOutputs: params.SymlinkOutputs.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001952 Inputs: params.Inputs.Strings(),
1953 Implicits: params.Implicits.Strings(),
1954 OrderOnly: params.OrderOnly.Strings(),
Colin Cross824f1162020-07-16 13:07:51 -07001955 Validations: params.Validations.Strings(),
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001956 Args: params.Args,
1957 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001958 }
1959
Colin Cross33bfb0a2016-11-21 17:23:08 -08001960 if params.Depfile != nil {
1961 bparams.Depfile = params.Depfile.String()
1962 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001963 if params.Output != nil {
1964 bparams.Outputs = append(bparams.Outputs, params.Output.String())
1965 }
Jingwen Chence679d22020-09-23 04:30:02 +00001966 if params.SymlinkOutput != nil {
1967 bparams.SymlinkOutputs = append(bparams.SymlinkOutputs, params.SymlinkOutput.String())
1968 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -07001969 if params.ImplicitOutput != nil {
1970 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
1971 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001972 if params.Input != nil {
1973 bparams.Inputs = append(bparams.Inputs, params.Input.String())
1974 }
1975 if params.Implicit != nil {
1976 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
1977 }
Colin Cross824f1162020-07-16 13:07:51 -07001978 if params.Validation != nil {
1979 bparams.Validations = append(bparams.Validations, params.Validation.String())
1980 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001981
Colin Cross0b9f31f2019-02-28 11:00:01 -08001982 bparams.Outputs = proptools.NinjaEscapeList(bparams.Outputs)
1983 bparams.ImplicitOutputs = proptools.NinjaEscapeList(bparams.ImplicitOutputs)
Jingwen Chence679d22020-09-23 04:30:02 +00001984 bparams.SymlinkOutputs = proptools.NinjaEscapeList(bparams.SymlinkOutputs)
Colin Cross0b9f31f2019-02-28 11:00:01 -08001985 bparams.Inputs = proptools.NinjaEscapeList(bparams.Inputs)
1986 bparams.Implicits = proptools.NinjaEscapeList(bparams.Implicits)
1987 bparams.OrderOnly = proptools.NinjaEscapeList(bparams.OrderOnly)
Colin Cross824f1162020-07-16 13:07:51 -07001988 bparams.Validations = proptools.NinjaEscapeList(bparams.Validations)
1989 bparams.Depfile = proptools.NinjaEscape(bparams.Depfile)
Colin Crossfe4bc362018-09-12 10:02:13 -07001990
Colin Cross0875c522017-11-28 17:34:01 -08001991 return bparams
1992}
1993
Colin Cross25de6c32019-06-06 14:29:25 -07001994func (m *moduleContext) Variable(pctx PackageContext, name, value string) {
1995 if m.config.captureBuild {
1996 m.variables[name] = value
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001997 }
1998
Colin Crossdc35e212019-06-06 16:13:11 -07001999 m.bp.Variable(pctx.PackageContext, name, value)
Colin Cross0875c522017-11-28 17:34:01 -08002000}
2001
Colin Cross25de6c32019-06-06 14:29:25 -07002002func (m *moduleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
Colin Cross0875c522017-11-28 17:34:01 -08002003 argNames ...string) blueprint.Rule {
2004
Ramy Medhat944839a2020-03-31 22:14:52 -04002005 if m.config.UseRemoteBuild() {
2006 if params.Pool == nil {
2007 // When USE_GOMA=true or USE_RBE=true are set and the rule is not supported by goma/RBE, restrict
2008 // jobs to the local parallelism value
2009 params.Pool = localPool
2010 } else if params.Pool == remotePool {
2011 // remotePool is a fake pool used to identify rule that are supported for remoting. If the rule's
2012 // pool is the remotePool, replace with nil so that ninja runs it at NINJA_REMOTE_NUM_JOBS
2013 // parallelism.
2014 params.Pool = nil
2015 }
Colin Cross2e2dbc22019-09-25 13:31:46 -07002016 }
2017
Colin Crossdc35e212019-06-06 16:13:11 -07002018 rule := m.bp.Rule(pctx.PackageContext, name, params, argNames...)
Colin Cross4c83e5c2019-02-25 14:54:28 -08002019
Colin Cross25de6c32019-06-06 14:29:25 -07002020 if m.config.captureBuild {
2021 m.ruleParams[rule] = params
Colin Cross4c83e5c2019-02-25 14:54:28 -08002022 }
2023
2024 return rule
Colin Cross0875c522017-11-28 17:34:01 -08002025}
2026
Colin Cross25de6c32019-06-06 14:29:25 -07002027func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
Colin Crossb88b3c52019-06-10 15:15:17 -07002028 if params.Description != "" {
2029 params.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
2030 }
2031
2032 if missingDeps := m.GetMissingDependencies(); len(missingDeps) > 0 {
2033 pctx, params = m.ninjaError(params, fmt.Errorf("module %s missing dependencies: %s\n",
2034 m.ModuleName(), strings.Join(missingDeps, ", ")))
2035 }
2036
Colin Cross25de6c32019-06-06 14:29:25 -07002037 if m.config.captureBuild {
2038 m.buildParams = append(m.buildParams, params)
Colin Cross0875c522017-11-28 17:34:01 -08002039 }
2040
Jingwen Chence679d22020-09-23 04:30:02 +00002041 bparams := convertBuildParams(params)
2042 err := validateBuildParams(bparams)
2043 if err != nil {
2044 m.ModuleErrorf(
2045 "%s: build parameter validation failed: %s",
2046 m.ModuleName(),
2047 err.Error())
2048 }
2049 m.bp.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -07002050}
Colin Crossc3d87d32020-06-04 13:25:17 -07002051
2052func (m *moduleContext) Phony(name string, deps ...Path) {
2053 addPhony(m.config, name, deps...)
2054}
2055
Colin Cross25de6c32019-06-06 14:29:25 -07002056func (m *moduleContext) GetMissingDependencies() []string {
Colin Cross6c4f21f2019-06-06 15:41:36 -07002057 var missingDeps []string
2058 missingDeps = append(missingDeps, m.Module().base().commonProperties.MissingDeps...)
Colin Crossdc35e212019-06-06 16:13:11 -07002059 missingDeps = append(missingDeps, m.bp.GetMissingDependencies()...)
Colin Cross6c4f21f2019-06-06 15:41:36 -07002060 missingDeps = FirstUniqueStrings(missingDeps)
2061 return missingDeps
Colin Cross6ff51382015-12-17 16:39:19 -08002062}
2063
Colin Crossdc35e212019-06-06 16:13:11 -07002064func (b *baseModuleContext) AddMissingDependencies(deps []string) {
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002065 if deps != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002066 missingDeps := &b.Module().base().commonProperties.MissingDeps
Colin Cross6c4f21f2019-06-06 15:41:36 -07002067 *missingDeps = append(*missingDeps, deps...)
2068 *missingDeps = FirstUniqueStrings(*missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -08002069 }
2070}
2071
Colin Crossdc35e212019-06-06 16:13:11 -07002072func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, strict bool) Module {
Colin Crossd11fcda2017-10-23 17:59:01 -07002073 aModule, _ := module.(Module)
Colin Crossdc35e212019-06-06 16:13:11 -07002074
2075 if !strict {
2076 return aModule
2077 }
2078
Colin Cross380c69a2019-06-10 17:49:58 +00002079 if aModule == nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002080 b.ModuleErrorf("module %q not an android module", b.OtherModuleName(module))
Colin Cross380c69a2019-06-10 17:49:58 +00002081 return nil
2082 }
2083
2084 if !aModule.Enabled() {
Colin Crossdc35e212019-06-06 16:13:11 -07002085 if b.Config().AllowMissingDependencies() {
2086 b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
Colin Cross380c69a2019-06-10 17:49:58 +00002087 } else {
Colin Crossdc35e212019-06-06 16:13:11 -07002088 b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule))
Colin Cross380c69a2019-06-10 17:49:58 +00002089 }
2090 return nil
2091 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002092 return aModule
2093}
2094
Colin Crossdc35e212019-06-06 16:13:11 -07002095func (b *baseModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
Jiyong Parkf2976302019-04-17 21:47:37 +09002096 type dep struct {
2097 mod blueprint.Module
2098 tag blueprint.DependencyTag
2099 }
2100 var deps []dep
Colin Crossdc35e212019-06-06 16:13:11 -07002101 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07002102 if aModule, _ := module.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
Colin Cross1184b642019-12-30 18:43:07 -08002103 returnedTag := b.bp.OtherModuleDependencyTag(aModule)
Jiyong Parkf2976302019-04-17 21:47:37 +09002104 if tag == nil || returnedTag == tag {
2105 deps = append(deps, dep{aModule, returnedTag})
2106 }
2107 }
2108 })
2109 if len(deps) == 1 {
2110 return deps[0].mod, deps[0].tag
2111 } else if len(deps) >= 2 {
2112 panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
Colin Crossdc35e212019-06-06 16:13:11 -07002113 name, b.ModuleName()))
Jiyong Parkf2976302019-04-17 21:47:37 +09002114 } else {
2115 return nil, nil
2116 }
2117}
2118
Colin Crossdc35e212019-06-06 16:13:11 -07002119func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module {
Colin Cross0ef08162019-05-01 15:50:51 -07002120 var deps []Module
Colin Crossdc35e212019-06-06 16:13:11 -07002121 b.VisitDirectDepsBlueprint(func(module blueprint.Module) {
Colin Cross25de6c32019-06-06 14:29:25 -07002122 if aModule, _ := module.(Module); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002123 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Cross0ef08162019-05-01 15:50:51 -07002124 deps = append(deps, aModule)
2125 }
2126 }
2127 })
2128 return deps
2129}
2130
Colin Cross25de6c32019-06-06 14:29:25 -07002131func (m *moduleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
2132 module, _ := m.getDirectDepInternal(name, tag)
2133 return module
Jiyong Parkf2976302019-04-17 21:47:37 +09002134}
2135
Colin Crossdc35e212019-06-06 16:13:11 -07002136func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
2137 return b.getDirectDepInternal(name, nil)
Jiyong Parkf2976302019-04-17 21:47:37 +09002138}
2139
Colin Crossdc35e212019-06-06 16:13:11 -07002140func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002141 b.bp.VisitDirectDeps(visit)
Colin Cross35143d02017-11-16 00:11:20 -08002142}
2143
Colin Crossdc35e212019-06-06 16:13:11 -07002144func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002145 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07002146 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002147 visit(aModule)
2148 }
2149 })
2150}
2151
Colin Crossdc35e212019-06-06 16:13:11 -07002152func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002153 b.bp.VisitDirectDeps(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07002154 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Cross1184b642019-12-30 18:43:07 -08002155 if b.bp.OtherModuleDependencyTag(aModule) == tag {
Colin Crossee6143c2017-12-30 17:54:27 -08002156 visit(aModule)
2157 }
2158 }
2159 })
2160}
2161
Colin Crossdc35e212019-06-06 16:13:11 -07002162func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002163 b.bp.VisitDirectDepsIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002164 // pred
2165 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002166 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002167 return pred(aModule)
2168 } else {
2169 return false
2170 }
2171 },
2172 // visit
2173 func(module blueprint.Module) {
2174 visit(module.(Module))
2175 })
2176}
2177
Colin Crossdc35e212019-06-06 16:13:11 -07002178func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002179 b.bp.VisitDepsDepthFirst(func(module blueprint.Module) {
Colin Crossdc35e212019-06-06 16:13:11 -07002180 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002181 visit(aModule)
2182 }
2183 })
2184}
2185
Colin Crossdc35e212019-06-06 16:13:11 -07002186func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
Colin Cross1184b642019-12-30 18:43:07 -08002187 b.bp.VisitDepsDepthFirstIf(
Colin Crossd11fcda2017-10-23 17:59:01 -07002188 // pred
2189 func(module blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002190 if aModule := b.validateAndroidModule(module, b.strictVisitDeps); aModule != nil {
Colin Crossd11fcda2017-10-23 17:59:01 -07002191 return pred(aModule)
2192 } else {
2193 return false
2194 }
2195 },
2196 // visit
2197 func(module blueprint.Module) {
2198 visit(module.(Module))
2199 })
2200}
2201
Colin Crossdc35e212019-06-06 16:13:11 -07002202func (b *baseModuleContext) WalkDepsBlueprint(visit func(blueprint.Module, blueprint.Module) bool) {
Colin Cross1184b642019-12-30 18:43:07 -08002203 b.bp.WalkDeps(visit)
Alex Light778127a2019-02-27 14:19:50 -08002204}
2205
Colin Crossdc35e212019-06-06 16:13:11 -07002206func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
2207 b.walkPath = []Module{b.Module()}
Paul Duffinc5192442020-03-31 11:31:36 +01002208 b.tagPath = []blueprint.DependencyTag{}
Colin Cross1184b642019-12-30 18:43:07 -08002209 b.bp.WalkDeps(func(child, parent blueprint.Module) bool {
Colin Crossdc35e212019-06-06 16:13:11 -07002210 childAndroidModule, _ := child.(Module)
2211 parentAndroidModule, _ := parent.(Module)
Colin Crossd11fcda2017-10-23 17:59:01 -07002212 if childAndroidModule != nil && parentAndroidModule != nil {
Colin Crossdc35e212019-06-06 16:13:11 -07002213 // record walkPath before visit
2214 for b.walkPath[len(b.walkPath)-1] != parentAndroidModule {
2215 b.walkPath = b.walkPath[0 : len(b.walkPath)-1]
Paul Duffinc5192442020-03-31 11:31:36 +01002216 b.tagPath = b.tagPath[0 : len(b.tagPath)-1]
Colin Crossdc35e212019-06-06 16:13:11 -07002217 }
2218 b.walkPath = append(b.walkPath, childAndroidModule)
Paul Duffinc5192442020-03-31 11:31:36 +01002219 b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule))
Colin Crossd11fcda2017-10-23 17:59:01 -07002220 return visit(childAndroidModule, parentAndroidModule)
2221 } else {
2222 return false
2223 }
2224 })
2225}
2226
Colin Crossdc35e212019-06-06 16:13:11 -07002227func (b *baseModuleContext) GetWalkPath() []Module {
2228 return b.walkPath
2229}
2230
Paul Duffinc5192442020-03-31 11:31:36 +01002231func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag {
2232 return b.tagPath
2233}
2234
Colin Cross4dfacf92020-09-16 19:22:27 -07002235func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
2236 b.bp.VisitAllModuleVariants(func(module blueprint.Module) {
2237 visit(module.(Module))
2238 })
2239}
2240
2241func (b *baseModuleContext) PrimaryModule() Module {
2242 return b.bp.PrimaryModule().(Module)
2243}
2244
2245func (b *baseModuleContext) FinalModule() Module {
2246 return b.bp.FinalModule().(Module)
2247}
2248
Jiyong Park1c7e9622020-05-07 16:12:13 +09002249// A regexp for removing boilerplate from BaseDependencyTag from the string representation of
2250// a dependency tag.
Colin Cross6e511a92020-07-27 21:26:48 -07002251var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002252
2253// PrettyPrintTag returns string representation of the tag, but prefers
2254// custom String() method if available.
2255func PrettyPrintTag(tag blueprint.DependencyTag) string {
2256 // Use tag's custom String() method if available.
2257 if stringer, ok := tag.(fmt.Stringer); ok {
2258 return stringer.String()
2259 }
2260
2261 // Otherwise, get a default string representation of the tag's struct.
Colin Cross6e511a92020-07-27 21:26:48 -07002262 tagString := fmt.Sprintf("%T: %+v", tag, tag)
Jiyong Park1c7e9622020-05-07 16:12:13 +09002263
2264 // Remove the boilerplate from BaseDependencyTag as it adds no value.
2265 tagString = tagCleaner.ReplaceAllString(tagString, "")
2266 return tagString
2267}
2268
2269func (b *baseModuleContext) GetPathString(skipFirst bool) string {
2270 sb := strings.Builder{}
2271 tagPath := b.GetTagPath()
2272 walkPath := b.GetWalkPath()
2273 if !skipFirst {
2274 sb.WriteString(walkPath[0].String())
2275 }
2276 for i, m := range walkPath[1:] {
2277 sb.WriteString("\n")
2278 sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i])))
2279 sb.WriteString(fmt.Sprintf(" -> %s", m.String()))
2280 }
2281 return sb.String()
2282}
2283
Colin Crossdc35e212019-06-06 16:13:11 -07002284func (m *moduleContext) ModuleSubDir() string {
2285 return m.bp.ModuleSubDir()
Colin Cross0875c522017-11-28 17:34:01 -08002286}
2287
Colin Cross0ea8ba82019-06-06 14:33:29 -07002288func (b *baseModuleContext) Target() Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002289 return b.target
Colin Crossa1ad8d12016-06-01 17:09:44 -07002290}
2291
Colin Cross0ea8ba82019-06-06 14:33:29 -07002292func (b *baseModuleContext) TargetPrimary() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002293 return b.targetPrimary
Colin Cross8b74d172016-09-13 09:59:14 -07002294}
2295
Colin Cross0ea8ba82019-06-06 14:33:29 -07002296func (b *baseModuleContext) MultiTargets() []Target {
Colin Cross25de6c32019-06-06 14:29:25 -07002297 return b.multiTargets
Colin Crossee0bc3b2018-10-02 22:01:37 -07002298}
2299
Colin Cross0ea8ba82019-06-06 14:33:29 -07002300func (b *baseModuleContext) Arch() Arch {
Colin Cross25de6c32019-06-06 14:29:25 -07002301 return b.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -08002302}
2303
Colin Cross0ea8ba82019-06-06 14:33:29 -07002304func (b *baseModuleContext) Os() OsType {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002305 return b.os
Dan Willemsen490fd492015-11-24 17:53:15 -08002306}
2307
Colin Cross0ea8ba82019-06-06 14:33:29 -07002308func (b *baseModuleContext) Host() bool {
Jiyong Park1613e552020-09-14 19:43:17 +09002309 return b.os.Class == Host
Colin Crossf6566ed2015-03-24 11:13:38 -07002310}
2311
Colin Cross0ea8ba82019-06-06 14:33:29 -07002312func (b *baseModuleContext) Device() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002313 return b.os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -07002314}
2315
Colin Cross0ea8ba82019-06-06 14:33:29 -07002316func (b *baseModuleContext) Darwin() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002317 return b.os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -07002318}
2319
Colin Cross0ea8ba82019-06-06 14:33:29 -07002320func (b *baseModuleContext) Fuchsia() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002321 return b.os == Fuchsia
Doug Horn21b94272019-01-16 12:06:11 -08002322}
2323
Colin Cross0ea8ba82019-06-06 14:33:29 -07002324func (b *baseModuleContext) Windows() bool {
Colin Crossfb0c16e2019-11-20 17:12:35 -08002325 return b.os == Windows
Colin Cross3edeee12017-04-04 12:59:48 -07002326}
2327
Colin Cross0ea8ba82019-06-06 14:33:29 -07002328func (b *baseModuleContext) Debug() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002329 return b.debug
Colin Crossf6566ed2015-03-24 11:13:38 -07002330}
2331
Colin Cross0ea8ba82019-06-06 14:33:29 -07002332func (b *baseModuleContext) PrimaryArch() bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002333 if len(b.config.Targets[b.target.Os]) <= 1 {
Colin Cross67a5c132017-05-09 13:45:28 -07002334 return true
2335 }
Colin Cross25de6c32019-06-06 14:29:25 -07002336 return b.target.Arch.ArchType == b.config.Targets[b.target.Os][0].Arch.ArchType
Colin Cross1e7d3702016-08-24 15:25:47 -07002337}
2338
Jiyong Park5baac542018-08-28 09:55:37 +09002339// Makes this module a platform module, i.e. not specific to soc, device,
Justin Yund5f6c822019-06-25 16:47:17 +09002340// product, or system_ext.
Colin Cross4157e882019-06-06 16:57:04 -07002341func (m *ModuleBase) MakeAsPlatform() {
2342 m.commonProperties.Vendor = boolPtr(false)
2343 m.commonProperties.Proprietary = boolPtr(false)
2344 m.commonProperties.Soc_specific = boolPtr(false)
2345 m.commonProperties.Product_specific = boolPtr(false)
Justin Yund5f6c822019-06-25 16:47:17 +09002346 m.commonProperties.System_ext_specific = boolPtr(false)
Jiyong Park5baac542018-08-28 09:55:37 +09002347}
2348
Colin Cross4157e882019-06-06 16:57:04 -07002349func (m *ModuleBase) EnableNativeBridgeSupportByDefault() {
2350 m.commonProperties.Native_bridge_supported = boolPtr(true)
dimitry03dc3f62019-05-09 14:07:34 +02002351}
2352
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002353func (m *ModuleBase) MakeAsSystemExt() {
Jooyung Han91df2082019-11-20 01:49:42 +09002354 m.commonProperties.Vendor = boolPtr(false)
2355 m.commonProperties.Proprietary = boolPtr(false)
2356 m.commonProperties.Soc_specific = boolPtr(false)
2357 m.commonProperties.Product_specific = boolPtr(false)
2358 m.commonProperties.System_ext_specific = boolPtr(true)
Sundong Ahnd95aa2d2019-10-08 19:34:03 +09002359}
2360
Jooyung Han344d5432019-08-23 11:17:39 +09002361// IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true"
2362func (m *ModuleBase) IsNativeBridgeSupported() bool {
2363 return proptools.Bool(m.commonProperties.Native_bridge_supported)
2364}
2365
Colin Cross25de6c32019-06-06 14:29:25 -07002366func (m *moduleContext) InstallInData() bool {
2367 return m.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -08002368}
2369
Jaewoong Jung0949f312019-09-11 10:25:18 -07002370func (m *moduleContext) InstallInTestcases() bool {
2371 return m.module.InstallInTestcases()
2372}
2373
Colin Cross25de6c32019-06-06 14:29:25 -07002374func (m *moduleContext) InstallInSanitizerDir() bool {
2375 return m.module.InstallInSanitizerDir()
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002376}
2377
Yifan Hong1b3348d2020-01-21 15:53:22 -08002378func (m *moduleContext) InstallInRamdisk() bool {
2379 return m.module.InstallInRamdisk()
2380}
2381
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002382func (m *moduleContext) InstallInVendorRamdisk() bool {
2383 return m.module.InstallInVendorRamdisk()
2384}
2385
Colin Cross25de6c32019-06-06 14:29:25 -07002386func (m *moduleContext) InstallInRecovery() bool {
2387 return m.module.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002388}
2389
Colin Cross90ba5f42019-10-02 11:10:58 -07002390func (m *moduleContext) InstallInRoot() bool {
2391 return m.module.InstallInRoot()
2392}
2393
Colin Cross607d8582019-07-29 16:44:46 -07002394func (m *moduleContext) InstallBypassMake() bool {
2395 return m.module.InstallBypassMake()
2396}
2397
Jiyong Park87788b52020-09-01 12:37:45 +09002398func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) {
Colin Cross6e359402020-02-10 15:29:54 -08002399 return m.module.InstallForceOS()
2400}
2401
Colin Cross70dda7e2019-10-01 22:05:35 -07002402func (m *moduleContext) skipInstall(fullInstallPath InstallPath) bool {
Colin Cross25de6c32019-06-06 14:29:25 -07002403 if m.module.base().commonProperties.SkipInstall {
Colin Cross893d8162017-04-26 17:34:03 -07002404 return true
2405 }
2406
Colin Cross3607f212018-05-07 15:28:05 -07002407 // We'll need a solution for choosing which of modules with the same name in different
2408 // namespaces to install. For now, reuse the list of namespaces exported to Make as the
2409 // list of namespaces to install in a Soong-only build.
Colin Cross25de6c32019-06-06 14:29:25 -07002410 if !m.module.base().commonProperties.NamespaceExportedToMake {
Colin Cross3607f212018-05-07 15:28:05 -07002411 return true
2412 }
2413
Colin Cross25de6c32019-06-06 14:29:25 -07002414 if m.Device() {
Jingwen Chencda22c92020-11-23 00:22:30 -05002415 if m.Config().KatiEnabled() && !m.InstallBypassMake() {
Colin Cross893d8162017-04-26 17:34:03 -07002416 return true
2417 }
Colin Cross893d8162017-04-26 17:34:03 -07002418 }
2419
2420 return false
2421}
2422
Colin Cross70dda7e2019-10-01 22:05:35 -07002423func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path,
2424 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002425 return m.installFile(installPath, name, srcPath, deps, false)
Colin Cross5c517922017-08-31 12:29:17 -07002426}
2427
Colin Cross70dda7e2019-10-01 22:05:35 -07002428func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path,
2429 deps ...Path) InstallPath {
Jiyong Park073ea552020-11-09 14:08:34 +09002430 return m.installFile(installPath, name, srcPath, deps, true)
Colin Cross5c517922017-08-31 12:29:17 -07002431}
2432
Jiyong Park073ea552020-11-09 14:08:34 +09002433func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath {
Colin Cross35cec122015-04-02 14:37:16 -07002434
Colin Cross25de6c32019-06-06 14:29:25 -07002435 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002436 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -08002437
Colin Cross25de6c32019-06-06 14:29:25 -07002438 if !m.skipInstall(fullInstallPath) {
Colin Cross5d583952020-11-24 16:21:24 -08002439 deps = append(deps, m.module.base().installFilesDepSet.ToList().Paths()...)
Colin Cross35cec122015-04-02 14:37:16 -07002440
Colin Cross89562dc2016-10-03 17:47:19 -07002441 var implicitDeps, orderOnlyDeps Paths
2442
Colin Cross25de6c32019-06-06 14:29:25 -07002443 if m.Host() {
Colin Cross89562dc2016-10-03 17:47:19 -07002444 // Installed host modules might be used during the build, depend directly on their
2445 // dependencies so their timestamp is updated whenever their dependency is updated
2446 implicitDeps = deps
2447 } else {
2448 orderOnlyDeps = deps
2449 }
2450
Jiyong Park073ea552020-11-09 14:08:34 +09002451 rule := Cp
2452 if executable {
2453 rule = CpExecutable
2454 }
2455
Colin Cross25de6c32019-06-06 14:29:25 -07002456 m.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -07002457 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -07002458 Description: "install " + fullInstallPath.Base(),
2459 Output: fullInstallPath,
2460 Input: srcPath,
2461 Implicits: implicitDeps,
2462 OrderOnly: orderOnlyDeps,
Jingwen Chencda22c92020-11-23 00:22:30 -05002463 Default: !m.Config().KatiEnabled(),
Dan Willemsen322acaf2016-01-12 23:07:05 -08002464 })
Colin Cross3f40fa42015-01-30 17:27:36 -08002465
Colin Cross25de6c32019-06-06 14:29:25 -07002466 m.installFiles = append(m.installFiles, fullInstallPath)
Dan Willemsen322acaf2016-01-12 23:07:05 -08002467 }
Jiyong Park073ea552020-11-09 14:08:34 +09002468
2469 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2470 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2471 srcPath: srcPath,
2472 symlinkTarget: "",
2473 executable: executable,
2474 })
2475
Colin Cross25de6c32019-06-06 14:29:25 -07002476 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -07002477 return fullInstallPath
2478}
2479
Colin Cross70dda7e2019-10-01 22:05:35 -07002480func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002481 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002482 m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -08002483
Jiyong Park073ea552020-11-09 14:08:34 +09002484 relPath, err := filepath.Rel(path.Dir(fullInstallPath.String()), srcPath.String())
2485 if err != nil {
2486 panic(fmt.Sprintf("Unable to generate symlink between %q and %q: %s", fullInstallPath.Base(), srcPath.Base(), err))
2487 }
Colin Cross25de6c32019-06-06 14:29:25 -07002488 if !m.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -07002489
Colin Cross25de6c32019-06-06 14:29:25 -07002490 m.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -07002491 Rule: Symlink,
2492 Description: "install symlink " + fullInstallPath.Base(),
2493 Output: fullInstallPath,
Dan Willemsen40efa1c2020-01-14 15:19:52 -08002494 Input: srcPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002495 Default: !m.Config().KatiEnabled(),
Colin Cross12fc4972016-01-11 12:49:11 -08002496 Args: map[string]string{
Alex Lightfb4353d2019-01-17 13:57:45 -08002497 "fromPath": relPath,
Colin Cross12fc4972016-01-11 12:49:11 -08002498 },
2499 })
Colin Cross3854a602016-01-11 12:49:11 -08002500
Colin Cross25de6c32019-06-06 14:29:25 -07002501 m.installFiles = append(m.installFiles, fullInstallPath)
2502 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross12fc4972016-01-11 12:49:11 -08002503 }
Jiyong Park073ea552020-11-09 14:08:34 +09002504
2505 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2506 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2507 srcPath: nil,
2508 symlinkTarget: relPath,
2509 executable: false,
2510 })
2511
Colin Cross3854a602016-01-11 12:49:11 -08002512 return fullInstallPath
2513}
2514
Jiyong Parkf1194352019-02-25 11:05:47 +09002515// installPath/name -> absPath where absPath might be a path that is available only at runtime
2516// (e.g. /apex/...)
Colin Cross70dda7e2019-10-01 22:05:35 -07002517func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath {
Colin Cross25de6c32019-06-06 14:29:25 -07002518 fullInstallPath := installPath.Join(m, name)
David Srbecky07656412020-06-04 01:26:16 +01002519 m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true)
Jiyong Parkf1194352019-02-25 11:05:47 +09002520
Colin Cross25de6c32019-06-06 14:29:25 -07002521 if !m.skipInstall(fullInstallPath) {
2522 m.Build(pctx, BuildParams{
Jiyong Parkf1194352019-02-25 11:05:47 +09002523 Rule: Symlink,
2524 Description: "install symlink " + fullInstallPath.Base() + " -> " + absPath,
2525 Output: fullInstallPath,
Jingwen Chencda22c92020-11-23 00:22:30 -05002526 Default: !m.Config().KatiEnabled(),
Jiyong Parkf1194352019-02-25 11:05:47 +09002527 Args: map[string]string{
2528 "fromPath": absPath,
2529 },
2530 })
2531
Colin Cross25de6c32019-06-06 14:29:25 -07002532 m.installFiles = append(m.installFiles, fullInstallPath)
Jiyong Parkf1194352019-02-25 11:05:47 +09002533 }
Jiyong Park073ea552020-11-09 14:08:34 +09002534
2535 m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{
2536 relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()),
2537 srcPath: nil,
2538 symlinkTarget: absPath,
2539 executable: false,
2540 })
2541
Jiyong Parkf1194352019-02-25 11:05:47 +09002542 return fullInstallPath
2543}
2544
Colin Cross25de6c32019-06-06 14:29:25 -07002545func (m *moduleContext) CheckbuildFile(srcPath Path) {
2546 m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
Colin Cross3f40fa42015-01-30 17:27:36 -08002547}
2548
Colin Crossc20dc852020-11-10 12:27:45 -08002549func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext {
2550 return m.bp
2551}
2552
Colin Cross41955e82019-05-29 14:40:35 -07002553// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
2554// was not a module reference.
2555func SrcIsModule(s string) (module string) {
Colin Cross068e0fe2016-12-13 15:23:47 -08002556 if len(s) > 1 && s[0] == ':' {
2557 return s[1:]
2558 }
2559 return ""
2560}
2561
Colin Cross41955e82019-05-29 14:40:35 -07002562// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the
2563// module name and an empty string for the tag, or empty strings if the input was not a module reference.
2564func SrcIsModuleWithTag(s string) (module, tag string) {
2565 if len(s) > 1 && s[0] == ':' {
2566 module = s[1:]
2567 if tagStart := strings.IndexByte(module, '{'); tagStart > 0 {
2568 if module[len(module)-1] == '}' {
2569 tag = module[tagStart+1 : len(module)-1]
2570 module = module[:tagStart]
2571 return module, tag
2572 }
2573 }
2574 return module, ""
2575 }
2576 return "", ""
Colin Cross068e0fe2016-12-13 15:23:47 -08002577}
2578
Colin Cross41955e82019-05-29 14:40:35 -07002579type sourceOrOutputDependencyTag struct {
2580 blueprint.BaseDependencyTag
2581 tag string
2582}
2583
2584func sourceOrOutputDepTag(tag string) blueprint.DependencyTag {
2585 return sourceOrOutputDependencyTag{tag: tag}
2586}
2587
2588var SourceDepTag = sourceOrOutputDepTag("")
Colin Cross068e0fe2016-12-13 15:23:47 -08002589
Colin Cross366938f2017-12-11 16:29:02 -08002590// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
2591// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002592//
2593// Deprecated: tag the property with `android:"path"` instead.
Colin Cross068e0fe2016-12-13 15:23:47 -08002594func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
Nan Zhang2439eb72017-04-10 11:27:50 -07002595 set := make(map[string]bool)
2596
Colin Cross068e0fe2016-12-13 15:23:47 -08002597 for _, s := range srcFiles {
Colin Cross41955e82019-05-29 14:40:35 -07002598 if m, t := SrcIsModuleWithTag(s); m != "" {
2599 if _, found := set[s]; found {
2600 ctx.ModuleErrorf("found source dependency duplicate: %q!", s)
Nan Zhang2439eb72017-04-10 11:27:50 -07002601 } else {
Colin Cross41955e82019-05-29 14:40:35 -07002602 set[s] = true
2603 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Nan Zhang2439eb72017-04-10 11:27:50 -07002604 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002605 }
2606 }
Colin Cross068e0fe2016-12-13 15:23:47 -08002607}
2608
Colin Cross366938f2017-12-11 16:29:02 -08002609// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
2610// using ":module" syntax, if any.
Colin Cross27b922f2019-03-04 22:35:41 -08002611//
2612// Deprecated: tag the property with `android:"path"` instead.
Colin Cross366938f2017-12-11 16:29:02 -08002613func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
2614 if s != nil {
Colin Cross41955e82019-05-29 14:40:35 -07002615 if m, t := SrcIsModuleWithTag(*s); m != "" {
2616 ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
Colin Cross366938f2017-12-11 16:29:02 -08002617 }
2618 }
2619}
2620
Colin Cross41955e82019-05-29 14:40:35 -07002621// A module that implements SourceFileProducer can be referenced from any property that is tagged with `android:"path"`
2622// 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 -08002623type SourceFileProducer interface {
2624 Srcs() Paths
2625}
2626
Colin Cross41955e82019-05-29 14:40:35 -07002627// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
Roland Levillain97c1f342019-11-22 14:20:54 +00002628// 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 -07002629// listed in the property.
2630type OutputFileProducer interface {
2631 OutputFiles(tag string) (Paths, error)
2632}
2633
Colin Cross5e708052019-08-06 13:59:50 -07002634// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag. On error, including if the
2635// module produced zero paths, it reports errors to the ctx and returns nil.
2636func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
2637 paths, err := outputFilesForModule(ctx, module, tag)
2638 if err != nil {
2639 reportPathError(ctx, err)
2640 return nil
2641 }
2642 return paths
2643}
2644
2645// OutputFileForModule returns the path from an OutputFileProducer with the given tag. On error, including if the
2646// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
2647func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
2648 paths, err := outputFilesForModule(ctx, module, tag)
2649 if err != nil {
2650 reportPathError(ctx, err)
2651 return nil
2652 }
2653 if len(paths) > 1 {
Ulya Trafimovich5ab276a2020-08-25 12:45:15 +01002654 ReportPathErrorf(ctx, "got multiple output files from module %q, expected exactly one",
Colin Cross5e708052019-08-06 13:59:50 -07002655 pathContextName(ctx, module))
2656 return nil
2657 }
2658 return paths[0]
2659}
2660
2661func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
2662 if outputFileProducer, ok := module.(OutputFileProducer); ok {
2663 paths, err := outputFileProducer.OutputFiles(tag)
2664 if err != nil {
2665 return nil, fmt.Errorf("failed to get output file from module %q: %s",
2666 pathContextName(ctx, module), err.Error())
2667 }
2668 if len(paths) == 0 {
2669 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2670 }
2671 return paths, nil
Colin Cross74b1e2b2020-11-22 20:23:02 -08002672 } else if sourceFileProducer, ok := module.(SourceFileProducer); ok {
2673 if tag != "" {
2674 return nil, fmt.Errorf("module %q is a SourceFileProducer, not an OutputFileProducer, and so does not support tag %q", pathContextName(ctx, module), tag)
2675 }
2676 paths := sourceFileProducer.Srcs()
2677 if len(paths) == 0 {
2678 return nil, fmt.Errorf("failed to get output files from module %q", pathContextName(ctx, module))
2679 }
2680 return paths, nil
Colin Cross5e708052019-08-06 13:59:50 -07002681 } else {
2682 return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
2683 }
2684}
2685
Colin Crossfe17f6f2019-03-28 19:30:56 -07002686type HostToolProvider interface {
2687 HostToolPath() OptionalPath
2688}
2689
Colin Cross27b922f2019-03-04 22:35:41 -08002690// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
2691// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002692//
2693// Deprecated: use PathsForModuleSrc or PathsForModuleSrcExcludes instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002694func (m *moduleContext) ExpandSources(srcFiles, excludes []string) Paths {
2695 return PathsForModuleSrcExcludes(m, srcFiles, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07002696}
2697
Colin Cross2fafa3e2019-03-05 12:39:51 -08002698// Returns a single path expanded from globs and modules referenced using ":module" syntax. The property must
2699// be tagged with `android:"path" to support automatic source module dependency resolution.
Colin Cross8a497952019-03-05 22:25:09 -08002700//
2701// Deprecated: use PathForModuleSrc instead.
Colin Cross25de6c32019-06-06 14:29:25 -07002702func (m *moduleContext) ExpandSource(srcFile, prop string) Path {
2703 return PathForModuleSrc(m, srcFile)
Colin Cross2fafa3e2019-03-05 12:39:51 -08002704}
2705
2706// Returns an optional single path expanded from globs and modules referenced using ":module" syntax if
2707// the srcFile is non-nil. The property must be tagged with `android:"path" to support automatic source module
2708// dependency resolution.
Colin Cross25de6c32019-06-06 14:29:25 -07002709func (m *moduleContext) ExpandOptionalSource(srcFile *string, prop string) OptionalPath {
Colin Cross2fafa3e2019-03-05 12:39:51 -08002710 if srcFile != nil {
Colin Cross25de6c32019-06-06 14:29:25 -07002711 return OptionalPathForPath(PathForModuleSrc(m, *srcFile))
Colin Cross2fafa3e2019-03-05 12:39:51 -08002712 }
2713 return OptionalPath{}
2714}
2715
Colin Cross25de6c32019-06-06 14:29:25 -07002716func (m *moduleContext) RequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002717 return m.module.RequiredModuleNames()
Nan Zhang6d34b302017-02-04 17:47:46 -08002718}
2719
Colin Cross25de6c32019-06-06 14:29:25 -07002720func (m *moduleContext) HostRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002721 return m.module.HostRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002722}
2723
Colin Cross25de6c32019-06-06 14:29:25 -07002724func (m *moduleContext) TargetRequiredModuleNames() []string {
Jiyong Park6a8cf5f2019-12-30 16:31:09 +09002725 return m.module.TargetRequiredModuleNames()
Sasha Smundakb6d23052019-04-01 18:37:36 -07002726}
2727
Colin Cross463a90e2015-06-17 14:20:06 -07002728func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07002729 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07002730}
2731
Colin Cross0875c522017-11-28 17:34:01 -08002732func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07002733 return &buildTargetSingleton{}
2734}
2735
Colin Cross87d8b562017-04-25 10:01:55 -07002736func parentDir(dir string) string {
2737 dir, _ = filepath.Split(dir)
2738 return filepath.Clean(dir)
2739}
2740
Colin Cross1f8c52b2015-06-16 16:38:17 -07002741type buildTargetSingleton struct{}
2742
Colin Cross0875c522017-11-28 17:34:01 -08002743func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
2744 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07002745
Colin Crossc3d87d32020-06-04 13:25:17 -07002746 mmTarget := func(dir string) string {
2747 return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1)
Colin Cross87d8b562017-04-25 10:01:55 -07002748 }
2749
Colin Cross0875c522017-11-28 17:34:01 -08002750 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002751
Colin Cross0875c522017-11-28 17:34:01 -08002752 ctx.VisitAllModules(func(module Module) {
2753 blueprintDir := module.base().blueprintDir
2754 installTarget := module.base().installTarget
2755 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07002756
Colin Cross0875c522017-11-28 17:34:01 -08002757 if checkbuildTarget != nil {
2758 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
2759 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
2760 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002761
Colin Cross0875c522017-11-28 17:34:01 -08002762 if installTarget != nil {
2763 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002764 }
2765 })
2766
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002767 suffix := ""
Jingwen Chencda22c92020-11-23 00:22:30 -05002768 if ctx.Config().KatiEnabled() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08002769 suffix = "-soong"
2770 }
2771
Colin Cross1f8c52b2015-06-16 16:38:17 -07002772 // Create a top-level checkbuild target that depends on all modules
Colin Crossc3d87d32020-06-04 13:25:17 -07002773 ctx.Phony("checkbuild"+suffix, checkbuildDeps...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002774
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002775 // Make will generate the MODULES-IN-* targets
Jingwen Chencda22c92020-11-23 00:22:30 -05002776 if ctx.Config().KatiEnabled() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002777 return
2778 }
2779
Colin Cross87d8b562017-04-25 10:01:55 -07002780 // Ensure ancestor directories are in modulesInDir
Inseob Kim1a365c62019-06-08 15:47:51 +09002781 dirs := SortedStringKeys(modulesInDir)
Colin Cross87d8b562017-04-25 10:01:55 -07002782 for _, dir := range dirs {
2783 dir := parentDir(dir)
2784 for dir != "." && dir != "/" {
2785 if _, exists := modulesInDir[dir]; exists {
2786 break
2787 }
2788 modulesInDir[dir] = nil
2789 dir = parentDir(dir)
2790 }
2791 }
2792
2793 // Make directories build their direct subdirectories
Colin Cross87d8b562017-04-25 10:01:55 -07002794 for _, dir := range dirs {
2795 p := parentDir(dir)
2796 if p != "." && p != "/" {
Colin Crossc3d87d32020-06-04 13:25:17 -07002797 modulesInDir[p] = append(modulesInDir[p], PathForPhony(ctx, mmTarget(dir)))
Colin Cross87d8b562017-04-25 10:01:55 -07002798 }
2799 }
2800
Dan Willemsend2e95fb2017-09-20 14:30:50 -07002801 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
2802 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
2803 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07002804 for _, dir := range dirs {
Colin Crossc3d87d32020-06-04 13:25:17 -07002805 ctx.Phony(mmTarget(dir), modulesInDir[dir]...)
Colin Cross1f8c52b2015-06-16 16:38:17 -07002806 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002807
2808 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
Jiyong Park1613e552020-09-14 19:43:17 +09002809 type osAndCross struct {
2810 os OsType
2811 hostCross bool
2812 }
2813 osDeps := map[osAndCross]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08002814 ctx.VisitAllModules(func(module Module) {
2815 if module.Enabled() {
Jiyong Park1613e552020-09-14 19:43:17 +09002816 key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
2817 osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002818 }
2819 })
2820
Colin Cross0875c522017-11-28 17:34:01 -08002821 osClass := make(map[string]Paths)
Jiyong Park1613e552020-09-14 19:43:17 +09002822 for key, deps := range osDeps {
Dan Willemsen61d88b82017-09-20 17:29:08 -07002823 var className string
2824
Jiyong Park1613e552020-09-14 19:43:17 +09002825 switch key.os.Class {
Dan Willemsen61d88b82017-09-20 17:29:08 -07002826 case Host:
Jiyong Park1613e552020-09-14 19:43:17 +09002827 if key.hostCross {
2828 className = "host-cross"
2829 } else {
2830 className = "host"
2831 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07002832 case Device:
2833 className = "target"
2834 default:
2835 continue
2836 }
2837
Jiyong Park1613e552020-09-14 19:43:17 +09002838 name := className + "-" + key.os.Name
Colin Crossc3d87d32020-06-04 13:25:17 -07002839 osClass[className] = append(osClass[className], PathForPhony(ctx, name))
Dan Willemsen61d88b82017-09-20 17:29:08 -07002840
Colin Crossc3d87d32020-06-04 13:25:17 -07002841 ctx.Phony(name, deps...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002842 }
2843
2844 // Wrap those into host|host-cross|target phony rules
Inseob Kim1a365c62019-06-08 15:47:51 +09002845 for _, class := range SortedStringKeys(osClass) {
Colin Crossc3d87d32020-06-04 13:25:17 -07002846 ctx.Phony(class, osClass[class]...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07002847 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07002848}
Colin Crossd779da42015-12-17 18:00:23 -08002849
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002850// Collect information for opening IDE project files in java/jdeps.go.
2851type IDEInfo interface {
2852 IDEInfo(ideInfo *IdeInfo)
2853 BaseModuleName() string
2854}
2855
2856// Extract the base module name from the Import name.
2857// Often the Import name has a prefix "prebuilt_".
2858// Remove the prefix explicitly if needed
2859// until we find a better solution to get the Import name.
2860type IDECustomizedModuleName interface {
2861 IDECustomizedModuleName() string
2862}
2863
2864type IdeInfo struct {
2865 Deps []string `json:"dependencies,omitempty"`
2866 Srcs []string `json:"srcs,omitempty"`
2867 Aidl_include_dirs []string `json:"aidl_include_dirs,omitempty"`
2868 Jarjar_rules []string `json:"jarjar_rules,omitempty"`
2869 Jars []string `json:"jars,omitempty"`
2870 Classes []string `json:"class,omitempty"`
2871 Installed_paths []string `json:"installed,omitempty"`
patricktu18c82ff2019-05-10 15:48:50 +08002872 SrcJars []string `json:"srcjars,omitempty"`
bralee1fbf4402020-05-21 10:11:59 +08002873 Paths []string `json:"path,omitempty"`
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002874}
Paul Duffinf88d8e02020-05-07 20:21:34 +01002875
2876func CheckBlueprintSyntax(ctx BaseModuleContext, filename string, contents string) []error {
2877 bpctx := ctx.blueprintBaseModuleContext()
2878 return blueprint.CheckBlueprintSyntax(bpctx.ModuleFactories(), filename, contents)
2879}
Colin Cross5d583952020-11-24 16:21:24 -08002880
2881// installPathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
2882// topological order.
2883type installPathsDepSet struct {
2884 depSet
2885}
2886
2887// newInstallPathsDepSet returns an immutable packagingSpecsDepSet with the given direct and
2888// transitive contents.
2889func newInstallPathsDepSet(direct InstallPaths, transitive []*installPathsDepSet) *installPathsDepSet {
2890 return &installPathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
2891}
2892
2893// ToList returns the installPathsDepSet flattened to a list in topological order.
2894func (d *installPathsDepSet) ToList() InstallPaths {
2895 if d == nil {
2896 return nil
2897 }
2898 return d.depSet.ToList().(InstallPaths)
2899}