Skip to content

Commit cf423cd

Browse files
committed
Move UserToolchain and Destination
Purpose of this is to make libSwift easier to use for parsing manifests.
1 parent 53e0734 commit cf423cd

File tree

13 files changed

+35
-11
lines changed

13 files changed

+35
-11
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Basic
1414
import Build
1515
import Utility
1616
import PackageGraph
17+
import Workspace
1718

1819
import func POSIX.exit
1920

Sources/TestSupport/Resources.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Build
1313
import Foundation
1414
import Commands
1515
import PackageLoading
16+
import Workspace
1617

1718
#if os(macOS)
1819
private func bundleRoot() -> AbsolutePath {

Sources/Workspace/Diagnostics.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ public enum ResolverDiagnostics {
134134
}
135135
}
136136

137+
public struct InvalidToolchainDiagnostic: DiagnosticData, Error {
138+
public static let id = DiagnosticID(
139+
type: InvalidToolchainDiagnostic.self,
140+
name: "org.swift.diags.invalid-toolchain",
141+
description: {
142+
$0 <<< "toolchain is invalid:" <<< { $0.error }
143+
}
144+
)
145+
146+
public let error: String
147+
public init(_ error: String) {
148+
self.error = error
149+
}
150+
}
151+
137152
public enum WorkspaceDiagnostics {
138153

139154
//MARK: - Errors

Sources/Commands/UserToolchain.swift renamed to Sources/Workspace/UserToolchain.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ public final class UserToolchain: Toolchain {
6161
/// Path to the xctest utility.
6262
///
6363
/// This is only present on macOS.
64-
let xctest: AbsolutePath?
64+
public let xctest: AbsolutePath?
6565

6666
/// Path to llbuild.
67-
let llbuild: AbsolutePath
67+
public let llbuild: AbsolutePath
6868

6969
/// The compilation destination object.
70-
let destination: Destination
70+
public let destination: Destination
7171

7272
/// Search paths from the PATH environment variable.
7373
let envSearchPaths: [AbsolutePath]
7474

7575
/// Returns the runtime library for the given sanitizer.
76-
func runtimeLibrary(for sanitizer: Sanitizer) throws -> AbsolutePath {
76+
public func runtimeLibrary(for sanitizer: Sanitizer) throws -> AbsolutePath {
7777
// FIXME: This is only for SwiftPM development time support. It is OK
7878
// for now but we shouldn't need to resolve the symlink. We need to lay
7979
// down symlinks to runtimes in our fake toolchain as part of the
@@ -85,7 +85,7 @@ public final class UserToolchain: Toolchain {
8585

8686
// Ensure that the runtime is present.
8787
guard localFileSystem.exists(runtime) else {
88-
throw Error.invalidToolchain(problem: "Missing runtime for \(sanitizer) sanitizer")
88+
throw InvalidToolchainDiagnostic("Missing runtime for \(sanitizer) sanitizer")
8989
}
9090

9191
return runtime
@@ -96,7 +96,7 @@ public final class UserToolchain: Toolchain {
9696
func validateCompiler(at path: AbsolutePath?) throws {
9797
guard let path = path else { return }
9898
guard localFileSystem.isExecutableFile(path) else {
99-
throw Error.invalidToolchain(problem: "could not find the `swiftc` at expected path \(path.asString)")
99+
throw InvalidToolchainDiagnostic("could not find the `swiftc` at expected path \(path.asString)")
100100
}
101101
}
102102

@@ -117,7 +117,7 @@ public final class UserToolchain: Toolchain {
117117
} else if let SWIFT_EXEC = SWIFT_EXEC {
118118
resolvedBinDirCompiler = SWIFT_EXEC
119119
} else {
120-
throw Error.invalidToolchain(problem: "could not find the `swiftc` at expected path \(binDirCompiler.asString)")
120+
throw InvalidToolchainDiagnostic("could not find the `swiftc` at expected path \(binDirCompiler.asString)")
121121
}
122122

123123
// The compiler for compilation tasks is SWIFT_EXEC or the bin dir compiler.
@@ -144,14 +144,14 @@ public final class UserToolchain: Toolchain {
144144
// No value in env, so search for `clang`.
145145
let foundPath = try Process.checkNonZeroExit(arguments: whichClangArgs).chomp()
146146
guard !foundPath.isEmpty else {
147-
throw Error.invalidToolchain(problem: "could not find `clang`")
147+
throw InvalidToolchainDiagnostic("could not find `clang`")
148148
}
149149
clangCompiler = AbsolutePath(foundPath)
150150
}
151151

152152
// Check that it's valid in the file system.
153153
guard localFileSystem.isExecutableFile(clangCompiler) else {
154-
throw Error.invalidToolchain(problem: "could not find `clang` at expected path \(clangCompiler.asString)")
154+
throw InvalidToolchainDiagnostic("could not find `clang` at expected path \(clangCompiler.asString)")
155155
}
156156
_clangCompiler = clangCompiler
157157
return clangCompiler
@@ -175,7 +175,7 @@ public final class UserToolchain: Toolchain {
175175
// Look for llbuild in bin dir.
176176
llbuild = binDir.appending(component: "swift-build-tool")
177177
guard localFileSystem.exists(llbuild) else {
178-
throw Error.invalidToolchain(problem: "could not find `llbuild` at expected path \(llbuild.asString)")
178+
throw InvalidToolchainDiagnostic("could not find `llbuild` at expected path \(llbuild.asString)")
179179
}
180180

181181

Tests/CommandsTests/BuildToolTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import XCTest
1313
import TestSupport
1414
import Basic
1515
import Commands
16+
import Workspace
1617

1718
struct BuildResult {
1819
let output: String

Tests/FunctionalPerformanceTests/BuildPerfTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Commands
1313
import TestSupport
1414
import Basic
1515
import Utility
16+
import Workspace
1617

1718
class BuildPerfTests: XCTestCasePerf {
1819

Tests/FunctionalTests/CFamilyTargetTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Basic
1515
import PackageModel
1616
import SourceControl
1717
import Utility
18+
import Workspace
1819

1920
typealias Process = Basic.Process
2021

Tests/FunctionalTests/DependencyResolutionTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Basic
1414
import Commands
1515
import TestSupport
1616
import SourceControl
17+
import Workspace
1718

1819
class DependencyResolutionTests: XCTestCase {
1920
func testInternalSimple() {

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import XCTest
1212
import TestSupport
1313
import Basic
14-
import struct Commands.Destination
1514
import PackageModel
1615
import Utility
1716
import SPMLibc
1817
import class Foundation.ProcessInfo
18+
import Workspace
1919

2020
typealias ProcessID = Basic.Process.ProcessID
2121

Tests/FunctionalTests/ModuleMapTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Commands
1313
import TestSupport
1414
import Basic
1515
import Utility
16+
import Workspace
1617

1718
class ModuleMapsTestCase: XCTestCase {
1819

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import TestSupport
1313
import XCTest
1414
import Utility
1515
import Commands
16+
import Workspace
1617

1718
class SwiftPMXCTestHelperTests: XCTestCase {
1819
func testBasicXCTestHelper() {

Tests/FunctionalTests/ToolsVersionTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import TestSupport
1616
import Commands
1717
import PackageModel
1818
import SourceControl
19+
import Workspace
1920

2021
class ToolsVersionTests: XCTestCase {
2122

0 commit comments

Comments
 (0)