| 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 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 28 | type testDecorator struct { | 
|  | 29 | *binaryDecorator | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 30 | } | 
|  | 31 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 32 | func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) { | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 33 | test.binaryDecorator.pythonInstaller.dir = "nativetest" | 
|  | 34 | test.binaryDecorator.pythonInstaller.dir64 = "nativetest64" | 
|  | 35 |  | 
|  | 36 | test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName() | 
|  | 37 |  | 
|  | 38 | test.binaryDecorator.pythonInstaller.install(ctx, file) | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 39 | } | 
|  | 40 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 41 | func NewTest(hod android.HostOrDeviceSupported) *Module { | 
|  | 42 | module, binary := NewBinary(hod) | 
|  | 43 |  | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 44 | binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64") | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | test := &testDecorator{binaryDecorator: binary} | 
|  | 47 |  | 
|  | 48 | module.bootstrapper = test | 
|  | 49 | module.installer = test | 
|  | 50 |  | 
|  | 51 | return module | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 54 | func PythonTestHostFactory() android.Module { | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 55 | module := NewTest(android.HostSupportedNoCross) | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 56 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 57 | return module.Init() | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 58 | } | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 59 |  | 
|  | 60 | func PythonTestFactory() android.Module { | 
|  | 61 | module := NewTest(android.HostAndDeviceSupported) | 
|  | 62 | module.multilib = android.MultilibBoth | 
|  | 63 |  | 
|  | 64 | return module.Init() | 
|  | 65 | } |