10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- @testable import PackageModel
14
- @testable import TSCUtility
15
- @testable import Build
16
13
import Basics
14
+ import Build
15
+ import PackageModel
17
16
import SPMBuildCore
17
+ import TSCUtility
18
18
import XCTest
19
19
20
- struct MockToolchain : PackageModel . Toolchain {
20
+ public struct MockToolchain : PackageModel . Toolchain {
21
21
#if os(Windows)
22
- let librarianPath = AbsolutePath ( " /fake/path/to/link.exe " )
22
+ public let librarianPath = AbsolutePath ( " /fake/path/to/link.exe " )
23
23
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
24
- let librarianPath = AbsolutePath ( " /fake/path/to/libtool " )
24
+ public let librarianPath = AbsolutePath ( " /fake/path/to/libtool " )
25
25
#else
26
- let librarianPath = AbsolutePath ( " /fake/path/to/llvm-ar " )
26
+ public let librarianPath = AbsolutePath ( " /fake/path/to/llvm-ar " )
27
27
#endif
28
- let swiftCompilerPath = AbsolutePath ( " /fake/path/to/swiftc " )
29
- let includeSearchPaths = [ AbsolutePath] ( )
30
- let librarySearchPaths = [ AbsolutePath] ( )
31
- let swiftResourcesPath : AbsolutePath ? = nil
32
- let swiftStaticResourcesPath : AbsolutePath ? = nil
33
- let isSwiftDevelopmentToolchain = false
34
- let sdkRootPath : AbsolutePath ? = nil
35
- let swiftPluginServerPath : AbsolutePath ? = nil
36
- let extraFlags = PackageModel . BuildFlags ( )
37
- let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration . default
38
-
39
- func getClangCompiler( ) throws -> AbsolutePath {
28
+ public let swiftCompilerPath = AbsolutePath ( " /fake/path/to/swiftc " )
29
+ public let includeSearchPaths = [ AbsolutePath] ( )
30
+ public let librarySearchPaths = [ AbsolutePath] ( )
31
+ public let swiftResourcesPath : AbsolutePath ? = nil
32
+ public let swiftStaticResourcesPath : AbsolutePath ? = nil
33
+ public let isSwiftDevelopmentToolchain = false
34
+ public let sdkRootPath : AbsolutePath ? = nil
35
+ public let swiftPluginServerPath : AbsolutePath ? = nil
36
+ public let extraFlags = PackageModel . BuildFlags ( )
37
+ public let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration . default
38
+
39
+ public func getClangCompiler( ) throws -> AbsolutePath {
40
40
return " /fake/path/to/clang "
41
41
}
42
42
43
- func _isClangCompilerVendorApple( ) throws -> Bool ? {
43
+ public func _isClangCompilerVendorApple( ) throws -> Bool ? {
44
44
#if os(macOS)
45
45
return true
46
46
#else
47
47
return false
48
48
#endif
49
49
}
50
+
51
+ public init ( ) {
52
+ }
50
53
}
51
54
52
55
53
56
extension Basics . Triple {
54
- static let x86_64MacOS = try ! Self ( " x86_64-apple-macosx " )
55
- static let x86_64Linux = try ! Self ( " x86_64-unknown-linux-gnu " )
56
- static let arm64Linux = try ! Self ( " aarch64-unknown-linux-gnu " )
57
- static let arm64Android = try ! Self ( " aarch64-unknown-linux-android " )
58
- static let windows = try ! Self ( " x86_64-unknown-windows-msvc " )
59
- static let wasi = try ! Self ( " wasm32-unknown-wasi " )
57
+ public static let x86_64MacOS = try ! Self ( " x86_64-apple-macosx " )
58
+ public static let x86_64Linux = try ! Self ( " x86_64-unknown-linux-gnu " )
59
+ public static let arm64Linux = try ! Self ( " aarch64-unknown-linux-gnu " )
60
+ public static let arm64Android = try ! Self ( " aarch64-unknown-linux-android " )
61
+ public static let windows = try ! Self ( " x86_64-unknown-windows-msvc " )
62
+ public static let wasi = try ! Self ( " wasm32-unknown-wasi " )
60
63
}
61
64
62
- let hostTriple = try ! UserToolchain . default. targetTriple
65
+ public let hostTriple = try ! UserToolchain . default. targetTriple
63
66
#if os(macOS)
64
- let defaultTargetTriple : String = hostTriple. tripleString ( forPlatformVersion: " 10.13 " )
67
+ public let defaultTargetTriple : String = hostTriple. tripleString ( forPlatformVersion: " 10.13 " )
65
68
#else
66
- let defaultTargetTriple : String = hostTriple. tripleString
69
+ public let defaultTargetTriple : String = hostTriple. tripleString
67
70
#endif
68
71
69
- func mockBuildParameters(
72
+ public func mockBuildParameters(
70
73
buildPath: AbsolutePath = " /path/to/build " ,
71
74
config: BuildConfiguration = . debug,
72
75
toolchain: PackageModel . Toolchain = MockToolchain ( ) ,
@@ -108,7 +111,7 @@ func mockBuildParameters(
108
111
)
109
112
}
110
113
111
- func mockBuildParameters( environment: BuildEnvironment ) -> BuildParameters {
114
+ public func mockBuildParameters( environment: BuildEnvironment ) -> BuildParameters {
112
115
let triple : Basics . Triple
113
116
switch environment. platform {
114
117
case . macOS:
@@ -130,34 +133,34 @@ enum BuildError: Swift.Error {
130
133
case error( String )
131
134
}
132
135
133
- struct BuildPlanResult {
136
+ public struct BuildPlanResult {
134
137
135
- let plan : Build . BuildPlan
136
- let targetMap : [ String : TargetBuildDescription ]
137
- let productMap : [ String : Build . ProductBuildDescription ]
138
+ public let plan : Build . BuildPlan
139
+ public let targetMap : [ String : TargetBuildDescription ]
140
+ public let productMap : [ String : Build . ProductBuildDescription ]
138
141
139
- init ( plan: Build . BuildPlan ) throws {
142
+ public init ( plan: Build . BuildPlan ) throws {
140
143
self . plan = plan
141
144
self . productMap = try Dictionary ( throwingUniqueKeysWithValues: plan. buildProducts. compactMap { $0 as? Build . ProductBuildDescription } . map { ( $0. product. name, $0) } )
142
145
self . targetMap = try Dictionary ( throwingUniqueKeysWithValues: plan. targetMap. map { ( $0. 0 . name, $0. 1 ) } )
143
146
}
144
147
145
- func checkTargetsCount( _ count: Int , file: StaticString = #file, line: UInt = #line) {
148
+ public func checkTargetsCount( _ count: Int , file: StaticString = #file, line: UInt = #line) {
146
149
XCTAssertEqual ( plan. targetMap. count, count, file: file, line: line)
147
150
}
148
151
149
- func checkProductsCount( _ count: Int , file: StaticString = #file, line: UInt = #line) {
152
+ public func checkProductsCount( _ count: Int , file: StaticString = #file, line: UInt = #line) {
150
153
XCTAssertEqual ( plan. productMap. count, count, file: file, line: line)
151
154
}
152
155
153
- func target( for name: String ) throws -> TargetBuildDescription {
156
+ public func target( for name: String ) throws -> TargetBuildDescription {
154
157
guard let target = targetMap [ name] else {
155
158
throw BuildError . error ( " Target \( name) not found. " )
156
159
}
157
160
return target
158
161
}
159
162
160
- func buildProduct( for name: String ) throws -> Build . ProductBuildDescription {
163
+ public func buildProduct( for name: String ) throws -> Build . ProductBuildDescription {
161
164
guard let product = productMap [ name] else {
162
165
// <rdar://problem/30162871> Display the thrown error on macOS
163
166
throw BuildError . error ( " Product \( name) not found. " )
@@ -167,7 +170,7 @@ struct BuildPlanResult {
167
170
}
168
171
169
172
extension TargetBuildDescription {
170
- func swiftTarget( ) throws -> SwiftTargetBuildDescription {
173
+ public func swiftTarget( ) throws -> SwiftTargetBuildDescription {
171
174
switch self {
172
175
case . swift( let target) :
173
176
return target
@@ -176,7 +179,7 @@ extension TargetBuildDescription {
176
179
}
177
180
}
178
181
179
- func clangTarget( ) throws -> ClangTargetBuildDescription {
182
+ public func clangTarget( ) throws -> ClangTargetBuildDescription {
180
183
switch self {
181
184
case . clang( let target) :
182
185
return target
0 commit comments