Determine location of libc dynamically in wxDynamicLibrary test
Don't hard code the path to it, even different Linux versions use different paths, e.g. /lib/x86_64-linux-gnu under Debian and /lib64 under Fedora, so just try all the possibilities until we find something.
This commit is contained in:
parent
f27acce6cd
commit
512b8033fe
1 changed files with 53 additions and 28 deletions
|
|
@ -28,42 +28,67 @@ TEST_CASE("DynamicLibrary::Load", "[dynlib]")
|
|||
#if defined(__WINDOWS__)
|
||||
static const char* const LIB_NAME = "kernel32.dll";
|
||||
static const char* const FUNC_NAME = "lstrlenA";
|
||||
#else // !__WINDOWS__
|
||||
#if defined(__DARWIN__)
|
||||
static const char* const LIB_NAME = "/usr/lib/libc.dylib";
|
||||
#elif defined(__LINUX__)
|
||||
#ifdef __x86_64__
|
||||
static const char* const LIB_NAME = "/lib/x86_64-linux-gnu/libc.so.6";
|
||||
#else
|
||||
static const char* const LIB_NAME = "/lib/libc.so.6";
|
||||
#endif
|
||||
#elif defined(__FreeBSD__)
|
||||
static const char* const LIB_NAME = "/lib/libc.so.7";
|
||||
#else
|
||||
static const char* const LIB_NAME = "/unknown/libc/location";
|
||||
#endif
|
||||
static const char* const FUNC_NAME = "strlen";
|
||||
|
||||
#elif defined(__DARWIN__)
|
||||
// Under macOS 12+ we can actually load the libc dylib even though the
|
||||
// corresponding file doesn't exist on disk, so skip this check there.
|
||||
#ifndef __DARWIN__
|
||||
if ( !wxFileName::Exists(LIB_NAME) )
|
||||
// corresponding file doesn't exist on disk, so we have to handle it
|
||||
// differently.
|
||||
static const char* const LIB_NAME = "/usr/lib/libc.dylib";
|
||||
static const char* const FUNC_NAME = "strlen";
|
||||
#else // other Unix
|
||||
static const char* const candidateDirs[] =
|
||||
{
|
||||
WARN("Shared library \"" << LIB_NAME << "\" doesn't exist, "
|
||||
"skipping DynamicLibraryTestCase::Load() test.");
|
||||
"/lib/x86_64-linux-gnu",
|
||||
"/lib",
|
||||
"/lib64",
|
||||
"/usr/lib",
|
||||
};
|
||||
|
||||
wxArrayString paths;
|
||||
wxDir::GetAllFiles("/lib", &paths, "libc.*", wxDIR_FILES);
|
||||
wxDir::GetAllFiles("/usr/lib", &paths, "libc.*", wxDIR_FILES);
|
||||
if ( !paths.empty() )
|
||||
static const char* const candidateVersions[] = { "6", "7", };
|
||||
|
||||
wxString LIB_NAME;
|
||||
wxArrayString allMatches;
|
||||
for ( size_t n = 0; n < WXSIZEOF(candidateDirs); ++n )
|
||||
{
|
||||
const wxString dir(candidateDirs[n]);
|
||||
|
||||
if ( !wxDir::Exists(dir) )
|
||||
continue;
|
||||
|
||||
for ( size_t m = 0; m < WXSIZEOF(candidateVersions); ++m )
|
||||
{
|
||||
WARN("Possible candidates:\n" << wxJoin(paths, '\n'));
|
||||
const wxString candidate = wxString::Format
|
||||
(
|
||||
"%s/libc.so.%s",
|
||||
dir, candidateVersions[m]
|
||||
);
|
||||
|
||||
if ( wxFileName::Exists(candidate) )
|
||||
{
|
||||
LIB_NAME = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !LIB_NAME.empty() )
|
||||
break;
|
||||
|
||||
wxDir::GetAllFiles(dir, &allMatches, "libc.*", wxDIR_FILES);
|
||||
}
|
||||
|
||||
if ( LIB_NAME.empty() )
|
||||
{
|
||||
WARN("Couldn't find libc.so, skipping DynamicLibrary::Load() test.");
|
||||
|
||||
if ( !allMatches.empty() )
|
||||
{
|
||||
WARN("Possible candidates:\n" << wxJoin(allMatches, '\n'));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif // !__DARWIN__
|
||||
#endif // __WINDOWS__/!__WINDOWS__
|
||||
|
||||
static const char* const FUNC_NAME = "strlen";
|
||||
#endif // OS
|
||||
|
||||
wxDynamicLibrary lib(LIB_NAME);
|
||||
REQUIRE( lib.IsLoaded() );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue