Skip to content

Commit b89aaf0

Browse files
authored
Merge pull request #1568 from millenomi/linux-bundle-executable
[SR-3077] Bundle.main.executableURL returns incorrect values on Linux
2 parents 920035a + 4928856 commit b89aaf0

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

CoreFoundation/PlugIn.subproj/CFBundle_Executable.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL
182182
if (executablePath) CFRetain(executablePath);
183183
__CFUnlock(&bundle->_lock);
184184
if (executablePath) {
185-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
186-
executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, executablePath, kCFURLPOSIXPathStyle, false);
187-
#elif DEPLOYMENT_TARGET_WINDOWS
188-
executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, executablePath, kCFURLWindowsPathStyle, false);
189-
#endif
185+
executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, executablePath, PLATFORM_PATH_STYLE, false);
190186
if (executableURL) {
191187
foundIt = true;
192188
}

TestFoundation/TestBundle.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ class TestBundle : XCTestCase {
250250
("test_bundlePreflight", test_bundlePreflight),
251251
("test_bundleFindExecutable", test_bundleFindExecutable),
252252
("test_bundleFindAuxiliaryExecutables", test_bundleFindAuxiliaryExecutables),
253+
("test_mainBundleExecutableURL", test_mainBundleExecutableURL),
253254
]
254255
}
255256

@@ -439,4 +440,12 @@ class TestBundle : XCTestCase {
439440
XCTAssertNil(bundle.url(forAuxiliaryExecutable: "does_not_exist_at_all"))
440441
}
441442
}
443+
444+
func test_mainBundleExecutableURL() {
445+
let maybeURL = Bundle.main.executableURL
446+
XCTAssertNotNil(maybeURL)
447+
guard let url = maybeURL else { return }
448+
449+
XCTAssertEqual(url.path, String(cString: _CFProcessPath()))
450+
}
442451
}

0 commit comments

Comments
 (0)