blob: 2b93d8ea4e45267006b2083f3c029539f8a2d186 [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 Cross6ff51382015-12-17 16:39:19 -080020 "strings"
Colin Crossf6566ed2015-03-24 11:13:38 -070021
22 "github.com/google/blueprint"
Colin Cross7f19f372016-11-01 11:10:25 -070023 "github.com/google/blueprint/pathtools"
Colin Cross3f40fa42015-01-30 17:27:36 -080024)
25
26var (
27 DeviceSharedLibrary = "shared_library"
28 DeviceStaticLibrary = "static_library"
29 DeviceExecutable = "executable"
30 HostSharedLibrary = "host_shared_library"
31 HostStaticLibrary = "host_static_library"
32 HostExecutable = "host_executable"
33)
34
Dan Willemsen34cc69e2015-09-23 15:26:20 -070035type ModuleBuildParams struct {
Dan Willemsen9f3c5742016-11-03 14:28:31 -070036 Rule blueprint.Rule
Colin Cross33bfb0a2016-11-21 17:23:08 -080037 Deps blueprint.Deps
38 Depfile WritablePath
Dan Willemsen9f3c5742016-11-03 14:28:31 -070039 Output WritablePath
40 Outputs WritablePaths
41 ImplicitOutput WritablePath
42 ImplicitOutputs WritablePaths
43 Input Path
44 Inputs Paths
45 Implicit Path
46 Implicits Paths
47 OrderOnly Paths
48 Default bool
49 Args map[string]string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070050}
51
Colin Crossf6566ed2015-03-24 11:13:38 -070052type androidBaseContext interface {
Colin Crossa1ad8d12016-06-01 17:09:44 -070053 Target() Target
Colin Cross8b74d172016-09-13 09:59:14 -070054 TargetPrimary() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070055 Arch() Arch
Colin Crossa1ad8d12016-06-01 17:09:44 -070056 Os() OsType
Colin Crossf6566ed2015-03-24 11:13:38 -070057 Host() bool
58 Device() bool
Colin Cross0af4b842015-04-30 16:36:18 -070059 Darwin() bool
Colin Cross3edeee12017-04-04 12:59:48 -070060 Windows() bool
Colin Crossf6566ed2015-03-24 11:13:38 -070061 Debug() bool
Colin Cross1e7d3702016-08-24 15:25:47 -070062 PrimaryArch() bool
Dan Willemsenaa118f92017-04-06 12:49:58 -070063 Vendor() bool
Colin Cross1332b002015-04-07 17:11:30 -070064 AConfig() Config
Colin Cross9272ade2016-08-17 15:24:12 -070065 DeviceConfig() DeviceConfig
Colin Crossf6566ed2015-03-24 11:13:38 -070066}
67
Colin Cross635c3b02016-05-18 15:37:25 -070068type BaseContext interface {
Colin Crossf6566ed2015-03-24 11:13:38 -070069 blueprint.BaseModuleContext
70 androidBaseContext
71}
72
Colin Cross635c3b02016-05-18 15:37:25 -070073type ModuleContext interface {
Colin Cross3f40fa42015-01-30 17:27:36 -080074 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -070075 androidBaseContext
Colin Cross3f40fa42015-01-30 17:27:36 -080076
Dan Willemsen34cc69e2015-09-23 15:26:20 -070077 // Similar to Build, but takes Paths instead of []string,
78 // and performs more verification.
79 ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams)
Colin Cross8f101b42015-06-17 15:09:06 -070080
Dan Willemsen34cc69e2015-09-23 15:26:20 -070081 ExpandSources(srcFiles, excludes []string) Paths
Colin Crossfaeb7aa2017-02-01 14:12:44 -080082 ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths
Colin Cross7f19f372016-11-01 11:10:25 -070083 Glob(globPattern string, excludes []string) Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070084
Colin Crossa2344662016-03-24 13:14:12 -070085 InstallFile(installPath OutputPath, srcPath Path, deps ...Path) OutputPath
86 InstallFileName(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath
Colin Cross3854a602016-01-11 12:49:11 -080087 InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -070088 CheckbuildFile(srcPath Path)
Dan Willemsen6553f5e2016-03-10 18:14:25 -080089
90 AddMissingDependencies(deps []string)
Colin Cross8d8f8e22016-08-03 11:57:50 -070091
Colin Cross8d8f8e22016-08-03 11:57:50 -070092 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -070093 InstallInSanitizerDir() bool
Nan Zhang6d34b302017-02-04 17:47:46 -080094
95 RequiredModuleNames() []string
Colin Cross3f40fa42015-01-30 17:27:36 -080096}
97
Colin Cross635c3b02016-05-18 15:37:25 -070098type Module interface {
Colin Cross3f40fa42015-01-30 17:27:36 -080099 blueprint.Module
100
Colin Cross635c3b02016-05-18 15:37:25 -0700101 GenerateAndroidBuildActions(ModuleContext)
Colin Cross1e676be2016-10-12 14:38:15 -0700102 DepsMutator(BottomUpMutatorContext)
Colin Cross3f40fa42015-01-30 17:27:36 -0800103
Colin Cross635c3b02016-05-18 15:37:25 -0700104 base() *ModuleBase
Dan Willemsen0effe062015-11-30 16:06:01 -0800105 Enabled() bool
Colin Crossa1ad8d12016-06-01 17:09:44 -0700106 Target() Target
Dan Willemsen782a2d12015-12-21 14:55:28 -0800107 InstallInData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700108 InstallInSanitizerDir() bool
Colin Crossa2f296f2016-11-29 15:16:18 -0800109 SkipInstall()
Colin Cross3f40fa42015-01-30 17:27:36 -0800110}
111
Colin Crossfc754582016-05-17 16:34:16 -0700112type nameProperties struct {
113 // The name of the module. Must be unique across all modules.
Colin Crossc77f9d12015-04-02 13:54:39 -0700114 Name string
Colin Crossfc754582016-05-17 16:34:16 -0700115}
116
117type commonProperties struct {
Colin Crossc77f9d12015-04-02 13:54:39 -0700118 Tags []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800119
Dan Willemsen0effe062015-11-30 16:06:01 -0800120 // emit build rules for this module
121 Enabled *bool `android:"arch_variant"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800122
Colin Cross7d5136f2015-05-11 13:39:40 -0700123 // control whether this module compiles for 32-bit, 64-bit, or both. Possible values
Colin Cross3f40fa42015-01-30 17:27:36 -0800124 // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
125 // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
126 // platform
Colin Cross69617d32016-09-06 10:39:07 -0700127 Compile_multilib string `android:"arch_variant"`
128
129 Target struct {
130 Host struct {
131 Compile_multilib string
132 }
133 Android struct {
134 Compile_multilib string
135 }
136 }
137
138 Default_multilib string `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800139
Dan Willemsen782a2d12015-12-21 14:55:28 -0800140 // whether this is a proprietary vendor module, and should be installed into /vendor
141 Proprietary bool
142
Colin Cross55708f32017-03-20 13:23:34 -0700143 // vendor who owns this module
144 Owner string
145
Dan Willemsenaa118f92017-04-06 12:49:58 -0700146 // whether this module is device specific and should be installed into /vendor
147 Vendor bool
148
Dan Willemsen0fda89f2016-06-01 15:25:32 -0700149 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
150 // file
151 Logtags []string
152
Dan Willemsen2277bcb2016-07-25 20:27:39 -0700153 // init.rc files to be installed if this module is installed
154 Init_rc []string
155
Chris Wolfe998306e2016-08-15 14:47:23 -0400156 // names of other modules to install if this module is installed
157 Required []string
158
Colin Crossa1ad8d12016-06-01 17:09:44 -0700159 // Set by TargetMutator
Colin Cross8b74d172016-09-13 09:59:14 -0700160 CompileTarget Target `blueprint:"mutated"`
161 CompilePrimary bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800162
163 // Set by InitAndroidModule
164 HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
Dan Willemsen0b24c742016-10-04 15:13:37 -0700165 ArchSpecific bool `blueprint:"mutated"`
Colin Crossce75d2c2016-10-06 16:12:58 -0700166
167 SkipInstall bool `blueprint:"mutated"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800168}
169
170type hostAndDeviceProperties struct {
Colin Crossa4190c12016-07-12 13:11:25 -0700171 Host_supported *bool
172 Device_supported *bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800173}
174
Colin Crossc472d572015-03-17 15:06:21 -0700175type Multilib string
176
177const (
Dan Willemsen218f6562015-07-08 18:13:11 -0700178 MultilibBoth Multilib = "both"
179 MultilibFirst Multilib = "first"
180 MultilibCommon Multilib = "common"
181 MultilibDefault Multilib = ""
Colin Crossc472d572015-03-17 15:06:21 -0700182)
183
Colin Crossa1ad8d12016-06-01 17:09:44 -0700184type HostOrDeviceSupported int
185
186const (
187 _ HostOrDeviceSupported = iota
188 HostSupported
Dan Albertc6345fb2016-10-20 01:36:11 -0700189 HostSupportedNoCross
Colin Crossa1ad8d12016-06-01 17:09:44 -0700190 DeviceSupported
191 HostAndDeviceSupported
192 HostAndDeviceDefault
Dan Willemsen0b24c742016-10-04 15:13:37 -0700193 NeitherHostNorDeviceSupported
Colin Crossa1ad8d12016-06-01 17:09:44 -0700194)
195
Colin Cross635c3b02016-05-18 15:37:25 -0700196func InitAndroidModule(m Module,
Colin Cross3f40fa42015-01-30 17:27:36 -0800197 propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
198
199 base := m.base()
200 base.module = m
Colin Cross5049f022015-03-18 13:28:46 -0700201
Colin Crossfc754582016-05-17 16:34:16 -0700202 propertyStructs = append(propertyStructs,
203 &base.nameProperties,
204 &base.commonProperties,
205 &base.variableProperties)
Colin Cross5049f022015-03-18 13:28:46 -0700206
207 return m, propertyStructs
208}
209
Colin Cross635c3b02016-05-18 15:37:25 -0700210func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib,
Colin Cross5049f022015-03-18 13:28:46 -0700211 propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
212
213 _, propertyStructs = InitAndroidModule(m, propertyStructs...)
214
215 base := m.base()
Colin Cross3f40fa42015-01-30 17:27:36 -0800216 base.commonProperties.HostOrDeviceSupported = hod
Colin Cross69617d32016-09-06 10:39:07 -0700217 base.commonProperties.Default_multilib = string(defaultMultilib)
Dan Willemsen0b24c742016-10-04 15:13:37 -0700218 base.commonProperties.ArchSpecific = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800219
Dan Willemsen218f6562015-07-08 18:13:11 -0700220 switch hod {
221 case HostAndDeviceSupported:
Colin Cross3f40fa42015-01-30 17:27:36 -0800222 // Default to module to device supported, host not supported, can override in module
223 // properties
Colin Crossa4190c12016-07-12 13:11:25 -0700224 base.hostAndDeviceProperties.Device_supported = boolPtr(true)
Dan Willemsen218f6562015-07-08 18:13:11 -0700225 fallthrough
226 case HostAndDeviceDefault:
Colin Cross3f40fa42015-01-30 17:27:36 -0800227 propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties)
228 }
229
Colin Crosscfad1192015-11-02 16:43:11 -0800230 return InitArchModule(m, propertyStructs...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800231}
232
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800233// A ModuleBase object contains the properties that are common to all Android
Colin Cross3f40fa42015-01-30 17:27:36 -0800234// modules. It should be included as an anonymous field in every module
235// struct definition. InitAndroidModule should then be called from the module's
236// factory function, and the return values from InitAndroidModule should be
237// returned from the factory function.
238//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800239// The ModuleBase type is responsible for implementing the GenerateBuildActions
240// method to support the blueprint.Module interface. This method will then call
241// the module's GenerateAndroidBuildActions method once for each build variant
242// that is to be built. GenerateAndroidBuildActions is passed a
243// AndroidModuleContext rather than the usual blueprint.ModuleContext.
Colin Cross3f40fa42015-01-30 17:27:36 -0800244// AndroidModuleContext exposes extra functionality specific to the Android build
245// system including details about the particular build variant that is to be
246// generated.
247//
248// For example:
249//
250// import (
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800251// "android/soong/android"
Colin Cross70b40592015-03-23 12:57:34 -0700252// "github.com/google/blueprint"
Colin Cross3f40fa42015-01-30 17:27:36 -0800253// )
254//
255// type myModule struct {
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800256// android.ModuleBase
Colin Cross3f40fa42015-01-30 17:27:36 -0800257// properties struct {
258// MyProperty string
259// }
260// }
261//
262// func NewMyModule() (blueprint.Module, []interface{}) {
263// m := &myModule{}
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800264// return android.InitAndroidModule(m, &m.properties)
Colin Cross3f40fa42015-01-30 17:27:36 -0800265// }
266//
Nan Zhangb9eeb1d2017-02-02 10:46:07 -0800267// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800268// // Get the CPU architecture for the current build variant.
269// variantArch := ctx.Arch()
270//
271// // ...
272// }
Colin Cross635c3b02016-05-18 15:37:25 -0700273type ModuleBase struct {
Colin Cross3f40fa42015-01-30 17:27:36 -0800274 // Putting the curiously recurring thing pointing to the thing that contains
275 // the thing pattern to good use.
Colin Cross635c3b02016-05-18 15:37:25 -0700276 module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800277
Colin Crossfc754582016-05-17 16:34:16 -0700278 nameProperties nameProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800279 commonProperties commonProperties
Colin Cross7f64b6d2015-07-09 13:57:48 -0700280 variableProperties variableProperties
Colin Cross3f40fa42015-01-30 17:27:36 -0800281 hostAndDeviceProperties hostAndDeviceProperties
282 generalProperties []interface{}
Dan Willemsenb1957a52016-06-23 23:44:54 -0700283 archProperties []interface{}
Colin Crossa120ec12016-08-19 16:07:38 -0700284 customizableProperties []interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800285
286 noAddressSanitizer bool
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700287 installFiles Paths
288 checkbuildFiles Paths
Colin Cross1f8c52b2015-06-16 16:38:17 -0700289
290 // Used by buildTargetSingleton to create checkbuild and per-directory build targets
291 // Only set on the final variant of each module
292 installTarget string
293 checkbuildTarget string
294 blueprintDir string
Colin Crossa120ec12016-08-19 16:07:38 -0700295
Colin Cross178a5092016-09-13 13:42:32 -0700296 hooks hooks
Colin Cross3f40fa42015-01-30 17:27:36 -0800297}
298
Colin Crossce75d2c2016-10-06 16:12:58 -0700299// Name returns the name of the module. It may be overridden by individual module types, for
300// example prebuilts will prepend prebuilt_ to the name.
Colin Crossfc754582016-05-17 16:34:16 -0700301func (a *ModuleBase) Name() string {
302 return a.nameProperties.Name
303}
304
Colin Crossce75d2c2016-10-06 16:12:58 -0700305// BaseModuleName returns the name of the module as specified in the blueprints file.
306func (a *ModuleBase) BaseModuleName() string {
307 return a.nameProperties.Name
308}
309
Colin Cross635c3b02016-05-18 15:37:25 -0700310func (a *ModuleBase) base() *ModuleBase {
Colin Cross3f40fa42015-01-30 17:27:36 -0800311 return a
312}
313
Colin Cross8b74d172016-09-13 09:59:14 -0700314func (a *ModuleBase) SetTarget(target Target, primary bool) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700315 a.commonProperties.CompileTarget = target
Colin Cross8b74d172016-09-13 09:59:14 -0700316 a.commonProperties.CompilePrimary = primary
Colin Crossd3ba0392015-05-07 14:11:29 -0700317}
318
Colin Crossa1ad8d12016-06-01 17:09:44 -0700319func (a *ModuleBase) Target() Target {
320 return a.commonProperties.CompileTarget
Dan Willemsen490fd492015-11-24 17:53:15 -0800321}
322
Colin Cross8b74d172016-09-13 09:59:14 -0700323func (a *ModuleBase) TargetPrimary() bool {
324 return a.commonProperties.CompilePrimary
325}
326
Colin Crossa1ad8d12016-06-01 17:09:44 -0700327func (a *ModuleBase) Os() OsType {
328 return a.Target().Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800329}
330
Colin Cross635c3b02016-05-18 15:37:25 -0700331func (a *ModuleBase) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700332 return a.Os().Class == Host || a.Os().Class == HostCross
Dan Willemsen97750522016-02-09 17:43:51 -0800333}
334
Colin Cross635c3b02016-05-18 15:37:25 -0700335func (a *ModuleBase) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700336 return a.Target().Arch
Dan Willemsen97750522016-02-09 17:43:51 -0800337}
338
Dan Willemsen0b24c742016-10-04 15:13:37 -0700339func (a *ModuleBase) ArchSpecific() bool {
340 return a.commonProperties.ArchSpecific
341}
342
Colin Crossa1ad8d12016-06-01 17:09:44 -0700343func (a *ModuleBase) OsClassSupported() []OsClass {
344 switch a.commonProperties.HostOrDeviceSupported {
345 case HostSupported:
Colin Crossa1ad8d12016-06-01 17:09:44 -0700346 return []OsClass{Host, HostCross}
Dan Albertc6345fb2016-10-20 01:36:11 -0700347 case HostSupportedNoCross:
348 return []OsClass{Host}
Colin Crossa1ad8d12016-06-01 17:09:44 -0700349 case DeviceSupported:
350 return []OsClass{Device}
351 case HostAndDeviceSupported:
352 var supported []OsClass
Colin Crossa4190c12016-07-12 13:11:25 -0700353 if Bool(a.hostAndDeviceProperties.Host_supported) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700354 supported = append(supported, Host, HostCross)
355 }
Colin Crossa4190c12016-07-12 13:11:25 -0700356 if Bool(a.hostAndDeviceProperties.Device_supported) {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700357 supported = append(supported, Device)
358 }
359 return supported
360 default:
361 return nil
362 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800363}
364
Colin Cross635c3b02016-05-18 15:37:25 -0700365func (a *ModuleBase) DeviceSupported() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800366 return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
367 a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
Colin Crossa4190c12016-07-12 13:11:25 -0700368 Bool(a.hostAndDeviceProperties.Device_supported)
Colin Cross3f40fa42015-01-30 17:27:36 -0800369}
370
Colin Cross635c3b02016-05-18 15:37:25 -0700371func (a *ModuleBase) Enabled() bool {
Dan Willemsen0effe062015-11-30 16:06:01 -0800372 if a.commonProperties.Enabled == nil {
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800373 return !a.Os().DefaultDisabled
Dan Willemsen490fd492015-11-24 17:53:15 -0800374 }
Dan Willemsen0effe062015-11-30 16:06:01 -0800375 return *a.commonProperties.Enabled
Colin Cross3f40fa42015-01-30 17:27:36 -0800376}
377
Colin Crossce75d2c2016-10-06 16:12:58 -0700378func (a *ModuleBase) SkipInstall() {
379 a.commonProperties.SkipInstall = true
380}
381
Colin Cross635c3b02016-05-18 15:37:25 -0700382func (a *ModuleBase) computeInstallDeps(
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700383 ctx blueprint.ModuleContext) Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800384
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700385 result := Paths{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800386 ctx.VisitDepsDepthFirstIf(isFileInstaller,
387 func(m blueprint.Module) {
388 fileInstaller := m.(fileInstaller)
389 files := fileInstaller.filesToInstall()
390 result = append(result, files...)
391 })
392
393 return result
394}
395
Colin Cross635c3b02016-05-18 15:37:25 -0700396func (a *ModuleBase) filesToInstall() Paths {
Colin Cross3f40fa42015-01-30 17:27:36 -0800397 return a.installFiles
398}
399
Colin Cross635c3b02016-05-18 15:37:25 -0700400func (p *ModuleBase) NoAddressSanitizer() bool {
Colin Cross3f40fa42015-01-30 17:27:36 -0800401 return p.noAddressSanitizer
402}
403
Colin Cross635c3b02016-05-18 15:37:25 -0700404func (p *ModuleBase) InstallInData() bool {
Dan Willemsen782a2d12015-12-21 14:55:28 -0800405 return false
406}
407
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700408func (p *ModuleBase) InstallInSanitizerDir() bool {
409 return false
410}
411
Colin Cross635c3b02016-05-18 15:37:25 -0700412func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700413 allInstalledFiles := Paths{}
414 allCheckbuildFiles := Paths{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800415 ctx.VisitAllModuleVariants(func(module blueprint.Module) {
Colin Cross635c3b02016-05-18 15:37:25 -0700416 a := module.(Module).base()
Colin Crossc9404352015-03-26 16:10:12 -0700417 allInstalledFiles = append(allInstalledFiles, a.installFiles...)
418 allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800419 })
420
Colin Cross9454bfa2015-03-17 13:24:18 -0700421 deps := []string{}
422
Colin Cross3f40fa42015-01-30 17:27:36 -0800423 if len(allInstalledFiles) > 0 {
Colin Cross9454bfa2015-03-17 13:24:18 -0700424 name := ctx.ModuleName() + "-install"
Colin Cross3f40fa42015-01-30 17:27:36 -0800425 ctx.Build(pctx, blueprint.BuildParams{
Colin Cross9454bfa2015-03-17 13:24:18 -0700426 Rule: blueprint.Phony,
427 Outputs: []string{name},
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700428 Implicits: allInstalledFiles.Strings(),
Colin Cross346aa132015-12-17 17:19:51 -0800429 Optional: ctx.Config().(Config).EmbeddedInMake(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700430 })
431 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700432 a.installTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700433 }
434
435 if len(allCheckbuildFiles) > 0 {
436 name := ctx.ModuleName() + "-checkbuild"
437 ctx.Build(pctx, blueprint.BuildParams{
438 Rule: blueprint.Phony,
439 Outputs: []string{name},
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700440 Implicits: allCheckbuildFiles.Strings(),
Colin Cross9454bfa2015-03-17 13:24:18 -0700441 Optional: true,
442 })
443 deps = append(deps, name)
Colin Cross1f8c52b2015-06-16 16:38:17 -0700444 a.checkbuildTarget = name
Colin Cross9454bfa2015-03-17 13:24:18 -0700445 }
446
447 if len(deps) > 0 {
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800448 suffix := ""
449 if ctx.Config().(Config).EmbeddedInMake() {
450 suffix = "-soong"
451 }
452
Colin Cross9454bfa2015-03-17 13:24:18 -0700453 ctx.Build(pctx, blueprint.BuildParams{
454 Rule: blueprint.Phony,
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800455 Outputs: []string{ctx.ModuleName() + suffix},
Colin Cross9454bfa2015-03-17 13:24:18 -0700456 Implicits: deps,
457 Optional: true,
Colin Cross3f40fa42015-01-30 17:27:36 -0800458 })
Colin Cross1f8c52b2015-06-16 16:38:17 -0700459
460 a.blueprintDir = ctx.ModuleDir()
Colin Cross3f40fa42015-01-30 17:27:36 -0800461 }
462}
463
Colin Cross635c3b02016-05-18 15:37:25 -0700464func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
Colin Cross6362e272015-10-29 15:25:03 -0700465 return androidBaseContextImpl{
Colin Cross8b74d172016-09-13 09:59:14 -0700466 target: a.commonProperties.CompileTarget,
467 targetPrimary: a.commonProperties.CompilePrimary,
Dan Willemsenaa118f92017-04-06 12:49:58 -0700468 vendor: a.commonProperties.Proprietary || a.commonProperties.Vendor,
Colin Cross8b74d172016-09-13 09:59:14 -0700469 config: ctx.Config().(Config),
Colin Cross3f40fa42015-01-30 17:27:36 -0800470 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800471}
472
Colin Cross635c3b02016-05-18 15:37:25 -0700473func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800474 androidCtx := &androidModuleContext{
Colin Cross8d8f8e22016-08-03 11:57:50 -0700475 module: a.module,
Colin Cross6362e272015-10-29 15:25:03 -0700476 ModuleContext: ctx,
477 androidBaseContextImpl: a.androidBaseContextFactory(ctx),
478 installDeps: a.computeInstallDeps(ctx),
479 installFiles: a.installFiles,
Colin Cross6ff51382015-12-17 16:39:19 -0800480 missingDeps: ctx.GetMissingDependencies(),
Colin Cross3f40fa42015-01-30 17:27:36 -0800481 }
482
Colin Cross9b1d13d2016-09-19 15:18:11 -0700483 if a.Enabled() {
484 a.module.GenerateAndroidBuildActions(androidCtx)
485 if ctx.Failed() {
486 return
487 }
488
489 a.installFiles = append(a.installFiles, androidCtx.installFiles...)
490 a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800491 }
492
Colin Cross9b1d13d2016-09-19 15:18:11 -0700493 if a == ctx.FinalModule().(Module).base() {
494 a.generateModuleTarget(ctx)
495 if ctx.Failed() {
496 return
497 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800498 }
499}
500
Colin Crossf6566ed2015-03-24 11:13:38 -0700501type androidBaseContextImpl struct {
Colin Cross8b74d172016-09-13 09:59:14 -0700502 target Target
503 targetPrimary bool
504 debug bool
Dan Willemsenaa118f92017-04-06 12:49:58 -0700505 vendor bool
Colin Cross8b74d172016-09-13 09:59:14 -0700506 config Config
Colin Crossf6566ed2015-03-24 11:13:38 -0700507}
508
Colin Cross3f40fa42015-01-30 17:27:36 -0800509type androidModuleContext struct {
510 blueprint.ModuleContext
Colin Crossf6566ed2015-03-24 11:13:38 -0700511 androidBaseContextImpl
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700512 installDeps Paths
513 installFiles Paths
514 checkbuildFiles Paths
Colin Cross6ff51382015-12-17 16:39:19 -0800515 missingDeps []string
Colin Cross8d8f8e22016-08-03 11:57:50 -0700516 module Module
Colin Cross6ff51382015-12-17 16:39:19 -0800517}
518
519func (a *androidModuleContext) ninjaError(outputs []string, err error) {
520 a.ModuleContext.Build(pctx, blueprint.BuildParams{
521 Rule: ErrorRule,
522 Outputs: outputs,
523 Optional: true,
524 Args: map[string]string{
525 "error": err.Error(),
526 },
527 })
528 return
Colin Cross3f40fa42015-01-30 17:27:36 -0800529}
530
Dan Willemsen14e5c2a2015-11-30 13:59:34 -0800531func (a *androidModuleContext) Build(pctx blueprint.PackageContext, params blueprint.BuildParams) {
Colin Cross7f19f372016-11-01 11:10:25 -0700532 if a.missingDeps != nil {
Colin Cross6ff51382015-12-17 16:39:19 -0800533 a.ninjaError(params.Outputs, fmt.Errorf("module %s missing dependencies: %s\n",
534 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
535 return
536 }
537
Colin Cross3f40fa42015-01-30 17:27:36 -0800538 params.Optional = true
539 a.ModuleContext.Build(pctx, params)
540}
541
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700542func (a *androidModuleContext) ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) {
543 bparams := blueprint.BuildParams{
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700544 Rule: params.Rule,
Colin Cross33bfb0a2016-11-21 17:23:08 -0800545 Deps: params.Deps,
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700546 Outputs: params.Outputs.Strings(),
547 ImplicitOutputs: params.ImplicitOutputs.Strings(),
548 Inputs: params.Inputs.Strings(),
549 Implicits: params.Implicits.Strings(),
550 OrderOnly: params.OrderOnly.Strings(),
551 Args: params.Args,
552 Optional: !params.Default,
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700553 }
554
Colin Cross33bfb0a2016-11-21 17:23:08 -0800555 if params.Depfile != nil {
556 bparams.Depfile = params.Depfile.String()
557 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700558 if params.Output != nil {
559 bparams.Outputs = append(bparams.Outputs, params.Output.String())
560 }
Dan Willemsen9f3c5742016-11-03 14:28:31 -0700561 if params.ImplicitOutput != nil {
562 bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String())
563 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700564 if params.Input != nil {
565 bparams.Inputs = append(bparams.Inputs, params.Input.String())
566 }
567 if params.Implicit != nil {
568 bparams.Implicits = append(bparams.Implicits, params.Implicit.String())
569 }
570
Colin Cross6ff51382015-12-17 16:39:19 -0800571 if a.missingDeps != nil {
572 a.ninjaError(bparams.Outputs, fmt.Errorf("module %s missing dependencies: %s\n",
573 a.ModuleName(), strings.Join(a.missingDeps, ", ")))
574 return
575 }
576
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700577 a.ModuleContext.Build(pctx, bparams)
578}
579
Colin Cross6ff51382015-12-17 16:39:19 -0800580func (a *androidModuleContext) GetMissingDependencies() []string {
581 return a.missingDeps
582}
583
Dan Willemsen6553f5e2016-03-10 18:14:25 -0800584func (a *androidModuleContext) AddMissingDependencies(deps []string) {
585 if deps != nil {
586 a.missingDeps = append(a.missingDeps, deps...)
587 }
588}
589
Colin Crossa1ad8d12016-06-01 17:09:44 -0700590func (a *androidBaseContextImpl) Target() Target {
591 return a.target
592}
593
Colin Cross8b74d172016-09-13 09:59:14 -0700594func (a *androidBaseContextImpl) TargetPrimary() bool {
595 return a.targetPrimary
596}
597
Colin Crossf6566ed2015-03-24 11:13:38 -0700598func (a *androidBaseContextImpl) Arch() Arch {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700599 return a.target.Arch
Colin Cross3f40fa42015-01-30 17:27:36 -0800600}
601
Colin Crossa1ad8d12016-06-01 17:09:44 -0700602func (a *androidBaseContextImpl) Os() OsType {
603 return a.target.Os
Dan Willemsen490fd492015-11-24 17:53:15 -0800604}
605
Colin Crossf6566ed2015-03-24 11:13:38 -0700606func (a *androidBaseContextImpl) Host() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700607 return a.target.Os.Class == Host || a.target.Os.Class == HostCross
Colin Crossf6566ed2015-03-24 11:13:38 -0700608}
609
610func (a *androidBaseContextImpl) Device() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700611 return a.target.Os.Class == Device
Colin Crossf6566ed2015-03-24 11:13:38 -0700612}
613
Colin Cross0af4b842015-04-30 16:36:18 -0700614func (a *androidBaseContextImpl) Darwin() bool {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700615 return a.target.Os == Darwin
Colin Cross0af4b842015-04-30 16:36:18 -0700616}
617
Colin Cross3edeee12017-04-04 12:59:48 -0700618func (a *androidBaseContextImpl) Windows() bool {
619 return a.target.Os == Windows
620}
621
Colin Crossf6566ed2015-03-24 11:13:38 -0700622func (a *androidBaseContextImpl) Debug() bool {
623 return a.debug
624}
625
Colin Cross1e7d3702016-08-24 15:25:47 -0700626func (a *androidBaseContextImpl) PrimaryArch() bool {
627 return a.target.Arch.ArchType == a.config.Targets[a.target.Os.Class][0].Arch.ArchType
628}
629
Colin Cross1332b002015-04-07 17:11:30 -0700630func (a *androidBaseContextImpl) AConfig() Config {
631 return a.config
632}
633
Colin Cross9272ade2016-08-17 15:24:12 -0700634func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig {
635 return DeviceConfig{a.config.deviceConfig}
636}
637
Dan Willemsenaa118f92017-04-06 12:49:58 -0700638func (a *androidBaseContextImpl) Vendor() bool {
639 return a.vendor
Dan Willemsen782a2d12015-12-21 14:55:28 -0800640}
641
Colin Cross8d8f8e22016-08-03 11:57:50 -0700642func (a *androidModuleContext) InstallInData() bool {
643 return a.module.InstallInData()
Dan Willemsen782a2d12015-12-21 14:55:28 -0800644}
645
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700646func (a *androidModuleContext) InstallInSanitizerDir() bool {
647 return a.module.InstallInSanitizerDir()
648}
649
Dan Willemsen782a2d12015-12-21 14:55:28 -0800650func (a *androidModuleContext) InstallFileName(installPath OutputPath, name string, srcPath Path,
Colin Crossa2344662016-03-24 13:14:12 -0700651 deps ...Path) OutputPath {
Colin Cross35cec122015-04-02 14:37:16 -0700652
Dan Willemsen782a2d12015-12-21 14:55:28 -0800653 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -0700654 a.module.base().hooks.runInstallHooks(a, fullInstallPath, false)
Colin Cross3f40fa42015-01-30 17:27:36 -0800655
Colin Crossce75d2c2016-10-06 16:12:58 -0700656 if !a.module.base().commonProperties.SkipInstall &&
Dan Willemsen0e2d97b2016-11-28 17:50:06 -0800657 (!a.Device() || !a.AConfig().SkipDeviceInstall()) {
Colin Crossce75d2c2016-10-06 16:12:58 -0700658
Dan Willemsen322acaf2016-01-12 23:07:05 -0800659 deps = append(deps, a.installDeps...)
Colin Cross35cec122015-04-02 14:37:16 -0700660
Colin Cross89562dc2016-10-03 17:47:19 -0700661 var implicitDeps, orderOnlyDeps Paths
662
663 if a.Host() {
664 // Installed host modules might be used during the build, depend directly on their
665 // dependencies so their timestamp is updated whenever their dependency is updated
666 implicitDeps = deps
667 } else {
668 orderOnlyDeps = deps
669 }
670
Dan Willemsen322acaf2016-01-12 23:07:05 -0800671 a.ModuleBuild(pctx, ModuleBuildParams{
672 Rule: Cp,
673 Output: fullInstallPath,
674 Input: srcPath,
Colin Cross89562dc2016-10-03 17:47:19 -0700675 Implicits: implicitDeps,
676 OrderOnly: orderOnlyDeps,
Dan Willemsen7f730fd2016-01-14 11:22:23 -0800677 Default: !a.AConfig().EmbeddedInMake(),
Dan Willemsen322acaf2016-01-12 23:07:05 -0800678 })
Colin Cross3f40fa42015-01-30 17:27:36 -0800679
Dan Willemsen322acaf2016-01-12 23:07:05 -0800680 a.installFiles = append(a.installFiles, fullInstallPath)
681 }
Colin Cross1f8c52b2015-06-16 16:38:17 -0700682 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
Colin Cross35cec122015-04-02 14:37:16 -0700683 return fullInstallPath
684}
685
Colin Crossa2344662016-03-24 13:14:12 -0700686func (a *androidModuleContext) InstallFile(installPath OutputPath, srcPath Path, deps ...Path) OutputPath {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700687 return a.InstallFileName(installPath, filepath.Base(srcPath.String()), srcPath, deps...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800688}
689
Colin Cross3854a602016-01-11 12:49:11 -0800690func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath {
691 fullInstallPath := installPath.Join(a, name)
Colin Cross178a5092016-09-13 13:42:32 -0700692 a.module.base().hooks.runInstallHooks(a, fullInstallPath, true)
Colin Cross3854a602016-01-11 12:49:11 -0800693
Colin Crossce75d2c2016-10-06 16:12:58 -0700694 if !a.module.base().commonProperties.SkipInstall &&
Dan Willemsen0e2d97b2016-11-28 17:50:06 -0800695 (!a.Device() || !a.AConfig().SkipDeviceInstall()) {
Colin Crossce75d2c2016-10-06 16:12:58 -0700696
Colin Cross12fc4972016-01-11 12:49:11 -0800697 a.ModuleBuild(pctx, ModuleBuildParams{
698 Rule: Symlink,
699 Output: fullInstallPath,
700 OrderOnly: Paths{srcPath},
701 Default: !a.AConfig().EmbeddedInMake(),
702 Args: map[string]string{
703 "fromPath": srcPath.String(),
704 },
705 })
Colin Cross3854a602016-01-11 12:49:11 -0800706
Colin Cross12fc4972016-01-11 12:49:11 -0800707 a.installFiles = append(a.installFiles, fullInstallPath)
708 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
709 }
Colin Cross3854a602016-01-11 12:49:11 -0800710 return fullInstallPath
711}
712
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700713func (a *androidModuleContext) CheckbuildFile(srcPath Path) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800714 a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
715}
716
Colin Cross3f40fa42015-01-30 17:27:36 -0800717type fileInstaller interface {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700718 filesToInstall() Paths
Colin Cross3f40fa42015-01-30 17:27:36 -0800719}
720
721func isFileInstaller(m blueprint.Module) bool {
722 _, ok := m.(fileInstaller)
723 return ok
724}
725
726func isAndroidModule(m blueprint.Module) bool {
Colin Cross635c3b02016-05-18 15:37:25 -0700727 _, ok := m.(Module)
Colin Cross3f40fa42015-01-30 17:27:36 -0800728 return ok
729}
Colin Crossfce53272015-04-08 11:21:40 -0700730
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700731func findStringInSlice(str string, slice []string) int {
732 for i, s := range slice {
733 if s == str {
734 return i
Colin Crossfce53272015-04-08 11:21:40 -0700735 }
736 }
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700737 return -1
738}
739
Colin Cross068e0fe2016-12-13 15:23:47 -0800740func SrcIsModule(s string) string {
741 if len(s) > 1 && s[0] == ':' {
742 return s[1:]
743 }
744 return ""
745}
746
747type sourceDependencyTag struct {
748 blueprint.BaseDependencyTag
749}
750
751var SourceDepTag sourceDependencyTag
752
753// Returns a list of modules that must be depended on to satisfy filegroup or generated sources
754// modules listed in srcFiles using ":module" syntax
755func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) {
756 var deps []string
Nan Zhang2439eb72017-04-10 11:27:50 -0700757 set := make(map[string]bool)
758
Colin Cross068e0fe2016-12-13 15:23:47 -0800759 for _, s := range srcFiles {
760 if m := SrcIsModule(s); m != "" {
Nan Zhang2439eb72017-04-10 11:27:50 -0700761 if _, found := set[m]; found {
762 ctx.ModuleErrorf("found source dependency duplicate: %q!", m)
763 } else {
764 set[m] = true
765 deps = append(deps, m)
766 }
Colin Cross068e0fe2016-12-13 15:23:47 -0800767 }
768 }
769
770 ctx.AddDependency(ctx.Module(), SourceDepTag, deps...)
771}
772
773type SourceFileProducer interface {
774 Srcs() Paths
775}
776
777// Returns a list of paths expanded from globs and modules referenced using ":module" syntax.
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800778// ExtractSourcesDeps must have already been called during the dependency resolution phase.
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700779func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths {
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800780 return ctx.ExpandSourcesSubDir(srcFiles, excludes, "")
781}
782
783func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths {
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700784 prefix := PathForModuleSrc(ctx).String()
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800785
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700786 for i, e := range excludes {
787 j := findStringInSlice(e, srcFiles)
788 if j != -1 {
789 srcFiles = append(srcFiles[:j], srcFiles[j+1:]...)
790 }
791
792 excludes[i] = filepath.Join(prefix, e)
793 }
794
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800795 expandedSrcFiles := make(Paths, 0, len(srcFiles))
Colin Cross8f101b42015-06-17 15:09:06 -0700796 for _, s := range srcFiles {
Colin Cross068e0fe2016-12-13 15:23:47 -0800797 if m := SrcIsModule(s); m != "" {
798 module := ctx.GetDirectDepWithTag(m, SourceDepTag)
799 if srcProducer, ok := module.(SourceFileProducer); ok {
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800800 expandedSrcFiles = append(expandedSrcFiles, srcProducer.Srcs()...)
Colin Cross068e0fe2016-12-13 15:23:47 -0800801 } else {
802 ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m)
803 }
804 } else if pathtools.IsGlob(s) {
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800805 globbedSrcFiles := ctx.Glob(filepath.Join(prefix, s), excludes)
806 expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...)
807 for i, s := range expandedSrcFiles {
808 expandedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir)
809 }
Colin Cross8f101b42015-06-17 15:09:06 -0700810 } else {
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800811 s := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir)
812 expandedSrcFiles = append(expandedSrcFiles, s)
Colin Cross8f101b42015-06-17 15:09:06 -0700813 }
814 }
815
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800816 return expandedSrcFiles
Colin Cross8f101b42015-06-17 15:09:06 -0700817}
818
Nan Zhang6d34b302017-02-04 17:47:46 -0800819func (ctx *androidModuleContext) RequiredModuleNames() []string {
820 return ctx.module.base().commonProperties.Required
821}
822
Colin Cross7f19f372016-11-01 11:10:25 -0700823func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths {
824 ret, err := ctx.GlobWithDeps(globPattern, excludes)
Colin Cross8f101b42015-06-17 15:09:06 -0700825 if err != nil {
826 ctx.ModuleErrorf("glob: %s", err.Error())
827 }
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700828 return pathsForModuleSrcFromFullPath(ctx, ret)
Colin Crossfce53272015-04-08 11:21:40 -0700829}
Colin Cross1f8c52b2015-06-16 16:38:17 -0700830
Colin Cross463a90e2015-06-17 14:20:06 -0700831func init() {
Colin Cross798bfce2016-10-12 14:28:16 -0700832 RegisterSingletonType("buildtarget", BuildTargetSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -0700833}
834
Colin Cross1f8c52b2015-06-16 16:38:17 -0700835func BuildTargetSingleton() blueprint.Singleton {
836 return &buildTargetSingleton{}
837}
838
839type buildTargetSingleton struct{}
840
841func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
842 checkbuildDeps := []string{}
843
844 dirModules := make(map[string][]string)
845
846 ctx.VisitAllModules(func(module blueprint.Module) {
Colin Cross635c3b02016-05-18 15:37:25 -0700847 if a, ok := module.(Module); ok {
Colin Cross1f8c52b2015-06-16 16:38:17 -0700848 blueprintDir := a.base().blueprintDir
849 installTarget := a.base().installTarget
850 checkbuildTarget := a.base().checkbuildTarget
851
852 if checkbuildTarget != "" {
853 checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
854 dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget)
855 }
856
857 if installTarget != "" {
858 dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
859 }
860 }
861 })
862
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800863 suffix := ""
864 if ctx.Config().(Config).EmbeddedInMake() {
865 suffix = "-soong"
866 }
867
Colin Cross1f8c52b2015-06-16 16:38:17 -0700868 // Create a top-level checkbuild target that depends on all modules
869 ctx.Build(pctx, blueprint.BuildParams{
870 Rule: blueprint.Phony,
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800871 Outputs: []string{"checkbuild" + suffix},
Colin Cross1f8c52b2015-06-16 16:38:17 -0700872 Implicits: checkbuildDeps,
Dan Willemsen218f6562015-07-08 18:13:11 -0700873 Optional: true,
Colin Cross1f8c52b2015-06-16 16:38:17 -0700874 })
875
876 // Create a mm/<directory> target that depends on all modules in a directory
877 dirs := sortedKeys(dirModules)
878 for _, dir := range dirs {
879 ctx.Build(pctx, blueprint.BuildParams{
880 Rule: blueprint.Phony,
881 Outputs: []string{filepath.Join("mm", dir)},
882 Implicits: dirModules[dir],
Dan Willemsen5ba07e82015-12-11 13:51:06 -0800883 // HACK: checkbuild should be an optional build, but force it
884 // enabled for now in standalone builds
Colin Cross1604ecf2015-12-17 16:33:43 -0800885 Optional: ctx.Config().(Config).EmbeddedInMake(),
Colin Cross1f8c52b2015-06-16 16:38:17 -0700886 })
887 }
888}
Colin Crossd779da42015-12-17 18:00:23 -0800889
890type AndroidModulesByName struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700891 slice []Module
Colin Crossd779da42015-12-17 18:00:23 -0800892 ctx interface {
893 ModuleName(blueprint.Module) string
894 ModuleSubDir(blueprint.Module) string
895 }
896}
897
898func (s AndroidModulesByName) Len() int { return len(s.slice) }
899func (s AndroidModulesByName) Less(i, j int) bool {
900 mi, mj := s.slice[i], s.slice[j]
901 ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj)
902
903 if ni != nj {
904 return ni < nj
905 } else {
906 return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj)
907 }
908}
909func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] }