blob: 952b72072b9e8fee5e4a59559b95577336dad707 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross3f40fa42015-01-30 17:27:36 -080018 "fmt"
19 "reflect"
20 "runtime"
21 "strings"
Colin Crossf6566ed2015-03-24 11:13:38 -070022
23 "github.com/google/blueprint"
24 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080025)
26
Colin Cross463a90e2015-06-17 14:20:06 -070027func init() {
Colin Crosscfad1192015-11-02 16:43:11 -080028 RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator)
29 RegisterTopDownMutator("defaults", defaultsMutator)
30
Colin Cross6362e272015-10-29 15:25:03 -070031 RegisterBottomUpMutator("host_or_device", HostOrDeviceMutator)
Dan Willemsen490fd492015-11-24 17:53:15 -080032 RegisterBottomUpMutator("host_type", HostTypeMutator)
Colin Cross6362e272015-10-29 15:25:03 -070033 RegisterBottomUpMutator("arch", ArchMutator)
Colin Cross463a90e2015-06-17 14:20:06 -070034}
35
Colin Cross3f40fa42015-01-30 17:27:36 -080036var (
Colin Crossec193632015-07-06 17:49:43 -070037 Arm = newArch("arm", "lib32")
38 Arm64 = newArch("arm64", "lib64")
39 Mips = newArch("mips", "lib32")
40 Mips64 = newArch("mips64", "lib64")
41 X86 = newArch("x86", "lib32")
42 X86_64 = newArch("x86_64", "lib64")
Colin Cross2fe66872015-03-30 17:20:39 -070043
44 Common = ArchType{
45 Name: "common",
46 }
Colin Cross3f40fa42015-01-30 17:27:36 -080047)
48
Colin Cross4225f652015-09-17 14:33:42 -070049var archTypeMap = map[string]ArchType{
50 "arm": Arm,
51 "arm64": Arm64,
52 "mips": Mips,
Colin Cross3b336c22015-11-23 16:28:31 -080053 "mips64": Mips64,
Colin Cross4225f652015-09-17 14:33:42 -070054 "x86": X86,
55 "x86_64": X86_64,
56}
57
Colin Cross3f40fa42015-01-30 17:27:36 -080058/*
59Example blueprints file containing all variant property groups, with comment listing what type
60of variants get properties in that group:
61
62module {
63 arch: {
64 arm: {
65 // Host or device variants with arm architecture
66 },
67 arm64: {
68 // Host or device variants with arm64 architecture
69 },
70 mips: {
71 // Host or device variants with mips architecture
72 },
73 mips64: {
74 // Host or device variants with mips64 architecture
75 },
76 x86: {
77 // Host or device variants with x86 architecture
78 },
79 x86_64: {
80 // Host or device variants with x86_64 architecture
81 },
82 },
83 multilib: {
84 lib32: {
85 // Host or device variants for 32-bit architectures
86 },
87 lib64: {
88 // Host or device variants for 64-bit architectures
89 },
90 },
91 target: {
92 android: {
93 // Device variants
94 },
95 host: {
96 // Host variants
97 },
98 linux: {
99 // Linux host variants
100 },
101 darwin: {
102 // Darwin host variants
103 },
104 windows: {
105 // Windows host variants
106 },
107 not_windows: {
108 // Non-windows host variants
109 },
110 },
111}
112*/
Colin Cross7d5136f2015-05-11 13:39:40 -0700113
Colin Cross85a88972015-11-23 13:29:51 -0800114type Embed interface{}
115
Colin Cross3f40fa42015-01-30 17:27:36 -0800116type archProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700117 // Properties to vary by target architecture
Colin Cross3f40fa42015-01-30 17:27:36 -0800118 Arch struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700119 // Properties for module variants being built to run on arm (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800120 Arm struct {
121 Embed `blueprint:"filter(android:\"arch_variant\")"`
122
123 // Arm arch variants
124 Armv5te interface{} `blueprint:"filter(android:\"arch_variant\")"`
125 Armv7_a interface{} `blueprint:"filter(android:\"arch_variant\")"`
126 Armv7_a_neon interface{} `blueprint:"filter(android:\"arch_variant\")"`
127
128 // Arm cpu variants
129 Cortex_a7 interface{} `blueprint:"filter(android:\"arch_variant\")"`
130 Cortex_a8 interface{} `blueprint:"filter(android:\"arch_variant\")"`
131 Cortex_a9 interface{} `blueprint:"filter(android:\"arch_variant\")"`
132 Cortex_a15 interface{} `blueprint:"filter(android:\"arch_variant\")"`
133 Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"`
134 Cortex_a53_a57 interface{} `blueprint:"filter(android:\"arch_variant\")"`
135 Krait interface{} `blueprint:"filter(android:\"arch_variant\")"`
136 Denver interface{} `blueprint:"filter(android:\"arch_variant\")"`
137 }
138
Colin Cross7d5136f2015-05-11 13:39:40 -0700139 // Properties for module variants being built to run on arm64 (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800140 Arm64 struct {
141 Embed `blueprint:"filter(android:\"arch_variant\")"`
142
143 // Arm64 arch variants
144 Armv8_a interface{} `blueprint:"filter(android:\"arch_variant\")"`
145
146 // Arm64 cpu variants
147 Cortex_a53 interface{} `blueprint:"filter(android:\"arch_variant\")"`
148 Denver64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
149 }
150
Colin Cross7d5136f2015-05-11 13:39:40 -0700151 // Properties for module variants being built to run on mips (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800152 Mips struct {
153 Embed `blueprint:"filter(android:\"arch_variant\")"`
154
155 // Mips arch variants
Colin Cross023f1e82015-11-23 16:15:10 -0800156 Mips32_fp interface{} `blueprint:"filter(android:\"arch_variant\")"`
157 Mips32r2_fp interface{} `blueprint:"filter(android:\"arch_variant\")"`
158 Mips32r2_fp_xburst interface{} `blueprint:"filter(android:\"arch_variant\")"`
159 Mips32r2dsp_fp interface{} `blueprint:"filter(android:\"arch_variant\")"`
160 Mips32r2dspr2_fp interface{} `blueprint:"filter(android:\"arch_variant\")"`
161 Mips32r6 interface{} `blueprint:"filter(android:\"arch_variant\")"`
162
163 // Mips arch features
Colin Cross85a88972015-11-23 13:29:51 -0800164 Rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"`
165 }
166
Colin Cross7d5136f2015-05-11 13:39:40 -0700167 // Properties for module variants being built to run on mips64 (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800168 Mips64 struct {
169 Embed `blueprint:"filter(android:\"arch_variant\")"`
170
171 // Mips64 arch variants
Colin Cross3b336c22015-11-23 16:28:31 -0800172 Mips64r2 interface{} `blueprint:"filter(android:\"arch_variant\")"`
173 Mips64r6 interface{} `blueprint:"filter(android:\"arch_variant\")"`
174
175 // Mips64 arch features
Colin Cross85a88972015-11-23 13:29:51 -0800176 Rev6 interface{} `blueprint:"filter(android:\"arch_variant\")"`
177 }
178
Colin Cross7d5136f2015-05-11 13:39:40 -0700179 // Properties for module variants being built to run on x86 (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800180 X86 struct {
181 Embed `blueprint:"filter(android:\"arch_variant\")"`
182
183 // X86 arch variants
Colin Crossb0cba6a2015-11-20 15:35:26 -0800184 Atom interface{} `blueprint:"filter(android:\"arch_variant\")"`
185 Haswell interface{} `blueprint:"filter(android:\"arch_variant\")"`
186 Ivybridge interface{} `blueprint:"filter(android:\"arch_variant\")"`
187 Sandybridge interface{} `blueprint:"filter(android:\"arch_variant\")"`
188 Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"`
Dan Willemsen8a354052016-05-10 14:30:51 -0700189 // Generic variant for X86 on X86_64
Colin Cross635c3b02016-05-18 15:37:25 -0700190 X86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross85a88972015-11-23 13:29:51 -0800191
192 // X86 arch features
Colin Crossb0cba6a2015-11-20 15:35:26 -0800193 Ssse3 interface{} `blueprint:"filter(android:\"arch_variant\")"`
194 Sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"`
195 Sse4_1 interface{} `blueprint:"filter(android:\"arch_variant\")"`
196 Sse4_2 interface{} `blueprint:"filter(android:\"arch_variant\")"`
197 Aes_ni interface{} `blueprint:"filter(android:\"arch_variant\")"`
198 Avx interface{} `blueprint:"filter(android:\"arch_variant\")"`
199 Popcnt interface{} `blueprint:"filter(android:\"arch_variant\")"`
200 Movbe interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross85a88972015-11-23 13:29:51 -0800201 }
202
Colin Cross7d5136f2015-05-11 13:39:40 -0700203 // Properties for module variants being built to run on x86_64 (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800204 X86_64 struct {
205 Embed `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross6371b382015-11-23 14:53:57 -0800206
207 // X86 arch variants
208 Haswell interface{} `blueprint:"filter(android:\"arch_variant\")"`
209 Ivybridge interface{} `blueprint:"filter(android:\"arch_variant\")"`
210 Sandybridge interface{} `blueprint:"filter(android:\"arch_variant\")"`
211 Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"`
212
213 // X86 arch features
214 Ssse3 interface{} `blueprint:"filter(android:\"arch_variant\")"`
215 Sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"`
216 Sse4_1 interface{} `blueprint:"filter(android:\"arch_variant\")"`
217 Sse4_2 interface{} `blueprint:"filter(android:\"arch_variant\")"`
218 Aes_ni interface{} `blueprint:"filter(android:\"arch_variant\")"`
219 Avx interface{} `blueprint:"filter(android:\"arch_variant\")"`
220 Popcnt interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross85a88972015-11-23 13:29:51 -0800221 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800222 }
Colin Crossec193632015-07-06 17:49:43 -0700223
Colin Cross7d5136f2015-05-11 13:39:40 -0700224 // Properties to vary by 32-bit or 64-bit
Colin Cross3f40fa42015-01-30 17:27:36 -0800225 Multilib struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700226 // Properties for module variants being built to run on 32-bit devices
227 Lib32 interface{} `blueprint:"filter(android:\"arch_variant\")"`
228 // Properties for module variants being built to run on 64-bit devices
229 Lib64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800230 }
Colin Cross7d5136f2015-05-11 13:39:40 -0700231 // Properties to vary by build target (host or device, os, os+archictecture)
Colin Cross3f40fa42015-01-30 17:27:36 -0800232 Target struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700233 // Properties for module variants being built to run on the host
234 Host interface{} `blueprint:"filter(android:\"arch_variant\")"`
235 // Properties for module variants being built to run on the device
236 Android interface{} `blueprint:"filter(android:\"arch_variant\")"`
237 // Properties for module variants being built to run on arm devices
238 Android_arm interface{} `blueprint:"filter(android:\"arch_variant\")"`
239 // Properties for module variants being built to run on arm64 devices
240 Android_arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
241 // Properties for module variants being built to run on mips devices
242 Android_mips interface{} `blueprint:"filter(android:\"arch_variant\")"`
243 // Properties for module variants being built to run on mips64 devices
244 Android_mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
245 // Properties for module variants being built to run on x86 devices
246 Android_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
247 // Properties for module variants being built to run on x86_64 devices
248 Android_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
249 // Properties for module variants being built to run on devices that support 64-bit
250 Android64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
251 // Properties for module variants being built to run on devices that do not support 64-bit
252 Android32 interface{} `blueprint:"filter(android:\"arch_variant\")"`
253 // Properties for module variants being built to run on linux hosts
254 Linux interface{} `blueprint:"filter(android:\"arch_variant\")"`
255 // Properties for module variants being built to run on linux x86 hosts
256 Linux_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
257 // Properties for module variants being built to run on linux x86_64 hosts
258 Linux_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
259 // Properties for module variants being built to run on darwin hosts
260 Darwin interface{} `blueprint:"filter(android:\"arch_variant\")"`
261 // Properties for module variants being built to run on darwin x86 hosts
262 Darwin_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
263 // Properties for module variants being built to run on darwin x86_64 hosts
264 Darwin_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
265 // Properties for module variants being built to run on windows hosts
266 Windows interface{} `blueprint:"filter(android:\"arch_variant\")"`
Dan Willemsen490fd492015-11-24 17:53:15 -0800267 // Properties for module variants being built to run on windows x86 hosts
268 Windows_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Dan Willemsen07cd0512016-02-03 23:16:33 -0800269 // Properties for module variants being built to run on windows x86_64 hosts
270 Windows_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700271 // Properties for module variants being built to run on linux or darwin hosts
272 Not_windows interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800273 }
274}
275
Colin Crossc5c24ad2015-11-20 15:35:00 -0800276var archFeatureMap = map[ArchType]map[string][]string{}
277
278func RegisterArchFeatures(arch ArchType, variant string, features ...string) {
Colin Cross85a88972015-11-23 13:29:51 -0800279 archField := proptools.FieldNameForProperty(arch.Name)
280 variantField := proptools.FieldNameForProperty(variant)
281 archStruct := reflect.ValueOf(archProperties{}.Arch).FieldByName(archField)
Colin Crossc5c24ad2015-11-20 15:35:00 -0800282 if variant != "" {
Colin Cross85a88972015-11-23 13:29:51 -0800283 if !archStruct.FieldByName(variantField).IsValid() {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800284 panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch))
285 }
286 }
287 for _, feature := range features {
288 field := proptools.FieldNameForProperty(feature)
Colin Cross85a88972015-11-23 13:29:51 -0800289 if !archStruct.FieldByName(field).IsValid() {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800290 panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant))
291 }
292 }
293 if archFeatureMap[arch] == nil {
294 archFeatureMap[arch] = make(map[string][]string)
295 }
296 archFeatureMap[arch][variant] = features
297}
298
Colin Cross3f40fa42015-01-30 17:27:36 -0800299// An Arch indicates a single CPU architecture.
300type Arch struct {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800301 ArchType ArchType
302 ArchVariant string
303 CpuVariant string
304 Abi []string
305 ArchFeatures []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800306}
307
308func (a Arch) String() string {
Colin Crossd3ba0392015-05-07 14:11:29 -0700309 s := a.ArchType.String()
Colin Cross3f40fa42015-01-30 17:27:36 -0800310 if a.ArchVariant != "" {
311 s += "_" + a.ArchVariant
312 }
313 if a.CpuVariant != "" {
314 s += "_" + a.CpuVariant
315 }
316 return s
317}
318
319type ArchType struct {
Colin Crossec193632015-07-06 17:49:43 -0700320 Name string
321 Multilib string
Colin Cross3f40fa42015-01-30 17:27:36 -0800322}
323
Colin Crossec193632015-07-06 17:49:43 -0700324func newArch(name, multilib string) ArchType {
Colin Cross3f40fa42015-01-30 17:27:36 -0800325 return ArchType{
Colin Crossec193632015-07-06 17:49:43 -0700326 Name: name,
327 Multilib: multilib,
Colin Cross3f40fa42015-01-30 17:27:36 -0800328 }
329}
330
331func (a ArchType) String() string {
332 return a.Name
333}
334
335type HostOrDeviceSupported int
336
337const (
338 _ HostOrDeviceSupported = iota
339 HostSupported
340 DeviceSupported
341 HostAndDeviceSupported
Dan Willemsen218f6562015-07-08 18:13:11 -0700342 HostAndDeviceDefault
Colin Cross3f40fa42015-01-30 17:27:36 -0800343)
344
345type HostOrDevice int
346
347const (
348 _ HostOrDevice = iota
349 Host
350 Device
351)
352
353func (hod HostOrDevice) String() string {
354 switch hod {
355 case Device:
356 return "device"
357 case Host:
358 return "host"
359 default:
360 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
361 }
362}
363
Colin Crossec193632015-07-06 17:49:43 -0700364func (hod HostOrDevice) Property() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800365 switch hod {
366 case Device:
367 return "android"
368 case Host:
369 return "host"
370 default:
371 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
372 }
373}
374
Colin Cross3f40fa42015-01-30 17:27:36 -0800375func (hod HostOrDevice) Host() bool {
376 if hod == 0 {
377 panic("HostOrDevice unset")
378 }
379 return hod == Host
380}
381
382func (hod HostOrDevice) Device() bool {
383 if hod == 0 {
384 panic("HostOrDevice unset")
385 }
386 return hod == Device
387}
388
389var hostOrDeviceName = map[HostOrDevice]string{
390 Device: "device",
391 Host: "host",
392}
393
Dan Willemsen490fd492015-11-24 17:53:15 -0800394type HostType int
395
396const (
397 NoHostType HostType = iota
398 Linux
399 Darwin
400 Windows
401)
402
403func CurrentHostType() HostType {
404 switch runtime.GOOS {
405 case "linux":
406 return Linux
407 case "darwin":
408 return Darwin
409 default:
410 panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
411 }
412}
413
414func (ht HostType) String() string {
415 switch ht {
416 case Linux:
417 return "linux"
418 case Darwin:
419 return "darwin"
420 case Windows:
421 return "windows"
422 default:
423 panic(fmt.Sprintf("unexpected HostType value %d", ht))
424 }
425}
426
427func (ht HostType) Field() string {
428 switch ht {
429 case Linux:
430 return "Linux"
431 case Darwin:
432 return "Darwin"
433 case Windows:
434 return "Windows"
435 default:
436 panic(fmt.Sprintf("unexpected HostType value %d", ht))
437 }
438}
439
Colin Cross3f40fa42015-01-30 17:27:36 -0800440var (
Colin Crossd3ba0392015-05-07 14:11:29 -0700441 commonArch = Arch{
442 ArchType: Common,
Colin Cross2fe66872015-03-30 17:20:39 -0700443 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800444)
445
Colin Cross635c3b02016-05-18 15:37:25 -0700446func HostOrDeviceMutator(mctx BottomUpMutatorContext) {
447 var module Module
Colin Crossd3ba0392015-05-07 14:11:29 -0700448 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700449 if module, ok = mctx.Module().(Module); !ok {
Colin Crossd3ba0392015-05-07 14:11:29 -0700450 return
451 }
452
453 hods := []HostOrDevice{}
454
455 if module.base().HostSupported() {
456 hods = append(hods, Host)
457 }
458
459 if module.base().DeviceSupported() {
460 hods = append(hods, Device)
461 }
462
463 if len(hods) == 0 {
464 return
465 }
466
467 hodNames := []string{}
468 for _, hod := range hods {
469 hodNames = append(hodNames, hod.String())
470 }
471
472 modules := mctx.CreateVariations(hodNames...)
473 for i, m := range modules {
Colin Cross635c3b02016-05-18 15:37:25 -0700474 m.(Module).base().SetHostOrDevice(hods[i])
Colin Crossd3ba0392015-05-07 14:11:29 -0700475 }
476}
477
Colin Cross635c3b02016-05-18 15:37:25 -0700478func HostTypeMutator(mctx BottomUpMutatorContext) {
479 var module Module
Dan Willemsen490fd492015-11-24 17:53:15 -0800480 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700481 if module, ok = mctx.Module().(Module); !ok {
Dan Willemsen490fd492015-11-24 17:53:15 -0800482 return
483 }
484
485 if !module.base().HostSupported() || !module.base().HostOrDevice().Host() {
486 return
487 }
488
489 buildTypes, err := decodeHostTypesProductVariables(mctx.Config().(Config).ProductVariables)
490 if err != nil {
491 mctx.ModuleErrorf("%s", err.Error())
492 return
493 }
494
495 typeNames := []string{}
496 for _, ht := range buildTypes {
497 typeNames = append(typeNames, ht.String())
498 }
499
500 modules := mctx.CreateVariations(typeNames...)
501 for i, m := range modules {
Colin Cross635c3b02016-05-18 15:37:25 -0700502 m.(Module).base().SetHostType(buildTypes[i])
Dan Willemsen490fd492015-11-24 17:53:15 -0800503 }
504}
505
Colin Cross635c3b02016-05-18 15:37:25 -0700506func ArchMutator(mctx BottomUpMutatorContext) {
507 var module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800508 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700509 if module, ok = mctx.Module().(Module); !ok {
Colin Cross3f40fa42015-01-30 17:27:36 -0800510 return
511 }
512
Colin Cross4225f652015-09-17 14:33:42 -0700513 moduleArches := []Arch{}
514 multilib := module.base().commonProperties.Compile_multilib
Colin Cross3f40fa42015-01-30 17:27:36 -0800515
Colin Crossd3ba0392015-05-07 14:11:29 -0700516 if module.base().HostSupported() && module.base().HostOrDevice().Host() {
Dan Willemsen218f6562015-07-08 18:13:11 -0700517 hostModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).HostArches[module.base().HostType()])
Colin Cross4225f652015-09-17 14:33:42 -0700518 if err != nil {
519 mctx.ModuleErrorf("%s", err.Error())
Colin Cross2fe66872015-03-30 17:20:39 -0700520 }
Colin Cross4225f652015-09-17 14:33:42 -0700521
522 moduleArches = append(moduleArches, hostModuleArches...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800523 }
524
Colin Crossd3ba0392015-05-07 14:11:29 -0700525 if module.base().DeviceSupported() && module.base().HostOrDevice().Device() {
Dan Willemsen218f6562015-07-08 18:13:11 -0700526 deviceModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).DeviceArches)
Colin Cross4225f652015-09-17 14:33:42 -0700527 if err != nil {
528 mctx.ModuleErrorf("%s", err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800529 }
Colin Cross4225f652015-09-17 14:33:42 -0700530
531 moduleArches = append(moduleArches, deviceModuleArches...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800532 }
533
Colin Cross4225f652015-09-17 14:33:42 -0700534 if len(moduleArches) == 0 {
Colin Cross5049f022015-03-18 13:28:46 -0700535 return
536 }
537
Colin Cross3f40fa42015-01-30 17:27:36 -0800538 archNames := []string{}
Colin Cross4225f652015-09-17 14:33:42 -0700539 for _, arch := range moduleArches {
Colin Cross3f40fa42015-01-30 17:27:36 -0800540 archNames = append(archNames, arch.String())
541 }
542
543 modules := mctx.CreateVariations(archNames...)
544
545 for i, m := range modules {
Colin Cross635c3b02016-05-18 15:37:25 -0700546 m.(Module).base().SetArch(moduleArches[i])
547 m.(Module).base().setArchProperties(mctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800548 }
549}
550
Colin Cross635c3b02016-05-18 15:37:25 -0700551func InitArchModule(m Module,
Colin Cross3f40fa42015-01-30 17:27:36 -0800552 propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
553
554 base := m.base()
555
Colin Cross3f40fa42015-01-30 17:27:36 -0800556 base.generalProperties = append(base.generalProperties,
Colin Cross3f40fa42015-01-30 17:27:36 -0800557 propertyStructs...)
558
559 for _, properties := range base.generalProperties {
560 propertiesValue := reflect.ValueOf(properties)
561 if propertiesValue.Kind() != reflect.Ptr {
Colin Crossca860ac2016-01-04 14:34:37 -0800562 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
563 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800564 }
565
566 propertiesValue = propertiesValue.Elem()
567 if propertiesValue.Kind() != reflect.Struct {
Colin Crossca860ac2016-01-04 14:34:37 -0800568 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
569 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800570 }
571
572 archProperties := &archProperties{}
573 forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) {
Colin Cross3ab7d882015-05-19 13:03:01 -0700574 newValue := proptools.CloneEmptyProperties(propertiesValue)
Colin Cross3f40fa42015-01-30 17:27:36 -0800575 v.Set(newValue)
576 })
577
578 base.archProperties = append(base.archProperties, archProperties)
579 }
580
581 var allProperties []interface{}
582 allProperties = append(allProperties, base.generalProperties...)
583 for _, asp := range base.archProperties {
584 allProperties = append(allProperties, asp)
585 }
586
587 return m, allProperties
588}
589
Colin Crossa716add2015-12-16 11:07:39 -0800590var variantReplacer = strings.NewReplacer("-", "_", ".", "_")
Colin Crossec193632015-07-06 17:49:43 -0700591
Colin Cross635c3b02016-05-18 15:37:25 -0700592func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext,
Colin Cross85a88972015-11-23 13:29:51 -0800593 dst, src interface{}, field, srcPrefix string) interface{} {
Colin Cross06a931b2015-10-28 17:23:31 -0700594
Colin Crosseeabb892015-11-20 13:07:51 -0800595 srcField := reflect.ValueOf(src).FieldByName(field)
596 if !srcField.IsValid() {
597 ctx.ModuleErrorf("field %q does not exist", srcPrefix)
Colin Cross85a88972015-11-23 13:29:51 -0800598 return nil
599 }
600
601 ret := srcField
602
603 if srcField.Kind() == reflect.Struct {
604 srcField = srcField.FieldByName("Embed")
Colin Crosseeabb892015-11-20 13:07:51 -0800605 }
606
607 src = srcField.Elem().Interface()
Colin Cross06a931b2015-10-28 17:23:31 -0700608
609 filter := func(property string,
610 dstField, srcField reflect.StructField,
611 dstValue, srcValue interface{}) (bool, error) {
612
613 srcProperty := srcPrefix + "." + property
614
615 if !proptools.HasTag(dstField, "android", "arch_variant") {
616 if ctx.ContainsProperty(srcProperty) {
617 return false, fmt.Errorf("can't be specific to a build variant")
618 } else {
619 return false, nil
620 }
621 }
622
623 return true, nil
624 }
625
Colin Cross6ee75b62016-05-05 15:57:15 -0700626 order := func(property string,
627 dstField, srcField reflect.StructField,
628 dstValue, srcValue interface{}) (proptools.Order, error) {
629 if proptools.HasTag(dstField, "android", "variant_prepend") {
630 return proptools.Prepend, nil
631 } else {
632 return proptools.Append, nil
633 }
634 }
635
636 err := proptools.ExtendProperties(dst, src, filter, order)
Colin Cross06a931b2015-10-28 17:23:31 -0700637 if err != nil {
638 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
639 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
640 } else {
641 panic(err)
642 }
643 }
Colin Cross85a88972015-11-23 13:29:51 -0800644
645 return ret.Interface()
Colin Cross06a931b2015-10-28 17:23:31 -0700646}
647
Colin Cross3f40fa42015-01-30 17:27:36 -0800648// Rewrite the module's properties structs to contain arch-specific values.
Colin Cross635c3b02016-05-18 15:37:25 -0700649func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
Colin Crossd3ba0392015-05-07 14:11:29 -0700650 arch := a.commonProperties.CompileArch
651 hod := a.commonProperties.CompileHostOrDevice
Dan Willemsen490fd492015-11-24 17:53:15 -0800652 ht := a.commonProperties.CompileHostType
Colin Crossd3ba0392015-05-07 14:11:29 -0700653
Colin Cross2fe66872015-03-30 17:20:39 -0700654 if arch.ArchType == Common {
655 return
656 }
657
Colin Cross3f40fa42015-01-30 17:27:36 -0800658 for i := range a.generalProperties {
Colin Cross06a931b2015-10-28 17:23:31 -0700659 genProps := a.generalProperties[i]
660 archProps := a.archProperties[i]
Colin Cross3f40fa42015-01-30 17:27:36 -0800661 // Handle arch-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700662 // arch: {
663 // arm64: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800664 // key: value,
665 // },
666 // },
667 t := arch.ArchType
Colin Cross06a931b2015-10-28 17:23:31 -0700668
Colin Crossec193632015-07-06 17:49:43 -0700669 field := proptools.FieldNameForProperty(t.Name)
Colin Cross06a931b2015-10-28 17:23:31 -0700670 prefix := "arch." + t.Name
Colin Cross85a88972015-11-23 13:29:51 -0800671 archStruct := a.appendProperties(ctx, genProps, archProps.Arch, field, prefix)
Colin Crossec193632015-07-06 17:49:43 -0700672
673 // Handle arch-variant-specific properties in the form:
674 // arch: {
675 // variant: {
676 // key: value,
677 // },
678 // },
Colin Crossa716add2015-12-16 11:07:39 -0800679 v := variantReplacer.Replace(arch.ArchVariant)
Colin Crossec193632015-07-06 17:49:43 -0700680 if v != "" {
681 field := proptools.FieldNameForProperty(v)
Colin Cross85a88972015-11-23 13:29:51 -0800682 prefix := "arch." + t.Name + "." + v
683 a.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossec193632015-07-06 17:49:43 -0700684 }
685
686 // Handle cpu-variant-specific properties in the form:
687 // arch: {
688 // variant: {
689 // key: value,
690 // },
691 // },
Colin Crossa716add2015-12-16 11:07:39 -0800692 c := variantReplacer.Replace(arch.CpuVariant)
Colin Crossec193632015-07-06 17:49:43 -0700693 if c != "" {
694 field := proptools.FieldNameForProperty(c)
Colin Cross85a88972015-11-23 13:29:51 -0800695 prefix := "arch." + t.Name + "." + c
696 a.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossec193632015-07-06 17:49:43 -0700697 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800698
Colin Crossc5c24ad2015-11-20 15:35:00 -0800699 // Handle arch-feature-specific properties in the form:
700 // arch: {
701 // feature: {
702 // key: value,
703 // },
704 // },
705 for _, feature := range arch.ArchFeatures {
706 field := proptools.FieldNameForProperty(feature)
Colin Cross85a88972015-11-23 13:29:51 -0800707 prefix := "arch." + t.Name + "." + feature
708 a.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc5c24ad2015-11-20 15:35:00 -0800709 }
710
Colin Cross3f40fa42015-01-30 17:27:36 -0800711 // Handle multilib-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700712 // multilib: {
713 // lib32: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800714 // key: value,
715 // },
716 // },
Colin Cross06a931b2015-10-28 17:23:31 -0700717 field = proptools.FieldNameForProperty(t.Multilib)
718 prefix = "multilib." + t.Multilib
719 a.appendProperties(ctx, genProps, archProps.Multilib, field, prefix)
Colin Cross3f40fa42015-01-30 17:27:36 -0800720
721 // Handle host-or-device-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700722 // target: {
723 // host: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800724 // key: value,
725 // },
726 // },
Colin Crossec193632015-07-06 17:49:43 -0700727 hodProperty := hod.Property()
Colin Cross06a931b2015-10-28 17:23:31 -0700728 field = proptools.FieldNameForProperty(hodProperty)
729 prefix = "target." + hodProperty
730 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Cross3f40fa42015-01-30 17:27:36 -0800731
732 // Handle host target properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700733 // target: {
734 // linux: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800735 // key: value,
736 // },
Colin Crossb05bff22015-04-30 15:08:04 -0700737 // not_windows: {
738 // key: value,
739 // },
740 // linux_x86: {
741 // key: value,
742 // },
743 // linux_arm: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800744 // key: value,
745 // },
746 // },
Colin Cross3f40fa42015-01-30 17:27:36 -0800747 if hod.Host() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800748 field := ht.Field()
749 prefix := "target." + ht.String()
Colin Cross06a931b2015-10-28 17:23:31 -0700750 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Dan Willemsen490fd492015-11-24 17:53:15 -0800751
752 t := arch.ArchType
753 field = ht.Field() + "_" + t.Name
754 prefix = "target." + ht.String() + "_" + t.Name
755 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
756
757 if ht != Windows {
758 field := "Not_windows"
759 prefix := "target.not_windows"
760 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
761 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800762 }
763
Colin Crossf8209412015-03-26 14:44:26 -0700764 // Handle 64-bit device properties in the form:
765 // target {
766 // android64 {
767 // key: value,
768 // },
769 // android32 {
770 // key: value,
771 // },
772 // },
773 // WARNING: this is probably not what you want to use in your blueprints file, it selects
774 // options for all targets on a device that supports 64-bit binaries, not just the targets
775 // that are being compiled for 64-bit. Its expected use case is binaries like linker and
776 // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
777 if hod.Device() {
778 if true /* && target_is_64_bit */ {
Colin Cross06a931b2015-10-28 17:23:31 -0700779 field := "Android64"
780 prefix := "target.android64"
781 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Crossf8209412015-03-26 14:44:26 -0700782 } else {
Colin Cross06a931b2015-10-28 17:23:31 -0700783 field := "Android32"
784 prefix := "target.android32"
785 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Crossf8209412015-03-26 14:44:26 -0700786 }
787 }
Colin Crossb05bff22015-04-30 15:08:04 -0700788
789 // Handle device architecture properties in the form:
790 // target {
791 // android_arm {
792 // key: value,
793 // },
794 // android_x86 {
795 // key: value,
796 // },
797 // },
798 if hod.Device() {
799 t := arch.ArchType
Colin Cross06a931b2015-10-28 17:23:31 -0700800 field := "Android_" + t.Name
801 prefix := "target.android_" + t.Name
802 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Crossb05bff22015-04-30 15:08:04 -0700803 }
804
Colin Cross3f40fa42015-01-30 17:27:36 -0800805 if ctx.Failed() {
806 return
807 }
808 }
809}
810
811func forEachInterface(v reflect.Value, f func(reflect.Value)) {
812 switch v.Kind() {
813 case reflect.Interface:
814 f(v)
815 case reflect.Struct:
816 for i := 0; i < v.NumField(); i++ {
817 forEachInterface(v.Field(i), f)
818 }
819 case reflect.Ptr:
820 forEachInterface(v.Elem(), f)
821 default:
822 panic(fmt.Errorf("Unsupported kind %s", v.Kind()))
823 }
824}
Colin Cross4225f652015-09-17 14:33:42 -0700825
Dan Willemsen490fd492015-11-24 17:53:15 -0800826// Get a list of HostTypes from the product variables
827func decodeHostTypesProductVariables(variables productVariables) ([]HostType, error) {
828 ret := []HostType{CurrentHostType()}
829
830 if variables.CrossHost != nil && *variables.CrossHost != "" {
831 switch *variables.CrossHost {
832 case "windows":
833 ret = append(ret, Windows)
834 default:
835 return nil, fmt.Errorf("Unsupported secondary host: %s", *variables.CrossHost)
836 }
837 }
838
839 return ret, nil
840}
841
Colin Cross4225f652015-09-17 14:33:42 -0700842// Convert the arch product variables into a list of host and device Arch structs
Dan Willemsen490fd492015-11-24 17:53:15 -0800843func decodeArchProductVariables(variables productVariables) (map[HostType][]Arch, []Arch, error) {
Colin Cross4225f652015-09-17 14:33:42 -0700844 if variables.HostArch == nil {
845 return nil, nil, fmt.Errorf("No host primary architecture set")
846 }
847
848 hostArch, err := decodeArch(*variables.HostArch, nil, nil, nil)
849 if err != nil {
850 return nil, nil, err
851 }
852
853 hostArches := []Arch{hostArch}
854
Colin Crosseeabb892015-11-20 13:07:51 -0800855 if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
Colin Cross4225f652015-09-17 14:33:42 -0700856 hostSecondaryArch, err := decodeArch(*variables.HostSecondaryArch, nil, nil, nil)
857 if err != nil {
858 return nil, nil, err
859 }
860 hostArches = append(hostArches, hostSecondaryArch)
861 }
862
Dan Willemsen490fd492015-11-24 17:53:15 -0800863 hostTypeArches := map[HostType][]Arch{
864 CurrentHostType(): hostArches,
865 }
866
867 if variables.CrossHost != nil && *variables.CrossHost != "" {
868 if variables.CrossHostArch == nil || *variables.CrossHostArch == "" {
869 return nil, nil, fmt.Errorf("No cross-host primary architecture set")
870 }
871
872 crossHostArch, err := decodeArch(*variables.CrossHostArch, nil, nil, nil)
873 if err != nil {
874 return nil, nil, err
875 }
876
877 crossHostArches := []Arch{crossHostArch}
878
879 if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
880 crossHostSecondaryArch, err := decodeArch(*variables.CrossHostSecondaryArch, nil, nil, nil)
881 if err != nil {
882 return nil, nil, err
883 }
884 crossHostArches = append(crossHostArches, crossHostSecondaryArch)
885 }
886
887 switch *variables.CrossHost {
888 case "windows":
889 hostTypeArches[Windows] = crossHostArches
890 default:
891 return nil, nil, fmt.Errorf("Unsupported cross-host: %s", *variables.CrossHost)
892 }
893 }
894
Colin Cross4225f652015-09-17 14:33:42 -0700895 if variables.DeviceArch == nil {
896 return nil, nil, fmt.Errorf("No device primary architecture set")
897 }
898
899 deviceArch, err := decodeArch(*variables.DeviceArch, variables.DeviceArchVariant,
900 variables.DeviceCpuVariant, variables.DeviceAbi)
901 if err != nil {
902 return nil, nil, err
903 }
904
905 deviceArches := []Arch{deviceArch}
906
Colin Crosseeabb892015-11-20 13:07:51 -0800907 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
Colin Cross4225f652015-09-17 14:33:42 -0700908 deviceSecondaryArch, err := decodeArch(*variables.DeviceSecondaryArch,
909 variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
910 variables.DeviceSecondaryAbi)
911 if err != nil {
912 return nil, nil, err
913 }
914 deviceArches = append(deviceArches, deviceSecondaryArch)
915 }
916
Dan Willemsen490fd492015-11-24 17:53:15 -0800917 return hostTypeArches, deviceArches, nil
Colin Cross4225f652015-09-17 14:33:42 -0700918}
919
Dan Willemsen322acaf2016-01-12 23:07:05 -0800920func decodeMegaDevice() ([]Arch, error) {
921 archSettings := []struct {
922 arch string
923 archVariant string
924 cpuVariant string
925 abi []string
926 }{
Dan Willemsen110a89d2016-01-14 15:17:19 -0800927 // armv5 is only used for unbundled apps
928 //{"arm", "armv5te", "", []string{"armeabi"}},
929 {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}},
930 {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -0800931 {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}},
932 {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -0800933 {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -0800934 {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}},
935 {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}},
936 {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}},
937 {"arm", "armv7-a-neon", "denver", []string{"armeabi-v7a"}},
938 {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -0800939 {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}},
940 {"arm64", "armv8-a", "denver64", []string{"arm64-v8a"}},
Dan Willemsen468cc312016-01-13 23:25:19 -0800941 {"mips", "mips32-fp", "", []string{"mips"}},
942 {"mips", "mips32r2-fp", "", []string{"mips"}},
943 {"mips", "mips32r2-fp-xburst", "", []string{"mips"}},
Dan Willemsen66187d92016-05-05 13:15:00 -0700944 {"mips", "mips32r6", "", []string{"mips"}},
Dan Willemsen468cc312016-01-13 23:25:19 -0800945 // mips32r2dsp[r2]-fp fails in the assembler for divdf3.c in compiler-rt:
946 // (same errors in make and soong)
947 // Error: invalid operands `mtlo $ac0,$11'
948 // Error: invalid operands `mthi $ac0,$12'
Dan Willemsen322acaf2016-01-12 23:07:05 -0800949 //{"mips", "mips32r2dsp-fp", "", []string{"mips"}},
950 //{"mips", "mips32r2dspr2-fp", "", []string{"mips"}},
951 // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc
952 //{"mips64", "mips64r2", "", []string{"mips64"}},
953 {"mips64", "mips64r6", "", []string{"mips64"}},
954 {"x86", "", "", []string{"x86"}},
955 {"x86", "atom", "", []string{"x86"}},
956 {"x86", "haswell", "", []string{"x86"}},
957 {"x86", "ivybridge", "", []string{"x86"}},
958 {"x86", "sandybridge", "", []string{"x86"}},
959 {"x86", "silvermont", "", []string{"x86"}},
Dan Willemsen8a354052016-05-10 14:30:51 -0700960 {"x86", "x86_64", "", []string{"x86"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -0800961 {"x86_64", "", "", []string{"x86_64"}},
962 {"x86_64", "haswell", "", []string{"x86_64"}},
963 {"x86_64", "ivybridge", "", []string{"x86_64"}},
964 {"x86_64", "sandybridge", "", []string{"x86_64"}},
965 {"x86_64", "silvermont", "", []string{"x86_64"}},
966 }
967
968 var ret []Arch
969
970 for _, config := range archSettings {
971 arch, err := decodeArch(config.arch, &config.archVariant,
972 &config.cpuVariant, &config.abi)
973 if err != nil {
974 return nil, err
975 }
976 ret = append(ret, arch)
977 }
978
979 return ret, nil
980}
981
Colin Cross4225f652015-09-17 14:33:42 -0700982// Convert a set of strings from product variables into a single Arch struct
983func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) {
984 stringPtr := func(p *string) string {
985 if p != nil {
986 return *p
987 }
988 return ""
989 }
990
991 slicePtr := func(p *[]string) []string {
992 if p != nil {
993 return *p
994 }
995 return nil
996 }
997
Colin Crosseeabb892015-11-20 13:07:51 -0800998 archType, ok := archTypeMap[arch]
999 if !ok {
1000 return Arch{}, fmt.Errorf("unknown arch %q", arch)
1001 }
Colin Cross4225f652015-09-17 14:33:42 -07001002
Colin Crosseeabb892015-11-20 13:07:51 -08001003 a := Arch{
Colin Cross4225f652015-09-17 14:33:42 -07001004 ArchType: archType,
1005 ArchVariant: stringPtr(archVariant),
1006 CpuVariant: stringPtr(cpuVariant),
1007 Abi: slicePtr(abi),
Colin Crosseeabb892015-11-20 13:07:51 -08001008 }
1009
1010 if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" {
1011 a.ArchVariant = ""
1012 }
1013
1014 if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" {
1015 a.CpuVariant = ""
1016 }
1017
1018 for i := 0; i < len(a.Abi); i++ {
1019 if a.Abi[i] == "" {
1020 a.Abi = append(a.Abi[:i], a.Abi[i+1:]...)
1021 i--
1022 }
1023 }
1024
Colin Crossc5c24ad2015-11-20 15:35:00 -08001025 if featureMap, ok := archFeatureMap[archType]; ok {
Dan Willemsenb4850992016-05-06 17:21:20 -07001026 a.ArchFeatures = featureMap[a.ArchVariant]
Colin Crossc5c24ad2015-11-20 15:35:00 -08001027 }
1028
Colin Crosseeabb892015-11-20 13:07:51 -08001029 return a, nil
Colin Cross4225f652015-09-17 14:33:42 -07001030}
1031
1032// Use the module multilib setting to select one or more arches from an arch list
1033func decodeMultilib(multilib string, arches []Arch) ([]Arch, error) {
1034 buildArches := []Arch{}
1035 switch multilib {
1036 case "common":
1037 buildArches = append(buildArches, commonArch)
1038 case "both":
1039 buildArches = append(buildArches, arches...)
1040 case "first":
1041 buildArches = append(buildArches, arches[0])
1042 case "32":
1043 for _, a := range arches {
1044 if a.ArchType.Multilib == "lib32" {
1045 buildArches = append(buildArches, a)
1046 }
1047 }
1048 case "64":
1049 for _, a := range arches {
1050 if a.ArchType.Multilib == "lib64" {
1051 buildArches = append(buildArches, a)
1052 }
1053 }
1054 default:
1055 return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`,
1056 multilib)
1057 //buildArches = append(buildArches, arches[0])
1058 }
1059
1060 return buildArches, nil
1061}