Implement vts_config module

Test: internal (see android/vts_config_test.go) + run 'm vts' and check
that host/linux-x86/vts/android-vts.zip remians the same
Change-Id: I0249a974a240e7669c3b9378c17739df8e120873
Fixes: 122617100
This commit is contained in:
Sasha Smundak 2019-02-12 17:12:08 -08:00
parent bce06b6840
commit ff36da04e8
6 changed files with 183 additions and 17 deletions

View file

@ -67,6 +67,7 @@ bootstrap_go_package {
"android/testing.go", "android/testing.go",
"android/util.go", "android/util.go",
"android/variable.go", "android/variable.go",
"android/vts_config.go",
"android/writedocs.go", "android/writedocs.go",
// Lock down environment access last // Lock down environment access last
@ -85,6 +86,7 @@ bootstrap_go_package {
"android/rule_builder_test.go", "android/rule_builder_test.go",
"android/util_test.go", "android/util_test.go",
"android/variable_test.go", "android/variable_test.go",
"android/vts_config_test.go",
], ],
} }

70
android/vts_config.go Normal file
View file

@ -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
}

View file

@ -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)
}
}

View file

@ -105,6 +105,7 @@ func init() {
"LOCAL_MANIFEST_FILE": "manifest", "LOCAL_MANIFEST_FILE": "manifest",
"LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile", "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile",
"LOCAL_TEST_CONFIG": "test_config",
}) })
addStandardProperties(bpparser.ListType, addStandardProperties(bpparser.ListType,
map[string]string{ map[string]string{
@ -513,8 +514,8 @@ func strip() func(ctx variableAssignmentContext) error {
func prebuiltClass(ctx variableAssignmentContext) error { func prebuiltClass(ctx variableAssignmentContext) error {
class := ctx.mkvalue.Value(ctx.file.scope) class := ctx.mkvalue.Value(ctx.file.scope)
if v, ok := prebuiltTypes[class]; ok { if _, ok := prebuiltTypes[class]; ok {
ctx.file.scope.Set("BUILD_PREBUILT", v) ctx.file.scope.Set("BUILD_PREBUILT", class)
} else { } else {
// reset to default // reset to default
ctx.file.scope.Set("BUILD_PREBUILT", "prebuilt") ctx.file.scope.Set("BUILD_PREBUILT", "prebuilt")
@ -873,6 +874,19 @@ var prebuiltTypes = map[string]string{
var soongModuleTypes = map[string]bool{} 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 { func androidScope() mkparser.Scope {
globalScope := mkparser.NewScope(nil) globalScope := mkparser.NewScope(nil)
globalScope.Set("CLEAR_VARS", clear_vars) globalScope.Set("CLEAR_VARS", clear_vars)
@ -887,12 +901,17 @@ func androidScope() mkparser.Scope {
globalScope.SetFunc("first-makefiles-under", includeIgnored) globalScope.SetFunc("first-makefiles-under", includeIgnored)
globalScope.SetFunc("all-named-subdir-makefiles", includeIgnored) globalScope.SetFunc("all-named-subdir-makefiles", includeIgnored)
globalScope.SetFunc("all-subdir-makefiles", includeIgnored) globalScope.SetFunc("all-subdir-makefiles", includeIgnored)
for k, v := range moduleTypes {
globalScope.Set(k, v) // The scope maps each known variable to a path, and then includePathToModule maps a path
soongModuleTypes[v] = true // 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 { for varName, moduleName := range prebuiltTypes {
soongModuleTypes[v] = true includePathToModule[varName] = moduleName
} }
return globalScope return globalScope

View file

@ -169,20 +169,21 @@ func convertFile(filename string, buffer *bytes.Buffer) (string, []error) {
handleAssignment(file, x, assignmentCond) handleAssignment(file, x, assignmentCond)
case *mkparser.Directive: case *mkparser.Directive:
switch x.Name { switch x.Name {
case "include": case "include", "-include":
val := x.Args.Value(file.scope) module, ok := mapIncludePath(x.Args.Value(file.scope))
switch { if !ok {
case soongModuleTypes[val]: file.errorf(x, "unsupported include")
handleModuleConditionals(file, x, conds) continue
makeModule(file, val) }
case val == clear_vars: switch module {
case clear_vars:
resetModule(file) resetModule(file)
case val == include_ignored: case include_ignored:
// subdirs are already automatically included in Soong // subdirs are already automatically included in Soong
continue continue
default: default:
file.errorf(x, "unsupported include") handleModuleConditionals(file, x, conds)
continue makeModule(file, module)
} }
case "ifeq", "ifneq", "ifdef", "ifndef": case "ifeq", "ifneq", "ifdef", "ifndef":
args := x.Args.Dump() args := x.Args.Dump()

View file

@ -1026,6 +1026,19 @@ prebuilt_etc {
recovery: true, 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",
}
`, `,
}, },
} }