Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package common |
| 16 | |
| 17 | import ( |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 18 | "path/filepath" |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 19 | "runtime" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 20 | |
| 21 | "github.com/google/blueprint" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | var ( |
| 25 | DeviceSharedLibrary = "shared_library" |
| 26 | DeviceStaticLibrary = "static_library" |
| 27 | DeviceExecutable = "executable" |
| 28 | HostSharedLibrary = "host_shared_library" |
| 29 | HostStaticLibrary = "host_static_library" |
| 30 | HostExecutable = "host_executable" |
| 31 | ) |
| 32 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 33 | type androidBaseContext interface { |
| 34 | Arch() Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 35 | HostOrDevice() HostOrDevice |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 36 | Host() bool |
| 37 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 38 | Darwin() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 39 | Debug() bool |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 40 | AConfig() Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | type AndroidBaseContext interface { |
| 44 | blueprint.BaseModuleContext |
| 45 | androidBaseContext |
| 46 | } |
| 47 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 48 | type AndroidModuleContext interface { |
| 49 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 50 | androidBaseContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 51 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 52 | InstallFile(installPath, srcPath string, deps ...string) string |
| 53 | InstallFileName(installPath, name, srcPath string, deps ...string) string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 54 | CheckbuildFile(srcPath string) |
| 55 | } |
| 56 | |
| 57 | type AndroidModule interface { |
| 58 | blueprint.Module |
| 59 | |
| 60 | GenerateAndroidBuildActions(AndroidModuleContext) |
| 61 | |
| 62 | base() *AndroidModuleBase |
| 63 | Disabled() bool |
| 64 | HostOrDevice() HostOrDevice |
| 65 | } |
| 66 | |
| 67 | type AndroidDynamicDepender interface { |
| 68 | AndroidDynamicDependencies(ctx AndroidDynamicDependerModuleContext) []string |
| 69 | } |
| 70 | |
| 71 | type AndroidDynamicDependerModuleContext interface { |
| 72 | blueprint.DynamicDependerModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 73 | androidBaseContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | type commonProperties struct { |
Colin Cross | c77f9d1 | 2015-04-02 13:54:39 -0700 | [diff] [blame] | 77 | Name string |
| 78 | Deps []string |
| 79 | Tags []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 80 | |
| 81 | // disabled: don't emit any build rules for this module |
| 82 | Disabled bool `android:"arch_variant"` |
| 83 | |
| 84 | // multilib: control whether this module compiles for 32-bit, 64-bit, or both. Possible values |
| 85 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 86 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
| 87 | // platform |
| 88 | Compile_multilib string |
| 89 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 90 | // Set by HostOrDeviceMutator |
| 91 | CompileHostOrDevice HostOrDevice `blueprint:"mutated"` |
| 92 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 93 | // Set by ArchMutator |
| 94 | CompileArch Arch `blueprint:"mutated"` |
| 95 | |
| 96 | // Set by InitAndroidModule |
| 97 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
| 98 | } |
| 99 | |
| 100 | type hostAndDeviceProperties struct { |
| 101 | Host_supported bool |
| 102 | Device_supported bool |
| 103 | } |
| 104 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 105 | type Multilib string |
| 106 | |
| 107 | const ( |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 108 | MultilibBoth Multilib = "both" |
| 109 | MultilibFirst Multilib = "first" |
| 110 | MultilibCommon Multilib = "common" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 111 | ) |
| 112 | |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 113 | func InitAndroidModule(m AndroidModule, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 114 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 115 | |
| 116 | base := m.base() |
| 117 | base.module = m |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 118 | base.extendedProperties = make(map[string]struct{}) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 119 | |
| 120 | propertyStructs = append(propertyStructs, &base.commonProperties) |
| 121 | |
| 122 | return m, propertyStructs |
| 123 | } |
| 124 | |
| 125 | func InitAndroidArchModule(m AndroidModule, hod HostOrDeviceSupported, defaultMultilib Multilib, |
| 126 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 127 | |
| 128 | _, propertyStructs = InitAndroidModule(m, propertyStructs...) |
| 129 | |
| 130 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 131 | base.commonProperties.HostOrDeviceSupported = hod |
| 132 | |
| 133 | if hod == HostAndDeviceSupported { |
| 134 | // Default to module to device supported, host not supported, can override in module |
| 135 | // properties |
| 136 | base.hostAndDeviceProperties.Device_supported = true |
| 137 | propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties) |
| 138 | } |
| 139 | |
| 140 | return InitArchModule(m, defaultMultilib, propertyStructs...) |
| 141 | } |
| 142 | |
| 143 | // A AndroidModuleBase object contains the properties that are common to all Android |
| 144 | // modules. It should be included as an anonymous field in every module |
| 145 | // struct definition. InitAndroidModule should then be called from the module's |
| 146 | // factory function, and the return values from InitAndroidModule should be |
| 147 | // returned from the factory function. |
| 148 | // |
| 149 | // The AndroidModuleBase type is responsible for implementing the |
| 150 | // GenerateBuildActions method to support the blueprint.Module interface. This |
| 151 | // method will then call the module's GenerateAndroidBuildActions method once |
| 152 | // for each build variant that is to be built. GenerateAndroidBuildActions is |
| 153 | // passed a AndroidModuleContext rather than the usual blueprint.ModuleContext. |
| 154 | // AndroidModuleContext exposes extra functionality specific to the Android build |
| 155 | // system including details about the particular build variant that is to be |
| 156 | // generated. |
| 157 | // |
| 158 | // For example: |
| 159 | // |
| 160 | // import ( |
| 161 | // "android/soong/common" |
Colin Cross | 70b4059 | 2015-03-23 12:57:34 -0700 | [diff] [blame] | 162 | // "github.com/google/blueprint" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 163 | // ) |
| 164 | // |
| 165 | // type myModule struct { |
| 166 | // common.AndroidModuleBase |
| 167 | // properties struct { |
| 168 | // MyProperty string |
| 169 | // } |
| 170 | // } |
| 171 | // |
| 172 | // func NewMyModule() (blueprint.Module, []interface{}) { |
| 173 | // m := &myModule{} |
| 174 | // return common.InitAndroidModule(m, &m.properties) |
| 175 | // } |
| 176 | // |
| 177 | // func (m *myModule) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 178 | // // Get the CPU architecture for the current build variant. |
| 179 | // variantArch := ctx.Arch() |
| 180 | // |
| 181 | // // ... |
| 182 | // } |
| 183 | type AndroidModuleBase struct { |
| 184 | // Putting the curiously recurring thing pointing to the thing that contains |
| 185 | // the thing pattern to good use. |
| 186 | module AndroidModule |
| 187 | |
| 188 | commonProperties commonProperties |
| 189 | hostAndDeviceProperties hostAndDeviceProperties |
| 190 | generalProperties []interface{} |
| 191 | archProperties []*archProperties |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 192 | extendedProperties map[string]struct{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 193 | |
| 194 | noAddressSanitizer bool |
| 195 | installFiles []string |
| 196 | checkbuildFiles []string |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame^] | 197 | |
| 198 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 199 | // Only set on the final variant of each module |
| 200 | installTarget string |
| 201 | checkbuildTarget string |
| 202 | blueprintDir string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | func (a *AndroidModuleBase) base() *AndroidModuleBase { |
| 206 | return a |
| 207 | } |
| 208 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 209 | func (a *AndroidModuleBase) SetHostOrDevice(hod HostOrDevice) { |
| 210 | a.commonProperties.CompileHostOrDevice = hod |
| 211 | } |
| 212 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 213 | func (a *AndroidModuleBase) SetArch(arch Arch) { |
| 214 | a.commonProperties.CompileArch = arch |
| 215 | } |
| 216 | |
| 217 | func (a *AndroidModuleBase) HostOrDevice() HostOrDevice { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 218 | return a.commonProperties.CompileHostOrDevice |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | func (a *AndroidModuleBase) HostSupported() bool { |
| 222 | return a.commonProperties.HostOrDeviceSupported == HostSupported || |
| 223 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
| 224 | a.hostAndDeviceProperties.Host_supported |
| 225 | } |
| 226 | |
| 227 | func (a *AndroidModuleBase) DeviceSupported() bool { |
| 228 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 229 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
| 230 | a.hostAndDeviceProperties.Device_supported |
| 231 | } |
| 232 | |
| 233 | func (a *AndroidModuleBase) Disabled() bool { |
| 234 | return a.commonProperties.Disabled |
| 235 | } |
| 236 | |
| 237 | func (a *AndroidModuleBase) computeInstallDeps( |
| 238 | ctx blueprint.ModuleContext) []string { |
| 239 | |
| 240 | result := []string{} |
| 241 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 242 | func(m blueprint.Module) { |
| 243 | fileInstaller := m.(fileInstaller) |
| 244 | files := fileInstaller.filesToInstall() |
| 245 | result = append(result, files...) |
| 246 | }) |
| 247 | |
| 248 | return result |
| 249 | } |
| 250 | |
| 251 | func (a *AndroidModuleBase) filesToInstall() []string { |
| 252 | return a.installFiles |
| 253 | } |
| 254 | |
| 255 | func (p *AndroidModuleBase) NoAddressSanitizer() bool { |
| 256 | return p.noAddressSanitizer |
| 257 | } |
| 258 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 259 | func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { |
| 260 | if a != ctx.FinalModule().(AndroidModule).base() { |
| 261 | return |
| 262 | } |
| 263 | |
| 264 | allInstalledFiles := []string{} |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 265 | allCheckbuildFiles := []string{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 266 | ctx.VisitAllModuleVariants(func(module blueprint.Module) { |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 267 | a := module.(AndroidModule).base() |
| 268 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 269 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 270 | }) |
| 271 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 272 | deps := []string{} |
| 273 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 274 | if len(allInstalledFiles) > 0 { |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 275 | name := ctx.ModuleName() + "-install" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 276 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 277 | Rule: blueprint.Phony, |
| 278 | Outputs: []string{name}, |
| 279 | Implicits: allInstalledFiles, |
| 280 | }) |
| 281 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame^] | 282 | a.installTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | if len(allCheckbuildFiles) > 0 { |
| 286 | name := ctx.ModuleName() + "-checkbuild" |
| 287 | ctx.Build(pctx, blueprint.BuildParams{ |
| 288 | Rule: blueprint.Phony, |
| 289 | Outputs: []string{name}, |
| 290 | Implicits: allCheckbuildFiles, |
| 291 | Optional: true, |
| 292 | }) |
| 293 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame^] | 294 | a.checkbuildTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | if len(deps) > 0 { |
| 298 | ctx.Build(pctx, blueprint.BuildParams{ |
| 299 | Rule: blueprint.Phony, |
| 300 | Outputs: []string{ctx.ModuleName()}, |
| 301 | Implicits: deps, |
| 302 | Optional: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 303 | }) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame^] | 304 | |
| 305 | a.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
| 309 | func (a *AndroidModuleBase) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { |
| 310 | actx := &androidDynamicDependerContext{ |
| 311 | DynamicDependerModuleContext: ctx, |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 312 | androidBaseContextImpl: androidBaseContextImpl{ |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 313 | arch: a.commonProperties.CompileArch, |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 314 | hod: a.commonProperties.CompileHostOrDevice, |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 315 | config: ctx.Config().(Config), |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 316 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | if dynamic, ok := a.module.(AndroidDynamicDepender); ok { |
| 320 | return dynamic.AndroidDynamicDependencies(actx) |
| 321 | } |
| 322 | |
| 323 | return nil |
| 324 | } |
| 325 | |
| 326 | func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { |
| 327 | androidCtx := &androidModuleContext{ |
| 328 | ModuleContext: ctx, |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 329 | androidBaseContextImpl: androidBaseContextImpl{ |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 330 | arch: a.commonProperties.CompileArch, |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 331 | hod: a.commonProperties.CompileHostOrDevice, |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 332 | config: ctx.Config().(Config), |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 333 | }, |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 334 | installDeps: a.computeInstallDeps(ctx), |
| 335 | installFiles: a.installFiles, |
| 336 | extendedProperties: a.extendedProperties, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | if a.commonProperties.Disabled { |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | a.module.GenerateAndroidBuildActions(androidCtx) |
| 344 | if ctx.Failed() { |
| 345 | return |
| 346 | } |
| 347 | |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 348 | a.installFiles = append(a.installFiles, androidCtx.installFiles...) |
| 349 | a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...) |
| 350 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 351 | a.generateModuleTarget(ctx) |
| 352 | if ctx.Failed() { |
| 353 | return |
| 354 | } |
| 355 | } |
| 356 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 357 | type androidBaseContextImpl struct { |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 358 | arch Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 359 | hod HostOrDevice |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 360 | debug bool |
| 361 | config Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 364 | type androidModuleContext struct { |
| 365 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 366 | androidBaseContextImpl |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 367 | installDeps []string |
| 368 | installFiles []string |
| 369 | checkbuildFiles []string |
| 370 | extendedProperties map[string]struct{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blueprint.BuildParams) { |
| 374 | params.Optional = true |
| 375 | a.ModuleContext.Build(pctx, params) |
| 376 | } |
| 377 | |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 378 | func (a *androidModuleContext) ContainsProperty(property string) bool { |
| 379 | if a.ModuleContext.ContainsProperty(property) { |
| 380 | return true |
| 381 | } |
| 382 | _, ok := a.extendedProperties[property] |
| 383 | return ok |
| 384 | } |
| 385 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 386 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 387 | return a.arch |
| 388 | } |
| 389 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 390 | func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice { |
| 391 | return a.hod |
| 392 | } |
| 393 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 394 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 395 | return a.hod.Host() |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 399 | return a.hod.Device() |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 402 | func (a *androidBaseContextImpl) Darwin() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 403 | return a.hod.Host() && runtime.GOOS == "darwin" |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 406 | func (a *androidBaseContextImpl) Debug() bool { |
| 407 | return a.debug |
| 408 | } |
| 409 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 410 | func (a *androidBaseContextImpl) AConfig() Config { |
| 411 | return a.config |
| 412 | } |
| 413 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 414 | func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string, |
| 415 | deps ...string) string { |
| 416 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 417 | config := a.AConfig() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 418 | var fullInstallPath string |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 419 | if a.hod.Device() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 420 | // TODO: replace unset with a device name once we have device targeting |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 421 | fullInstallPath = filepath.Join(config.DeviceOut(), "system", |
| 422 | installPath, name) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 423 | } else { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 424 | fullInstallPath = filepath.Join(config.HostOut(), installPath, name) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 427 | deps = append(deps, a.installDeps...) |
| 428 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 429 | a.ModuleContext.Build(pctx, blueprint.BuildParams{ |
| 430 | Rule: Cp, |
| 431 | Outputs: []string{fullInstallPath}, |
| 432 | Inputs: []string{srcPath}, |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 433 | OrderOnly: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 434 | }) |
| 435 | |
| 436 | a.installFiles = append(a.installFiles, fullInstallPath) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame^] | 437 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 438 | return fullInstallPath |
| 439 | } |
| 440 | |
| 441 | func (a *androidModuleContext) InstallFile(installPath, srcPath string, deps ...string) string { |
| 442 | return a.InstallFileName(installPath, filepath.Base(srcPath), srcPath, deps...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | func (a *androidModuleContext) CheckbuildFile(srcPath string) { |
| 446 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 447 | } |
| 448 | |
| 449 | type androidDynamicDependerContext struct { |
| 450 | blueprint.DynamicDependerModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 451 | androidBaseContextImpl |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | type fileInstaller interface { |
| 455 | filesToInstall() []string |
| 456 | } |
| 457 | |
| 458 | func isFileInstaller(m blueprint.Module) bool { |
| 459 | _, ok := m.(fileInstaller) |
| 460 | return ok |
| 461 | } |
| 462 | |
| 463 | func isAndroidModule(m blueprint.Module) bool { |
| 464 | _, ok := m.(AndroidModule) |
| 465 | return ok |
| 466 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 467 | |
| 468 | func ExpandSources(ctx AndroidModuleContext, srcFiles []string) []string { |
| 469 | prefix := ModuleSrcDir(ctx) |
| 470 | for i, srcFile := range srcFiles { |
| 471 | if srcFile[0] == '-' { |
| 472 | srcFiles[i] = "-" + filepath.Join(prefix, srcFile[1:]) |
| 473 | } else { |
| 474 | srcFiles[i] = filepath.Join(prefix, srcFile) |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | srcFiles = expandGlobs(ctx, srcFiles) |
| 479 | return srcFiles |
| 480 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame^] | 481 | |
| 482 | func BuildTargetSingleton() blueprint.Singleton { |
| 483 | return &buildTargetSingleton{} |
| 484 | } |
| 485 | |
| 486 | type buildTargetSingleton struct{} |
| 487 | |
| 488 | func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 489 | checkbuildDeps := []string{} |
| 490 | |
| 491 | dirModules := make(map[string][]string) |
| 492 | |
| 493 | ctx.VisitAllModules(func(module blueprint.Module) { |
| 494 | if a, ok := module.(AndroidModule); ok { |
| 495 | blueprintDir := a.base().blueprintDir |
| 496 | installTarget := a.base().installTarget |
| 497 | checkbuildTarget := a.base().checkbuildTarget |
| 498 | |
| 499 | if checkbuildTarget != "" { |
| 500 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
| 501 | dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget) |
| 502 | } |
| 503 | |
| 504 | if installTarget != "" { |
| 505 | dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget) |
| 506 | } |
| 507 | } |
| 508 | }) |
| 509 | |
| 510 | // Create a top-level checkbuild target that depends on all modules |
| 511 | ctx.Build(pctx, blueprint.BuildParams{ |
| 512 | Rule: blueprint.Phony, |
| 513 | Outputs: []string{"checkbuild"}, |
| 514 | Implicits: checkbuildDeps, |
| 515 | // HACK: checkbuild should be an optional build, but force it enabled for now |
| 516 | //Optional: true, |
| 517 | }) |
| 518 | |
| 519 | // Create a mm/<directory> target that depends on all modules in a directory |
| 520 | dirs := sortedKeys(dirModules) |
| 521 | for _, dir := range dirs { |
| 522 | ctx.Build(pctx, blueprint.BuildParams{ |
| 523 | Rule: blueprint.Phony, |
| 524 | Outputs: []string{filepath.Join("mm", dir)}, |
| 525 | Implicits: dirModules[dir], |
| 526 | Optional: true, |
| 527 | }) |
| 528 | } |
| 529 | } |