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 | |
| 23 | "github.com/google/blueprint" |
| 24 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 27 | func init() { |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 28 | RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) |
| 29 | RegisterTopDownMutator("defaults", defaultsMutator) |
| 30 | |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 31 | RegisterBottomUpMutator("host_or_device", HostOrDeviceMutator) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 32 | RegisterBottomUpMutator("host_type", HostTypeMutator) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 33 | RegisterBottomUpMutator("arch", ArchMutator) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 36 | var ( |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 37 | Arm = newArch("arm", "lib32") |
| 38 | Arm64 = newArch("arm64", "lib64") |
| 39 | Mips = newArch("mips", "lib32") |
| 40 | Mips64 = newArch("mips64", "lib64") |
| 41 | X86 = newArch("x86", "lib32") |
| 42 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 43 | |
| 44 | Common = ArchType{ |
| 45 | Name: "common", |
| 46 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 47 | ) |
| 48 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 49 | var archTypeMap = map[string]ArchType{ |
| 50 | "arm": Arm, |
| 51 | "arm64": Arm64, |
| 52 | "mips": Mips, |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 53 | "mips64": Mips64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 54 | "x86": X86, |
| 55 | "x86_64": X86_64, |
| 56 | } |
| 57 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 58 | /* |
| 59 | Example blueprints file containing all variant property groups, with comment listing what type |
| 60 | of variants get properties in that group: |
| 61 | |
| 62 | module { |
| 63 | arch: { |
| 64 | arm: { |
| 65 | // Host or device variants with arm architecture |
| 66 | }, |
| 67 | arm64: { |
| 68 | // Host or device variants with arm64 architecture |
| 69 | }, |
| 70 | mips: { |
| 71 | // Host or device variants with mips architecture |
| 72 | }, |
| 73 | mips64: { |
| 74 | // Host or device variants with mips64 architecture |
| 75 | }, |
| 76 | x86: { |
| 77 | // Host or device variants with x86 architecture |
| 78 | }, |
| 79 | x86_64: { |
| 80 | // Host or device variants with x86_64 architecture |
| 81 | }, |
| 82 | }, |
| 83 | multilib: { |
| 84 | lib32: { |
| 85 | // Host or device variants for 32-bit architectures |
| 86 | }, |
| 87 | lib64: { |
| 88 | // Host or device variants for 64-bit architectures |
| 89 | }, |
| 90 | }, |
| 91 | target: { |
| 92 | android: { |
| 93 | // Device variants |
| 94 | }, |
| 95 | host: { |
| 96 | // Host variants |
| 97 | }, |
| 98 | linux: { |
| 99 | // Linux host variants |
| 100 | }, |
| 101 | darwin: { |
| 102 | // Darwin host variants |
| 103 | }, |
| 104 | windows: { |
| 105 | // Windows host variants |
| 106 | }, |
| 107 | not_windows: { |
| 108 | // Non-windows host variants |
| 109 | }, |
| 110 | }, |
| 111 | } |
| 112 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 113 | |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 114 | type Embed interface{} |
| 115 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 116 | type archProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 117 | // Properties to vary by target architecture |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 118 | Arch struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 119 | // Properties for module variants being built to run on arm (host or device) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 120 | Arm struct { |
| 121 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 122 | |
| 123 | // Arm arch variants |
| 124 | Armv5te interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 125 | Armv7_a interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 126 | Armv7_a_neon interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 127 | |
| 128 | // Arm cpu variants |
| 129 | Cortex_a7 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 130 | Cortex_a8 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 131 | Cortex_a9 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 132 | Cortex_a15 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 133 | Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 134 | Cortex_a53_a57 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 135 | Krait interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 136 | Denver interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 137 | } |
| 138 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 139 | // Properties for module variants being built to run on arm64 (host or device) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 140 | Arm64 struct { |
| 141 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 142 | |
| 143 | // Arm64 arch variants |
| 144 | Armv8_a interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 145 | |
| 146 | // Arm64 cpu variants |
| 147 | Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 148 | Denver64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 149 | } |
| 150 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 151 | // Properties for module variants being built to run on mips (host or device) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 152 | Mips struct { |
| 153 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 154 | |
| 155 | // Mips arch variants |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 156 | Mips32_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 157 | Mips32r2_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 158 | Mips32r2_fp_xburst interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 159 | Mips32r2dsp_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 160 | Mips32r2dspr2_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 161 | Mips32r6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 162 | |
| 163 | // Mips arch features |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 164 | Rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 165 | } |
| 166 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 167 | // Properties for module variants being built to run on mips64 (host or device) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 168 | Mips64 struct { |
| 169 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 170 | |
| 171 | // Mips64 arch variants |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 172 | Mips64r2 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 173 | Mips64r6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 174 | |
| 175 | // Mips64 arch features |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 176 | Rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 177 | } |
| 178 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 179 | // Properties for module variants being built to run on x86 (host or device) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 180 | X86 struct { |
| 181 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 182 | |
| 183 | // X86 arch variants |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 184 | Atom interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 185 | Haswell interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 186 | Ivybridge interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 187 | Sandybridge interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 188 | Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 189 | |
| 190 | // X86 arch features |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 191 | Ssse3 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 192 | Sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 193 | Sse4_1 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 194 | Sse4_2 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 195 | Aes_ni interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 196 | Avx interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 197 | Popcnt interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 198 | Movbe interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 201 | // Properties for module variants being built to run on x86_64 (host or device) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 202 | X86_64 struct { |
| 203 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 204 | |
| 205 | // X86 arch variants |
| 206 | Haswell interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 207 | Ivybridge interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 208 | Sandybridge interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 209 | Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 210 | |
| 211 | // X86 arch features |
| 212 | Ssse3 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 213 | Sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 214 | Sse4_1 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 215 | Sse4_2 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 216 | Aes_ni interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 217 | Avx interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 218 | Popcnt interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 219 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 220 | } |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 221 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 222 | // Properties to vary by 32-bit or 64-bit |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 223 | Multilib struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 224 | // Properties for module variants being built to run on 32-bit devices |
| 225 | Lib32 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 226 | // Properties for module variants being built to run on 64-bit devices |
| 227 | Lib64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 228 | } |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 229 | // Properties to vary by build target (host or device, os, os+archictecture) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 230 | Target struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 231 | // Properties for module variants being built to run on the host |
| 232 | Host interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 233 | // Properties for module variants being built to run on the device |
| 234 | Android interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 235 | // Properties for module variants being built to run on arm devices |
| 236 | Android_arm interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 237 | // Properties for module variants being built to run on arm64 devices |
| 238 | Android_arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 239 | // Properties for module variants being built to run on mips devices |
| 240 | Android_mips interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 241 | // Properties for module variants being built to run on mips64 devices |
| 242 | Android_mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 243 | // Properties for module variants being built to run on x86 devices |
| 244 | Android_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 245 | // Properties for module variants being built to run on x86_64 devices |
| 246 | Android_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 247 | // Properties for module variants being built to run on devices that support 64-bit |
| 248 | Android64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 249 | // Properties for module variants being built to run on devices that do not support 64-bit |
| 250 | Android32 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 251 | // Properties for module variants being built to run on linux hosts |
| 252 | Linux interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 253 | // Properties for module variants being built to run on linux x86 hosts |
| 254 | Linux_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 255 | // Properties for module variants being built to run on linux x86_64 hosts |
| 256 | Linux_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 257 | // Properties for module variants being built to run on darwin hosts |
| 258 | Darwin interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 259 | // Properties for module variants being built to run on darwin x86 hosts |
| 260 | Darwin_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 261 | // Properties for module variants being built to run on darwin x86_64 hosts |
| 262 | Darwin_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 263 | // Properties for module variants being built to run on windows hosts |
| 264 | Windows interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 265 | // Properties for module variants being built to run on windows x86 hosts |
| 266 | Windows_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 267 | // Properties for module variants being built to run on linux or darwin hosts |
| 268 | Not_windows interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 272 | var archFeatureMap = map[ArchType]map[string][]string{} |
| 273 | |
| 274 | func RegisterArchFeatures(arch ArchType, variant string, features ...string) { |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 275 | archField := proptools.FieldNameForProperty(arch.Name) |
| 276 | variantField := proptools.FieldNameForProperty(variant) |
| 277 | archStruct := reflect.ValueOf(archProperties{}.Arch).FieldByName(archField) |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 278 | if variant != "" { |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 279 | if !archStruct.FieldByName(variantField).IsValid() { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 280 | panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch)) |
| 281 | } |
| 282 | } |
| 283 | for _, feature := range features { |
| 284 | field := proptools.FieldNameForProperty(feature) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 285 | if !archStruct.FieldByName(field).IsValid() { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 286 | panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant)) |
| 287 | } |
| 288 | } |
| 289 | if archFeatureMap[arch] == nil { |
| 290 | archFeatureMap[arch] = make(map[string][]string) |
| 291 | } |
| 292 | archFeatureMap[arch][variant] = features |
| 293 | } |
| 294 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 295 | // An Arch indicates a single CPU architecture. |
| 296 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 297 | ArchType ArchType |
| 298 | ArchVariant string |
| 299 | CpuVariant string |
| 300 | Abi []string |
| 301 | ArchFeatures []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 305 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 306 | if a.ArchVariant != "" { |
| 307 | s += "_" + a.ArchVariant |
| 308 | } |
| 309 | if a.CpuVariant != "" { |
| 310 | s += "_" + a.CpuVariant |
| 311 | } |
| 312 | return s |
| 313 | } |
| 314 | |
| 315 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 316 | Name string |
| 317 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 320 | func newArch(name, multilib string) ArchType { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 321 | return ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 322 | Name: name, |
| 323 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | func (a ArchType) String() string { |
| 328 | return a.Name |
| 329 | } |
| 330 | |
| 331 | type HostOrDeviceSupported int |
| 332 | |
| 333 | const ( |
| 334 | _ HostOrDeviceSupported = iota |
| 335 | HostSupported |
| 336 | DeviceSupported |
| 337 | HostAndDeviceSupported |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 338 | HostAndDeviceDefault |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 339 | ) |
| 340 | |
| 341 | type HostOrDevice int |
| 342 | |
| 343 | const ( |
| 344 | _ HostOrDevice = iota |
| 345 | Host |
| 346 | Device |
| 347 | ) |
| 348 | |
| 349 | func (hod HostOrDevice) String() string { |
| 350 | switch hod { |
| 351 | case Device: |
| 352 | return "device" |
| 353 | case Host: |
| 354 | return "host" |
| 355 | default: |
| 356 | panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod)) |
| 357 | } |
| 358 | } |
| 359 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 360 | func (hod HostOrDevice) Property() string { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 361 | switch hod { |
| 362 | case Device: |
| 363 | return "android" |
| 364 | case Host: |
| 365 | return "host" |
| 366 | default: |
| 367 | panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod)) |
| 368 | } |
| 369 | } |
| 370 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 371 | func (hod HostOrDevice) Host() bool { |
| 372 | if hod == 0 { |
| 373 | panic("HostOrDevice unset") |
| 374 | } |
| 375 | return hod == Host |
| 376 | } |
| 377 | |
| 378 | func (hod HostOrDevice) Device() bool { |
| 379 | if hod == 0 { |
| 380 | panic("HostOrDevice unset") |
| 381 | } |
| 382 | return hod == Device |
| 383 | } |
| 384 | |
| 385 | var hostOrDeviceName = map[HostOrDevice]string{ |
| 386 | Device: "device", |
| 387 | Host: "host", |
| 388 | } |
| 389 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 390 | type HostType int |
| 391 | |
| 392 | const ( |
| 393 | NoHostType HostType = iota |
| 394 | Linux |
| 395 | Darwin |
| 396 | Windows |
| 397 | ) |
| 398 | |
| 399 | func CurrentHostType() HostType { |
| 400 | switch runtime.GOOS { |
| 401 | case "linux": |
| 402 | return Linux |
| 403 | case "darwin": |
| 404 | return Darwin |
| 405 | default: |
| 406 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | func (ht HostType) String() string { |
| 411 | switch ht { |
| 412 | case Linux: |
| 413 | return "linux" |
| 414 | case Darwin: |
| 415 | return "darwin" |
| 416 | case Windows: |
| 417 | return "windows" |
| 418 | default: |
| 419 | panic(fmt.Sprintf("unexpected HostType value %d", ht)) |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func (ht HostType) Field() string { |
| 424 | switch ht { |
| 425 | case Linux: |
| 426 | return "Linux" |
| 427 | case Darwin: |
| 428 | return "Darwin" |
| 429 | case Windows: |
| 430 | return "Windows" |
| 431 | default: |
| 432 | panic(fmt.Sprintf("unexpected HostType value %d", ht)) |
| 433 | } |
| 434 | } |
| 435 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 436 | var ( |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 437 | commonArch = Arch{ |
| 438 | ArchType: Common, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 439 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 440 | ) |
| 441 | |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 442 | func HostOrDeviceMutator(mctx AndroidBottomUpMutatorContext) { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 443 | var module AndroidModule |
| 444 | var ok bool |
| 445 | if module, ok = mctx.Module().(AndroidModule); !ok { |
| 446 | return |
| 447 | } |
| 448 | |
| 449 | hods := []HostOrDevice{} |
| 450 | |
| 451 | if module.base().HostSupported() { |
| 452 | hods = append(hods, Host) |
| 453 | } |
| 454 | |
| 455 | if module.base().DeviceSupported() { |
| 456 | hods = append(hods, Device) |
| 457 | } |
| 458 | |
| 459 | if len(hods) == 0 { |
| 460 | return |
| 461 | } |
| 462 | |
| 463 | hodNames := []string{} |
| 464 | for _, hod := range hods { |
| 465 | hodNames = append(hodNames, hod.String()) |
| 466 | } |
| 467 | |
| 468 | modules := mctx.CreateVariations(hodNames...) |
| 469 | for i, m := range modules { |
| 470 | m.(AndroidModule).base().SetHostOrDevice(hods[i]) |
| 471 | } |
| 472 | } |
| 473 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 474 | func HostTypeMutator(mctx AndroidBottomUpMutatorContext) { |
| 475 | var module AndroidModule |
| 476 | var ok bool |
| 477 | if module, ok = mctx.Module().(AndroidModule); !ok { |
| 478 | return |
| 479 | } |
| 480 | |
| 481 | if !module.base().HostSupported() || !module.base().HostOrDevice().Host() { |
| 482 | return |
| 483 | } |
| 484 | |
| 485 | buildTypes, err := decodeHostTypesProductVariables(mctx.Config().(Config).ProductVariables) |
| 486 | if err != nil { |
| 487 | mctx.ModuleErrorf("%s", err.Error()) |
| 488 | return |
| 489 | } |
| 490 | |
| 491 | typeNames := []string{} |
| 492 | for _, ht := range buildTypes { |
| 493 | typeNames = append(typeNames, ht.String()) |
| 494 | } |
| 495 | |
| 496 | modules := mctx.CreateVariations(typeNames...) |
| 497 | for i, m := range modules { |
| 498 | m.(AndroidModule).base().SetHostType(buildTypes[i]) |
| 499 | } |
| 500 | } |
| 501 | |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 502 | func ArchMutator(mctx AndroidBottomUpMutatorContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 503 | var module AndroidModule |
| 504 | var ok bool |
| 505 | if module, ok = mctx.Module().(AndroidModule); !ok { |
| 506 | return |
| 507 | } |
| 508 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 509 | moduleArches := []Arch{} |
| 510 | multilib := module.base().commonProperties.Compile_multilib |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 511 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 512 | if module.base().HostSupported() && module.base().HostOrDevice().Host() { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 513 | hostModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).HostArches[module.base().HostType()]) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 514 | if err != nil { |
| 515 | mctx.ModuleErrorf("%s", err.Error()) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 516 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 517 | |
| 518 | moduleArches = append(moduleArches, hostModuleArches...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 521 | if module.base().DeviceSupported() && module.base().HostOrDevice().Device() { |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 522 | deviceModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).DeviceArches) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 523 | if err != nil { |
| 524 | mctx.ModuleErrorf("%s", err.Error()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 525 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 526 | |
| 527 | moduleArches = append(moduleArches, deviceModuleArches...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 530 | if len(moduleArches) == 0 { |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 531 | return |
| 532 | } |
| 533 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 534 | archNames := []string{} |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 535 | for _, arch := range moduleArches { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 536 | archNames = append(archNames, arch.String()) |
| 537 | } |
| 538 | |
| 539 | modules := mctx.CreateVariations(archNames...) |
| 540 | |
| 541 | for i, m := range modules { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 542 | m.(AndroidModule).base().SetArch(moduleArches[i]) |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 543 | m.(AndroidModule).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 547 | func InitArchModule(m AndroidModule, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 548 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 549 | |
| 550 | base := m.base() |
| 551 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 552 | base.generalProperties = append(base.generalProperties, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 553 | propertyStructs...) |
| 554 | |
| 555 | for _, properties := range base.generalProperties { |
| 556 | propertiesValue := reflect.ValueOf(properties) |
| 557 | if propertiesValue.Kind() != reflect.Ptr { |
| 558 | panic("properties must be a pointer to a struct") |
| 559 | } |
| 560 | |
| 561 | propertiesValue = propertiesValue.Elem() |
| 562 | if propertiesValue.Kind() != reflect.Struct { |
| 563 | panic("properties must be a pointer to a struct") |
| 564 | } |
| 565 | |
| 566 | archProperties := &archProperties{} |
| 567 | forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) { |
Colin Cross | 3ab7d88 | 2015-05-19 13:03:01 -0700 | [diff] [blame] | 568 | newValue := proptools.CloneEmptyProperties(propertiesValue) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 569 | v.Set(newValue) |
| 570 | }) |
| 571 | |
| 572 | base.archProperties = append(base.archProperties, archProperties) |
| 573 | } |
| 574 | |
| 575 | var allProperties []interface{} |
| 576 | allProperties = append(allProperties, base.generalProperties...) |
| 577 | for _, asp := range base.archProperties { |
| 578 | allProperties = append(allProperties, asp) |
| 579 | } |
| 580 | |
| 581 | return m, allProperties |
| 582 | } |
| 583 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 584 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 585 | |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 586 | func (a *AndroidModuleBase) appendProperties(ctx AndroidBottomUpMutatorContext, |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 587 | dst, src interface{}, field, srcPrefix string) interface{} { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 588 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 589 | srcField := reflect.ValueOf(src).FieldByName(field) |
| 590 | if !srcField.IsValid() { |
| 591 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 592 | return nil |
| 593 | } |
| 594 | |
| 595 | ret := srcField |
| 596 | |
| 597 | if srcField.Kind() == reflect.Struct { |
| 598 | srcField = srcField.FieldByName("Embed") |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | src = srcField.Elem().Interface() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 602 | |
| 603 | filter := func(property string, |
| 604 | dstField, srcField reflect.StructField, |
| 605 | dstValue, srcValue interface{}) (bool, error) { |
| 606 | |
| 607 | srcProperty := srcPrefix + "." + property |
| 608 | |
| 609 | if !proptools.HasTag(dstField, "android", "arch_variant") { |
| 610 | if ctx.ContainsProperty(srcProperty) { |
| 611 | return false, fmt.Errorf("can't be specific to a build variant") |
| 612 | } else { |
| 613 | return false, nil |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | return true, nil |
| 618 | } |
| 619 | |
| 620 | err := proptools.AppendProperties(dst, src, filter) |
| 621 | if err != nil { |
| 622 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 623 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 624 | } else { |
| 625 | panic(err) |
| 626 | } |
| 627 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 628 | |
| 629 | return ret.Interface() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 632 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 633 | func (a *AndroidModuleBase) setArchProperties(ctx AndroidBottomUpMutatorContext) { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 634 | arch := a.commonProperties.CompileArch |
| 635 | hod := a.commonProperties.CompileHostOrDevice |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 636 | ht := a.commonProperties.CompileHostType |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 637 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 638 | if arch.ArchType == Common { |
| 639 | return |
| 640 | } |
| 641 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 642 | for i := range a.generalProperties { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 643 | genProps := a.generalProperties[i] |
| 644 | archProps := a.archProperties[i] |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 645 | // Handle arch-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 646 | // arch: { |
| 647 | // arm64: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 648 | // key: value, |
| 649 | // }, |
| 650 | // }, |
| 651 | t := arch.ArchType |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 652 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 653 | field := proptools.FieldNameForProperty(t.Name) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 654 | prefix := "arch." + t.Name |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 655 | archStruct := a.appendProperties(ctx, genProps, archProps.Arch, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 656 | |
| 657 | // Handle arch-variant-specific properties in the form: |
| 658 | // arch: { |
| 659 | // variant: { |
| 660 | // key: value, |
| 661 | // }, |
| 662 | // }, |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 663 | v := variantReplacer.Replace(arch.ArchVariant) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 664 | if v != "" { |
| 665 | field := proptools.FieldNameForProperty(v) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 666 | prefix := "arch." + t.Name + "." + v |
| 667 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | // Handle cpu-variant-specific properties in the form: |
| 671 | // arch: { |
| 672 | // variant: { |
| 673 | // key: value, |
| 674 | // }, |
| 675 | // }, |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 676 | c := variantReplacer.Replace(arch.CpuVariant) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 677 | if c != "" { |
| 678 | field := proptools.FieldNameForProperty(c) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 679 | prefix := "arch." + t.Name + "." + c |
| 680 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 681 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 682 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 683 | // Handle arch-feature-specific properties in the form: |
| 684 | // arch: { |
| 685 | // feature: { |
| 686 | // key: value, |
| 687 | // }, |
| 688 | // }, |
| 689 | for _, feature := range arch.ArchFeatures { |
| 690 | field := proptools.FieldNameForProperty(feature) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 691 | prefix := "arch." + t.Name + "." + feature |
| 692 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 693 | } |
| 694 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 695 | // Handle multilib-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 696 | // multilib: { |
| 697 | // lib32: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 698 | // key: value, |
| 699 | // }, |
| 700 | // }, |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 701 | field = proptools.FieldNameForProperty(t.Multilib) |
| 702 | prefix = "multilib." + t.Multilib |
| 703 | a.appendProperties(ctx, genProps, archProps.Multilib, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 704 | |
| 705 | // Handle host-or-device-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 706 | // target: { |
| 707 | // host: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 708 | // key: value, |
| 709 | // }, |
| 710 | // }, |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 711 | hodProperty := hod.Property() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 712 | field = proptools.FieldNameForProperty(hodProperty) |
| 713 | prefix = "target." + hodProperty |
| 714 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 715 | |
| 716 | // Handle host target properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 717 | // target: { |
| 718 | // linux: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 719 | // key: value, |
| 720 | // }, |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 721 | // not_windows: { |
| 722 | // key: value, |
| 723 | // }, |
| 724 | // linux_x86: { |
| 725 | // key: value, |
| 726 | // }, |
| 727 | // linux_arm: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 728 | // key: value, |
| 729 | // }, |
| 730 | // }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 731 | if hod.Host() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 732 | field := ht.Field() |
| 733 | prefix := "target." + ht.String() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 734 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 735 | |
| 736 | t := arch.ArchType |
| 737 | field = ht.Field() + "_" + t.Name |
| 738 | prefix = "target." + ht.String() + "_" + t.Name |
| 739 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
| 740 | |
| 741 | if ht != Windows { |
| 742 | field := "Not_windows" |
| 743 | prefix := "target.not_windows" |
| 744 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
| 745 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 748 | // Handle 64-bit device properties in the form: |
| 749 | // target { |
| 750 | // android64 { |
| 751 | // key: value, |
| 752 | // }, |
| 753 | // android32 { |
| 754 | // key: value, |
| 755 | // }, |
| 756 | // }, |
| 757 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 758 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 759 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 760 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 761 | if hod.Device() { |
| 762 | if true /* && target_is_64_bit */ { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 763 | field := "Android64" |
| 764 | prefix := "target.android64" |
| 765 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 766 | } else { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 767 | field := "Android32" |
| 768 | prefix := "target.android32" |
| 769 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 770 | } |
| 771 | } |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 772 | |
| 773 | // Handle device architecture properties in the form: |
| 774 | // target { |
| 775 | // android_arm { |
| 776 | // key: value, |
| 777 | // }, |
| 778 | // android_x86 { |
| 779 | // key: value, |
| 780 | // }, |
| 781 | // }, |
| 782 | if hod.Device() { |
| 783 | t := arch.ArchType |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 784 | field := "Android_" + t.Name |
| 785 | prefix := "target.android_" + t.Name |
| 786 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 789 | if ctx.Failed() { |
| 790 | return |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 796 | switch v.Kind() { |
| 797 | case reflect.Interface: |
| 798 | f(v) |
| 799 | case reflect.Struct: |
| 800 | for i := 0; i < v.NumField(); i++ { |
| 801 | forEachInterface(v.Field(i), f) |
| 802 | } |
| 803 | case reflect.Ptr: |
| 804 | forEachInterface(v.Elem(), f) |
| 805 | default: |
| 806 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 807 | } |
| 808 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 809 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 810 | // Get a list of HostTypes from the product variables |
| 811 | func decodeHostTypesProductVariables(variables productVariables) ([]HostType, error) { |
| 812 | ret := []HostType{CurrentHostType()} |
| 813 | |
| 814 | if variables.CrossHost != nil && *variables.CrossHost != "" { |
| 815 | switch *variables.CrossHost { |
| 816 | case "windows": |
| 817 | ret = append(ret, Windows) |
| 818 | default: |
| 819 | return nil, fmt.Errorf("Unsupported secondary host: %s", *variables.CrossHost) |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | return ret, nil |
| 824 | } |
| 825 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 826 | // Convert the arch product variables into a list of host and device Arch structs |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 827 | func decodeArchProductVariables(variables productVariables) (map[HostType][]Arch, []Arch, error) { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 828 | if variables.HostArch == nil { |
| 829 | return nil, nil, fmt.Errorf("No host primary architecture set") |
| 830 | } |
| 831 | |
| 832 | hostArch, err := decodeArch(*variables.HostArch, nil, nil, nil) |
| 833 | if err != nil { |
| 834 | return nil, nil, err |
| 835 | } |
| 836 | |
| 837 | hostArches := []Arch{hostArch} |
| 838 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 839 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 840 | hostSecondaryArch, err := decodeArch(*variables.HostSecondaryArch, nil, nil, nil) |
| 841 | if err != nil { |
| 842 | return nil, nil, err |
| 843 | } |
| 844 | hostArches = append(hostArches, hostSecondaryArch) |
| 845 | } |
| 846 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 847 | hostTypeArches := map[HostType][]Arch{ |
| 848 | CurrentHostType(): hostArches, |
| 849 | } |
| 850 | |
| 851 | if variables.CrossHost != nil && *variables.CrossHost != "" { |
| 852 | if variables.CrossHostArch == nil || *variables.CrossHostArch == "" { |
| 853 | return nil, nil, fmt.Errorf("No cross-host primary architecture set") |
| 854 | } |
| 855 | |
| 856 | crossHostArch, err := decodeArch(*variables.CrossHostArch, nil, nil, nil) |
| 857 | if err != nil { |
| 858 | return nil, nil, err |
| 859 | } |
| 860 | |
| 861 | crossHostArches := []Arch{crossHostArch} |
| 862 | |
| 863 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
| 864 | crossHostSecondaryArch, err := decodeArch(*variables.CrossHostSecondaryArch, nil, nil, nil) |
| 865 | if err != nil { |
| 866 | return nil, nil, err |
| 867 | } |
| 868 | crossHostArches = append(crossHostArches, crossHostSecondaryArch) |
| 869 | } |
| 870 | |
| 871 | switch *variables.CrossHost { |
| 872 | case "windows": |
| 873 | hostTypeArches[Windows] = crossHostArches |
| 874 | default: |
| 875 | return nil, nil, fmt.Errorf("Unsupported cross-host: %s", *variables.CrossHost) |
| 876 | } |
| 877 | } |
| 878 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 879 | if variables.DeviceArch == nil { |
| 880 | return nil, nil, fmt.Errorf("No device primary architecture set") |
| 881 | } |
| 882 | |
| 883 | deviceArch, err := decodeArch(*variables.DeviceArch, variables.DeviceArchVariant, |
| 884 | variables.DeviceCpuVariant, variables.DeviceAbi) |
| 885 | if err != nil { |
| 886 | return nil, nil, err |
| 887 | } |
| 888 | |
| 889 | deviceArches := []Arch{deviceArch} |
| 890 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 891 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 892 | deviceSecondaryArch, err := decodeArch(*variables.DeviceSecondaryArch, |
| 893 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 894 | variables.DeviceSecondaryAbi) |
| 895 | if err != nil { |
| 896 | return nil, nil, err |
| 897 | } |
| 898 | deviceArches = append(deviceArches, deviceSecondaryArch) |
| 899 | } |
| 900 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 901 | return hostTypeArches, deviceArches, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame^] | 904 | func decodeMegaDevice() ([]Arch, error) { |
| 905 | archSettings := []struct { |
| 906 | arch string |
| 907 | archVariant string |
| 908 | cpuVariant string |
| 909 | abi []string |
| 910 | }{ |
| 911 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 912 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
| 913 | // gtest_all_test.cc fails to build: |
| 914 | // error in backend: Unsupported library call operation! |
| 915 | //{"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
| 916 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 917 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 918 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
| 919 | {"arm", "armv7-a-neon", "denver", []string{"armeabi-v7a"}}, |
| 920 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
| 921 | {"arm64", "", "cortex-a53", []string{"arm64-v8a"}}, |
| 922 | {"arm64", "", "denver64", []string{"arm64-v8a"}}, |
| 923 | // mips is missing __popcountsi2 from libc |
| 924 | //{"mips", "mips32-fp", "", []string{"mips"}}, |
| 925 | //{"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 926 | //{"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
| 927 | //{"mips", "mips32r6", "", []string{"mips32r6"}}, |
| 928 | // mips32r2dsp[r2]-fp also fails in the assembler for dmisc.c in libc: |
| 929 | // Error: invalid operands `mtlo $ac0,$8' |
| 930 | // Error: invalid operands `mthi $ac0,$3' |
| 931 | //{"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 932 | //{"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
| 933 | // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc |
| 934 | //{"mips64", "mips64r2", "", []string{"mips64"}}, |
| 935 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 936 | {"x86", "", "", []string{"x86"}}, |
| 937 | {"x86", "atom", "", []string{"x86"}}, |
| 938 | {"x86", "haswell", "", []string{"x86"}}, |
| 939 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 940 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 941 | {"x86", "silvermont", "", []string{"x86"}}, |
| 942 | {"x86_64", "", "", []string{"x86_64"}}, |
| 943 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 944 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 945 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 946 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
| 947 | } |
| 948 | |
| 949 | var ret []Arch |
| 950 | |
| 951 | for _, config := range archSettings { |
| 952 | arch, err := decodeArch(config.arch, &config.archVariant, |
| 953 | &config.cpuVariant, &config.abi) |
| 954 | if err != nil { |
| 955 | return nil, err |
| 956 | } |
| 957 | ret = append(ret, arch) |
| 958 | } |
| 959 | |
| 960 | return ret, nil |
| 961 | } |
| 962 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 963 | // Convert a set of strings from product variables into a single Arch struct |
| 964 | func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) { |
| 965 | stringPtr := func(p *string) string { |
| 966 | if p != nil { |
| 967 | return *p |
| 968 | } |
| 969 | return "" |
| 970 | } |
| 971 | |
| 972 | slicePtr := func(p *[]string) []string { |
| 973 | if p != nil { |
| 974 | return *p |
| 975 | } |
| 976 | return nil |
| 977 | } |
| 978 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 979 | archType, ok := archTypeMap[arch] |
| 980 | if !ok { |
| 981 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 982 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 983 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 984 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 985 | ArchType: archType, |
| 986 | ArchVariant: stringPtr(archVariant), |
| 987 | CpuVariant: stringPtr(cpuVariant), |
| 988 | Abi: slicePtr(abi), |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 992 | a.ArchVariant = "" |
| 993 | } |
| 994 | |
| 995 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 996 | a.CpuVariant = "" |
| 997 | } |
| 998 | |
| 999 | for i := 0; i < len(a.Abi); i++ { |
| 1000 | if a.Abi[i] == "" { |
| 1001 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1002 | i-- |
| 1003 | } |
| 1004 | } |
| 1005 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1006 | if featureMap, ok := archFeatureMap[archType]; ok { |
| 1007 | a.ArchFeatures = featureMap[stringPtr(archVariant)] |
| 1008 | } |
| 1009 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1010 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | // Use the module multilib setting to select one or more arches from an arch list |
| 1014 | func decodeMultilib(multilib string, arches []Arch) ([]Arch, error) { |
| 1015 | buildArches := []Arch{} |
| 1016 | switch multilib { |
| 1017 | case "common": |
| 1018 | buildArches = append(buildArches, commonArch) |
| 1019 | case "both": |
| 1020 | buildArches = append(buildArches, arches...) |
| 1021 | case "first": |
| 1022 | buildArches = append(buildArches, arches[0]) |
| 1023 | case "32": |
| 1024 | for _, a := range arches { |
| 1025 | if a.ArchType.Multilib == "lib32" { |
| 1026 | buildArches = append(buildArches, a) |
| 1027 | } |
| 1028 | } |
| 1029 | case "64": |
| 1030 | for _, a := range arches { |
| 1031 | if a.ArchType.Multilib == "lib64" { |
| 1032 | buildArches = append(buildArches, a) |
| 1033 | } |
| 1034 | } |
| 1035 | default: |
| 1036 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`, |
| 1037 | multilib) |
| 1038 | //buildArches = append(buildArches, arches[0]) |
| 1039 | } |
| 1040 | |
| 1041 | return buildArches, nil |
| 1042 | } |