blob: 39326f06e8e7aae0c2772634773f74ac38fdd90c [file] [log] [blame]
Nan Zhang5323f8e2017-05-10 13:37:54 -07001// Copyright 2017 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 python
16
17import (
18 "android/soong/android"
Nan Zhang5323f8e2017-05-10 13:37:54 -070019)
20
21// This file contains the module types for building Python test.
22
23func init() {
24 android.RegisterModuleType("python_test_host", PythonTestHostFactory)
Nan Zhangd9ec5e72017-12-01 20:00:31 +000025 android.RegisterModuleType("python_test", PythonTestFactory)
Nan Zhang5323f8e2017-05-10 13:37:54 -070026}
27
Julien Despreze146e392018-08-02 15:00:46 -070028type TestProperties struct {
29 // the name of the test configuration (for example "AndroidTest.xml") that should be
30 // installed with the module.
31 Test_config *string `android:"arch_variant"`
32}
33
Nan Zhangd4e641b2017-07-12 12:55:28 -070034type testDecorator struct {
35 *binaryDecorator
Julien Despreze146e392018-08-02 15:00:46 -070036
37 testProperties TestProperties
38}
39
40func (test *testDecorator) bootstrapperProps() []interface{} {
41 return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties)
Nan Zhang5323f8e2017-05-10 13:37:54 -070042}
43
Nan Zhangd4e641b2017-07-12 12:55:28 -070044func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) {
Nan Zhangd9ec5e72017-12-01 20:00:31 +000045 test.binaryDecorator.pythonInstaller.dir = "nativetest"
46 test.binaryDecorator.pythonInstaller.dir64 = "nativetest64"
47
48 test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName()
49
50 test.binaryDecorator.pythonInstaller.install(ctx, file)
Nan Zhang5323f8e2017-05-10 13:37:54 -070051}
52
Nan Zhangd4e641b2017-07-12 12:55:28 -070053func NewTest(hod android.HostOrDeviceSupported) *Module {
54 module, binary := NewBinary(hod)
55
Nan Zhangd9ec5e72017-12-01 20:00:31 +000056 binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64")
Nan Zhangd4e641b2017-07-12 12:55:28 -070057
58 test := &testDecorator{binaryDecorator: binary}
59
60 module.bootstrapper = test
61 module.installer = test
62
63 return module
Nan Zhang5323f8e2017-05-10 13:37:54 -070064}
65
Colin Cross36242852017-06-23 15:06:31 -070066func PythonTestHostFactory() android.Module {
Nan Zhangd4e641b2017-07-12 12:55:28 -070067 module := NewTest(android.HostSupportedNoCross)
Nan Zhang5323f8e2017-05-10 13:37:54 -070068
Nan Zhangd4e641b2017-07-12 12:55:28 -070069 return module.Init()
Nan Zhang5323f8e2017-05-10 13:37:54 -070070}
Nan Zhangd9ec5e72017-12-01 20:00:31 +000071
72func PythonTestFactory() android.Module {
73 module := NewTest(android.HostAndDeviceSupported)
74 module.multilib = android.MultilibBoth
75
76 return module.Init()
77}