Skip to content

Commit 86f2b73

Browse files
authored
Merge pull request swiftlang#168 from allevato/update-tsc
Remove swift-tools-support-core dependency.
2 parents 6207f97 + b564aa0 commit 86f2b73

File tree

8 files changed

+31
-33
lines changed

8 files changed

+31
-33
lines changed

Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let package = Package(
2222
],
2323
dependencies: [
2424
.package(url: "https://github.com/apple/swift-syntax", from: "0.50200.0"),
25-
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.0.1"),
2625
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.0.4")),
2726
],
2827
targets: [
@@ -62,12 +61,11 @@ let package = Package(
6261
.target(
6362
name: "swift-format",
6463
dependencies: [
64+
"ArgumentParser",
6565
"SwiftFormat",
6666
"SwiftFormatConfiguration",
6767
"SwiftFormatCore",
6868
"SwiftSyntax",
69-
"SwiftToolsSupport-auto",
70-
"ArgumentParser",
7169
]
7270
),
7371
.testTarget(

Sources/swift-format/Subcommands/DumpConfiguration.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import ArgumentParser
1414
import Foundation
1515
import SwiftFormatConfiguration
16-
import TSCBasic
17-
import TSCUtility
1816

1917
extension SwiftFormatCommand {
2018
/// Dumps the tool's default configuration in JSON format to standard output.

Sources/swift-format/Subcommands/Format.swift

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Foundation
1515
import SwiftFormat
1616
import SwiftFormatConfiguration
1717
import SwiftSyntax
18-
import TSCBasic
1918

2019
extension SwiftFormatCommand {
2120
/// Formats one or more files containing Swift code.
@@ -89,31 +88,29 @@ private func formatMain(
8988
// fixed anyway.
9089
let formatter = SwiftFormatter(configuration: configuration, diagnosticEngine: nil)
9190
formatter.debugOptions = debugOptions
92-
let assumingFileURL = URL(fileURLWithPath: assumingFilename ?? "<stdin>")
91+
92+
let path = assumingFilename ?? "<stdin>"
93+
let assumingFileURL = URL(fileURLWithPath: path)
9394

9495
guard let source = readSource(from: sourceFile) else {
9596
diagnosticEngine.diagnose(
96-
Diagnostic.Message(
97-
.error, "Unable to read source for formatting from \(assumingFileURL.path)."))
97+
Diagnostic.Message(.error, "Unable to read source for formatting from \(path)."))
9898
return
9999
}
100100

101+
var stdoutStream = FileHandle.standardOutput
101102
do {
102103
if inPlace {
103-
let cwd = FileManager.default.currentDirectoryPath
104-
var buffer = BufferedOutputByteStream()
104+
var buffer = ""
105105
try formatter.format(source: source, assumingFileURL: assumingFileURL, to: &buffer)
106-
buffer.flush()
107-
try localFileSystem.writeFileContents(
108-
AbsolutePath(assumingFileURL.path, relativeTo: AbsolutePath(cwd)),
109-
bytes: buffer.bytes
110-
)
106+
107+
let bufferData = buffer.data(using: .utf8)! // Conversion to UTF-8 cannot fail
108+
try bufferData.write(to: assumingFileURL, options: .atomic)
111109
} else {
112110
try formatter.format(source: source, assumingFileURL: assumingFileURL, to: &stdoutStream)
113-
stdoutStream.flush()
111+
stdoutStream.synchronizeFile()
114112
}
115113
} catch SwiftFormatError.fileNotReadable {
116-
let path = assumingFileURL.path
117114
diagnosticEngine.diagnose(
118115
Diagnostic.Message(
119116
.error, "Unable to format \(path): file is not readable or does not exist."))
@@ -125,17 +122,15 @@ private func formatMain(
125122
return
126123
}
127124
stdoutStream.write(source)
128-
stdoutStream.flush()
125+
stdoutStream.synchronizeFile()
129126
return
130127
}
131-
let path = assumingFileURL.path
132128
let location = SourceLocationConverter(file: path, source: source).location(for: position)
133129
diagnosticEngine.diagnose(
134130
Diagnostic.Message(.error, "file contains invalid or unrecognized Swift syntax."),
135131
location: location)
136132
return
137133
} catch {
138-
let path = assumingFileURL.path
139134
diagnosticEngine.diagnose(Diagnostic.Message(.error, "Unable to format \(path): \(error)"))
140135
return
141136
}

Sources/swift-format/Subcommands/LegacyMain.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SwiftFormat
1616
import SwiftFormatConfiguration
1717
import SwiftFormatCore
1818
import SwiftSyntax
19-
import TSCBasic
2019

2120
extension SwiftFormatCommand {
2221
/// Keep the legacy `-m/--mode` flag working temporarily when no other subcommand is specified.

Sources/swift-format/Subcommands/Lint.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Foundation
1515
import SwiftFormat
1616
import SwiftFormatConfiguration
1717
import SwiftSyntax
18-
import TSCBasic
1918

2019
extension SwiftFormatCommand {
2120
/// Emits style diagnostics for one or more files containing Swift code.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Foundation
14+
15+
extension FileHandle: TextOutputStream {
16+
public func write(_ string: String) {
17+
self.write(string.data(using: .utf8)!) // Conversion to UTF-8 cannot fail
18+
}
19+
}

Sources/swift-format/Utilities/Helpers.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SwiftFormat
1616
import SwiftFormatConfiguration
1717
import SwiftFormatCore
1818
import SwiftSyntax
19-
import TSCBasic
2019

2120
/// Throws an error that causes the current command to exit the process with a failure exit code if
2221
/// any of the preceding operations emitted diagnostics.

0 commit comments

Comments
 (0)