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