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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 20 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 21 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 22 | "android/soong" |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 23 | "android/soong/glob" |
| 24 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | var ( |
| 29 | DeviceSharedLibrary = "shared_library" |
| 30 | DeviceStaticLibrary = "static_library" |
| 31 | DeviceExecutable = "executable" |
| 32 | HostSharedLibrary = "host_shared_library" |
| 33 | HostStaticLibrary = "host_static_library" |
| 34 | HostExecutable = "host_executable" |
| 35 | ) |
| 36 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 37 | type ModuleBuildParams struct { |
| 38 | Rule blueprint.Rule |
| 39 | Output WritablePath |
| 40 | Outputs WritablePaths |
| 41 | Input Path |
| 42 | Inputs Paths |
| 43 | Implicit Path |
| 44 | Implicits Paths |
| 45 | OrderOnly Paths |
| 46 | Default bool |
| 47 | Args map[string]string |
| 48 | } |
| 49 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 50 | type androidBaseContext interface { |
| 51 | Arch() Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 52 | HostOrDevice() HostOrDevice |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 53 | HostType() HostType |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 54 | Host() bool |
| 55 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 56 | Darwin() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 57 | Debug() bool |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 58 | AConfig() Config |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 59 | Proprietary() bool |
| 60 | InstallInData() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 63 | type BaseContext interface { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 64 | blueprint.BaseModuleContext |
| 65 | androidBaseContext |
| 66 | } |
| 67 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 68 | type ModuleContext interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 69 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 70 | androidBaseContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 71 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 72 | // Similar to Build, but takes Paths instead of []string, |
| 73 | // and performs more verification. |
| 74 | ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 75 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 76 | ExpandSources(srcFiles, excludes []string) Paths |
| 77 | Glob(outDir, globPattern string, excludes []string) Paths |
| 78 | |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 79 | InstallFile(installPath OutputPath, srcPath Path, deps ...Path) OutputPath |
| 80 | InstallFileName(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 81 | CheckbuildFile(srcPath Path) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 82 | |
| 83 | AddMissingDependencies(deps []string) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 86 | type Module interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 87 | blueprint.Module |
| 88 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 89 | GenerateAndroidBuildActions(ModuleContext) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 90 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 91 | base() *ModuleBase |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 92 | Enabled() bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 93 | HostOrDevice() HostOrDevice |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 94 | InstallInData() bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 97 | type commonProperties struct { |
Colin Cross | c77f9d1 | 2015-04-02 13:54:39 -0700 | [diff] [blame] | 98 | Name string |
| 99 | Deps []string |
| 100 | Tags []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 101 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 102 | // emit build rules for this module |
| 103 | Enabled *bool `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 104 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 105 | // control whether this module compiles for 32-bit, 64-bit, or both. Possible values |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 106 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 107 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
| 108 | // platform |
| 109 | Compile_multilib string |
| 110 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 111 | // whether this is a proprietary vendor module, and should be installed into /vendor |
| 112 | Proprietary bool |
| 113 | |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame^] | 114 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 115 | // file |
| 116 | Logtags []string |
| 117 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 118 | // Set by HostOrDeviceMutator |
| 119 | CompileHostOrDevice HostOrDevice `blueprint:"mutated"` |
| 120 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 121 | // Set by HostTypeMutator |
| 122 | CompileHostType HostType `blueprint:"mutated"` |
| 123 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 124 | // Set by ArchMutator |
| 125 | CompileArch Arch `blueprint:"mutated"` |
| 126 | |
| 127 | // Set by InitAndroidModule |
| 128 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
| 129 | } |
| 130 | |
| 131 | type hostAndDeviceProperties struct { |
| 132 | Host_supported bool |
| 133 | Device_supported bool |
| 134 | } |
| 135 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 136 | type Multilib string |
| 137 | |
| 138 | const ( |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 139 | MultilibBoth Multilib = "both" |
| 140 | MultilibFirst Multilib = "first" |
| 141 | MultilibCommon Multilib = "common" |
| 142 | MultilibDefault Multilib = "" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 143 | ) |
| 144 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 145 | func InitAndroidModule(m Module, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 146 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 147 | |
| 148 | base := m.base() |
| 149 | base.module = m |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 150 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 151 | propertyStructs = append(propertyStructs, &base.commonProperties, &base.variableProperties) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 152 | |
| 153 | return m, propertyStructs |
| 154 | } |
| 155 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 156 | func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib, |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 157 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 158 | |
| 159 | _, propertyStructs = InitAndroidModule(m, propertyStructs...) |
| 160 | |
| 161 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 162 | base.commonProperties.HostOrDeviceSupported = hod |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 163 | base.commonProperties.Compile_multilib = string(defaultMultilib) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 164 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 165 | switch hod { |
| 166 | case HostAndDeviceSupported: |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 167 | // Default to module to device supported, host not supported, can override in module |
| 168 | // properties |
| 169 | base.hostAndDeviceProperties.Device_supported = true |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 170 | fallthrough |
| 171 | case HostAndDeviceDefault: |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 172 | propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties) |
| 173 | } |
| 174 | |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 175 | return InitArchModule(m, propertyStructs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // A AndroidModuleBase object contains the properties that are common to all Android |
| 179 | // modules. It should be included as an anonymous field in every module |
| 180 | // struct definition. InitAndroidModule should then be called from the module's |
| 181 | // factory function, and the return values from InitAndroidModule should be |
| 182 | // returned from the factory function. |
| 183 | // |
| 184 | // The AndroidModuleBase type is responsible for implementing the |
| 185 | // GenerateBuildActions method to support the blueprint.Module interface. This |
| 186 | // method will then call the module's GenerateAndroidBuildActions method once |
| 187 | // for each build variant that is to be built. GenerateAndroidBuildActions is |
| 188 | // passed a AndroidModuleContext rather than the usual blueprint.ModuleContext. |
| 189 | // AndroidModuleContext exposes extra functionality specific to the Android build |
| 190 | // system including details about the particular build variant that is to be |
| 191 | // generated. |
| 192 | // |
| 193 | // For example: |
| 194 | // |
| 195 | // import ( |
| 196 | // "android/soong/common" |
Colin Cross | 70b4059 | 2015-03-23 12:57:34 -0700 | [diff] [blame] | 197 | // "github.com/google/blueprint" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 198 | // ) |
| 199 | // |
| 200 | // type myModule struct { |
| 201 | // common.AndroidModuleBase |
| 202 | // properties struct { |
| 203 | // MyProperty string |
| 204 | // } |
| 205 | // } |
| 206 | // |
| 207 | // func NewMyModule() (blueprint.Module, []interface{}) { |
| 208 | // m := &myModule{} |
| 209 | // return common.InitAndroidModule(m, &m.properties) |
| 210 | // } |
| 211 | // |
| 212 | // func (m *myModule) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 213 | // // Get the CPU architecture for the current build variant. |
| 214 | // variantArch := ctx.Arch() |
| 215 | // |
| 216 | // // ... |
| 217 | // } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 218 | type ModuleBase struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 219 | // Putting the curiously recurring thing pointing to the thing that contains |
| 220 | // the thing pattern to good use. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 221 | module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 222 | |
| 223 | commonProperties commonProperties |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 224 | variableProperties variableProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 225 | hostAndDeviceProperties hostAndDeviceProperties |
| 226 | generalProperties []interface{} |
| 227 | archProperties []*archProperties |
| 228 | |
| 229 | noAddressSanitizer bool |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 230 | installFiles Paths |
| 231 | checkbuildFiles Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 232 | |
| 233 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 234 | // Only set on the final variant of each module |
| 235 | installTarget string |
| 236 | checkbuildTarget string |
| 237 | blueprintDir string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 240 | func (a *ModuleBase) base() *ModuleBase { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 241 | return a |
| 242 | } |
| 243 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 244 | func (a *ModuleBase) SetHostOrDevice(hod HostOrDevice) { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 245 | a.commonProperties.CompileHostOrDevice = hod |
| 246 | } |
| 247 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 248 | func (a *ModuleBase) SetHostType(ht HostType) { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 249 | a.commonProperties.CompileHostType = ht |
| 250 | } |
| 251 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 252 | func (a *ModuleBase) SetArch(arch Arch) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 253 | a.commonProperties.CompileArch = arch |
| 254 | } |
| 255 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 256 | func (a *ModuleBase) HostOrDevice() HostOrDevice { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 257 | return a.commonProperties.CompileHostOrDevice |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 260 | func (a *ModuleBase) HostType() HostType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 261 | return a.commonProperties.CompileHostType |
| 262 | } |
| 263 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 264 | func (a *ModuleBase) Host() bool { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 265 | return a.HostOrDevice().Host() |
| 266 | } |
| 267 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 268 | func (a *ModuleBase) Arch() Arch { |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 269 | return a.commonProperties.CompileArch |
| 270 | } |
| 271 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 272 | func (a *ModuleBase) HostSupported() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 273 | return a.commonProperties.HostOrDeviceSupported == HostSupported || |
| 274 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
| 275 | a.hostAndDeviceProperties.Host_supported |
| 276 | } |
| 277 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 278 | func (a *ModuleBase) DeviceSupported() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 279 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 280 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
| 281 | a.hostAndDeviceProperties.Device_supported |
| 282 | } |
| 283 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 284 | func (a *ModuleBase) Enabled() bool { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 285 | if a.commonProperties.Enabled == nil { |
| 286 | if a.HostSupported() && a.HostOrDevice().Host() && a.HostType() == Windows { |
| 287 | return false |
| 288 | } else { |
| 289 | return true |
| 290 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 291 | } |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 292 | return *a.commonProperties.Enabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 295 | func (a *ModuleBase) computeInstallDeps( |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 296 | ctx blueprint.ModuleContext) Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 297 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 298 | result := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 299 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 300 | func(m blueprint.Module) { |
| 301 | fileInstaller := m.(fileInstaller) |
| 302 | files := fileInstaller.filesToInstall() |
| 303 | result = append(result, files...) |
| 304 | }) |
| 305 | |
| 306 | return result |
| 307 | } |
| 308 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 309 | func (a *ModuleBase) filesToInstall() Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 310 | return a.installFiles |
| 311 | } |
| 312 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 313 | func (p *ModuleBase) NoAddressSanitizer() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 314 | return p.noAddressSanitizer |
| 315 | } |
| 316 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 317 | func (p *ModuleBase) InstallInData() bool { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 318 | return false |
| 319 | } |
| 320 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 321 | func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { |
| 322 | if a != ctx.FinalModule().(Module).base() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 323 | return |
| 324 | } |
| 325 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 326 | allInstalledFiles := Paths{} |
| 327 | allCheckbuildFiles := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 328 | ctx.VisitAllModuleVariants(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 329 | a := module.(Module).base() |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 330 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 331 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 332 | }) |
| 333 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 334 | deps := []string{} |
| 335 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 336 | if len(allInstalledFiles) > 0 { |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 337 | name := ctx.ModuleName() + "-install" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 338 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 339 | Rule: blueprint.Phony, |
| 340 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 341 | Implicits: allInstalledFiles.Strings(), |
Colin Cross | 346aa13 | 2015-12-17 17:19:51 -0800 | [diff] [blame] | 342 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 343 | }) |
| 344 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 345 | a.installTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | if len(allCheckbuildFiles) > 0 { |
| 349 | name := ctx.ModuleName() + "-checkbuild" |
| 350 | ctx.Build(pctx, blueprint.BuildParams{ |
| 351 | Rule: blueprint.Phony, |
| 352 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 353 | Implicits: allCheckbuildFiles.Strings(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 354 | Optional: true, |
| 355 | }) |
| 356 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 357 | a.checkbuildTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | if len(deps) > 0 { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 361 | suffix := "" |
| 362 | if ctx.Config().(Config).EmbeddedInMake() { |
| 363 | suffix = "-soong" |
| 364 | } |
| 365 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 366 | ctx.Build(pctx, blueprint.BuildParams{ |
| 367 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 368 | Outputs: []string{ctx.ModuleName() + suffix}, |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 369 | Implicits: deps, |
| 370 | Optional: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 371 | }) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 372 | |
| 373 | a.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 377 | func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 378 | return androidBaseContextImpl{ |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 379 | arch: a.commonProperties.CompileArch, |
| 380 | hod: a.commonProperties.CompileHostOrDevice, |
| 381 | ht: a.commonProperties.CompileHostType, |
| 382 | proprietary: a.commonProperties.Proprietary, |
| 383 | config: ctx.Config().(Config), |
| 384 | installInData: a.module.InstallInData(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 385 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 388 | func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 389 | androidCtx := &androidModuleContext{ |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 390 | ModuleContext: ctx, |
| 391 | androidBaseContextImpl: a.androidBaseContextFactory(ctx), |
| 392 | installDeps: a.computeInstallDeps(ctx), |
| 393 | installFiles: a.installFiles, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 394 | missingDeps: ctx.GetMissingDependencies(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 397 | if !a.Enabled() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 398 | return |
| 399 | } |
| 400 | |
| 401 | a.module.GenerateAndroidBuildActions(androidCtx) |
| 402 | if ctx.Failed() { |
| 403 | return |
| 404 | } |
| 405 | |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 406 | a.installFiles = append(a.installFiles, androidCtx.installFiles...) |
| 407 | a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...) |
| 408 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 409 | a.generateModuleTarget(ctx) |
| 410 | if ctx.Failed() { |
| 411 | return |
| 412 | } |
| 413 | } |
| 414 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 415 | type androidBaseContextImpl struct { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 416 | arch Arch |
| 417 | hod HostOrDevice |
| 418 | ht HostType |
| 419 | debug bool |
| 420 | config Config |
| 421 | proprietary bool |
| 422 | installInData bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 425 | type androidModuleContext struct { |
| 426 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 427 | androidBaseContextImpl |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 428 | installDeps Paths |
| 429 | installFiles Paths |
| 430 | checkbuildFiles Paths |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 431 | missingDeps []string |
| 432 | } |
| 433 | |
| 434 | func (a *androidModuleContext) ninjaError(outputs []string, err error) { |
| 435 | a.ModuleContext.Build(pctx, blueprint.BuildParams{ |
| 436 | Rule: ErrorRule, |
| 437 | Outputs: outputs, |
| 438 | Optional: true, |
| 439 | Args: map[string]string{ |
| 440 | "error": err.Error(), |
| 441 | }, |
| 442 | }) |
| 443 | return |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Dan Willemsen | 14e5c2a | 2015-11-30 13:59:34 -0800 | [diff] [blame] | 446 | func (a *androidModuleContext) Build(pctx blueprint.PackageContext, params blueprint.BuildParams) { |
Colin Cross | e2c4874 | 2016-04-27 13:47:35 -0700 | [diff] [blame] | 447 | if a.missingDeps != nil && params.Rule != globRule { |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 448 | a.ninjaError(params.Outputs, fmt.Errorf("module %s missing dependencies: %s\n", |
| 449 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
| 450 | return |
| 451 | } |
| 452 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 453 | params.Optional = true |
| 454 | a.ModuleContext.Build(pctx, params) |
| 455 | } |
| 456 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 457 | func (a *androidModuleContext) ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) { |
| 458 | bparams := blueprint.BuildParams{ |
| 459 | Rule: params.Rule, |
| 460 | Outputs: params.Outputs.Strings(), |
| 461 | Inputs: params.Inputs.Strings(), |
| 462 | Implicits: params.Implicits.Strings(), |
| 463 | OrderOnly: params.OrderOnly.Strings(), |
| 464 | Args: params.Args, |
| 465 | Optional: !params.Default, |
| 466 | } |
| 467 | |
| 468 | if params.Output != nil { |
| 469 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 470 | } |
| 471 | if params.Input != nil { |
| 472 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 473 | } |
| 474 | if params.Implicit != nil { |
| 475 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 476 | } |
| 477 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 478 | if a.missingDeps != nil { |
| 479 | a.ninjaError(bparams.Outputs, fmt.Errorf("module %s missing dependencies: %s\n", |
| 480 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
| 481 | return |
| 482 | } |
| 483 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 484 | a.ModuleContext.Build(pctx, bparams) |
| 485 | } |
| 486 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 487 | func (a *androidModuleContext) GetMissingDependencies() []string { |
| 488 | return a.missingDeps |
| 489 | } |
| 490 | |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 491 | func (a *androidModuleContext) AddMissingDependencies(deps []string) { |
| 492 | if deps != nil { |
| 493 | a.missingDeps = append(a.missingDeps, deps...) |
| 494 | } |
| 495 | } |
| 496 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 497 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 498 | return a.arch |
| 499 | } |
| 500 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 501 | func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice { |
| 502 | return a.hod |
| 503 | } |
| 504 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 505 | func (a *androidBaseContextImpl) HostType() HostType { |
| 506 | return a.ht |
| 507 | } |
| 508 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 509 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 510 | return a.hod.Host() |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 514 | return a.hod.Device() |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 517 | func (a *androidBaseContextImpl) Darwin() bool { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 518 | return a.hod.Host() && a.ht == Darwin |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 521 | func (a *androidBaseContextImpl) Debug() bool { |
| 522 | return a.debug |
| 523 | } |
| 524 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 525 | func (a *androidBaseContextImpl) AConfig() Config { |
| 526 | return a.config |
| 527 | } |
| 528 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 529 | func (a *androidBaseContextImpl) Proprietary() bool { |
| 530 | return a.proprietary |
| 531 | } |
| 532 | |
| 533 | func (a *androidBaseContextImpl) InstallInData() bool { |
| 534 | return a.installInData |
| 535 | } |
| 536 | |
| 537 | func (a *androidModuleContext) InstallFileName(installPath OutputPath, name string, srcPath Path, |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 538 | deps ...Path) OutputPath { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 539 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 540 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 541 | |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 542 | if a.Host() || !a.AConfig().SkipDeviceInstall() { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 543 | deps = append(deps, a.installDeps...) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 544 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 545 | a.ModuleBuild(pctx, ModuleBuildParams{ |
| 546 | Rule: Cp, |
| 547 | Output: fullInstallPath, |
| 548 | Input: srcPath, |
| 549 | OrderOnly: Paths(deps), |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 550 | Default: !a.AConfig().EmbeddedInMake(), |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 551 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 552 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 553 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 554 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 555 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 556 | return fullInstallPath |
| 557 | } |
| 558 | |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 559 | func (a *androidModuleContext) InstallFile(installPath OutputPath, srcPath Path, deps ...Path) OutputPath { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 560 | return a.InstallFileName(installPath, filepath.Base(srcPath.String()), srcPath, deps...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 561 | } |
| 562 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 563 | func (a *androidModuleContext) CheckbuildFile(srcPath Path) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 564 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 565 | } |
| 566 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 567 | type fileInstaller interface { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 568 | filesToInstall() Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | func isFileInstaller(m blueprint.Module) bool { |
| 572 | _, ok := m.(fileInstaller) |
| 573 | return ok |
| 574 | } |
| 575 | |
| 576 | func isAndroidModule(m blueprint.Module) bool { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 577 | _, ok := m.(Module) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 578 | return ok |
| 579 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 580 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 581 | func findStringInSlice(str string, slice []string) int { |
| 582 | for i, s := range slice { |
| 583 | if s == str { |
| 584 | return i |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 585 | } |
| 586 | } |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 587 | return -1 |
| 588 | } |
| 589 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 590 | func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths { |
| 591 | prefix := PathForModuleSrc(ctx).String() |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 592 | for i, e := range excludes { |
| 593 | j := findStringInSlice(e, srcFiles) |
| 594 | if j != -1 { |
| 595 | srcFiles = append(srcFiles[:j], srcFiles[j+1:]...) |
| 596 | } |
| 597 | |
| 598 | excludes[i] = filepath.Join(prefix, e) |
| 599 | } |
| 600 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 601 | globbedSrcFiles := make(Paths, 0, len(srcFiles)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 602 | for _, s := range srcFiles { |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 603 | if glob.IsGlob(s) { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 604 | globbedSrcFiles = append(globbedSrcFiles, ctx.Glob("src_glob", filepath.Join(prefix, s), excludes)...) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 605 | } else { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 606 | globbedSrcFiles = append(globbedSrcFiles, PathForModuleSrc(ctx, s)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
| 610 | return globbedSrcFiles |
| 611 | } |
| 612 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 613 | func (ctx *androidModuleContext) Glob(outDir, globPattern string, excludes []string) Paths { |
| 614 | ret, err := Glob(ctx, PathForModuleOut(ctx, outDir).String(), globPattern, excludes) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 615 | if err != nil { |
| 616 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 617 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 618 | return pathsForModuleSrcFromFullPath(ctx, ret) |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 619 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 620 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 621 | func init() { |
| 622 | soong.RegisterSingletonType("buildtarget", BuildTargetSingleton) |
| 623 | } |
| 624 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 625 | func BuildTargetSingleton() blueprint.Singleton { |
| 626 | return &buildTargetSingleton{} |
| 627 | } |
| 628 | |
| 629 | type buildTargetSingleton struct{} |
| 630 | |
| 631 | func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 632 | checkbuildDeps := []string{} |
| 633 | |
| 634 | dirModules := make(map[string][]string) |
| 635 | |
| 636 | ctx.VisitAllModules(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 637 | if a, ok := module.(Module); ok { |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 638 | blueprintDir := a.base().blueprintDir |
| 639 | installTarget := a.base().installTarget |
| 640 | checkbuildTarget := a.base().checkbuildTarget |
| 641 | |
| 642 | if checkbuildTarget != "" { |
| 643 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
| 644 | dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget) |
| 645 | } |
| 646 | |
| 647 | if installTarget != "" { |
| 648 | dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget) |
| 649 | } |
| 650 | } |
| 651 | }) |
| 652 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 653 | suffix := "" |
| 654 | if ctx.Config().(Config).EmbeddedInMake() { |
| 655 | suffix = "-soong" |
| 656 | } |
| 657 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 658 | // Create a top-level checkbuild target that depends on all modules |
| 659 | ctx.Build(pctx, blueprint.BuildParams{ |
| 660 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 661 | Outputs: []string{"checkbuild" + suffix}, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 662 | Implicits: checkbuildDeps, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 663 | Optional: true, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 664 | }) |
| 665 | |
| 666 | // Create a mm/<directory> target that depends on all modules in a directory |
| 667 | dirs := sortedKeys(dirModules) |
| 668 | for _, dir := range dirs { |
| 669 | ctx.Build(pctx, blueprint.BuildParams{ |
| 670 | Rule: blueprint.Phony, |
| 671 | Outputs: []string{filepath.Join("mm", dir)}, |
| 672 | Implicits: dirModules[dir], |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 673 | // HACK: checkbuild should be an optional build, but force it |
| 674 | // enabled for now in standalone builds |
Colin Cross | 1604ecf | 2015-12-17 16:33:43 -0800 | [diff] [blame] | 675 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 676 | }) |
| 677 | } |
| 678 | } |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 679 | |
| 680 | type AndroidModulesByName struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 681 | slice []Module |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 682 | ctx interface { |
| 683 | ModuleName(blueprint.Module) string |
| 684 | ModuleSubDir(blueprint.Module) string |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | func (s AndroidModulesByName) Len() int { return len(s.slice) } |
| 689 | func (s AndroidModulesByName) Less(i, j int) bool { |
| 690 | mi, mj := s.slice[i], s.slice[j] |
| 691 | ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj) |
| 692 | |
| 693 | if ni != nj { |
| 694 | return ni < nj |
| 695 | } else { |
| 696 | return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj) |
| 697 | } |
| 698 | } |
| 699 | func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] } |