blob: 3d8f6838dc96b16384c65440b5f1eb58def1e8b1 [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 Cross3f40fa42015-01-30 17:27:36 -080019 "path/filepath"
Colin Cross0875c522017-11-28 17:34:01 -080020 "sort"
Colin Cross6ff51382015-12-17 16:39:19 -080021 "strings"
Colin Crossaabf6792017-11-29 00:27:14 -080022 "text/scanner"
Colin Crossf6566ed2015-03-24 11:13:38 -070023
24 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070025 "github.com/google/blueprint/pathtools"
Colin Cross3f40fa42015-01-30 17:27:36 -080026)
27
28var (
29 DeviceSharedLibrary = "shared_library"
30 DeviceStaticLibrary = "static_library"
31 DeviceExecutable = "executable"
32 HostSharedLibrary = "host_shared_library"
33 HostStaticLibrary = "host_static_library"
34 HostExecutable = "host_executable"
35)
36
Colin Crossae887032017-10-23 17:16:14 -070037type BuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070038 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080039 Deps blueprint.Deps
40 Depfile WritablePath
Colin Cross67a5c132017-05-09 13:45:28 -070041 Description string
Dan Willemsen9f3c5742016-11-03 14:28:31 -070042 Output WritablePath
43 Outputs WritablePaths
44 ImplicitOutput WritablePath
45 ImplicitOutputs WritablePaths
46 Input Path
47 Inputs Paths
48 Implicit Path
49 Implicits Paths
50 OrderOnly Paths
51 Default bool
52 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070053}
54
Colin Crossae887032017-10-23 17:16:14 -070055type ModuleBuildParams BuildParams
56
Colin Crossf6566ed2015-03-24 11:13:38 -070057type androidBaseContext interface {
Colin Crossa1ad8d12016-06-01 17:09:44 -070058 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070059 TargetPrimary() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070060 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070061 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070062 Host() bool
63 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070064 Darwin() bool
Colin Cross3edeee12017-04-04 12:59:48 -070065 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070066 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070067 PrimaryArch() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070068 InstallOnVendorPartition() bool
Colin Cross1332b002015-04-07 17:11:30 -070069 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -070070 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -070071}
72
Colin Cross635c3b02016-05-18 15:37:25 -070073type BaseContext interface {
Colin Crossaabf6792017-11-29 00:27:14 -080074 BaseModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -070075 androidBaseContext
76}
77
Colin Crossaabf6792017-11-29 00:27:14 -080078// BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns
79// a Config instead of an interface{}.
80type BaseModuleContext interface {
81 ModuleName() string
82 ModuleDir() string
83 Config() Config
84
85 ContainsProperty(name string) bool
86 Errorf(pos scanner.Position, fmt string, args ...interface{})
87 ModuleErrorf(fmt string, args ...interface{})
88 PropertyErrorf(property, fmt string, args ...interface{})
89 Failed() bool
90
91 // GlobWithDeps returns a list of files that match the specified pattern but do not match any
92 // of the patterns in excludes. It also adds efficient dependencies to rerun the primary
93 // builder whenever a file matching the pattern as added or removed, without rerunning if a
94 // file that does not match the pattern is added to a searched directory.
95 GlobWithDeps(pattern string, excludes []string) ([]string, error)
96
97 Fs() pathtools.FileSystem
98 AddNinjaFileDeps(deps ...string)
99}
100
Colin Cross635c3b02016-05-18 15:37:25 -0700101type ModuleContext interface {
Colin Crossf6566ed2015-03-24 11:13:38 -0700102 androidBaseContext
Colin Crossaabf6792017-11-29 00:27:14 -0800103 BaseModuleContext
Colin Cross3f40fa42015-01-30 17:27:36 -0800104
Colin Crossae887032017-10-23 17:16:14 -0700105 // Deprecated: use ModuleContext.Build instead.
Colin Cross0875c522017-11-28 17:34:01 -0800106 ModuleBuild(pctx PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -0700107
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108 ExpandSources(srcFiles, excludes []string) Paths
Colin Cross366938f2017-12-11 16:29:02 -0800109 ExpandSource(srcFile, prop string) Path
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800110 ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths
Colin Cross7f19f372016-11-01 11:10:25 -0700111 Glob(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross5c517922017-08-31 12:29:17 -0700113 InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
114 InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -0800115 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800117
118 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -0700119
Colin Cross8d8f8e22016-08-03 11:57:50 -0700120 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700121 InstallInSanitizerDir() bool
Nan Zhang6d34b302017-02-04 17:47:46 -0800122
123 RequiredModuleNames() []string
Colin Cross3f68a132017-10-23 17:10:29 -0700124
125 // android.ModuleContext methods
126 // These are duplicated instead of embedded so that can eventually be wrapped to take an
127 // android.Module instead of a blueprint.Module
128 OtherModuleName(m blueprint.Module) string
129 OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
130 OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
131
132 GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
133 GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
134
135 ModuleSubDir() string
136
Colin Cross35143d02017-11-16 00:11:20 -0800137 VisitDirectDepsBlueprint(visit func(blueprint.Module))
Colin Crossd11fcda2017-10-23 17:59:01 -0700138 VisitDirectDeps(visit func(Module))
139 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
140 VisitDepsDepthFirst(visit func(Module))
141 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
142 WalkDeps(visit func(Module, Module) bool)
Colin Cross3f68a132017-10-23 17:10:29 -0700143
Colin Cross0875c522017-11-28 17:34:01 -0800144 Variable(pctx PackageContext, name, value string)
145 Rule(pctx PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule
Colin Crossae887032017-10-23 17:16:14 -0700146 // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string,
147 // and performs more verification.
Colin Cross0875c522017-11-28 17:34:01 -0800148 Build(pctx PackageContext, params BuildParams)
Colin Cross3f68a132017-10-23 17:10:29 -0700149
Colin Cross0875c522017-11-28 17:34:01 -0800150 PrimaryModule() Module
151 FinalModule() Module
152 VisitAllModuleVariants(visit func(Module))
Colin Cross3f68a132017-10-23 17:10:29 -0700153
154 GetMissingDependencies() []string
Jeff Gaston088e29e2017-11-29 16:47:17 -0800155 Namespace() blueprint.Namespace
Colin Cross3f40fa42015-01-30 17:27:36 -0800156}
157
Colin Cross635c3b02016-05-18 15:37:25 -0700158type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -0800159 blueprint.Module
160
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700161 // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
162 // but GenerateAndroidBuildActions also has access to Android-specific information.
163 // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
Colin Cross635c3b02016-05-18 15:37:25 -0700164 GenerateAndroidBuildActions(ModuleContext)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700165
Colin Cross1e676be2016-10-12 14:38:15 -0700166 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800167
Colin Cross635c3b02016-05-18 15:37:25 -0700168 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800169 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700170 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800171 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700172 InstallInSanitizerDir() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800173 SkipInstall()
Colin Cross36242852017-06-23 15:06:31 -0700174
175 AddProperties(props ...interface{})
176 GetProperties() []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700177
Colin Crossae887032017-10-23 17:16:14 -0700178 BuildParamsForTests() []BuildParams
Colin Cross3f40fa42015-01-30 17:27:36 -0800179}
180
Colin Crossfc754582016-05-17 16:34:16 -0700181type nameProperties struct {
182 // The name of the module. Must be unique across all modules.
Nan Zhang0007d812017-11-07 10:57:05 -0800183 Name *string
Colin Crossfc754582016-05-17 16:34:16 -0700184}
185
186type commonProperties struct {
Colin Crossc77f9d12015-04-02 13:54:39 -0700187 Tags []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800188
Dan Willemsen0effe062015-11-30 16:06:01 -0800189 // emit build rules for this module
190 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800191
Colin Cross7d5136f2015-05-11 13:39:40 -0700192 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800193 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
194 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
195 // platform
Colin Cross7d716ba2017-11-01 10:38:29 -0700196 Compile_multilib *string `android:"arch_variant"`
Colin Cross69617d32016-09-06 10:39:07 -0700197
198 Target struct {
199 Host struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700200 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700201 }
202 Android struct {
Colin Cross7d716ba2017-11-01 10:38:29 -0700203 Compile_multilib *string
Colin Cross69617d32016-09-06 10:39:07 -0700204 }
205 }
206
207 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800208
Dan Willemsen782a2d12015-12-21 14:55:28 -0800209 // whether this is a proprietary vendor module, and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700210 Proprietary *bool
Dan Willemsen782a2d12015-12-21 14:55:28 -0800211
Colin Cross55708f32017-03-20 13:23:34 -0700212 // vendor who owns this module
Dan Willemsenefac4a82017-07-18 19:42:09 -0700213 Owner *string
Colin Cross55708f32017-03-20 13:23:34 -0700214
Dan Willemsenaa118f92017-04-06 12:49:58 -0700215 // whether this module is device specific and should be installed into /vendor
Colin Cross7d716ba2017-11-01 10:38:29 -0700216 Vendor *bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700217
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700218 // init.rc files to be installed if this module is installed
219 Init_rc []string
220
Chris Wolfe998306e2016-08-15 14:47:23 -0400221 // names of other modules to install if this module is installed
Colin Crossc602b7d2017-05-05 13:36:36 -0700222 Required []string `android:"arch_variant"`
Chris Wolfe998306e2016-08-15 14:47:23 -0400223
Colin Cross5aac3622017-08-31 15:07:09 -0700224 // relative path to a file to include in the list of notices for the device
225 Notice *string
226
Colin Crossa1ad8d12016-06-01 17:09:44 -0700227 // Set by TargetMutator
Colin Cross8b74d172016-09-13 09:59:14 -0700228 CompileTarget Target `blueprint:"mutated"`
229 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800230
231 // Set by InitAndroidModule
232 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700233 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700234
235 SkipInstall bool `blueprint:"mutated"`
Jeff Gaston088e29e2017-11-29 16:47:17 -0800236
237 NamespaceExportedToMake bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800238}
239
240type hostAndDeviceProperties struct {
Colin Crossa4190c12016-07-12 13:11:25 -0700241 Host_supported *bool
242 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800243}
244
Colin Crossc472d572015-03-17 15:06:21 -0700245type Multilib string
246
247const (
Colin Cross6b4a32d2017-12-05 13:42:45 -0800248 MultilibBoth Multilib = "both"
249 MultilibFirst Multilib = "first"
250 MultilibCommon Multilib = "common"
251 MultilibCommonFirst Multilib = "common_first"
252 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700253)
254
Colin Crossa1ad8d12016-06-01 17:09:44 -0700255type HostOrDeviceSupported int
256
257const (
258 _ HostOrDeviceSupported = iota
259 HostSupported
Dan Albertc6345fb2016-10-20 01:36:11 -0700260 HostSupportedNoCross
Colin Crossa1ad8d12016-06-01 17:09:44 -0700261 DeviceSupported
262 HostAndDeviceSupported
263 HostAndDeviceDefault
Dan Willemsen0b24c742016-10-04 15:13:37 -0700264 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700265)
266
Colin Cross36242852017-06-23 15:06:31 -0700267func InitAndroidModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800268 base := m.base()
269 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700270
Colin Cross36242852017-06-23 15:06:31 -0700271 m.AddProperties(
Colin Crossfc754582016-05-17 16:34:16 -0700272 &base.nameProperties,
273 &base.commonProperties,
274 &base.variableProperties)
Colin Cross5049f022015-03-18 13:28:46 -0700275}
276
Colin Cross36242852017-06-23 15:06:31 -0700277func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
278 InitAndroidModule(m)
Colin Cross5049f022015-03-18 13:28:46 -0700279
280 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800281 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700282 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700283 base.commonProperties.ArchSpecific = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800284
Dan Willemsen218f6562015-07-08 18:13:11 -0700285 switch hod {
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700286 case HostAndDeviceSupported, HostAndDeviceDefault:
Colin Cross36242852017-06-23 15:06:31 -0700287 m.AddProperties(&base.hostAndDeviceProperties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800288 }
289
Colin Cross36242852017-06-23 15:06:31 -0700290 InitArchModule(m)
Colin Cross3f40fa42015-01-30 17:27:36 -0800291}
292
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800293// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800294// modules. It should be included as an anonymous field in every module
295// struct definition. InitAndroidModule should then be called from the module's
296// factory function, and the return values from InitAndroidModule should be
297// returned from the factory function.
298//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800299// The ModuleBase type is responsible for implementing the GenerateBuildActions
300// method to support the blueprint.Module interface. This method will then call
301// the module's GenerateAndroidBuildActions method once for each build variant
302// that is to be built. GenerateAndroidBuildActions is passed a
303// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800304// AndroidModuleContext exposes extra functionality specific to the Android build
305// system including details about the particular build variant that is to be
306// generated.
307//
308// For example:
309//
310// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800311// "android/soong/android"
Colin Cross3f40fa42015-01-30 17:27:36 -0800312// )
313//
314// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800315// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800316// properties struct {
317// MyProperty string
318// }
319// }
320//
Colin Cross36242852017-06-23 15:06:31 -0700321// func NewMyModule() android.Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800322// m := &myModule{}
Colin Cross36242852017-06-23 15:06:31 -0700323// m.AddProperties(&m.properties)
324// android.InitAndroidModule(m)
325// return m
Colin Cross3f40fa42015-01-30 17:27:36 -0800326// }
327//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800328// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800329// // Get the CPU architecture for the current build variant.
330// variantArch := ctx.Arch()
331//
332// // ...
333// }
Colin Cross635c3b02016-05-18 15:37:25 -0700334type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800335 // Putting the curiously recurring thing pointing to the thing that contains
336 // the thing pattern to good use.
Colin Cross36242852017-06-23 15:06:31 -0700337 // TODO: remove this
Colin Cross635c3b02016-05-18 15:37:25 -0700338 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800339
Colin Crossfc754582016-05-17 16:34:16 -0700340 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800341 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700342 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800343 hostAndDeviceProperties hostAndDeviceProperties
344 generalProperties []interface{}
Dan Willemsenb1957a52016-06-23 23:44:54 -0700345 archProperties []interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700346 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800347
348 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700349 installFiles Paths
350 checkbuildFiles Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -0700351
352 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
353 // Only set on the final variant of each module
Colin Cross0875c522017-11-28 17:34:01 -0800354 installTarget WritablePath
355 checkbuildTarget WritablePath
Colin Cross1f8c52b2015-06-16 16:38:17 -0700356 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700357
Colin Cross178a5092016-09-13 13:42:32 -0700358 hooks hooks
Colin Cross36242852017-06-23 15:06:31 -0700359
360 registerProps []interface{}
Colin Crosscec81712017-07-13 14:43:27 -0700361
362 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700363 buildParams []BuildParams
Colin Cross36242852017-06-23 15:06:31 -0700364}
365
366func (a *ModuleBase) AddProperties(props ...interface{}) {
367 a.registerProps = append(a.registerProps, props...)
368}
369
370func (a *ModuleBase) GetProperties() []interface{} {
371 return a.registerProps
Colin Cross3f40fa42015-01-30 17:27:36 -0800372}
373
Colin Crossae887032017-10-23 17:16:14 -0700374func (a *ModuleBase) BuildParamsForTests() []BuildParams {
Colin Crosscec81712017-07-13 14:43:27 -0700375 return a.buildParams
376}
377
Colin Crossce75d2c2016-10-06 16:12:58 -0700378// Name returns the name of the module. It may be overridden by individual module types, for
379// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700380func (a *ModuleBase) Name() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800381 return String(a.nameProperties.Name)
Colin Crossfc754582016-05-17 16:34:16 -0700382}
383
Colin Crossce75d2c2016-10-06 16:12:58 -0700384// BaseModuleName returns the name of the module as specified in the blueprints file.
385func (a *ModuleBase) BaseModuleName() string {
Nan Zhang0007d812017-11-07 10:57:05 -0800386 return String(a.nameProperties.Name)
Colin Crossce75d2c2016-10-06 16:12:58 -0700387}
388
Colin Cross635c3b02016-05-18 15:37:25 -0700389func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800390 return a
391}
392
Colin Cross8b74d172016-09-13 09:59:14 -0700393func (a *ModuleBase) SetTarget(target Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700394 a.commonProperties.CompileTarget = target
Colin Cross8b74d172016-09-13 09:59:14 -0700395 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700396}
397
Colin Crossa1ad8d12016-06-01 17:09:44 -0700398func (a *ModuleBase) Target() Target {
399 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800400}
401
Colin Cross8b74d172016-09-13 09:59:14 -0700402func (a *ModuleBase) TargetPrimary() bool {
403 return a.commonProperties.CompilePrimary
404}
405
Colin Crossa1ad8d12016-06-01 17:09:44 -0700406func (a *ModuleBase) Os() OsType {
407 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800408}
409
Colin Cross635c3b02016-05-18 15:37:25 -0700410func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700411 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800412}
413
Colin Cross635c3b02016-05-18 15:37:25 -0700414func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700415 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800416}
417
Dan Willemsen0b24c742016-10-04 15:13:37 -0700418func (a *ModuleBase) ArchSpecific() bool {
419 return a.commonProperties.ArchSpecific
420}
421
Colin Crossa1ad8d12016-06-01 17:09:44 -0700422func (a *ModuleBase) OsClassSupported() []OsClass {
423 switch a.commonProperties.HostOrDeviceSupported {
424 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700425 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700426 case HostSupportedNoCross:
427 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700428 case DeviceSupported:
429 return []OsClass{Device}
430 case HostAndDeviceSupported:
431 var supported []OsClass
Colin Crossa4190c12016-07-12 13:11:25 -0700432 if Bool(a.hostAndDeviceProperties.Host_supported) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700433 supported = append(supported, Host, HostCross)
434 }
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700435 if a.hostAndDeviceProperties.Device_supported == nil ||
436 *a.hostAndDeviceProperties.Device_supported {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700437 supported = append(supported, Device)
438 }
439 return supported
440 default:
441 return nil
442 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800443}
444
Colin Cross635c3b02016-05-18 15:37:25 -0700445func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800446 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
447 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Nan Zhang1a0f09b2017-07-05 10:35:11 -0700448 (a.hostAndDeviceProperties.Device_supported == nil ||
449 *a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800450}
451
Colin Cross635c3b02016-05-18 15:37:25 -0700452func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800453 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800454 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800455 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800456 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800457}
458
Colin Crossce75d2c2016-10-06 16:12:58 -0700459func (a *ModuleBase) SkipInstall() {
460 a.commonProperties.SkipInstall = true
461}
462
Colin Cross635c3b02016-05-18 15:37:25 -0700463func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700464 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800465
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700466 result := Paths{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800467 ctx.VisitDepsDepthFirstIf(isFileInstaller,
468 func(m blueprint.Module) {
469 fileInstaller := m.(fileInstaller)
470 files := fileInstaller.filesToInstall()
471 result = append(result, files...)
472 })
473
474 return result
475}
476
Colin Cross635c3b02016-05-18 15:37:25 -0700477func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800478 return a.installFiles
479}
480
Colin Cross635c3b02016-05-18 15:37:25 -0700481func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800482 return p.noAddressSanitizer
483}
484
Colin Cross635c3b02016-05-18 15:37:25 -0700485func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800486 return false
487}
488
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700489func (p *ModuleBase) InstallInSanitizerDir() bool {
490 return false
491}
492
Colin Cross0875c522017-11-28 17:34:01 -0800493func (a *ModuleBase) generateModuleTarget(ctx ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700494 allInstalledFiles := Paths{}
495 allCheckbuildFiles := Paths{}
Colin Cross0875c522017-11-28 17:34:01 -0800496 ctx.VisitAllModuleVariants(func(module Module) {
497 a := module.base()
Colin Crossc9404352015-03-26 16:10:12 -0700498 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
499 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800500 })
501
Colin Cross0875c522017-11-28 17:34:01 -0800502 var deps Paths
Colin Cross9454bfa2015-03-17 13:24:18 -0700503
Jeff Gaston088e29e2017-11-29 16:47:17 -0800504 namespacePrefix := ctx.Namespace().(*Namespace).id
505 if namespacePrefix != "" {
506 namespacePrefix = namespacePrefix + "-"
507 }
508
Colin Cross3f40fa42015-01-30 17:27:36 -0800509 if len(allInstalledFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800510 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-install")
Colin Cross0875c522017-11-28 17:34:01 -0800511 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700512 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800513 Output: name,
514 Implicits: allInstalledFiles,
Colin Crossaabf6792017-11-29 00:27:14 -0800515 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700516 })
517 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700518 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700519 }
520
521 if len(allCheckbuildFiles) > 0 {
Jeff Gaston088e29e2017-11-29 16:47:17 -0800522 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+"-checkbuild")
Colin Cross0875c522017-11-28 17:34:01 -0800523 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700524 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -0800525 Output: name,
526 Implicits: allCheckbuildFiles,
Colin Cross9454bfa2015-03-17 13:24:18 -0700527 })
528 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700529 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700530 }
531
532 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800533 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -0800534 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800535 suffix = "-soong"
536 }
537
Jeff Gaston088e29e2017-11-29 16:47:17 -0800538 name := PathForPhony(ctx, namespacePrefix+ctx.ModuleName()+suffix)
Colin Cross0875c522017-11-28 17:34:01 -0800539 ctx.Build(pctx, BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700540 Rule: blueprint.Phony,
Jeff Gaston088e29e2017-11-29 16:47:17 -0800541 Outputs: []WritablePath{name},
Colin Cross9454bfa2015-03-17 13:24:18 -0700542 Implicits: deps,
Colin Cross3f40fa42015-01-30 17:27:36 -0800543 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700544
545 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800546 }
547}
548
Colin Cross635c3b02016-05-18 15:37:25 -0700549func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700550 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700551 target: a.commonProperties.CompileTarget,
552 targetPrimary: a.commonProperties.CompilePrimary,
Colin Cross7d716ba2017-11-01 10:38:29 -0700553 vendor: Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Vendor),
Colin Cross8b74d172016-09-13 09:59:14 -0700554 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800555 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800556}
557
Colin Cross0875c522017-11-28 17:34:01 -0800558func (a *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) {
559 ctx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700560 module: a.module,
Colin Cross0875c522017-11-28 17:34:01 -0800561 ModuleContext: blueprintCtx,
562 androidBaseContextImpl: a.androidBaseContextFactory(blueprintCtx),
563 installDeps: a.computeInstallDeps(blueprintCtx),
Colin Cross6362e272015-10-29 15:25:03 -0700564 installFiles: a.installFiles,
Colin Cross0875c522017-11-28 17:34:01 -0800565 missingDeps: blueprintCtx.GetMissingDependencies(),
Colin Cross3f40fa42015-01-30 17:27:36 -0800566 }
567
Colin Cross67a5c132017-05-09 13:45:28 -0700568 desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " "
569 var suffix []string
Colin Cross0875c522017-11-28 17:34:01 -0800570 if ctx.Os().Class != Device && ctx.Os().Class != Generic {
571 suffix = append(suffix, ctx.Os().String())
Colin Cross67a5c132017-05-09 13:45:28 -0700572 }
Colin Cross0875c522017-11-28 17:34:01 -0800573 if !ctx.PrimaryArch() {
574 suffix = append(suffix, ctx.Arch().ArchType.String())
Colin Cross67a5c132017-05-09 13:45:28 -0700575 }
576
577 ctx.Variable(pctx, "moduleDesc", desc)
578
579 s := ""
580 if len(suffix) > 0 {
581 s = " [" + strings.Join(suffix, " ") + "]"
582 }
583 ctx.Variable(pctx, "moduleDescSuffix", s)
584
Colin Cross9b1d13d2016-09-19 15:18:11 -0700585 if a.Enabled() {
Colin Cross0875c522017-11-28 17:34:01 -0800586 a.module.GenerateAndroidBuildActions(ctx)
Colin Cross9b1d13d2016-09-19 15:18:11 -0700587 if ctx.Failed() {
588 return
589 }
590
Colin Cross0875c522017-11-28 17:34:01 -0800591 a.installFiles = append(a.installFiles, ctx.installFiles...)
592 a.checkbuildFiles = append(a.checkbuildFiles, ctx.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800593 }
594
Colin Cross9b1d13d2016-09-19 15:18:11 -0700595 if a == ctx.FinalModule().(Module).base() {
596 a.generateModuleTarget(ctx)
597 if ctx.Failed() {
598 return
599 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800600 }
Colin Crosscec81712017-07-13 14:43:27 -0700601
Colin Cross0875c522017-11-28 17:34:01 -0800602 a.buildParams = ctx.buildParams
Colin Cross3f40fa42015-01-30 17:27:36 -0800603}
604
Colin Crossf6566ed2015-03-24 11:13:38 -0700605type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700606 target Target
607 targetPrimary bool
608 debug bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700609 vendor bool
Colin Cross8b74d172016-09-13 09:59:14 -0700610 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700611}
612
Colin Cross3f40fa42015-01-30 17:27:36 -0800613type androidModuleContext struct {
614 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700615 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700616 installDeps Paths
617 installFiles Paths
618 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800619 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700620 module Module
Colin Crosscec81712017-07-13 14:43:27 -0700621
622 // For tests
Colin Crossae887032017-10-23 17:16:14 -0700623 buildParams []BuildParams
Colin Cross6ff51382015-12-17 16:39:19 -0800624}
625
Colin Cross67a5c132017-05-09 13:45:28 -0700626func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) {
Colin Cross0875c522017-11-28 17:34:01 -0800627 a.ModuleContext.Build(pctx.PackageContext, blueprint.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700628 Rule: ErrorRule,
629 Description: desc,
630 Outputs: outputs,
631 Optional: true,
Colin Cross6ff51382015-12-17 16:39:19 -0800632 Args: map[string]string{
633 "error": err.Error(),
634 },
635 })
636 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800637}
638
Colin Crossaabf6792017-11-29 00:27:14 -0800639func (a *androidModuleContext) Config() Config {
640 return a.ModuleContext.Config().(Config)
641}
642
Colin Cross0875c522017-11-28 17:34:01 -0800643func (a *androidModuleContext) ModuleBuild(pctx PackageContext, params ModuleBuildParams) {
Colin Crossae887032017-10-23 17:16:14 -0700644 a.Build(pctx, BuildParams(params))
Colin Cross3f40fa42015-01-30 17:27:36 -0800645}
646
Colin Cross0875c522017-11-28 17:34:01 -0800647func convertBuildParams(params BuildParams) blueprint.BuildParams {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700648 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700649 Rule: params.Rule,
Colin Cross0875c522017-11-28 17:34:01 -0800650 Description: params.Description,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800651 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700652 Outputs: params.Outputs.Strings(),
653 ImplicitOutputs: params.ImplicitOutputs.Strings(),
654 Inputs: params.Inputs.Strings(),
655 Implicits: params.Implicits.Strings(),
656 OrderOnly: params.OrderOnly.Strings(),
657 Args: params.Args,
658 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700659 }
660
Colin Cross33bfb0a2016-11-21 17:23:08 -0800661 if params.Depfile != nil {
662 bparams.Depfile = params.Depfile.String()
663 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700664 if params.Output != nil {
665 bparams.Outputs = append(bparams.Outputs, params.Output.String())
666 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700667 if params.ImplicitOutput != nil {
668 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
669 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700670 if params.Input != nil {
671 bparams.Inputs = append(bparams.Inputs, params.Input.String())
672 }
673 if params.Implicit != nil {
674 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
675 }
676
Colin Cross0875c522017-11-28 17:34:01 -0800677 return bparams
678}
679
680func (a *androidModuleContext) Variable(pctx PackageContext, name, value string) {
681 a.ModuleContext.Variable(pctx.PackageContext, name, value)
682}
683
684func (a *androidModuleContext) Rule(pctx PackageContext, name string, params blueprint.RuleParams,
685 argNames ...string) blueprint.Rule {
686
687 return a.ModuleContext.Rule(pctx.PackageContext, name, params, argNames...)
688}
689
690func (a *androidModuleContext) Build(pctx PackageContext, params BuildParams) {
691 if a.config.captureBuild {
692 a.buildParams = append(a.buildParams, params)
693 }
694
695 bparams := convertBuildParams(params)
696
697 if bparams.Description != "" {
698 bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}"
699 }
700
Colin Cross6ff51382015-12-17 16:39:19 -0800701 if a.missingDeps != nil {
Colin Cross67a5c132017-05-09 13:45:28 -0700702 a.ninjaError(bparams.Description, bparams.Outputs,
703 fmt.Errorf("module %s missing dependencies: %s\n",
704 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
Colin Cross6ff51382015-12-17 16:39:19 -0800705 return
706 }
707
Colin Cross0875c522017-11-28 17:34:01 -0800708 a.ModuleContext.Build(pctx.PackageContext, bparams)
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700709}
710
Colin Cross6ff51382015-12-17 16:39:19 -0800711func (a *androidModuleContext) GetMissingDependencies() []string {
712 return a.missingDeps
713}
714
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800715func (a *androidModuleContext) AddMissingDependencies(deps []string) {
716 if deps != nil {
717 a.missingDeps = append(a.missingDeps, deps...)
Colin Crossd11fcda2017-10-23 17:59:01 -0700718 a.missingDeps = FirstUniqueStrings(a.missingDeps)
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800719 }
720}
721
Colin Crossd11fcda2017-10-23 17:59:01 -0700722func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module {
723 aModule, _ := module.(Module)
724 if aModule == nil {
725 a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule))
726 return nil
727 }
728
729 if !aModule.Enabled() {
Colin Cross6510f912017-11-29 00:27:14 -0800730 if a.Config().AllowMissingDependencies() {
Colin Crossd11fcda2017-10-23 17:59:01 -0700731 a.AddMissingDependencies([]string{a.OtherModuleName(aModule)})
732 } else {
733 a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule))
734 }
735 return nil
736 }
737
738 return aModule
739}
740
Colin Cross35143d02017-11-16 00:11:20 -0800741func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
742 a.ModuleContext.VisitDirectDeps(visit)
743}
744
Colin Crossd11fcda2017-10-23 17:59:01 -0700745func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) {
746 a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) {
747 if aModule := a.validateAndroidModule(module); aModule != nil {
748 visit(aModule)
749 }
750 })
751}
752
753func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
754 a.ModuleContext.VisitDirectDepsIf(
755 // pred
756 func(module blueprint.Module) bool {
757 if aModule := a.validateAndroidModule(module); aModule != nil {
758 return pred(aModule)
759 } else {
760 return false
761 }
762 },
763 // visit
764 func(module blueprint.Module) {
765 visit(module.(Module))
766 })
767}
768
769func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) {
770 a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) {
771 if aModule := a.validateAndroidModule(module); aModule != nil {
772 visit(aModule)
773 }
774 })
775}
776
777func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) {
778 a.ModuleContext.VisitDepsDepthFirstIf(
779 // pred
780 func(module blueprint.Module) bool {
781 if aModule := a.validateAndroidModule(module); aModule != nil {
782 return pred(aModule)
783 } else {
784 return false
785 }
786 },
787 // visit
788 func(module blueprint.Module) {
789 visit(module.(Module))
790 })
791}
792
793func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) {
794 a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool {
795 childAndroidModule := a.validateAndroidModule(child)
796 parentAndroidModule := a.validateAndroidModule(parent)
797 if childAndroidModule != nil && parentAndroidModule != nil {
798 return visit(childAndroidModule, parentAndroidModule)
799 } else {
800 return false
801 }
802 })
803}
804
Colin Cross0875c522017-11-28 17:34:01 -0800805func (a *androidModuleContext) VisitAllModuleVariants(visit func(Module)) {
806 a.ModuleContext.VisitAllModuleVariants(func(module blueprint.Module) {
807 visit(module.(Module))
808 })
809}
810
811func (a *androidModuleContext) PrimaryModule() Module {
812 return a.ModuleContext.PrimaryModule().(Module)
813}
814
815func (a *androidModuleContext) FinalModule() Module {
816 return a.ModuleContext.FinalModule().(Module)
817}
818
Colin Crossa1ad8d12016-06-01 17:09:44 -0700819func (a *androidBaseContextImpl) Target() Target {
820 return a.target
821}
822
Colin Cross8b74d172016-09-13 09:59:14 -0700823func (a *androidBaseContextImpl) TargetPrimary() bool {
824 return a.targetPrimary
825}
826
Colin Crossf6566ed2015-03-24 11:13:38 -0700827func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700828 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -0800829}
830
Colin Crossa1ad8d12016-06-01 17:09:44 -0700831func (a *androidBaseContextImpl) Os() OsType {
832 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800833}
834
Colin Crossf6566ed2015-03-24 11:13:38 -0700835func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700836 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -0700837}
838
839func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700840 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -0700841}
842
Colin Cross0af4b842015-04-30 16:36:18 -0700843func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700844 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -0700845}
846
Colin Cross3edeee12017-04-04 12:59:48 -0700847func (a *androidBaseContextImpl) Windows() bool {
848 return a.target.Os == Windows
849}
850
Colin Crossf6566ed2015-03-24 11:13:38 -0700851func (a *androidBaseContextImpl) Debug() bool {
852 return a.debug
853}
854
Colin Cross1e7d3702016-08-24 15:25:47 -0700855func (a *androidBaseContextImpl) PrimaryArch() bool {
Colin Cross67a5c132017-05-09 13:45:28 -0700856 if len(a.config.Targets[a.target.Os.Class]) <= 1 {
857 return true
858 }
Colin Cross1e7d3702016-08-24 15:25:47 -0700859 return a.target.Arch.ArchType == a.config.Targets[a.target.Os.Class][0].Arch.ArchType
860}
861
Colin Cross1332b002015-04-07 17:11:30 -0700862func (a *androidBaseContextImpl) AConfig() Config {
863 return a.config
864}
865
Colin Cross9272ade2016-08-17 15:24:12 -0700866func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
867 return DeviceConfig{a.config.deviceConfig}
868}
869
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700870func (a *androidBaseContextImpl) InstallOnVendorPartition() bool {
Dan Willemsenaa118f92017-04-06 12:49:58 -0700871 return a.vendor
Dan Willemsen782a2d12015-12-21 14:55:28 -0800872}
873
Colin Cross8d8f8e22016-08-03 11:57:50 -0700874func (a *androidModuleContext) InstallInData() bool {
875 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -0800876}
877
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700878func (a *androidModuleContext) InstallInSanitizerDir() bool {
879 return a.module.InstallInSanitizerDir()
880}
881
Colin Cross893d8162017-04-26 17:34:03 -0700882func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool {
883 if a.module.base().commonProperties.SkipInstall {
884 return true
885 }
886
887 if a.Device() {
Colin Cross6510f912017-11-29 00:27:14 -0800888 if a.Config().SkipDeviceInstall() {
Colin Cross893d8162017-04-26 17:34:03 -0700889 return true
890 }
891
Colin Cross6510f912017-11-29 00:27:14 -0800892 if a.Config().SkipMegaDeviceInstall(fullInstallPath.String()) {
Colin Cross893d8162017-04-26 17:34:03 -0700893 return true
894 }
895 }
896
897 return false
898}
899
Colin Cross5c517922017-08-31 12:29:17 -0700900func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -0700901 deps ...Path) OutputPath {
Colin Cross5c517922017-08-31 12:29:17 -0700902 return a.installFile(installPath, name, srcPath, Cp, deps)
903}
904
905func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path,
906 deps ...Path) OutputPath {
907 return a.installFile(installPath, name, srcPath, CpExecutable, deps)
908}
909
910func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path,
911 rule blueprint.Rule, deps []Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -0700912
Dan Willemsen782a2d12015-12-21 14:55:28 -0800913 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -0700914 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -0800915
Colin Cross893d8162017-04-26 17:34:03 -0700916 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -0700917
Dan Willemsen322acaf2016-01-12 23:07:05 -0800918 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -0700919
Colin Cross89562dc2016-10-03 17:47:19 -0700920 var implicitDeps, orderOnlyDeps Paths
921
922 if a.Host() {
923 // Installed host modules might be used during the build, depend directly on their
924 // dependencies so their timestamp is updated whenever their dependency is updated
925 implicitDeps = deps
926 } else {
927 orderOnlyDeps = deps
928 }
929
Colin Crossae887032017-10-23 17:16:14 -0700930 a.Build(pctx, BuildParams{
Colin Cross5c517922017-08-31 12:29:17 -0700931 Rule: rule,
Colin Cross67a5c132017-05-09 13:45:28 -0700932 Description: "install " + fullInstallPath.Base(),
933 Output: fullInstallPath,
934 Input: srcPath,
935 Implicits: implicitDeps,
936 OrderOnly: orderOnlyDeps,
Colin Cross6510f912017-11-29 00:27:14 -0800937 Default: !a.Config().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -0800938 })
Colin Cross3f40fa42015-01-30 17:27:36 -0800939
Dan Willemsen322acaf2016-01-12 23:07:05 -0800940 a.installFiles = append(a.installFiles, fullInstallPath)
941 }
Colin Cross1f8c52b2015-06-16 16:38:17 -0700942 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -0700943 return fullInstallPath
944}
945
Colin Cross3854a602016-01-11 12:49:11 -0800946func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
947 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -0700948 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -0800949
Colin Cross893d8162017-04-26 17:34:03 -0700950 if !a.skipInstall(fullInstallPath) {
Colin Crossce75d2c2016-10-06 16:12:58 -0700951
Colin Crossae887032017-10-23 17:16:14 -0700952 a.Build(pctx, BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -0700953 Rule: Symlink,
954 Description: "install symlink " + fullInstallPath.Base(),
955 Output: fullInstallPath,
956 OrderOnly: Paths{srcPath},
Colin Cross6510f912017-11-29 00:27:14 -0800957 Default: !a.Config().EmbeddedInMake(),
Colin Cross12fc4972016-01-11 12:49:11 -0800958 Args: map[string]string{
959 "fromPath": srcPath.String(),
960 },
961 })
Colin Cross3854a602016-01-11 12:49:11 -0800962
Colin Cross12fc4972016-01-11 12:49:11 -0800963 a.installFiles = append(a.installFiles, fullInstallPath)
964 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
965 }
Colin Cross3854a602016-01-11 12:49:11 -0800966 return fullInstallPath
967}
968
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700969func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800970 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
971}
972
Colin Cross3f40fa42015-01-30 17:27:36 -0800973type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700974 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -0800975}
976
977func isFileInstaller(m blueprint.Module) bool {
978 _, ok := m.(fileInstaller)
979 return ok
980}
981
982func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -0700983 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -0800984 return ok
985}
Colin Crossfce53272015-04-08 11:21:40 -0700986
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700987func findStringInSlice(str string, slice []string) int {
988 for i, s := range slice {
989 if s == str {
990 return i
Colin Crossfce53272015-04-08 11:21:40 -0700991 }
992 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700993 return -1
994}
995
Colin Cross068e0fe2016-12-13 15:23:47 -0800996func SrcIsModule(s string) string {
997 if len(s) > 1 && s[0] == ':' {
998 return s[1:]
999 }
1000 return ""
1001}
1002
1003type sourceDependencyTag struct {
1004 blueprint.BaseDependencyTag
1005}
1006
1007var SourceDepTag sourceDependencyTag
1008
Colin Cross366938f2017-12-11 16:29:02 -08001009// Adds necessary dependencies to satisfy filegroup or generated sources modules listed in srcFiles
1010// using ":module" syntax, if any.
Colin Cross068e0fe2016-12-13 15:23:47 -08001011func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
1012 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -07001013 set := make(map[string]bool)
1014
Colin Cross068e0fe2016-12-13 15:23:47 -08001015 for _, s := range srcFiles {
1016 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -07001017 if _, found := set[m]; found {
1018 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
1019 } else {
1020 set[m] = true
1021 deps = append(deps, m)
1022 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001023 }
1024 }
1025
1026 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
1027}
1028
Colin Cross366938f2017-12-11 16:29:02 -08001029// Adds necessary dependencies to satisfy filegroup or generated sources modules specified in s
1030// using ":module" syntax, if any.
1031func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) {
1032 if s != nil {
1033 if m := SrcIsModule(*s); m != "" {
1034 ctx.AddDependency(ctx.Module(), SourceDepTag, m)
1035 }
1036 }
1037}
1038
Colin Cross068e0fe2016-12-13 15:23:47 -08001039type SourceFileProducer interface {
1040 Srcs() Paths
1041}
1042
1043// Returns a list of paths expanded from globs and modules referenced using ":module" syntax.
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001044// ExtractSourcesDeps must have already been called during the dependency resolution phase.
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001045func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001046 return ctx.ExpandSourcesSubDir(srcFiles, excludes, "")
1047}
1048
Colin Cross366938f2017-12-11 16:29:02 -08001049// Returns a single path expanded from globs and modules referenced using ":module" syntax.
1050// ExtractSourceDeps must have already been called during the dependency resolution phase.
1051func (ctx *androidModuleContext) ExpandSource(srcFile, prop string) Path {
1052 srcFiles := ctx.ExpandSourcesSubDir([]string{srcFile}, nil, "")
1053 if len(srcFiles) == 1 {
1054 return srcFiles[0]
1055 } else {
1056 ctx.PropertyErrorf(prop, "module providing %s must produce exactly one file", prop)
1057 return nil
1058 }
1059}
1060
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001061func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths {
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001062 prefix := PathForModuleSrc(ctx).String()
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001063
Dan Willemsen2ef08f42015-06-30 18:15:24 -07001064 for i, e := range excludes {
1065 j := findStringInSlice(e, srcFiles)
1066 if j != -1 {
1067 srcFiles = append(srcFiles[:j], srcFiles[j+1:]...)
1068 }
1069
1070 excludes[i] = filepath.Join(prefix, e)
1071 }
1072
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001073 expandedSrcFiles := make(Paths, 0, len(srcFiles))
Colin Cross8f101b42015-06-17 15:09:06 -07001074 for _, s := range srcFiles {
Colin Cross068e0fe2016-12-13 15:23:47 -08001075 if m := SrcIsModule(s); m != "" {
1076 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
Colin Cross0617bb82017-10-24 13:01:18 -07001077 if module == nil {
1078 // Error will have been handled by ExtractSourcesDeps
1079 continue
1080 }
Colin Cross068e0fe2016-12-13 15:23:47 -08001081 if srcProducer, ok := module.(SourceFileProducer); ok {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001082 expandedSrcFiles = append(expandedSrcFiles, srcProducer.Srcs()...)
Colin Cross068e0fe2016-12-13 15:23:47 -08001083 } else {
1084 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
1085 }
1086 } else if pathtools.IsGlob(s) {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001087 globbedSrcFiles := ctx.Glob(filepath.Join(prefix, s), excludes)
Colin Cross05a39cb2017-10-09 13:35:19 -07001088 for i, s := range globbedSrcFiles {
1089 globbedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir)
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001090 }
Colin Cross05a39cb2017-10-09 13:35:19 -07001091 expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...)
Colin Cross8f101b42015-06-17 15:09:06 -07001092 } else {
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001093 s := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir)
1094 expandedSrcFiles = append(expandedSrcFiles, s)
Colin Cross8f101b42015-06-17 15:09:06 -07001095 }
1096 }
1097
Colin Crossfaeb7aa2017-02-01 14:12:44 -08001098 return expandedSrcFiles
Colin Cross8f101b42015-06-17 15:09:06 -07001099}
1100
Nan Zhang6d34b302017-02-04 17:47:46 -08001101func (ctx *androidModuleContext) RequiredModuleNames() []string {
1102 return ctx.module.base().commonProperties.Required
1103}
1104
Colin Cross7f19f372016-11-01 11:10:25 -07001105func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
1106 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -07001107 if err != nil {
1108 ctx.ModuleErrorf("glob: %s", err.Error())
1109 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -07001110 return pathsForModuleSrcFromFullPath(ctx, ret)
Colin Crossfce53272015-04-08 11:21:40 -07001111}
Colin Cross1f8c52b2015-06-16 16:38:17 -07001112
Colin Cross463a90e2015-06-17 14:20:06 -07001113func init() {
Colin Cross798bfce2016-10-12 14:28:16 -07001114 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -07001115}
1116
Colin Cross0875c522017-11-28 17:34:01 -08001117func BuildTargetSingleton() Singleton {
Colin Cross1f8c52b2015-06-16 16:38:17 -07001118 return &buildTargetSingleton{}
1119}
1120
Colin Cross87d8b562017-04-25 10:01:55 -07001121func parentDir(dir string) string {
1122 dir, _ = filepath.Split(dir)
1123 return filepath.Clean(dir)
1124}
1125
Colin Cross1f8c52b2015-06-16 16:38:17 -07001126type buildTargetSingleton struct{}
1127
Colin Cross0875c522017-11-28 17:34:01 -08001128func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
1129 var checkbuildDeps Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -07001130
Colin Cross0875c522017-11-28 17:34:01 -08001131 mmTarget := func(dir string) WritablePath {
1132 return PathForPhony(ctx,
1133 "MODULES-IN-"+strings.Replace(filepath.Clean(dir), "/", "-", -1))
Colin Cross87d8b562017-04-25 10:01:55 -07001134 }
1135
Colin Cross0875c522017-11-28 17:34:01 -08001136 modulesInDir := make(map[string]Paths)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001137
Colin Cross0875c522017-11-28 17:34:01 -08001138 ctx.VisitAllModules(func(module Module) {
1139 blueprintDir := module.base().blueprintDir
1140 installTarget := module.base().installTarget
1141 checkbuildTarget := module.base().checkbuildTarget
Colin Cross1f8c52b2015-06-16 16:38:17 -07001142
Colin Cross0875c522017-11-28 17:34:01 -08001143 if checkbuildTarget != nil {
1144 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
1145 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget)
1146 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001147
Colin Cross0875c522017-11-28 17:34:01 -08001148 if installTarget != nil {
1149 modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget)
Colin Cross1f8c52b2015-06-16 16:38:17 -07001150 }
1151 })
1152
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001153 suffix := ""
Colin Crossaabf6792017-11-29 00:27:14 -08001154 if ctx.Config().EmbeddedInMake() {
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001155 suffix = "-soong"
1156 }
1157
Colin Cross1f8c52b2015-06-16 16:38:17 -07001158 // Create a top-level checkbuild target that depends on all modules
Colin Cross0875c522017-11-28 17:34:01 -08001159 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001160 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001161 Output: PathForPhony(ctx, "checkbuild"+suffix),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001162 Implicits: checkbuildDeps,
Colin Cross1f8c52b2015-06-16 16:38:17 -07001163 })
1164
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001165 // Make will generate the MODULES-IN-* targets
Colin Crossaabf6792017-11-29 00:27:14 -08001166 if ctx.Config().EmbeddedInMake() {
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001167 return
1168 }
1169
Colin Cross0875c522017-11-28 17:34:01 -08001170 sortedKeys := func(m map[string]Paths) []string {
1171 s := make([]string, 0, len(m))
1172 for k := range m {
1173 s = append(s, k)
1174 }
1175 sort.Strings(s)
1176 return s
1177 }
1178
Colin Cross87d8b562017-04-25 10:01:55 -07001179 // Ensure ancestor directories are in modulesInDir
1180 dirs := sortedKeys(modulesInDir)
1181 for _, dir := range dirs {
1182 dir := parentDir(dir)
1183 for dir != "." && dir != "/" {
1184 if _, exists := modulesInDir[dir]; exists {
1185 break
1186 }
1187 modulesInDir[dir] = nil
1188 dir = parentDir(dir)
1189 }
1190 }
1191
1192 // Make directories build their direct subdirectories
1193 dirs = sortedKeys(modulesInDir)
1194 for _, dir := range dirs {
1195 p := parentDir(dir)
1196 if p != "." && p != "/" {
1197 modulesInDir[p] = append(modulesInDir[p], mmTarget(dir))
1198 }
1199 }
1200
Dan Willemsend2e95fb2017-09-20 14:30:50 -07001201 // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and
1202 // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp
1203 // files.
Colin Cross1f8c52b2015-06-16 16:38:17 -07001204 for _, dir := range dirs {
Colin Cross0875c522017-11-28 17:34:01 -08001205 ctx.Build(pctx, BuildParams{
Colin Cross1f8c52b2015-06-16 16:38:17 -07001206 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001207 Output: mmTarget(dir),
Colin Cross87d8b562017-04-25 10:01:55 -07001208 Implicits: modulesInDir[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -08001209 // HACK: checkbuild should be an optional build, but force it
1210 // enabled for now in standalone builds
Colin Crossaabf6792017-11-29 00:27:14 -08001211 Default: !ctx.Config().EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -07001212 })
1213 }
Dan Willemsen61d88b82017-09-20 17:29:08 -07001214
1215 // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild.
1216 osDeps := map[OsType]Paths{}
Colin Cross0875c522017-11-28 17:34:01 -08001217 ctx.VisitAllModules(func(module Module) {
1218 if module.Enabled() {
1219 os := module.Target().Os
1220 osDeps[os] = append(osDeps[os], module.base().checkbuildFiles...)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001221 }
1222 })
1223
Colin Cross0875c522017-11-28 17:34:01 -08001224 osClass := make(map[string]Paths)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001225 for os, deps := range osDeps {
1226 var className string
1227
1228 switch os.Class {
1229 case Host:
1230 className = "host"
1231 case HostCross:
1232 className = "host-cross"
1233 case Device:
1234 className = "target"
1235 default:
1236 continue
1237 }
1238
Colin Cross0875c522017-11-28 17:34:01 -08001239 name := PathForPhony(ctx, className+"-"+os.Name)
Dan Willemsen61d88b82017-09-20 17:29:08 -07001240 osClass[className] = append(osClass[className], name)
1241
Colin Cross0875c522017-11-28 17:34:01 -08001242 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001243 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001244 Output: name,
1245 Implicits: deps,
Dan Willemsen61d88b82017-09-20 17:29:08 -07001246 })
1247 }
1248
1249 // Wrap those into host|host-cross|target phony rules
1250 osClasses := sortedKeys(osClass)
1251 for _, class := range osClasses {
Colin Cross0875c522017-11-28 17:34:01 -08001252 ctx.Build(pctx, BuildParams{
Dan Willemsen61d88b82017-09-20 17:29:08 -07001253 Rule: blueprint.Phony,
Colin Cross0875c522017-11-28 17:34:01 -08001254 Output: PathForPhony(ctx, class),
Dan Willemsen61d88b82017-09-20 17:29:08 -07001255 Implicits: osClass[class],
Dan Willemsen61d88b82017-09-20 17:29:08 -07001256 })
1257 }
Colin Cross1f8c52b2015-06-16 16:38:17 -07001258}
Colin Crossd779da42015-12-17 18:00:23 -08001259
1260type AndroidModulesByName struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001261 slice []Module
Colin Crossd779da42015-12-17 18:00:23 -08001262 ctx interface {
1263 ModuleName(blueprint.Module) string
1264 ModuleSubDir(blueprint.Module) string
1265 }
1266}
1267
1268func (s AndroidModulesByName) Len() int { return len(s.slice) }
1269func (s AndroidModulesByName) Less(i, j int) bool {
1270 mi, mj := s.slice[i], s.slice[j]
1271 ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj)
1272
1273 if ni != nj {
1274 return ni < nj
1275 } else {
1276 return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj)
1277 }
1278}
1279func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] }