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 | "fmt" |
| 19 | "reflect" |
| 20 | "runtime" |
| 21 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 22 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 23 | "android/soong" |
| 24 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
| 26 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 29 | func init() { |
| 30 | soong.RegisterEarlyMutator("host_or_device", HostOrDeviceMutator) |
| 31 | soong.RegisterEarlyMutator("arch", ArchMutator) |
| 32 | } |
| 33 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 34 | var ( |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 35 | Arm = newArch("arm", "lib32") |
| 36 | Arm64 = newArch("arm64", "lib64") |
| 37 | Mips = newArch("mips", "lib32") |
| 38 | Mips64 = newArch("mips64", "lib64") |
| 39 | X86 = newArch("x86", "lib32") |
| 40 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 41 | |
| 42 | Common = ArchType{ |
| 43 | Name: "common", |
| 44 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 45 | ) |
| 46 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 47 | var archTypeMap = map[string]ArchType{ |
| 48 | "arm": Arm, |
| 49 | "arm64": Arm64, |
| 50 | "mips": Mips, |
| 51 | "misp64": Mips64, |
| 52 | "x86": X86, |
| 53 | "x86_64": X86_64, |
| 54 | } |
| 55 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 56 | /* |
| 57 | Example blueprints file containing all variant property groups, with comment listing what type |
| 58 | of variants get properties in that group: |
| 59 | |
| 60 | module { |
| 61 | arch: { |
| 62 | arm: { |
| 63 | // Host or device variants with arm architecture |
| 64 | }, |
| 65 | arm64: { |
| 66 | // Host or device variants with arm64 architecture |
| 67 | }, |
| 68 | mips: { |
| 69 | // Host or device variants with mips architecture |
| 70 | }, |
| 71 | mips64: { |
| 72 | // Host or device variants with mips64 architecture |
| 73 | }, |
| 74 | x86: { |
| 75 | // Host or device variants with x86 architecture |
| 76 | }, |
| 77 | x86_64: { |
| 78 | // Host or device variants with x86_64 architecture |
| 79 | }, |
| 80 | }, |
| 81 | multilib: { |
| 82 | lib32: { |
| 83 | // Host or device variants for 32-bit architectures |
| 84 | }, |
| 85 | lib64: { |
| 86 | // Host or device variants for 64-bit architectures |
| 87 | }, |
| 88 | }, |
| 89 | target: { |
| 90 | android: { |
| 91 | // Device variants |
| 92 | }, |
| 93 | host: { |
| 94 | // Host variants |
| 95 | }, |
| 96 | linux: { |
| 97 | // Linux host variants |
| 98 | }, |
| 99 | darwin: { |
| 100 | // Darwin host variants |
| 101 | }, |
| 102 | windows: { |
| 103 | // Windows host variants |
| 104 | }, |
| 105 | not_windows: { |
| 106 | // Non-windows host variants |
| 107 | }, |
| 108 | }, |
| 109 | } |
| 110 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 111 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 112 | type archProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 113 | // Properties to vary by target architecture |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 114 | Arch struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 115 | // Properties for module variants being built to run on arm (host or device) |
| 116 | Arm interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 117 | // Properties for module variants being built to run on arm64 (host or device) |
| 118 | Arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 119 | // Properties for module variants being built to run on mips (host or device) |
| 120 | Mips interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 121 | // Properties for module variants being built to run on mips64 (host or device) |
| 122 | Mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 123 | // Properties for module variants being built to run on x86 (host or device) |
| 124 | X86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 125 | // Properties for module variants being built to run on x86_64 (host or device) |
| 126 | X86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 127 | |
| 128 | // Arm arch variants |
| 129 | Armv5te interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 130 | Armv7_a interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 131 | Armv7_a_neon interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 132 | |
| 133 | // Arm cpu variants |
| 134 | Cortex_a7 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 135 | Cortex_a8 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 136 | Cortex_a9 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 137 | Cortex_a15 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 138 | Krait interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 139 | Denver interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 140 | |
| 141 | // Arm64 cpu variants |
Dan Willemsen | 00faa6d | 2015-09-11 17:38:13 -0700 | [diff] [blame] | 142 | Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 143 | Denver64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 144 | |
| 145 | // Mips arch variants |
| 146 | Mips_rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 147 | |
Colin Cross | 01432f6 | 2015-07-09 17:56:26 -0700 | [diff] [blame] | 148 | // X86 arch variants |
| 149 | X86_sse3 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 150 | X86_sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 151 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 152 | // X86 cpu variants |
| 153 | Atom interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 154 | Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 155 | } |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 156 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 157 | // Properties to vary by 32-bit or 64-bit |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 158 | Multilib struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 159 | // Properties for module variants being built to run on 32-bit devices |
| 160 | Lib32 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 161 | // Properties for module variants being built to run on 64-bit devices |
| 162 | Lib64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 163 | } |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 164 | // Properties to vary by build target (host or device, os, os+archictecture) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 165 | Target struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 166 | // Properties for module variants being built to run on the host |
| 167 | Host interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 168 | // Properties for module variants being built to run on the device |
| 169 | Android interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 170 | // Properties for module variants being built to run on arm devices |
| 171 | Android_arm interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 172 | // Properties for module variants being built to run on arm64 devices |
| 173 | Android_arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 174 | // Properties for module variants being built to run on mips devices |
| 175 | Android_mips interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 176 | // Properties for module variants being built to run on mips64 devices |
| 177 | Android_mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 178 | // Properties for module variants being built to run on x86 devices |
| 179 | Android_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 180 | // Properties for module variants being built to run on x86_64 devices |
| 181 | Android_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 182 | // Properties for module variants being built to run on devices that support 64-bit |
| 183 | Android64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 184 | // Properties for module variants being built to run on devices that do not support 64-bit |
| 185 | Android32 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 186 | // Properties for module variants being built to run on linux hosts |
| 187 | Linux interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 188 | // Properties for module variants being built to run on linux x86 hosts |
| 189 | Linux_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 190 | // Properties for module variants being built to run on linux x86_64 hosts |
| 191 | Linux_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 192 | // Properties for module variants being built to run on darwin hosts |
| 193 | Darwin interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 194 | // Properties for module variants being built to run on darwin x86 hosts |
| 195 | Darwin_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 196 | // Properties for module variants being built to run on darwin x86_64 hosts |
| 197 | Darwin_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 198 | // Properties for module variants being built to run on windows hosts |
| 199 | Windows interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 200 | // Properties for module variants being built to run on linux or darwin hosts |
| 201 | Not_windows interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | // An Arch indicates a single CPU architecture. |
| 206 | type Arch struct { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 207 | ArchType ArchType |
| 208 | ArchVariant string |
| 209 | CpuVariant string |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 210 | Abi []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 214 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 215 | if a.ArchVariant != "" { |
| 216 | s += "_" + a.ArchVariant |
| 217 | } |
| 218 | if a.CpuVariant != "" { |
| 219 | s += "_" + a.CpuVariant |
| 220 | } |
| 221 | return s |
| 222 | } |
| 223 | |
| 224 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 225 | Name string |
| 226 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 229 | func newArch(name, multilib string) ArchType { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 230 | return ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 231 | Name: name, |
| 232 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | func (a ArchType) String() string { |
| 237 | return a.Name |
| 238 | } |
| 239 | |
| 240 | type HostOrDeviceSupported int |
| 241 | |
| 242 | const ( |
| 243 | _ HostOrDeviceSupported = iota |
| 244 | HostSupported |
| 245 | DeviceSupported |
| 246 | HostAndDeviceSupported |
| 247 | ) |
| 248 | |
| 249 | type HostOrDevice int |
| 250 | |
| 251 | const ( |
| 252 | _ HostOrDevice = iota |
| 253 | Host |
| 254 | Device |
| 255 | ) |
| 256 | |
| 257 | func (hod HostOrDevice) String() string { |
| 258 | switch hod { |
| 259 | case Device: |
| 260 | return "device" |
| 261 | case Host: |
| 262 | return "host" |
| 263 | default: |
| 264 | panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod)) |
| 265 | } |
| 266 | } |
| 267 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 268 | func (hod HostOrDevice) Property() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 269 | switch hod { |
| 270 | case Device: |
| 271 | return "android" |
| 272 | case Host: |
| 273 | return "host" |
| 274 | default: |
| 275 | panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod)) |
| 276 | } |
| 277 | } |
| 278 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 279 | func (hod HostOrDevice) Host() bool { |
| 280 | if hod == 0 { |
| 281 | panic("HostOrDevice unset") |
| 282 | } |
| 283 | return hod == Host |
| 284 | } |
| 285 | |
| 286 | func (hod HostOrDevice) Device() bool { |
| 287 | if hod == 0 { |
| 288 | panic("HostOrDevice unset") |
| 289 | } |
| 290 | return hod == Device |
| 291 | } |
| 292 | |
| 293 | var hostOrDeviceName = map[HostOrDevice]string{ |
| 294 | Device: "device", |
| 295 | Host: "host", |
| 296 | } |
| 297 | |
| 298 | var ( |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 299 | commonArch = Arch{ |
| 300 | ArchType: Common, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 301 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 302 | ) |
| 303 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 304 | func HostOrDeviceMutator(mctx blueprint.EarlyMutatorContext) { |
| 305 | var module AndroidModule |
| 306 | var ok bool |
| 307 | if module, ok = mctx.Module().(AndroidModule); !ok { |
| 308 | return |
| 309 | } |
| 310 | |
| 311 | hods := []HostOrDevice{} |
| 312 | |
| 313 | if module.base().HostSupported() { |
| 314 | hods = append(hods, Host) |
| 315 | } |
| 316 | |
| 317 | if module.base().DeviceSupported() { |
| 318 | hods = append(hods, Device) |
| 319 | } |
| 320 | |
| 321 | if len(hods) == 0 { |
| 322 | return |
| 323 | } |
| 324 | |
| 325 | hodNames := []string{} |
| 326 | for _, hod := range hods { |
| 327 | hodNames = append(hodNames, hod.String()) |
| 328 | } |
| 329 | |
| 330 | modules := mctx.CreateVariations(hodNames...) |
| 331 | for i, m := range modules { |
| 332 | m.(AndroidModule).base().SetHostOrDevice(hods[i]) |
| 333 | } |
| 334 | } |
| 335 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 336 | func ArchMutator(mctx blueprint.EarlyMutatorContext) { |
| 337 | var module AndroidModule |
| 338 | var ok bool |
| 339 | if module, ok = mctx.Module().(AndroidModule); !ok { |
| 340 | return |
| 341 | } |
| 342 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 343 | hostArches, deviceArches, err := decodeArchProductVariables(mctx.Config().(Config).ProductVariables) |
| 344 | if err != nil { |
| 345 | mctx.ModuleErrorf("%s", err.Error()) |
| 346 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 347 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 348 | moduleArches := []Arch{} |
| 349 | multilib := module.base().commonProperties.Compile_multilib |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 350 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 351 | if module.base().HostSupported() && module.base().HostOrDevice().Host() { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 352 | hostModuleArches, err := decodeMultilib(multilib, hostArches) |
| 353 | if err != nil { |
| 354 | mctx.ModuleErrorf("%s", err.Error()) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 355 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 356 | |
| 357 | moduleArches = append(moduleArches, hostModuleArches...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 360 | if module.base().DeviceSupported() && module.base().HostOrDevice().Device() { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 361 | deviceModuleArches, err := decodeMultilib(multilib, deviceArches) |
| 362 | if err != nil { |
| 363 | mctx.ModuleErrorf("%s", err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 364 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 365 | |
| 366 | moduleArches = append(moduleArches, deviceModuleArches...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 369 | if len(moduleArches) == 0 { |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 370 | return |
| 371 | } |
| 372 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 373 | archNames := []string{} |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 374 | for _, arch := range moduleArches { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 375 | archNames = append(archNames, arch.String()) |
| 376 | } |
| 377 | |
| 378 | modules := mctx.CreateVariations(archNames...) |
| 379 | |
| 380 | for i, m := range modules { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 381 | m.(AndroidModule).base().SetArch(moduleArches[i]) |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 382 | m.(AndroidModule).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 386 | func InitArchModule(m AndroidModule, defaultMultilib Multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 387 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 388 | |
| 389 | base := m.base() |
| 390 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 391 | base.commonProperties.Compile_multilib = string(defaultMultilib) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 392 | |
| 393 | base.generalProperties = append(base.generalProperties, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 394 | propertyStructs...) |
| 395 | |
| 396 | for _, properties := range base.generalProperties { |
| 397 | propertiesValue := reflect.ValueOf(properties) |
| 398 | if propertiesValue.Kind() != reflect.Ptr { |
| 399 | panic("properties must be a pointer to a struct") |
| 400 | } |
| 401 | |
| 402 | propertiesValue = propertiesValue.Elem() |
| 403 | if propertiesValue.Kind() != reflect.Struct { |
| 404 | panic("properties must be a pointer to a struct") |
| 405 | } |
| 406 | |
| 407 | archProperties := &archProperties{} |
| 408 | forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) { |
Colin Cross | 3ab7d88 | 2015-05-19 13:03:01 -0700 | [diff] [blame] | 409 | newValue := proptools.CloneEmptyProperties(propertiesValue) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 410 | v.Set(newValue) |
| 411 | }) |
| 412 | |
| 413 | base.archProperties = append(base.archProperties, archProperties) |
| 414 | } |
| 415 | |
| 416 | var allProperties []interface{} |
| 417 | allProperties = append(allProperties, base.generalProperties...) |
| 418 | for _, asp := range base.archProperties { |
| 419 | allProperties = append(allProperties, asp) |
| 420 | } |
| 421 | |
| 422 | return m, allProperties |
| 423 | } |
| 424 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 425 | var dashToUnderscoreReplacer = strings.NewReplacer("-", "_") |
| 426 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 427 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 428 | func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext) { |
| 429 | arch := a.commonProperties.CompileArch |
| 430 | hod := a.commonProperties.CompileHostOrDevice |
| 431 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 432 | if arch.ArchType == Common { |
| 433 | return |
| 434 | } |
| 435 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 436 | callback := func(srcPropertyName, dstPropertyName string) { |
| 437 | a.extendedProperties[dstPropertyName] = struct{}{} |
| 438 | } |
| 439 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 440 | for i := range a.generalProperties { |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 441 | generalPropsValue := []reflect.Value{reflect.ValueOf(a.generalProperties[i]).Elem()} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 442 | |
| 443 | // Handle arch-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 444 | // arch: { |
| 445 | // arm64: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 446 | // key: value, |
| 447 | // }, |
| 448 | // }, |
| 449 | t := arch.ArchType |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 450 | field := proptools.FieldNameForProperty(t.Name) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 451 | extendProperties(ctx, "arch_variant", "arch."+t.Name, generalPropsValue, |
| 452 | reflect.ValueOf(a.archProperties[i].Arch).FieldByName(field).Elem().Elem(), callback) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 453 | |
| 454 | // Handle arch-variant-specific properties in the form: |
| 455 | // arch: { |
| 456 | // variant: { |
| 457 | // key: value, |
| 458 | // }, |
| 459 | // }, |
| 460 | v := dashToUnderscoreReplacer.Replace(arch.ArchVariant) |
| 461 | if v != "" { |
| 462 | field := proptools.FieldNameForProperty(v) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 463 | extendProperties(ctx, "arch_variant", "arch."+v, generalPropsValue, |
| 464 | reflect.ValueOf(a.archProperties[i].Arch).FieldByName(field).Elem().Elem(), callback) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | // Handle cpu-variant-specific properties in the form: |
| 468 | // arch: { |
| 469 | // variant: { |
| 470 | // key: value, |
| 471 | // }, |
| 472 | // }, |
| 473 | c := dashToUnderscoreReplacer.Replace(arch.CpuVariant) |
| 474 | if c != "" { |
| 475 | field := proptools.FieldNameForProperty(c) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 476 | extendProperties(ctx, "arch_variant", "arch."+c, generalPropsValue, |
| 477 | reflect.ValueOf(a.archProperties[i].Arch).FieldByName(field).Elem().Elem(), callback) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 478 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 479 | |
| 480 | // Handle multilib-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 481 | // multilib: { |
| 482 | // lib32: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 483 | // key: value, |
| 484 | // }, |
| 485 | // }, |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 486 | multilibField := proptools.FieldNameForProperty(t.Multilib) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 487 | extendProperties(ctx, "arch_variant", "multilib."+t.Multilib, generalPropsValue, |
| 488 | reflect.ValueOf(a.archProperties[i].Multilib).FieldByName(multilibField).Elem().Elem(), callback) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 489 | |
| 490 | // Handle host-or-device-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 491 | // target: { |
| 492 | // host: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 493 | // key: value, |
| 494 | // }, |
| 495 | // }, |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 496 | hodProperty := hod.Property() |
| 497 | hodField := proptools.FieldNameForProperty(hodProperty) |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 498 | extendProperties(ctx, "arch_variant", "target."+hodProperty, generalPropsValue, |
| 499 | reflect.ValueOf(a.archProperties[i].Target).FieldByName(hodField).Elem().Elem(), callback) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 500 | |
| 501 | // Handle host target properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 502 | // target: { |
| 503 | // linux: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 504 | // key: value, |
| 505 | // }, |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 506 | // not_windows: { |
| 507 | // key: value, |
| 508 | // }, |
| 509 | // linux_x86: { |
| 510 | // key: value, |
| 511 | // }, |
| 512 | // linux_arm: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 513 | // key: value, |
| 514 | // }, |
| 515 | // }, |
| 516 | var osList = []struct { |
| 517 | goos string |
| 518 | field string |
| 519 | }{ |
| 520 | {"darwin", "Darwin"}, |
| 521 | {"linux", "Linux"}, |
| 522 | {"windows", "Windows"}, |
| 523 | } |
| 524 | |
| 525 | if hod.Host() { |
| 526 | for _, v := range osList { |
| 527 | if v.goos == runtime.GOOS { |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 528 | extendProperties(ctx, "arch_variant", "target."+v.goos, generalPropsValue, |
| 529 | reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field).Elem().Elem(), callback) |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 530 | t := arch.ArchType |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 531 | extendProperties(ctx, "arch_variant", "target."+v.goos+"_"+t.Name, generalPropsValue, |
| 532 | reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field+"_"+t.Name).Elem().Elem(), callback) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 535 | extendProperties(ctx, "arch_variant", "target.not_windows", generalPropsValue, |
| 536 | reflect.ValueOf(a.archProperties[i].Target).FieldByName("Not_windows").Elem().Elem(), callback) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 539 | // Handle 64-bit device properties in the form: |
| 540 | // target { |
| 541 | // android64 { |
| 542 | // key: value, |
| 543 | // }, |
| 544 | // android32 { |
| 545 | // key: value, |
| 546 | // }, |
| 547 | // }, |
| 548 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 549 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 550 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 551 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 552 | if hod.Device() { |
| 553 | if true /* && target_is_64_bit */ { |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 554 | extendProperties(ctx, "arch_variant", "target.android64", generalPropsValue, |
| 555 | reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android64").Elem().Elem(), callback) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 556 | } else { |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 557 | extendProperties(ctx, "arch_variant", "target.android32", generalPropsValue, |
| 558 | reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android32").Elem().Elem(), callback) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 561 | |
| 562 | // Handle device architecture properties in the form: |
| 563 | // target { |
| 564 | // android_arm { |
| 565 | // key: value, |
| 566 | // }, |
| 567 | // android_x86 { |
| 568 | // key: value, |
| 569 | // }, |
| 570 | // }, |
| 571 | if hod.Device() { |
| 572 | t := arch.ArchType |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 573 | extendProperties(ctx, "arch_variant", "target.android_"+t.Name, generalPropsValue, |
| 574 | reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android_"+t.Name).Elem().Elem(), callback) |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 577 | if ctx.Failed() { |
| 578 | return |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 584 | switch v.Kind() { |
| 585 | case reflect.Interface: |
| 586 | f(v) |
| 587 | case reflect.Struct: |
| 588 | for i := 0; i < v.NumField(); i++ { |
| 589 | forEachInterface(v.Field(i), f) |
| 590 | } |
| 591 | case reflect.Ptr: |
| 592 | forEachInterface(v.Elem(), f) |
| 593 | default: |
| 594 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 595 | } |
| 596 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame^] | 597 | |
| 598 | // Convert the arch product variables into a list of host and device Arch structs |
| 599 | func decodeArchProductVariables(variables productVariables) ([]Arch, []Arch, error) { |
| 600 | if variables.HostArch == nil { |
| 601 | return nil, nil, fmt.Errorf("No host primary architecture set") |
| 602 | } |
| 603 | |
| 604 | hostArch, err := decodeArch(*variables.HostArch, nil, nil, nil) |
| 605 | if err != nil { |
| 606 | return nil, nil, err |
| 607 | } |
| 608 | |
| 609 | hostArches := []Arch{hostArch} |
| 610 | |
| 611 | if variables.HostSecondaryArch != nil { |
| 612 | hostSecondaryArch, err := decodeArch(*variables.HostSecondaryArch, nil, nil, nil) |
| 613 | if err != nil { |
| 614 | return nil, nil, err |
| 615 | } |
| 616 | hostArches = append(hostArches, hostSecondaryArch) |
| 617 | } |
| 618 | |
| 619 | if variables.DeviceArch == nil { |
| 620 | return nil, nil, fmt.Errorf("No device primary architecture set") |
| 621 | } |
| 622 | |
| 623 | deviceArch, err := decodeArch(*variables.DeviceArch, variables.DeviceArchVariant, |
| 624 | variables.DeviceCpuVariant, variables.DeviceAbi) |
| 625 | if err != nil { |
| 626 | return nil, nil, err |
| 627 | } |
| 628 | |
| 629 | deviceArches := []Arch{deviceArch} |
| 630 | |
| 631 | if variables.DeviceSecondaryArch != nil { |
| 632 | deviceSecondaryArch, err := decodeArch(*variables.DeviceSecondaryArch, |
| 633 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 634 | variables.DeviceSecondaryAbi) |
| 635 | if err != nil { |
| 636 | return nil, nil, err |
| 637 | } |
| 638 | deviceArches = append(deviceArches, deviceSecondaryArch) |
| 639 | } |
| 640 | |
| 641 | return hostArches, deviceArches, nil |
| 642 | } |
| 643 | |
| 644 | // Convert a set of strings from product variables into a single Arch struct |
| 645 | func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) { |
| 646 | stringPtr := func(p *string) string { |
| 647 | if p != nil { |
| 648 | return *p |
| 649 | } |
| 650 | return "" |
| 651 | } |
| 652 | |
| 653 | slicePtr := func(p *[]string) []string { |
| 654 | if p != nil { |
| 655 | return *p |
| 656 | } |
| 657 | return nil |
| 658 | } |
| 659 | |
| 660 | archType := archTypeMap[arch] |
| 661 | |
| 662 | return Arch{ |
| 663 | ArchType: archType, |
| 664 | ArchVariant: stringPtr(archVariant), |
| 665 | CpuVariant: stringPtr(cpuVariant), |
| 666 | Abi: slicePtr(abi), |
| 667 | }, nil |
| 668 | } |
| 669 | |
| 670 | // Use the module multilib setting to select one or more arches from an arch list |
| 671 | func decodeMultilib(multilib string, arches []Arch) ([]Arch, error) { |
| 672 | buildArches := []Arch{} |
| 673 | switch multilib { |
| 674 | case "common": |
| 675 | buildArches = append(buildArches, commonArch) |
| 676 | case "both": |
| 677 | buildArches = append(buildArches, arches...) |
| 678 | case "first": |
| 679 | buildArches = append(buildArches, arches[0]) |
| 680 | case "32": |
| 681 | for _, a := range arches { |
| 682 | if a.ArchType.Multilib == "lib32" { |
| 683 | buildArches = append(buildArches, a) |
| 684 | } |
| 685 | } |
| 686 | case "64": |
| 687 | for _, a := range arches { |
| 688 | if a.ArchType.Multilib == "lib64" { |
| 689 | buildArches = append(buildArches, a) |
| 690 | } |
| 691 | } |
| 692 | default: |
| 693 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`, |
| 694 | multilib) |
| 695 | //buildArches = append(buildArches, arches[0]) |
| 696 | } |
| 697 | |
| 698 | return buildArches, nil |
| 699 | } |