blob: 23ec5500b4e1213a29866a30561da1c8a599381f [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
15package common
16
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\")"`
Colin Cross85a88972015-11-23 13:29:51 -0800189
190 // X86 arch features
Colin Crossb0cba6a2015-11-20 15:35:26 -0800191 Ssse3 interface{} `blueprint:"filter(android:\"arch_variant\")"`
192 Sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"`
193 Sse4_1 interface{} `blueprint:"filter(android:\"arch_variant\")"`
194 Sse4_2 interface{} `blueprint:"filter(android:\"arch_variant\")"`
195 Aes_ni interface{} `blueprint:"filter(android:\"arch_variant\")"`
196 Avx interface{} `blueprint:"filter(android:\"arch_variant\")"`
197 Popcnt interface{} `blueprint:"filter(android:\"arch_variant\")"`
198 Movbe interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross85a88972015-11-23 13:29:51 -0800199 }
200
Colin Cross7d5136f2015-05-11 13:39:40 -0700201 // Properties for module variants being built to run on x86_64 (host or device)
Colin Cross85a88972015-11-23 13:29:51 -0800202 X86_64 struct {
203 Embed `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross6371b382015-11-23 14:53:57 -0800204
205 // X86 arch variants
206 Haswell interface{} `blueprint:"filter(android:\"arch_variant\")"`
207 Ivybridge interface{} `blueprint:"filter(android:\"arch_variant\")"`
208 Sandybridge interface{} `blueprint:"filter(android:\"arch_variant\")"`
209 Silvermont interface{} `blueprint:"filter(android:\"arch_variant\")"`
210
211 // X86 arch features
212 Ssse3 interface{} `blueprint:"filter(android:\"arch_variant\")"`
213 Sse4 interface{} `blueprint:"filter(android:\"arch_variant\")"`
214 Sse4_1 interface{} `blueprint:"filter(android:\"arch_variant\")"`
215 Sse4_2 interface{} `blueprint:"filter(android:\"arch_variant\")"`
216 Aes_ni interface{} `blueprint:"filter(android:\"arch_variant\")"`
217 Avx interface{} `blueprint:"filter(android:\"arch_variant\")"`
218 Popcnt interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross85a88972015-11-23 13:29:51 -0800219 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800220 }
Colin Crossec193632015-07-06 17:49:43 -0700221
Colin Cross7d5136f2015-05-11 13:39:40 -0700222 // Properties to vary by 32-bit or 64-bit
Colin Cross3f40fa42015-01-30 17:27:36 -0800223 Multilib struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700224 // Properties for module variants being built to run on 32-bit devices
225 Lib32 interface{} `blueprint:"filter(android:\"arch_variant\")"`
226 // Properties for module variants being built to run on 64-bit devices
227 Lib64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800228 }
Colin Cross7d5136f2015-05-11 13:39:40 -0700229 // Properties to vary by build target (host or device, os, os+archictecture)
Colin Cross3f40fa42015-01-30 17:27:36 -0800230 Target struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700231 // Properties for module variants being built to run on the host
232 Host interface{} `blueprint:"filter(android:\"arch_variant\")"`
233 // Properties for module variants being built to run on the device
234 Android interface{} `blueprint:"filter(android:\"arch_variant\")"`
235 // Properties for module variants being built to run on arm devices
236 Android_arm interface{} `blueprint:"filter(android:\"arch_variant\")"`
237 // Properties for module variants being built to run on arm64 devices
238 Android_arm64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
239 // Properties for module variants being built to run on mips devices
240 Android_mips interface{} `blueprint:"filter(android:\"arch_variant\")"`
241 // Properties for module variants being built to run on mips64 devices
242 Android_mips64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
243 // Properties for module variants being built to run on x86 devices
244 Android_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
245 // Properties for module variants being built to run on x86_64 devices
246 Android_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
247 // Properties for module variants being built to run on devices that support 64-bit
248 Android64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
249 // Properties for module variants being built to run on devices that do not support 64-bit
250 Android32 interface{} `blueprint:"filter(android:\"arch_variant\")"`
251 // Properties for module variants being built to run on linux hosts
252 Linux interface{} `blueprint:"filter(android:\"arch_variant\")"`
253 // Properties for module variants being built to run on linux x86 hosts
254 Linux_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
255 // Properties for module variants being built to run on linux x86_64 hosts
256 Linux_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
257 // Properties for module variants being built to run on darwin hosts
258 Darwin interface{} `blueprint:"filter(android:\"arch_variant\")"`
259 // Properties for module variants being built to run on darwin x86 hosts
260 Darwin_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
261 // Properties for module variants being built to run on darwin x86_64 hosts
262 Darwin_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
263 // Properties for module variants being built to run on windows hosts
264 Windows interface{} `blueprint:"filter(android:\"arch_variant\")"`
Dan Willemsen490fd492015-11-24 17:53:15 -0800265 // Properties for module variants being built to run on windows x86 hosts
266 Windows_x86 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Dan Willemsen07cd0512016-02-03 23:16:33 -0800267 // Properties for module variants being built to run on windows x86_64 hosts
268 Windows_x86_64 interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700269 // Properties for module variants being built to run on linux or darwin hosts
270 Not_windows interface{} `blueprint:"filter(android:\"arch_variant\")"`
Colin Cross3f40fa42015-01-30 17:27:36 -0800271 }
272}
273
Colin Crossc5c24ad2015-11-20 15:35:00 -0800274var archFeatureMap = map[ArchType]map[string][]string{}
275
276func RegisterArchFeatures(arch ArchType, variant string, features ...string) {
Colin Cross85a88972015-11-23 13:29:51 -0800277 archField := proptools.FieldNameForProperty(arch.Name)
278 variantField := proptools.FieldNameForProperty(variant)
279 archStruct := reflect.ValueOf(archProperties{}.Arch).FieldByName(archField)
Colin Crossc5c24ad2015-11-20 15:35:00 -0800280 if variant != "" {
Colin Cross85a88972015-11-23 13:29:51 -0800281 if !archStruct.FieldByName(variantField).IsValid() {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800282 panic(fmt.Errorf("Invalid variant %q for arch %q", variant, arch))
283 }
284 }
285 for _, feature := range features {
286 field := proptools.FieldNameForProperty(feature)
Colin Cross85a88972015-11-23 13:29:51 -0800287 if !archStruct.FieldByName(field).IsValid() {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800288 panic(fmt.Errorf("Invalid feature %q for arch %q variant %q", feature, arch, variant))
289 }
290 }
291 if archFeatureMap[arch] == nil {
292 archFeatureMap[arch] = make(map[string][]string)
293 }
294 archFeatureMap[arch][variant] = features
295}
296
Colin Cross3f40fa42015-01-30 17:27:36 -0800297// An Arch indicates a single CPU architecture.
298type Arch struct {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800299 ArchType ArchType
300 ArchVariant string
301 CpuVariant string
302 Abi []string
303 ArchFeatures []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800304}
305
306func (a Arch) String() string {
Colin Crossd3ba0392015-05-07 14:11:29 -0700307 s := a.ArchType.String()
Colin Cross3f40fa42015-01-30 17:27:36 -0800308 if a.ArchVariant != "" {
309 s += "_" + a.ArchVariant
310 }
311 if a.CpuVariant != "" {
312 s += "_" + a.CpuVariant
313 }
314 return s
315}
316
317type ArchType struct {
Colin Crossec193632015-07-06 17:49:43 -0700318 Name string
319 Multilib string
Colin Cross3f40fa42015-01-30 17:27:36 -0800320}
321
Colin Crossec193632015-07-06 17:49:43 -0700322func newArch(name, multilib string) ArchType {
Colin Cross3f40fa42015-01-30 17:27:36 -0800323 return ArchType{
Colin Crossec193632015-07-06 17:49:43 -0700324 Name: name,
325 Multilib: multilib,
Colin Cross3f40fa42015-01-30 17:27:36 -0800326 }
327}
328
329func (a ArchType) String() string {
330 return a.Name
331}
332
333type HostOrDeviceSupported int
334
335const (
336 _ HostOrDeviceSupported = iota
337 HostSupported
338 DeviceSupported
339 HostAndDeviceSupported
Dan Willemsen218f6562015-07-08 18:13:11 -0700340 HostAndDeviceDefault
Colin Cross3f40fa42015-01-30 17:27:36 -0800341)
342
343type HostOrDevice int
344
345const (
346 _ HostOrDevice = iota
347 Host
348 Device
349)
350
351func (hod HostOrDevice) String() string {
352 switch hod {
353 case Device:
354 return "device"
355 case Host:
356 return "host"
357 default:
358 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
359 }
360}
361
Colin Crossec193632015-07-06 17:49:43 -0700362func (hod HostOrDevice) Property() string {
Colin Cross3f40fa42015-01-30 17:27:36 -0800363 switch hod {
364 case Device:
365 return "android"
366 case Host:
367 return "host"
368 default:
369 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
370 }
371}
372
Colin Cross3f40fa42015-01-30 17:27:36 -0800373func (hod HostOrDevice) Host() bool {
374 if hod == 0 {
375 panic("HostOrDevice unset")
376 }
377 return hod == Host
378}
379
380func (hod HostOrDevice) Device() bool {
381 if hod == 0 {
382 panic("HostOrDevice unset")
383 }
384 return hod == Device
385}
386
387var hostOrDeviceName = map[HostOrDevice]string{
388 Device: "device",
389 Host: "host",
390}
391
Dan Willemsen490fd492015-11-24 17:53:15 -0800392type HostType int
393
394const (
395 NoHostType HostType = iota
396 Linux
397 Darwin
398 Windows
399)
400
401func CurrentHostType() HostType {
402 switch runtime.GOOS {
403 case "linux":
404 return Linux
405 case "darwin":
406 return Darwin
407 default:
408 panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
409 }
410}
411
412func (ht HostType) String() string {
413 switch ht {
414 case Linux:
415 return "linux"
416 case Darwin:
417 return "darwin"
418 case Windows:
419 return "windows"
420 default:
421 panic(fmt.Sprintf("unexpected HostType value %d", ht))
422 }
423}
424
425func (ht HostType) Field() string {
426 switch ht {
427 case Linux:
428 return "Linux"
429 case Darwin:
430 return "Darwin"
431 case Windows:
432 return "Windows"
433 default:
434 panic(fmt.Sprintf("unexpected HostType value %d", ht))
435 }
436}
437
Colin Cross3f40fa42015-01-30 17:27:36 -0800438var (
Colin Crossd3ba0392015-05-07 14:11:29 -0700439 commonArch = Arch{
440 ArchType: Common,
Colin Cross2fe66872015-03-30 17:20:39 -0700441 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800442)
443
Colin Cross6362e272015-10-29 15:25:03 -0700444func HostOrDeviceMutator(mctx AndroidBottomUpMutatorContext) {
Colin Crossd3ba0392015-05-07 14:11:29 -0700445 var module AndroidModule
446 var ok bool
447 if module, ok = mctx.Module().(AndroidModule); !ok {
448 return
449 }
450
451 hods := []HostOrDevice{}
452
453 if module.base().HostSupported() {
454 hods = append(hods, Host)
455 }
456
457 if module.base().DeviceSupported() {
458 hods = append(hods, Device)
459 }
460
461 if len(hods) == 0 {
462 return
463 }
464
465 hodNames := []string{}
466 for _, hod := range hods {
467 hodNames = append(hodNames, hod.String())
468 }
469
470 modules := mctx.CreateVariations(hodNames...)
471 for i, m := range modules {
472 m.(AndroidModule).base().SetHostOrDevice(hods[i])
473 }
474}
475
Dan Willemsen490fd492015-11-24 17:53:15 -0800476func HostTypeMutator(mctx AndroidBottomUpMutatorContext) {
477 var module AndroidModule
478 var ok bool
479 if module, ok = mctx.Module().(AndroidModule); !ok {
480 return
481 }
482
483 if !module.base().HostSupported() || !module.base().HostOrDevice().Host() {
484 return
485 }
486
487 buildTypes, err := decodeHostTypesProductVariables(mctx.Config().(Config).ProductVariables)
488 if err != nil {
489 mctx.ModuleErrorf("%s", err.Error())
490 return
491 }
492
493 typeNames := []string{}
494 for _, ht := range buildTypes {
495 typeNames = append(typeNames, ht.String())
496 }
497
498 modules := mctx.CreateVariations(typeNames...)
499 for i, m := range modules {
500 m.(AndroidModule).base().SetHostType(buildTypes[i])
501 }
502}
503
Colin Cross6362e272015-10-29 15:25:03 -0700504func ArchMutator(mctx AndroidBottomUpMutatorContext) {
Colin Cross3f40fa42015-01-30 17:27:36 -0800505 var module AndroidModule
506 var ok bool
507 if module, ok = mctx.Module().(AndroidModule); !ok {
508 return
509 }
510
Colin Cross4225f652015-09-17 14:33:42 -0700511 moduleArches := []Arch{}
512 multilib := module.base().commonProperties.Compile_multilib
Colin Cross3f40fa42015-01-30 17:27:36 -0800513
Colin Crossd3ba0392015-05-07 14:11:29 -0700514 if module.base().HostSupported() && module.base().HostOrDevice().Host() {
Dan Willemsen218f6562015-07-08 18:13:11 -0700515 hostModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).HostArches[module.base().HostType()])
Colin Cross4225f652015-09-17 14:33:42 -0700516 if err != nil {
517 mctx.ModuleErrorf("%s", err.Error())
Colin Cross2fe66872015-03-30 17:20:39 -0700518 }
Colin Cross4225f652015-09-17 14:33:42 -0700519
520 moduleArches = append(moduleArches, hostModuleArches...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800521 }
522
Colin Crossd3ba0392015-05-07 14:11:29 -0700523 if module.base().DeviceSupported() && module.base().HostOrDevice().Device() {
Dan Willemsen218f6562015-07-08 18:13:11 -0700524 deviceModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).DeviceArches)
Colin Cross4225f652015-09-17 14:33:42 -0700525 if err != nil {
526 mctx.ModuleErrorf("%s", err.Error())
Colin Cross3f40fa42015-01-30 17:27:36 -0800527 }
Colin Cross4225f652015-09-17 14:33:42 -0700528
529 moduleArches = append(moduleArches, deviceModuleArches...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800530 }
531
Colin Cross4225f652015-09-17 14:33:42 -0700532 if len(moduleArches) == 0 {
Colin Cross5049f022015-03-18 13:28:46 -0700533 return
534 }
535
Colin Cross3f40fa42015-01-30 17:27:36 -0800536 archNames := []string{}
Colin Cross4225f652015-09-17 14:33:42 -0700537 for _, arch := range moduleArches {
Colin Cross3f40fa42015-01-30 17:27:36 -0800538 archNames = append(archNames, arch.String())
539 }
540
541 modules := mctx.CreateVariations(archNames...)
542
543 for i, m := range modules {
Colin Cross4225f652015-09-17 14:33:42 -0700544 m.(AndroidModule).base().SetArch(moduleArches[i])
Colin Crossd3ba0392015-05-07 14:11:29 -0700545 m.(AndroidModule).base().setArchProperties(mctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800546 }
547}
548
Colin Crosscfad1192015-11-02 16:43:11 -0800549func InitArchModule(m AndroidModule,
Colin Cross3f40fa42015-01-30 17:27:36 -0800550 propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
551
552 base := m.base()
553
Colin Cross3f40fa42015-01-30 17:27:36 -0800554 base.generalProperties = append(base.generalProperties,
Colin Cross3f40fa42015-01-30 17:27:36 -0800555 propertyStructs...)
556
557 for _, properties := range base.generalProperties {
558 propertiesValue := reflect.ValueOf(properties)
559 if propertiesValue.Kind() != reflect.Ptr {
Colin Crossca860ac2016-01-04 14:34:37 -0800560 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
561 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800562 }
563
564 propertiesValue = propertiesValue.Elem()
565 if propertiesValue.Kind() != reflect.Struct {
Colin Crossca860ac2016-01-04 14:34:37 -0800566 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
567 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -0800568 }
569
570 archProperties := &archProperties{}
571 forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) {
Colin Cross3ab7d882015-05-19 13:03:01 -0700572 newValue := proptools.CloneEmptyProperties(propertiesValue)
Colin Cross3f40fa42015-01-30 17:27:36 -0800573 v.Set(newValue)
574 })
575
576 base.archProperties = append(base.archProperties, archProperties)
577 }
578
579 var allProperties []interface{}
580 allProperties = append(allProperties, base.generalProperties...)
581 for _, asp := range base.archProperties {
582 allProperties = append(allProperties, asp)
583 }
584
585 return m, allProperties
586}
587
Colin Crossa716add2015-12-16 11:07:39 -0800588var variantReplacer = strings.NewReplacer("-", "_", ".", "_")
Colin Crossec193632015-07-06 17:49:43 -0700589
Colin Cross6362e272015-10-29 15:25:03 -0700590func (a *AndroidModuleBase) appendProperties(ctx AndroidBottomUpMutatorContext,
Colin Cross85a88972015-11-23 13:29:51 -0800591 dst, src interface{}, field, srcPrefix string) interface{} {
Colin Cross06a931b2015-10-28 17:23:31 -0700592
Colin Crosseeabb892015-11-20 13:07:51 -0800593 srcField := reflect.ValueOf(src).FieldByName(field)
594 if !srcField.IsValid() {
595 ctx.ModuleErrorf("field %q does not exist", srcPrefix)
Colin Cross85a88972015-11-23 13:29:51 -0800596 return nil
597 }
598
599 ret := srcField
600
601 if srcField.Kind() == reflect.Struct {
602 srcField = srcField.FieldByName("Embed")
Colin Crosseeabb892015-11-20 13:07:51 -0800603 }
604
605 src = srcField.Elem().Interface()
Colin Cross06a931b2015-10-28 17:23:31 -0700606
607 filter := func(property string,
608 dstField, srcField reflect.StructField,
609 dstValue, srcValue interface{}) (bool, error) {
610
611 srcProperty := srcPrefix + "." + property
612
613 if !proptools.HasTag(dstField, "android", "arch_variant") {
614 if ctx.ContainsProperty(srcProperty) {
615 return false, fmt.Errorf("can't be specific to a build variant")
616 } else {
617 return false, nil
618 }
619 }
620
621 return true, nil
622 }
623
Colin Cross6ee75b62016-05-05 15:57:15 -0700624 order := func(property string,
625 dstField, srcField reflect.StructField,
626 dstValue, srcValue interface{}) (proptools.Order, error) {
627 if proptools.HasTag(dstField, "android", "variant_prepend") {
628 return proptools.Prepend, nil
629 } else {
630 return proptools.Append, nil
631 }
632 }
633
634 err := proptools.ExtendProperties(dst, src, filter, order)
Colin Cross06a931b2015-10-28 17:23:31 -0700635 if err != nil {
636 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
637 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
638 } else {
639 panic(err)
640 }
641 }
Colin Cross85a88972015-11-23 13:29:51 -0800642
643 return ret.Interface()
Colin Cross06a931b2015-10-28 17:23:31 -0700644}
645
Colin Cross3f40fa42015-01-30 17:27:36 -0800646// Rewrite the module's properties structs to contain arch-specific values.
Colin Cross6362e272015-10-29 15:25:03 -0700647func (a *AndroidModuleBase) setArchProperties(ctx AndroidBottomUpMutatorContext) {
Colin Crossd3ba0392015-05-07 14:11:29 -0700648 arch := a.commonProperties.CompileArch
649 hod := a.commonProperties.CompileHostOrDevice
Dan Willemsen490fd492015-11-24 17:53:15 -0800650 ht := a.commonProperties.CompileHostType
Colin Crossd3ba0392015-05-07 14:11:29 -0700651
Colin Cross2fe66872015-03-30 17:20:39 -0700652 if arch.ArchType == Common {
653 return
654 }
655
Colin Cross3f40fa42015-01-30 17:27:36 -0800656 for i := range a.generalProperties {
Colin Cross06a931b2015-10-28 17:23:31 -0700657 genProps := a.generalProperties[i]
658 archProps := a.archProperties[i]
Colin Cross3f40fa42015-01-30 17:27:36 -0800659 // Handle arch-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700660 // arch: {
661 // arm64: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800662 // key: value,
663 // },
664 // },
665 t := arch.ArchType
Colin Cross06a931b2015-10-28 17:23:31 -0700666
Colin Crossec193632015-07-06 17:49:43 -0700667 field := proptools.FieldNameForProperty(t.Name)
Colin Cross06a931b2015-10-28 17:23:31 -0700668 prefix := "arch." + t.Name
Colin Cross85a88972015-11-23 13:29:51 -0800669 archStruct := a.appendProperties(ctx, genProps, archProps.Arch, field, prefix)
Colin Crossec193632015-07-06 17:49:43 -0700670
671 // Handle arch-variant-specific properties in the form:
672 // arch: {
673 // variant: {
674 // key: value,
675 // },
676 // },
Colin Crossa716add2015-12-16 11:07:39 -0800677 v := variantReplacer.Replace(arch.ArchVariant)
Colin Crossec193632015-07-06 17:49:43 -0700678 if v != "" {
679 field := proptools.FieldNameForProperty(v)
Colin Cross85a88972015-11-23 13:29:51 -0800680 prefix := "arch." + t.Name + "." + v
681 a.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossec193632015-07-06 17:49:43 -0700682 }
683
684 // Handle cpu-variant-specific properties in the form:
685 // arch: {
686 // variant: {
687 // key: value,
688 // },
689 // },
Colin Crossa716add2015-12-16 11:07:39 -0800690 c := variantReplacer.Replace(arch.CpuVariant)
Colin Crossec193632015-07-06 17:49:43 -0700691 if c != "" {
692 field := proptools.FieldNameForProperty(c)
Colin Cross85a88972015-11-23 13:29:51 -0800693 prefix := "arch." + t.Name + "." + c
694 a.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossec193632015-07-06 17:49:43 -0700695 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800696
Colin Crossc5c24ad2015-11-20 15:35:00 -0800697 // Handle arch-feature-specific properties in the form:
698 // arch: {
699 // feature: {
700 // key: value,
701 // },
702 // },
703 for _, feature := range arch.ArchFeatures {
704 field := proptools.FieldNameForProperty(feature)
Colin Cross85a88972015-11-23 13:29:51 -0800705 prefix := "arch." + t.Name + "." + feature
706 a.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc5c24ad2015-11-20 15:35:00 -0800707 }
708
Colin Cross3f40fa42015-01-30 17:27:36 -0800709 // Handle multilib-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700710 // multilib: {
711 // lib32: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800712 // key: value,
713 // },
714 // },
Colin Cross06a931b2015-10-28 17:23:31 -0700715 field = proptools.FieldNameForProperty(t.Multilib)
716 prefix = "multilib." + t.Multilib
717 a.appendProperties(ctx, genProps, archProps.Multilib, field, prefix)
Colin Cross3f40fa42015-01-30 17:27:36 -0800718
719 // Handle host-or-device-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700720 // target: {
721 // host: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800722 // key: value,
723 // },
724 // },
Colin Crossec193632015-07-06 17:49:43 -0700725 hodProperty := hod.Property()
Colin Cross06a931b2015-10-28 17:23:31 -0700726 field = proptools.FieldNameForProperty(hodProperty)
727 prefix = "target." + hodProperty
728 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Cross3f40fa42015-01-30 17:27:36 -0800729
730 // Handle host target properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700731 // target: {
732 // linux: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800733 // key: value,
734 // },
Colin Crossb05bff22015-04-30 15:08:04 -0700735 // not_windows: {
736 // key: value,
737 // },
738 // linux_x86: {
739 // key: value,
740 // },
741 // linux_arm: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800742 // key: value,
743 // },
744 // },
Colin Cross3f40fa42015-01-30 17:27:36 -0800745 if hod.Host() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800746 field := ht.Field()
747 prefix := "target." + ht.String()
Colin Cross06a931b2015-10-28 17:23:31 -0700748 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Dan Willemsen490fd492015-11-24 17:53:15 -0800749
750 t := arch.ArchType
751 field = ht.Field() + "_" + t.Name
752 prefix = "target." + ht.String() + "_" + t.Name
753 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
754
755 if ht != Windows {
756 field := "Not_windows"
757 prefix := "target.not_windows"
758 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
759 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800760 }
761
Colin Crossf8209412015-03-26 14:44:26 -0700762 // Handle 64-bit device properties in the form:
763 // target {
764 // android64 {
765 // key: value,
766 // },
767 // android32 {
768 // key: value,
769 // },
770 // },
771 // WARNING: this is probably not what you want to use in your blueprints file, it selects
772 // options for all targets on a device that supports 64-bit binaries, not just the targets
773 // that are being compiled for 64-bit. Its expected use case is binaries like linker and
774 // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
775 if hod.Device() {
776 if true /* && target_is_64_bit */ {
Colin Cross06a931b2015-10-28 17:23:31 -0700777 field := "Android64"
778 prefix := "target.android64"
779 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Crossf8209412015-03-26 14:44:26 -0700780 } else {
Colin Cross06a931b2015-10-28 17:23:31 -0700781 field := "Android32"
782 prefix := "target.android32"
783 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Crossf8209412015-03-26 14:44:26 -0700784 }
785 }
Colin Crossb05bff22015-04-30 15:08:04 -0700786
787 // Handle device architecture properties in the form:
788 // target {
789 // android_arm {
790 // key: value,
791 // },
792 // android_x86 {
793 // key: value,
794 // },
795 // },
796 if hod.Device() {
797 t := arch.ArchType
Colin Cross06a931b2015-10-28 17:23:31 -0700798 field := "Android_" + t.Name
799 prefix := "target.android_" + t.Name
800 a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
Colin Crossb05bff22015-04-30 15:08:04 -0700801 }
802
Colin Cross3f40fa42015-01-30 17:27:36 -0800803 if ctx.Failed() {
804 return
805 }
806 }
807}
808
809func forEachInterface(v reflect.Value, f func(reflect.Value)) {
810 switch v.Kind() {
811 case reflect.Interface:
812 f(v)
813 case reflect.Struct:
814 for i := 0; i < v.NumField(); i++ {
815 forEachInterface(v.Field(i), f)
816 }
817 case reflect.Ptr:
818 forEachInterface(v.Elem(), f)
819 default:
820 panic(fmt.Errorf("Unsupported kind %s", v.Kind()))
821 }
822}
Colin Cross4225f652015-09-17 14:33:42 -0700823
Dan Willemsen490fd492015-11-24 17:53:15 -0800824// Get a list of HostTypes from the product variables
825func decodeHostTypesProductVariables(variables productVariables) ([]HostType, error) {
826 ret := []HostType{CurrentHostType()}
827
828 if variables.CrossHost != nil && *variables.CrossHost != "" {
829 switch *variables.CrossHost {
830 case "windows":
831 ret = append(ret, Windows)
832 default:
833 return nil, fmt.Errorf("Unsupported secondary host: %s", *variables.CrossHost)
834 }
835 }
836
837 return ret, nil
838}
839
Colin Cross4225f652015-09-17 14:33:42 -0700840// Convert the arch product variables into a list of host and device Arch structs
Dan Willemsen490fd492015-11-24 17:53:15 -0800841func decodeArchProductVariables(variables productVariables) (map[HostType][]Arch, []Arch, error) {
Colin Cross4225f652015-09-17 14:33:42 -0700842 if variables.HostArch == nil {
843 return nil, nil, fmt.Errorf("No host primary architecture set")
844 }
845
846 hostArch, err := decodeArch(*variables.HostArch, nil, nil, nil)
847 if err != nil {
848 return nil, nil, err
849 }
850
851 hostArches := []Arch{hostArch}
852
Colin Crosseeabb892015-11-20 13:07:51 -0800853 if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
Colin Cross4225f652015-09-17 14:33:42 -0700854 hostSecondaryArch, err := decodeArch(*variables.HostSecondaryArch, nil, nil, nil)
855 if err != nil {
856 return nil, nil, err
857 }
858 hostArches = append(hostArches, hostSecondaryArch)
859 }
860
Dan Willemsen490fd492015-11-24 17:53:15 -0800861 hostTypeArches := map[HostType][]Arch{
862 CurrentHostType(): hostArches,
863 }
864
865 if variables.CrossHost != nil && *variables.CrossHost != "" {
866 if variables.CrossHostArch == nil || *variables.CrossHostArch == "" {
867 return nil, nil, fmt.Errorf("No cross-host primary architecture set")
868 }
869
870 crossHostArch, err := decodeArch(*variables.CrossHostArch, nil, nil, nil)
871 if err != nil {
872 return nil, nil, err
873 }
874
875 crossHostArches := []Arch{crossHostArch}
876
877 if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
878 crossHostSecondaryArch, err := decodeArch(*variables.CrossHostSecondaryArch, nil, nil, nil)
879 if err != nil {
880 return nil, nil, err
881 }
882 crossHostArches = append(crossHostArches, crossHostSecondaryArch)
883 }
884
885 switch *variables.CrossHost {
886 case "windows":
887 hostTypeArches[Windows] = crossHostArches
888 default:
889 return nil, nil, fmt.Errorf("Unsupported cross-host: %s", *variables.CrossHost)
890 }
891 }
892
Colin Cross4225f652015-09-17 14:33:42 -0700893 if variables.DeviceArch == nil {
894 return nil, nil, fmt.Errorf("No device primary architecture set")
895 }
896
897 deviceArch, err := decodeArch(*variables.DeviceArch, variables.DeviceArchVariant,
898 variables.DeviceCpuVariant, variables.DeviceAbi)
899 if err != nil {
900 return nil, nil, err
901 }
902
903 deviceArches := []Arch{deviceArch}
904
Colin Crosseeabb892015-11-20 13:07:51 -0800905 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
Colin Cross4225f652015-09-17 14:33:42 -0700906 deviceSecondaryArch, err := decodeArch(*variables.DeviceSecondaryArch,
907 variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
908 variables.DeviceSecondaryAbi)
909 if err != nil {
910 return nil, nil, err
911 }
912 deviceArches = append(deviceArches, deviceSecondaryArch)
913 }
914
Dan Willemsen490fd492015-11-24 17:53:15 -0800915 return hostTypeArches, deviceArches, nil
Colin Cross4225f652015-09-17 14:33:42 -0700916}
917
Dan Willemsen322acaf2016-01-12 23:07:05 -0800918func decodeMegaDevice() ([]Arch, error) {
919 archSettings := []struct {
920 arch string
921 archVariant string
922 cpuVariant string
923 abi []string
924 }{
Dan Willemsen110a89d2016-01-14 15:17:19 -0800925 // armv5 is only used for unbundled apps
926 //{"arm", "armv5te", "", []string{"armeabi"}},
927 {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}},
928 {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -0800929 {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}},
930 {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -0800931 {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -0800932 {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}},
933 {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}},
934 {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}},
935 {"arm", "armv7-a-neon", "denver", []string{"armeabi-v7a"}},
936 {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -0800937 {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}},
938 {"arm64", "armv8-a", "denver64", []string{"arm64-v8a"}},
Dan Willemsen468cc312016-01-13 23:25:19 -0800939 {"mips", "mips32-fp", "", []string{"mips"}},
940 {"mips", "mips32r2-fp", "", []string{"mips"}},
941 {"mips", "mips32r2-fp-xburst", "", []string{"mips"}},
Dan Willemsen66187d92016-05-05 13:15:00 -0700942 {"mips", "mips32r6", "", []string{"mips"}},
Dan Willemsen468cc312016-01-13 23:25:19 -0800943 // mips32r2dsp[r2]-fp fails in the assembler for divdf3.c in compiler-rt:
944 // (same errors in make and soong)
945 // Error: invalid operands `mtlo $ac0,$11'
946 // Error: invalid operands `mthi $ac0,$12'
Dan Willemsen322acaf2016-01-12 23:07:05 -0800947 //{"mips", "mips32r2dsp-fp", "", []string{"mips"}},
948 //{"mips", "mips32r2dspr2-fp", "", []string{"mips"}},
949 // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc
950 //{"mips64", "mips64r2", "", []string{"mips64"}},
951 {"mips64", "mips64r6", "", []string{"mips64"}},
952 {"x86", "", "", []string{"x86"}},
953 {"x86", "atom", "", []string{"x86"}},
954 {"x86", "haswell", "", []string{"x86"}},
955 {"x86", "ivybridge", "", []string{"x86"}},
956 {"x86", "sandybridge", "", []string{"x86"}},
957 {"x86", "silvermont", "", []string{"x86"}},
958 {"x86_64", "", "", []string{"x86_64"}},
959 {"x86_64", "haswell", "", []string{"x86_64"}},
960 {"x86_64", "ivybridge", "", []string{"x86_64"}},
961 {"x86_64", "sandybridge", "", []string{"x86_64"}},
962 {"x86_64", "silvermont", "", []string{"x86_64"}},
963 }
964
965 var ret []Arch
966
967 for _, config := range archSettings {
968 arch, err := decodeArch(config.arch, &config.archVariant,
969 &config.cpuVariant, &config.abi)
970 if err != nil {
971 return nil, err
972 }
973 ret = append(ret, arch)
974 }
975
976 return ret, nil
977}
978
Colin Cross4225f652015-09-17 14:33:42 -0700979// Convert a set of strings from product variables into a single Arch struct
980func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Arch, error) {
981 stringPtr := func(p *string) string {
982 if p != nil {
983 return *p
984 }
985 return ""
986 }
987
988 slicePtr := func(p *[]string) []string {
989 if p != nil {
990 return *p
991 }
992 return nil
993 }
994
Colin Crosseeabb892015-11-20 13:07:51 -0800995 archType, ok := archTypeMap[arch]
996 if !ok {
997 return Arch{}, fmt.Errorf("unknown arch %q", arch)
998 }
Colin Cross4225f652015-09-17 14:33:42 -0700999
Colin Crosseeabb892015-11-20 13:07:51 -08001000 a := Arch{
Colin Cross4225f652015-09-17 14:33:42 -07001001 ArchType: archType,
1002 ArchVariant: stringPtr(archVariant),
1003 CpuVariant: stringPtr(cpuVariant),
1004 Abi: slicePtr(abi),
Colin Crosseeabb892015-11-20 13:07:51 -08001005 }
1006
1007 if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" {
1008 a.ArchVariant = ""
1009 }
1010
1011 if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" {
1012 a.CpuVariant = ""
1013 }
1014
1015 for i := 0; i < len(a.Abi); i++ {
1016 if a.Abi[i] == "" {
1017 a.Abi = append(a.Abi[:i], a.Abi[i+1:]...)
1018 i--
1019 }
1020 }
1021
Colin Crossc5c24ad2015-11-20 15:35:00 -08001022 if featureMap, ok := archFeatureMap[archType]; ok {
1023 a.ArchFeatures = featureMap[stringPtr(archVariant)]
1024 }
1025
Colin Crosseeabb892015-11-20 13:07:51 -08001026 return a, nil
Colin Cross4225f652015-09-17 14:33:42 -07001027}
1028
1029// Use the module multilib setting to select one or more arches from an arch list
1030func decodeMultilib(multilib string, arches []Arch) ([]Arch, error) {
1031 buildArches := []Arch{}
1032 switch multilib {
1033 case "common":
1034 buildArches = append(buildArches, commonArch)
1035 case "both":
1036 buildArches = append(buildArches, arches...)
1037 case "first":
1038 buildArches = append(buildArches, arches[0])
1039 case "32":
1040 for _, a := range arches {
1041 if a.ArchType.Multilib == "lib32" {
1042 buildArches = append(buildArches, a)
1043 }
1044 }
1045 case "64":
1046 for _, a := range arches {
1047 if a.ArchType.Multilib == "lib64" {
1048 buildArches = append(buildArches, a)
1049 }
1050 }
1051 default:
1052 return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`,
1053 multilib)
1054 //buildArches = append(buildArches, arches[0])
1055 }
1056
1057 return buildArches, nil
1058}