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