Skip to content

Commit 7f1461b

Browse files
committed
Fix the paths up a little, and address a linking issue on Windows.
The path to the runtime should be something like /usr/lib/swift/libswiftCore.dylib So we want to strip lib/swift/ off to get the Swift root. We also want auxiliary executables in /usr/libexec/swift rather than just /usr/libexec (While still supporting flat layout for Windows.) rdar://103071801
1 parent 09723c4 commit 7f1461b

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

stdlib/public/runtime/Paths.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ _swift_getDefaultRootPath()
9999
const char *ptr = runtimePath + runtimePathLen;
100100
while (ptr > runtimePath && !_swift_isPathSep(*--ptr));
101101

102-
// Remove the "lib" directory if it's present
103-
if (ptr - runtimePath >= 4
104-
&& _swift_isPathSep(ptr[-4])
105-
&& std::strncmp(ptr - 3, "lib", 3) == 0) {
106-
ptr -= 4;
102+
// Remove lib/swift/ if present
103+
if (ptr - runtimePath >= 10
104+
&& _swift_isPathSep(ptr[-10])
105+
&& std::strncmp(ptr - 9, "lib", 3) == 0
106+
&& _swift_isPathSep(ptr[-6])
107+
&& std::strncmp(ptr - 5, "swift", 5) == 0) {
108+
ptr -= 10;
107109
}
108110

109111
// If the result is empty, return "./" or ".\\"
@@ -152,9 +154,9 @@ swift_getAuxiliaryExecutablePath(const char *name)
152154
{
153155
const char *rootPath = swift_getRootPath();
154156

155-
// Form <rootPath>/libexec/
157+
// Form <rootPath>/libexec/swift/
156158
size_t rootPathLen = std::strlen(rootPath);
157-
const char *libexecStr = PATHSEP_STR "libexec" PATHSEP_STR;
159+
const char *libexecStr = PATHSEP_STR "libexec" PATHSEP_STR "swift" PATHSEP_STR;
158160
size_t libexecLen = std::strlen(libexecStr);
159161
char *libexecPath = (char *)malloc(rootPathLen + libexecLen + 1);
160162
std::memcpy(libexecPath, rootPath, rootPathLen);

test/Runtime/Paths.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-clang %s -std=c++11 -I %swift_src_root/include -I %swift_src_root/stdlib/public/SwiftShims -I %clang-include-dir -isysroot %sdk %platform-dylib-dir/%target-library-name(swiftCore) -o %t/paths-test
2+
// RUN: %target-clang %s -std=c++11 -I %swift_src_root/include -I %swift_src_root/stdlib/public/SwiftShims -I %clang-include-dir -isysroot %sdk -L %swift_obj_root/lib/swift/%target-sdk-name -lswiftCore -o %t/paths-test
33
// RUN: %target-codesign %t/paths-test
44
// RUN: %target-run %t/paths-test | %FileCheck %s
55

@@ -45,6 +45,11 @@ isfile(const char *path) {
4545
return stat(path, &st) == 0 && !(st.st_mode & S_IFDIR);
4646
}
4747

48+
static bool
49+
containsLibSwift(const char *path) {
50+
return strstr(path, "/lib/swift/") != 0 || strstr(path, "\\lib\\swift\\") != 0;
51+
}
52+
4853
int main(void) {
4954
const char *runtimePath = swift_getRuntimePath();
5055

@@ -64,6 +69,12 @@ int main(void) {
6469
printf("root path: %s\n", rootPath ? rootPath : "<NULL>");
6570
printf("root is a directory: %s\n", isdir(rootPath) ? "yes" : "no");
6671

72+
// Root path should not contain /lib/swift
73+
74+
// CHECK: root path contains /lib/swift: no
75+
printf("root path contains /lib/swift: %s\n",
76+
containsLibSwift(rootPath) ? "yes" : "no");
77+
6778
// Auxiliary executable path must be in swift-root/libexec.
6879
#define UNLIKELY_NAME "anUnlikelyExecutableName"
6980

0 commit comments

Comments
 (0)