From 1f6d90f4c71aeb117f8ea7a0cc7f4aa09ae44cff Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Wed, 17 Jun 2020 16:10:42 -0400 Subject: [PATCH] Create 'cc_prebuilt_test_library_shared' module type This new module type allows cc_test modules to depend on prebuilt shared libraries and have them included as data dependencies alongside the test binary. Test: Manually verified to facilitate mk-to-bp migration of bionic-unit-test prebuilt dependencies (aosp/1339035) Change-Id: Idbac0854f1f9e2e01bbfa63591de458b61733e17 --- cc/cc_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- cc/prebuilt.go | 11 +++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/cc/cc_test.go b/cc/cc_test.go index 041c4a388..38a5c2d6d 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -612,7 +612,6 @@ func TestDataLibsRelativeInstallPath(t *testing.T) { } outputPath := outputFiles[0].String() - testBinaryPath := testBinary.dataPaths()[0] if !strings.HasSuffix(outputPath, "/main_test") { t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) @@ -620,7 +619,7 @@ func TestDataLibsRelativeInstallPath(t *testing.T) { entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ - " but was '%s'", testBinaryPath) + " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) } } @@ -2967,6 +2966,52 @@ func TestRecovery(t *testing.T) { } } +func TestDataLibsPrebuiltSharedTestLibrary(t *testing.T) { + bp := ` + cc_prebuilt_test_library_shared { + name: "test_lib", + relative_install_path: "foo/bar/baz", + srcs: ["srcpath/dontusethispath/baz.so"], + } + + 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.Fatalf("Expected cc_test to produce output files, error: %s", err) + } + if len(outputFiles) != 1 { + t.Errorf("expected exactly one output file. output files: [%s]", outputFiles) + } + if len(testBinary.dataPaths()) != 1 { + t.Errorf("expected exactly one test data file. test data files: [%s]", testBinary.dataPaths()) + } + + outputPath := outputFiles[0].String() + + if !strings.HasSuffix(outputPath, "/main_test") { + t.Errorf("expected test output file to be 'main_test', but was '%s'", outputPath) + } + entries := android.AndroidMkEntriesForTest(t, config, "", module)[0] + if !strings.HasSuffix(entries.EntryMap["LOCAL_TEST_DATA"][0], ":test_lib.so:foo/bar/baz") { + t.Errorf("expected LOCAL_TEST_DATA to end with `:test_lib.so:foo/bar/baz`,"+ + " but was '%s'", entries.EntryMap["LOCAL_TEST_DATA"][0]) + } +} + func TestVersionedStubs(t *testing.T) { ctx := testCc(t, ` cc_library_shared { diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 0751f1ca6..653b43ef0 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -26,6 +26,7 @@ func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_prebuilt_library", PrebuiltLibraryFactory) ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory) ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory) ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) } @@ -243,6 +244,16 @@ func PrebuiltSharedLibraryFactory() android.Module { return module.Init() } +// cc_prebuilt_test_library_shared installs a precompiled shared library +// to be used as a data dependency of a test-related module (such as cc_test, or +// cc_test_library). +func PrebuiltSharedTestLibraryFactory() android.Module { + module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported) + library.BuildOnlyShared() + library.baseInstaller = NewTestInstaller() + return module.Init() +} + func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { module, library := NewPrebuiltLibrary(hod) library.BuildOnlyShared()