@@ -61,18 +61,86 @@ std::string TestUtils::GetTestLibraryPath() {
6161 const char * cwd_override = std::getenv (" PARQUET_TEST_LIBRARY_CWD" );
6262 std::string base_path;
6363
64+ const std::string exec_dir = GetExecutableDirectory ();
6465 if (cwd_override && cwd_override[0 ]) {
6566 base_path = std::string (cwd_override);
6667 } else {
6768 // Get the directory where the executable is located
68- base_path = GetExecutableDirectory () ;
69+ base_path = exec_dir ;
6970 }
7071
7172 std::vector<std::string> possible_filenames = {
72- " libDBPATestAgent.so" , " libDBPATestAgent.dylib" , " DBPATestAgent.dll" };
73+ #if defined(__linux__)
74+ " libDBPATestAgent.so"
75+ #elif defined(__APPLE__)
76+ " libDBPATestAgent.dylib"
77+ #elif defined(_WIN32)
78+ // Windows (MSVC): no "lib" prefix for DLLs
79+ " DBPATestAgent.dll" ,
80+ // Windows (MinGW): typically uses "lib" prefix even for DLLs
81+ " libDBPATestAgent.dll" ,
7382
74- std::vector<std::string> possible_directories = {GetExecutableDirectory () + " /" ,
75- base_path + " /" , " ./" , " " };
83+ // Some toolchains use a debug postfix (commonly "d")
84+ " DBPATestAgentd.dll" ,
85+ " libDBPATestAgentd.dll"
86+ #endif
87+ };
88+
89+ std::vector<std::string> possible_directories = {exec_dir + " /" , base_path + " /" ,
90+ " ./" , " " };
91+
92+ // Arrow's CMake places most runtime artifacts under:
93+ // <build>/cpp/<lowercase-build-type>/
94+ // and CI often runs `ctest` from <build>/cpp. On Windows in particular, this
95+ // means the shared library can sit under "./debug/" (or "./release/") even
96+ // when the test executable isn't.
97+ const std::string cwd = std::filesystem::current_path ().string ();
98+ const std::filesystem::path cwd_path = std::filesystem::current_path ();
99+ const std::filesystem::path exec_dir_path = std::filesystem::path (exec_dir);
100+ const std::string exec_parent = exec_dir_path.parent_path ().string ();
101+
102+ // Common CMake build-type directory spellings (Arrow CI frequently uses "debug").
103+ const std::vector<std::string> build_type_dirs = {
104+ " debug" , " Debug" , " release" , " Release" , " relwithdebinfo" , " RelWithDebInfo" ,
105+ " minsizerel" , " MinSizeRel" };
106+
107+ auto add_build_type_dirs = [&](const std::filesystem::path& root) {
108+ if (root.empty ()) {
109+ return ;
110+ }
111+ const std::string root_s = root.string ();
112+ for (const auto & cfg : build_type_dirs) {
113+ possible_directories.push_back (root_s + " /" + cfg + " /" );
114+ }
115+ };
116+
117+ // Search build-type dirs under CWD and a few parents (handles ctest running
118+ // from build/cpp/src/* while outputs are in build/cpp/<cfg>/).
119+ {
120+ std::filesystem::path p = cwd_path;
121+ for (int i = 0 ; i < 5 && !p.empty (); ++i) {
122+ add_build_type_dirs (p);
123+ p = p.parent_path ();
124+ }
125+ }
126+
127+ // Also handle the common "build root" case where CWD is <build> (not <build>/cpp).
128+ for (const auto & cfg : build_type_dirs) {
129+ possible_directories.push_back (cwd + " /cpp/" + cfg + " /" );
130+ }
131+
132+ // Finally, search under the executable's parent and its parents.
133+ {
134+ std::filesystem::path p = exec_dir_path.parent_path ();
135+ for (int i = 0 ; i < 5 && !p.empty (); ++i) {
136+ add_build_type_dirs (p);
137+ p = p.parent_path ();
138+ }
139+ }
140+
141+ if (!exec_parent.empty ()) {
142+ possible_directories.push_back (exec_parent + " /" );
143+ }
76144
77145 for (const auto & filename : possible_filenames) {
78146 for (const auto & directory : possible_directories) {
@@ -83,7 +151,7 @@ std::string TestUtils::GetTestLibraryPath() {
83151 }
84152 }
85153
86- throw std::runtime_error (" Could not find library" );
154+ throw std::runtime_error (" test_utils.cc: Could not find DBPATestAgent library " );
87155}
88156
89157} // namespace parquet::encryption::external::test
0 commit comments