Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff36da04 authored by Sasha Smundak's avatar Sasha Smundak
Browse files

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
parent bce06b68
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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",
    ],
}

android/vts_config.go

0 → 100644
+70 −0
Original line number Diff line number Diff line
// 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
}
+61 −0
Original line number Diff line number Diff line
// 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)
	}
}
+26 −7
Original line number Diff line number Diff line
@@ -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
+11 −10
Original line number Diff line number Diff line
@@ -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()
Loading