diff --git a/Android.bp b/Android.bp index 36a428a20..ee51942cd 100644 --- a/Android.bp +++ b/Android.bp @@ -67,6 +67,7 @@ bootstrap_go_package { "android/testing.go", "android/util.go", "android/variable.go", + "android/vts_config.go", "android/writedocs.go", // Lock down environment access last @@ -85,6 +86,7 @@ bootstrap_go_package { "android/rule_builder_test.go", "android/util_test.go", "android/variable_test.go", + "android/vts_config_test.go", ], } diff --git a/android/vts_config.go b/android/vts_config.go new file mode 100644 index 000000000..f468ba8a0 --- /dev/null +++ b/android/vts_config.go @@ -0,0 +1,70 @@ +// Copyright 2016 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 ( + "fmt" + "io" +) + +// Implements vts_config module + +func init() { + RegisterModuleType("vts_config", VtsConfigFactory) +} + +type vtsConfigProperties struct { + // Test manifest file name if different from AndroidTest.xml. + Test_config *string +} + +type VtsConfig struct { + ModuleBase + properties vtsConfigProperties + OutputFilePath OutputPath +} + +func (me *VtsConfig) GenerateAndroidBuildActions(ctx ModuleContext) { + me.OutputFilePath = PathForModuleOut(ctx, me.BaseModuleName()).OutputPath +} + +func (me *VtsConfig) AndroidMk() AndroidMkData { + androidMkData := AndroidMkData{ + Class: "FAKE", + Include: "$(BUILD_SYSTEM)/android_vts_host_config.mk", + OutputFile: OptionalPathForPath(me.OutputFilePath), + } + if me.properties.Test_config != nil { + androidMkData.Extra = []AndroidMkExtraFunc{ + func(w io.Writer, outputFile Path) { + fmt.Fprintf(w, "LOCAL_TEST_CONFIG := %s\n", + *me.properties.Test_config) + }, + } + } + return androidMkData +} + +func InitVtsConfigModule(me *VtsConfig) { + me.AddProperties(&me.properties) +} + +// Defines VTS configuration. +func VtsConfigFactory() Module { + module := &VtsConfig{} + InitVtsConfigModule(module) + InitAndroidArchModule(module /*TODO: or HostAndDeviceSupported? */, HostSupported, MultilibFirst) + return module +} diff --git a/android/vts_config_test.go b/android/vts_config_test.go new file mode 100644 index 000000000..7d4c9b1cf --- /dev/null +++ b/android/vts_config_test.go @@ -0,0 +1,61 @@ +// Copyright 2018 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 ( + "io/ioutil" + "os" + "testing" +) + +func testVtsConfig(test *testing.T, bpFileContents string) *TestContext { + buildDir, err := ioutil.TempDir("", "soong_vts_config_test") + if err != nil { + test.Fatal(err) + } + + config := TestArchConfig(buildDir, nil) + defer func() { os.RemoveAll(buildDir) }() + + ctx := NewTestArchContext() + ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory)) + ctx.Register() + mockFiles := map[string][]byte{ + "Android.bp": []byte(bpFileContents), + } + ctx.MockFileSystem(mockFiles) + _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) + FailIfErrored(test, errs) + _, errs = ctx.PrepareBuildActions(config) + FailIfErrored(test, errs) + return ctx +} + +func TestVtsConfig(t *testing.T) { + ctx := testVtsConfig(t, ` +vts_config { name: "plain"} +vts_config { name: "with_manifest", test_config: "manifest.xml" } +`) + + variants := ctx.ModuleVariantsForTests("plain") + if len(variants) > 1 { + t.Errorf("expected 1, got %d", len(variants)) + } + expectedOutputFilename := ctx.ModuleForTests( + "plain", variants[0]).Module().(*VtsConfig).OutputFilePath.Base() + if expectedOutputFilename != "plain" { + t.Errorf("expected plain, got %q", expectedOutputFilename) + } +} diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go index 1ecda2d5c..a5dfcd905 100644 --- a/androidmk/cmd/androidmk/android.go +++ b/androidmk/cmd/androidmk/android.go @@ -105,6 +105,7 @@ func init() { "LOCAL_MANIFEST_FILE": "manifest", "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile", + "LOCAL_TEST_CONFIG": "test_config", }) addStandardProperties(bpparser.ListType, map[string]string{ @@ -513,8 +514,8 @@ func strip() func(ctx variableAssignmentContext) error { func prebuiltClass(ctx variableAssignmentContext) error { class := ctx.mkvalue.Value(ctx.file.scope) - if v, ok := prebuiltTypes[class]; ok { - ctx.file.scope.Set("BUILD_PREBUILT", v) + if _, ok := prebuiltTypes[class]; ok { + ctx.file.scope.Set("BUILD_PREBUILT", class) } else { // reset to default ctx.file.scope.Set("BUILD_PREBUILT", "prebuilt") @@ -873,6 +874,19 @@ var prebuiltTypes = map[string]string{ var soongModuleTypes = map[string]bool{} +var includePathToModule = map[string]string{ + "test/vts/tools/build/Android.host_config.mk": "vts_config", + // The rest will be populated dynamically in androidScope below +} + +func mapIncludePath(path string) (string, bool) { + if path == clear_vars || path == include_ignored { + return path, true + } + module, ok := includePathToModule[path] + return module, ok +} + func androidScope() mkparser.Scope { globalScope := mkparser.NewScope(nil) globalScope.Set("CLEAR_VARS", clear_vars) @@ -887,12 +901,17 @@ func androidScope() mkparser.Scope { globalScope.SetFunc("first-makefiles-under", includeIgnored) globalScope.SetFunc("all-named-subdir-makefiles", includeIgnored) globalScope.SetFunc("all-subdir-makefiles", includeIgnored) - for k, v := range moduleTypes { - globalScope.Set(k, v) - soongModuleTypes[v] = true + + // The scope maps each known variable to a path, and then includePathToModule maps a path + // to a module. We don't care what the actual path value is so long as the value in scope + // is mapped, so we might as well use variable name as key, too. + for varName, moduleName := range moduleTypes { + path := varName + globalScope.Set(varName, path) + includePathToModule[path] = moduleName } - for _, v := range prebuiltTypes { - soongModuleTypes[v] = true + for varName, moduleName := range prebuiltTypes { + includePathToModule[varName] = moduleName } return globalScope diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index b6a973c0d..0426b43f1 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -169,20 +169,21 @@ func convertFile(filename string, buffer *bytes.Buffer) (string, []error) { handleAssignment(file, x, assignmentCond) case *mkparser.Directive: switch x.Name { - case "include": - val := x.Args.Value(file.scope) - switch { - case soongModuleTypes[val]: - handleModuleConditionals(file, x, conds) - makeModule(file, val) - case val == clear_vars: + case "include", "-include": + module, ok := mapIncludePath(x.Args.Value(file.scope)) + if !ok { + file.errorf(x, "unsupported include") + continue + } + switch module { + case clear_vars: resetModule(file) - case val == include_ignored: + case include_ignored: // subdirs are already automatically included in Soong continue default: - file.errorf(x, "unsupported include") - continue + handleModuleConditionals(file, x, conds) + makeModule(file, module) } case "ifeq", "ifneq", "ifdef", "ifndef": args := x.Args.Dump() diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index 52b8476ac..618dd42f3 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -1026,6 +1026,19 @@ prebuilt_etc { recovery: true, } +`, + }, + { + desc: "vts_config", + in: ` +include $(CLEAR_VARS) +LOCAL_MODULE := vtsconf +include test/vts/tools/build/Android.host_config.mk +`, + expected: ` +vts_config { + name: "vtsconf", +} `, }, }