Skip to content

Commit 9df513a

Browse files
committed
[Interpreter] Clean up the /usr/lib/swift fallback code.
- Check the target triple at runtime to decide whether to use the fallback. - Change isInResourceDir to actually check the resource dir. - Use ArrayRef<std::string> instead of std::vector<std::string>.
1 parent 3f77409 commit 9df513a

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
using namespace swift;
3131
using namespace llvm::opt;
3232

33-
#if defined(__APPLE__) && defined(__MACH__)
34-
/// The path for Swift libraries in the OS.
35-
#define OS_LIBRARY_PATH "/usr/lib/swift"
36-
#endif
33+
/// The path for Swift libraries in the OS on Darwin.
34+
#define DARWIN_OS_LIBRARY_PATH "/usr/lib/swift"
3735

3836
swift::CompilerInvocation::CompilerInvocation() {
3937
setTargetTriple(llvm::sys::getDefaultTargetTriple());
@@ -73,9 +71,8 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
7371
llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple));
7472
SearchPathOpts.RuntimeLibraryPaths.clear();
7573
SearchPathOpts.RuntimeLibraryPaths.push_back(LibPath.str());
76-
#if defined(__APPLE__) && defined(__MACH__)
77-
SearchPathOpts.RuntimeLibraryPaths.push_back(OS_LIBRARY_PATH);
78-
#endif
74+
if (Triple.isOSDarwin())
75+
SearchPathOpts.RuntimeLibraryPaths.push_back(DARWIN_OS_LIBRARY_PATH);
7976

8077
// Set up the import paths containing the swiftmodules for the libraries in
8178
// RuntimeLibraryPath.

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,12 +1066,9 @@ class ParseableInterfaceModuleLoaderImpl {
10661066
}
10671067

10681068
bool isInResourceDir(StringRef path) {
1069-
for (auto &RuntimeLibraryPath : ctx.SearchPathOpts.RuntimeLibraryPaths) {
1070-
if (path.startswith(RuntimeLibraryPath)) {
1071-
return true;
1072-
}
1073-
}
1074-
return false;
1069+
StringRef resourceDir = ctx.SearchPathOpts.RuntimeResourcePath;
1070+
if (resourceDir.empty()) return false;
1071+
return path.startswith(resourceDir);
10751072
}
10761073

10771074
/// Finds the most appropriate .swiftmodule, whose dependencies are up to

lib/Immediate/Immediate.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,25 @@ static void *loadRuntimeLib(StringRef runtimeLibPathWithName) {
5959
#endif
6060
}
6161

62-
static void *loadRuntimeLib(StringRef sharedLibName, StringRef runtimeLibPath) {
62+
static void *loadRuntimeLibAtPath(StringRef sharedLibName,
63+
StringRef runtimeLibPath) {
6364
// FIXME: Need error-checking.
6465
llvm::SmallString<128> Path = runtimeLibPath;
6566
llvm::sys::path::append(Path, sharedLibName);
6667
return loadRuntimeLib(Path);
6768
}
6869

6970
static void *loadRuntimeLib(StringRef sharedLibName,
70-
const std::vector<std::string> runtimeLibPaths) {
71+
ArrayRef<std::string> runtimeLibPaths) {
7172
for (auto &runtimeLibPath : runtimeLibPaths) {
72-
if (void *handle = loadRuntimeLib(sharedLibName, runtimeLibPath))
73+
if (void *handle = loadRuntimeLibAtPath(sharedLibName, runtimeLibPath))
7374
return handle;
7475
}
7576
return nullptr;
7677
}
7778

78-
void *swift::immediate::loadSwiftRuntime(const std::vector<std::string>
79-
&runtimeLibPaths) {
79+
void *swift::immediate::loadSwiftRuntime(ArrayRef<std::string>
80+
runtimeLibPaths) {
8081
return loadRuntimeLib("libswiftCore" LTDL_SHLIB_EXT, runtimeLibPaths);
8182
}
8283

lib/Immediate/ImmediateImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace immediate {
3737
/// Returns a handle to the runtime suitable for other \c dlsym or \c dlclose
3838
/// calls or \c null if an error occurred.
3939
///
40-
/// \param runtimeLibPath Path to search for compiler-relative stdlib dylibs.
41-
void *loadSwiftRuntime(const std::vector<std::string> &runtimeLibPaths);
40+
/// \param runtimeLibPaths Paths to search for stdlib dylibs.
41+
void *loadSwiftRuntime(ArrayRef<std::string> runtimeLibPaths);
4242
bool tryLoadLibraries(ArrayRef<LinkLibrary> LinkLibraries,
4343
SearchPathOptions SearchPathOpts,
4444
DiagnosticEngine &Diags);

0 commit comments

Comments
 (0)