Skip to content

Replace deprecated uses of <<< with send #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "main",
"revision": "7c8bcf3eab7286855a2eb0cd0df103ea2761e259",
"revision": "ee4cb5e1c2ba6b033a964c77c96bc057be2e2e2a",
"version": null
}
},
Expand Down
60 changes: 30 additions & 30 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1507,17 +1508,17 @@ 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()
}
// In verbose mode, print out the job
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,
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -1721,36 +1721,36 @@ 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
}
}

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<S: OutputByteStream>(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()
}
}
Expand Down Expand Up @@ -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")
}
}

Expand Down
14 changes: 9 additions & 5 deletions Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down
15 changes: 7 additions & 8 deletions Sources/SwiftDriver/Execution/ArgsResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import class Foundation.NSLock

import TSCBasic // <<<
import func TSCBasic.withTemporaryDirectory
import protocol TSCBasic.FileSystem
import struct TSCBasic.AbsolutePath
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
}
}
Expand All @@ -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")
}
}
}
Expand Down Expand Up @@ -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)"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

import TSCBasic // <<<
import protocol TSCBasic.FileSystem
import struct TSCBasic.AbsolutePath
import struct TSCBasic.Diagnostic
Expand Down Expand Up @@ -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()
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

import TSCBasic // <<<
import protocol TSCBasic.WritableByteStream

// MARK: - Asking to write dot files / interface
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -225,11 +224,11 @@ fileprivate struct DOTDependencyGraphSerializer<Graph: ExportableGraph>: 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() {
Expand All @@ -250,12 +249,12 @@ fileprivate struct DOTDependencyGraphSerializer<Graph: ExportableGraph>: 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 {
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import SwiftOptions
import class Foundation.JSONDecoder

import TSCBasic // <<<
import protocol TSCBasic.DiagnosticData
import struct TSCBasic.AbsolutePath
import struct TSCBasic.Diagnostic
Expand Down
Loading