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