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() |
Colin Cross | b4330e2 | 2017-12-22 15:47:09 -0800 | [diff] [blame] | 122 | if variant != "" && !InList(variant, archVariants[arch]) { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 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 { |
Colin Cross | b4330e2 | 2017-12-22 15:47:09 -0800 | [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}, |
Dan Willemsen | e97e68a | 2018-08-28 17:12:56 -0700 | [diff] [blame] | 204 | Darwin: []ArchType{X86_64}, |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 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 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 298 | base := module.base() |
| 299 | |
| 300 | if !base.ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 301 | return |
| 302 | } |
| 303 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 304 | osClasses := base.OsClassSupported() |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 305 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 306 | var moduleTargets []Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 307 | primaryModules := make(map[int]bool) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 308 | |
| 309 | for _, class := range osClasses { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 310 | classTargets := mctx.Config().Targets[class] |
| 311 | if len(classTargets) == 0 { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 312 | continue |
| 313 | } |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 314 | // only the primary arch in the recovery partition |
| 315 | if module.InstallInRecovery() { |
| 316 | classTargets = []Target{mctx.Config().Targets[Device][0]} |
| 317 | } |
| 318 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 319 | var multilib string |
| 320 | switch class { |
| 321 | case Device: |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 322 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 323 | case Host, HostCross: |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 324 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 325 | } |
| 326 | if multilib == "" { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 327 | multilib = String(base.commonProperties.Compile_multilib) |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 328 | } |
| 329 | if multilib == "" { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 330 | multilib = base.commonProperties.Default_multilib |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 331 | } |
Colin Cross | 628a88c | 2016-09-13 15:15:51 -0700 | [diff] [blame] | 332 | var prefer32 bool |
| 333 | switch class { |
| 334 | case Device: |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 335 | prefer32 = mctx.Config().DevicePrefer32BitExecutables() |
Colin Cross | 628a88c | 2016-09-13 15:15:51 -0700 | [diff] [blame] | 336 | case HostCross: |
| 337 | // Windows builds always prefer 32-bit |
| 338 | prefer32 = true |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 339 | } |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 340 | targets, err := decodeMultilib(multilib, classTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 341 | if err != nil { |
| 342 | mctx.ModuleErrorf("%s", err.Error()) |
| 343 | } |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 344 | if len(targets) > 0 { |
| 345 | primaryModules[len(moduleTargets)] = true |
| 346 | moduleTargets = append(moduleTargets, targets...) |
| 347 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 350 | if len(moduleTargets) == 0 { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame^] | 351 | base.commonProperties.Enabled = boolPtr(false) |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 352 | return |
| 353 | } |
| 354 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 355 | targetNames := make([]string, len(moduleTargets)) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 356 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 357 | for i, target := range moduleTargets { |
| 358 | targetNames[i] = target.String() |
| 359 | } |
| 360 | |
| 361 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 362 | for i, m := range modules { |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 363 | m.(Module).base().SetTarget(moduleTargets[i], primaryModules[i]) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 364 | m.(Module).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 368 | func filterArchStruct(prop reflect.Type) (reflect.Type, bool) { |
| 369 | var fields []reflect.StructField |
| 370 | |
| 371 | ptr := prop.Kind() == reflect.Ptr |
| 372 | if ptr { |
| 373 | prop = prop.Elem() |
| 374 | } |
| 375 | |
| 376 | for i := 0; i < prop.NumField(); i++ { |
| 377 | field := prop.Field(i) |
| 378 | if !proptools.HasTag(field, "android", "arch_variant") { |
| 379 | continue |
| 380 | } |
| 381 | |
| 382 | // The arch_variant field isn't necessary past this point |
| 383 | // Instead of wasting space, just remove it. Go also has a |
| 384 | // 16-bit limit on structure name length. The name is constructed |
| 385 | // based on the Go source representation of the structure, so |
| 386 | // the tag names count towards that length. |
| 387 | // |
| 388 | // TODO: handle the uncommon case of other tags being involved |
| 389 | if field.Tag == `android:"arch_variant"` { |
| 390 | field.Tag = "" |
| 391 | } |
| 392 | |
| 393 | // Recurse into structs |
| 394 | switch field.Type.Kind() { |
| 395 | case reflect.Struct: |
| 396 | var ok bool |
| 397 | field.Type, ok = filterArchStruct(field.Type) |
| 398 | if !ok { |
| 399 | continue |
| 400 | } |
| 401 | case reflect.Ptr: |
| 402 | if field.Type.Elem().Kind() == reflect.Struct { |
| 403 | nestedType, ok := filterArchStruct(field.Type.Elem()) |
| 404 | if !ok { |
| 405 | continue |
| 406 | } |
| 407 | field.Type = reflect.PtrTo(nestedType) |
| 408 | } |
| 409 | case reflect.Interface: |
| 410 | panic("Interfaces are not supported in arch_variant properties") |
| 411 | } |
| 412 | |
| 413 | fields = append(fields, field) |
| 414 | } |
| 415 | if len(fields) == 0 { |
| 416 | return nil, false |
| 417 | } |
| 418 | |
| 419 | ret := reflect.StructOf(fields) |
| 420 | if ptr { |
| 421 | ret = reflect.PtrTo(ret) |
| 422 | } |
| 423 | return ret, true |
| 424 | } |
| 425 | |
| 426 | func createArchType(props reflect.Type) reflect.Type { |
| 427 | props, ok := filterArchStruct(props) |
| 428 | if !ok { |
| 429 | return nil |
| 430 | } |
| 431 | |
| 432 | variantFields := func(names []string) []reflect.StructField { |
| 433 | ret := make([]reflect.StructField, len(names)) |
| 434 | |
| 435 | for i, name := range names { |
| 436 | ret[i].Name = name |
| 437 | ret[i].Type = props |
| 438 | } |
| 439 | |
| 440 | return ret |
| 441 | } |
| 442 | |
| 443 | archFields := make([]reflect.StructField, len(archTypeList)) |
| 444 | for i, arch := range archTypeList { |
| 445 | variants := []string{} |
| 446 | |
| 447 | for _, archVariant := range archVariants[arch] { |
Colin Cross | 0906f17 | 2017-04-26 14:00:43 -0700 | [diff] [blame] | 448 | archVariant := variantReplacer.Replace(archVariant) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 449 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) |
| 450 | } |
| 451 | for _, feature := range archFeatures[arch] { |
Colin Cross | 0906f17 | 2017-04-26 14:00:43 -0700 | [diff] [blame] | 452 | feature := variantReplacer.Replace(feature) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 453 | variants = append(variants, proptools.FieldNameForProperty(feature)) |
| 454 | } |
| 455 | |
| 456 | fields := variantFields(variants) |
| 457 | |
| 458 | fields = append([]reflect.StructField{reflect.StructField{ |
| 459 | Name: "BlueprintEmbed", |
| 460 | Type: props, |
| 461 | Anonymous: true, |
| 462 | }}, fields...) |
| 463 | |
| 464 | archFields[i] = reflect.StructField{ |
| 465 | Name: arch.Field, |
| 466 | Type: reflect.StructOf(fields), |
| 467 | } |
| 468 | } |
| 469 | archType := reflect.StructOf(archFields) |
| 470 | |
| 471 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) |
| 472 | |
| 473 | targets := []string{ |
| 474 | "Host", |
| 475 | "Android64", |
| 476 | "Android32", |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 477 | "Bionic", |
Dan Willemsen | 86fc1eb | 2017-10-02 20:32:35 -0700 | [diff] [blame] | 478 | "Linux", |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 479 | "Not_windows", |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 480 | "Arm_on_x86", |
| 481 | "Arm_on_x86_64", |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 482 | } |
| 483 | for _, os := range osTypeList { |
| 484 | targets = append(targets, os.Field) |
| 485 | |
| 486 | for _, archType := range osArchTypeMap[os] { |
| 487 | targets = append(targets, os.Field+"_"+archType.Name) |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 488 | |
Dan Willemsen | 86fc1eb | 2017-10-02 20:32:35 -0700 | [diff] [blame] | 489 | if os.Linux() { |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 490 | target := "Linux_" + archType.Name |
Colin Cross | b4330e2 | 2017-12-22 15:47:09 -0800 | [diff] [blame] | 491 | if !InList(target, targets) { |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 492 | targets = append(targets, target) |
| 493 | } |
| 494 | } |
| 495 | if os.Bionic() { |
| 496 | target := "Bionic_" + archType.Name |
Colin Cross | b4330e2 | 2017-12-22 15:47:09 -0800 | [diff] [blame] | 497 | if !InList(target, targets) { |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 498 | targets = append(targets, target) |
| 499 | } |
| 500 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
| 504 | targetType := reflect.StructOf(variantFields(targets)) |
| 505 | return reflect.StructOf([]reflect.StructField{ |
| 506 | reflect.StructField{ |
| 507 | Name: "Arch", |
| 508 | Type: archType, |
| 509 | }, |
| 510 | reflect.StructField{ |
| 511 | Name: "Multilib", |
| 512 | Type: multilibType, |
| 513 | }, |
| 514 | reflect.StructField{ |
| 515 | Name: "Target", |
| 516 | Type: targetType, |
| 517 | }, |
| 518 | }) |
| 519 | } |
| 520 | |
| 521 | var archPropTypeMap OncePer |
| 522 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 523 | func InitArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 524 | |
| 525 | base := m.base() |
| 526 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 527 | base.generalProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 528 | |
| 529 | for _, properties := range base.generalProperties { |
| 530 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 531 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 532 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 533 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 534 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | propertiesValue = propertiesValue.Elem() |
| 538 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 539 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 540 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 541 | } |
| 542 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 543 | archPropType := archPropTypeMap.Once(t, func() interface{} { |
| 544 | return createArchType(t) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 545 | }) |
| 546 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 547 | if archPropType != nil { |
| 548 | base.archProperties = append(base.archProperties, reflect.New(archPropType.(reflect.Type)).Interface()) |
| 549 | } else { |
| 550 | base.archProperties = append(base.archProperties, nil) |
| 551 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 554 | for _, asp := range base.archProperties { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 555 | if asp != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 556 | m.AddProperties(asp) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 557 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 560 | base.customizableProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 561 | } |
| 562 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 563 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 564 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 565 | func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 566 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 567 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 568 | src = src.FieldByName(field) |
| 569 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 570 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 571 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 574 | ret := src |
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 | if src.Kind() == reflect.Struct { |
| 577 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 580 | order := func(property string, |
| 581 | dstField, srcField reflect.StructField, |
| 582 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 583 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 584 | return proptools.Prepend, nil |
| 585 | } else { |
| 586 | return proptools.Append, nil |
| 587 | } |
| 588 | } |
| 589 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 590 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 591 | if err != nil { |
| 592 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 593 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 594 | } else { |
| 595 | panic(err) |
| 596 | } |
| 597 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 598 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 599 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 602 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 603 | func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 604 | arch := a.Arch() |
| 605 | os := a.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 606 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 607 | for i := range a.generalProperties { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 608 | genProps := a.generalProperties[i] |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 609 | if a.archProperties[i] == nil { |
| 610 | continue |
| 611 | } |
| 612 | archProps := reflect.ValueOf(a.archProperties[i]).Elem() |
| 613 | |
| 614 | archProp := archProps.FieldByName("Arch") |
| 615 | multilibProp := archProps.FieldByName("Multilib") |
| 616 | targetProp := archProps.FieldByName("Target") |
| 617 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 618 | var field string |
| 619 | var prefix string |
| 620 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 621 | // Handle arch-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 622 | // arch: { |
| 623 | // arm64: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 624 | // key: value, |
| 625 | // }, |
| 626 | // }, |
| 627 | t := arch.ArchType |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 628 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 629 | if arch.ArchType != Common { |
| 630 | field := proptools.FieldNameForProperty(t.Name) |
| 631 | prefix := "arch." + t.Name |
| 632 | archStruct := a.appendProperties(ctx, genProps, archProp, field, prefix) |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 633 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 634 | // Handle arch-variant-specific properties in the form: |
| 635 | // arch: { |
| 636 | // variant: { |
| 637 | // key: value, |
| 638 | // }, |
| 639 | // }, |
| 640 | v := variantReplacer.Replace(arch.ArchVariant) |
| 641 | if v != "" { |
| 642 | field := proptools.FieldNameForProperty(v) |
| 643 | prefix := "arch." + t.Name + "." + v |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 644 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 645 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 646 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 647 | // Handle cpu-variant-specific properties in the form: |
| 648 | // arch: { |
| 649 | // variant: { |
| 650 | // key: value, |
| 651 | // }, |
| 652 | // }, |
| 653 | if arch.CpuVariant != arch.ArchVariant { |
| 654 | c := variantReplacer.Replace(arch.CpuVariant) |
| 655 | if c != "" { |
| 656 | field := proptools.FieldNameForProperty(c) |
| 657 | prefix := "arch." + t.Name + "." + c |
| 658 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 659 | } |
| 660 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 661 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 662 | // Handle arch-feature-specific properties in the form: |
| 663 | // arch: { |
| 664 | // feature: { |
| 665 | // key: value, |
| 666 | // }, |
| 667 | // }, |
| 668 | for _, feature := range arch.ArchFeatures { |
| 669 | field := proptools.FieldNameForProperty(feature) |
| 670 | prefix := "arch." + t.Name + "." + feature |
| 671 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 672 | } |
| 673 | |
| 674 | // Handle multilib-specific properties in the form: |
| 675 | // multilib: { |
| 676 | // lib32: { |
| 677 | // key: value, |
| 678 | // }, |
| 679 | // }, |
| 680 | field = proptools.FieldNameForProperty(t.Multilib) |
| 681 | prefix = "multilib." + t.Multilib |
| 682 | a.appendProperties(ctx, genProps, multilibProp, field, prefix) |
| 683 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 684 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 685 | // Handle host-specific properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 686 | // target: { |
| 687 | // host: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 688 | // key: value, |
| 689 | // }, |
| 690 | // }, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 691 | if os.Class == Host || os.Class == HostCross { |
| 692 | field = "Host" |
| 693 | prefix = "target.host" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 694 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 695 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 696 | |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 697 | // Handle target OS generalities of the form: |
| 698 | // target: { |
| 699 | // bionic: { |
| 700 | // key: value, |
| 701 | // }, |
| 702 | // bionic_x86: { |
| 703 | // key: value, |
| 704 | // }, |
| 705 | // } |
Dan Willemsen | 86fc1eb | 2017-10-02 20:32:35 -0700 | [diff] [blame] | 706 | if os.Linux() { |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 707 | field = "Linux" |
| 708 | prefix = "target.linux" |
| 709 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 710 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 711 | if arch.ArchType != Common { |
| 712 | field = "Linux_" + arch.ArchType.Name |
| 713 | prefix = "target.linux_" + arch.ArchType.Name |
| 714 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 715 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | if os.Bionic() { |
| 719 | field = "Bionic" |
| 720 | prefix = "target.bionic" |
| 721 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 722 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 723 | if arch.ArchType != Common { |
| 724 | field = "Bionic_" + t.Name |
| 725 | prefix = "target.bionic_" + t.Name |
| 726 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 727 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 730 | // Handle target OS properties in the form: |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 731 | // target: { |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 732 | // linux_glibc: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 733 | // key: value, |
| 734 | // }, |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 735 | // not_windows: { |
| 736 | // key: value, |
| 737 | // }, |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 738 | // linux_glibc_x86: { |
Colin Cross | b05bff2 | 2015-04-30 15:08:04 -0700 | [diff] [blame] | 739 | // key: value, |
| 740 | // }, |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 741 | // linux_glibc_arm: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 742 | // key: value, |
| 743 | // }, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 744 | // android { |
| 745 | // key: value, |
| 746 | // }, |
| 747 | // android_arm { |
| 748 | // key: value, |
| 749 | // }, |
| 750 | // android_x86 { |
| 751 | // key: value, |
| 752 | // }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 753 | // }, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 754 | field = os.Field |
| 755 | prefix = "target." + os.Name |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 756 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 757 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 758 | if arch.ArchType != Common { |
| 759 | field = os.Field + "_" + t.Name |
| 760 | prefix = "target." + os.Name + "_" + t.Name |
| 761 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 762 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 763 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 764 | if (os.Class == Host || os.Class == HostCross) && os != Windows { |
| 765 | field := "Not_windows" |
| 766 | prefix := "target.not_windows" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 767 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 770 | // Handle 64-bit device properties in the form: |
| 771 | // target { |
| 772 | // android64 { |
| 773 | // key: value, |
| 774 | // }, |
| 775 | // android32 { |
| 776 | // key: value, |
| 777 | // }, |
| 778 | // }, |
| 779 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 780 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 781 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 782 | // 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] | 783 | if os.Class == Device { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 784 | if ctx.Config().Android64() { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 785 | field := "Android64" |
| 786 | prefix := "target.android64" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 787 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 788 | } else { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 789 | field := "Android32" |
| 790 | prefix := "target.android32" |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 791 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | f820941 | 2015-03-26 14:44:26 -0700 | [diff] [blame] | 792 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 793 | |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 794 | if (arch.ArchType == X86 && (hasArmAbi(arch) || |
| 795 | hasArmAndroidArch(ctx.Config().Targets[Device]))) || |
| 796 | (arch.ArchType == Arm && |
| 797 | hasX86AndroidArch(ctx.Config().Targets[Device])) { |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 798 | field := "Arm_on_x86" |
| 799 | prefix := "target.arm_on_x86" |
| 800 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 801 | } |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 802 | if (arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 803 | hasArmAndroidArch(ctx.Config().Targets[Device]))) || |
| 804 | (arch.ArchType == Arm && |
| 805 | hasX8664AndroidArch(ctx.Config().Targets[Device])) { |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 806 | field := "Arm_on_x86_64" |
| 807 | prefix := "target.arm_on_x86_64" |
| 808 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 809 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 810 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
| 814 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 815 | switch v.Kind() { |
| 816 | case reflect.Interface: |
| 817 | f(v) |
| 818 | case reflect.Struct: |
| 819 | for i := 0; i < v.NumField(); i++ { |
| 820 | forEachInterface(v.Field(i), f) |
| 821 | } |
| 822 | case reflect.Ptr: |
| 823 | forEachInterface(v.Elem(), f) |
| 824 | default: |
| 825 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 826 | } |
| 827 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 828 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 829 | // 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] | 830 | func decodeTargetProductVariables(config *config) (map[OsClass][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 831 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 832 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 833 | targets := make(map[OsClass][]Target) |
| 834 | var targetErr error |
| 835 | |
| 836 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi *[]string) { |
| 837 | if targetErr != nil { |
| 838 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 839 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 840 | |
| 841 | arch, err := decodeArch(archName, archVariant, cpuVariant, abi) |
| 842 | if err != nil { |
| 843 | targetErr = err |
| 844 | return |
| 845 | } |
| 846 | |
| 847 | targets[os.Class] = append(targets[os.Class], |
| 848 | Target{ |
| 849 | Os: os, |
| 850 | Arch: arch, |
| 851 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 852 | } |
| 853 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 854 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 855 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 858 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 859 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 860 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 861 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 862 | } |
| 863 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 864 | if Bool(config.Host_bionic) { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 865 | addTarget(LinuxBionic, "x86_64", nil, nil, nil) |
| 866 | } |
| 867 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 868 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 869 | crossHostOs := osByName(*variables.CrossHost) |
| 870 | if crossHostOs == NoOsType { |
| 871 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 872 | } |
| 873 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 874 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 875 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 876 | } |
| 877 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 878 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 879 | |
| 880 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 881 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 885 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
| 886 | addTarget(Android, *variables.DeviceArch, variables.DeviceArchVariant, |
| 887 | variables.DeviceCpuVariant, variables.DeviceAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 888 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 889 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 890 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 891 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 892 | variables.DeviceSecondaryAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 893 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 894 | deviceArches := targets[Device] |
| 895 | if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib { |
| 896 | deviceArches[1].Arch.Native = false |
| 897 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 898 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 901 | if targetErr != nil { |
| 902 | return nil, targetErr |
| 903 | } |
| 904 | |
| 905 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 908 | // hasArmAbi returns true if arch has at least one arm ABI |
| 909 | func hasArmAbi(arch Arch) bool { |
| 910 | for _, abi := range arch.Abi { |
| 911 | if strings.HasPrefix(abi, "arm") { |
| 912 | return true |
| 913 | } |
| 914 | } |
| 915 | return false |
| 916 | } |
| 917 | |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 918 | // hasArmArch returns true if targets has at least arm Android arch |
| 919 | func hasArmAndroidArch(targets []Target) bool { |
| 920 | for _, target := range targets { |
| 921 | if target.Os == Android && target.Arch.ArchType == Arm { |
| 922 | return true |
| 923 | } |
| 924 | } |
| 925 | return false |
| 926 | } |
| 927 | |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 928 | // hasX86Arch returns true if targets has at least x86 Android arch |
| 929 | func hasX86AndroidArch(targets []Target) bool { |
| 930 | for _, target := range targets { |
| 931 | if target.Os == Android && target.Arch.ArchType == X86 { |
| 932 | return true |
| 933 | } |
| 934 | } |
| 935 | return false |
| 936 | } |
| 937 | |
| 938 | // hasX8664Arch returns true if targets has at least x86_64 Android arch |
| 939 | func hasX8664AndroidArch(targets []Target) bool { |
| 940 | for _, target := range targets { |
| 941 | if target.Os == Android && target.Arch.ArchType == X86_64 { |
| 942 | return true |
| 943 | } |
| 944 | } |
| 945 | return false |
| 946 | } |
| 947 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 948 | type archConfig struct { |
| 949 | arch string |
| 950 | archVariant string |
| 951 | cpuVariant string |
| 952 | abi []string |
| 953 | } |
| 954 | |
| 955 | func getMegaDeviceConfig() []archConfig { |
| 956 | return []archConfig{ |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 957 | {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}}, |
| 958 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 959 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 960 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 961 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 962 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 963 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 964 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 965 | {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 966 | {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 967 | {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 968 | {"arm", "armv7-a-neon", "denver", []string{"armeabi-v7a"}}, |
| 969 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Alex Naidis | ae4fc18 | 2016-08-20 00:14:56 +0200 | [diff] [blame] | 970 | {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 971 | {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 972 | {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 973 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 974 | {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 975 | {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 976 | {"arm64", "armv8-a", "denver64", []string{"arm64-v8a"}}, |
Alex Naidis | ac01ff5 | 2016-08-30 15:56:33 +0200 | [diff] [blame] | 977 | {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 978 | {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 979 | {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 980 | {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 981 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 982 | {"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 983 | {"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
Dan Willemsen | 65fb981 | 2016-07-19 21:37:28 -0700 | [diff] [blame] | 984 | //{"mips", "mips32r6", "", []string{"mips"}}, |
Colin Cross | 1837b80 | 2017-04-26 19:10:34 -0700 | [diff] [blame] | 985 | {"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 986 | {"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 987 | // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc |
| 988 | //{"mips64", "mips64r2", "", []string{"mips64"}}, |
| 989 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 990 | {"x86", "", "", []string{"x86"}}, |
| 991 | {"x86", "atom", "", []string{"x86"}}, |
| 992 | {"x86", "haswell", "", []string{"x86"}}, |
| 993 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 994 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 995 | {"x86", "silvermont", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 996 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 997 | {"x86_64", "", "", []string{"x86_64"}}, |
| 998 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 999 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 1000 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 1001 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
| 1002 | } |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1003 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1004 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1005 | func getNdkAbisConfig() []archConfig { |
| 1006 | return []archConfig{ |
Dan Albert | d3c8ca4 | 2017-12-20 14:48:39 -0800 | [diff] [blame] | 1007 | {"arm", "armv7-a", "", []string{"armeabi"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1008 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1009 | {"x86", "", "", []string{"x86"}}, |
| 1010 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | func decodeArchSettings(archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1015 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1016 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1017 | for _, config := range archConfigs { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1018 | arch, err := decodeArch(config.arch, &config.archVariant, |
| 1019 | &config.cpuVariant, &config.abi) |
| 1020 | if err != nil { |
| 1021 | return nil, err |
| 1022 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1023 | arch.Native = false |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1024 | ret = append(ret, Target{ |
| 1025 | Os: Android, |
| 1026 | Arch: arch, |
| 1027 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | return ret, nil |
| 1031 | } |
| 1032 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1033 | // Convert a set of strings from product variables into a single Arch struct |
| 1034 | func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) { |
| 1035 | stringPtr := func(p *string) string { |
| 1036 | if p != nil { |
| 1037 | return *p |
| 1038 | } |
| 1039 | return "" |
| 1040 | } |
| 1041 | |
| 1042 | slicePtr := func(p *[]string) []string { |
| 1043 | if p != nil { |
| 1044 | return *p |
| 1045 | } |
| 1046 | return nil |
| 1047 | } |
| 1048 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1049 | archType, ok := archTypeMap[arch] |
| 1050 | if !ok { |
| 1051 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1052 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1053 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1054 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1055 | ArchType: archType, |
| 1056 | ArchVariant: stringPtr(archVariant), |
| 1057 | CpuVariant: stringPtr(cpuVariant), |
| 1058 | Abi: slicePtr(abi), |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1059 | Native: true, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 1063 | a.ArchVariant = "" |
| 1064 | } |
| 1065 | |
| 1066 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 1067 | a.CpuVariant = "" |
| 1068 | } |
| 1069 | |
| 1070 | for i := 0; i < len(a.Abi); i++ { |
| 1071 | if a.Abi[i] == "" { |
| 1072 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1073 | i-- |
| 1074 | } |
| 1075 | } |
| 1076 | |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1077 | if featureMap, ok := archFeatureMap[archType]; ok { |
Dan Willemsen | b485099 | 2016-05-06 17:21:20 -0700 | [diff] [blame] | 1078 | a.ArchFeatures = featureMap[a.ArchVariant] |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1081 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1084 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 1085 | var ret []Target |
| 1086 | for _, t := range targets { |
| 1087 | if t.Arch.ArchType.Multilib == multilib { |
| 1088 | ret = append(ret, t) |
| 1089 | } |
| 1090 | } |
| 1091 | return ret |
| 1092 | } |
| 1093 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1094 | func getCommonTargets(targets []Target) []Target { |
| 1095 | var ret []Target |
| 1096 | set := make(map[string]bool) |
| 1097 | |
| 1098 | for _, t := range targets { |
| 1099 | if _, found := set[t.Os.String()]; !found { |
| 1100 | set[t.Os.String()] = true |
| 1101 | ret = append(ret, commonTargetMap[t.Os.String()]) |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | return ret |
| 1106 | } |
| 1107 | |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1108 | func firstTarget(targets []Target, filters ...string) []Target { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1109 | for _, filter := range filters { |
| 1110 | buildTargets := filterMultilibTargets(targets, filter) |
| 1111 | if len(buildTargets) > 0 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1112 | return buildTargets[:1] |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | return nil |
| 1116 | } |
| 1117 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1118 | // 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] | 1119 | func decodeMultilib(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1120 | buildTargets := []Target{} |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1121 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1122 | switch multilib { |
| 1123 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1124 | buildTargets = getCommonTargets(targets) |
| 1125 | case "common_first": |
| 1126 | buildTargets = getCommonTargets(targets) |
| 1127 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1128 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1129 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1130 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1131 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1132 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1133 | if prefer32 { |
| 1134 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1135 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1136 | } else { |
| 1137 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1138 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1139 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1140 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1141 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1142 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1143 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1144 | case "first": |
| 1145 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1146 | buildTargets = firstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1147 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1148 | buildTargets = firstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1149 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1150 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1151 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1152 | if len(buildTargets) == 0 { |
| 1153 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1154 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1155 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1156 | 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] | 1157 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1160 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1161 | } |