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 | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 18 | "encoding" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "fmt" |
| 20 | "reflect" |
| 21 | "runtime" |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 22 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 24 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | var ( |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 29 | archTypeList []ArchType |
| 30 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 31 | Arm = newArch("arm", "lib32") |
| 32 | Arm64 = newArch("arm64", "lib64") |
| 33 | Mips = newArch("mips", "lib32") |
| 34 | Mips64 = newArch("mips64", "lib64") |
| 35 | X86 = newArch("x86", "lib32") |
| 36 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 37 | |
| 38 | Common = ArchType{ |
| 39 | Name: "common", |
| 40 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 41 | ) |
| 42 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 43 | var archTypeMap = map[string]ArchType{ |
| 44 | "arm": Arm, |
| 45 | "arm64": Arm64, |
| 46 | "mips": Mips, |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 47 | "mips64": Mips64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 48 | "x86": X86, |
| 49 | "x86_64": X86_64, |
| 50 | } |
| 51 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 52 | /* |
| 53 | Example blueprints file containing all variant property groups, with comment listing what type |
| 54 | of variants get properties in that group: |
| 55 | |
| 56 | module { |
| 57 | arch: { |
| 58 | arm: { |
| 59 | // Host or device variants with arm architecture |
| 60 | }, |
| 61 | arm64: { |
| 62 | // Host or device variants with arm64 architecture |
| 63 | }, |
| 64 | mips: { |
| 65 | // Host or device variants with mips architecture |
| 66 | }, |
| 67 | mips64: { |
| 68 | // Host or device variants with mips64 architecture |
| 69 | }, |
| 70 | x86: { |
| 71 | // Host or device variants with x86 architecture |
| 72 | }, |
| 73 | x86_64: { |
| 74 | // Host or device variants with x86_64 architecture |
| 75 | }, |
| 76 | }, |
| 77 | multilib: { |
| 78 | lib32: { |
| 79 | // Host or device variants for 32-bit architectures |
| 80 | }, |
| 81 | lib64: { |
| 82 | // Host or device variants for 64-bit architectures |
| 83 | }, |
| 84 | }, |
| 85 | target: { |
| 86 | android: { |
| 87 | // Device variants |
| 88 | }, |
| 89 | host: { |
| 90 | // Host variants |
| 91 | }, |
Dan Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 92 | linux_glibc: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 93 | // Linux host variants |
| 94 | }, |
| 95 | darwin: { |
| 96 | // Darwin host variants |
| 97 | }, |
| 98 | windows: { |
| 99 | // Windows host variants |
| 100 | }, |
| 101 | not_windows: { |
| 102 | // Non-windows host variants |
| 103 | }, |
| 104 | }, |
| 105 | } |
| 106 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 107 | |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 108 | var archVariants = map[ArchType][]string{ |
| 109 | Arm: { |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame^] | 110 | "armv7-a", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 111 | "armv7-a-neon", |
| 112 | "armv8-a", |
| 113 | "armv8-2a", |
| 114 | "cortex-a7", |
| 115 | "cortex-a8", |
| 116 | "cortex-a9", |
| 117 | "cortex-a15", |
| 118 | "cortex-a53", |
| 119 | "cortex-a53-a57", |
| 120 | "cortex-a55", |
| 121 | "cortex-a72", |
| 122 | "cortex-a73", |
| 123 | "cortex-a75", |
| 124 | "cortex-a76", |
| 125 | "krait", |
| 126 | "kryo", |
| 127 | "kryo385", |
| 128 | "exynos-m1", |
| 129 | "exynos-m2", |
| 130 | }, |
| 131 | Arm64: { |
| 132 | "armv8_a", |
| 133 | "armv8_2a", |
| 134 | "cortex-a53", |
| 135 | "cortex-a55", |
| 136 | "cortex-a72", |
| 137 | "cortex-a73", |
| 138 | "cortex-a75", |
| 139 | "cortex-a76", |
| 140 | "kryo", |
| 141 | "kryo385", |
| 142 | "exynos-m1", |
| 143 | "exynos-m2", |
| 144 | }, |
| 145 | Mips: { |
| 146 | "mips32_fp", |
| 147 | "mips32r2_fp", |
| 148 | "mips32r2_fp_xburst", |
| 149 | "mips32r2dsp_fp", |
| 150 | "mips32r2dspr2_fp", |
| 151 | "mips32r6", |
| 152 | }, |
| 153 | Mips64: { |
| 154 | "mips64r2", |
| 155 | "mips64r6", |
| 156 | }, |
| 157 | X86: { |
| 158 | "atom", |
| 159 | "haswell", |
| 160 | "ivybridge", |
| 161 | "sandybridge", |
| 162 | "silvermont", |
| 163 | "x86_64", |
| 164 | }, |
| 165 | X86_64: { |
| 166 | "haswell", |
| 167 | "ivybridge", |
| 168 | "sandybridge", |
| 169 | "silvermont", |
| 170 | }, |
| 171 | } |
| 172 | |
| 173 | var archFeatures = map[ArchType][]string{ |
| 174 | Arm: { |
| 175 | "neon", |
| 176 | }, |
| 177 | Mips: { |
| 178 | "dspr2", |
| 179 | "rev6", |
| 180 | "msa", |
| 181 | }, |
| 182 | Mips64: { |
| 183 | "rev6", |
| 184 | "msa", |
| 185 | }, |
| 186 | X86: { |
| 187 | "ssse3", |
| 188 | "sse4", |
| 189 | "sse4_1", |
| 190 | "sse4_2", |
| 191 | "aes_ni", |
| 192 | "avx", |
| 193 | "popcnt", |
| 194 | "movbe", |
| 195 | }, |
| 196 | X86_64: { |
| 197 | "ssse3", |
| 198 | "sse4", |
| 199 | "sse4_1", |
| 200 | "sse4_2", |
| 201 | "aes_ni", |
| 202 | "avx", |
| 203 | "popcnt", |
| 204 | }, |
| 205 | } |
| 206 | |
| 207 | var archFeatureMap = map[ArchType]map[string][]string{ |
| 208 | Arm: { |
| 209 | "armv7-a-neon": { |
| 210 | "neon", |
| 211 | }, |
| 212 | "armv8-a": { |
| 213 | "neon", |
| 214 | }, |
| 215 | "armv8-2a": { |
| 216 | "neon", |
| 217 | }, |
| 218 | }, |
| 219 | Mips: { |
| 220 | "mips32r2dspr2_fp": { |
| 221 | "dspr2", |
| 222 | }, |
| 223 | "mips32r6": { |
| 224 | "rev6", |
| 225 | }, |
| 226 | }, |
| 227 | Mips64: { |
| 228 | "mips64r6": { |
| 229 | "rev6", |
| 230 | }, |
| 231 | }, |
| 232 | X86: { |
| 233 | "atom": { |
| 234 | "ssse3", |
| 235 | "movbe", |
| 236 | }, |
| 237 | "haswell": { |
| 238 | "ssse3", |
| 239 | "sse4", |
| 240 | "sse4_1", |
| 241 | "sse4_2", |
| 242 | "aes_ni", |
| 243 | "avx", |
| 244 | "popcnt", |
| 245 | "movbe", |
| 246 | }, |
| 247 | "ivybridge": { |
| 248 | "ssse3", |
| 249 | "sse4", |
| 250 | "sse4_1", |
| 251 | "sse4_2", |
| 252 | "aes_ni", |
| 253 | "avx", |
| 254 | "popcnt", |
| 255 | }, |
| 256 | "sandybridge": { |
| 257 | "ssse3", |
| 258 | "sse4", |
| 259 | "sse4_1", |
| 260 | "sse4_2", |
| 261 | "popcnt", |
| 262 | }, |
| 263 | "silvermont": { |
| 264 | "ssse3", |
| 265 | "sse4", |
| 266 | "sse4_1", |
| 267 | "sse4_2", |
| 268 | "aes_ni", |
| 269 | "popcnt", |
| 270 | "movbe", |
| 271 | }, |
| 272 | "x86_64": { |
| 273 | "ssse3", |
| 274 | "sse4", |
| 275 | "sse4_1", |
| 276 | "sse4_2", |
| 277 | "popcnt", |
| 278 | }, |
| 279 | }, |
| 280 | X86_64: { |
| 281 | "haswell": { |
| 282 | "ssse3", |
| 283 | "sse4", |
| 284 | "sse4_1", |
| 285 | "sse4_2", |
| 286 | "aes_ni", |
| 287 | "avx", |
| 288 | "popcnt", |
| 289 | }, |
| 290 | "ivybridge": { |
| 291 | "ssse3", |
| 292 | "sse4", |
| 293 | "sse4_1", |
| 294 | "sse4_2", |
| 295 | "aes_ni", |
| 296 | "avx", |
| 297 | "popcnt", |
| 298 | }, |
| 299 | "sandybridge": { |
| 300 | "ssse3", |
| 301 | "sse4", |
| 302 | "sse4_1", |
| 303 | "sse4_2", |
| 304 | "popcnt", |
| 305 | }, |
| 306 | "silvermont": { |
| 307 | "ssse3", |
| 308 | "sse4", |
| 309 | "sse4_1", |
| 310 | "sse4_2", |
| 311 | "aes_ni", |
| 312 | "popcnt", |
| 313 | }, |
| 314 | }, |
| 315 | } |
| 316 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 317 | var defaultArchFeatureMap = map[OsType]map[ArchType][]string{} |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 318 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 319 | func RegisterDefaultArchVariantFeatures(os OsType, arch ArchType, features ...string) { |
| 320 | checkCalledFromInit() |
| 321 | |
| 322 | for _, feature := range features { |
| 323 | if !InList(feature, archFeatures[arch]) { |
| 324 | panic(fmt.Errorf("Invalid feature %q for arch %q variant \"\"", feature, arch)) |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | if defaultArchFeatureMap[os] == nil { |
| 329 | defaultArchFeatureMap[os] = make(map[ArchType][]string) |
| 330 | } |
| 331 | defaultArchFeatureMap[os][arch] = features |
| 332 | } |
| 333 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 334 | // An Arch indicates a single CPU architecture. |
| 335 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 336 | ArchType ArchType |
| 337 | ArchVariant string |
| 338 | CpuVariant string |
| 339 | Abi []string |
| 340 | ArchFeatures []string |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 341 | Native bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 345 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 346 | if a.ArchVariant != "" { |
| 347 | s += "_" + a.ArchVariant |
| 348 | } |
| 349 | if a.CpuVariant != "" { |
| 350 | s += "_" + a.CpuVariant |
| 351 | } |
| 352 | return s |
| 353 | } |
| 354 | |
| 355 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 356 | Name string |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 357 | Field string |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 358 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 361 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 362 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 363 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 364 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 365 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 366 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 367 | archTypeList = append(archTypeList, archType) |
| 368 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | func (a ArchType) String() string { |
| 372 | return a.Name |
| 373 | } |
| 374 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 375 | var _ encoding.TextMarshaler = ArchType{} |
| 376 | |
| 377 | func (a ArchType) MarshalText() ([]byte, error) { |
| 378 | return []byte(strconv.Quote(a.String())), nil |
| 379 | } |
| 380 | |
| 381 | var _ encoding.TextUnmarshaler = &ArchType{} |
| 382 | |
| 383 | func (a *ArchType) UnmarshalText(text []byte) error { |
| 384 | if u, ok := archTypeMap[string(text)]; ok { |
| 385 | *a = u |
| 386 | return nil |
| 387 | } |
| 388 | |
| 389 | return fmt.Errorf("unknown ArchType %q", text) |
| 390 | } |
| 391 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 392 | var BuildOs = func() OsType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 393 | switch runtime.GOOS { |
| 394 | case "linux": |
| 395 | return Linux |
| 396 | case "darwin": |
| 397 | return Darwin |
| 398 | default: |
| 399 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 400 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 401 | }() |
| 402 | |
| 403 | var ( |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 404 | osTypeList []OsType |
| 405 | commonTargetMap = make(map[string]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 406 | |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 407 | NoOsType OsType |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 408 | Linux = NewOsType("linux_glibc", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 409 | Darwin = NewOsType("darwin", Host, false) |
Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 410 | LinuxBionic = NewOsType("linux_bionic", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 411 | Windows = NewOsType("windows", HostCross, true) |
| 412 | Android = NewOsType("android", Device, false) |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 413 | Fuchsia = NewOsType("fuchsia", Device, false) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 414 | |
| 415 | osArchTypeMap = map[OsType][]ArchType{ |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 416 | Linux: []ArchType{X86, X86_64}, |
| 417 | LinuxBionic: []ArchType{X86_64}, |
Dan Willemsen | e97e68a | 2018-08-28 17:12:56 -0700 | [diff] [blame] | 418 | Darwin: []ArchType{X86_64}, |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 419 | Windows: []ArchType{X86, X86_64}, |
| 420 | Android: []ArchType{Arm, Arm64, Mips, Mips64, X86, X86_64}, |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 421 | Fuchsia: []ArchType{Arm64, X86_64}, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 422 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 423 | ) |
| 424 | |
| 425 | type OsType struct { |
| 426 | Name, Field string |
| 427 | Class OsClass |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 428 | |
| 429 | DefaultDisabled bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 432 | type OsClass int |
| 433 | |
| 434 | const ( |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 435 | Generic OsClass = iota |
| 436 | Device |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 437 | Host |
| 438 | HostCross |
| 439 | ) |
| 440 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 441 | func (class OsClass) String() string { |
| 442 | switch class { |
| 443 | case Generic: |
| 444 | return "generic" |
| 445 | case Device: |
| 446 | return "device" |
| 447 | case Host: |
| 448 | return "host" |
| 449 | case HostCross: |
| 450 | return "host cross" |
| 451 | default: |
| 452 | panic(fmt.Errorf("unknown class %d", class)) |
| 453 | } |
| 454 | } |
| 455 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 456 | func (os OsType) String() string { |
| 457 | return os.Name |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 460 | func (os OsType) Bionic() bool { |
| 461 | return os == Android || os == LinuxBionic |
| 462 | } |
| 463 | |
| 464 | func (os OsType) Linux() bool { |
| 465 | return os == Android || os == Linux || os == LinuxBionic |
| 466 | } |
| 467 | |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 468 | func NewOsType(name string, class OsClass, defDisabled bool) OsType { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 469 | os := OsType{ |
| 470 | Name: name, |
| 471 | Field: strings.Title(name), |
| 472 | Class: class, |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 473 | |
| 474 | DefaultDisabled: defDisabled, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 475 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 476 | osTypeList = append(osTypeList, os) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 477 | |
| 478 | if _, found := commonTargetMap[name]; found { |
| 479 | panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) |
| 480 | } else { |
| 481 | commonTargetMap[name] = Target{Os: os, Arch: Arch{ArchType: Common}} |
| 482 | } |
| 483 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 484 | return os |
| 485 | } |
| 486 | |
| 487 | func osByName(name string) OsType { |
| 488 | for _, os := range osTypeList { |
| 489 | if os.Name == name { |
| 490 | return os |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 497 | type Target struct { |
| 498 | Os OsType |
| 499 | Arch Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 502 | func (target Target) String() string { |
| 503 | return target.Os.String() + "_" + target.Arch.String() |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 506 | // archMutator splits a module into a variant for each Target requested by the module. Target selection |
| 507 | // for a module is in three levels, OsClass, mulitlib, and then Target. |
| 508 | // OsClass selection is determined by: |
| 509 | // - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects |
| 510 | // whether the module type can compile for host, device or both. |
| 511 | // - The host_supported and device_supported properties on the module. |
| 512 | // If host is supported for the module, the Host and HostCross OsClasses are are selected. If device is supported |
| 513 | // for the module, the Device OsClass is selected. |
| 514 | // Within each selected OsClass, the multilib selection is determined by: |
| 515 | // - The compile_multilib property if it set (which may be overriden by target.android.compile_multlib or |
| 516 | // target.host.compile_multilib). |
| 517 | // - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. |
| 518 | // Valid multilib values include: |
| 519 | // "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). |
| 520 | // "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64, |
| 521 | // but may be arm for a 32-bit only build or a build with TARGET_PREFER_32_BIT=true set. |
| 522 | // "32": compile for only a single 32-bit Target supported by the OsClass. |
| 523 | // "64": compile for only a single 64-bit Target supported by the OsClass. |
| 524 | // "common": compile a for a single Target that will work on all Targets suported by the OsClass (for example Java). |
| 525 | // |
| 526 | // Once the list of Targets is determined, the module is split into a variant for each Target. |
| 527 | // |
| 528 | // Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass, |
| 529 | // but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets(). |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 530 | func archMutator(mctx BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 531 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 532 | var ok bool |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 533 | if module, ok = mctx.Module().(Module); !ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 534 | return |
| 535 | } |
| 536 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 537 | base := module.base() |
| 538 | |
| 539 | if !base.ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 540 | return |
| 541 | } |
| 542 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 543 | var moduleTargets []Target |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 544 | moduleMultiTargets := make(map[int][]Target) |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 545 | primaryModules := make(map[int]bool) |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 546 | osClasses := base.OsClassSupported() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 547 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 548 | for _, os := range osTypeList { |
| 549 | supportedClass := false |
| 550 | for _, osClass := range osClasses { |
| 551 | if os.Class == osClass { |
| 552 | supportedClass = true |
| 553 | } |
| 554 | } |
| 555 | if !supportedClass { |
| 556 | continue |
| 557 | } |
| 558 | |
| 559 | osTargets := mctx.Config().Targets[os] |
| 560 | if len(osTargets) == 0 { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 561 | continue |
| 562 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 563 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 564 | // only the primary arch in the recovery partition |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 565 | if os == Android && module.InstallInRecovery() { |
| 566 | osTargets = []Target{osTargets[0]} |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 569 | prefer32 := false |
| 570 | if base.prefer32 != nil { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 571 | prefer32 = base.prefer32(mctx, base, os.Class) |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 572 | } |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 573 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 574 | multilib, extraMultilib := decodeMultilib(base, os.Class) |
| 575 | targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 576 | if err != nil { |
| 577 | mctx.ModuleErrorf("%s", err.Error()) |
| 578 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 579 | |
| 580 | var multiTargets []Target |
| 581 | if extraMultilib != "" { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 582 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 583 | if err != nil { |
| 584 | mctx.ModuleErrorf("%s", err.Error()) |
| 585 | } |
| 586 | } |
| 587 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 588 | if len(targets) > 0 { |
| 589 | primaryModules[len(moduleTargets)] = true |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 590 | moduleMultiTargets[len(moduleTargets)] = multiTargets |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 591 | moduleTargets = append(moduleTargets, targets...) |
| 592 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 595 | if len(moduleTargets) == 0 { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 596 | base.commonProperties.Enabled = boolPtr(false) |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 597 | return |
| 598 | } |
| 599 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 600 | targetNames := make([]string, len(moduleTargets)) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 601 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 602 | for i, target := range moduleTargets { |
| 603 | targetNames[i] = target.String() |
| 604 | } |
| 605 | |
| 606 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 607 | for i, m := range modules { |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 608 | m.(Module).base().SetTarget(moduleTargets[i], moduleMultiTargets[i], primaryModules[i]) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 609 | m.(Module).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 613 | func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) { |
| 614 | switch class { |
| 615 | case Device: |
| 616 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) |
| 617 | case Host, HostCross: |
| 618 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) |
| 619 | } |
| 620 | if multilib == "" { |
| 621 | multilib = String(base.commonProperties.Compile_multilib) |
| 622 | } |
| 623 | if multilib == "" { |
| 624 | multilib = base.commonProperties.Default_multilib |
| 625 | } |
| 626 | |
| 627 | if base.commonProperties.UseTargetVariants { |
| 628 | return multilib, "" |
| 629 | } else { |
| 630 | // For app modules a single arch variant will be created per OS class which is expected to handle all the |
| 631 | // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib |
| 632 | if multilib == base.commonProperties.Default_multilib { |
| 633 | multilib = "first" |
| 634 | } |
| 635 | return base.commonProperties.Default_multilib, multilib |
| 636 | } |
| 637 | } |
| 638 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 639 | func filterArchStructFields(fields []reflect.StructField) (filteredFields []reflect.StructField, filtered bool) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 640 | for _, field := range fields { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 641 | if !proptools.HasTag(field, "android", "arch_variant") { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 642 | filtered = true |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 643 | continue |
| 644 | } |
| 645 | |
| 646 | // The arch_variant field isn't necessary past this point |
| 647 | // Instead of wasting space, just remove it. Go also has a |
| 648 | // 16-bit limit on structure name length. The name is constructed |
| 649 | // based on the Go source representation of the structure, so |
| 650 | // the tag names count towards that length. |
| 651 | // |
| 652 | // TODO: handle the uncommon case of other tags being involved |
| 653 | if field.Tag == `android:"arch_variant"` { |
| 654 | field.Tag = "" |
| 655 | } |
| 656 | |
| 657 | // Recurse into structs |
| 658 | switch field.Type.Kind() { |
| 659 | case reflect.Struct: |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 660 | var subFiltered bool |
| 661 | field.Type, subFiltered = filterArchStruct(field.Type) |
| 662 | filtered = filtered || subFiltered |
| 663 | if field.Type == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 664 | continue |
| 665 | } |
| 666 | case reflect.Ptr: |
| 667 | if field.Type.Elem().Kind() == reflect.Struct { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 668 | nestedType, subFiltered := filterArchStruct(field.Type.Elem()) |
| 669 | filtered = filtered || subFiltered |
| 670 | if nestedType == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 671 | continue |
| 672 | } |
| 673 | field.Type = reflect.PtrTo(nestedType) |
| 674 | } |
| 675 | case reflect.Interface: |
| 676 | panic("Interfaces are not supported in arch_variant properties") |
| 677 | } |
| 678 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 679 | filteredFields = append(filteredFields, field) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 680 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 681 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 682 | return filteredFields, filtered |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 685 | // filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a reflect.Type |
| 686 | // that only contains the fields in the original type that have an `android:"arch_variant"` struct tag, and a bool |
| 687 | // that is true if the new struct type has fewer fields than the original type. If there are no fields in the |
| 688 | // original type with the struct tag it returns nil and true. |
| 689 | func filterArchStruct(prop reflect.Type) (filteredProp reflect.Type, filtered bool) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 690 | var fields []reflect.StructField |
| 691 | |
| 692 | ptr := prop.Kind() == reflect.Ptr |
| 693 | if ptr { |
| 694 | prop = prop.Elem() |
| 695 | } |
| 696 | |
| 697 | for i := 0; i < prop.NumField(); i++ { |
| 698 | fields = append(fields, prop.Field(i)) |
| 699 | } |
| 700 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 701 | filteredFields, filtered := filterArchStructFields(fields) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 702 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 703 | if len(filteredFields) == 0 { |
| 704 | return nil, true |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 707 | if !filtered { |
| 708 | if ptr { |
| 709 | return reflect.PtrTo(prop), false |
| 710 | } |
| 711 | return prop, false |
| 712 | } |
| 713 | |
| 714 | ret := reflect.StructOf(filteredFields) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 715 | if ptr { |
| 716 | ret = reflect.PtrTo(ret) |
| 717 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 718 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 719 | return ret, true |
| 720 | } |
| 721 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 722 | // filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a list of |
| 723 | // reflect.Type that only contains the fields in the original type that have an `android:"arch_variant"` struct tag, |
| 724 | // and a bool that is true if the new struct type has fewer fields than the original type. If there are no fields in |
| 725 | // the original type with the struct tag it returns nil and true. Each returned struct type will have a maximum of |
| 726 | // 10 top level fields in it to attempt to avoid hitting the reflect.StructOf name length limit, although the limit |
| 727 | // can still be reached with a single struct field with many fields in it. |
| 728 | func filterArchStructSharded(prop reflect.Type) (filteredProp []reflect.Type, filtered bool) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 729 | var fields []reflect.StructField |
| 730 | |
| 731 | ptr := prop.Kind() == reflect.Ptr |
| 732 | if ptr { |
| 733 | prop = prop.Elem() |
| 734 | } |
| 735 | |
| 736 | for i := 0; i < prop.NumField(); i++ { |
| 737 | fields = append(fields, prop.Field(i)) |
| 738 | } |
| 739 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 740 | fields, filtered = filterArchStructFields(fields) |
| 741 | if !filtered { |
| 742 | if ptr { |
| 743 | return []reflect.Type{reflect.PtrTo(prop)}, false |
| 744 | } |
| 745 | return []reflect.Type{prop}, false |
| 746 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 747 | |
| 748 | if len(fields) == 0 { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 749 | return nil, true |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | shards := shardFields(fields, 10) |
| 753 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 754 | for _, shard := range shards { |
| 755 | s := reflect.StructOf(shard) |
| 756 | if ptr { |
| 757 | s = reflect.PtrTo(s) |
| 758 | } |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 759 | filteredProp = append(filteredProp, s) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 762 | return filteredProp, true |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | func shardFields(fields []reflect.StructField, shardSize int) [][]reflect.StructField { |
| 766 | ret := make([][]reflect.StructField, 0, (len(fields)+shardSize-1)/shardSize) |
| 767 | for len(fields) > shardSize { |
| 768 | ret = append(ret, fields[0:shardSize]) |
| 769 | fields = fields[shardSize:] |
| 770 | } |
| 771 | if len(fields) > 0 { |
| 772 | ret = append(ret, fields) |
| 773 | } |
| 774 | return ret |
| 775 | } |
| 776 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 777 | // createArchType takes a reflect.Type that is either a struct or a pointer to a struct, and returns a list of |
| 778 | // reflect.Type that contains the arch-variant properties inside structs for each architecture, os, target, multilib, |
| 779 | // etc. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 780 | func createArchType(props reflect.Type) []reflect.Type { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 781 | propShards, _ := filterArchStructSharded(props) |
| 782 | if len(propShards) == 0 { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 783 | return nil |
| 784 | } |
| 785 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 786 | var ret []reflect.Type |
| 787 | for _, props := range propShards { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 788 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 789 | variantFields := func(names []string) []reflect.StructField { |
| 790 | ret := make([]reflect.StructField, len(names)) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 791 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 792 | for i, name := range names { |
| 793 | ret[i].Name = name |
| 794 | ret[i].Type = props |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 795 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 796 | |
| 797 | return ret |
| 798 | } |
| 799 | |
| 800 | archFields := make([]reflect.StructField, len(archTypeList)) |
| 801 | for i, arch := range archTypeList { |
| 802 | variants := []string{} |
| 803 | |
| 804 | for _, archVariant := range archVariants[arch] { |
| 805 | archVariant := variantReplacer.Replace(archVariant) |
| 806 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) |
| 807 | } |
| 808 | for _, feature := range archFeatures[arch] { |
| 809 | feature := variantReplacer.Replace(feature) |
| 810 | variants = append(variants, proptools.FieldNameForProperty(feature)) |
| 811 | } |
| 812 | |
| 813 | fields := variantFields(variants) |
| 814 | |
| 815 | fields = append([]reflect.StructField{{ |
| 816 | Name: "BlueprintEmbed", |
| 817 | Type: props, |
| 818 | Anonymous: true, |
| 819 | }}, fields...) |
| 820 | |
| 821 | archFields[i] = reflect.StructField{ |
| 822 | Name: arch.Field, |
| 823 | Type: reflect.StructOf(fields), |
| 824 | } |
| 825 | } |
| 826 | archType := reflect.StructOf(archFields) |
| 827 | |
| 828 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) |
| 829 | |
| 830 | targets := []string{ |
| 831 | "Host", |
| 832 | "Android64", |
| 833 | "Android32", |
| 834 | "Bionic", |
| 835 | "Linux", |
| 836 | "Not_windows", |
| 837 | "Arm_on_x86", |
| 838 | "Arm_on_x86_64", |
| 839 | } |
| 840 | for _, os := range osTypeList { |
| 841 | targets = append(targets, os.Field) |
| 842 | |
| 843 | for _, archType := range osArchTypeMap[os] { |
| 844 | targets = append(targets, os.Field+"_"+archType.Name) |
| 845 | |
| 846 | if os.Linux() { |
| 847 | target := "Linux_" + archType.Name |
| 848 | if !InList(target, targets) { |
| 849 | targets = append(targets, target) |
| 850 | } |
| 851 | } |
| 852 | if os.Bionic() { |
| 853 | target := "Bionic_" + archType.Name |
| 854 | if !InList(target, targets) { |
| 855 | targets = append(targets, target) |
| 856 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 859 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 860 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 861 | targetType := reflect.StructOf(variantFields(targets)) |
| 862 | ret = append(ret, reflect.StructOf([]reflect.StructField{ |
| 863 | { |
| 864 | Name: "Arch", |
| 865 | Type: archType, |
| 866 | }, |
| 867 | { |
| 868 | Name: "Multilib", |
| 869 | Type: multilibType, |
| 870 | }, |
| 871 | { |
| 872 | Name: "Target", |
| 873 | Type: targetType, |
| 874 | }, |
| 875 | })) |
| 876 | } |
| 877 | return ret |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | var archPropTypeMap OncePer |
| 881 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 882 | func InitArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 883 | |
| 884 | base := m.base() |
| 885 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 886 | base.generalProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 887 | |
| 888 | for _, properties := range base.generalProperties { |
| 889 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 890 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 891 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 892 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 893 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | propertiesValue = propertiesValue.Elem() |
| 897 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 898 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 899 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 900 | } |
| 901 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 902 | archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 903 | return createArchType(t) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 904 | }).([]reflect.Type) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 905 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 906 | var archProperties []interface{} |
| 907 | for _, t := range archPropTypes { |
| 908 | archProperties = append(archProperties, reflect.New(t).Interface()) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 909 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 910 | base.archProperties = append(base.archProperties, archProperties) |
| 911 | m.AddProperties(archProperties...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 912 | } |
| 913 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 914 | base.customizableProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 917 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 918 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 919 | func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 920 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 921 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 922 | src = src.FieldByName(field) |
| 923 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 924 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 925 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 926 | } |
| 927 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 928 | ret := src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 929 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 930 | if src.Kind() == reflect.Struct { |
| 931 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 934 | order := func(property string, |
| 935 | dstField, srcField reflect.StructField, |
| 936 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 937 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 938 | return proptools.Prepend, nil |
| 939 | } else { |
| 940 | return proptools.Append, nil |
| 941 | } |
| 942 | } |
| 943 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 944 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 945 | if err != nil { |
| 946 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 947 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 948 | } else { |
| 949 | panic(err) |
| 950 | } |
| 951 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 952 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 953 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 956 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 957 | func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 958 | arch := a.Arch() |
| 959 | os := a.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 960 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 961 | for i := range a.generalProperties { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 962 | genProps := a.generalProperties[i] |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 963 | if a.archProperties[i] == nil { |
| 964 | continue |
| 965 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 966 | for _, archProperties := range a.archProperties[i] { |
| 967 | archPropValues := reflect.ValueOf(archProperties).Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 968 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 969 | archProp := archPropValues.FieldByName("Arch") |
| 970 | multilibProp := archPropValues.FieldByName("Multilib") |
| 971 | targetProp := archPropValues.FieldByName("Target") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 972 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 973 | var field string |
| 974 | var prefix string |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 975 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 976 | // Handle arch-specific properties in the form: |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 977 | // arch: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 978 | // arm64: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 979 | // key: value, |
| 980 | // }, |
| 981 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 982 | t := arch.ArchType |
| 983 | |
| 984 | if arch.ArchType != Common { |
| 985 | field := proptools.FieldNameForProperty(t.Name) |
| 986 | prefix := "arch." + t.Name |
| 987 | archStruct := a.appendProperties(ctx, genProps, archProp, field, prefix) |
| 988 | |
| 989 | // Handle arch-variant-specific properties in the form: |
| 990 | // arch: { |
| 991 | // variant: { |
| 992 | // key: value, |
| 993 | // }, |
| 994 | // }, |
| 995 | v := variantReplacer.Replace(arch.ArchVariant) |
| 996 | if v != "" { |
| 997 | field := proptools.FieldNameForProperty(v) |
| 998 | prefix := "arch." + t.Name + "." + v |
| 999 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 1000 | } |
| 1001 | |
| 1002 | // Handle cpu-variant-specific properties in the form: |
| 1003 | // arch: { |
| 1004 | // variant: { |
| 1005 | // key: value, |
| 1006 | // }, |
| 1007 | // }, |
| 1008 | if arch.CpuVariant != arch.ArchVariant { |
| 1009 | c := variantReplacer.Replace(arch.CpuVariant) |
| 1010 | if c != "" { |
| 1011 | field := proptools.FieldNameForProperty(c) |
| 1012 | prefix := "arch." + t.Name + "." + c |
| 1013 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | // Handle arch-feature-specific properties in the form: |
| 1018 | // arch: { |
| 1019 | // feature: { |
| 1020 | // key: value, |
| 1021 | // }, |
| 1022 | // }, |
| 1023 | for _, feature := range arch.ArchFeatures { |
| 1024 | field := proptools.FieldNameForProperty(feature) |
| 1025 | prefix := "arch." + t.Name + "." + feature |
| 1026 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 1027 | } |
| 1028 | |
| 1029 | // Handle multilib-specific properties in the form: |
| 1030 | // multilib: { |
| 1031 | // lib32: { |
| 1032 | // key: value, |
| 1033 | // }, |
| 1034 | // }, |
| 1035 | field = proptools.FieldNameForProperty(t.Multilib) |
| 1036 | prefix = "multilib." + t.Multilib |
| 1037 | a.appendProperties(ctx, genProps, multilibProp, field, prefix) |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 1038 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1039 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1040 | // Handle host-specific properties in the form: |
| 1041 | // target: { |
| 1042 | // host: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1043 | // key: value, |
| 1044 | // }, |
| 1045 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1046 | if os.Class == Host || os.Class == HostCross { |
| 1047 | field = "Host" |
| 1048 | prefix = "target.host" |
| 1049 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1050 | } |
| 1051 | |
| 1052 | // Handle target OS generalities of the form: |
| 1053 | // target: { |
| 1054 | // bionic: { |
| 1055 | // key: value, |
| 1056 | // }, |
| 1057 | // bionic_x86: { |
| 1058 | // key: value, |
| 1059 | // }, |
| 1060 | // } |
| 1061 | if os.Linux() { |
| 1062 | field = "Linux" |
| 1063 | prefix = "target.linux" |
| 1064 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1065 | |
| 1066 | if arch.ArchType != Common { |
| 1067 | field = "Linux_" + arch.ArchType.Name |
| 1068 | prefix = "target.linux_" + arch.ArchType.Name |
| 1069 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1072 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1073 | if os.Bionic() { |
| 1074 | field = "Bionic" |
| 1075 | prefix = "target.bionic" |
| 1076 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1077 | |
| 1078 | if arch.ArchType != Common { |
| 1079 | field = "Bionic_" + t.Name |
| 1080 | prefix = "target.bionic_" + t.Name |
| 1081 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | // Handle target OS properties in the form: |
| 1086 | // target: { |
| 1087 | // linux_glibc: { |
| 1088 | // key: value, |
| 1089 | // }, |
| 1090 | // not_windows: { |
| 1091 | // key: value, |
| 1092 | // }, |
| 1093 | // linux_glibc_x86: { |
| 1094 | // key: value, |
| 1095 | // }, |
| 1096 | // linux_glibc_arm: { |
| 1097 | // key: value, |
| 1098 | // }, |
| 1099 | // android { |
| 1100 | // key: value, |
| 1101 | // }, |
| 1102 | // android_arm { |
| 1103 | // key: value, |
| 1104 | // }, |
| 1105 | // android_x86 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1106 | // key: value, |
| 1107 | // }, |
| 1108 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1109 | field = os.Field |
| 1110 | prefix = "target." + os.Name |
| 1111 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1112 | |
| 1113 | if arch.ArchType != Common { |
| 1114 | field = os.Field + "_" + t.Name |
| 1115 | prefix = "target." + os.Name + "_" + t.Name |
| 1116 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1119 | if (os.Class == Host || os.Class == HostCross) && os != Windows { |
| 1120 | field := "Not_windows" |
| 1121 | prefix := "target.not_windows" |
| 1122 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1123 | } |
| 1124 | |
| 1125 | // Handle 64-bit device properties in the form: |
| 1126 | // target { |
| 1127 | // android64 { |
| 1128 | // key: value, |
| 1129 | // }, |
| 1130 | // android32 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1131 | // key: value, |
| 1132 | // }, |
| 1133 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1134 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 1135 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 1136 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 1137 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 1138 | if os.Class == Device { |
| 1139 | if ctx.Config().Android64() { |
| 1140 | field := "Android64" |
| 1141 | prefix := "target.android64" |
| 1142 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1143 | } else { |
| 1144 | field := "Android32" |
| 1145 | prefix := "target.android32" |
| 1146 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1147 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1148 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1149 | if (arch.ArchType == X86 && (hasArmAbi(arch) || |
| 1150 | hasArmAndroidArch(ctx.Config().Targets[Android]))) || |
| 1151 | (arch.ArchType == Arm && |
| 1152 | hasX86AndroidArch(ctx.Config().Targets[Android])) { |
| 1153 | field := "Arm_on_x86" |
| 1154 | prefix := "target.arm_on_x86" |
| 1155 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1156 | } |
| 1157 | if (arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 1158 | hasArmAndroidArch(ctx.Config().Targets[Android]))) || |
| 1159 | (arch.ArchType == Arm && |
| 1160 | hasX8664AndroidArch(ctx.Config().Targets[Android])) { |
| 1161 | field := "Arm_on_x86_64" |
| 1162 | prefix := "target.arm_on_x86_64" |
| 1163 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1164 | } |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1165 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1166 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 1171 | switch v.Kind() { |
| 1172 | case reflect.Interface: |
| 1173 | f(v) |
| 1174 | case reflect.Struct: |
| 1175 | for i := 0; i < v.NumField(); i++ { |
| 1176 | forEachInterface(v.Field(i), f) |
| 1177 | } |
| 1178 | case reflect.Ptr: |
| 1179 | forEachInterface(v.Elem(), f) |
| 1180 | default: |
| 1181 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 1182 | } |
| 1183 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1184 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1185 | // Convert the arch product variables into a list of targets for each os class structs |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1186 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1187 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1188 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1189 | targets := make(map[OsType][]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1190 | var targetErr error |
| 1191 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1192 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1193 | if targetErr != nil { |
| 1194 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1195 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1196 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1197 | arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1198 | if err != nil { |
| 1199 | targetErr = err |
| 1200 | return |
| 1201 | } |
| 1202 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1203 | targets[os] = append(targets[os], |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1204 | Target{ |
| 1205 | Os: os, |
| 1206 | Arch: arch, |
| 1207 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1210 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1211 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1214 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1215 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1216 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1217 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1220 | if Bool(config.Host_bionic) { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 1221 | addTarget(LinuxBionic, "x86_64", nil, nil, nil) |
| 1222 | } |
| 1223 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1224 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1225 | crossHostOs := osByName(*variables.CrossHost) |
| 1226 | if crossHostOs == NoOsType { |
| 1227 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 1228 | } |
| 1229 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1230 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1231 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1234 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1235 | |
| 1236 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1237 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1241 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1242 | var target = Android |
| 1243 | if Bool(variables.Fuchsia) { |
| 1244 | target = Fuchsia |
| 1245 | } |
| 1246 | |
| 1247 | addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant, |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1248 | variables.DeviceCpuVariant, variables.DeviceAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1249 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1250 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 1251 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 1252 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 1253 | variables.DeviceSecondaryAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1254 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1255 | deviceArches := targets[Android] |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1256 | if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib { |
| 1257 | deviceArches[1].Arch.Native = false |
| 1258 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1259 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1262 | if targetErr != nil { |
| 1263 | return nil, targetErr |
| 1264 | } |
| 1265 | |
| 1266 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1269 | // hasArmAbi returns true if arch has at least one arm ABI |
| 1270 | func hasArmAbi(arch Arch) bool { |
| 1271 | for _, abi := range arch.Abi { |
| 1272 | if strings.HasPrefix(abi, "arm") { |
| 1273 | return true |
| 1274 | } |
| 1275 | } |
| 1276 | return false |
| 1277 | } |
| 1278 | |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1279 | // hasArmArch returns true if targets has at least arm Android arch |
| 1280 | func hasArmAndroidArch(targets []Target) bool { |
| 1281 | for _, target := range targets { |
| 1282 | if target.Os == Android && target.Arch.ArchType == Arm { |
| 1283 | return true |
| 1284 | } |
| 1285 | } |
| 1286 | return false |
| 1287 | } |
| 1288 | |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1289 | // hasX86Arch returns true if targets has at least x86 Android arch |
| 1290 | func hasX86AndroidArch(targets []Target) bool { |
| 1291 | for _, target := range targets { |
| 1292 | if target.Os == Android && target.Arch.ArchType == X86 { |
| 1293 | return true |
| 1294 | } |
| 1295 | } |
| 1296 | return false |
| 1297 | } |
| 1298 | |
| 1299 | // hasX8664Arch returns true if targets has at least x86_64 Android arch |
| 1300 | func hasX8664AndroidArch(targets []Target) bool { |
| 1301 | for _, target := range targets { |
| 1302 | if target.Os == Android && target.Arch.ArchType == X86_64 { |
| 1303 | return true |
| 1304 | } |
| 1305 | } |
| 1306 | return false |
| 1307 | } |
| 1308 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1309 | type archConfig struct { |
| 1310 | arch string |
| 1311 | archVariant string |
| 1312 | cpuVariant string |
| 1313 | abi []string |
| 1314 | } |
| 1315 | |
| 1316 | func getMegaDeviceConfig() []archConfig { |
| 1317 | return []archConfig{ |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame^] | 1318 | {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1319 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1320 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 1321 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1322 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1323 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 1324 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 1325 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1326 | {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1327 | {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1328 | {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1329 | {"arm", "armv7-a-neon", "cortex-a76", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1330 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Alex Naidis | ae4fc18 | 2016-08-20 00:14:56 +0200 | [diff] [blame] | 1331 | {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1332 | {"arm", "armv7-a-neon", "kryo385", []string{"armeabi-v7a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1333 | {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1334 | {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1335 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1336 | {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1337 | {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}}, |
Alex Naidis | ac01ff5 | 2016-08-30 15:56:33 +0200 | [diff] [blame] | 1338 | {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1339 | {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1340 | {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1341 | {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1342 | {"arm64", "armv8-2a", "cortex-a76", []string{"arm64-v8a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1343 | {"arm64", "armv8-2a", "kryo385", []string{"arm64-v8a"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 1344 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 1345 | {"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 1346 | {"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
Dan Willemsen | 65fb981 | 2016-07-19 21:37:28 -0700 | [diff] [blame] | 1347 | //{"mips", "mips32r6", "", []string{"mips"}}, |
Colin Cross | 1837b80 | 2017-04-26 19:10:34 -0700 | [diff] [blame] | 1348 | {"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 1349 | {"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1350 | // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc |
| 1351 | //{"mips64", "mips64r2", "", []string{"mips64"}}, |
| 1352 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 1353 | {"x86", "", "", []string{"x86"}}, |
| 1354 | {"x86", "atom", "", []string{"x86"}}, |
| 1355 | {"x86", "haswell", "", []string{"x86"}}, |
| 1356 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 1357 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 1358 | {"x86", "silvermont", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 1359 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1360 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1361 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 1362 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 1363 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 1364 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
| 1365 | } |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1366 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1367 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1368 | func getNdkAbisConfig() []archConfig { |
| 1369 | return []archConfig{ |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame^] | 1370 | {"arm", "armv7-a", "", []string{"armeabi"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1371 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1372 | {"x86", "", "", []string{"x86"}}, |
| 1373 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1374 | } |
| 1375 | } |
| 1376 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1377 | func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1378 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1379 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1380 | for _, config := range archConfigs { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1381 | arch, err := decodeArch(os, config.arch, &config.archVariant, |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1382 | &config.cpuVariant, config.abi) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1383 | if err != nil { |
| 1384 | return nil, err |
| 1385 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1386 | arch.Native = false |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1387 | ret = append(ret, Target{ |
| 1388 | Os: Android, |
| 1389 | Arch: arch, |
| 1390 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | return ret, nil |
| 1394 | } |
| 1395 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1396 | // Convert a set of strings from product variables into a single Arch struct |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1397 | func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1398 | stringPtr := func(p *string) string { |
| 1399 | if p != nil { |
| 1400 | return *p |
| 1401 | } |
| 1402 | return "" |
| 1403 | } |
| 1404 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1405 | archType, ok := archTypeMap[arch] |
| 1406 | if !ok { |
| 1407 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1408 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1409 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1410 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1411 | ArchType: archType, |
| 1412 | ArchVariant: stringPtr(archVariant), |
| 1413 | CpuVariant: stringPtr(cpuVariant), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1414 | Abi: abi, |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1415 | Native: true, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 1419 | a.ArchVariant = "" |
| 1420 | } |
| 1421 | |
| 1422 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 1423 | a.CpuVariant = "" |
| 1424 | } |
| 1425 | |
| 1426 | for i := 0; i < len(a.Abi); i++ { |
| 1427 | if a.Abi[i] == "" { |
| 1428 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1429 | i-- |
| 1430 | } |
| 1431 | } |
| 1432 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1433 | if a.ArchVariant == "" { |
| 1434 | if featureMap, ok := defaultArchFeatureMap[os]; ok { |
| 1435 | a.ArchFeatures = featureMap[archType] |
| 1436 | } |
| 1437 | } else { |
| 1438 | if featureMap, ok := archFeatureMap[archType]; ok { |
| 1439 | a.ArchFeatures = featureMap[a.ArchVariant] |
| 1440 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1443 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1446 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 1447 | var ret []Target |
| 1448 | for _, t := range targets { |
| 1449 | if t.Arch.ArchType.Multilib == multilib { |
| 1450 | ret = append(ret, t) |
| 1451 | } |
| 1452 | } |
| 1453 | return ret |
| 1454 | } |
| 1455 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1456 | func getCommonTargets(targets []Target) []Target { |
| 1457 | var ret []Target |
| 1458 | set := make(map[string]bool) |
| 1459 | |
| 1460 | for _, t := range targets { |
| 1461 | if _, found := set[t.Os.String()]; !found { |
| 1462 | set[t.Os.String()] = true |
| 1463 | ret = append(ret, commonTargetMap[t.Os.String()]) |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | return ret |
| 1468 | } |
| 1469 | |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1470 | func firstTarget(targets []Target, filters ...string) []Target { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1471 | for _, filter := range filters { |
| 1472 | buildTargets := filterMultilibTargets(targets, filter) |
| 1473 | if len(buildTargets) > 0 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1474 | return buildTargets[:1] |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | return nil |
| 1478 | } |
| 1479 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1480 | // Use the module multilib setting to select one or more targets from a target list |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1481 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1482 | buildTargets := []Target{} |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1483 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1484 | switch multilib { |
| 1485 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1486 | buildTargets = getCommonTargets(targets) |
| 1487 | case "common_first": |
| 1488 | buildTargets = getCommonTargets(targets) |
| 1489 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1490 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1491 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1492 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1493 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1494 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1495 | if prefer32 { |
| 1496 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1497 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1498 | } else { |
| 1499 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1500 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1501 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1502 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1503 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1504 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1505 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1506 | case "first": |
| 1507 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1508 | buildTargets = firstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1509 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1510 | buildTargets = firstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1511 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1512 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1513 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1514 | if len(buildTargets) == 0 { |
| 1515 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1516 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1517 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1518 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1519 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1522 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1523 | } |