Skip to content
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
1 change: 1 addition & 0 deletions Sources/Basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ add_library(Basics
Netrc.swift
Observability.swift
OSSignpost.swift
Process.swift
ProgressAnimation/NinjaProgressAnimation.swift
ProgressAnimation/PercentProgressAnimation.swift
ProgressAnimation/ProgressAnimationProtocol.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ public enum OperatingSystem: Hashable, Sendable {
case windows
case linux
case android
case freebsd
case unknown
}

extension ProcessInfo {
#if os(macOS)
public static let hostOperatingSystem = OperatingSystem.macOS
#elseif os(Linux)
public static let hostOperatingSystem = OperatingSystem.linux
#elseif os(Windows)
public static let hostOperatingSystem = OperatingSystem.windows
#else
public static let hostOperatingSystem = OperatingSystem.unknown
#endif
public static var hostOperatingSystem: OperatingSystem {
#if os(macOS)
.macOS
#elseif os(Linux)
.linux
#elseif os(Windows)
.windows
#elseif os(FreeBSD)
.freebsd
#else
.unknown
#endif
}

#if os(Windows)
public static let EOL = "\r\n"
Expand Down
37 changes: 33 additions & 4 deletions Sources/PackageModel/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import Basics
import Foundation

public protocol Toolchain {
/// Path of the librarian.
Expand Down Expand Up @@ -88,12 +89,33 @@ extension Toolchain {
}
}

/// Base toolchain path that's given to Swift Build to initialize its core.
public var toolchainDir: AbsolutePath {
get throws {
try resolveSymlinks(swiftCompilerPath)
.parentDirectory // bin
.parentDirectory // usr
.parentDirectory // <toolchain>
let compilerPath = try resolveSymlinks(swiftCompilerPath)
let os = ProcessInfo.hostOperatingSystem
switch os {
case .windows:
return compilerPath
.parentDirectory // bin
.parentDirectory // usr
.parentDirectory // <version>
.parentDirectory // Toolchains
.parentDirectory // <toolchain>
case .macOS, .linux, .android:
return compilerPath
.parentDirectory // bin
.parentDirectory // usr
.parentDirectory // <toolchain>
case .freebsd:
return compilerPath
.parentDirectory // bin
.parentDirectory // local
.parentDirectory // usr
.parentDirectory // <toolchain>
case .unknown:
throw UnknownToolchainLayout(os: os)
}
}
}

Expand Down Expand Up @@ -128,3 +150,10 @@ extension Toolchain {
try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
}
}

struct UnknownToolchainLayout: Error, CustomStringConvertible {
let os: OperatingSystem
var description: String {
"Unknown toolchain layout for host operating system: \(os)"
}
}
1 change: 1 addition & 0 deletions Sources/_InternalTestSupport/SkippedTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import class Foundation.FileManager
import class Foundation.ProcessInfo
import Basics
import Testing

extension Trait where Self == Testing.ConditionTrait {
Expand Down