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 | |
| 27 | var ( |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 28 | archTypeList []ArchType |
| 29 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 30 | Arm = newArch("arm", "lib32") |
| 31 | Arm64 = newArch("arm64", "lib64") |
| 32 | Mips = newArch("mips", "lib32") |
| 33 | Mips64 = newArch("mips64", "lib64") |
| 34 | X86 = newArch("x86", "lib32") |
| 35 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 36 | |
| 37 | Common = ArchType{ |
| 38 | Name: "common", |
| 39 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 40 | ) |
| 41 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 42 | var archTypeMap = map[string]ArchType{ |
| 43 | "arm": Arm, |
| 44 | "arm64": Arm64, |
| 45 | "mips": Mips, |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 46 | "mips64": Mips64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 47 | "x86": X86, |
| 48 | "x86_64": X86_64, |
| 49 | } |
| 50 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 51 | /* |
| 52 | Example blueprints file containing all variant property groups, with comment listing what type |
| 53 | of variants get properties in that group: |
| 54 | |
| 55 | module { |
| 56 | arch: { |
| 57 | arm: { |
| 58 | // Host or device variants with arm architecture |
| 59 | }, |
| 60 | arm64: { |
| 61 | // Host or device variants with arm64 architecture |
| 62 | }, |
| 63 | mips: { |
| 64 | // Host or device variants with mips architecture |
| 65 | }, |
| 66 | mips64: { |
| 67 | // Host or device variants with mips64 architecture |
| 68 | }, |
| 69 | x86: { |
| 70 | // Host or device variants with x86 architecture |
| 71 | }, |
| 72 | x86_64: { |
| 73 | // Host or device variants with x86_64 architecture |
| 74 | }, |
| 75 | }, |
| 76 | multilib: { |
| 77 | lib32: { |
| 78 | // Host or device variants for 32-bit architectures |
| 79 | }, |
| 80 | lib64: { |
| 81 | // Host or device variants for 64-bit architectures |
| 82 | }, |
| 83 | }, |
| 84 | target: { |
| 85 | android: { |
| 86 | // Device variants |
| 87 | }, |
| 88 | host: { |
| 89 | // Host variants |
| 90 | }, |
| 91 | linux: { |
| 92 | // Linux host variants |
| 93 | }, |
| 94 | darwin: { |
| 95 | // Darwin host variants |
| 96 | }, |
| 97 | windows: { |
| 98 | // Windows host variants |
| 99 | }, |
| 100 | not_windows: { |
| 101 | // Non-windows host variants |
| 102 | }, |
| 103 | }, |
| 104 | } |
| 105 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 106 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 107 | var archVariants = map[ArchType][]string{} |
| 108 | var archFeatures = map[ArchType][]string{} |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 109 | var archFeatureMap = map[ArchType]map[string][]string{} |
| 110 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 111 | func RegisterArchVariants(arch ArchType, variants ...string) { |
| 112 | checkCalledFromInit() |
| 113 | archVariants[arch] = append(archVariants[arch], variants...) |
| 114 | } |
| 115 | |
| 116 | func RegisterArchFeatures(arch ArchType, features ...string) { |
| 117 | checkCalledFromInit() |
| 118 | archFeatures[arch] = append(archFeatures[arch], features...) |
| 119 | } |
| 120 | |
| 121 | func RegisterArchVariantFeatures(arch ArchType, variant string, features ...string) { |
| 122 | checkCalledFromInit() |
| 123 | if variant != "" && !inList(variant, archVariants[arch]) { |
| 124 | panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch)) |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 125 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 126 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 127 | for _, feature := range features { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 128 | if !inList(feature, archFeatures[arch]) { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 129 | panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant)) |
| 130 | } |
| 131 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 132 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 133 | if archFeatureMap[arch] == nil { |
| 134 | archFeatureMap[arch] = make(map[string][]string) |
| 135 | } |
| 136 | archFeatureMap[arch][variant] = features |
| 137 | } |
| 138 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 139 | // An Arch indicates a single CPU architecture. |
| 140 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 141 | ArchType ArchType |
| 142 | ArchVariant string |
| 143 | CpuVariant string |
| 144 | Abi []string |
| 145 | ArchFeatures []string |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 146 | Native bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 150 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 151 | if a.ArchVariant != "" { |
| 152 | s += "_" + a.ArchVariant |
| 153 | } |
| 154 | if a.CpuVariant != "" { |
| 155 | s += "_" + a.CpuVariant |
| 156 | } |
| 157 | return s |
| 158 | } |
| 159 | |
| 160 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 161 | Name string |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 162 | Field string |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 163 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 166 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 167 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 168 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 169 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 170 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 171 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 172 | archTypeList = append(archTypeList, archType) |
| 173 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | func (a ArchType) String() string { |
| 177 | return a.Name |
| 178 | } |
| 179 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 180 | var BuildOs = func() OsType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 181 | switch runtime.GOOS { |
| 182 | case "linux": |
| 183 | return Linux |
| 184 | case "darwin": |
| 185 | return Darwin |
| 186 | default: |
| 187 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 188 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 189 | }() |
| 190 | |
| 191 | var ( |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 192 | osTypeList []OsType |
| 193 | commonTargetMap = make(map[string]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 194 | |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 195 | NoOsType OsType |
| 196 | Linux = NewOsType("linux", Host, false) |
| 197 | Darwin = NewOsType("darwin", Host, false) |
| 198 | LinuxBionic = NewOsType("linux_bionic", Host, true) |
| 199 | Windows = NewOsType("windows", HostCross, true) |
| 200 | Android = NewOsType("android", Device, false) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 201 | |
| 202 | osArchTypeMap = map[OsType][]ArchType{ |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 203 | Linux: []ArchType{X86, X86_64}, |
| 204 | LinuxBionic: []ArchType{X86_64}, |
| 205 | Darwin: []ArchType{X86, X86_64}, |
| 206 | Windows: []ArchType{X86, X86_64}, |
| 207 | Android: []ArchType{Arm, Arm64, Mips, Mips64, X86, X86_64}, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 208 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 209 | ) |
| 210 | |
| 211 | type OsType struct { |
| 212 | Name, Field string |
| 213 | Class OsClass |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 214 | |
| 215 | DefaultDisabled bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 218 | type OsClass int |
| 219 | |
| 220 | const ( |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 221 | Generic OsClass = iota |
| 222 | Device |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 223 | Host |
| 224 | HostCross |
| 225 | ) |
| 226 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 227 | func (class OsClass) String() string { |
| 228 | switch class { |
| 229 | case Generic: |
| 230 | return "generic" |
| 231 | case Device: |
| 232 | return "device" |
| 233 | case Host: |
| 234 | return "host" |
| 235 | case HostCross: |
| 236 | return "host cross" |
| 237 | default: |
| 238 | panic(fmt.Errorf("unknown class %d", class)) |
| 239 | } |
| 240 | } |
| 241 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 242 | func (os OsType) String() string { |
| 243 | return os.Name |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 246 | func NewOsType(name string, class OsClass, defDisabled bool) OsType { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 247 | os := OsType{ |
| 248 | Name: name, |
| 249 | Field: strings.Title(name), |
| 250 | Class: class, |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 251 | |
| 252 | DefaultDisabled: defDisabled, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 253 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 254 | osTypeList = append(osTypeList, os) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 255 | |
| 256 | if _, found := commonTargetMap[name]; found { |
| 257 | panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) |
| 258 | } else { |
| 259 | commonTargetMap[name] = Target{Os: os, Arch: Arch{ArchType: Common}} |
| 260 | } |
| 261 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 262 | return os |
| 263 | } |
| 264 | |
| 265 | func osByName(name string) OsType { |
| 266 | for _, os := range osTypeList { |
| 267 | if os.Name == name { |
| 268 | return os |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 275 | type Target struct { |
| 276 | Os OsType |
| 277 | Arch Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 280 | func (target Target) String() string { |
| 281 | return target.Os.String() + "_" + target.Arch.String() |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 284 | func archMutator(mctx BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 285 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 286 | var ok bool |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 287 | if module, ok = mctx.Module().(Module); !ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 288 | return |
| 289 | } |
| 290 | |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 291 | if !module.base().ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 292 | return |
| 293 | } |
| 294 | |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 295 | osClasses := module.base().OsClassSupported() |
| 296 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 297 | var moduleTargets []Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 298 | primaryModules := make(map[int]bool) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 299 | |
| 300 | for _, class := range osClasses { |
| 301 | targets := mctx.AConfig().Targets[class] |
| 302 | if len(targets) == 0 { |
| 303 | continue |
| 304 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 305 | var multilib string |
| 306 | switch class { |
| 307 | case Device: |
| 308 | multilib = module.base().commonProperties.Target.Android.Compile_multilib |
| 309 | case Host, HostCross: |
| 310 | multilib = module.base().commonProperties.Target.Host.Compile_multilib |
| 311 | } |
| 312 | if multilib == "" { |
| 313 | multilib = module.base().commonProperties.Compile_multilib |
| 314 | } |
| 315 | if multilib == "" { |
| 316 | multilib = module.base().commonProperties.Default_multilib |
| 317 | } |
Colin Cross | 628a88c | 2016-09-13 15:15:51 -0700 | [diff] [blame] | 318 | var prefer32 bool |
| 319 | switch class { |
| 320 | case Device: |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 321 | prefer32 = mctx.AConfig().DevicePrefer32BitExecutables() |
Colin Cross | 628a88c | 2016-09-13 15:15:51 -0700 | [diff] [blame] | 322 | case HostCross: |
| 323 | // Windows builds always prefer 32-bit |
| 324 | prefer32 = true |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 325 | } |
| 326 | targets, err := decodeMultilib(multilib, targets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 327 | if err != nil { |
| 328 | mctx.ModuleErrorf("%s", err.Error()) |
| 329 | } |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 330 | if len(targets) > 0 { |
| 331 | primaryModules[len(moduleTargets)] = true |
| 332 | moduleTargets = append(moduleTargets, targets...) |
| 333 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 336 | if len(moduleTargets) == 0 { |
| 337 | module.base().commonProperties.Enabled = boolPtr(false) |
| 338 | return |
| 339 | } |
| 340 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 341 | targetNames := make([]string, len(moduleTargets)) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 342 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 343 | for i, target := range moduleTargets { |
| 344 | targetNames[i] = target.String() |
| 345 | } |
| 346 | |
| 347 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 348 | for i, m := range modules { |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 349 | m.(Module).base().SetTarget(moduleTargets[i], primaryModules[i]) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 350 | m.(Module).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 354 | func filterArchStruct(prop reflect.Type) (reflect.Type, bool) { |
| 355 | var fields []reflect.StructField |
| 356 | |
| 357 | ptr := prop.Kind() == reflect.Ptr |
| 358 | if ptr { |
| 359 | prop = prop.Elem() |
| 360 | } |
| 361 | |
| 362 | for i := 0; i < prop.NumField(); i++ { |
| 363 | field := prop.Field(i) |
| 364 | if !proptools.HasTag(field, "android", "arch_variant") { |
| 365 | continue |
| 366 | } |
| 367 | |
| 368 | // The arch_variant field isn't necessary past this point |
| 369 | // Instead of wasting space, just remove it. Go also has a |
| 370 | // 16-bit limit on structure name length. The name is constructed |
| 371 | // based on the Go source representation of the structure, so |
| 372 | // the tag names count towards that length. |
| 373 | // |
| 374 | // TODO: handle the uncommon case of other tags being involved |
| 375 | if field.Tag == `android:"arch_variant"` { |
| 376 | field.Tag = "" |
| 377 | } |
| 378 | |
| 379 | // Recurse into structs |
| 380 | switch field.Type.Kind() { |
| 381 | case reflect.Struct: |
| 382 | var ok bool |
| 383 | field.Type, ok = filterArchStruct(field.Type) |
| 384 | if !ok { |
| 385 | continue |
| 386 | } |
| 387 | case reflect.Ptr: |
| 388 | if field.Type.Elem().Kind() == reflect.Struct { |
| 389 | nestedType, ok := filterArchStruct(field.Type.Elem()) |
| 390 | if !ok { |
| 391 | continue |
| 392 | } |
| 393 | field.Type = reflect.PtrTo(nestedType) |
| 394 | } |
| 395 | case reflect.Interface: |
| 396 | panic("Interfaces are not supported in arch_variant properties") |
| 397 | } |
| 398 | |
| 399 | fields = append(fields, field) |
| 400 | } |
| 401 | if len(fields) == 0 { |
| 402 | return nil, false |
| 403 | } |
| 404 | |
| 405 | ret := reflect.StructOf(fields) |
| 406 | if ptr { |
| 407 | ret = reflect.PtrTo(ret) |
| 408 | } |
| 409 | return ret, true |
| 410 | } |
| 411 | |
| 412 | func createArchType(props reflect.Type) reflect.Type { |
| 413 | props, ok := filterArchStruct(props) |
| 414 | if !ok { |
| 415 | return nil |
| 416 | } |
| 417 | |
| 418 | variantFields := func(names []string) []reflect.StructField { |
| 419 | ret := make([]reflect.StructField, len(names)) |
| 420 | |
| 421 | for i, name := range names { |
| 422 | ret[i].Name = name |
| 423 | ret[i].Type = props |
| 424 | } |
| 425 | |
| 426 | return ret |
| 427 | } |
| 428 | |
| 429 | archFields := make([]reflect.StructField, len(archTypeList)) |
| 430 | for i, arch := range archTypeList { |
| 431 | variants := []string{} |
| 432 | |
| 433 | for _, archVariant := range archVariants[arch] { |
Colin Cross | 0906f17 | 2017-04-26 14:00:43 -0700 | [diff] [blame] | 434 | archVariant := variantReplacer.Replace(archVariant) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 435 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) |
| 436 | } |
| 437 | for _, feature := range archFeatures[arch] { |
Colin Cross | 0906f17 | 2017-04-26 14:00:43 -0700 | [diff] [blame] | 438 | feature := variantReplacer.Replace(feature) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 439 | variants = append(variants, proptools.FieldNameForProperty(feature)) |
| 440 | } |
| 441 | |
| 442 | fields := variantFields(variants) |
| 443 | |
| 444 | fields = append([]reflect.StructField{reflect.StructField{ |
| 445 | Name: "BlueprintEmbed", |
| 446 | Type: props, |
| 447 | Anonymous: true, |
| 448 | }}, fields...) |
| 449 | |
| 450 | archFields[i] = reflect.StructField{ |
| 451 | Name: arch.Field, |
| 452 | Type: reflect.StructOf(fields), |
| 453 | } |
| 454 | } |
| 455 | archType := reflect.StructOf(archFields) |
| 456 | |
| 457 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) |
| 458 | |
| 459 | targets := []string{ |
| 460 | "Host", |
| 461 | "Android64", |
| 462 | "Android32", |
| 463 | "Not_windows", |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 464 | "Arm_on_x86", |
| 465 | "Arm_on_x86_64", |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 466 | } |
| 467 | for _, os := range osTypeList { |
| 468 | targets = append(targets, os.Field) |
| 469 | |
| 470 | for _, archType := range osArchTypeMap[os] { |
| 471 | targets = append(targets, os.Field+"_"+archType.Name) |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | targetType := reflect.StructOf(variantFields(targets)) |
| 476 | return reflect.StructOf([]reflect.StructField{ |
| 477 | reflect.StructField{ |
| 478 | Name: "Arch", |
| 479 | Type: archType, |
| 480 | }, |
| 481 | reflect.StructField{ |
| 482 | Name: "Multilib", |
| 483 | Type: multilibType, |
| 484 | }, |
| 485 | reflect.StructField{ |
| 486 | Name: "Target", |
| 487 | Type: targetType, |
| 488 | }, |
| 489 | }) |
| 490 | } |
| 491 | |
| 492 | var archPropTypeMap OncePer |
| 493 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 494 | func InitArchModule(m Module, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 495 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 496 | |
| 497 | base := m.base() |
| 498 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 499 | base.generalProperties = append(base.generalProperties, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 500 | propertyStructs...) |
| 501 | |
| 502 | for _, properties := range base.generalProperties { |
| 503 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 504 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 505 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 506 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 507 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | propertiesValue = propertiesValue.Elem() |
| 511 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 512 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 513 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 516 | archPropType := archPropTypeMap.Once(t, func() interface{} { |
| 517 | return createArchType(t) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 518 | }) |
| 519 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 520 | if archPropType != nil { |
| 521 | base.archProperties = append(base.archProperties, reflect.New(archPropType.(reflect.Type)).Interface()) |
| 522 | } else { |
| 523 | base.archProperties = append(base.archProperties, nil) |
| 524 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | var allProperties []interface{} |
| 528 | allProperties = append(allProperties, base.generalProperties...) |
| 529 | for _, asp := range base.archProperties { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 530 | if asp != nil { |
| 531 | allProperties = append(allProperties, asp) |
| 532 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 535 | base.customizableProperties = allProperties |
| 536 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 537 | return m, allProperties |
| 538 | } |
| 539 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 540 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 541 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 542 | func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 543 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 544 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 545 | src = src.FieldByName(field) |
| 546 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 547 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 548 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 551 | ret := src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 552 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 553 | if src.Kind() == reflect.Struct { |
| 554 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 557 | order := func(property string, |
| 558 | dstField, srcField reflect.StructField, |
| 559 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 560 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 561 | return proptools.Prepend, nil |
| 562 | } else { |
| 563 | return proptools.Append, nil |
| 564 | } |
| 565 | } |
| 566 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 567 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 568 | if err != nil { |
| 569 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 570 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 571 | } else { |
| 572 | panic(err) |
| 573 | } |
| 574 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 575 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 576 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 579 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 580 | func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 581 | arch := a.Arch() |
| 582 | os := a.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 583 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 584 | if arch.ArchType == Common { |
| 585 | return |
| 586 | } |
| 587 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 588 | for i := range a.generalProperties { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 589 | genProps := a.generalProperties[i] |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 590 | if a.archProperties[i] == nil { |
| 591 | continue |
| 592 | } |
| 593 | archProps := reflect.ValueOf(a.archProperties[i]).Elem() |
| 594 | |
| 595 | archProp := archProps.FieldByName("Arch") |
| 596 | multilibProp := archProps.FieldByName("Multilib") |
| 597 | targetProp := archProps.FieldByName("Target") |
| 598 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 599 | // Handle arch-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 600 | // arch: { |
| 601 | // arm64: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 602 | // key: value, |
| 603 | // }, |
| 604 | // }, |
| 605 | t := arch.ArchType |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 606 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 607 | field := proptools.FieldNameForProperty(t.Name) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 608 | prefix := "arch." + t.Name |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 609 | archStruct := a.appendProperties(ctx, genProps, archProp, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 610 | |
| 611 | // Handle arch-variant-specific properties in the form: |
| 612 | // arch: { |
| 613 | // variant: { |
| 614 | // key: value, |
| 615 | // }, |
| 616 | // }, |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 617 | v := variantReplacer.Replace(arch.ArchVariant) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 618 | if v != "" { |
| 619 | field := proptools.FieldNameForProperty(v) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 620 | prefix := "arch." + t.Name + "." + v |
| 621 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | // Handle cpu-variant-specific properties in the form: |
| 625 | // arch: { |
| 626 | // variant: { |
| 627 | // key: value, |
| 628 | // }, |
| 629 | // }, |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 630 | if arch.CpuVariant != arch.ArchVariant { |
| 631 | c := variantReplacer.Replace(arch.CpuVariant) |
| 632 | if c != "" { |
| 633 | field := proptools.FieldNameForProperty(c) |
| 634 | prefix := "arch." + t.Name + "." + c |
| 635 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 636 | } |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 637 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 638 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 639 | // Handle arch-feature-specific properties in the form: |
| 640 | // arch: { |
| 641 | // feature: { |
| 642 | // key: value, |
| 643 | // }, |
| 644 | // }, |
| 645 | for _, feature := range arch.ArchFeatures { |
| 646 | field := proptools.FieldNameForProperty(feature) |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 647 | prefix := "arch." + t.Name + "." + feature |
| 648 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 649 | } |
| 650 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 651 | // Handle multilib-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 652 | // multilib: { |
| 653 | // lib32: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 654 | // key: value, |
| 655 | // }, |
| 656 | // }, |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 657 | field = proptools.FieldNameForProperty(t.Multilib) |
| 658 | prefix = "multilib." + t.Multilib |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 659 | a.appendProperties(ctx, genProps, multilibProp, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 660 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 661 | // Handle host-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 662 | // target: { |
| 663 | // host: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 664 | // key: value, |
| 665 | // }, |
| 666 | // }, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 667 | if os.Class == Host || os.Class == HostCross { |
| 668 | field = "Host" |
| 669 | prefix = "target.host" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 670 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 671 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 672 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 673 | // Handle target OS properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 674 | // target: { |
| 675 | // linux: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 676 | // key: value, |
| 677 | // }, |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 678 | // not_windows: { |
| 679 | // key: value, |
| 680 | // }, |
| 681 | // linux_x86: { |
| 682 | // key: value, |
| 683 | // }, |
| 684 | // linux_arm: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 685 | // key: value, |
| 686 | // }, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 687 | // android { |
| 688 | // key: value, |
| 689 | // }, |
| 690 | // android_arm { |
| 691 | // key: value, |
| 692 | // }, |
| 693 | // android_x86 { |
| 694 | // key: value, |
| 695 | // }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 696 | // }, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 697 | // }, |
| 698 | field = os.Field |
| 699 | prefix = "target." + os.Name |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 700 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 701 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 702 | field = os.Field + "_" + t.Name |
| 703 | prefix = "target." + os.Name + "_" + t.Name |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 704 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 705 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 706 | if (os.Class == Host || os.Class == HostCross) && os != Windows { |
| 707 | field := "Not_windows" |
| 708 | prefix := "target.not_windows" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 709 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 712 | // Handle 64-bit device properties in the form: |
| 713 | // target { |
| 714 | // android64 { |
| 715 | // key: value, |
| 716 | // }, |
| 717 | // android32 { |
| 718 | // key: value, |
| 719 | // }, |
| 720 | // }, |
| 721 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 722 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 723 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 724 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 725 | if os.Class == Device { |
| 726 | if ctx.AConfig().Android64() { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 727 | field := "Android64" |
| 728 | prefix := "target.android64" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 729 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 730 | } else { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 731 | field := "Android32" |
| 732 | prefix := "target.android32" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 733 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 734 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 735 | |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 736 | if arch.ArchType == X86 && (hasArmAbi(arch) || |
| 737 | hasArmAndroidArch(ctx.AConfig().Targets[Device])) { |
| 738 | field := "Arm_on_x86" |
| 739 | prefix := "target.arm_on_x86" |
| 740 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 741 | } |
| 742 | if arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 743 | hasArmAndroidArch(ctx.AConfig().Targets[Device])) { |
| 744 | field := "Arm_on_x86_64" |
| 745 | prefix := "target.arm_on_x86_64" |
| 746 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 747 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 748 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | |
| 752 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 753 | switch v.Kind() { |
| 754 | case reflect.Interface: |
| 755 | f(v) |
| 756 | case reflect.Struct: |
| 757 | for i := 0; i < v.NumField(); i++ { |
| 758 | forEachInterface(v.Field(i), f) |
| 759 | } |
| 760 | case reflect.Ptr: |
| 761 | forEachInterface(v.Elem(), f) |
| 762 | default: |
| 763 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 764 | } |
| 765 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 766 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 767 | // Convert the arch product variables into a list of targets for each os class structs |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 768 | func decodeTargetProductVariables(config *config) (map[OsClass][]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 769 | variables := config.ProductVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 770 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 771 | targets := make(map[OsClass][]Target) |
| 772 | var targetErr error |
| 773 | |
| 774 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi *[]string) { |
| 775 | if targetErr != nil { |
| 776 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 777 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 778 | |
| 779 | arch, err := decodeArch(archName, archVariant, cpuVariant, abi) |
| 780 | if err != nil { |
| 781 | targetErr = err |
| 782 | return |
| 783 | } |
| 784 | |
| 785 | targets[os.Class] = append(targets[os.Class], |
| 786 | Target{ |
| 787 | Os: os, |
| 788 | Arch: arch, |
| 789 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 790 | } |
| 791 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 792 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 793 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 796 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 797 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 798 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 799 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 800 | } |
| 801 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 802 | if config.Host_bionic != nil && *config.Host_bionic { |
| 803 | addTarget(LinuxBionic, "x86_64", nil, nil, nil) |
| 804 | } |
| 805 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 806 | if variables.CrossHost != nil && *variables.CrossHost != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 807 | crossHostOs := osByName(*variables.CrossHost) |
| 808 | if crossHostOs == NoOsType { |
| 809 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 810 | } |
| 811 | |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 812 | if variables.CrossHostArch == nil || *variables.CrossHostArch == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 813 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 814 | } |
| 815 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 816 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 817 | |
| 818 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 819 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 823 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
| 824 | addTarget(Android, *variables.DeviceArch, variables.DeviceArchVariant, |
| 825 | variables.DeviceCpuVariant, variables.DeviceAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 826 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 827 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 828 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 829 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 830 | variables.DeviceSecondaryAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 831 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 832 | deviceArches := targets[Device] |
| 833 | if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib { |
| 834 | deviceArches[1].Arch.Native = false |
| 835 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 836 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 839 | if targetErr != nil { |
| 840 | return nil, targetErr |
| 841 | } |
| 842 | |
| 843 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 846 | // hasArmAbi returns true if arch has at least one arm ABI |
| 847 | func hasArmAbi(arch Arch) bool { |
| 848 | for _, abi := range arch.Abi { |
| 849 | if strings.HasPrefix(abi, "arm") { |
| 850 | return true |
| 851 | } |
| 852 | } |
| 853 | return false |
| 854 | } |
| 855 | |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 856 | // hasArmArch returns true if targets has at least arm Android arch |
| 857 | func hasArmAndroidArch(targets []Target) bool { |
| 858 | for _, target := range targets { |
| 859 | if target.Os == Android && target.Arch.ArchType == Arm { |
| 860 | return true |
| 861 | } |
| 862 | } |
| 863 | return false |
| 864 | } |
| 865 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 866 | type archConfig struct { |
| 867 | arch string |
| 868 | archVariant string |
| 869 | cpuVariant string |
| 870 | abi []string |
| 871 | } |
| 872 | |
| 873 | func getMegaDeviceConfig() []archConfig { |
| 874 | return []archConfig{ |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 875 | // armv5 is only used for unbundled apps |
| 876 | //{"arm", "armv5te", "", []string{"armeabi"}}, |
| 877 | {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}}, |
| 878 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 879 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 880 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 881 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 882 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 883 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 884 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame^] | 885 | {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 886 | {"arm", "armv7-a-neon", "denver", []string{"armeabi-v7a"}}, |
| 887 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Alex Naidis | ae4fc18 | 2016-08-20 00:14:56 +0200 | [diff] [blame] | 888 | {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 889 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame^] | 890 | {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 891 | {"arm64", "armv8-a", "denver64", []string{"arm64-v8a"}}, |
Alex Naidis | ac01ff5 | 2016-08-30 15:56:33 +0200 | [diff] [blame] | 892 | {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 893 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 894 | {"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 895 | {"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
Dan Willemsen | 65fb981 | 2016-07-19 21:37:28 -0700 | [diff] [blame] | 896 | //{"mips", "mips32r6", "", []string{"mips"}}, |
Colin Cross | 1837b80 | 2017-04-26 19:10:34 -0700 | [diff] [blame] | 897 | {"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 898 | {"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 899 | // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc |
| 900 | //{"mips64", "mips64r2", "", []string{"mips64"}}, |
| 901 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 902 | {"x86", "", "", []string{"x86"}}, |
| 903 | {"x86", "atom", "", []string{"x86"}}, |
| 904 | {"x86", "haswell", "", []string{"x86"}}, |
| 905 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 906 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 907 | {"x86", "silvermont", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 908 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 909 | {"x86_64", "", "", []string{"x86_64"}}, |
| 910 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 911 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 912 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 913 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
| 914 | } |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 915 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 916 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 917 | func getNdkAbisConfig() []archConfig { |
| 918 | return []archConfig{ |
| 919 | {"arm", "armv5te", "", []string{"armeabi"}}, |
| 920 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
| 921 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 922 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 923 | {"x86", "", "", []string{"x86"}}, |
| 924 | {"x86_64", "", "", []string{"x86_64"}}, |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | func decodeArchSettings(archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 929 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 930 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 931 | for _, config := range archConfigs { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 932 | arch, err := decodeArch(config.arch, &config.archVariant, |
| 933 | &config.cpuVariant, &config.abi) |
| 934 | if err != nil { |
| 935 | return nil, err |
| 936 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 937 | arch.Native = false |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 938 | ret = append(ret, Target{ |
| 939 | Os: Android, |
| 940 | Arch: arch, |
| 941 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | return ret, nil |
| 945 | } |
| 946 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 947 | // Convert a set of strings from product variables into a single Arch struct |
| 948 | func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) { |
| 949 | stringPtr := func(p *string) string { |
| 950 | if p != nil { |
| 951 | return *p |
| 952 | } |
| 953 | return "" |
| 954 | } |
| 955 | |
| 956 | slicePtr := func(p *[]string) []string { |
| 957 | if p != nil { |
| 958 | return *p |
| 959 | } |
| 960 | return nil |
| 961 | } |
| 962 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 963 | archType, ok := archTypeMap[arch] |
| 964 | if !ok { |
| 965 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 966 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 967 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 968 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 969 | ArchType: archType, |
| 970 | ArchVariant: stringPtr(archVariant), |
| 971 | CpuVariant: stringPtr(cpuVariant), |
| 972 | Abi: slicePtr(abi), |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 973 | Native: true, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 977 | a.ArchVariant = "" |
| 978 | } |
| 979 | |
| 980 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 981 | a.CpuVariant = "" |
| 982 | } |
| 983 | |
| 984 | for i := 0; i < len(a.Abi); i++ { |
| 985 | if a.Abi[i] == "" { |
| 986 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 987 | i-- |
| 988 | } |
| 989 | } |
| 990 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 991 | if featureMap, ok := archFeatureMap[archType]; ok { |
Dan Willemsen | b485099 | 2016-05-06 17:21:20 -0700 | [diff] [blame] | 992 | a.ArchFeatures = featureMap[a.ArchVariant] |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 993 | } |
| 994 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 995 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 998 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 999 | var ret []Target |
| 1000 | for _, t := range targets { |
| 1001 | if t.Arch.ArchType.Multilib == multilib { |
| 1002 | ret = append(ret, t) |
| 1003 | } |
| 1004 | } |
| 1005 | return ret |
| 1006 | } |
| 1007 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1008 | func getCommonTargets(targets []Target) []Target { |
| 1009 | var ret []Target |
| 1010 | set := make(map[string]bool) |
| 1011 | |
| 1012 | for _, t := range targets { |
| 1013 | if _, found := set[t.Os.String()]; !found { |
| 1014 | set[t.Os.String()] = true |
| 1015 | ret = append(ret, commonTargetMap[t.Os.String()]) |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | return ret |
| 1020 | } |
| 1021 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1022 | // Use the module multilib setting to select one or more targets from a target list |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1023 | func decodeMultilib(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1024 | buildTargets := []Target{} |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1025 | if multilib == "first" { |
| 1026 | if prefer32 { |
| 1027 | multilib = "prefer32" |
| 1028 | } else { |
| 1029 | multilib = "prefer64" |
| 1030 | } |
| 1031 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1032 | switch multilib { |
| 1033 | case "common": |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1034 | buildTargets = append(buildTargets, getCommonTargets(targets)...) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1035 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1036 | if prefer32 { |
| 1037 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1038 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1039 | } else { |
| 1040 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1041 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1042 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1043 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1044 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1045 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1046 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1047 | case "prefer32": |
| 1048 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1049 | if len(buildTargets) == 0 { |
| 1050 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1051 | } |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1052 | case "prefer64": |
| 1053 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1054 | if len(buildTargets) == 0 { |
| 1055 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1056 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1057 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1058 | 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] | 1059 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1062 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1063 | } |