Skip to content

Commit 8228314

Browse files
committed
Tests: adjust the BuildPlanTests for Windows
The Windows toolchain does not find the default linker by default as that requires the sourcing of Visual Studio's scripts to setup the environment. Adjust the tests to explicitly specify the linker to ensure that the toolchain is usable on Windows without constraint on the environment. While in the area, adjust the expectations to account for platform path spellings. This allows us to pass these tests on Windows now. Adjust the path representation to account for Windows to allow the matching to succeed.
1 parent ab73215 commit 8228314

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Basics
13+
@testable import Basics
1414
@testable import Build
1515
@_implementationOnly import DriverSupport
1616
import PackageLoading
@@ -43,12 +43,14 @@ final class BuildPlanTests: XCTestCase {
4343
"/barPkg/Sources/BarLogging/file.swift"
4444
)
4545
let observability = ObservabilitySystem.makeForTesting()
46+
let fooPkg: AbsolutePath = "/fooPkg"
47+
let barPkg: AbsolutePath = "/barPkg"
4648
XCTAssertThrowsError(try loadPackageGraph(
4749
fileSystem: fs,
4850
manifests: [
4951
Manifest.createFileSystemManifest(
5052
displayName: "fooPkg",
51-
path: "/fooPkg",
53+
path: fooPkg,
5254
products: [
5355
ProductDescription(name: "Logging", type: .library(.dynamic), targets: ["FooLogging"]),
5456
],
@@ -57,7 +59,7 @@ final class BuildPlanTests: XCTestCase {
5759
]),
5860
Manifest.createFileSystemManifest(
5961
displayName: "barPkg",
60-
path: "/barPkg",
62+
path: barPkg,
6163
products: [
6264
ProductDescription(name: "Logging", type: .library(.static), targets: ["BarLogging"]),
6365
],
@@ -69,24 +71,21 @@ final class BuildPlanTests: XCTestCase {
6971
path: "/thisPkg",
7072
toolsVersion: .v5_8,
7173
dependencies: [
72-
.localSourceControl(path: "/fooPkg", requirement: .upToNextMajor(from: "1.0.0")),
73-
.localSourceControl(path: "/barPkg", requirement: .upToNextMajor(from: "2.0.0")),
74+
.localSourceControl(path: fooPkg, requirement: .upToNextMajor(from: "1.0.0")),
75+
.localSourceControl(path: barPkg, requirement: .upToNextMajor(from: "2.0.0")),
7476
],
7577
targets: [
7678
TargetDescription(name: "exe",
77-
dependencies: [.product(name: "Logging",
78-
package: "fooPkg"
79-
),
80-
.product(name: "Logging",
81-
package: "barPkg"
82-
),
79+
dependencies: [.product(name: "Logging", package: "fooPkg"),
80+
.product(name: "Logging", package: "barPkg"),
8381
],
8482
type: .executable),
8583
]),
8684
],
8785
observabilityScope: observability.topScope
8886
)) { error in
89-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '/barPkg'), 'foopkg' (at '/fooPkg')")
87+
XCTAssertEqual((error as? PackageGraphError)?.description,
88+
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
9089
}
9190
}
9291

@@ -418,13 +417,15 @@ final class BuildPlanTests: XCTestCase {
418417
"/barPkg/Sources/BarLogging/file.swift"
419418
)
420419
let observability = ObservabilitySystem.makeForTesting()
420+
let fooPkg: AbsolutePath = "/fooPkg"
421+
let barPkg: AbsolutePath = "/barPkg"
421422

422423
XCTAssertThrowsError(try loadPackageGraph(
423424
fileSystem: fs,
424425
manifests: [
425426
Manifest.createFileSystemManifest(
426427
displayName: "fooPkg",
427-
path: "/fooPkg",
428+
path: fooPkg,
428429
toolsVersion: .v5_8,
429430
products: [
430431
ProductDescription(name: "Logging", type: .library(.automatic), targets: ["FooLogging"]),
@@ -434,7 +435,7 @@ final class BuildPlanTests: XCTestCase {
434435
]),
435436
Manifest.createFileSystemManifest(
436437
displayName: "barPkg",
437-
path: "/barPkg",
438+
path: barPkg,
438439
products: [
439440
ProductDescription(name: "Logging", type: .library(.automatic), targets: ["BarLogging"]),
440441
],
@@ -450,19 +451,16 @@ final class BuildPlanTests: XCTestCase {
450451
],
451452
targets: [
452453
TargetDescription(name: "exe",
453-
dependencies: [.product(name: "Logging",
454-
package: "fooPkg"
455-
),
456-
.product(name: "Logging",
457-
package: "barPkg"
458-
),
454+
dependencies: [.product(name: "Logging", package: "fooPkg"),
455+
.product(name: "Logging", package: "barPkg"),
459456
],
460457
type: .executable),
461458
]),
462459
],
463460
observabilityScope: observability.topScope
464461
)) { error in
465-
XCTAssertEqual((error as? PackageGraphError)?.description, "multiple products named 'Logging' in: 'barpkg' (at '/barPkg'), 'foopkg' (at '/fooPkg')")
462+
XCTAssertEqual((error as? PackageGraphError)?.description,
463+
"multiple products named 'Logging' in: 'barpkg' (at '\(barPkg)'), 'foopkg' (at '\(fooPkg)')")
466464
}
467465
}
468466

@@ -3585,7 +3583,7 @@ final class BuildPlanTests: XCTestCase {
35853583
toolset: .init(
35863584
knownTools: [
35873585
.cCompiler: .init(extraCLIOptions: ["-I/fake/sdk/sysroot", "-clang-flag-from-json"]),
3588-
.swiftCompiler: .init(extraCLIOptions: ["-swift-flag-from-json"])
3586+
.swiftCompiler: .init(extraCLIOptions: ["-use-ld=lld", "-swift-flag-from-json"])
35893587
],
35903588
rootPaths: try UserToolchain.default.swiftSDK.toolset.rootPaths
35913589
),
@@ -3616,7 +3614,17 @@ final class BuildPlanTests: XCTestCase {
36163614
XCTAssertMatch(try lib.basicArguments(isCXX: false), args)
36173615

36183616
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
3619-
XCTAssertMatch(exe, ["-module-cache-path", "\(buildPath.appending(components: "ModuleCache"))", .anySequence, "-swift-flag-from-json", "-g", "-swift-command-line-flag", .anySequence, "-Xcc", "-clang-flag-from-json", "-Xcc", "-g", "-Xcc", "-clang-command-line-flag"])
3617+
XCTAssertMatch(exe, [
3618+
"-module-cache-path", "\(buildPath.appending(components: "ModuleCache"))",
3619+
.anySequence,
3620+
"-swift-flag-from-json",
3621+
.anySequence,
3622+
"-swift-command-line-flag",
3623+
.anySequence,
3624+
"-Xcc", "-clang-flag-from-json",
3625+
.anySequence,
3626+
"-Xcc", "-clang-command-line-flag"
3627+
])
36203628
}
36213629

36223630
func testUserToolchainWithToolsetCompileFlags() throws {
@@ -3799,14 +3807,17 @@ final class BuildPlanTests: XCTestCase {
37993807
XCTAssertNoDiagnostics(observability.diagnostics)
38003808

38013809
let targetTriple = try UserToolchain.default.targetTriple
3802-
let sdkIncludeSearchPath = "/usr/lib/swift_static/none/include"
3803-
let sdkLibrarySearchPath = "/usr/lib/swift_static/none/lib"
3810+
let sdkIncludeSearchPath = AbsolutePath("/usr/lib/swift_static/none/include")
3811+
let sdkLibrarySearchPath = AbsolutePath("/usr/lib/swift_static/none/lib")
38043812
let swiftSDK = try SwiftSDK(
38053813
targetTriple: targetTriple,
38063814
properties: .init(
38073815
sdkRootPath: "/fake/sdk",
3808-
includeSearchPaths: [sdkIncludeSearchPath],
3809-
librarySearchPaths: [sdkLibrarySearchPath]))
3816+
includeSearchPaths: [sdkIncludeSearchPath.pathString],
3817+
librarySearchPaths: [sdkLibrarySearchPath.pathString]),
3818+
toolset: .init(knownTools: [
3819+
.swiftCompiler: .init(extraCLIOptions: ["-use-ld=lld"]),
3820+
]))
38103821
let toolchain = try UserToolchain(swiftSDK: swiftSDK)
38113822
let buildParameters = mockBuildParameters(toolchain: toolchain)
38123823
let result = try BuildPlanResult(plan: BuildPlan(
@@ -4798,10 +4809,10 @@ final class BuildPlanTests: XCTestCase {
47984809
try llbuild.generateManifest(at: yaml)
47994810

48004811
let yamlContents: String = try fs.readFileContents(yaml)
4801-
XCTAssertMatch(yamlContents, .contains("""
4802-
inputs: ["/Pkg/Snippets/ASnippet.swift","/Pkg/.build/debug/Lib.swiftmodule"
4803-
"""))
4804-
4812+
let inputs: SerializedJSON = """
4813+
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift"))","\(AbsolutePath("/Pkg/.build/debug/Lib.swiftmodule"))"
4814+
"""
4815+
XCTAssertMatch(yamlContents, .contains(inputs.underlying))
48054816
}
48064817

48074818
private func sanitizerTest(_ sanitizer: PackageModel.Sanitizer, expectedName: String) throws {

0 commit comments

Comments
 (0)