[SR-6548] SwiftPM's POSIX.chdir never works when binary is found via $PATH
#4904 opened on Dec 6, 2017
Description
| Previous ID | SR-6548 |
| Radar | None |
| Original Reporter | jaybuff (JIRA User) |
| Type | Bug |
| Votes | 0 |
| Component/s | Package Manager |
| Labels | Bug, StarterBug |
| Assignee | legendecas (JIRA) |
| Priority | Medium |
md5: 7f6b9fff863f8eada827047e65debf1f
Issue Description:
I'm using SwiftPM's Utility product and ran into an issue with chdir. To reproduce the program has to be found on the path:
swift package init --type executable
- add swiftpm dependency to Package.swift like this:
.package(url: "https://github.com/apple/swift-package-manager.git", .exact("0.1.0"))
$ cat Sources/ChdirProg/main.swift
import POSIX
try chdir("/tmp")
swift build
export PATH=$PWD/.build/debug/:$PATH
ChdirProg
fatal error: Error raised at top level: realpath error: No such file or directory (2): ChdirProg: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.65.2/src/swift/stdlib/public/core/ErrorType.swift, line 187
This is because POSIX/chdir.swift calls realpath(CommandLine.arguments.first when the program name is resolved via $PATH.
I suspect this causes issues with --package-path, but am unsure how to cause this bug to manifest itself with swift build. Perhaps when swift build re-execs swift-build it always uses the full path?