Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package python |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 19 | ) |
| 20 | |
| 21 | // This file contains the module types for building Python test. |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterModuleType("python_test_host", PythonTestHostFactory) |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 25 | android.RegisterModuleType("python_test", PythonTestFactory) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame^] | 28 | type 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 Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 34 | type testDecorator struct { |
| 35 | *binaryDecorator |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame^] | 36 | |
| 37 | testProperties TestProperties |
| 38 | } |
| 39 | |
| 40 | func (test *testDecorator) bootstrapperProps() []interface{} { |
| 41 | return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 44 | func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) { |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 45 | 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 Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 53 | func NewTest(hod android.HostOrDeviceSupported) *Module { |
| 54 | module, binary := NewBinary(hod) |
| 55 | |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 56 | binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64") |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 57 | |
| 58 | test := &testDecorator{binaryDecorator: binary} |
| 59 | |
| 60 | module.bootstrapper = test |
| 61 | module.installer = test |
| 62 | |
| 63 | return module |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 66 | func PythonTestHostFactory() android.Module { |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 67 | module := NewTest(android.HostSupportedNoCross) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 68 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 69 | return module.Init() |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 70 | } |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 71 | |
| 72 | func PythonTestFactory() android.Module { |
| 73 | module := NewTest(android.HostAndDeviceSupported) |
| 74 | module.multilib = android.MultilibBoth |
| 75 | |
| 76 | return module.Init() |
| 77 | } |