1// Copyright 2016 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 android
16
17import (
18	"fmt"
19	"io"
20	"strings"
21)
22
23func init() {
24	RegisterModuleType("vts_config", VtsConfigFactory)
25}
26
27type vtsConfigProperties struct {
28	// Override the default (AndroidTest.xml) test manifest file name.
29	Test_config *string
30	// Additional test suites to add the test to.
31	Test_suites []string `android:"arch_variant"`
32}
33
34type VtsConfig struct {
35	ModuleBase
36	properties     vtsConfigProperties
37	OutputFilePath OutputPath
38}
39
40func (me *VtsConfig) GenerateAndroidBuildActions(ctx ModuleContext) {
41	me.OutputFilePath = PathForModuleOut(ctx, me.BaseModuleName()).OutputPath
42}
43
44func (me *VtsConfig) AndroidMk() AndroidMkData {
45	androidMkData := AndroidMkData{
46		Class:      "FAKE",
47		Include:    "$(BUILD_SYSTEM)/suite_host_config.mk",
48		OutputFile: OptionalPathForPath(me.OutputFilePath),
49	}
50	androidMkData.Extra = []AndroidMkExtraFunc{
51		func(w io.Writer, outputFile Path) {
52			if me.properties.Test_config != nil {
53				fmt.Fprintf(w, "LOCAL_TEST_CONFIG := %s\n",
54					*me.properties.Test_config)
55			}
56			fmt.Fprintf(w, "LOCAL_COMPATIBILITY_SUITE := vts10 %s\n",
57				strings.Join(me.properties.Test_suites, " "))
58		},
59	}
60	return androidMkData
61}
62
63func InitVtsConfigModule(me *VtsConfig) {
64	me.AddProperties(&me.properties)
65}
66
67// vts_config generates a Vendor Test Suite (VTS10) configuration file from the
68// <test_config> xml file and stores it in a subdirectory of $(HOST_OUT).
69func VtsConfigFactory() Module {
70	module := &VtsConfig{}
71	InitVtsConfigModule(module)
72	InitAndroidArchModule(module /*TODO: or HostAndDeviceSupported? */, HostSupported, MultilibFirst)
73	return module
74}
75