diff --git a/CoreFoundation/PlugIn.subproj/CFBundle_Executable.c b/CoreFoundation/PlugIn.subproj/CFBundle_Executable.c index 7e3b39d186..dbb33d8eb3 100644 --- a/CoreFoundation/PlugIn.subproj/CFBundle_Executable.c +++ b/CoreFoundation/PlugIn.subproj/CFBundle_Executable.c @@ -182,11 +182,7 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL if (executablePath) CFRetain(executablePath); __CFUnlock(&bundle->_lock); if (executablePath) { -#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI - executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, executablePath, kCFURLPOSIXPathStyle, false); -#elif DEPLOYMENT_TARGET_WINDOWS - executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, executablePath, kCFURLWindowsPathStyle, false); -#endif + executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, executablePath, PLATFORM_PATH_STYLE, false); if (executableURL) { foundIt = true; } diff --git a/TestFoundation/TestBundle.swift b/TestFoundation/TestBundle.swift index c5dba82a5f..d5e8f5f6ea 100644 --- a/TestFoundation/TestBundle.swift +++ b/TestFoundation/TestBundle.swift @@ -250,6 +250,7 @@ class TestBundle : XCTestCase { ("test_bundlePreflight", test_bundlePreflight), ("test_bundleFindExecutable", test_bundleFindExecutable), ("test_bundleFindAuxiliaryExecutables", test_bundleFindAuxiliaryExecutables), + ("test_mainBundleExecutableURL", test_mainBundleExecutableURL), ] } @@ -439,4 +440,12 @@ class TestBundle : XCTestCase { XCTAssertNil(bundle.url(forAuxiliaryExecutable: "does_not_exist_at_all")) } } + + func test_mainBundleExecutableURL() { + let maybeURL = Bundle.main.executableURL + XCTAssertNotNil(maybeURL) + guard let url = maybeURL else { return } + + XCTAssertEqual(url.path, String(cString: _CFProcessPath())) + } }