diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-25 07:15:11 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-05-25 07:15:11 +0000 |
commit | 3541482d499f686054d2f16937d92199a8fa332a (patch) | |
tree | b8719f6184f03a7e2139c26d8cf409b1d00dd991 | |
parent | b229b3ad7fe9c7909622c6e4a559590680e2e342 (diff) | |
parent | 9a70ccb8bde324f8d4686785f3e725155da29975 (diff) | |
download | build_soong-3541482d499f686054d2f16937d92199a8fa332a.tar.gz build_soong-3541482d499f686054d2f16937d92199a8fa332a.tar.bz2 build_soong-3541482d499f686054d2f16937d92199a8fa332a.zip |
release-request-33b11ddd-d658-45bf-bdb2-acceb024fe39-for-git_oc-release-4042766 snap-temp-L87400000067730042
Change-Id: I36d4ff7a8f9f8f01f5c85252748c59e2340e0612
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | android/variable.go | 68 | ||||
-rw-r--r-- | android/variable_test.go | 124 |
3 files changed, 181 insertions, 12 deletions
@@ -71,6 +71,7 @@ bootstrap_go_package { "android/expand_test.go", "android/paths_test.go", "android/prebuilt_test.go", + "android/variable_test.go", ], } diff --git a/android/variable.go b/android/variable.go index 08b3bda5..0cdd865b 100644 --- a/android/variable.go +++ b/android/variable.go @@ -65,6 +65,10 @@ type variableProperties struct { Cflags []string } + Override_rs_driver struct { + Cflags []string + } + // debuggable is true for eng and userdebug builds, and can be used to turn on additional // debugging features that don't significantly impact runtime behavior. userdebug builds // are used for dogfooding and performance testing, and should be as similar to user builds @@ -144,6 +148,8 @@ type productVariables struct { ArtUseReadBarrier *bool `json:",omitempty"` BtConfigIncludeDir *string `json:",omitempty"` + + Override_rs_driver *string `json:",omitempty"` } func boolPtr(v bool) *bool { @@ -227,7 +233,7 @@ func variableMutator(mctx BottomUpMutatorContext) { func (a *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext, prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) { - printfIntoProperties(productVariablePropertyValue, variableValue) + printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue) err := proptools.AppendMatchingProperties(a.generalProperties, productVariablePropertyValue.Addr().Interface(), nil) @@ -240,7 +246,17 @@ func (a *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext, } } -func printfIntoProperties(productVariablePropertyValue reflect.Value, variableValue interface{}) { +func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string, + productVariablePropertyValue reflect.Value, i int, err error) { + + field := productVariablePropertyValue.Type().Field(i).Name + property := prefix + "." + proptools.PropertyNameForField(field) + ctx.PropertyErrorf(property, "%s", err) +} + +func printfIntoProperties(ctx BottomUpMutatorContext, prefix string, + productVariablePropertyValue reflect.Value, variableValue interface{}) { + for i := 0; i < productVariablePropertyValue.NumField(); i++ { propertyValue := productVariablePropertyValue.Field(i) kind := propertyValue.Kind() @@ -252,36 +268,64 @@ func printfIntoProperties(productVariablePropertyValue reflect.Value, variableVa } switch propertyValue.Kind() { case reflect.String: - printfIntoProperty(propertyValue, variableValue) + err := printfIntoProperty(propertyValue, variableValue) + if err != nil { + printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err) + } case reflect.Slice: for j := 0; j < propertyValue.Len(); j++ { - printfIntoProperty(propertyValue.Index(j), variableValue) + err := printfIntoProperty(propertyValue.Index(j), variableValue) + if err != nil { + printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err) + } } case reflect.Bool: // Nothing case reflect.Struct: - printfIntoProperties(propertyValue, variableValue) + printfIntoProperties(ctx, prefix, propertyValue, variableValue) default: panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind())) } } } -func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) { +func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error { s := propertyValue.String() - // For now, we only support int formats - var i int + + count := strings.Count(s, "%") + if count == 0 { + return nil + } + + if count > 1 { + return fmt.Errorf("product variable properties only support a single '%%'") + } + if strings.Contains(s, "%d") { switch v := variableValue.(type) { case int: - i = v + // Nothing case bool: if v { - i = 1 + variableValue = 1 + } else { + variableValue = 0 } default: - panic(fmt.Errorf("unsupported type %T", variableValue)) + return fmt.Errorf("unsupported type %T for %%d", variableValue) } - propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, i))) + } else if strings.Contains(s, "%s") { + switch variableValue.(type) { + case string: + // Nothing + default: + return fmt.Errorf("unsupported type %T for %%s", variableValue) + } + } else { + return fmt.Errorf("unsupported %% in product variable property") } + + propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue))) + + return nil } diff --git a/android/variable_test.go b/android/variable_test.go new file mode 100644 index 00000000..ce9ba548 --- /dev/null +++ b/android/variable_test.go @@ -0,0 +1,124 @@ +// Copyright 2015 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package android + +import ( + "reflect" + "testing" +) + +type printfIntoPropertyTestCase struct { + in string + val interface{} + out string + err bool +} + +var printfIntoPropertyTestCases = []printfIntoPropertyTestCase{ + { + in: "%d", + val: 0, + out: "0", + }, + { + in: "%d", + val: 1, + out: "1", + }, + { + in: "%d", + val: 2, + out: "2", + }, + { + in: "%d", + val: false, + out: "0", + }, + { + in: "%d", + val: true, + out: "1", + }, + { + in: "%d", + val: -1, + out: "-1", + }, + + { + in: "-DA=%d", + val: 1, + out: "-DA=1", + }, + { + in: "-DA=%du", + val: 1, + out: "-DA=1u", + }, + { + in: "-DA=%s", + val: "abc", + out: "-DA=abc", + }, + { + in: `-DA="%s"`, + val: "abc", + out: `-DA="abc"`, + }, + + { + in: "%%", + err: true, + }, + { + in: "%d%s", + err: true, + }, + { + in: "%d,%s", + err: true, + }, + { + in: "%d", + val: "", + err: true, + }, + { + in: "%d", + val: 1.5, + err: true, + }, + { + in: "%f", + val: 1.5, + err: true, + }, +} + +func TestPrintfIntoProperty(t *testing.T) { + for _, testCase := range printfIntoPropertyTestCases { + s := testCase.in + v := reflect.ValueOf(&s).Elem() + err := printfIntoProperty(v, testCase.val) + if err != nil && !testCase.err { + t.Errorf("unexpected error %s", err) + } else if err == nil && testCase.err { + t.Errorf("expected error") + } else if err == nil && v.String() != testCase.out { + t.Errorf("expected %q got %q", testCase.out, v.String()) + } + } +} |