Merge "Add `data_libs` property to cc_test rules"

This commit is contained in:
Christopher Parsons 2020-07-07 21:26:56 +00:00 committed by Gerrit Code Review
commit c87fbdd0bd
4 changed files with 79 additions and 0 deletions

View File

@ -96,6 +96,9 @@ type Deps struct {
HeaderLibs []string
RuntimeLibs []string
// Used for data dependencies adjacent to tests
DataLibs []string
StaticUnwinderIfLegacy bool
ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
@ -423,6 +426,7 @@ type xref interface {
}
var (
dataLibDepTag = DependencyTag{Name: "data_lib", Library: true, Shared: true}
sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
@ -1980,6 +1984,10 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
addSharedLibDependencies(lateSharedDepTag, lib, "")
}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "shared"},
}, dataLibDepTag, deps.DataLibs...)
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "shared"},
}, runtimeDepTag, deps.RuntimeLibs...)

View File

@ -526,6 +526,56 @@ func TestVndkUsingCoreVariant(t *testing.T) {
checkVndkLibrariesOutput(t, ctx, "vndkcorevariant.libraries.txt", []string{"libc++.so", "libvndk2.so", "libvndk_sp.so"})
}
func TestDataLibs(t *testing.T) {
bp := `
cc_test_library {
name: "test_lib",
srcs: ["test_lib.cpp"],
gtest: false,
}
cc_test {
name: "main_test",
data_libs: ["test_lib"],
gtest: false,
}
`
config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
ctx := testCcWithConfig(t, config)
module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
testBinary := module.(*Module).linker.(*testBinary)
outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
if err != nil {
t.Errorf("Expected cc_test to produce output files, error: %s", err)
return
}
if len(outputFiles) != 1 {
t.Errorf("expected exactly one output file. output files: [%s]", outputFiles)
return
}
if len(testBinary.dataPaths()) != 1 {
t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths())
return
}
outputPath := outputFiles[0].String()
testBinaryPath := testBinary.dataPaths()[0].String()
if !strings.HasSuffix(outputPath, "/main_test") {
t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath)
return
}
if !strings.HasSuffix(testBinaryPath, "/test_lib.so") {
t.Errorf("expected test data file to be 'test_lib.so', but was '%s'", testBinaryPath)
return
}
}
func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
ctx := testCcNoVndk(t, `
cc_library {

View File

@ -58,6 +58,9 @@ type TestBinaryProperties struct {
// the test
Data []string `android:"path,arch_variant"`
// list of shared library modules that should be installed alongside the test
Data_libs []string `android:"arch_variant"`
// list of compatibility suites (for example "cts", "vts") that the module should be
// installed into.
Test_suites []string `android:"arch_variant"`
@ -325,6 +328,7 @@ func (test *testBinary) linkerInit(ctx BaseModuleContext) {
func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
deps = test.testDecorator.linkerDeps(ctx, deps)
deps = test.binaryDecorator.linkerDeps(ctx, deps)
deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...)
return deps
}
@ -336,6 +340,21 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
test.data = android.PathsForModuleSrc(ctx, test.Properties.Data)
ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
ccDep, ok := dep.(LinkableInterface)
if !ok {
ctx.ModuleErrorf("data_lib %q is not a linkable cc module", depName)
}
if ccDep.OutputFile().Valid() {
test.data = append(test.data, ccDep.OutputFile().Path())
} else {
ctx.ModuleErrorf("data_lib %q has no output file", depName)
}
})
var api_level_prop string
var configs []tradefed.Config
var min_level string
@ -507,6 +526,7 @@ func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps
func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
var configs []tradefed.Config
if Bool(benchmark.Properties.Require_root) {
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})

View File

@ -500,6 +500,7 @@ func CreateTestContext() *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_fuzz", FuzzFactory)
ctx.RegisterModuleType("cc_test", TestFactory)
ctx.RegisterModuleType("cc_test_library", TestLibraryFactory)
ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory)
ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory)
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)