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