Skip to content

Fix search for the Swift compiler on Windows #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Sources/TSCBasic/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ private struct UNIXPath: Path {
return name != "" && name != "." && name != ".." && !name.contains("/")
}

#if os(Windows)
static func isAbsolutePath(_ path: String) -> Bool {
return !path.withCString(encodedAs: UTF16.self, PathIsRelativeW)
}
#endif

var dirname: String {
#if os(Windows)
let dir = string.deletingLastPathComponent
Expand All @@ -421,7 +427,11 @@ private struct UNIXPath: Path {
}

var isAbsolute: Bool {
string.hasPrefix("/")
#if os(Windows)
return UNIXPath.isAbsolutePath(string)
#else
return string.hasPrefix("/")
#endif
}

var basename: String {
Expand Down Expand Up @@ -608,7 +618,7 @@ private struct UNIXPath: Path {
defer { fsr.deallocate() }

let realpath = String(cString: fsr)
if realpath.withCString(encodedAs: UTF16.self, PathIsRelativeW) {
if !UNIXPath.isAbsolutePath(realpath) {
throw PathValidationError.invalidAbsolutePath(path)
}
self.init(normalizingAbsolutePath: path)
Expand All @@ -630,7 +640,7 @@ private struct UNIXPath: Path {
defer { fsr.deallocate() }

let realpath: String = String(cString: fsr)
if !realpath.withCString(encodedAs: UTF16.self, PathIsRelativeW) {
if UNIXPath.isAbsolutePath(realpath) {
throw PathValidationError.invalidRelativePath(path)
}
self.init(normalizingRelativePath: path)
Expand Down
18 changes: 9 additions & 9 deletions Sources/TSCBasic/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ public func getEnvSearchPaths(
currentWorkingDirectory: AbsolutePath?
) -> [AbsolutePath] {
// Compute search paths from PATH variable.
return (pathString ?? "").split(separator: ":").map(String.init).compactMap({ pathString in
// If this is an absolute path, we're done.
if pathString.first == "/" {
return AbsolutePath(pathString)
}
// Otherwise convert it into absolute path relative to the working directory.
guard let cwd = currentWorkingDirectory else {
return nil
#if os(Windows)
let pathSeparator: Character = ";"
#else
let pathSeparator: Character = ":"
#endif
return (pathString ?? "").split(separator: pathSeparator).map(String.init).compactMap({ pathString in
if let cwd = currentWorkingDirectory {
return AbsolutePath(pathString, relativeTo: cwd)
}
return AbsolutePath(pathString, relativeTo: cwd)
return try? AbsolutePath(validating: pathString)
})
}

Expand Down