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 | 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("arch", ArchMutator) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 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, |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 51 | "mips64": Mips64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 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 | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 112 | type Embed interface{} |
| 113 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 114 | type archProperties struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 115 | // Properties to vary by target architecture |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 116 | Arch struct { |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 117 | // 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] | 118 | Arm struct { |
| 119 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 120 | |
| 121 | // Arm arch variants |
| 122 | Armv5te interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 123 | Armv7_a interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 124 | Armv7_a_neon interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 125 | |
| 126 | // Arm cpu variants |
| 127 | Cortex_a7 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 128 | Cortex_a8 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 129 | Cortex_a9 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 130 | Cortex_a15 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 131 | Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 132 | Cortex_a53_a57 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 133 | Krait interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 134 | Denver interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 135 | } |
| 136 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 137 | // 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] | 138 | Arm64 struct { |
| 139 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 140 | |
| 141 | // Arm64 arch variants |
| 142 | Armv8_a interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 143 | |
| 144 | // Arm64 cpu variants |
| 145 | Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 146 | Denver64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 147 | } |
| 148 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 149 | // 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] | 150 | Mips struct { |
| 151 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 152 | |
| 153 | // Mips arch variants |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 154 | Mips32_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 155 | Mips32r2_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 156 | Mips32r2_fp_xburst interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 157 | Mips32r2dsp_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 158 | Mips32r2dspr2_fp interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 159 | Mips32r6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 160 | |
| 161 | // Mips arch features |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 162 | Rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 163 | } |
| 164 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 165 | // 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] | 166 | Mips64 struct { |
| 167 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 168 | |
| 169 | // Mips64 arch variants |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 170 | Mips64r2 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 171 | Mips64r6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 172 | |
| 173 | // Mips64 arch features |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 174 | Rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 175 | } |
| 176 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 177 | // 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] | 178 | X86 struct { |
| 179 | Embed `blueprint:"filter(android:\"arch_variant\")"` |
| 180 | |
| 181 | // X86 arch variants |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 182 | Atom interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 183 | Haswell interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 184 | Ivybridge interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 185 | Sandybridge interface{} `blueprint:"filter(android:\"arch_variant\")"` |
| 186 | Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 187 | // Generic variant for X86 on X86_64 |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 188 | X86_64 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\")"` |
Dan Willemsen | 07cd051 | 2016-02-03 23:16:33 -0800 | [diff] [blame] | 267 | // Properties for module variants being built to run on windows x86_64 hosts |
| 268 | Windows_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 269 | // Properties for module variants being built to run on linux or darwin hosts |
| 270 | Not_windows interface{} `blueprint:"filter(android:\"arch_variant\")"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 274 | var archFeatureMap = map[ArchType]map[string][]string{} |
| 275 | |
| 276 | func RegisterArchFeatures(arch ArchType, variant string, features ...string) { |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 277 | archField := proptools.FieldNameForProperty(arch.Name) |
| 278 | variantField := proptools.FieldNameForProperty(variant) |
| 279 | archStruct := reflect.ValueOf(archProperties{}.Arch).FieldByName(archField) |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 280 | if variant != "" { |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 281 | if !archStruct.FieldByName(variantField).IsValid() { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 282 | panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch)) |
| 283 | } |
| 284 | } |
| 285 | for _, feature := range features { |
| 286 | field := proptools.FieldNameForProperty(feature) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 287 | if !archStruct.FieldByName(field).IsValid() { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 288 | panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant)) |
| 289 | } |
| 290 | } |
| 291 | if archFeatureMap[arch] == nil { |
| 292 | archFeatureMap[arch] = make(map[string][]string) |
| 293 | } |
| 294 | archFeatureMap[arch][variant] = features |
| 295 | } |
| 296 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 297 | // An Arch indicates a single CPU architecture. |
| 298 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 299 | ArchType ArchType |
| 300 | ArchVariant string |
| 301 | CpuVariant string |
| 302 | Abi []string |
| 303 | ArchFeatures []string |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 304 | Native bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 308 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 309 | if a.ArchVariant != "" { |
| 310 | s += "_" + a.ArchVariant |
| 311 | } |
| 312 | if a.CpuVariant != "" { |
| 313 | s += "_" + a.CpuVariant |
| 314 | } |
| 315 | return s |
| 316 | } |
| 317 | |
| 318 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 319 | Name string |
| 320 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 323 | func newArch(name, multilib string) ArchType { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 324 | return ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 325 | Name: name, |
| 326 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | func (a ArchType) String() string { |
| 331 | return a.Name |
| 332 | } |
| 333 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 334 | var BuildOs = func() OsType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 335 | switch runtime.GOOS { |
| 336 | case "linux": |
| 337 | return Linux |
| 338 | case "darwin": |
| 339 | return Darwin |
| 340 | default: |
| 341 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 342 | } |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 343 | }() |
| 344 | |
| 345 | var ( |
| 346 | osTypeList []OsType |
| 347 | |
| 348 | NoOsType OsType |
| 349 | Linux = NewOsType("linux", Host) |
| 350 | Darwin = NewOsType("darwin", Host) |
| 351 | Windows = NewOsType("windows", HostCross) |
| 352 | Android = NewOsType("android", Device) |
| 353 | ) |
| 354 | |
| 355 | type OsType struct { |
| 356 | Name, Field string |
| 357 | Class OsClass |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 360 | type OsClass int |
| 361 | |
| 362 | const ( |
| 363 | Device OsClass = iota |
| 364 | Host |
| 365 | HostCross |
| 366 | ) |
| 367 | |
| 368 | func (os OsType) String() string { |
| 369 | return os.Name |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 372 | func NewOsType(name string, class OsClass) OsType { |
| 373 | os := OsType{ |
| 374 | Name: name, |
| 375 | Field: strings.Title(name), |
| 376 | Class: class, |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 377 | } |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 378 | osTypeList = append(osTypeList, os) |
| 379 | return os |
| 380 | } |
| 381 | |
| 382 | func osByName(name string) OsType { |
| 383 | for _, os := range osTypeList { |
| 384 | if os.Name == name { |
| 385 | return os |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 392 | var ( |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 393 | commonTarget = Target{ |
| 394 | Os: Android, |
| 395 | Arch: Arch{ |
| 396 | ArchType: Common, |
| 397 | }, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 398 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 399 | ) |
| 400 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 401 | type Target struct { |
| 402 | Os OsType |
| 403 | Arch Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 406 | func (target Target) String() string { |
| 407 | return target.Os.String() + "_" + target.Arch.String() |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 410 | func ArchMutator(mctx BottomUpMutatorContext) { |
| 411 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 412 | var ok bool |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 413 | if module, ok = mctx.Module().(Module); !ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 414 | return |
| 415 | } |
| 416 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 417 | osClasses := module.base().OsClassSupported() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 418 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 419 | if len(osClasses) == 0 { |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 420 | return |
| 421 | } |
| 422 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 423 | var moduleTargets []Target |
| 424 | |
| 425 | for _, class := range osClasses { |
| 426 | multilib := module.base().commonProperties.Compile_multilib |
| 427 | targets, err := decodeMultilib(multilib, mctx.AConfig().Targets[class]) |
| 428 | if err != nil { |
| 429 | mctx.ModuleErrorf("%s", err.Error()) |
| 430 | } |
| 431 | moduleTargets = append(moduleTargets, targets...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 434 | targetNames := make([]string, len(moduleTargets)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 435 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 436 | for i, target := range moduleTargets { |
| 437 | targetNames[i] = target.String() |
| 438 | } |
| 439 | |
| 440 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 441 | for i, m := range modules { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 442 | m.(Module).base().SetTarget(moduleTargets[i]) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 443 | m.(Module).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 447 | func InitArchModule(m Module, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 448 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 449 | |
| 450 | base := m.base() |
| 451 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 452 | base.generalProperties = append(base.generalProperties, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 453 | propertyStructs...) |
| 454 | |
| 455 | for _, properties := range base.generalProperties { |
| 456 | propertiesValue := reflect.ValueOf(properties) |
| 457 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 458 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 459 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | propertiesValue = propertiesValue.Elem() |
| 463 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 464 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 465 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | archProperties := &archProperties{} |
| 469 | forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) { |
Colin Cross | 3ab7d88 | 2015-05-19 13:03:01 -0700 | [diff] [blame] | 470 | newValue := proptools.CloneEmptyProperties(propertiesValue) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 471 | v.Set(newValue) |
| 472 | }) |
| 473 | |
| 474 | base.archProperties = append(base.archProperties, archProperties) |
| 475 | } |
| 476 | |
| 477 | var allProperties []interface{} |
| 478 | allProperties = append(allProperties, base.generalProperties...) |
| 479 | for _, asp := range base.archProperties { |
| 480 | allProperties = append(allProperties, asp) |
| 481 | } |
| 482 | |
| 483 | return m, allProperties |
| 484 | } |
| 485 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 486 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 487 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 488 | func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 489 | dst, src interface{}, field, srcPrefix string) interface{} { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 490 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 491 | srcField := reflect.ValueOf(src).FieldByName(field) |
| 492 | if !srcField.IsValid() { |
| 493 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 494 | return nil |
| 495 | } |
| 496 | |
| 497 | ret := srcField |
| 498 | |
| 499 | if srcField.Kind() == reflect.Struct { |
| 500 | srcField = srcField.FieldByName("Embed") |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | src = srcField.Elem().Interface() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 504 | |
| 505 | filter := func(property string, |
| 506 | dstField, srcField reflect.StructField, |
| 507 | dstValue, srcValue interface{}) (bool, error) { |
| 508 | |
| 509 | srcProperty := srcPrefix + "." + property |
| 510 | |
| 511 | if !proptools.HasTag(dstField, "android", "arch_variant") { |
| 512 | if ctx.ContainsProperty(srcProperty) { |
| 513 | return false, fmt.Errorf("can't be specific to a build variant") |
| 514 | } else { |
| 515 | return false, nil |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | return true, nil |
| 520 | } |
| 521 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 522 | order := func(property string, |
| 523 | dstField, srcField reflect.StructField, |
| 524 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 525 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 526 | return proptools.Prepend, nil |
| 527 | } else { |
| 528 | return proptools.Append, nil |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | err := proptools.ExtendProperties(dst, src, filter, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 533 | if err != nil { |
| 534 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 535 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 536 | } else { |
| 537 | panic(err) |
| 538 | } |
| 539 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 540 | |
| 541 | return ret.Interface() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 544 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 545 | func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 546 | arch := a.Arch() |
| 547 | os := a.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 548 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 549 | if arch.ArchType == Common { |
| 550 | return |
| 551 | } |
| 552 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 553 | for i := range a.generalProperties { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 554 | genProps := a.generalProperties[i] |
| 555 | archProps := a.archProperties[i] |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 556 | // Handle arch-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 557 | // arch: { |
| 558 | // arm64: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 559 | // key: value, |
| 560 | // }, |
| 561 | // }, |
| 562 | t := arch.ArchType |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 563 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 564 | field := proptools.FieldNameForProperty(t.Name) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 565 | prefix := "arch." + t.Name |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 566 | archStruct := a.appendProperties(ctx, genProps, archProps.Arch, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 567 | |
| 568 | // Handle arch-variant-specific properties in the form: |
| 569 | // arch: { |
| 570 | // variant: { |
| 571 | // key: value, |
| 572 | // }, |
| 573 | // }, |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 574 | v := variantReplacer.Replace(arch.ArchVariant) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 575 | if v != "" { |
| 576 | field := proptools.FieldNameForProperty(v) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 577 | prefix := "arch." + t.Name + "." + v |
| 578 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | // Handle cpu-variant-specific properties in the form: |
| 582 | // arch: { |
| 583 | // variant: { |
| 584 | // key: value, |
| 585 | // }, |
| 586 | // }, |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 587 | c := variantReplacer.Replace(arch.CpuVariant) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 588 | if c != "" { |
| 589 | field := proptools.FieldNameForProperty(c) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 590 | prefix := "arch." + t.Name + "." + c |
| 591 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 592 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 593 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 594 | // Handle arch-feature-specific properties in the form: |
| 595 | // arch: { |
| 596 | // feature: { |
| 597 | // key: value, |
| 598 | // }, |
| 599 | // }, |
| 600 | for _, feature := range arch.ArchFeatures { |
| 601 | field := proptools.FieldNameForProperty(feature) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 602 | prefix := "arch." + t.Name + "." + feature |
| 603 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 606 | // Handle multilib-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 607 | // multilib: { |
| 608 | // lib32: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 609 | // key: value, |
| 610 | // }, |
| 611 | // }, |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 612 | field = proptools.FieldNameForProperty(t.Multilib) |
| 613 | prefix = "multilib." + t.Multilib |
| 614 | a.appendProperties(ctx, genProps, archProps.Multilib, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 615 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 616 | // Handle host-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 617 | // target: { |
| 618 | // host: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 619 | // key: value, |
| 620 | // }, |
| 621 | // }, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 622 | if os.Class == Host || os.Class == HostCross { |
| 623 | field = "Host" |
| 624 | prefix = "target.host" |
| 625 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
| 626 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 627 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 628 | // Handle target OS properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 629 | // target: { |
| 630 | // linux: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 631 | // key: value, |
| 632 | // }, |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 633 | // not_windows: { |
| 634 | // key: value, |
| 635 | // }, |
| 636 | // linux_x86: { |
| 637 | // key: value, |
| 638 | // }, |
| 639 | // linux_arm: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 640 | // key: value, |
| 641 | // }, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 642 | // android { |
| 643 | // key: value, |
| 644 | // }, |
| 645 | // android_arm { |
| 646 | // key: value, |
| 647 | // }, |
| 648 | // android_x86 { |
| 649 | // key: value, |
| 650 | // }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 651 | // }, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 652 | // }, |
| 653 | field = os.Field |
| 654 | prefix = "target." + os.Name |
| 655 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 656 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 657 | field = os.Field + "_" + t.Name |
| 658 | prefix = "target." + os.Name + "_" + t.Name |
| 659 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 660 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 661 | if (os.Class == Host || os.Class == HostCross) && os != Windows { |
| 662 | field := "Not_windows" |
| 663 | prefix := "target.not_windows" |
| 664 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 667 | // Handle 64-bit device properties in the form: |
| 668 | // target { |
| 669 | // android64 { |
| 670 | // key: value, |
| 671 | // }, |
| 672 | // android32 { |
| 673 | // key: value, |
| 674 | // }, |
| 675 | // }, |
| 676 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 677 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 678 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 679 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 680 | if os.Class == Device { |
| 681 | if ctx.AConfig().Android64() { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 682 | field := "Android64" |
| 683 | prefix := "target.android64" |
| 684 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 685 | } else { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 686 | field := "Android32" |
| 687 | prefix := "target.android32" |
| 688 | a.appendProperties(ctx, genProps, archProps.Target, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
| 694 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 695 | switch v.Kind() { |
| 696 | case reflect.Interface: |
| 697 | f(v) |
| 698 | case reflect.Struct: |
| 699 | for i := 0; i < v.NumField(); i++ { |
| 700 | forEachInterface(v.Field(i), f) |
| 701 | } |
| 702 | case reflect.Ptr: |
| 703 | forEachInterface(v.Elem(), f) |
| 704 | default: |
| 705 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 706 | } |
| 707 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 708 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 709 | // Convert the arch product variables into a list of targets for each os class structs |
| 710 | func decodeTargetProductVariables(config Config) (map[OsClass][]Target, error) { |
| 711 | variables := config.ProductVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 712 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 713 | targets := make(map[OsClass][]Target) |
| 714 | var targetErr error |
| 715 | |
| 716 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi *[]string) { |
| 717 | if targetErr != nil { |
| 718 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 719 | } |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 720 | |
| 721 | arch, err := decodeArch(archName, archVariant, cpuVariant, abi) |
| 722 | if err != nil { |
| 723 | targetErr = err |
| 724 | return |
| 725 | } |
| 726 | |
| 727 | targets[os.Class] = append(targets[os.Class], |
| 728 | Target{ |
| 729 | Os: os, |
| 730 | Arch: arch, |
| 731 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 732 | } |
| 733 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 734 | if variables.HostArch == nil { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 735 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 738 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 739 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 740 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 741 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | if variables.CrossHost != nil && *variables.CrossHost != "" { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 745 | crossHostOs := osByName(*variables.CrossHost) |
| 746 | if crossHostOs == NoOsType { |
| 747 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 748 | } |
| 749 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 750 | if variables.CrossHostArch == nil || *variables.CrossHostArch == "" { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 751 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 754 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 755 | |
| 756 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 757 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 761 | if variables.DeviceArch == nil { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 762 | return nil, fmt.Errorf("No device primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 765 | addTarget(Android, *variables.DeviceArch, variables.DeviceArchVariant, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 766 | variables.DeviceCpuVariant, variables.DeviceAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 767 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 768 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 769 | addTarget(Android, *variables.DeviceSecondaryArch, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 770 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 771 | variables.DeviceSecondaryAbi) |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 772 | |
| 773 | deviceArches := targets[Device] |
| 774 | if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib { |
| 775 | deviceArches[1].Arch.Native = false |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 776 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 779 | if targetErr != nil { |
| 780 | return nil, targetErr |
| 781 | } |
| 782 | |
| 783 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 786 | func decodeMegaDevice() ([]Target, error) { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 787 | archSettings := []struct { |
| 788 | arch string |
| 789 | archVariant string |
| 790 | cpuVariant string |
| 791 | abi []string |
| 792 | }{ |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 793 | // armv5 is only used for unbundled apps |
| 794 | //{"arm", "armv5te", "", []string{"armeabi"}}, |
| 795 | {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}}, |
| 796 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 797 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 798 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 799 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 800 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 801 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 802 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
| 803 | {"arm", "armv7-a-neon", "denver", []string{"armeabi-v7a"}}, |
| 804 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 805 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
| 806 | {"arm64", "armv8-a", "denver64", []string{"arm64-v8a"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 807 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 808 | {"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 809 | {"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
Dan Willemsen | 66187d9 | 2016-05-05 13:15:00 -0700 | [diff] [blame] | 810 | {"mips", "mips32r6", "", []string{"mips"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 811 | // mips32r2dsp[r2]-fp fails in the assembler for divdf3.c in compiler-rt: |
| 812 | // (same errors in make and soong) |
| 813 | // Error: invalid operands `mtlo $ac0,$11' |
| 814 | // Error: invalid operands `mthi $ac0,$12' |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 815 | //{"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 816 | //{"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
| 817 | // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc |
| 818 | //{"mips64", "mips64r2", "", []string{"mips64"}}, |
| 819 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 820 | {"x86", "", "", []string{"x86"}}, |
| 821 | {"x86", "atom", "", []string{"x86"}}, |
| 822 | {"x86", "haswell", "", []string{"x86"}}, |
| 823 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 824 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 825 | {"x86", "silvermont", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 826 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 827 | {"x86_64", "", "", []string{"x86_64"}}, |
| 828 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 829 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 830 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 831 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
| 832 | } |
| 833 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 834 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 835 | |
| 836 | for _, config := range archSettings { |
| 837 | arch, err := decodeArch(config.arch, &config.archVariant, |
| 838 | &config.cpuVariant, &config.abi) |
| 839 | if err != nil { |
| 840 | return nil, err |
| 841 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 842 | arch.Native = false |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 843 | ret = append(ret, Target{ |
| 844 | Os: Android, |
| 845 | Arch: arch, |
| 846 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | return ret, nil |
| 850 | } |
| 851 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 852 | // Convert a set of strings from product variables into a single Arch struct |
| 853 | func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) { |
| 854 | stringPtr := func(p *string) string { |
| 855 | if p != nil { |
| 856 | return *p |
| 857 | } |
| 858 | return "" |
| 859 | } |
| 860 | |
| 861 | slicePtr := func(p *[]string) []string { |
| 862 | if p != nil { |
| 863 | return *p |
| 864 | } |
| 865 | return nil |
| 866 | } |
| 867 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 868 | archType, ok := archTypeMap[arch] |
| 869 | if !ok { |
| 870 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 871 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 872 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 873 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 874 | ArchType: archType, |
| 875 | ArchVariant: stringPtr(archVariant), |
| 876 | CpuVariant: stringPtr(cpuVariant), |
| 877 | Abi: slicePtr(abi), |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 878 | Native: true, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 882 | a.ArchVariant = "" |
| 883 | } |
| 884 | |
| 885 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 886 | a.CpuVariant = "" |
| 887 | } |
| 888 | |
| 889 | for i := 0; i < len(a.Abi); i++ { |
| 890 | if a.Abi[i] == "" { |
| 891 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 892 | i-- |
| 893 | } |
| 894 | } |
| 895 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 896 | if featureMap, ok := archFeatureMap[archType]; ok { |
Dan Willemsen | b485099 | 2016-05-06 17:21:20 -0700 | [diff] [blame] | 897 | a.ArchFeatures = featureMap[a.ArchVariant] |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 898 | } |
| 899 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 900 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 903 | // Use the module multilib setting to select one or more targets from a target list |
| 904 | func decodeMultilib(multilib string, targets []Target) ([]Target, error) { |
| 905 | buildTargets := []Target{} |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 906 | switch multilib { |
| 907 | case "common": |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 908 | buildTargets = append(buildTargets, commonTarget) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 909 | case "both": |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 910 | buildTargets = append(buildTargets, targets...) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 911 | case "first": |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 912 | buildTargets = append(buildTargets, targets[0]) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 913 | case "32": |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 914 | for _, t := range targets { |
| 915 | if t.Arch.ArchType.Multilib == "lib32" { |
| 916 | buildTargets = append(buildTargets, t) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | case "64": |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 920 | for _, t := range targets { |
| 921 | if t.Arch.ArchType.Multilib == "lib64" { |
| 922 | buildTargets = append(buildTargets, t) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | default: |
| 926 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`, |
| 927 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 930 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 931 | } |