diff --git a/Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift b/Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift index cf7e63d8d..67a197b9d 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/FirstWaveComputer.swift @@ -188,7 +188,7 @@ extension IncrementalCompilationState.FirstWaveComputer { let invalidateOutOfDate = { (modulesRequiringRebuild: inout Set) in reporter?.reportExplicitDependencyWillBeReBuilt(moduleId.moduleNameForDiagnostic, reason: "Out-of-date") modulesRequiringRebuild.insert(moduleId) - try invalidatePath(&modulesRequiringRebuild) + invalidatePath(&modulesRequiringRebuild) } // Visit the module's dependencies @@ -202,10 +202,10 @@ extension IncrementalCompilationState.FirstWaveComputer { } if modulesRequiringRebuild.contains(moduleId) { - try invalidatePath(&modulesRequiringRebuild) + invalidatePath(&modulesRequiringRebuild) } else if try !IncrementalCompilationState.IncrementalDependencyAndInputSetup.verifyModuleDependencyUpToDate(moduleID: moduleId, moduleInfo: moduleInfo, fileSystem: fileSystem, reporter: reporter) { - try invalidateOutOfDate(&modulesRequiringRebuild) + invalidateOutOfDate(&modulesRequiringRebuild) } else { // Only if this module is known to be up-to-date with respect to its inputs // and dependencies do we mark it as visited. We may need to re-visit diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index 519029afa..9d8eeff53 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -138,7 +138,7 @@ extension Driver { if let value = parsedOptions.getLastArgument(rootArg)?.asSingle, isFrontendArgSupported(rootArg) { commandLine.appendFlag(rootArg.spelling) - commandLine.appendPath(.init(value)) + commandLine.appendPath(try .init(validating: value)) } if let value = parsedOptions.getLastArgument(versionArg)?.asSingle, diff --git a/Sources/swift-build-sdk-interfaces/main.swift b/Sources/swift-build-sdk-interfaces/main.swift index 9a71e5642..f79225df2 100644 --- a/Sources/swift-build-sdk-interfaces/main.swift +++ b/Sources/swift-build-sdk-interfaces/main.swift @@ -83,7 +83,8 @@ do { // append the SDK version number so all modules will built into // the SDK-versioned sub-directory. if outputDir.basename == "prebuilt-modules" { - outputDir = try AbsolutePath(validating: collector.versionString, relativeTo: outputDir) + outputDir = try AbsolutePath(validating: collector.versionString, + relativeTo: outputDir) } if !localFileSystem.exists(outputDir) { try localFileSystem.createDirectory(outputDir, recursive: true) @@ -100,10 +101,10 @@ do { } else { swiftcPath = try AbsolutePath(validating: "Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", relativeTo: sdkPath.parentDirectory - .parentDirectory - .parentDirectory - .parentDirectory - .parentDirectory) + .parentDirectory + .parentDirectory + .parentDirectory + .parentDirectory) } if !localFileSystem.exists(swiftcPath) { diagnosticsEngine.emit(error: "cannot find swift compiler: \(swiftcPath.pathString)") diff --git a/Tests/SwiftDriverTests/APIDigesterTests.swift b/Tests/SwiftDriverTests/APIDigesterTests.swift index f3b697ed3..1349a6166 100644 --- a/Tests/SwiftDriverTests/APIDigesterTests.swift +++ b/Tests/SwiftDriverTests/APIDigesterTests.swift @@ -112,7 +112,7 @@ class APIDigesterTests: XCTestCase { "-output-file-map", ofmPath.pathString, ]) let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .generateABIBaseline }) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/path/to/baseline.abi.json")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/path/to/baseline.abi.json")))])) } } do { @@ -136,7 +136,7 @@ class APIDigesterTests: XCTestCase { "-output-file-map", ofmPath.pathString, ]) let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .generateABIBaseline }) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/path/to/sourceinfo.abi.json")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/path/to/sourceinfo.abi.json")))])) } } } @@ -149,8 +149,8 @@ class APIDigesterTests: XCTestCase { XCTAssertTrue(digesterJob.commandLine.contains("-dump-sdk")) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init(validating: "/path/to/sdk")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init(validating: "/some/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.relative(.init("foo.api.json")))])) @@ -165,8 +165,8 @@ class APIDigesterTests: XCTestCase { XCTAssertTrue(digesterJob.commandLine.contains("-dump-sdk")) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init(validating: "/path/to/sdk")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init(validating: "/some/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-o", .path(.relative(.init("foo.abi.json")))])) @@ -238,10 +238,10 @@ class APIDigesterTests: XCTestCase { let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .compareAPIBaseline }) XCTAssertTrue(digesterJob.commandLine.contains("-diagnose-sdk")) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-module", "foo"])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-baseline-path", .path(.absolute(.init("/baseline/path")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-baseline-path", .path(.absolute(.init(validating: "/baseline/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.relative(.init(".")))])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/path/to/sdk")))])) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init("/some/path")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init(validating: "/path/to/sdk")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-I", .path(.absolute(.init(validating: "/some/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-F", .path(.relative(.init("framework/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-breakage-allowlist-path", .path(.relative(.init("allowlist/path")))])) @@ -257,7 +257,7 @@ class APIDigesterTests: XCTestCase { "-digester-breakage-allowlist-path", "allowlist/path"]) let digesterJob = try XCTUnwrap(driver.planBuild().first { $0.kind == .compareABIBaseline }) XCTAssertTrue(digesterJob.commandLine.contains("-diagnose-sdk")) - XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-input-paths", .path(.absolute(.init("/baseline/path")))])) + try XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-input-paths", .path(.absolute(.init(validating: "/baseline/path")))])) XCTAssertTrue(digesterJob.commandLine.contains(subsequence: ["-breakage-allowlist-path", .path(.relative(.init("allowlist/path")))])) XCTAssertTrue(digesterJob.commandLine.contains("-abi")) diff --git a/Tests/SwiftDriverTests/CachingBuildTests.swift b/Tests/SwiftDriverTests/CachingBuildTests.swift index ab47db4bd..494c2cda0 100644 --- a/Tests/SwiftDriverTests/CachingBuildTests.swift +++ b/Tests/SwiftDriverTests/CachingBuildTests.swift @@ -16,13 +16,15 @@ import TSCBasic import XCTest import TestUtilities -private var testInputsPath: AbsolutePath = { - var root: AbsolutePath = AbsolutePath(#file) - while root.basename != "Tests" { - root = root.parentDirectory +private var testInputsPath: AbsolutePath { + get throws { + var root: AbsolutePath = try AbsolutePath(validating: #file) + while root.basename != "Tests" { + root = root.parentDirectory + } + return root.parentDirectory.appending(component: "TestInputs") } - return root.parentDirectory.appending(component: "TestInputs") -}() +} private func checkCachingBuildJob(job: Job, moduleId: ModuleDependencyId, @@ -151,14 +153,14 @@ final class CachingBuildTests: XCTestCase { $0 <<< "import G;" } let casPath = path.appending(component: "cas") + let swiftModuleInterfacesPath: AbsolutePath = + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let bridgingHeaderpath: AbsolutePath = cHeadersPath.appending(component: "Bridging.h") - let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-macosx11.0", @@ -282,11 +284,11 @@ final class CachingBuildTests: XCTestCase { } let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let casPath = path.appending(component: "cas") let swiftInterfacePath: AbsolutePath = path.appending(component: "testExplicitModuleVerifyInterfaceJobs.swiftinterface") let privateSwiftInterfacePath: AbsolutePath = path.appending(component: "testExplicitModuleVerifyInterfaceJobs.private.swiftinterface") @@ -431,11 +433,11 @@ final class CachingBuildTests: XCTestCase { } let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -550,11 +552,11 @@ final class CachingBuildTests: XCTestCase { } let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let casPath = path.appending(component: "cas") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", diff --git a/Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift b/Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift index 76305704c..34a75cdce 100644 --- a/Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift +++ b/Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift @@ -22,7 +22,7 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker /// /// Ensure that a round-trip fails when the minor version number changes func testSerializedVersionChangeDetection() throws { - let mockPath = try VirtualPath.absolute(AbsolutePath(validating: "/module-dependency-graph")) + let mockPath = VirtualPath.absolute(try AbsolutePath(validating: "/module-dependency-graph")) let fs = InMemoryFileSystem() let graph = Self.mockGraphCreator.mockUpAGraph() let currentVersion = ModuleDependencyGraph.serializedGraphVersion @@ -55,7 +55,7 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker } func roundTrip(_ originalGraph: ModuleDependencyGraph) throws { - let mockPath = try VirtualPath.absolute(AbsolutePath(validating: "/module-dependency-graph")) + let mockPath = VirtualPath.absolute(try AbsolutePath(validating: "/module-dependency-graph")) let fs = InMemoryFileSystem() let outputFileMap = OutputFileMap.mock(maxIndex: Self.maxIndex) diff --git a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift index a62c810f0..f77799d8c 100644 --- a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift +++ b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift @@ -16,13 +16,15 @@ import TSCBasic import XCTest import TestUtilities -private var testInputsPath: AbsolutePath = { - var root: AbsolutePath = AbsolutePath(#file) - while root.basename != "Tests" { - root = root.parentDirectory +private var testInputsPath: AbsolutePath { + get throws { + var root: AbsolutePath = try AbsolutePath(validating: #file) + while root.basename != "Tests" { + root = root.parentDirectory + } + return root.parentDirectory.appending(component: "TestInputs") } - return root.parentDirectory.appending(component: "TestInputs") -}() +} /// Check that an explicit module build job contains expected inputs and options private func checkExplicitModuleBuildJob(job: Job, @@ -177,11 +179,11 @@ final class ExplicitModuleBuildTests: XCTestCase { func testModuleDependencyBuildCommandGenerationWithExternalFramework() throws { do { let externalDetails: ExternalTargetModuleDetailsMap = - [.swiftPrebuiltExternal("A"): ExternalTargetModuleDetails(path: AbsolutePath("/tmp/A.swiftmodule"), + try [.swiftPrebuiltExternal("A"): ExternalTargetModuleDetails(path: AbsolutePath(validating: "/tmp/A.swiftmodule"), isFramework: true), - .swiftPrebuiltExternal("K"): ExternalTargetModuleDetails(path: AbsolutePath("/tmp/K.swiftmodule"), + .swiftPrebuiltExternal("K"): ExternalTargetModuleDetails(path: AbsolutePath(validating: "/tmp/K.swiftmodule"), isFramework: true), - .swiftPrebuiltExternal("simpleTestModule"): ExternalTargetModuleDetails(path: AbsolutePath("/tmp/simpleTestModule.swiftmodule"), + .swiftPrebuiltExternal("simpleTestModule"): ExternalTargetModuleDetails(path: AbsolutePath(validating: "/tmp/simpleTestModule.swiftmodule"), isFramework: true)] var driver = try Driver(args: ["swiftc", "-explicit-module-build", "-module-name", "simpleTestModule", @@ -247,13 +249,13 @@ final class ExplicitModuleBuildTests: XCTestCase { ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let bridgingHeaderpath: AbsolutePath = cHeadersPath.appending(component: "Bridging.h") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-macosx11.0", @@ -366,11 +368,11 @@ final class ExplicitModuleBuildTests: XCTestCase { } let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftInterfacePath: AbsolutePath = path.appending(component: "testExplicitModuleVerifyInterfaceJobs.swiftinterface") let privateSwiftInterfacePath: AbsolutePath = path.appending(component: "testExplicitModuleVerifyInterfaceJobs.private.swiftinterface") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] @@ -498,14 +500,14 @@ final class ExplicitModuleBuildTests: XCTestCase { """ ) + let swiftModuleInterfacesPath: AbsolutePath = + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let bridgingHeaderpath: AbsolutePath = cHeadersPath.appending(component: "Bridging.h") - let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] let pchOutputDir: AbsolutePath = path var driver = try Driver(args: ["swiftc", @@ -625,11 +627,11 @@ final class ExplicitModuleBuildTests: XCTestCase { try localFileSystem.writeFileContents(main, bytes: "import C\n") let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swift", "-target", "x86_64-apple-macosx11.0", @@ -829,8 +831,8 @@ final class ExplicitModuleBuildTests: XCTestCase { func testModuleAliasingInterfaceWithScanDeps() throws { try withTemporaryDirectory { path in let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] let (stdLibPath, shimsPath, _, _) = try getDriverArtifactsForScanning() @@ -1107,11 +1109,11 @@ final class ExplicitModuleBuildTests: XCTestCase { ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -1217,7 +1219,7 @@ final class ExplicitModuleBuildTests: XCTestCase { env: ProcessEnv.vars) let sdkPath = try executor.checkNonZeroExit( args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp() - let stdLibPath = AbsolutePath(sdkPath).appending(component: "usr") + let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr") .appending(component: "lib") .appending(component: "swift") return (stdLibPath, stdLibPath.appending(component: "shims")) @@ -1286,11 +1288,11 @@ final class ExplicitModuleBuildTests: XCTestCase { """ ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] let scannerCommand = ["-scan-dependencies", "-import-prescan", @@ -1392,11 +1394,11 @@ final class ExplicitModuleBuildTests: XCTestCase { try localFileSystem.writeFileContents(main, bytes: "import S;") let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -1464,11 +1466,11 @@ final class ExplicitModuleBuildTests: XCTestCase { ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -1563,8 +1565,8 @@ final class ExplicitModuleBuildTests: XCTestCase { import G; """ ) - let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds").appending(component: "CHeaders") - let swiftModuleInterfacesPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds").appending(component: "Swift") + let cHeadersPath: AbsolutePath = try testInputsPath.appending(component: "ExplicitModuleBuilds").appending(component: "CHeaders") + let swiftModuleInterfacesPath: AbsolutePath = try testInputsPath.appending(component: "ExplicitModuleBuilds").appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] let baseCommandLine = ["swiftc", @@ -1664,11 +1666,11 @@ final class ExplicitModuleBuildTests: XCTestCase { ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -1720,11 +1722,11 @@ final class ExplicitModuleBuildTests: XCTestCase { ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -1860,11 +1862,11 @@ final class ExplicitModuleBuildTests: XCTestCase { ) let cHeadersPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "CHeaders") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = - testInputsPath.appending(component: "ExplicitModuleBuilds") - .appending(component: "Swift") + try testInputsPath.appending(component: "ExplicitModuleBuilds") + .appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", "-I", cHeadersPath.nativePathString(escaped: true), @@ -1931,7 +1933,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } let mockSDKPath: String = - testInputsPath.appending(component: "mock-sdk.sdk").pathString + try testInputsPath.appending(component: "mock-sdk.sdk").pathString let diagnosticEnging = DiagnosticsEngine() let collector = try SDKPrebuiltModuleInputsCollector(VirtualPath(path: mockSDKPath).absolutePath!, diagnosticEnging) let interfaceMap = try collector.collectSwiftInterfaceMap().inputMap @@ -2101,9 +2103,9 @@ final class ExplicitModuleBuildTests: XCTestCase { XCTAssertTrue(current.file.basename == baseline.file.basename) } let mockSDKPath: String = - testInputsPath.appending(component: "mock-sdk.sdk").pathString + try testInputsPath.appending(component: "mock-sdk.sdk").pathString let baselineABIPath: String = - testInputsPath.appending(component: "ABIBaselines").pathString + try testInputsPath.appending(component: "ABIBaselines").pathString let collector = try SDKPrebuiltModuleInputsCollector(VirtualPath(path: mockSDKPath).absolutePath!, DiagnosticsEngine()) let interfaceMap = try collector.collectSwiftInterfaceMap().inputMap try withTemporaryDirectory { path in @@ -2128,7 +2130,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } } func testPrebuiltModuleInternalSDK() throws { - let mockSDKPath = testInputsPath.appending(component: "mock-sdk.Internal.sdk") + let mockSDKPath = try testInputsPath.appending(component: "mock-sdk.Internal.sdk") let mockSDKPathStr: String = mockSDKPath.pathString let collector = try SDKPrebuiltModuleInputsCollector(VirtualPath(path: mockSDKPathStr).absolutePath!, DiagnosticsEngine()) let interfaceMap = try collector.collectSwiftInterfaceMap().inputMap @@ -2152,7 +2154,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } } func testCollectSwiftAdopters() throws { - let mockSDKPath = testInputsPath.appending(component: "mock-sdk.Internal.sdk") + let mockSDKPath = try testInputsPath.appending(component: "mock-sdk.Internal.sdk") let mockSDKPathStr: String = mockSDKPath.pathString let collector = try SDKPrebuiltModuleInputsCollector(VirtualPath(path: mockSDKPathStr).absolutePath!, DiagnosticsEngine()) let adopters = try collector.collectSwiftInterfaceMap().adopters @@ -2172,7 +2174,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } func testCollectSwiftAdoptersWhetherMixed() throws { - let mockSDKPath = testInputsPath.appending(component: "mock-sdk.Internal.sdk") + let mockSDKPath = try testInputsPath.appending(component: "mock-sdk.Internal.sdk") let mockSDKPathStr: String = mockSDKPath.pathString let collector = try SDKPrebuiltModuleInputsCollector(VirtualPath(path: mockSDKPathStr).absolutePath!, DiagnosticsEngine()) let adopters = try collector.collectSwiftInterfaceMap().adopters diff --git a/Tests/SwiftDriverTests/IncrementalCompilationTests.swift b/Tests/SwiftDriverTests/IncrementalCompilationTests.swift index f59a3bd5d..5e168d342 100644 --- a/Tests/SwiftDriverTests/IncrementalCompilationTests.swift +++ b/Tests/SwiftDriverTests/IncrementalCompilationTests.swift @@ -20,8 +20,8 @@ import TestUtilities // MARK: - Instance variables and initialization final class IncrementalCompilationTests: XCTestCase { - var tempDir: AbsolutePath = AbsolutePath("/tmp") - var explicitModuleCacheDir: AbsolutePath = AbsolutePath("/tmp/ModuleCache") + var tempDir: AbsolutePath = try! AbsolutePath(validating: "/tmp") + var explicitModuleCacheDir: AbsolutePath = try! AbsolutePath(validating: "/tmp/ModuleCache") var derivedDataDir: AbsolutePath { tempDir.appending(component: "derivedData") diff --git a/Tests/SwiftDriverTests/IntegrationTests.swift b/Tests/SwiftDriverTests/IntegrationTests.swift index 998ce0119..414d888d5 100644 --- a/Tests/SwiftDriverTests/IntegrationTests.swift +++ b/Tests/SwiftDriverTests/IntegrationTests.swift @@ -14,14 +14,14 @@ import TSCBasic #if os(macOS) -internal func bundleRoot() -> AbsolutePath { +internal func bundleRoot() throws -> AbsolutePath { for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { - return AbsolutePath(bundle.bundlePath).parentDirectory + return try AbsolutePath(validating: bundle.bundlePath).parentDirectory } fatalError() } -private let packageDirectory = AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory +private let packageDirectory = try! AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory // The "default" here means lit.py will be invoked as an executable, while otherwise let's use // python 3 explicitly. @@ -31,7 +31,7 @@ func makeDriverSymlinks( in tempDir: AbsolutePath, with swiftBuildDir: AbsolutePath? = nil ) throws -> (swift: AbsolutePath, swiftc: AbsolutePath) { - let binDir = bundleRoot() + let binDir = try bundleRoot() let driver = binDir.appending(component: "swift-driver") let tempBinDir = tempDir.appending(components: "bin") @@ -95,7 +95,7 @@ final class IntegrationTests: IntegrationTestCase { environment: ProcessEnv.vars.merging(extraEnv) { $1 } ) - XCTAssertTrue(localFileSystem.isExecutableFile(AbsolutePath("debug/swift-driver", relativeTo: buildPath)), result) + XCTAssertTrue(localFileSystem.isExecutableFile(try AbsolutePath(validating: "debug/swift-driver", relativeTo: buildPath)), result) } #endif } @@ -173,8 +173,8 @@ final class IntegrationTests: IntegrationTestCase { // you've cloned this package into a Swift compiler working directory, // that means it'll be the directory with build/, llvm/, swift/, and // swift-driver/ in it. - let litConfigDir = AbsolutePath( - litConfigPathString, + let litConfigDir = try AbsolutePath( + validating: litConfigPathString, relativeTo: swiftRootDir ) diff --git a/Tests/SwiftDriverTests/JobExecutorTests.swift b/Tests/SwiftDriverTests/JobExecutorTests.swift index bc1224b00..0ca3e2f87 100644 --- a/Tests/SwiftDriverTests/JobExecutorTests.swift +++ b/Tests/SwiftDriverTests/JobExecutorTests.swift @@ -63,32 +63,43 @@ class JobCollectingDelegate: JobExecutionDelegate { extension DarwinToolchain { /// macOS SDK path, for testing only. var sdk: Result { - Result { - let result = try executor.checkNonZeroExit( - args: "xcrun", "-sdk", "macosx", "--show-sdk-path", - environment: env - ).spm_chomp() - return AbsolutePath(result) + get throws { + Result { + let result = try executor.checkNonZeroExit( + args: "xcrun", "-sdk", "macosx", "--show-sdk-path", + environment: env + ).spm_chomp() + return try AbsolutePath(validating: result) + } } } /// macOS resource directory, for testing only. var resourcesDirectory: Result { - return Result { - try AbsolutePath("../../lib/swift/macosx", relativeTo: getToolPath(.swiftCompiler)) + get throws { + return Result { + try AbsolutePath(validating: "../../lib/swift/macosx", + relativeTo: getToolPath(.swiftCompiler)) + } } } var clangRT: Result { - resourcesDirectory.map { AbsolutePath("../clang/lib/darwin/libclang_rt.osx.a", relativeTo: $0) } + get throws { + try resourcesDirectory.tryMap { try AbsolutePath(validating: "../clang/lib/darwin/libclang_rt.osx.a", relativeTo: $0) } + } } var compatibility50: Result { - resourcesDirectory.map { $0.appending(component: "libswiftCompatibility50.a") } + get throws { + try resourcesDirectory.map { $0.appending(component: "libswiftCompatibility50.a") } + } } var compatibilityDynamicReplacements: Result { - resourcesDirectory.map { $0.appending(component: "libswiftCompatibilityDynamicReplacements.a") } + get throws { + try resourcesDirectory.map { $0.appending(component: "libswiftCompatibilityDynamicReplacements.a") } + } } } @@ -198,9 +209,9 @@ final class JobExecutorTests: XCTestCase { XCTAssertEqual(delegate.started.count, 3) let fooObject = try resolver.resolve(.path(.temporary(RelativePath("foo.o")))) - XCTAssertTrue(localFileSystem.exists(AbsolutePath(fooObject)), "expected foo.o to be present in the temporary directory") + try XCTAssertTrue(localFileSystem.exists(AbsolutePath(validating: fooObject)), "expected foo.o to be present in the temporary directory") try resolver.removeTemporaryDirectory() - XCTAssertFalse(localFileSystem.exists(AbsolutePath(fooObject)), "expected foo.o to be removed from the temporary directory") + try XCTAssertFalse(localFileSystem.exists(AbsolutePath(validating: fooObject)), "expected foo.o to be removed from the temporary directory") } #endif } @@ -283,10 +294,10 @@ final class JobExecutorTests: XCTestCase { #if os(Windows) throw XCTSkip("processId.getter returning `-1`") #else - let job = Job( + let job = try Job( moduleName: "main", kind: .compile, - tool: ResolvedTool(path: AbsolutePath("/usr/bin/swift"), supportsResponseFiles: false), + tool: ResolvedTool(path: AbsolutePath(validating: "/usr/bin/swift"), supportsResponseFiles: false), commandLine: [.flag("something")], inputs: [], primaryInputs: [], @@ -324,7 +335,7 @@ final class JobExecutorTests: XCTestCase { env[envVarName] = dummyPath let overriddenSwiftPath = try DarwinToolchain(env: env, executor: executor).getToolPath(.swiftCompiler) - XCTAssertEqual(overriddenSwiftPath, AbsolutePath(dummyPath)) + try XCTAssertEqual(overriddenSwiftPath, AbsolutePath(validating: dummyPath)) // GenericUnixToolchain env.removeValue(forKey: envVarName) @@ -334,7 +345,7 @@ final class JobExecutorTests: XCTestCase { env[envVarName] = dummyPath let unixOverriddenSwiftPath = try GenericUnixToolchain(env: env, executor: executor).getToolPath(.swiftCompiler) - XCTAssertEqual(unixOverriddenSwiftPath, AbsolutePath(dummyPath)) + try XCTAssertEqual(unixOverriddenSwiftPath, AbsolutePath(validating: dummyPath)) } func testInputModifiedDuringSingleJobBuild() throws { @@ -366,13 +377,13 @@ final class JobExecutorTests: XCTestCase { processSet: ProcessSet(), fileSystem: localFileSystem, env: [:]) - let job = Job(moduleName: "Module", + let job = try Job(moduleName: "Module", kind: .compile, tool: ResolvedTool( - path: AbsolutePath("/path/to/the tool"), + path: AbsolutePath(validating: "/path/to/the tool"), supportsResponseFiles: false), - commandLine: [.path(.absolute(.init("/with space"))), - .path(.absolute(.init("/withoutspace")))], + commandLine: [.path(.absolute(.init(validating: "/with space"))), + .path(.absolute(.init(validating: "/withoutspace")))], inputs: [], primaryInputs: [], outputs: []) #if os(Windows) XCTAssertEqual(try executor.description(of: job, forceResponseFiles: false), @@ -492,10 +503,12 @@ final class JobExecutorTests: XCTestCase { try driver.run(jobs: jobs) XCTAssertTrue(localFileSystem.exists(outputPath)) // -save-temps wasn't passed, so ensure the temporary file was removed. - XCTAssertFalse( - localFileSystem.exists(.init(try executor.resolver.resolve(.path(driver.allSourcesFileList!)))) + try XCTAssertFalse( + localFileSystem.exists(.init(validating: try executor.resolver.resolve(.path(driver.allSourcesFileList!)))) + ) + try XCTAssertFalse( + localFileSystem.exists(.init(validating: try executor.resolver.resolve(.path(compileOutput)))) ) - XCTAssertFalse(localFileSystem.exists(.init(try executor.resolver.resolve(.path(compileOutput))))) } } @@ -528,10 +541,12 @@ final class JobExecutorTests: XCTestCase { try driver.run(jobs: jobs) XCTAssertTrue(localFileSystem.exists(outputPath)) // -save-temps was passed, so ensure the temporary file was not removed. - XCTAssertTrue( - localFileSystem.exists(.init(try executor.resolver.resolve(.path(driver.allSourcesFileList!)))) + try XCTAssertTrue( + localFileSystem.exists(.init(validating: try executor.resolver.resolve(.path(driver.allSourcesFileList!)))) + ) + try XCTAssertTrue( + localFileSystem.exists(.init(validating: try executor.resolver.resolve(.path(compileOutput)))) ) - XCTAssertTrue(localFileSystem.exists(.init(try executor.resolver.resolve(.path(compileOutput))))) } } @@ -563,8 +578,8 @@ final class JobExecutorTests: XCTestCase { } try? driver.run(jobs: jobs) // A job crashed, so ensure any temporary files written so far are preserved. - XCTAssertTrue( - localFileSystem.exists(.init(try executor.resolver.resolve(.path(driver.allSourcesFileList!)))) + try XCTAssertTrue( + localFileSystem.exists(.init(validating: try executor.resolver.resolve(.path(driver.allSourcesFileList!)))) ) } } diff --git a/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift b/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift index 12eaf13e5..953a75987 100644 --- a/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift +++ b/Tests/SwiftDriverTests/ModuleDependencyGraphTests.swift @@ -1451,7 +1451,7 @@ extension Job { type: .swift) try! self.init(moduleName: "nothing", kind: .compile, - tool: ResolvedTool(path: AbsolutePath("/dummy"), supportsResponseFiles: false), + tool: ResolvedTool(path: AbsolutePath(validating: "/dummy"), supportsResponseFiles: false), commandLine: [], inputs: [input], primaryInputs: [input], diff --git a/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift b/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift index 68f8c8ba9..5bfda10b6 100644 --- a/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift +++ b/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift @@ -218,9 +218,9 @@ final class NonincrementalCompilationTests: XCTestCase { func testReadAndWriteBuildRecord() throws { let version = "Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)" let options = "abbbfbcaf36b93e58efaadd8271ff142" - let file2 = try AbsolutePath(validating: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/file2.swift") - let main = try AbsolutePath(validating: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/main.swift") - let gazorp = try AbsolutePath(validating: "/Volumes/gazorp.swift") + let file2: AbsolutePath = try AbsolutePath(validating: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/file2.swift") + let main: AbsolutePath = try AbsolutePath(validating: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/main.swift") + let gazorp: AbsolutePath = try AbsolutePath(validating: "/Volumes/gazorp.swift") let inputString = """ version: "\(version)" diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index c8a98de60..ac29268d3 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -36,7 +36,7 @@ private func rebase(_ arcs: String..., at base: AbsolutePath) -> String { } private var testInputsPath: AbsolutePath = { - var root: AbsolutePath = AbsolutePath(#file) + var root: AbsolutePath = try! AbsolutePath(validating: #file) while root.basename != "Tests" { root = root.parentDirectory } @@ -50,10 +50,8 @@ final class SwiftDriverTests: XCTestCase { do { self.ld = try withTemporaryDirectory(removeTreeOnDeinit: false) { let ld = $0.appending(component: executableName("ld64.lld")) - try localFileSystem.writeFileContents(ld, bytes: "") - try localFileSystem.chmod(.executable, path: AbsolutePath(ld.nativePathString(escaped: false))) - + try localFileSystem.chmod(.executable, path: AbsolutePath(validating: ld.nativePathString(escaped: false))) return ld } } catch { @@ -201,7 +199,7 @@ final class SwiftDriverTests: XCTestCase { func testJoinedPathOptions() throws { var driver = try Driver(args: ["swiftc", "-c", "-I=/some/dir", "-F=other/relative/dir", "foo.swift"]) let jobs = try driver.planBuild() - XCTAssertTrue(jobs[0].commandLine.contains(.joinedOptionAndPath("-I=", .absolute(.init("/some/dir"))))) + try XCTAssertTrue(jobs[0].commandLine.contains(.joinedOptionAndPath("-I=", .absolute(.init(validating: "/some/dir"))))) XCTAssertTrue(jobs[0].commandLine.contains(.joinedOptionAndPath("-F=", .relative(.init("other/relative/dir"))))) } @@ -213,9 +211,9 @@ final class SwiftDriverTests: XCTestCase { let jobs = try driver.planBuild() XCTAssertEqual(jobs[0].kind, .compile) // The relative ordering of -F and -Fsystem options should be preserved. - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: [.flag("-F"), .path(.absolute(.init("/path/to/frameworks"))), - .flag("-Fsystem"), .path(.absolute(.init("/path/to/systemframeworks"))), - .flag("-F"), .path(.absolute(.init("/path/to/more/frameworks")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: [.flag("-F"), .path(.absolute(.init(validating: "/path/to/frameworks"))), + .flag("-Fsystem"), .path(.absolute(.init(validating: "/path/to/systemframeworks"))), + .flag("-F"), .path(.absolute(.init(validating: "/path/to/more/frameworks")))])) } func testBatchModeDiagnostics() throws { @@ -282,15 +280,15 @@ final class SwiftDriverTests: XCTestCase { let driver1 = try Driver(args: ["swiftc", "a.swift", "/tmp/b.swift"]) XCTAssertEqual(driver1.inputFiles, [ TypedVirtualPath(file: VirtualPath.relative(RelativePath("a.swift")).intern(), type: .swift), - TypedVirtualPath(file: VirtualPath.absolute(AbsolutePath("/tmp/b.swift")).intern(), type: .swift) ]) + TypedVirtualPath(file: VirtualPath.absolute(try AbsolutePath(validating: "/tmp/b.swift")).intern(), type: .swift) ]) let workingDirectory = localFileSystem.currentWorkingDirectory!.appending(components: "wobble") let tempDirectory = localFileSystem.currentWorkingDirectory!.appending(components: "tmp") let driver2 = try Driver(args: ["swiftc", "a.swift", "-working-directory", workingDirectory.pathString, rebase("b.swift", at: tempDirectory)]) XCTAssertEqual(driver2.inputFiles, - [ TypedVirtualPath(file: VirtualPath.absolute(AbsolutePath(rebase("a.swift", at: workingDirectory))).intern(), type: .swift), - TypedVirtualPath(file: VirtualPath.absolute(AbsolutePath(rebase("b.swift", at: tempDirectory))).intern(), type: .swift) ]) + [ TypedVirtualPath(file: VirtualPath.absolute(try AbsolutePath(validating: rebase("a.swift", at: workingDirectory))).intern(), type: .swift), + TypedVirtualPath(file: VirtualPath.absolute(try AbsolutePath(validating: rebase("b.swift", at: tempDirectory))).intern(), type: .swift) ]) let driver3 = try Driver(args: ["swift", "-"]) XCTAssertEqual(driver3.inputFiles, [ TypedVirtualPath(file: .standardInput, type: .swift )]) @@ -796,8 +794,8 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(plannedJobs[0].kind == .emitModule) XCTAssertTrue(plannedJobs[1].kind == .compile) XCTAssertTrue(plannedJobs[2].kind == .link) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.dia")))])) - XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.dia")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.dia")))])) + try XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.dia")))])) } // WMO @@ -810,8 +808,8 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(plannedJobs[0].kind == .compile) XCTAssertTrue(plannedJobs[1].kind == .emitModule) XCTAssertTrue(plannedJobs[2].kind == .link) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.dia")))])) - XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.dia")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.dia")))])) + try XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-serialize-diagnostics-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.dia")))])) } } } @@ -840,8 +838,8 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(plannedJobs[0].kind == .emitModule) XCTAssertTrue(plannedJobs[1].kind == .compile) XCTAssertTrue(plannedJobs[2].kind == .link) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.d")))])) - XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.d")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.d")))])) + try XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.d")))])) } // WMO @@ -854,15 +852,15 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(plannedJobs[0].kind == .compile) XCTAssertTrue(plannedJobs[1].kind == .emitModule) XCTAssertTrue(plannedJobs[2].kind == .link) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.d")))])) - XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.d")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.d")))])) + try XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: ["-emit-dependencies-path", .path(.absolute(.init(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.d")))])) } } } func testOutputFileMapLoading() throws { let objroot: AbsolutePath = - AbsolutePath("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") + try AbsolutePath(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") let contents = ByteString(""" { @@ -894,7 +892,7 @@ final class SwiftDriverTests: XCTestCase { func testFindingObjectPathFromllvmBCPath() throws { let objroot: AbsolutePath = - AbsolutePath("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") + try AbsolutePath(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") let contents = ByteString( """ @@ -925,7 +923,7 @@ final class SwiftDriverTests: XCTestCase { func testOutputFileMapLoadingDocAndSourceinfo() throws { let objroot: AbsolutePath = - AbsolutePath("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") + try AbsolutePath(validating: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") let contents = ByteString( """ @@ -999,10 +997,10 @@ final class SwiftDriverTests: XCTestCase { "-module-name", "test", "/tmp/second.swift", "/tmp/main.swift" ]) var jobs = try driver.planBuild() - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/second.o")))])) - XCTAssertTrue(jobs[1].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/main.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/second.o")))])) - XCTAssertTrue(jobs[1].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/main.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/second.o")))])) + try XCTAssertTrue(jobs[1].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/main.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/second.o")))])) + try XCTAssertTrue(jobs[1].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/main.o")))])) // b) with filelists driver = try Driver(args: [ @@ -1011,14 +1009,14 @@ final class SwiftDriverTests: XCTestCase { "-module-name", "test", "/tmp/second.swift", "/tmp/main.swift" ]) jobs = try driver.planBuild() - XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[0]), - [.absolute(.init("/tmp/build1/second.o"))]) - XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[0]), - [.absolute(.init("/tmp/build2/second.o"))]) - XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[1]), - [.absolute(.init("/tmp/build1/main.o"))]) - XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[1]), - [.absolute(.init("/tmp/build2/main.o"))]) + try XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[0]), + [.absolute(.init(validating: "/tmp/build1/second.o"))]) + try XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[0]), + [.absolute(.init(validating: "/tmp/build2/second.o"))]) + try XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[1]), + [.absolute(.init(validating: "/tmp/build1/main.o"))]) + try XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[1]), + [.absolute(.init(validating: "/tmp/build2/main.o"))]) // 2. Batch mode (two primary files) @@ -1029,10 +1027,10 @@ final class SwiftDriverTests: XCTestCase { "-module-name", "test", "/tmp/second.swift", "/tmp/main.swift" ]) jobs = try driver.planBuild() - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/second.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/main.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/second.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/main.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/second.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/main.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/second.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/main.o")))])) // b) with filelists driver = try Driver(args: [ @@ -1042,10 +1040,10 @@ final class SwiftDriverTests: XCTestCase { "-module-name", "test", "/tmp/second.swift", "/tmp/main.swift" ]) jobs = try driver.planBuild() - XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[0]), - [.absolute(.init("/tmp/build1/second.o")), .absolute(.init("/tmp/build1/main.o"))]) - XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[0]), - [.absolute(.init("/tmp/build2/second.o")), .absolute(.init("/tmp/build2/main.o"))]) + try XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[0]), + [.absolute(.init(validating: "/tmp/build1/second.o")), .absolute(.init(validating: "/tmp/build1/main.o"))]) + try XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[0]), + [.absolute(.init(validating: "/tmp/build2/second.o")), .absolute(.init(validating: "/tmp/build2/main.o"))]) // 3. Multi-threaded WMO // a) without filelists @@ -1055,10 +1053,10 @@ final class SwiftDriverTests: XCTestCase { "-module-name", "test", "/tmp/second.swift", "/tmp/main.swift" ]) jobs = try driver.planBuild() - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/second.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/second.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/main.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/main.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/second.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/second.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/main.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/main.o")))])) // b) with filelists driver = try Driver(args: [ @@ -1068,10 +1066,10 @@ final class SwiftDriverTests: XCTestCase { "-module-name", "test", "/tmp/second.swift", "/tmp/main.swift" ]) jobs = try driver.planBuild() - XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[0]), - [.absolute(.init("/tmp/build1/second.o")), .absolute(.init("/tmp/build1/main.o"))]) - XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[0]), - [.absolute(.init("/tmp/build2/second.o")), .absolute(.init("/tmp/build2/main.o"))]) + try XCTAssertEqual(getFileListElements(for: "-output-filelist", job: jobs[0]), + [.absolute(.init(validating: "/tmp/build1/second.o")), .absolute(.init(validating: "/tmp/build1/main.o"))]) + try XCTAssertEqual(getFileListElements(for: "-index-unit-output-path-filelist", job: jobs[0]), + [.absolute(.init(validating: "/tmp/build2/second.o")), .absolute(.init(validating: "/tmp/build2/main.o"))]) // 4. Index-file (single primary) driver = try Driver(args: [ @@ -1082,8 +1080,8 @@ final class SwiftDriverTests: XCTestCase { "-index-unit-output-path", "/tmp/build2/second.o" ]) jobs = try driver.planBuild() - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init("/tmp/build1/second.o")))])) - XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init("/tmp/build2/second.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-o", .path(.absolute(.init(validating: "/tmp/build1/second.o")))])) + try XCTAssertTrue(jobs[0].commandLine.contains(subsequence: ["-index-unit-output-path", .path(.absolute(.init(validating: "/tmp/build2/second.o")))])) } } } @@ -1194,14 +1192,14 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(plannedJobs[0].kind, .compile) XCTAssertTrue(plannedJobs[0].primaryInputs.map{ $0.file.description }.elementsEqual(["foo.swift", "bar.swift"])) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-emit-const-values-path"), .path(.absolute(.init("/tmp/foo.build/foo.swiftconstvalues")))])) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-emit-const-values-path"), .path(.absolute(.init("/tmp/foo.build/bar.swiftconstvalues")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-emit-const-values-path"), .path(.absolute(.init(validating: "/tmp/foo.build/foo.swiftconstvalues")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-emit-const-values-path"), .path(.absolute(.init(validating: "/tmp/foo.build/bar.swiftconstvalues")))])) XCTAssertEqual(plannedJobs[0].outputs.filter({ $0.type == .swiftConstValues }).count, 2) XCTAssertEqual(plannedJobs[1].kind, .compile) XCTAssertTrue(plannedJobs[1].primaryInputs.map{ $0.file.description }.elementsEqual(["baz.swift"])) XCTAssertTrue(plannedJobs[1].commandLine.contains("-emit-const-values-path")) XCTAssertEqual(plannedJobs[1].outputs.filter({ $0.type == .swiftConstValues }).count, 1) - XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: [.flag("-emit-const-values-path"), .path(.absolute(.init("/tmp/foo.build/baz.swiftconstvalues")))])) + try XCTAssertTrue(plannedJobs[1].commandLine.contains(subsequence: [.flag("-emit-const-values-path"), .path(.absolute(.init(validating: "/tmp/foo.build/baz.swiftconstvalues")))])) XCTAssertEqual(plannedJobs[2].kind, .link) } @@ -1244,8 +1242,8 @@ final class SwiftDriverTests: XCTestCase { let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs() XCTAssertEqual(plannedJobs.count, 2) XCTAssertEqual(plannedJobs[0].kind, .compile) - XCTAssertEqual(plannedJobs[0].outputs.first(where: { $0.type == .swiftConstValues })?.file, - .absolute(.init("/tmp/foo.build/foo.master.swiftconstvalues"))) + try XCTAssertEqual(plannedJobs[0].outputs.first(where: { $0.type == .swiftConstValues })?.file, + .absolute(.init(validating: "/tmp/foo.build/foo.master.swiftconstvalues"))) XCTAssertEqual(plannedJobs[1].kind, .link) } } @@ -1268,7 +1266,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(plannedJobs.count, 3) XCTAssertTrue(plannedJobs[0].kind == .emitModule) - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-serialize-diagnostics-path"), .path(.absolute(.init("/build/Foo-test.dia")))])) + try XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: [.flag("-serialize-diagnostics-path"), .path(.absolute(.init(validating: "/build/Foo-test.dia")))])) } } @@ -1772,7 +1770,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(cmd.contains(.flag("-dynamiclib"))) XCTAssertTrue(cmd.contains(.flag("-w"))) XCTAssertTrue(cmd.contains(.flag("-L"))) - XCTAssertTrue(cmd.contains(.path(.absolute(AbsolutePath("/tmp"))))) + try XCTAssertTrue(cmd.contains(.path(.absolute(AbsolutePath(validating: "/tmp"))))) XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.dylib")) XCTAssertFalse(cmd.contains(.flag("-static"))) @@ -1896,7 +1894,7 @@ final class SwiftDriverTests: XCTestCase { // linker, so be consistent with this XCTAssertFalse(cmd.contains(.flag("-w"))) XCTAssertFalse(cmd.contains(.flag("-L"))) - XCTAssertFalse(cmd.contains(.path(.absolute(AbsolutePath("/tmp"))))) + try XCTAssertFalse(cmd.contains(.path(.absolute(AbsolutePath(validating: "/tmp"))))) XCTAssertFalse(cmd.contains(.flag("-dylib"))) XCTAssertFalse(cmd.contains(.flag("-shared"))) @@ -1926,7 +1924,7 @@ final class SwiftDriverTests: XCTestCase { // linker, so be consistent with this XCTAssertFalse(cmd.contains(.flag("-w"))) XCTAssertFalse(cmd.contains(.flag("-L"))) - XCTAssertFalse(cmd.contains(.path(.absolute(AbsolutePath("/tmp"))))) + try XCTAssertFalse(cmd.contains(.path(.absolute(AbsolutePath(validating: "/tmp"))))) XCTAssertFalse(cmd.contains(.flag("-dylib"))) XCTAssertFalse(cmd.contains(.flag("-shared"))) @@ -2221,7 +2219,7 @@ final class SwiftDriverTests: XCTestCase { let linkJob = plannedJobs[3] let cmd = linkJob.commandLine XCTAssertTrue(cmd.contains(subsequence: ["-target", "wasm32-unknown-wasi"])) - XCTAssertTrue(cmd.contains(subsequence: ["--sysroot", .path(.absolute(.init("/sdk/path")))])) + try XCTAssertTrue(cmd.contains(subsequence: ["--sysroot", .path(.absolute(.init(validating: "/sdk/path")))])) XCTAssertTrue(cmd.contains(.path(.absolute(path.appending(components: "wasi", "wasm32", "swiftrt.o"))))) XCTAssertTrue(commandContainsTemporaryPath(cmd, "foo.o")) XCTAssertTrue(commandContainsTemporaryPath(cmd, "bar.o")) @@ -2315,7 +2313,7 @@ final class SwiftDriverTests: XCTestCase { let result = try process.waitUntilExit() guard result.exitStatus == .terminated(code: EXIT_SUCCESS) else { return nil } guard let path = String(bytes: try result.output.get(), encoding: .utf8) else { return nil } - return path.isEmpty ? nil : AbsolutePath(path.spm_chomp()) + return try path.isEmpty ? nil : AbsolutePath(validating: path.spm_chomp()) #endif } @@ -2834,7 +2832,7 @@ final class SwiftDriverTests: XCTestCase { // Make sure the supplementary output map has an entry for the Swift file // under indexing and its indexData entry is the primary output file let entry = map.entries[VirtualPath.relative(RelativePath("foo5.swift")).intern()]! - XCTAssert(VirtualPath.lookup(entry[.indexData]!) == .absolute(AbsolutePath("/tmp/t.o"))) + XCTAssert(VirtualPath.lookup(entry[.indexData]!) == .absolute(try AbsolutePath(validating: "/tmp/t.o"))) return default: break @@ -2982,9 +2980,8 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(matchTemporary(plannedJobs[0].outputs[1].file, "bar.o")) XCTAssertTrue(matchTemporary(plannedJobs[0].outputs[2].file, "wibble.o")) XCTAssert(!plannedJobs[0].commandLine.contains(.flag("-primary-file"))) - let emitModuleJob = try plannedJobs.findJob(.emitModule) - XCTAssertEqual(emitModuleJob.outputs[3].file, VirtualPath.absolute(AbsolutePath("/tmp/salty/Test.swiftinterface"))) + XCTAssertEqual(emitModuleJob.outputs[3].file, VirtualPath.absolute(try AbsolutePath(validating: "/tmp/salty/Test.swiftinterface"))) XCTAssert(!emitModuleJob.commandLine.contains(.flag("-primary-file"))) XCTAssertEqual(plannedJobs[2].kind, .link) @@ -3012,7 +3009,7 @@ final class SwiftDriverTests: XCTestCase { let moduleJob = try plannedJobs.findJob(.emitModule) XCTAssertTrue(moduleJob.commandLine.contains("-module-alias")) XCTAssertTrue(moduleJob.commandLine.contains("Car=Bar")) - XCTAssertEqual(moduleJob.outputs[0].file, .absolute(AbsolutePath("/tmp/dir/Foo.swiftmodule"))) + XCTAssertEqual(moduleJob.outputs[0].file, .absolute(try AbsolutePath(validating: "/tmp/dir/Foo.swiftmodule"))) XCTAssertEqual(driver.moduleOutputInfo.name, "Foo") XCTAssertNotNil(driver.moduleOutputInfo.aliases) @@ -3157,7 +3154,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(plannedJobs[2].outputs.count, driver.targetTriple.isDarwin ? 4 : 3) XCTAssertEqual(plannedJobs[2].outputs[0].file, .relative(RelativePath("Test.swiftmodule"))) XCTAssertEqual(plannedJobs[2].outputs[1].file, .relative(RelativePath("Test.swiftdoc"))) - XCTAssertEqual(plannedJobs[2].outputs[2].file, .absolute(AbsolutePath("/foo/bar/Test.swiftsourceinfo"))) + XCTAssertEqual(plannedJobs[2].outputs[2].file, .absolute(try AbsolutePath(validating: "/foo/bar/Test.swiftsourceinfo"))) if driver.targetTriple.isDarwin { XCTAssertEqual(plannedJobs[2].outputs[3].file, .relative(RelativePath("Test.abi.json"))) } @@ -3172,11 +3169,11 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(plannedJobs.count, 3) XCTAssertTrue(plannedJobs[2].tool.name.contains("swift")) XCTAssertEqual(plannedJobs[2].outputs.count, driver.targetTriple.isDarwin ? 4 : 3) - XCTAssertEqual(plannedJobs[2].outputs[0].file, .absolute(AbsolutePath(rebase("Test.swiftmodule", at: root)))) - XCTAssertEqual(plannedJobs[2].outputs[1].file, .absolute(AbsolutePath(rebase("Test.swiftdoc", at: root)))) - XCTAssertEqual(plannedJobs[2].outputs[2].file, .absolute(AbsolutePath(rebase("Test.swiftsourceinfo", at: root)))) + try XCTAssertEqual(plannedJobs[2].outputs[0].file, .absolute(AbsolutePath(validating: rebase("Test.swiftmodule", at: root)))) + try XCTAssertEqual(plannedJobs[2].outputs[1].file, .absolute(AbsolutePath(validating: rebase("Test.swiftdoc", at: root)))) + try XCTAssertEqual(plannedJobs[2].outputs[2].file, .absolute(AbsolutePath(validating: rebase("Test.swiftsourceinfo", at: root)))) if driver.targetTriple.isDarwin { - XCTAssertEqual(plannedJobs[2].outputs[3].file, .absolute(AbsolutePath(rebase("Test.abi.json", at: root)))) + try XCTAssertEqual(plannedJobs[2].outputs[3].file, .absolute(AbsolutePath(validating: rebase("Test.abi.json", at: root)))) } } @@ -3220,7 +3217,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(matchTemporary(plannedJobs[0].outputs[0].file, "input.swiftmodule")) XCTAssertEqual(plannedJobs[1].kind, .mergeModule) XCTAssertTrue(matchTemporary(plannedJobs[1].inputs[0].file, "input.swiftmodule")) - XCTAssertEqual(plannedJobs[1].outputs[0].file, .absolute(AbsolutePath("/tmp/test.swiftmodule"))) + XCTAssertEqual(plannedJobs[1].outputs[0].file, .absolute(try AbsolutePath(validating: "/tmp/test.swiftmodule"))) } } @@ -3239,11 +3236,11 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(plannedJobs[0].tool.name.contains("swift")) XCTAssertTrue(plannedJobs[0].commandLine.contains(.flag("-parse-as-library"))) XCTAssertEqual(plannedJobs[0].outputs.count, driver.targetTriple.isDarwin ? 4 : 3) - XCTAssertEqual(plannedJobs[0].outputs[0].file, .absolute(AbsolutePath(rebase("Test.swiftmodule", at: root)))) - XCTAssertEqual(plannedJobs[0].outputs[1].file, .absolute(AbsolutePath(rebase("Test.swiftdoc", at: root)))) - XCTAssertEqual(plannedJobs[0].outputs[2].file, .absolute(AbsolutePath(rebase("Test.swiftsourceinfo", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[0].file, .absolute(try AbsolutePath(validating: rebase("Test.swiftmodule", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[1].file, .absolute(try AbsolutePath(validating: rebase("Test.swiftdoc", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[2].file, .absolute(try AbsolutePath(validating: rebase("Test.swiftsourceinfo", at: root)))) if driver.targetTriple.isDarwin { - XCTAssertEqual(plannedJobs[0].outputs[3].file, .absolute(AbsolutePath(rebase("Test.abi.json", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[3].file, .absolute(try AbsolutePath(validating: rebase("Test.abi.json", at: root)))) } // We don't know the output file of the symbol graph, just make sure the flag is passed along. @@ -3261,11 +3258,11 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.emitModule, .compile])) XCTAssertTrue(plannedJobs[0].tool.name.contains("swift")) XCTAssertEqual(plannedJobs[0].outputs.count, driver.targetTriple.isDarwin ? 4 : 3) - XCTAssertEqual(plannedJobs[0].outputs[0].file, .absolute(AbsolutePath(rebase("Test.swiftmodule", at: root)))) - XCTAssertEqual(plannedJobs[0].outputs[1].file, .absolute(AbsolutePath(rebase("Test.swiftdoc", at: root)))) - XCTAssertEqual(plannedJobs[0].outputs[2].file, .absolute(AbsolutePath(rebase("Test.swiftsourceinfo", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[0].file, .absolute(try AbsolutePath(validating: rebase("Test.swiftmodule", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[1].file, .absolute(try AbsolutePath(validating: rebase("Test.swiftdoc", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[2].file, .absolute(try AbsolutePath(validating: rebase("Test.swiftsourceinfo", at: root)))) if driver.targetTriple.isDarwin { - XCTAssertEqual(plannedJobs[0].outputs[3].file, .absolute(AbsolutePath(rebase("Test.abi.json", at: root)))) + XCTAssertEqual(plannedJobs[0].outputs[3].file, .absolute(try AbsolutePath(validating: rebase("Test.abi.json", at: root)))) } } @@ -3321,11 +3318,11 @@ final class SwiftDriverTests: XCTestCase { let emitModuleJob = try plannedJobs.findJob(.emitModule) XCTAssertTrue(emitModuleJob.tool.name.contains("swift")) XCTAssertEqual(emitModuleJob.outputs.count, 3 + abiFileCount) - XCTAssertEqual(1, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftmodule", at: root)))}).count) - XCTAssertEqual(1, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftdoc", at: root)))}).count) - XCTAssertEqual(1, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftsourceinfo", at: root)))}).count) + XCTAssertEqual(1, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftmodule", at: root)))}).count) + XCTAssertEqual(1, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftdoc", at: root)))}).count) + XCTAssertEqual(1, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftsourceinfo", at: root)))}).count) if abiFileCount == 1 { - XCTAssertEqual(abiFileCount, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.abi.json", at: root)))}).count) + XCTAssertEqual(abiFileCount, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.abi.json", at: root)))}).count) } // We don't know the output file of the symbol graph, just make sure the flag is passed along. @@ -3344,11 +3341,11 @@ final class SwiftDriverTests: XCTestCase { let emitModuleJob = plannedJobs[0] XCTAssertTrue(emitModuleJob.tool.name.contains("swift")) XCTAssertEqual(emitModuleJob.outputs.count, 3 + abiFileCount) - XCTAssertEqual(1, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftmodule", at: root)))}).count) - XCTAssertEqual(1, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftdoc", at: root)))}).count) - XCTAssertEqual(1, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftsourceinfo", at: root)))}).count) + XCTAssertEqual(1, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftmodule", at: root)))}).count) + XCTAssertEqual(1, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftdoc", at: root)))}).count) + XCTAssertEqual(1, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftsourceinfo", at: root)))}).count) if abiFileCount == 1 { - XCTAssertEqual(abiFileCount, emitModuleJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.abi.json", at: root)))}).count) + XCTAssertEqual(abiFileCount, try emitModuleJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.abi.json", at: root)))}).count) } } @@ -3369,11 +3366,11 @@ final class SwiftDriverTests: XCTestCase { let compileJob = try plannedJobs.findJob(.compile) XCTAssertEqual(compileJob.outputs.count, 4 + abiFileCount) XCTAssertEqual(1, compileJob.outputs.filter({$0.type == .object}).count) - XCTAssertEqual(1, compileJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftmodule", at: root)))}).count) - XCTAssertEqual(1, compileJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftdoc", at: root)))}).count) - XCTAssertEqual(1, compileJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.swiftsourceinfo", at: root)))}).count) + XCTAssertEqual(1, try compileJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftmodule", at: root)))}).count) + XCTAssertEqual(1, try compileJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftdoc", at: root)))}).count) + XCTAssertEqual(1, try compileJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.swiftsourceinfo", at: root)))}).count) if abiFileCount == 1 { - XCTAssertEqual(abiFileCount, compileJob.outputs.filter({$0.file == .absolute(AbsolutePath(rebase("Test.abi.json", at: root)))}).count) + XCTAssertEqual(abiFileCount, try compileJob.outputs.filter({$0.file == .absolute(try AbsolutePath(validating: rebase("Test.abi.json", at: root)))}).count) } } @@ -4221,8 +4218,7 @@ final class SwiftDriverTests: XCTestCase { 0x02 ] try localFileSystem.writeFileContents(ld, bytes: contents) - try localFileSystem.chmod(.executable, path: AbsolutePath(ld.pathString)) - + try localFileSystem.chmod(.executable, path: try AbsolutePath(validating: ld.pathString)) // Drop SWIFT_DRIVER_CLANG_EXEC from the environment so it doesn't // interfere with tool lookup. var env = ProcessEnv.vars @@ -4682,8 +4678,8 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(plannedJobs.count, 1) let job = plannedJobs[0] XCTAssertTrue( - job.commandLine.contains(subsequence: ["-emit-loaded-module-trace-path", - .path(.absolute(.init("/some/path/to/the.trace.json")))]) + try job.commandLine.contains(subsequence: ["-emit-loaded-module-trace-path", + .path(.absolute(.init(validating: "/some/path/to/the.trace.json")))]) ) } } @@ -4876,9 +4872,9 @@ final class SwiftDriverTests: XCTestCase { var driver = try Driver(args: ["swiftc", "foo.swift", "-sdk", "/"]) let plannedJobs = try driver.planBuild() - XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-sdk", .path(.absolute(.init("/")))])) + XCTAssertTrue(plannedJobs[0].commandLine.contains(subsequence: ["-sdk", .path(.absolute(try .init(validating: "/")))])) if !driver.targetTriple.isDarwin { - XCTAssertFalse(plannedJobs[2].commandLine.contains(subsequence: ["-L", .path(.absolute(.init("/usr/lib/swift")))])) + XCTAssertFalse(plannedJobs[2].commandLine.contains(subsequence: ["-L", .path(.absolute(try .init(validating: "/usr/lib/swift")))])) } } @@ -5247,7 +5243,7 @@ final class SwiftDriverTests: XCTestCase { try withTemporaryDirectory { path in let input = path.appending(component: "ImmediateTest.swift") try localFileSystem.writeFileContents(input, bytes: "print(\"Hello, World\")") - let binDir = bundleRoot() + let binDir = try bundleRoot() let driver = binDir.appending(component: "swift-driver") let args = [driver.description, "--driver-mode=swift", "-v", input.description] // Immediate mode takes over the process with `exec` so we need to create @@ -6311,7 +6307,7 @@ final class SwiftDriverTests: XCTestCase { // FIXME: On Linux, we might not have any Clang in the path. We need a // better override. var env = ProcessEnv.vars - let swiftHelp: AbsolutePath = AbsolutePath("/usr/bin/nonexistent-swift-help") + let swiftHelp: AbsolutePath = try AbsolutePath(validating: "/usr/bin/nonexistent-swift-help") env["SWIFT_DRIVER_SWIFT_HELP_EXEC"] = swiftHelp.pathString env["SWIFT_DRIVER_CLANG_EXEC"] = "/usr/bin/clang" var driver = try Driver( @@ -6541,7 +6537,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(configs.count, 0) } do { - let configs = Driver.parseAdopterConfigs(AbsolutePath("/abc/c/a.json")) + let configs = Driver.parseAdopterConfigs(try AbsolutePath(validating: "/abc/c/a.json")) XCTAssertEqual(configs.count, 0) } } @@ -7209,7 +7205,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(frontend.commandLine.contains(subsequence: [ .flag("-windows-sdk-root"), - .path(.absolute(.init("/SDK"))) + .path(.absolute(try .init(validating: "/SDK"))) ])) } @@ -7233,7 +7229,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(frontend.commandLine.contains(subsequence: [ .flag("-windows-sdk-root"), - .path(.absolute(.init("/SDK"))) + .path(.absolute(try .init(validating: "/SDK"))) ])) XCTAssertTrue(frontend.commandLine.contains(subsequence: [ .flag("-windows-sdk-version"), @@ -7249,7 +7245,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(frontend.commandLine.contains(subsequence: [ .flag("-visualc-tools-root"), - .path(.absolute(.init("/MSVC/14.34.31933"))), + .path(.absolute(try .init(validating: "/MSVC/14.34.31933"))), ])) } @@ -7277,7 +7273,7 @@ final class SwiftDriverTests: XCTestCase { ])) XCTAssertTrue(frontend.commandLine.contains(subsequence: [ .flag("-visualc-tools-root"), - .path(.absolute(.init("/MSVC"))), + .path(.absolute(try .init(validating: "/MSVC"))), ])) } } diff --git a/Tests/TestUtilities/Fixture.swift b/Tests/TestUtilities/Fixture.swift index 274572799..8cc7c3b90 100644 --- a/Tests/TestUtilities/Fixture.swift +++ b/Tests/TestUtilities/Fixture.swift @@ -30,10 +30,10 @@ public enum Fixture { on fileSystem: FileSystem = localFileSystem ) -> AbsolutePath? { let packageRootPath: AbsolutePath = - AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory + try! AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory let fixturePath = - AbsolutePath(relativePath.pathString, - relativeTo: packageRootPath.appending(component: "TestInputs")) + try! AbsolutePath(validating: relativePath.pathString, + relativeTo: packageRootPath.appending(component: "TestInputs")) .appending(component: file) // Check that the fixture is really there.