2019-10-25 05:47:54 +02:00
|
|
|
// Copyright 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// 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 rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
2019-11-01 04:56:47 +01:00
|
|
|
"android/soong/tradefed"
|
2019-10-25 05:47:54 +02:00
|
|
|
)
|
|
|
|
|
2019-11-01 04:56:47 +01:00
|
|
|
type TestProperties struct {
|
2020-06-11 19:25:36 +02:00
|
|
|
// Disables the creation of a test-specific directory when used with
|
|
|
|
// relative_install_path. Useful if several tests need to be in the same
|
|
|
|
// directory, but test_per_src doesn't work.
|
|
|
|
No_named_install_directory *bool
|
|
|
|
|
2019-11-01 04:56:47 +01:00
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2020-06-10 00:09:22 +02:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2019-11-01 04:56:47 +01:00
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2020-06-10 00:09:22 +02:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2019-11-01 04:56:47 +01:00
|
|
|
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
|
|
|
}
|
|
|
|
|
2019-10-25 05:47:54 +02:00
|
|
|
// A test module is a binary module with extra --test compiler flag
|
|
|
|
// and different default installation directory.
|
|
|
|
// In golang, inheriance is written as a component.
|
2019-11-01 04:56:47 +01:00
|
|
|
type testDecorator struct {
|
2019-10-25 05:47:54 +02:00
|
|
|
*binaryDecorator
|
2019-11-01 04:56:47 +01:00
|
|
|
Properties TestProperties
|
|
|
|
testConfig android.Path
|
2019-10-25 05:47:54 +02:00
|
|
|
}
|
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
func (test *testDecorator) nativeCoverage() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-11-01 04:56:47 +01:00
|
|
|
func NewRustTest(hod android.HostOrDeviceSupported) (*Module, *testDecorator) {
|
2019-10-25 05:47:54 +02:00
|
|
|
module := newModule(hod, android.MultilibFirst)
|
|
|
|
|
2019-11-01 04:56:47 +01:00
|
|
|
test := &testDecorator{
|
2019-10-25 05:47:54 +02:00
|
|
|
binaryDecorator: &binaryDecorator{
|
2019-12-13 04:36:05 +01:00
|
|
|
baseCompiler: NewBaseCompiler("nativetest", "nativetest64", InstallInData),
|
2019-10-25 05:47:54 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.compiler = test
|
2020-06-11 19:25:36 +02:00
|
|
|
module.AddProperties(&test.Properties)
|
2019-10-25 05:47:54 +02:00
|
|
|
return module, test
|
|
|
|
}
|
|
|
|
|
2019-11-01 04:56:47 +01:00
|
|
|
func (test *testDecorator) compilerProps() []interface{} {
|
|
|
|
return append(test.binaryDecorator.compilerProps(), &test.Properties)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testDecorator) install(ctx ModuleContext, file android.Path) {
|
2020-06-11 19:25:36 +02:00
|
|
|
test.testConfig = tradefed.AutoGenRustTestConfig(ctx,
|
2019-11-01 04:56:47 +01:00
|
|
|
test.Properties.Test_config,
|
|
|
|
test.Properties.Test_config_template,
|
|
|
|
test.Properties.Test_suites,
|
2020-06-11 19:25:36 +02:00
|
|
|
nil,
|
2019-11-01 04:56:47 +01:00
|
|
|
test.Properties.Auto_gen_config)
|
2020-06-11 19:25:36 +02:00
|
|
|
|
2019-12-13 04:36:05 +01:00
|
|
|
// default relative install path is module name
|
2020-06-11 19:25:36 +02:00
|
|
|
if !Bool(test.Properties.No_named_install_directory) {
|
2019-12-13 04:36:05 +01:00
|
|
|
test.baseCompiler.relative = ctx.ModuleName()
|
2020-06-11 19:25:36 +02:00
|
|
|
} else if String(test.baseCompiler.Properties.Relative_install_path) == "" {
|
|
|
|
ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set")
|
2019-12-13 04:36:05 +01:00
|
|
|
}
|
2020-06-11 19:25:36 +02:00
|
|
|
|
2019-11-01 04:56:47 +01:00
|
|
|
test.binaryDecorator.install(ctx, file)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
2019-10-25 05:47:54 +02:00
|
|
|
flags = test.binaryDecorator.compilerFlags(ctx, flags)
|
|
|
|
flags.RustFlags = append(flags.RustFlags, "--test")
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Rust tests are binary files built with --test.
|
|
|
|
android.RegisterModuleType("rust_test", RustTestFactory)
|
|
|
|
android.RegisterModuleType("rust_test_host", RustTestHostFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RustTestFactory() android.Module {
|
|
|
|
module, _ := NewRustTest(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func RustTestHostFactory() android.Module {
|
|
|
|
module, _ := NewRustTest(android.HostSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|