Skip to content

Commit 4e1c996

Browse files
authored
[llvm][test][CGPluginTest] Keep plugin in shared library directory
Scoping to the root build directory instead of using the path directly is awkward and the only such occurrence in the test suite. It's also prone to breakage for downstreams that change the library path. But it's not even necessary: during build we have the appropriate RPATHs set so we can just depend on the dynamic loader to find it. This extra logic is probably just copy-paste from PluginsTest.cpp. Additionally: * Removed TargetParser as a dependency because it doesn't seem to actually be used. * Moved `add_dependencies()` to `DEPENDS` to better match the rest of LLVM.
1 parent 03e16c8 commit 4e1c996

File tree

4 files changed

+6
-25
lines changed

4 files changed

+6
-25
lines changed

llvm/test/Other/codegen-plugin-loading.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -load %llvmshlibdir/../unittests/CodeGen/CGPluginTest/CGTestPlugin%pluginext %s -o - | FileCheck %s
1+
; RUN: llc -load %llvm_obj_root/unittests/CodeGen/CGPluginTest/CGTestPlugin%pluginext %s -o - | FileCheck %s
22
; REQUIRES: native, system-linux, llvm-dylib
33

44
; CHECK: CodeGen Test Pass running on main

llvm/unittests/CodeGen/CGPluginTest/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
44
Core
55
MC
66
Target
7-
TargetParser
87
CodeGen
98
)
109

llvm/unittests/CodeGen/CGPluginTest/Plugin/CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ if (NOT WIN32 AND NOT CYGWIN)
33
add_llvm_library(CGTestPlugin MODULE BUILDTREE_ONLY
44
CodeGenTestPass.cpp
55
Plugin.cpp
6-
)
76

8-
# Put PLUGIN next to the unit test executable.
9-
set_output_directory(CGTestPlugin
10-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
11-
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
7+
DEPENDS
8+
intrinsics_gen
9+
vt_gen
1210
)
13-
set_target_properties(CGTestPlugin PROPERTIES FOLDER "Tests")
1411

15-
add_dependencies(CGTestPlugin intrinsics_gen vt_gen)
12+
set_target_properties(CGTestPlugin PROPERTIES FOLDER "Tests")
1613
add_dependencies(CGPluginTest CGTestPlugin)
1714
endif ()

llvm/unittests/CodeGen/CGPluginTest/PluginTest.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@
2525

2626
using namespace llvm;
2727

28-
namespace {
29-
void anchor() {}
30-
31-
std::string libPath(const std::string &Name) {
32-
const auto &Argvs = testing::internal::GetArgvs();
33-
const char *Argv0 = Argvs.size() > 0 ? Argvs[0].c_str() : "CGPluginTest";
34-
void *Ptr = (void *)(intptr_t)anchor;
35-
std::string Path = sys::fs::getMainExecutable(Argv0, Ptr);
36-
SmallString<256> Buf{sys::path::parent_path(Path)};
37-
sys::path::append(Buf, (Name + LLVM_PLUGIN_EXT).c_str());
38-
return std::string(Buf.str());
39-
}
40-
} // namespace
41-
4228
namespace llvm {
4329
class CGPluginTests : public testing::Test {
4430
protected:
@@ -56,8 +42,7 @@ TEST_F(CGPluginTests, LoadPlugin) {
5642
GTEST_SKIP();
5743
#endif
5844

59-
auto PluginPath = libPath("CGTestPlugin");
60-
ASSERT_NE("", PluginPath);
45+
auto PluginPath{std::string{"CGTestPlugin"} + LLVM_PLUGIN_EXT};
6146

6247
std::string Error;
6348
auto Library = sys::DynamicLibrary::getLibrary(PluginPath.c_str(), &Error);

0 commit comments

Comments
 (0)