swiftlang/swift-package-manager

[SR-6548] SwiftPM's POSIX.chdir never works when binary is found via $PATH

Open

#4904 aperta il 6 dic 2017

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Swift (1462 fork)batch import
buggood first issue

Metriche repository

Star
 (10.145 star)
Metriche merge PR
 (Merge medio 9g 13h) (90 PR mergiate in 30 g)

Descrizione

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

  1. 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?

Guida contributor