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 |
| 197 | } |
| 198 | |
| 199 | func (a *AndroidModuleBase) base() *AndroidModuleBase { |
| 200 | return a |
| 201 | } |
| 202 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 203 | func (a *AndroidModuleBase) SetHostOrDevice(hod HostOrDevice) { |
| 204 | a.commonProperties.CompileHostOrDevice = hod |
| 205 | } |
| 206 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 207 | func (a *AndroidModuleBase) SetArch(arch Arch) { |
| 208 | a.commonProperties.CompileArch = arch |
| 209 | } |
| 210 | |
| 211 | func (a *AndroidModuleBase) HostOrDevice() HostOrDevice { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 212 | return a.commonProperties.CompileHostOrDevice |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | func (a *AndroidModuleBase) HostSupported() bool { |
| 216 | return a.commonProperties.HostOrDeviceSupported == HostSupported || |
| 217 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
| 218 | a.hostAndDeviceProperties.Host_supported |
| 219 | } |
| 220 | |
| 221 | func (a *AndroidModuleBase) DeviceSupported() bool { |
| 222 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 223 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
| 224 | a.hostAndDeviceProperties.Device_supported |
| 225 | } |
| 226 | |
| 227 | func (a *AndroidModuleBase) Disabled() bool { |
| 228 | return a.commonProperties.Disabled |
| 229 | } |
| 230 | |
| 231 | func (a *AndroidModuleBase) computeInstallDeps( |
| 232 | ctx blueprint.ModuleContext) []string { |
| 233 | |
| 234 | result := []string{} |
| 235 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 236 | func(m blueprint.Module) { |
| 237 | fileInstaller := m.(fileInstaller) |
| 238 | files := fileInstaller.filesToInstall() |
| 239 | result = append(result, files...) |
| 240 | }) |
| 241 | |
| 242 | return result |
| 243 | } |
| 244 | |
| 245 | func (a *AndroidModuleBase) filesToInstall() []string { |
| 246 | return a.installFiles |
| 247 | } |
| 248 | |
| 249 | func (p *AndroidModuleBase) NoAddressSanitizer() bool { |
| 250 | return p.noAddressSanitizer |
| 251 | } |
| 252 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 253 | func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { |
| 254 | if a != ctx.FinalModule().(AndroidModule).base() { |
| 255 | return |
| 256 | } |
| 257 | |
| 258 | allInstalledFiles := []string{} |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 259 | allCheckbuildFiles := []string{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 260 | ctx.VisitAllModuleVariants(func(module blueprint.Module) { |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 261 | a := module.(AndroidModule).base() |
| 262 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 263 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 264 | }) |
| 265 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 266 | deps := []string{} |
| 267 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 268 | if len(allInstalledFiles) > 0 { |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 269 | name := ctx.ModuleName() + "-install" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 270 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 271 | Rule: blueprint.Phony, |
| 272 | Outputs: []string{name}, |
| 273 | Implicits: allInstalledFiles, |
| 274 | }) |
| 275 | deps = append(deps, name) |
| 276 | } |
| 277 | |
| 278 | if len(allCheckbuildFiles) > 0 { |
| 279 | name := ctx.ModuleName() + "-checkbuild" |
| 280 | ctx.Build(pctx, blueprint.BuildParams{ |
| 281 | Rule: blueprint.Phony, |
| 282 | Outputs: []string{name}, |
| 283 | Implicits: allCheckbuildFiles, |
| 284 | Optional: true, |
| 285 | }) |
| 286 | deps = append(deps, name) |
| 287 | } |
| 288 | |
| 289 | if len(deps) > 0 { |
| 290 | ctx.Build(pctx, blueprint.BuildParams{ |
| 291 | Rule: blueprint.Phony, |
| 292 | Outputs: []string{ctx.ModuleName()}, |
| 293 | Implicits: deps, |
| 294 | Optional: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 295 | }) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | func (a *AndroidModuleBase) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { |
| 300 | actx := &androidDynamicDependerContext{ |
| 301 | DynamicDependerModuleContext: ctx, |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 302 | androidBaseContextImpl: androidBaseContextImpl{ |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 303 | arch: a.commonProperties.CompileArch, |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 304 | hod: a.commonProperties.CompileHostOrDevice, |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 305 | config: ctx.Config().(Config), |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 306 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | if dynamic, ok := a.module.(AndroidDynamicDepender); ok { |
| 310 | return dynamic.AndroidDynamicDependencies(actx) |
| 311 | } |
| 312 | |
| 313 | return nil |
| 314 | } |
| 315 | |
| 316 | func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { |
| 317 | androidCtx := &androidModuleContext{ |
| 318 | ModuleContext: ctx, |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 319 | androidBaseContextImpl: androidBaseContextImpl{ |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 320 | arch: a.commonProperties.CompileArch, |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 321 | hod: a.commonProperties.CompileHostOrDevice, |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 322 | config: ctx.Config().(Config), |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 323 | }, |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 324 | installDeps: a.computeInstallDeps(ctx), |
| 325 | installFiles: a.installFiles, |
| 326 | extendedProperties: a.extendedProperties, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | if a.commonProperties.Disabled { |
| 330 | return |
| 331 | } |
| 332 | |
| 333 | a.module.GenerateAndroidBuildActions(androidCtx) |
| 334 | if ctx.Failed() { |
| 335 | return |
| 336 | } |
| 337 | |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 338 | a.installFiles = append(a.installFiles, androidCtx.installFiles...) |
| 339 | a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...) |
| 340 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 341 | a.generateModuleTarget(ctx) |
| 342 | if ctx.Failed() { |
| 343 | return |
| 344 | } |
| 345 | } |
| 346 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 347 | type androidBaseContextImpl struct { |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 348 | arch Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 349 | hod HostOrDevice |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 350 | debug bool |
| 351 | config Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 354 | type androidModuleContext struct { |
| 355 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 356 | androidBaseContextImpl |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 357 | installDeps []string |
| 358 | installFiles []string |
| 359 | checkbuildFiles []string |
| 360 | extendedProperties map[string]struct{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blueprint.BuildParams) { |
| 364 | params.Optional = true |
| 365 | a.ModuleContext.Build(pctx, params) |
| 366 | } |
| 367 | |
Colin Cross | 28d7659 | 2015-03-26 16:14:04 -0700 | [diff] [blame] | 368 | func (a *androidModuleContext) ContainsProperty(property string) bool { |
| 369 | if a.ModuleContext.ContainsProperty(property) { |
| 370 | return true |
| 371 | } |
| 372 | _, ok := a.extendedProperties[property] |
| 373 | return ok |
| 374 | } |
| 375 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 376 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 377 | return a.arch |
| 378 | } |
| 379 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 380 | func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice { |
| 381 | return a.hod |
| 382 | } |
| 383 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 384 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 385 | return a.hod.Host() |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 389 | return a.hod.Device() |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 392 | func (a *androidBaseContextImpl) Darwin() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 393 | return a.hod.Host() && runtime.GOOS == "darwin" |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 396 | func (a *androidBaseContextImpl) Debug() bool { |
| 397 | return a.debug |
| 398 | } |
| 399 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 400 | func (a *androidBaseContextImpl) AConfig() Config { |
| 401 | return a.config |
| 402 | } |
| 403 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 404 | func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string, |
| 405 | deps ...string) string { |
| 406 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 407 | config := a.AConfig() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 408 | var fullInstallPath string |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame^] | 409 | if a.hod.Device() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 410 | // TODO: replace unset with a device name once we have device targeting |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 411 | fullInstallPath = filepath.Join(config.DeviceOut(), "system", |
| 412 | installPath, name) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 413 | } else { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 414 | fullInstallPath = filepath.Join(config.HostOut(), installPath, name) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 417 | deps = append(deps, a.installDeps...) |
| 418 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 419 | a.ModuleContext.Build(pctx, blueprint.BuildParams{ |
| 420 | Rule: Cp, |
| 421 | Outputs: []string{fullInstallPath}, |
| 422 | Inputs: []string{srcPath}, |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 423 | OrderOnly: deps, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 424 | }) |
| 425 | |
| 426 | a.installFiles = append(a.installFiles, fullInstallPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 427 | return fullInstallPath |
| 428 | } |
| 429 | |
| 430 | func (a *androidModuleContext) InstallFile(installPath, srcPath string, deps ...string) string { |
| 431 | return a.InstallFileName(installPath, filepath.Base(srcPath), srcPath, deps...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | func (a *androidModuleContext) CheckbuildFile(srcPath string) { |
| 435 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 436 | } |
| 437 | |
| 438 | type androidDynamicDependerContext struct { |
| 439 | blueprint.DynamicDependerModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 440 | androidBaseContextImpl |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | type fileInstaller interface { |
| 444 | filesToInstall() []string |
| 445 | } |
| 446 | |
| 447 | func isFileInstaller(m blueprint.Module) bool { |
| 448 | _, ok := m.(fileInstaller) |
| 449 | return ok |
| 450 | } |
| 451 | |
| 452 | func isAndroidModule(m blueprint.Module) bool { |
| 453 | _, ok := m.(AndroidModule) |
| 454 | return ok |
| 455 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 456 | |
| 457 | func ExpandSources(ctx AndroidModuleContext, srcFiles []string) []string { |
| 458 | prefix := ModuleSrcDir(ctx) |
| 459 | for i, srcFile := range srcFiles { |
| 460 | if srcFile[0] == '-' { |
| 461 | srcFiles[i] = "-" + filepath.Join(prefix, srcFile[1:]) |
| 462 | } else { |
| 463 | srcFiles[i] = filepath.Join(prefix, srcFile) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | srcFiles = expandGlobs(ctx, srcFiles) |
| 468 | return srcFiles |
| 469 | } |