blob: 2a09ae9592318729738e1bf113e17af3cd1afda9 [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
27var (
28 Arm = newArch32("Arm")
29 Arm64 = newArch64("Arm64")
30 Mips = newArch32("Mips")
31 Mips64 = newArch64("Mips64")
32 X86 = newArch32("X86")
33 X86_64 = newArch64("X86_64")
Colin Cross2fe66872015-03-30 17:20:39 -070034
35 Common = ArchType{
36 Name: "common",
37 }
Colin Cross3f40fa42015-01-30 17:27:36 -080038)
39
40/*
41Example blueprints file containing all variant property groups, with comment listing what type
42of variants get properties in that group:
43
44module {
45 arch: {
46 arm: {
47 // Host or device variants with arm architecture
48 },
49 arm64: {
50 // Host or device variants with arm64 architecture
51 },
52 mips: {
53 // Host or device variants with mips architecture
54 },
55 mips64: {
56 // Host or device variants with mips64 architecture
57 },
58 x86: {
59 // Host or device variants with x86 architecture
60 },
61 x86_64: {
62 // Host or device variants with x86_64 architecture
63 },
64 },
65 multilib: {
66 lib32: {
67 // Host or device variants for 32-bit architectures
68 },
69 lib64: {
70 // Host or device variants for 64-bit architectures
71 },
72 },
73 target: {
74 android: {
75 // Device variants
76 },
77 host: {
78 // Host variants
79 },
80 linux: {
81 // Linux host variants
82 },
83 darwin: {
84 // Darwin host variants
85 },
86 windows: {
87 // Windows host variants
88 },
89 not_windows: {
90 // Non-windows host variants
91 },
92 },
93}
94*/
95type archProperties struct {
96 Arch struct {
97 Arm interface{}
98 Arm64 interface{}
99 Mips interface{}
100 Mips64 interface{}
101 X86 interface{}
102 X86_64 interface{}
103 }
104 Multilib struct {
105 Lib32 interface{}
106 Lib64 interface{}
107 }
108 Target struct {
Colin Crossb05bff22015-04-30 15:08:04 -0700109 Host interface{}
110 Android interface{}
111 Android_arm interface{}
112 Android_arm64 interface{}
113 Android_mips interface{}
114 Android_mips64 interface{}
115 Android_x86 interface{}
116 Android_x86_64 interface{}
117 Android64 interface{}
118 Android32 interface{}
119 Linux interface{}
120 Linux_x86 interface{}
121 Linux_x86_64 interface{}
122 Darwin interface{}
123 Darwin_x86 interface{}
124 Darwin_x86_64 interface{}
125 Windows interface{}
126 Not_windows interface{}
Colin Cross3f40fa42015-01-30 17:27:36 -0800127 }
128}
129
130// An Arch indicates a single CPU architecture.
131type Arch struct {
Colin Crossd3ba0392015-05-07 14:11:29 -0700132 ArchType ArchType
133 ArchVariant string
134 CpuVariant string
135 Abi string
Colin Cross3f40fa42015-01-30 17:27:36 -0800136}
137
138func (a Arch) String() string {
Colin Crossd3ba0392015-05-07 14:11:29 -0700139 s := a.ArchType.String()
Colin Cross3f40fa42015-01-30 17:27:36 -0800140 if a.ArchVariant != "" {
141 s += "_" + a.ArchVariant
142 }
143 if a.CpuVariant != "" {
144 s += "_" + a.CpuVariant
145 }
146 return s
147}
148
149type ArchType struct {
150 Name string
151 Field string
152 Multilib string
153 MultilibField string
154}
155
156func newArch32(field string) ArchType {
157 return ArchType{
158 Name: strings.ToLower(field),
159 Field: field,
160 Multilib: "lib32",
161 MultilibField: "Lib32",
162 }
163}
164
165func newArch64(field string) ArchType {
166 return ArchType{
167 Name: strings.ToLower(field),
168 Field: field,
169 Multilib: "lib64",
170 MultilibField: "Lib64",
171 }
172}
173
174func (a ArchType) String() string {
175 return a.Name
176}
177
178type HostOrDeviceSupported int
179
180const (
181 _ HostOrDeviceSupported = iota
182 HostSupported
183 DeviceSupported
184 HostAndDeviceSupported
185)
186
187type HostOrDevice int
188
189const (
190 _ HostOrDevice = iota
191 Host
192 Device
193)
194
195func (hod HostOrDevice) String() string {
196 switch hod {
197 case Device:
198 return "device"
199 case Host:
200 return "host"
201 default:
202 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
203 }
204}
205
206func (hod HostOrDevice) FieldLower() string {
207 switch hod {
208 case Device:
209 return "android"
210 case Host:
211 return "host"
212 default:
213 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
214 }
215}
216
217func (hod HostOrDevice) Field() string {
218 switch hod {
219 case Device:
220 return "Android"
221 case Host:
222 return "Host"
223 default:
224 panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
225 }
226}
227
228func (hod HostOrDevice) Host() bool {
229 if hod == 0 {
230 panic("HostOrDevice unset")
231 }
232 return hod == Host
233}
234
235func (hod HostOrDevice) Device() bool {
236 if hod == 0 {
237 panic("HostOrDevice unset")
238 }
239 return hod == Device
240}
241
242var hostOrDeviceName = map[HostOrDevice]string{
243 Device: "device",
244 Host: "host",
245}
246
247var (
248 armArch = Arch{
Colin Crossd3ba0392015-05-07 14:11:29 -0700249 ArchType: Arm,
250 ArchVariant: "armv7-a-neon",
251 CpuVariant: "cortex-a15",
252 Abi: "armeabi-v7a",
Colin Cross3f40fa42015-01-30 17:27:36 -0800253 }
254 arm64Arch = Arch{
Colin Crossd3ba0392015-05-07 14:11:29 -0700255 ArchType: Arm64,
256 ArchVariant: "armv8-a",
257 CpuVariant: "denver",
258 Abi: "arm64-v8a",
Colin Cross3f40fa42015-01-30 17:27:36 -0800259 }
Colin Crossd3ba0392015-05-07 14:11:29 -0700260 x86Arch = Arch{
261 ArchType: X86,
Colin Cross3f40fa42015-01-30 17:27:36 -0800262 }
Colin Crossd3ba0392015-05-07 14:11:29 -0700263 x8664Arch = Arch{
264 ArchType: X86_64,
Colin Cross3f40fa42015-01-30 17:27:36 -0800265 }
Colin Crossd3ba0392015-05-07 14:11:29 -0700266 commonArch = Arch{
267 ArchType: Common,
Colin Cross2fe66872015-03-30 17:20:39 -0700268 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800269)
270
Colin Crossd3ba0392015-05-07 14:11:29 -0700271func HostOrDeviceMutator(mctx blueprint.EarlyMutatorContext) {
272 var module AndroidModule
273 var ok bool
274 if module, ok = mctx.Module().(AndroidModule); !ok {
275 return
276 }
277
278 hods := []HostOrDevice{}
279
280 if module.base().HostSupported() {
281 hods = append(hods, Host)
282 }
283
284 if module.base().DeviceSupported() {
285 hods = append(hods, Device)
286 }
287
288 if len(hods) == 0 {
289 return
290 }
291
292 hodNames := []string{}
293 for _, hod := range hods {
294 hodNames = append(hodNames, hod.String())
295 }
296
297 modules := mctx.CreateVariations(hodNames...)
298 for i, m := range modules {
299 m.(AndroidModule).base().SetHostOrDevice(hods[i])
300 }
301}
302
Colin Cross3f40fa42015-01-30 17:27:36 -0800303func ArchMutator(mctx blueprint.EarlyMutatorContext) {
304 var module AndroidModule
305 var ok bool
306 if module, ok = mctx.Module().(AndroidModule); !ok {
307 return
308 }
309
310 // TODO: this is all hardcoded for arm64 primary, arm secondary for now
311 // Replace with a configuration file written by lunch or bootstrap
312
313 arches := []Arch{}
314
Colin Crossd3ba0392015-05-07 14:11:29 -0700315 if module.base().HostSupported() && module.base().HostOrDevice().Host() {
Colin Cross2fe66872015-03-30 17:20:39 -0700316 switch module.base().commonProperties.Compile_multilib {
317 case "common":
Colin Crossd3ba0392015-05-07 14:11:29 -0700318 arches = append(arches, commonArch)
Colin Cross2fe66872015-03-30 17:20:39 -0700319 default:
Colin Crossd3ba0392015-05-07 14:11:29 -0700320 arches = append(arches, x8664Arch)
Colin Cross2fe66872015-03-30 17:20:39 -0700321 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800322 }
323
Colin Crossd3ba0392015-05-07 14:11:29 -0700324 if module.base().DeviceSupported() && module.base().HostOrDevice().Device() {
Colin Cross3f40fa42015-01-30 17:27:36 -0800325 switch module.base().commonProperties.Compile_multilib {
Colin Cross2fe66872015-03-30 17:20:39 -0700326 case "common":
Colin Crossd3ba0392015-05-07 14:11:29 -0700327 arches = append(arches, commonArch)
Colin Cross3f40fa42015-01-30 17:27:36 -0800328 case "both":
329 arches = append(arches, arm64Arch, armArch)
330 case "first", "64":
331 arches = append(arches, arm64Arch)
332 case "32":
333 arches = append(arches, armArch)
334 default:
335 mctx.ModuleErrorf(`compile_multilib must be "both", "first", "32", or "64", found %q`,
336 module.base().commonProperties.Compile_multilib)
337 }
338 }
339
Colin Cross5049f022015-03-18 13:28:46 -0700340 if len(arches) == 0 {
341 return
342 }
343
Colin Cross3f40fa42015-01-30 17:27:36 -0800344 archNames := []string{}
345 for _, arch := range arches {
346 archNames = append(archNames, arch.String())
347 }
348
349 modules := mctx.CreateVariations(archNames...)
350
351 for i, m := range modules {
352 m.(AndroidModule).base().SetArch(arches[i])
Colin Crossd3ba0392015-05-07 14:11:29 -0700353 m.(AndroidModule).base().setArchProperties(mctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800354 }
355}
356
Colin Crossc472d572015-03-17 15:06:21 -0700357func InitArchModule(m AndroidModule, defaultMultilib Multilib,
Colin Cross3f40fa42015-01-30 17:27:36 -0800358 propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
359
360 base := m.base()
361
Colin Crossc472d572015-03-17 15:06:21 -0700362 base.commonProperties.Compile_multilib = string(defaultMultilib)
Colin Cross3f40fa42015-01-30 17:27:36 -0800363
364 base.generalProperties = append(base.generalProperties,
Colin Cross3f40fa42015-01-30 17:27:36 -0800365 propertyStructs...)
366
367 for _, properties := range base.generalProperties {
368 propertiesValue := reflect.ValueOf(properties)
369 if propertiesValue.Kind() != reflect.Ptr {
370 panic("properties must be a pointer to a struct")
371 }
372
373 propertiesValue = propertiesValue.Elem()
374 if propertiesValue.Kind() != reflect.Struct {
375 panic("properties must be a pointer to a struct")
376 }
377
378 archProperties := &archProperties{}
379 forEachInterface(reflect.ValueOf(archProperties), func(v reflect.Value) {
380 newValue := proptools.CloneProperties(propertiesValue)
381 proptools.ZeroProperties(newValue.Elem())
382 v.Set(newValue)
383 })
384
385 base.archProperties = append(base.archProperties, archProperties)
386 }
387
388 var allProperties []interface{}
389 allProperties = append(allProperties, base.generalProperties...)
390 for _, asp := range base.archProperties {
391 allProperties = append(allProperties, asp)
392 }
393
394 return m, allProperties
395}
396
397// Rewrite the module's properties structs to contain arch-specific values.
Colin Crossd3ba0392015-05-07 14:11:29 -0700398func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext) {
399 arch := a.commonProperties.CompileArch
400 hod := a.commonProperties.CompileHostOrDevice
401
Colin Cross2fe66872015-03-30 17:20:39 -0700402 if arch.ArchType == Common {
403 return
404 }
405
Colin Cross3f40fa42015-01-30 17:27:36 -0800406 for i := range a.generalProperties {
407 generalPropsValue := reflect.ValueOf(a.generalProperties[i]).Elem()
408
409 // Handle arch-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700410 // arch: {
411 // arm64: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800412 // key: value,
413 // },
414 // },
415 t := arch.ArchType
Colin Cross28d76592015-03-26 16:14:04 -0700416 a.extendProperties(ctx, "arch", t.Name, generalPropsValue,
Colin Cross3f40fa42015-01-30 17:27:36 -0800417 reflect.ValueOf(a.archProperties[i].Arch).FieldByName(t.Field).Elem().Elem())
418
419 // Handle multilib-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700420 // multilib: {
421 // lib32: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800422 // key: value,
423 // },
424 // },
Colin Cross28d76592015-03-26 16:14:04 -0700425 a.extendProperties(ctx, "multilib", t.Multilib, generalPropsValue,
Colin Cross3f40fa42015-01-30 17:27:36 -0800426 reflect.ValueOf(a.archProperties[i].Multilib).FieldByName(t.MultilibField).Elem().Elem())
427
428 // Handle host-or-device-specific properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700429 // target: {
430 // host: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800431 // key: value,
432 // },
433 // },
Colin Cross28d76592015-03-26 16:14:04 -0700434 a.extendProperties(ctx, "target", hod.FieldLower(), generalPropsValue,
Colin Cross3f40fa42015-01-30 17:27:36 -0800435 reflect.ValueOf(a.archProperties[i].Target).FieldByName(hod.Field()).Elem().Elem())
436
437 // Handle host target properties in the form:
Colin Crossb05bff22015-04-30 15:08:04 -0700438 // target: {
439 // linux: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800440 // key: value,
441 // },
Colin Crossb05bff22015-04-30 15:08:04 -0700442 // not_windows: {
443 // key: value,
444 // },
445 // linux_x86: {
446 // key: value,
447 // },
448 // linux_arm: {
Colin Cross3f40fa42015-01-30 17:27:36 -0800449 // key: value,
450 // },
451 // },
452 var osList = []struct {
453 goos string
454 field string
455 }{
456 {"darwin", "Darwin"},
457 {"linux", "Linux"},
458 {"windows", "Windows"},
459 }
460
461 if hod.Host() {
462 for _, v := range osList {
463 if v.goos == runtime.GOOS {
Colin Cross28d76592015-03-26 16:14:04 -0700464 a.extendProperties(ctx, "target", v.goos, generalPropsValue,
Colin Cross3f40fa42015-01-30 17:27:36 -0800465 reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field).Elem().Elem())
Colin Crossb05bff22015-04-30 15:08:04 -0700466 t := arch.ArchType
467 a.extendProperties(ctx, "target", v.goos+"_"+t.Name, generalPropsValue,
468 reflect.ValueOf(a.archProperties[i].Target).FieldByName(v.field+"_"+t.Name).Elem().Elem())
Colin Cross3f40fa42015-01-30 17:27:36 -0800469 }
470 }
Colin Cross28d76592015-03-26 16:14:04 -0700471 a.extendProperties(ctx, "target", "not_windows", generalPropsValue,
Colin Cross3f40fa42015-01-30 17:27:36 -0800472 reflect.ValueOf(a.archProperties[i].Target).FieldByName("Not_windows").Elem().Elem())
473 }
474
Colin Crossf8209412015-03-26 14:44:26 -0700475 // Handle 64-bit device properties in the form:
476 // target {
477 // android64 {
478 // key: value,
479 // },
480 // android32 {
481 // key: value,
482 // },
483 // },
484 // WARNING: this is probably not what you want to use in your blueprints file, it selects
485 // options for all targets on a device that supports 64-bit binaries, not just the targets
486 // that are being compiled for 64-bit. Its expected use case is binaries like linker and
487 // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
488 if hod.Device() {
489 if true /* && target_is_64_bit */ {
Colin Cross28d76592015-03-26 16:14:04 -0700490 a.extendProperties(ctx, "target", "android64", generalPropsValue,
Colin Crossf8209412015-03-26 14:44:26 -0700491 reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android64").Elem().Elem())
492 } else {
Colin Cross28d76592015-03-26 16:14:04 -0700493 a.extendProperties(ctx, "target", "android32", generalPropsValue,
Colin Crossf8209412015-03-26 14:44:26 -0700494 reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android32").Elem().Elem())
495 }
496 }
Colin Crossb05bff22015-04-30 15:08:04 -0700497
498 // Handle device architecture properties in the form:
499 // target {
500 // android_arm {
501 // key: value,
502 // },
503 // android_x86 {
504 // key: value,
505 // },
506 // },
507 if hod.Device() {
508 t := arch.ArchType
509 a.extendProperties(ctx, "target", "android_"+t.Name, generalPropsValue,
510 reflect.ValueOf(a.archProperties[i].Target).FieldByName("Android_"+t.Name).Elem().Elem())
511 }
512
Colin Cross3f40fa42015-01-30 17:27:36 -0800513 if ctx.Failed() {
514 return
515 }
516 }
517}
518
519func forEachInterface(v reflect.Value, f func(reflect.Value)) {
520 switch v.Kind() {
521 case reflect.Interface:
522 f(v)
523 case reflect.Struct:
524 for i := 0; i < v.NumField(); i++ {
525 forEachInterface(v.Field(i), f)
526 }
527 case reflect.Ptr:
528 forEachInterface(v.Elem(), f)
529 default:
530 panic(fmt.Errorf("Unsupported kind %s", v.Kind()))
531 }
532}
533
534// TODO: move this to proptools
Colin Cross28d76592015-03-26 16:14:04 -0700535func (a *AndroidModuleBase) extendProperties(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
Colin Cross3f40fa42015-01-30 17:27:36 -0800536 dstValue, srcValue reflect.Value) {
Colin Cross28d76592015-03-26 16:14:04 -0700537 a.extendPropertiesRecursive(ctx, variationType, variationName, dstValue, srcValue, "")
Colin Cross3f40fa42015-01-30 17:27:36 -0800538}
539
Colin Cross28d76592015-03-26 16:14:04 -0700540func (a *AndroidModuleBase) extendPropertiesRecursive(ctx blueprint.EarlyMutatorContext, variationType, variationName string,
Colin Cross3f40fa42015-01-30 17:27:36 -0800541 dstValue, srcValue reflect.Value, recursePrefix string) {
542
543 typ := dstValue.Type()
544 if srcValue.Type() != typ {
545 panic(fmt.Errorf("can't extend mismatching types (%s <- %s)",
546 dstValue.Kind(), srcValue.Kind()))
547 }
548
549 for i := 0; i < srcValue.NumField(); i++ {
550 field := typ.Field(i)
551 if field.PkgPath != "" {
552 // The field is not exported so just skip it.
553 continue
554 }
555
556 srcFieldValue := srcValue.Field(i)
557 dstFieldValue := dstValue.Field(i)
558
559 localPropertyName := proptools.PropertyNameForField(field.Name)
560 propertyName := fmt.Sprintf("%s.%s.%s%s", variationType, variationName,
561 recursePrefix, localPropertyName)
562 propertyPresentInVariation := ctx.ContainsProperty(propertyName)
563
564 if !propertyPresentInVariation {
565 continue
566 }
567
568 tag := field.Tag.Get("android")
569 tags := map[string]bool{}
570 for _, entry := range strings.Split(tag, ",") {
571 if entry != "" {
572 tags[entry] = true
573 }
574 }
575
576 if !tags["arch_variant"] {
577 ctx.PropertyErrorf(propertyName, "property %q can't be specific to a build variant",
578 recursePrefix+proptools.PropertyNameForField(field.Name))
579 continue
580 }
581
Colin Cross28d76592015-03-26 16:14:04 -0700582 if !ctx.ContainsProperty(propertyName) {
583 continue
584 }
585 a.extendedProperties[localPropertyName] = struct{}{}
586
Colin Cross3f40fa42015-01-30 17:27:36 -0800587 switch srcFieldValue.Kind() {
588 case reflect.Bool:
589 // Replace the original value.
590 dstFieldValue.Set(srcFieldValue)
591 case reflect.String:
592 // Append the extension string.
593 dstFieldValue.SetString(dstFieldValue.String() +
594 srcFieldValue.String())
595 case reflect.Struct:
596 // Recursively extend the struct's fields.
597 newRecursePrefix := fmt.Sprintf("%s%s.", recursePrefix, strings.ToLower(field.Name))
Colin Cross28d76592015-03-26 16:14:04 -0700598 a.extendPropertiesRecursive(ctx, variationType, variationName,
Colin Cross3f40fa42015-01-30 17:27:36 -0800599 dstFieldValue, srcFieldValue,
600 newRecursePrefix)
601 case reflect.Slice:
602 val, err := archCombineSlices(dstFieldValue, srcFieldValue, tags["arch_subtract"])
603 if err != nil {
604 ctx.PropertyErrorf(propertyName, err.Error())
605 continue
606 }
607 dstFieldValue.Set(val)
608 case reflect.Ptr, reflect.Interface:
609 // Recursively extend the pointed-to struct's fields.
610 if dstFieldValue.IsNil() != srcFieldValue.IsNil() {
611 panic(fmt.Errorf("can't extend field %q: nilitude mismatch"))
612 }
613 if dstFieldValue.Type() != srcFieldValue.Type() {
614 panic(fmt.Errorf("can't extend field %q: type mismatch"))
615 }
616 if !dstFieldValue.IsNil() {
617 newRecursePrefix := fmt.Sprintf("%s.%s", recursePrefix, field.Name)
Colin Cross28d76592015-03-26 16:14:04 -0700618 a.extendPropertiesRecursive(ctx, variationType, variationName,
Colin Cross3f40fa42015-01-30 17:27:36 -0800619 dstFieldValue.Elem(), srcFieldValue.Elem(),
620 newRecursePrefix)
621 }
622 default:
623 panic(fmt.Errorf("unexpected kind for property struct field %q: %s",
624 field.Name, srcFieldValue.Kind()))
625 }
626 }
627}
628
629func archCombineSlices(general, arch reflect.Value, canSubtract bool) (reflect.Value, error) {
630 if !canSubtract {
631 // Append the extension slice.
632 return reflect.AppendSlice(general, arch), nil
633 }
634
635 // Support -val in arch list to subtract a value from original list
636 l := general.Interface().([]string)
637 for archIndex := 0; archIndex < arch.Len(); archIndex++ {
638 archString := arch.Index(archIndex).String()
639 if strings.HasPrefix(archString, "-") {
640 generalIndex := findStringInSlice(archString[1:], l)
641 if generalIndex == -1 {
642 return reflect.Value{},
643 fmt.Errorf("can't find %q to subtract from general properties", archString[1:])
644 }
645 l = append(l[:generalIndex], l[generalIndex+1:]...)
646 } else {
647 l = append(l, archString)
648 }
649 }
650
651 return reflect.ValueOf(l), nil
652}
653
654func findStringInSlice(str string, slice []string) int {
655 for i, s := range slice {
656 if s == str {
657 return i
658 }
659 }
660
661 return -1
662}