diff --git a/Package.resolved b/Package.resolved index eac64def5..cce5d7443 100644 --- a/Package.resolved +++ b/Package.resolved @@ -33,7 +33,7 @@ "repositoryURL": "https://github.com/apple/swift-tools-support-core.git", "state": { "branch": "main", - "revision": "7c8bcf3eab7286855a2eb0cd0df103ea2761e259", + "revision": "ee4cb5e1c2ba6b033a964c77c96bc057be2e2e2a", "version": null } }, diff --git a/Sources/SwiftDriver/Driver/Driver.swift b/Sources/SwiftDriver/Driver/Driver.swift index 31e430b57..87e969782 100644 --- a/Sources/SwiftDriver/Driver/Driver.swift +++ b/Sources/SwiftDriver/Driver/Driver.swift @@ -12,14 +12,15 @@ import SwiftOptions import class Dispatch.DispatchQueue - -import TSCBasic // <<< import class TSCBasic.DiagnosticsEngine +import class TSCBasic.UnknownLocation import enum TSCBasic.ProcessEnv +import func TSCBasic.withTemporaryDirectory import protocol TSCBasic.DiagnosticData import protocol TSCBasic.FileSystem import protocol TSCBasic.OutputByteStream import struct TSCBasic.AbsolutePath +import struct TSCBasic.ByteString import struct TSCBasic.Diagnostic import struct TSCBasic.FileInfo import struct TSCBasic.RelativePath @@ -475,23 +476,23 @@ public struct Driver { stdErrQueue.sync { let stream = stderrStream if !(diagnostic.location is UnknownLocation) { - stream <<< diagnostic.location.description <<< ": " + stream.send("\(diagnostic.location.description): ") } switch diagnostic.message.behavior { case .error: - stream <<< "error: " + stream.send("error: ") case .warning: - stream <<< "warning: " + stream.send("warning: ") case .note: - stream <<< "note: " + stream.send("note: ") case .remark: - stream <<< "remark: " + stream.send("remark: ") case .ignored: break } - stream <<< diagnostic.localizedDescription <<< "\n" + stream.send("\(diagnostic.localizedDescription)\n") stream.flush() } } @@ -1430,7 +1431,7 @@ extension Driver { if parsedOptions.contains(.driverPrintOutputFileMap) { if let outputFileMap = self.outputFileMap { - stderrStream <<< outputFileMap.description + stderrStream.send(outputFileMap.description) stderrStream.flush() } else { diagnosticEngine.emit(.error_no_output_file_map_specified) @@ -1507,9 +1508,9 @@ extension Driver { // Print the driver source version first before we print the compiler // versions. if inPlaceJob.kind == .versionRequest && !Driver.driverSourceVersion.isEmpty { - stderrStream <<< "swift-driver version: " <<< Driver.driverSourceVersion <<< " " + stderrStream.send("swift-driver version: \(Driver.driverSourceVersion) ") if let blocklistVersion = try Driver.findCompilerClientsConfigVersion(RelativeTo: try toolchain.executableDir) { - stderrStream <<< blocklistVersion <<< " " + stderrStream.send("\(blocklistVersion) ") } stderrStream.flush() } @@ -1517,7 +1518,7 @@ extension Driver { if parsedOptions.contains(.v) { let arguments: [String] = try executor.resolver.resolveArgumentList(for: inPlaceJob, useResponseFiles: forceResponseFiles ? .forced : .heuristic) - stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n" + stdoutStream.send("\(arguments.map { $0.spm_shellEscaped() }.joined(separator: " "))\n") stdoutStream.flush() } try executor.execute(job: inPlaceJob, @@ -1640,17 +1641,16 @@ extension Driver { } private func printBindings(_ job: Job) { - stdoutStream <<< #"# ""# <<< targetTriple.triple - stdoutStream <<< #"" - ""# <<< job.tool.basename - stdoutStream <<< #"", inputs: ["# - stdoutStream <<< job.displayInputs.map { "\"" + $0.file.name + "\"" }.joined(separator: ", ") + stdoutStream.send(#"# ""#).send(targetTriple.triple) + stdoutStream.send(#"" - ""#).send(job.tool.basename) + stdoutStream.send(#"", inputs: ["#) + stdoutStream.send(job.displayInputs.map { "\"" + $0.file.name + "\"" }.joined(separator: ", ")) - stdoutStream <<< "], output: {" + stdoutStream.send("], output: {") - stdoutStream <<< job.outputs.map { $0.type.name + ": \"" + $0.file.name + "\"" }.joined(separator: ", ") + stdoutStream.send(job.outputs.map { $0.type.name + ": \"" + $0.file.name + "\"" }.joined(separator: ", ")) - stdoutStream <<< "}" - stdoutStream <<< "\n" + stdoutStream.send("}\n") stdoutStream.flush() } @@ -1721,19 +1721,19 @@ extension Driver { } // Print current Job - stdoutStream <<< nextId <<< ": " <<< job.kind.rawValue <<< ", {" + stdoutStream.send("\(nextId): ").send(job.kind.rawValue).send(", {") switch job.kind { // Don't sort for compile jobs. Puts pch last case .compile: - stdoutStream <<< inputIds.map(\.description).joined(separator: ", ") + stdoutStream.send(inputIds.map(\.description).joined(separator: ", ")) default: - stdoutStream <<< inputIds.sorted().map(\.description).joined(separator: ", ") + stdoutStream.send(inputIds.sorted().map(\.description).joined(separator: ", ")) } var typeName = job.outputs.first?.type.name if typeName == nil { typeName = "none" } - stdoutStream <<< "}, " <<< typeName! <<< "\n" + stdoutStream.send("}, \(typeName!)\n") jobIdMap[job] = nextId nextId += 1 } @@ -1741,16 +1741,16 @@ extension Driver { private static func printInputIfNew(_ input: TypedVirtualPath, inputIdMap: inout [TypedVirtualPath: UInt], nextId: inout UInt) { if inputIdMap[input] == nil { - stdoutStream <<< nextId <<< ": " <<< "input, " - stdoutStream <<< "\"" <<< input.file <<< "\", " <<< input.type <<< "\n" + stdoutStream.send("\(nextId): input, ") + stdoutStream.send("\"\(input.file)\", \(input.type)\n") inputIdMap[input] = nextId nextId += 1 } } private func printVersion(outputStream: inout S) throws { - outputStream <<< frontendTargetInfo.compilerVersion <<< "\n" - outputStream <<< "Target: \(frontendTargetInfo.target.triple.triple)\n" + outputStream.send("\(frontendTargetInfo.compilerVersion)\n") + outputStream.send("Target: \(frontendTargetInfo.target.triple.triple)\n") outputStream.flush() } } @@ -2007,9 +2007,9 @@ extension Driver { let filePath = VirtualPath.absolute(absPath.appending(component: "main.swift")) try fileSystem.writeFileContents(filePath) { file in - file <<< ###"#sourceLocation(file: "-e", line: 1)\###n"### + file.send(###"#sourceLocation(file: "-e", line: 1)\###n"###) for option in parsedOptions.arguments(for: .e) { - file <<< option.argument.asSingle <<< "\n" + file.send("\(option.argument.asSingle)\n") } } diff --git a/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift b/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift index f220ea5f2..4d6577d04 100644 --- a/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift +++ b/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift @@ -23,7 +23,6 @@ import Musl #error("Missing libc or equivalent") #endif -import TSCBasic // <<< import class TSCBasic.DiagnosticsEngine import struct TSCBasic.Diagnostic import struct TSCBasic.ProcessResult @@ -79,7 +78,7 @@ import var TSCBasic.stdoutStream case .regular, .silent: break case .verbose: - stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n" + stdoutStream.send("\(arguments.map { $0.spm_shellEscaped() }.joined(separator: " "))\n") stdoutStream.flush() case .parsableOutput: let messages = constructJobBeganMessages(job: job, arguments: arguments, pid: pid) @@ -114,7 +113,7 @@ import var TSCBasic.stdoutStream let output = (try? result.utf8Output() + result.utf8stderrOutput()) ?? "" if !output.isEmpty { Driver.stdErrQueue.sync { - stderrStream <<< output + stderrStream.send(output) stderrStream.flush() } } @@ -169,8 +168,13 @@ import var TSCBasic.stdoutStream // FIXME: Do we need to do error handling here? Can this even fail? guard let json = try? message.toJSON() else { return } Driver.stdErrQueue.sync { - stderrStream <<< json.count <<< "\n" - stderrStream <<< String(data: json, encoding: .utf8)! <<< "\n" + stderrStream.send( + """ + \(json.count) + \(String(data: json, encoding: .utf8)!) + + """ + ) stderrStream.flush() } } diff --git a/Sources/SwiftDriver/Execution/ArgsResolver.swift b/Sources/SwiftDriver/Execution/ArgsResolver.swift index b74167dd0..79f9ff88d 100644 --- a/Sources/SwiftDriver/Execution/ArgsResolver.swift +++ b/Sources/SwiftDriver/Execution/ArgsResolver.swift @@ -12,7 +12,6 @@ import class Foundation.NSLock -import TSCBasic // <<< import func TSCBasic.withTemporaryDirectory import protocol TSCBasic.FileSystem import struct TSCBasic.AbsolutePath @@ -50,7 +49,7 @@ public final class ArgsResolver { // FIXME: withTemporaryDirectory uses FileManager.default, need to create a FileSystem.temporaryDirectory api. let tmpDir: AbsolutePath = try withTemporaryDirectory(removeTreeOnDeinit: false) { path in // FIXME: TSC removes empty directories even when removeTreeOnDeinit is false. This seems like a bug. - try fileSystem.writeFileContents(path.appending(component: ".keep-directory")) { $0 <<< "" } + try fileSystem.writeFileContents(path.appending(component: ".keep-directory")) { $0.send("") } return path } self.temporaryDirectory = .absolute(tmpDir) @@ -152,7 +151,7 @@ public final class ArgsResolver { if let absPath = path.absolutePath { try fileSystem.writeFileContents(absPath) { out in for path in contents { - try! out <<< unsafeResolve(path: path) <<< "\n" + try! out.send("\(unsafeResolve(path: path))\n") } } } @@ -167,13 +166,13 @@ public final class ArgsResolver { // and the frontend (llvm) only seems to support implicit block format. try fileSystem.writeFileContents(absPath) { out in for (input, map) in outputFileMap.entries { - out <<< quoteAndEscape(path: VirtualPath.lookup(input)) <<< ":" + out.send("\(quoteAndEscape(path: VirtualPath.lookup(input))):") if map.isEmpty { - out <<< " {}\n" + out.send(" {}\n") } else { - out <<< "\n" + out.send("\n") for (type, output) in map { - out <<< " " <<< type.name <<< ": " <<< quoteAndEscape(path: VirtualPath.lookup(output)) <<< "\n" + out.send(" \(type.name): \(quoteAndEscape(path: VirtualPath.lookup(output)))\n") } } } @@ -213,7 +212,7 @@ public final class ArgsResolver { // Wrap all arguments in double quotes to ensure that both Unix and // Windows tools understand the response file. try fileSystem.writeFileContents(absPath) { - $0 <<< resolvedArguments[1...].map { quote($0) }.joined(separator: "\n") + $0.send(resolvedArguments[1...].map { quote($0) }.joined(separator: "\n")) } resolvedArguments = [resolvedArguments[0], "@\(absPath.pathString)"] } diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift index a12c1e14f..82008bf91 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift @@ -10,7 +10,6 @@ // //===----------------------------------------------------------------------===// -import TSCBasic // <<< import protocol TSCBasic.FileSystem import struct TSCBasic.AbsolutePath import struct TSCBasic.Diagnostic @@ -49,7 +48,7 @@ extension Diagnostic.Message { var dependencyGraph = try performDependencyScan() if parsedOptions.hasArgument(.printPreprocessedExplicitDependencyGraph) { - try stdoutStream <<< dependencyGraph.toJSONString() + try stdoutStream.send(dependencyGraph.toJSONString()) stdoutStream.flush() } @@ -68,7 +67,7 @@ extension Diagnostic.Message { if parsedOptions.hasArgument(.printExplicitDependencyGraph) { let outputFormat = parsedOptions.getLastArgument(.explicitDependencyGraphFormat)?.asSingle if outputFormat == nil || outputFormat == "json" { - try stdoutStream <<< dependencyGraph.toJSONString() + try stdoutStream.send(dependencyGraph.toJSONString()) } else if outputFormat == "dot" { DOTModuleDependencyGraphSerializer(dependencyGraph).writeDOT(to: &stdoutStream) } @@ -224,7 +223,7 @@ public extension Driver { if parsedOptions.contains(.v) { let arguments: [String] = try executor.resolver.resolveArgumentList(for: scannerJob, useResponseFiles: .disabled) - stdoutStream <<< arguments.map { $0.spm_shellEscaped() }.joined(separator: " ") <<< "\n" + stdoutStream.send("\(arguments.map { $0.spm_shellEscaped() }.joined(separator: " "))\n") stdoutStream.flush() } diff --git a/Sources/SwiftDriver/IncrementalCompilation/DependencyGraphDotFileWriter.swift b/Sources/SwiftDriver/IncrementalCompilation/DependencyGraphDotFileWriter.swift index 52ad83447..c404d90e6 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/DependencyGraphDotFileWriter.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/DependencyGraphDotFileWriter.swift @@ -10,7 +10,6 @@ // //===----------------------------------------------------------------------===// -import TSCBasic // <<< import protocol TSCBasic.WritableByteStream // MARK: - Asking to write dot files / interface @@ -126,7 +125,7 @@ extension ModuleDependencyGraph.Node: ExportableNode { extension ExportableNode { fileprivate func emit(id: Int, to out: inout WritableByteStream, _ t: InternedStringTable) { - out <<< DotFileNode(id: id, node: self, in: t).description <<< "\n" + out.send("\(DotFileNode(id: id, node: self, in: t).description)\n") } fileprivate func label(in t: InternedStringTable) -> String { @@ -225,11 +224,11 @@ fileprivate struct DOTDependencyGraphSerializer: Interne } private func emitPrelude() { - out <<< "digraph " <<< graphID.quoted <<< " {\n" + out.send("digraph \(graphID.quoted) {\n") } private mutating func emitLegend() { for dummy in DependencyKey.Designator.oneOfEachKind { - out <<< DotFileNode(forLegend: dummy).description <<< "\n" + out.send("\(DotFileNode(forLegend: dummy).description)\n") } } private mutating func emitNodes() { @@ -250,12 +249,12 @@ fileprivate struct DOTDependencyGraphSerializer: Interne private func emitArcs() { graph.forEachExportableArc { (def: Graph.Node, use: Graph.Node) in if include(def: def, use: use) { - out <<< DotFileArc(defID: nodeIDs[def]!, useID: nodeIDs[use]!).description <<< "\n" + out.send("\(DotFileArc(defID: nodeIDs[def]!, useID: nodeIDs[use]!).description)\n") } } } private func emitPostlude() { - out <<< "\n}\n" + out.send("\n}\n") } func include(_ n: Graph.Node) -> Bool { diff --git a/Sources/SwiftDriver/Jobs/Planning.swift b/Sources/SwiftDriver/Jobs/Planning.swift index c52d03410..fd5e23e51 100644 --- a/Sources/SwiftDriver/Jobs/Planning.swift +++ b/Sources/SwiftDriver/Jobs/Planning.swift @@ -13,7 +13,6 @@ import SwiftOptions import class Foundation.JSONDecoder -import TSCBasic // <<< import protocol TSCBasic.DiagnosticData import struct TSCBasic.AbsolutePath import struct TSCBasic.Diagnostic diff --git a/Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift b/Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift index df08f08a2..39d35f1a4 100644 --- a/Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift +++ b/Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift @@ -13,7 +13,6 @@ import SwiftOptions import class Foundation.JSONEncoder import class Foundation.JSONSerialization -import TSCBasic // <<< import class TSCBasic.DiagnosticsEngine import protocol TSCBasic.WritableByteStream import struct TSCBasic.AbsolutePath @@ -127,7 +126,7 @@ fileprivate func logOutput(_ job: Job, _ result: ProcessResult, _ logPath: Absol } let fileName = "\(job.moduleName)-\(interfaceBase)-\(stdout ? "out" : errKind.rawValue).txt" try localFileSystem.writeFileContents(logPath.appending(component: fileName)) { - $0 <<< content + $0.send(content) } } @@ -136,8 +135,8 @@ func printJobInfo(_ job: Job, _ start: Bool, _ verbose: Bool) { return } Driver.stdErrQueue.sync { - stderrStream <<< (start ? "started: " : "finished: ") - stderrStream <<< getLastInputPath(job).pathString <<< "\n" + stderrStream.send(start ? "started: " : "finished: ") + stderrStream.send("\(getLastInputPath(job).pathString)\n") stderrStream.flush() } } @@ -185,8 +184,8 @@ fileprivate class ModuleCompileDelegate: JobExecutionDelegate { failingModules.insert(job.moduleName) let result: String = try! result.utf8stderrOutput() Driver.stdErrQueue.sync { - stderrStream <<< "failed: " <<< commandMap[pid]! <<< "\n" - stderrStream <<< result <<< "\n" + stderrStream.send("failed: \(commandMap[pid]!)\n") + stderrStream.send("\(result)\n") stderrStream.flush() } } @@ -203,7 +202,7 @@ fileprivate class ModuleCompileDelegate: JobExecutionDelegate { try logOutput(job, result, logPath, false) } catch { Driver.stdErrQueue.sync { - stderrStream <<< "Failed to generate log file" + stderrStream.send("Failed to generate log file") stderrStream.flush() } } @@ -241,7 +240,7 @@ fileprivate class ABICheckingDelegate: JobExecutionDelegate { try logOutput(job, result, logPath, false) } catch { Driver.stdErrQueue.sync { - stderrStream <<< "Failed to generate log file" + stderrStream.send("Failed to generate log file") stderrStream.flush() } } @@ -529,15 +528,15 @@ extension InterModuleDependencyGraph { func dumpModuleName(_ stream: WritableByteStream, _ dep: ModuleDependencyId) { switch dep { case .swift(let name): - stream <<< "\"\(name).swiftmodule\"" + stream.send("\"\(name).swiftmodule\"") case .clang(let name): - stream <<< "\"\(name).pcm\"" + stream.send("\"\(name).pcm\"") default: break } } - try localFileSystem.writeFileContents(path) {Stream in - Stream <<< "digraph {\n" + try localFileSystem.writeFileContents(path) { Stream in + Stream.send("digraph {\n") for key in modules.keys { switch key { case .swift(let name): @@ -554,15 +553,15 @@ extension InterModuleDependencyGraph { return } dumpModuleName(Stream, key) - Stream <<< " -> " + Stream.send(" -> ") dumpModuleName(Stream, dep) - Stream <<< ";\n" + Stream.send(";\n") } default: break } } - Stream <<< "}\n" + Stream.send("}\n") } } } diff --git a/Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift b/Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift index b842da9f1..662faf574 100644 --- a/Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift +++ b/Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift @@ -72,7 +72,7 @@ public final class WebAssemblyToolchain: Toolchain { case .executable: return moduleName case .dynamicLibrary: - // WASM doesn't support dynamic libraries yet, but we'll report the error later. + // Wasm doesn't support dynamic libraries yet, but we'll report the error later. return "" case .staticLibrary: return "lib\(moduleName).a" diff --git a/Sources/swift-build-sdk-interfaces/main.swift b/Sources/swift-build-sdk-interfaces/main.swift index 3d890b43a..9a71e5642 100644 --- a/Sources/swift-build-sdk-interfaces/main.swift +++ b/Sources/swift-build-sdk-interfaces/main.swift @@ -21,7 +21,6 @@ import Glibc import Musl #endif -import TSCBasic // <<< import class TSCBasic.DiagnosticsEngine import class TSCBasic.ProcessSet import enum TSCBasic.ProcessEnv @@ -134,7 +133,7 @@ do { let tempPath = $0.path try localFileSystem.writeFileContents(tempPath, body: { for module in allModules { - $0 <<< "import " <<< module <<< "\n" + $0.send("import \(module)\n") } }) let executor = try SwiftDriverExecutor(diagnosticsEngine: diagnosticsEngine, @@ -166,7 +165,7 @@ do { currentABIDir: currentABIDir, baselineABIDir: baselineABIDir) if verbose { Driver.stdErrQueue.sync { - stderrStream <<< "job count: \(jobs.count + danglingJobs.count)\n" + stderrStream.send("job count: \(jobs.count + danglingJobs.count)\n") stderrStream.flush() } } diff --git a/Tests/SwiftDriverTests/APIDigesterTests.swift b/Tests/SwiftDriverTests/APIDigesterTests.swift index 0241806da..f3b697ed3 100644 --- a/Tests/SwiftDriverTests/APIDigesterTests.swift +++ b/Tests/SwiftDriverTests/APIDigesterTests.swift @@ -95,13 +95,13 @@ class APIDigesterTests: XCTestCase { try withTemporaryDirectory { path in let ofmPath = path.appending(component: "ofm.json") try localFileSystem.writeFileContents(ofmPath) { - $0 <<< """ + $0.send(""" { "": { "abi-baseline-json": "/path/to/baseline.abi.json" } } - """ + """) } var driver = try Driver(args: ["swiftc", "-wmo", "-emit-module", "-emit-module-interface", "-enable-library-evolution", @@ -119,13 +119,13 @@ class APIDigesterTests: XCTestCase { try withTemporaryDirectory { path in let ofmPath = path.appending(component: "ofm.json") try localFileSystem.writeFileContents(ofmPath) { - $0 <<< """ + $0.send(""" { "": { "swiftsourceinfo": "/path/to/sourceinfo" } } - """ + """) } var driver = try Driver(args: ["swiftc", "-wmo", "-emit-module", "-emit-module-interface", "-enable-library-evolution", @@ -183,13 +183,13 @@ class APIDigesterTests: XCTestCase { try localFileSystem.changeCurrentWorkingDirectory(to: path) let source = path.appending(component: "foo.swift") try localFileSystem.writeFileContents(source) { - $0 <<< """ + $0.send(""" import C import E import G public struct MyStruct {} - """ + """) } let packageRootPath = URL(fileURLWithPath: #file).pathComponents @@ -274,11 +274,11 @@ class APIDigesterTests: XCTestCase { try localFileSystem.changeCurrentWorkingDirectory(to: path) let source = path.appending(component: "foo.swift") try localFileSystem.writeFileContents(source) { - $0 <<< """ + $0.send(""" public struct MyStruct { public var a: Int } - """ + """) } var driver = try Driver(args: ["swiftc", "-working-directory", path.pathString, @@ -295,11 +295,11 @@ class APIDigesterTests: XCTestCase { XCTAssertFalse(driver.diagnosticEngine.hasErrors) try localFileSystem.writeFileContents(source) { - $0 <<< """ + $0.send(""" public struct MyStruct { public var a: Bool } - """ + """) } var driver2 = try Driver(args: ["swiftc", "-working-directory", path.pathString, @@ -335,16 +335,16 @@ class APIDigesterTests: XCTestCase { let source = path.appending(component: "foo.swift") let allowlist = path.appending(component: "allowlist.txt") try localFileSystem.writeFileContents(source) { - $0 <<< """ + $0.send(""" @frozen public struct MyStruct { var a: Int var b: String var c: Int } - """ + """) } try localFileSystem.writeFileContents(allowlist) { - $0 <<< "ABI breakage: var MyStruct.c has declared type change from Swift.Int to Swift.String" + $0.send("ABI breakage: var MyStruct.c has declared type change from Swift.Int to Swift.String") } var driver = try Driver(args: ["swiftc", "-working-directory", path.pathString, @@ -364,13 +364,13 @@ class APIDigesterTests: XCTestCase { XCTAssertFalse(driver.diagnosticEngine.hasErrors) try localFileSystem.writeFileContents(source) { - $0 <<< """ + $0.send(""" @frozen public struct MyStruct { var b: String var a: Int var c: String } - """ + """) } var driver2 = try Driver(args: ["swiftc", "-working-directory", path.pathString, diff --git a/Tests/SwiftDriverTests/CrossModuleIncrementalBuildTests.swift b/Tests/SwiftDriverTests/CrossModuleIncrementalBuildTests.swift index 4f1a2c0a0..750a14035 100644 --- a/Tests/SwiftDriverTests/CrossModuleIncrementalBuildTests.swift +++ b/Tests/SwiftDriverTests/CrossModuleIncrementalBuildTests.swift @@ -49,14 +49,14 @@ class CrossModuleIncrementalBuildTests: XCTestCase { try localFileSystem.changeCurrentWorkingDirectory(to: path) let magic = path.appending(component: "magic.swift") try localFileSystem.writeFileContents(magic) { - $0 <<< "public func castASpell() {}" + $0.send("public func castASpell() {}") } let ofm = path.appending(component: "ofm.json") try localFileSystem.writeFileContents(ofm) { - $0 <<< self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) { + $0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) { $0 + "-some_suffix" - } + }) } let driverArgs = [ @@ -76,9 +76,9 @@ class CrossModuleIncrementalBuildTests: XCTestCase { } try localFileSystem.writeFileContents(ofm) { - $0 <<< self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) { + $0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) { $0 + "-some_other_suffix" - } + }) } do { @@ -98,12 +98,12 @@ class CrossModuleIncrementalBuildTests: XCTestCase { do { let magic = path.appending(component: "magic.swift") try localFileSystem.writeFileContents(magic) { - $0 <<< "public func castASpell() {}" + $0.send("public func castASpell() {}") } let ofm = path.appending(component: "ofm.json") try localFileSystem.writeFileContents(ofm) { - $0 <<< self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) + $0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ])) } var driver = try Driver(args: [ @@ -122,13 +122,13 @@ class CrossModuleIncrementalBuildTests: XCTestCase { let main = path.appending(component: "main.swift") try localFileSystem.writeFileContents(main) { - $0 <<< "import MagicKit\n" - $0 <<< "castASpell()" + $0.send("import MagicKit\n") + $0.send("castASpell()") } let ofm = path.appending(component: "ofm2.json") try localFileSystem.writeFileContents(ofm) { - $0 <<< self.makeOutputFileMap(in: path, module: "theModule", for: [ main ]) + $0.send(self.makeOutputFileMap(in: path, module: "theModule", for: [ main ])) } var driver = try Driver(args: [ diff --git a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift index c5b306221..a62c810f0 100644 --- a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift +++ b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift @@ -238,11 +238,13 @@ final class ExplicitModuleBuildTests: XCTestCase { func testExplicitModuleBuildJobs() throws { try withTemporaryDirectory { path in let main = path.appending(component: "testExplicitModuleBuildJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -488,11 +490,13 @@ final class ExplicitModuleBuildTests: XCTestCase { func testExplicitModuleBuildPCHOutputJobs() throws { try withTemporaryDirectory { path in let main = path.appending(component: "testExplicitModuleBuildPCHOutputJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -618,9 +622,7 @@ final class ExplicitModuleBuildTests: XCTestCase { func testImmediateModeExplicitModuleBuild() throws { try withTemporaryDirectory { path in let main = path.appending(component: "testExplicitModuleBuildJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C\n" - } + try localFileSystem.writeFileContents(main, bytes: "import C\n") let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -729,9 +731,7 @@ final class ExplicitModuleBuildTests: XCTestCase { let srcBar = path.appending(component: "bar.swift") let moduleBarPath = path.appending(component: "Bar.swiftmodule").nativePathString(escaped: true) - try localFileSystem.writeFileContents(srcBar) { - $0 <<< "public class KlassBar {}" - } + try localFileSystem.writeFileContents(srcBar, bytes: "public class KlassBar {}") // Create Bar.swiftmodule var driver = try Driver(args: ["swiftc", @@ -762,10 +762,12 @@ final class ExplicitModuleBuildTests: XCTestCase { // in source files, while its contents are compiled as Bar (real // name on disk). let srcFoo = path.appending(component: "Foo.swift") - try localFileSystem.writeFileContents(srcFoo) { - $0 <<< "import Car\n" - $0 <<< "func run() -> Car.KlassBar? { return nil }" - } + try localFileSystem.writeFileContents(srcFoo, bytes: + """ + import Car + func run() -> Car.KlassBar? { return nil } + """ + ) // Module alias with the fallback scanner (frontend scanner) var driverA = try Driver(args: ["swiftc", @@ -838,9 +840,7 @@ final class ExplicitModuleBuildTests: XCTestCase { // in source files, while its contents are compiled as E (real // name on disk). let srcFoo = path.appending(component: "Foo.swift") - try localFileSystem.writeFileContents(srcFoo) { - $0 <<< "import Car\n" - } + try localFileSystem.writeFileContents(srcFoo, bytes: "import Car\n") // Module alias with the fallback scanner (frontend scanner) var driverA = try Driver(args: ["swiftc", @@ -920,10 +920,12 @@ final class ExplicitModuleBuildTests: XCTestCase { try withTemporaryDirectory { path in let main = path.appending(component: "foo.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import Car;" - $0 <<< "import Jet;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import Car;\ + import Jet; + """ + ) let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] let scannerCommand = ["-scan-dependencies", "-import-prescan", @@ -949,9 +951,7 @@ final class ExplicitModuleBuildTests: XCTestCase { try localFileSystem.createDirectory(moduleCachePath) let srcBar = path.appending(component: "bar.swift") let moduleBarPath = path.appending(component: "Bar.swiftmodule").nativePathString(escaped: true) - try localFileSystem.writeFileContents(srcBar) { - $0 <<< "public class KlassBar {}" - } + try localFileSystem.writeFileContents(srcBar, bytes: "public class KlassBar {}") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] let (stdLibPath, shimsPath, _, _) = try getDriverArtifactsForScanning() @@ -986,10 +986,12 @@ final class ExplicitModuleBuildTests: XCTestCase { // `-module-alias Car=Bar` allows Car (alias) to be referenced // in source files in Foo, but its contents will be compiled // as Bar (real name on-disk). - try localFileSystem.writeFileContents(srcFoo) { - $0 <<< "import Car\n" - $0 <<< "func run() -> Car.KlassBar? { return nil }" - } + try localFileSystem.writeFileContents(srcFoo, bytes: + """ + import Car + func run() -> Car.KlassBar? { return nil } + """ + ) var driver2 = try Driver(args: ["swiftc", "-I", path.nativePathString(escaped: true), "-explicit-module-build", @@ -1096,11 +1098,13 @@ final class ExplicitModuleBuildTests: XCTestCase { let moduleCachePath = path.appending(component: "ModuleCache") try localFileSystem.createDirectory(moduleCachePath) let main = path.appending(component: "testExplicitModuleBuildEndToEnd.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C; + import E; + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -1138,15 +1142,11 @@ final class ExplicitModuleBuildTests: XCTestCase { frameworkModuleDir.appending(component: hostTriple.archName + ".swiftmodule") try localFileSystem.createDirectory(frameworkModuleDir, recursive: true) let fooSourcePath = path.appending(component: "Foo.swift") - try localFileSystem.writeFileContents(fooSourcePath) { - $0 <<< "public func foo() {}" - } + try localFileSystem.writeFileContents(fooSourcePath, bytes: "public func foo() {}") // Setup our main test module let mainSourcePath = path.appending(component: "Foo.swift") - try localFileSystem.writeFileContents(mainSourcePath) { - $0 <<< "import Foo" - } + try localFileSystem.writeFileContents(mainSourcePath, bytes: "import Foo") // 1. Build Foo module let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] @@ -1278,11 +1278,13 @@ final class ExplicitModuleBuildTests: XCTestCase { // Create a simple test case. try withTemporaryDirectory { path in let main = path.appending(component: "testDependencyScanning.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G;" + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") .appending(component: "CHeaders") @@ -1387,9 +1389,7 @@ final class ExplicitModuleBuildTests: XCTestCase { try withTemporaryDirectory { path in let main = path.appending(component: "testDependencyScanning.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import S;" - } + try localFileSystem.writeFileContents(main, bytes: "import S;") let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -1455,11 +1455,13 @@ final class ExplicitModuleBuildTests: XCTestCase { // Create a simple test case. try withTemporaryDirectory { path in let main = path.appending(component: "testDependencyScanning.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -1554,11 +1556,13 @@ final class ExplicitModuleBuildTests: XCTestCase { func testPrintingExplicitDependencyGraph() throws { try withTemporaryDirectory { path in let main = path.appending(component: "testPrintingExplicitDependencyGraph.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds").appending(component: "CHeaders") let swiftModuleInterfacesPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds").appending(component: "Swift") let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] @@ -1651,11 +1655,13 @@ final class ExplicitModuleBuildTests: XCTestCase { // Create a simple test case. try withTemporaryDirectory { path in let main = path.appending(component: "testDependencyScanning.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -1705,11 +1711,13 @@ final class ExplicitModuleBuildTests: XCTestCase { try withTemporaryDirectory { path in let cacheSavePath = path.appending(component: "saved.moddepcache") let main = path.appending(component: "testDependencyScanning.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -1837,18 +1845,19 @@ final class ExplicitModuleBuildTests: XCTestCase { XCTAssertEqual(moduleMap[1].isFramework, false) } - func testTraceDependency() throws { try withTemporaryDirectory { path in try localFileSystem.changeCurrentWorkingDirectory(to: path) let moduleCachePath = path.appending(component: "ModuleCache") try localFileSystem.createDirectory(moduleCachePath) let main = path.appending(component: "testTraceDependency.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import C;" - $0 <<< "import E;" - $0 <<< "import G;" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import C;\ + import E;\ + import G; + """ + ) let cHeadersPath: AbsolutePath = testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -1937,14 +1946,17 @@ final class ExplicitModuleBuildTests: XCTestCase { try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import A\n" - $0 <<< "import E\n" - $0 <<< "import F\n" - $0 <<< "import G\n" - $0 <<< "import H\n" - $0 <<< "import Swift\n" - } + try localFileSystem.writeFileContents(main, bytes: + """ + import A + import E + import F + import G + import H + import Swift + + """ + ) let moduleCachePath = "/tmp/module-cache" var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPath, @@ -1990,9 +2002,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import H\n" - } + try localFileSystem.writeFileContents(main, bytes: "import H\n") var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPath, ]) @@ -2028,9 +2038,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import Swift\n" - } + try localFileSystem.writeFileContents(main, bytes: "import Swift\n") var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPath, ]) @@ -2044,9 +2052,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import F\n" - } + try localFileSystem.writeFileContents(main, bytes: "import F\n") var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPath, ]) @@ -2064,9 +2070,7 @@ final class ExplicitModuleBuildTests: XCTestCase { } try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import H\n" - } + try localFileSystem.writeFileContents(main, bytes: "import H\n") var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPath, ]) @@ -2104,9 +2108,7 @@ final class ExplicitModuleBuildTests: XCTestCase { let interfaceMap = try collector.collectSwiftInterfaceMap().inputMap try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import A\n" - } + try localFileSystem.writeFileContents(main, bytes: "import A\n") let moduleCachePath = "/tmp/module-cache" var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPath, @@ -2132,9 +2134,7 @@ final class ExplicitModuleBuildTests: XCTestCase { let interfaceMap = try collector.collectSwiftInterfaceMap().inputMap try withTemporaryDirectory { path in let main = path.appending(component: "testPrebuiltModuleGenerationJobs.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import A\n" - } + try localFileSystem.writeFileContents(main, bytes: "import A\n") let moduleCachePath = "/tmp/module-cache" var driver = try Driver(args: ["swiftc", main.pathString, "-sdk", mockSDKPathStr, diff --git a/Tests/SwiftDriverTests/IncrementalCompilationTests.swift b/Tests/SwiftDriverTests/IncrementalCompilationTests.swift index 04a94832f..f59a3bd5d 100644 --- a/Tests/SwiftDriverTests/IncrementalCompilationTests.swift +++ b/Tests/SwiftDriverTests/IncrementalCompilationTests.swift @@ -1313,7 +1313,7 @@ extension IncrementalCompilationTests { for (file, contents) in self.inputPathsAndContents { let linkTarget = tempDir.appending(component: "links").appending(component: file.basename) - try! localFileSystem.writeFileContents(linkTarget) { $0 <<< contents } + try! localFileSystem.writeFileContents(linkTarget) { $0.send(contents) } } try doABuild( @@ -1346,7 +1346,7 @@ extension IncrementalCompilationTests { private func touch(_ path: AbsolutePath) { Thread.sleep(forTimeInterval: 1) let existingContents = try! localFileSystem.readFileContents(path) - try! localFileSystem.writeFileContents(path) { $0 <<< existingContents } + try! localFileSystem.writeFileContents(path) { $0.send(existingContents) } } /// Set modification time of a file @@ -1372,11 +1372,11 @@ extension IncrementalCompilationTests { try! localFileSystem.removeFileTree(swiftDepsPath) } - private func replace(contentsOf name: String, with replacement: String ) { + private func replace(contentsOf name: String, with replacement: String) { print("*** replacing \(name) ***", to: &stderrStream); stderrStream.flush() let path = inputPath(basename: name) let previousContents = try! localFileSystem.readFileContents(path).cString - try! localFileSystem.writeFileContents(path) { $0 <<< replacement } + try! localFileSystem.writeFileContents(path) { $0.send(replacement) } let newContents = try! localFileSystem.readFileContents(path).cString XCTAssert(previousContents != newContents, "\(path.pathString) unchanged after write") XCTAssert(replacement == newContents, "\(path.pathString) failed to write") @@ -1384,9 +1384,7 @@ extension IncrementalCompilationTests { private func write(_ contents: String, to basename: String) { print("*** writing \(contents) to \(basename)") - try! localFileSystem.writeFileContents(inputPath(basename: basename)) { - $0 <<< contents - } + try! localFileSystem.writeFileContents(inputPath(basename: basename)) { $0.send(contents) } } private func readPriors() -> ByteString? { diff --git a/Tests/SwiftDriverTests/JobExecutorTests.swift b/Tests/SwiftDriverTests/JobExecutorTests.swift index 5fb422d42..bc1224b00 100644 --- a/Tests/SwiftDriverTests/JobExecutorTests.swift +++ b/Tests/SwiftDriverTests/JobExecutorTests.swift @@ -105,12 +105,8 @@ final class JobExecutorTests: XCTestCase { let foo = path.appending(component: "foo.swift") let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(foo) { - $0 <<< "let foo = 5" - } - try localFileSystem.writeFileContents(main) { - $0 <<< "print(foo)" - } + try localFileSystem.writeFileContents(foo, bytes: "let foo = 5") + try localFileSystem.writeFileContents(main, bytes: "print(foo)") let exec = path.appending(component: "main") @@ -263,9 +259,8 @@ final class JobExecutorTests: XCTestCase { // Create a file with inpuit let inputFile = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(inputFile) { - $0 <<< "print(\"Hello, World\")" - } + try localFileSystem.writeFileContents(inputFile, bytes: "print(\"Hello, World\")") + // We are going to override he executors standard input FileHandle to the above // input file, to simulate it being piped over standard input to this compilation. let testFile: FileHandle = FileHandle(forReadingAtPath: inputFile.description)! @@ -348,18 +343,14 @@ final class JobExecutorTests: XCTestCase { #else try withTemporaryDirectory { path in let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "let foo = 1" - } + try localFileSystem.writeFileContents(main, bytes: "let foo = 1") var driver = try Driver(args: ["swift", main.pathString]) let jobs = try driver.planBuild() XCTAssertTrue(jobs.count == 1 && jobs[0].requiresInPlaceExecution) // Change the file - try localFileSystem.writeFileContents(main) { - $0 <<< "let foo = 1" - } + try localFileSystem.writeFileContents(main, bytes: "let foo = 1") XCTAssertThrowsError(try driver.run(jobs: jobs)) { XCTAssertEqual($0 as? Job.InputError, @@ -395,14 +386,10 @@ final class JobExecutorTests: XCTestCase { func testInputModifiedDuringMultiJobBuild() throws { try withTemporaryDirectory { path in let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "let foo = 1" - } + try localFileSystem.writeFileContents(main, bytes: "let foo = 1") let other = path.appending(component: "other.swift") - try localFileSystem.writeFileContents(other) { - $0 <<< "let bar = 2" - } + try localFileSystem.writeFileContents(other, bytes: "let bar = 2") let output = path.appending(component: "a.out") @@ -416,9 +403,7 @@ final class JobExecutorTests: XCTestCase { XCTAssertTrue(jobs.count > 1) // Change the file - try localFileSystem.writeFileContents(other) { - $0 <<< "let bar = 3" - } + try localFileSystem.writeFileContents(other, bytes: "let bar = 3") verifier.expect(.error("input file '\(other.description)' was modified during the build")) // There's a tool-specific linker error that usually happens here from @@ -481,9 +466,8 @@ final class JobExecutorTests: XCTestCase { do { try withTemporaryDirectory { path in let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "print(\"hello, world!\")" - } + try localFileSystem.writeFileContents(main, bytes: "print(\"hello, world!\")") + let diags = DiagnosticsEngine() let executor = try SwiftDriverExecutor(diagnosticsEngine: diags, processSet: ProcessSet(), @@ -518,9 +502,7 @@ final class JobExecutorTests: XCTestCase { do { try withTemporaryDirectory { path in let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "print(\"hello, world!\")" - } + try localFileSystem.writeFileContents(main, bytes: "print(\"hello, world!\")") let diags = DiagnosticsEngine() let executor = try SwiftDriverExecutor(diagnosticsEngine: diags, processSet: ProcessSet(), @@ -556,9 +538,7 @@ final class JobExecutorTests: XCTestCase { do { try withTemporaryDirectory { path in let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "print(\"hello, world!\")" - } + try localFileSystem.writeFileContents(main, bytes: "print(\"hello, world!\")") let diags = DiagnosticsEngine() let executor = try SwiftDriverExecutor(diagnosticsEngine: diags, processSet: ProcessSet(), diff --git a/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift b/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift index 96ff8ba69..68f8c8ba9 100644 --- a/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift +++ b/Tests/SwiftDriverTests/NonincrementalCompilationTests.swift @@ -276,13 +276,10 @@ final class NonincrementalCompilationTests: XCTestCase { } try withTemporaryDirectory { path in let main = path.appending(component: "main.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "let foo = 1" - } + try localFileSystem.writeFileContents(main, bytes: "let foo = 1") let other = path.appending(component: "other.swift") - try localFileSystem.writeFileContents(other) { - $0 <<< "let bar = 2" - } + try localFileSystem.writeFileContents(other, bytes: "let bar = 2") + try assertDriverDiagnostics(args: [ "swiftc", "-module-name", "theModule", "-working-directory", path.pathString, main.pathString, other.pathString diff --git a/Tests/SwiftDriverTests/ParsableMessageTests.swift b/Tests/SwiftDriverTests/ParsableMessageTests.swift index 704885b23..21eca2bb7 100644 --- a/Tests/SwiftDriverTests/ParsableMessageTests.swift +++ b/Tests/SwiftDriverTests/ParsableMessageTests.swift @@ -407,9 +407,8 @@ final class ParsableMessageTests: XCTestCase { let errorOutput = try withHijackedErrorStream { let main = path.appending(component: "main.swift") let output = path.appending(component: "main.o") - try localFileSystem.writeFileContents(main) { - $0 <<< "nonexistentPrint(\"hello, compilation error!\")" - } + try localFileSystem.writeFileContents(main, bytes: "nonexistentPrint(\"hello, compilation error!\")") + let diags = DiagnosticsEngine() let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", main.pathString, @@ -432,9 +431,8 @@ final class ParsableMessageTests: XCTestCase { let errorOutput = try withHijackedErrorStream { let main = path.appending(component: "main.swift") let output = path.appending(component: "main.o") - try localFileSystem.writeFileContents(main) { - $0 <<< "print(\"hello, world!\")" - } + try localFileSystem.writeFileContents(main, bytes: "print(\"hello, world!\")") + let diags = DiagnosticsEngine() let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? [] var driver = try Driver(args: ["swiftc", main.pathString, diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 553f24a0c..c8a98de60 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -51,7 +51,7 @@ final class SwiftDriverTests: XCTestCase { self.ld = try withTemporaryDirectory(removeTreeOnDeinit: false) { let ld = $0.appending(component: executableName("ld64.lld")) - try localFileSystem.writeFileContents(ld) { $0 <<< "" } + try localFileSystem.writeFileContents(ld, bytes: "") try localFileSystem.chmod(.executable, path: AbsolutePath(ld.nativePathString(escaped: false))) return ld @@ -333,8 +333,8 @@ final class SwiftDriverTests: XCTestCase { let main = path.appending(component: "main.swift") let util = path.appending(component: "util.swift") let utilRelative = util.relative(to: cwd) - try localFileSystem.writeFileContents(main) { $0 <<< "print(hi)" } - try localFileSystem.writeFileContents(util) { $0 <<< "let hi = \"hi\"" } + try localFileSystem.writeFileContents(main, bytes: "print(hi)") + try localFileSystem.writeFileContents(util, bytes: "let hi = \"hi\"") let mainMDate = try localFileSystem.lastModificationTime(for: .absolute(main)) let utilMDate = try localFileSystem.lastModificationTime(for: .absolute(util)) @@ -774,7 +774,7 @@ final class SwiftDriverTests: XCTestCase { func testEmitModuleSeparatelyDiagnosticPath() throws { try withTemporaryFile { fileMapFile in - let outputMapContents = """ + let outputMapContents: ByteString = """ { "": { "diagnostics": "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.dia", @@ -785,7 +785,7 @@ final class SwiftDriverTests: XCTestCase { } } """ - try localFileSystem.writeFileContents(fileMapFile.path) { $0 <<< outputMapContents } + try localFileSystem.writeFileContents(fileMapFile.path, bytes: outputMapContents) // Plain (batch/single-file) compile do { @@ -818,7 +818,7 @@ final class SwiftDriverTests: XCTestCase { func testEmitModuleSeparatelyDependenciesPath() throws { try withTemporaryFile { fileMapFile in - let outputMapContents = """ + let outputMapContents: ByteString = """ { "": { "dependencies": "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.d", @@ -829,7 +829,7 @@ final class SwiftDriverTests: XCTestCase { } } """ - try localFileSystem.writeFileContents(fileMapFile.path) { $0 <<< outputMapContents } + try localFileSystem.writeFileContents(fileMapFile.path, bytes: outputMapContents) // Plain (batch/single-file) compile do { @@ -864,7 +864,7 @@ final class SwiftDriverTests: XCTestCase { let objroot: AbsolutePath = AbsolutePath("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") - let contents = """ + let contents = ByteString(""" { "": { "swift-dependencies": "\(objroot.appending(components: "master.swiftdeps").nativePathString(escaped: true))" @@ -876,11 +876,11 @@ final class SwiftDriverTests: XCTestCase { "swift-dependencies": "\(objroot.appending(components: "foo.swiftdeps").nativePathString(escaped: true))" } } - """ + """.utf8) try withTemporaryFile { file in try assertNoDiagnostics { diags in - try localFileSystem.writeFileContents(file.path) { $0 <<< contents } + try localFileSystem.writeFileContents(file.path, bytes: contents) let outputFileMap = try OutputFileMap.load(fileSystem: localFileSystem, file: .absolute(file.path), diagnosticEngine: diags) let object = try outputFileMap.getOutput(inputFile: VirtualPath.intern(path: "/tmp/foo/Sources/foo/foo.swift"), outputType: .object) @@ -896,23 +896,25 @@ final class SwiftDriverTests: XCTestCase { let objroot: AbsolutePath = AbsolutePath("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") - let contents = """ - { - "": { - "swift-dependencies": "\(objroot.appending(components: "master.swiftdeps").nativePathString(escaped: true))" - }, - "/tmp/foo/Sources/foo/foo.swift": { - "dependencies": "\(objroot.appending(components: "foo.d").nativePathString(escaped: true))", - "object": "\(objroot.appending(components: "foo.swift.o").nativePathString(escaped: true))", - "swiftmodule": "\(objroot.appending(components: "foo~partial.swiftmodule").nativePathString(escaped: true))", - "swift-dependencies": "\(objroot.appending(components: "foo.swiftdeps").nativePathString(escaped: true))", - "llvm-bc": "\(objroot.appending(components: "foo.swift.bc").nativePathString(escaped: true))" + let contents = ByteString( + """ + { + "": { + "swift-dependencies": "\(objroot.appending(components: "master.swiftdeps").nativePathString(escaped: true))" + }, + "/tmp/foo/Sources/foo/foo.swift": { + "dependencies": "\(objroot.appending(components: "foo.d").nativePathString(escaped: true))", + "object": "\(objroot.appending(components: "foo.swift.o").nativePathString(escaped: true))", + "swiftmodule": "\(objroot.appending(components: "foo~partial.swiftmodule").nativePathString(escaped: true))", + "swift-dependencies": "\(objroot.appending(components: "foo.swiftdeps").nativePathString(escaped: true))", + "llvm-bc": "\(objroot.appending(components: "foo.swift.bc").nativePathString(escaped: true))" + } } - } - """ + """.utf8 + ) try withTemporaryFile { file in try assertNoDiagnostics { diags in - try localFileSystem.writeFileContents(file.path) { $0 <<< contents } + try localFileSystem.writeFileContents(file.path, bytes: contents) let outputFileMap = try OutputFileMap.load(fileSystem: localFileSystem, file: .absolute(file.path), diagnosticEngine: diags) let obj = try outputFileMap.getOutput(inputFile: VirtualPath.intern(path: "/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.swift.bc"), outputType: .object) @@ -925,23 +927,25 @@ final class SwiftDriverTests: XCTestCase { let objroot: AbsolutePath = AbsolutePath("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build") - let contents = """ - { - "": { - "swift-dependencies": "\(objroot.appending(components: "master.swiftdeps").nativePathString(escaped: true))" - }, - "/tmp/foo/Sources/foo/foo.swift": { - "dependencies": "\(objroot.appending(components: "foo.d").nativePathString(escaped: true))", - "object": "\(objroot.appending(components: "foo.swift.o").nativePathString(escaped: true))", - "swiftmodule": "\(objroot.appending(components: "foo~partial.swiftmodule").nativePathString(escaped: true))", - "swift-dependencies": "\(objroot.appending(components: "foo.swiftdeps").nativePathString(escaped: true))" + let contents = ByteString( + """ + { + "": { + "swift-dependencies": "\(objroot.appending(components: "master.swiftdeps").nativePathString(escaped: true))" + }, + "/tmp/foo/Sources/foo/foo.swift": { + "dependencies": "\(objroot.appending(components: "foo.d").nativePathString(escaped: true))", + "object": "\(objroot.appending(components: "foo.swift.o").nativePathString(escaped: true))", + "swiftmodule": "\(objroot.appending(components: "foo~partial.swiftmodule").nativePathString(escaped: true))", + "swift-dependencies": "\(objroot.appending(components: "foo.swiftdeps").nativePathString(escaped: true))" + } } - } - """ + """.utf8 + ) try withTemporaryFile { file in try assertNoDiagnostics { diags in - try localFileSystem.writeFileContents(file.path) { $0 <<< contents } + try localFileSystem.writeFileContents(file.path, bytes: contents) let outputFileMap = try OutputFileMap.load(fileSystem: localFileSystem, file: .absolute(file.path), diagnosticEngine: diags) let doc = try outputFileMap.getOutput(inputFile: VirtualPath.intern(path: "/tmp/foo/Sources/foo/foo.swift"), outputType: .swiftDocumentation) @@ -954,18 +958,20 @@ final class SwiftDriverTests: XCTestCase { } func testIndexUnitOutputPath() throws { - let contents = """ - { - "/tmp/main.swift": { - "object": "/tmp/build1/main.o", - "index-unit-output-path": "/tmp/build2/main.o", - }, - "/tmp/second.swift": { - "object": "/tmp/build1/second.o", - "index-unit-output-path": "/tmp/build2/second.o", + let contents = ByteString( + """ + { + "/tmp/main.swift": { + "object": "/tmp/build1/main.o", + "index-unit-output-path": "/tmp/build2/main.o", + }, + "/tmp/second.swift": { + "object": "/tmp/build1/second.o", + "index-unit-output-path": "/tmp/build2/second.o", + } } - } - """ + """.utf8 + ) func getFileListElements(for filelistOpt: String, job: Job) -> [VirtualPath] { let optIndex = job.commandLine.firstIndex(of: .flag(filelistOpt))! @@ -983,7 +989,7 @@ final class SwiftDriverTests: XCTestCase { try withTemporaryFile { file in try assertNoDiagnostics { diags in - try localFileSystem.writeFileContents(file.path) { $0 <<< contents } + try localFileSystem.writeFileContents(file.path, bytes: contents) // 1. Incremental mode (single primary file) // a) without filelists @@ -1162,7 +1168,7 @@ final class SwiftDriverTests: XCTestCase { } try withTemporaryFile { fileMapFile in // Batch with output-file-map - let outputMapContents = """ + let outputMapContents: ByteString = """ { "foo.swift": { "object": "/tmp/foo.build/foo.swift.o", @@ -1178,7 +1184,7 @@ final class SwiftDriverTests: XCTestCase { } } """ - try localFileSystem.writeFileContents(fileMapFile.path) { $0 <<< outputMapContents } + try localFileSystem.writeFileContents(fileMapFile.path, bytes: outputMapContents) var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "baz.swift", "-enable-batch-mode","-driver-batch-size-limit", "2", "-module-name", "Foo", "-emit-const-values", @@ -1211,7 +1217,7 @@ final class SwiftDriverTests: XCTestCase { } try withTemporaryFile { fileMapFile in // WMO with output-file-map - let outputMapContents = """ + let outputMapContents: ByteString = """ { "": { "const-values": "/tmp/foo.build/foo.master.swiftconstvalues" @@ -1230,7 +1236,7 @@ final class SwiftDriverTests: XCTestCase { } } """ - try localFileSystem.writeFileContents(fileMapFile.path) { $0 <<< outputMapContents } + try localFileSystem.writeFileContents(fileMapFile.path, bytes: outputMapContents) var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "baz.swift", "-whole-module-optimization", "-module-name", "Foo", "-emit-const-values", @@ -1247,15 +1253,14 @@ final class SwiftDriverTests: XCTestCase { func testEmitModuleSepratelyEmittingDiagnosticsWithOutputFileMap() throws { try withTemporaryDirectory { path in let outputFileMap = path.appending(component: "outputFileMap.json") - try localFileSystem.writeFileContents(outputFileMap) { - $0 <<< """ + try localFileSystem.writeFileContents(outputFileMap, bytes: """ { "": { "emit-module-diagnostics": "/build/Foo-test.dia" } } """ - } + ) var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Foo", "-emit-module", "-serialize-diagnostics", "-experimental-emit-module-separately", "-output-file-map", outputFileMap.description]) @@ -1368,8 +1373,8 @@ final class SwiftDriverTests: XCTestCase { try withTemporaryDirectory(dir: cwd, removeTreeOnDeinit: true) { path in let outputFileMap = path.appending(component: "outputFileMap.json") - try localFileSystem.writeFileContents(outputFileMap) { - $0 <<< """ + try localFileSystem.writeFileContents(outputFileMap, bytes: + """ { "": { "swift-dependencies": "build/master.swiftdeps" @@ -1384,7 +1389,7 @@ final class SwiftDriverTests: XCTestCase { } } """ - } + ) let outputFileMapRelative = outputFileMap.relative(to: cwd).pathString // FIXME: Needs a better way to check that outputFileMap correctly loaded XCTAssertNoThrow(try Driver(args: [ @@ -1400,16 +1405,18 @@ final class SwiftDriverTests: XCTestCase { let diags = DiagnosticsEngine() let fooPath = path.appending(component: "foo.rsp") let barPath = path.appending(component: "bar.rsp") - try localFileSystem.writeFileContents(fooPath) { #if os(Windows) - $0 <<< "hello\nbye\n\"bye to you\"\n@\(barPath.nativePathString(escaped: true))" + try localFileSystem.writeFileContents(fooPath, bytes: + .init("hello\nbye\n\"bye to you\"\n@\(barPath.nativePathString(escaped: true))".utf8) + ) #else - $0 <<< "hello\nbye\nbye\\ to\\ you\n@\(barPath.nativePathString(escaped: true))" + try localFileSystem.writeFileContents(fooPath, bytes: + .init("hello\nbye\nbye\\ to\\ you\n@\(barPath.nativePathString(escaped: true))".utf8) + ) #endif - } - try localFileSystem.writeFileContents(barPath) { - $0 <<< "from\nbar\n@\(fooPath.nativePathString(escaped: true))" - } + try localFileSystem.writeFileContents(barPath, bytes: + .init("from\nbar\n@\(fooPath.nativePathString(escaped: true))".utf8) + ) let args = try Driver.expandResponseFiles(["swift", "compiler", "-Xlinker", "@loader_path", "@" + fooPath.pathString, "something"], fileSystem: localFileSystem, diagnosticsEngine: diags) XCTAssertEqual(args, ["swift", "compiler", "-Xlinker", "@loader_path", "hello", "bye", "bye to you", "from", "bar", "something"]) XCTAssertEqual(diags.diagnostics.count, 1) @@ -1428,16 +1435,13 @@ final class SwiftDriverTests: XCTestCase { let diags = DiagnosticsEngine() let fooPath = path.appending(component: "foo.rsp") let barPath = path.appending(component: "bar.rsp") - try localFileSystem.writeFileContents(fooPath) { #if os(Windows) - $0 <<< "hello\nbye\n\"bye to you\"\n@bar.rsp" + try localFileSystem.writeFileContents(fooPath, bytes: "hello\nbye\n\"bye to you\"\n@bar.rsp") #else - $0 <<< "hello\nbye\nbye\\ to\\ you\n@bar.rsp" + try localFileSystem.writeFileContents(fooPath, bytes: "hello\nbye\nbye\\ to\\ you\n@bar.rsp") #endif - } - try localFileSystem.writeFileContents(barPath) { - $0 <<< "from\nbar\n@foo.rsp" - } + try localFileSystem.writeFileContents(barPath, bytes: "from\nbar\n@foo.rsp") + let args = try Driver.expandResponseFiles(["swift", "compiler", "-Xlinker", "@loader_path", "@foo.rsp", "something"], fileSystem: localFileSystem, diagnosticsEngine: diags) XCTAssertEqual(args, ["swift", "compiler", "-Xlinker", "@loader_path", "hello", "bye", "bye to you", "from", "bar", "something"]) XCTAssertEqual(diags.diagnostics.count, 1) @@ -1459,16 +1463,13 @@ final class SwiftDriverTests: XCTestCase { let diags = DiagnosticsEngine() let fooPath = path.appending(components: "subdir", "foo.rsp") let barPath = path.appending(components: "subdir", "bar.rsp") - try localFileSystem.writeFileContents(fooPath) { #if os(Windows) - $0 <<< "hello\nbye\n\"bye to you\"\n@subdir/bar.rsp" + try localFileSystem.writeFileContents(fooPath, bytes: "hello\nbye\n\"bye to you\"\n@subdir/bar.rsp") #else - $0 <<< "hello\nbye\nbye\\ to\\ you\n@subdir/bar.rsp" + try localFileSystem.writeFileContents(fooPath, bytes: "hello\nbye\nbye\\ to\\ you\n@subdir/bar.rsp") #endif - } - try localFileSystem.writeFileContents(barPath) { - $0 <<< "from\nbar\n@subdir/foo.rsp" - } + try localFileSystem.writeFileContents(barPath, bytes: "from\nbar\n@subdir/foo.rsp") + let args = try Driver.expandResponseFiles(["swift", "compiler", "-Xlinker", "@loader_path", "@subdir/foo.rsp", "something"], fileSystem: localFileSystem, diagnosticsEngine: diags) XCTAssertEqual(args, ["swift", "compiler", "-Xlinker", "@loader_path", "hello", "bye", "bye to you", "from", "bar", "something"]) XCTAssertEqual(diags.diagnostics.count, 1) @@ -1485,35 +1486,38 @@ final class SwiftDriverTests: XCTestCase { let escapingPath = path.appending(component: "escaping.rsp") #if os(Windows) - try localFileSystem.writeFileContents(fooPath) { - $0 <<< "a\\b c\\\\d e\\\\\"f g\" h\\\"i j\\\\\\\"k \"lmn\" o pqr \"st \\\"u\" \\v" - <<< "\n@\(barPath.nativePathString(escaped: true))" - } - try localFileSystem.writeFileContents(barPath) { - $0 <<< #""" + try localFileSystem.writeFileContents(fooPath, bytes: + """ + a\\b c\\\\d e\\\\\"f g\" h\\\"i j\\\\\\\"k \"lmn\" o pqr \"st \\\"u\" \\v" + @\(barPath.nativePathString(escaped: true)) + """ + ) + try localFileSystem.writeFileContents(barPath, bytes: + #""" -Xswiftc -use-ld=lld -Xcc -IS:\Library\sqlite-3.36.0\usr\include -Xlinker -LS:\Library\sqlite-3.36.0\usr\lib """# - } + ) let args = try Driver.expandResponseFiles(["@\(fooPath.pathString)"], fileSystem: localFileSystem, diagnosticsEngine: diags) XCTAssertEqual(args, ["a\\b", "c\\\\d", "e\\f g", "h\"i", "j\\\"k", "lmn", "o", "pqr", "st \"u", "\\v", "-Xswiftc", "-use-ld=lld", "-Xcc", "-IS:\\Library\\sqlite-3.36.0\\usr\\include", "-Xlinker", "-LS:\\Library\\sqlite-3.36.0\\usr\\lib"]) #else - try localFileSystem.writeFileContents(fooPath) { - $0 <<< #""" - Command1 --kkc - //This is a comment - // this is another comment - but this is \\\\\a command - @\#(barPath.nativePathString(escaped: true)) - @NotAFile - -flag="quoted string with a \"quote\" inside" -another-flag - """# - <<< "\nthis line\thas lots \t of whitespace" - } + try localFileSystem.writeFileContents(fooPath, bytes: + .init((#""" + Command1 --kkc + //This is a comment + // this is another comment + but this is \\\\\a command + @\#(barPath.nativePathString(escaped: true)) + @NotAFile + -flag="quoted string with a \"quote\" inside" -another-flag + """# + + "\nthis line\thas lots \t of whitespace").utf8 + ) + ) - try localFileSystem.writeFileContents(barPath) { - $0 <<< #""" + try localFileSystem.writeFileContents(barPath, bytes: + #""" swift "rocks!" compiler @@ -1524,11 +1528,11 @@ final class SwiftDriverTests: XCTestCase { cd Unquoted\ Dir // Bye! """# - } + ) - try localFileSystem.writeFileContents(escapingPath) { - $0 <<< "swift\n--driver-mode=swiftc\n-v\r\n//comment\n\"the end\"" - } + try localFileSystem.writeFileContents(escapingPath, bytes: + "swift\n--driver-mode=swiftc\n-v\r\n//comment\n\"the end\"" + ) let args = try Driver.expandResponseFiles(["@" + fooPath.pathString], fileSystem: localFileSystem, diagnosticsEngine: diags) XCTAssertEqual(args, ["Command1", "--kkc", "but", "this", "is", #"\\a"#, "command", #"swift"#, "rocks!" ,"compiler", "-Xlinker", "@loader_path", "mkdir", "Quoted Dir", "cd", "Unquoted Dir", "@NotAFile", #"-flag=quoted string with a "quote" inside"#, "-another-flag", "this", "line", "has", "lots", "of", "whitespace"]) let escapingArgs = try Driver.expandResponseFiles(["@" + escapingPath.pathString], fileSystem: localFileSystem, diagnosticsEngine: diags) @@ -2331,7 +2335,8 @@ final class SwiftDriverTests: XCTestCase { pathDynamicReplacementsMac, path5_0iOS, path5_1iOS, pathDynamicReplacementsiOS, pathCompatibilityPacksMac] { - try localFileSystem.writeFileContents(compatibilityLibPath) { $0 <<< "Empty" } + try localFileSystem.createDirectory(compatibilityLibPath.parentDirectory, recursive: true) + try localFileSystem.writeFileContents(compatibilityLibPath, bytes: "Empty") } let commonArgs = ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-resource-dir", path.pathString] @@ -2950,17 +2955,19 @@ final class SwiftDriverTests: XCTestCase { } func testWholeModuleOptimizationOutputFileMap() throws { - let contents = """ - { - "": { - "swiftinterface": "/tmp/salty/Test.swiftinterface" + let contents = ByteString( + """ + { + "": { + "swiftinterface": "/tmp/salty/Test.swiftinterface" + } } - } - """ + """.utf8 + ) try withTemporaryFile { file in try assertNoDiagnostics { diags in - try localFileSystem.writeFileContents(file.path) { $0 <<< contents } + try localFileSystem.writeFileContents(file.path, bytes: contents) var driver1 = try Driver(args: [ "swiftc", "-whole-module-optimization", "foo.swift", "bar.swift", "wibble.swift", "-module-name", "Test", "-num-threads", "4", "-output-file-map", file.path.pathString, "-emit-module-interface" @@ -3789,9 +3796,7 @@ final class SwiftDriverTests: XCTestCase { // Check -clang-target is on by default when explicit module is on. try withTemporaryDirectory { path in let main = path.appending(component: "Foo.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import Swift" - } + try localFileSystem.writeFileContents(main, bytes: "import Swift") var driver = try Driver(args: ["swiftc", "-explicit-module-build", "-target", "arm64-apple-macos10.14", "-sdk", sdkRoot.pathString, @@ -3827,9 +3832,7 @@ final class SwiftDriverTests: XCTestCase { // Check -disable-clang-target works try withTemporaryDirectory { path in let main = path.appending(component: "Foo.swift") - try localFileSystem.writeFileContents(main) { - $0 <<< "import Swift" - } + try localFileSystem.writeFileContents(main, bytes: "import Swift") var driver = try Driver(args: ["swiftc", "-disable-clang-target", "-explicit-module-build", "-target", "arm64-apple-macos10.14", @@ -4206,7 +4209,7 @@ final class SwiftDriverTests: XCTestCase { try withTemporaryDirectory { tmpDir in let ld = tmpDir.appending(component: executableName("clang")) // tiny PE binary from: https://archive.is/w01DO - let contents: [UInt8] = [ + let contents: ByteString = [ 0x4d, 0x5a, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4c, 0x01, 0x01, 0x00, 0x6a, 0x2a, 0x58, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x03, 0x01, 0x0b, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, @@ -4217,7 +4220,7 @@ final class SwiftDriverTests: XCTestCase { 0x68, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 ] - try localFileSystem.writeFileContents(ld) { $0 <<< contents } + try localFileSystem.writeFileContents(ld, bytes: contents) try localFileSystem.chmod(.executable, path: AbsolutePath(ld.pathString)) // Drop SWIFT_DRIVER_CLANG_EXEC from the environment so it doesn't @@ -4243,8 +4246,9 @@ final class SwiftDriverTests: XCTestCase { try withTemporaryDirectory { tmpDir in let sdk1 = tmpDir.appending(component: "MacOSX10.15.sdk") - try localFileSystem.writeFileContents(sdk1.appending(component: "SDKSettings.json")) { - $0 <<< """ + try localFileSystem.createDirectory(sdk1, recursive: true) + try localFileSystem.writeFileContents(sdk1.appending(component: "SDKSettings.json"), bytes: + """ { "Version":"10.15", "CanonicalName": "macosx10.15", @@ -4260,11 +4264,12 @@ final class SwiftDriverTests: XCTestCase { } } """ - } + ) let sdk2 = tmpDir.appending(component: "MacOSX10.15.4.sdk") - try localFileSystem.writeFileContents(sdk2.appending(component: "SDKSettings.json")) { - $0 <<< """ + try localFileSystem.createDirectory(sdk2, recursive: true) + try localFileSystem.writeFileContents(sdk2.appending(component: "SDKSettings.json"), bytes: + """ { "Version":"10.15.4", "CanonicalName": "macosx10.15.4", @@ -4294,7 +4299,7 @@ final class SwiftDriverTests: XCTestCase { } } """ - } + ) do { var driver = try Driver(args: ["swiftc", @@ -5198,20 +5203,20 @@ final class SwiftDriverTests: XCTestCase { let libSwift: AbsolutePath = path.appending(components: "Inputs", "lib.swift") let outputFileMap = path.appending(component: "output_file_map.json") - let fileMap = """ -{ - \"\(dummyInput.nativePathString(escaped: true))\": { - \"object\": \"\(basicOutputFileMapObj.nativePathString(escaped: true))\" - }, - \"\(mainSwift.nativePathString(escaped: true))\": { - \"object\": \"\(mainObj.nativePathString(escaped: true))\" - }, - \"\(libSwift.nativePathString(escaped: true))\": { - \"object\": \"\(libObj.nativePathString(escaped: true))\" - } -} -""" - try localFileSystem.writeFileContents(outputFileMap) { $0 <<< fileMap } + let fileMap = ByteString(""" + { + \"\(dummyInput.nativePathString(escaped: true))\": { + \"object\": \"\(basicOutputFileMapObj.nativePathString(escaped: true))\" + }, + \"\(mainSwift.nativePathString(escaped: true))\": { + \"object\": \"\(mainObj.nativePathString(escaped: true))\" + }, + \"\(libSwift.nativePathString(escaped: true))\": { + \"object\": \"\(libObj.nativePathString(escaped: true))\" + } + } + """.utf8) + try localFileSystem.writeFileContents(outputFileMap, bytes: fileMap) var driver = try Driver(args: ["swiftc", "-driver-print-output-file-map", "-target", "x86_64-apple-macosx10.9", @@ -5241,7 +5246,7 @@ final class SwiftDriverTests: XCTestCase { #if os(macOS) try withTemporaryDirectory { path in let input = path.appending(component: "ImmediateTest.swift") - try localFileSystem.writeFileContents(input) { $0 <<< "print(\"Hello, World\")" } + try localFileSystem.writeFileContents(input, bytes: "print(\"Hello, World\")") let binDir = bundleRoot() let driver = binDir.appending(component: "swift-driver") let args = [driver.description, "--driver-mode=swift", "-v", input.description] @@ -6500,25 +6505,27 @@ final class SwiftDriverTests: XCTestCase { func testIsIosMacInterface() throws { try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { $0 <<< "// swift-module-flags: -target x86_64-apple-ios15.0-macabi" } + try localFileSystem.writeFileContents(file.path, bytes: "// swift-module-flags: -target x86_64-apple-ios15.0-macabi") XCTAssertTrue(try isIosMacInterface(VirtualPath.absolute(file.path))) } try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { $0 <<< "// swift-module-flags: -target arm64e-apple-macos12.0" } + try localFileSystem.writeFileContents(file.path, bytes: "// swift-module-flags: -target arm64e-apple-macos12.0") XCTAssertFalse(try isIosMacInterface(VirtualPath.absolute(file.path))) } } func testAdopterConfigFile() throws { try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { - $0 <<< "[" - $0 <<< " {" - $0 <<< " \"key\": \"SkipFeature1\"," - $0 <<< " \"moduleNames\": [\"foo\", \"bar\"]" - $0 <<< " }" - $0 <<< "]" - } + try localFileSystem.writeFileContents(file.path, bytes: + #""" + [ + { + "key": "SkipFeature1", + "moduleNames": ["foo", "bar"] + } + ] + """# + ) let configs = Driver.parseAdopterConfigs(file.path) XCTAssertEqual(configs.count, 1) XCTAssertEqual(configs[0].key, "SkipFeature1") @@ -6529,9 +6536,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(Driver.getAllConfiguredModules(withKey: "SkipFeature2", configs).isEmpty) } try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { - $0 <<< "][ malformed }{" - } + try localFileSystem.writeFileContents(file.path, bytes: "][ malformed }{") let configs = Driver.parseAdopterConfigs(file.path) XCTAssertEqual(configs.count, 0) } @@ -6543,11 +6548,13 @@ final class SwiftDriverTests: XCTestCase { func testExtractPackageName() throws { try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { - $0 <<< "// swift-module-flags: -target arm64e-apple-macos12.0" <<< "\n" - $0 <<< "// swift-module-flags-ignorable: -library-level api" - $0 <<< "// swift-module-flags-ignorable-private: -package-name myPkg" - } + try localFileSystem.writeFileContents(file.path, bytes: + """ + // swift-module-flags: -target arm64e-apple-macos12.0 + // swift-module-flags-ignorable: -library-level api\ + // swift-module-flags-ignorable-private: -package-name myPkg + """ + ) let flags = try getAllModuleFlags(VirtualPath.absolute(file.path)) let idx = flags.firstIndex(of: "-package-name") XCTAssertNotNil(idx) @@ -6558,22 +6565,24 @@ final class SwiftDriverTests: XCTestCase { func testExtractLibraryLevel() throws { try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { $0 <<< "// swift-module-flags: -library-level api" } + try localFileSystem.writeFileContents(file.path, bytes: "// swift-module-flags: -library-level api") let flags = try getAllModuleFlags(VirtualPath.absolute(file.path)) XCTAssertEqual(try getLibraryLevel(flags), .api) } try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { - $0 <<< "// swift-module-flags: -target arm64e-apple-macos12.0" <<< "\n" - $0 <<< "// swift-module-flags-ignorable: -library-level spi" - } + try localFileSystem.writeFileContents(file.path, bytes: + """ + // swift-module-flags: -target arm64e-apple-macos12.0 + // swift-module-flags-ignorable: -library-level spi + """ + ) let flags = try getAllModuleFlags(VirtualPath.absolute(file.path)) XCTAssertEqual(try getLibraryLevel(flags), .spi) } try withTemporaryFile { file in - try localFileSystem.writeFileContents(file.path) { - $0 <<< "// swift-module-flags: -target arm64e-apple-macos12.0" - } + try localFileSystem.writeFileContents(file.path, bytes: + "// swift-module-flags: -target arm64e-apple-macos12.0" + ) let flags = try getAllModuleFlags(VirtualPath.absolute(file.path)) XCTAssertEqual(try getLibraryLevel(flags), .unspecified) } @@ -6826,10 +6835,12 @@ final class SwiftDriverTests: XCTestCase { derivedData: tmpDir, to: ofm) - try localFileSystem.writeFileContents(main) { - $0 <<< "// no errors here" - $0 <<< "func foo() {}" - } + try localFileSystem.writeFileContents(main, bytes: + """ + // no errors here + func foo() {} + """ + ) /// return true if no error func doBuild() throws -> Bool { let sdkArguments = try XCTUnwrap(try Driver.sdkArgumentsForTesting()) @@ -6854,10 +6865,12 @@ final class SwiftDriverTests: XCTestCase { ] XCTAssert(outputs.allSatisfy(localFileSystem.exists)) - try localFileSystem.writeFileContents(main) { - $0 <<< "#error(\"Yipes!\")" - $0 <<< "func foo() {}" - } + try localFileSystem.writeFileContents(main, bytes: + """ + #error(\"Yipes!\") + func foo() {} + """ + ) XCTAssertFalse(try doBuild()) XCTAssert(outputs.allSatisfy {!localFileSystem.exists($0)}) } diff --git a/Tests/SwiftDriverTests/SwiftDriverToolingInterfaceTests.swift b/Tests/SwiftDriverTests/SwiftDriverToolingInterfaceTests.swift index 98022ea9c..d6a57b667 100644 --- a/Tests/SwiftDriverTests/SwiftDriverToolingInterfaceTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverToolingInterfaceTests.swift @@ -18,8 +18,8 @@ final class SwiftDriverToolingInterfaceTests: XCTestCase { func testCreateCompilerInvocation() throws { try withTemporaryDirectory { path in let inputFile = path.appending(components: "test.swift") - try localFileSystem.writeFileContents(inputFile) { $0 <<< "public func foo()" } - + try localFileSystem.writeFileContents(inputFile) { $0.send("public func foo()") } + // Expected success scenarios: do { let testCommand = inputFile.description