-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix some stream operator deprecation warnings #6487
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
35d57c7
Fix some stream operator deprecation warnings
MaxDesiatov f3309f4
Fix stray comment line
MaxDesiatov 7830e2d
Fix stray comment line
MaxDesiatov cc9a3a1
Convert `ManifestWriter.swift` to use `.send`
MaxDesiatov 0a2e2e3
Convert BuildTests and Commands/Utilities to use `.send`
MaxDesiatov 32eb78c
Fix tests related to `DependenciesSerializer.swift`
MaxDesiatov 0652698
Avoid linebreaks in raw string literals
MaxDesiatov 5e431ef
Fix test discovery test error
MaxDesiatov 473335b
Clean up more uses of streams
MaxDesiatov c46654f
Fix test build errors
MaxDesiatov 1ac5ea5
Fix another test failure
MaxDesiatov f91a72e
Convert remaining uses of stream operator to `.send`
MaxDesiatov 7b40d20
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov 82de8e7
Fix remaining test failures
MaxDesiatov 9c4ded5
Fix `PluginInvocationTests`
MaxDesiatov b1a6538
Fix `WorkspaceTests`
MaxDesiatov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,23 +309,23 @@ public final class SwiftTargetBuildDescription { | |
guard needsResourceEmbedding else { return } | ||
|
||
let stream = BufferedOutputByteStream() | ||
stream <<< """ | ||
struct PackageResources { | ||
stream.send( | ||
""" | ||
struct PackageResources { | ||
""" | ||
""" | ||
) | ||
|
||
try resources.forEach { | ||
guard $0.rule == .embedInCode else { return } | ||
|
||
let variableName = $0.path.basename.spm_mangledToC99ExtendedIdentifier() | ||
let fileContent = try Data(contentsOf: URL(fileURLWithPath: $0.path.pathString)).map { String($0) }.joined(separator: ",") | ||
|
||
stream <<< "static let \(variableName): [UInt8] = [\(fileContent)]\n" | ||
stream.send("static let \(variableName): [UInt8] = [\(fileContent)]\n") | ||
} | ||
|
||
stream <<< """ | ||
} | ||
""" | ||
stream.send("}") | ||
|
||
let subpath = try RelativePath(validating: "embedded_resources.swift") | ||
self.derivedSources.relativePaths.append(subpath) | ||
|
@@ -355,24 +355,26 @@ public final class SwiftTargetBuildDescription { | |
} | ||
|
||
let stream = BufferedOutputByteStream() | ||
stream <<< """ | ||
\(self.toolsVersion < .vNext ? "import" : "@_implementationOnly import") class Foundation.Bundle | ||
stream.send( | ||
""" | ||
\(self.toolsVersion < .vNext ? "import" : "@_implementationOnly import") class Foundation.Bundle | ||
extension Foundation.Bundle { | ||
static let module: Bundle = { | ||
let mainPath = \(mainPathSubstitution) | ||
let buildPath = "\(bundlePath.pathString.asSwiftStringLiteralConstant)" | ||
extension Foundation.Bundle { | ||
static let module: Bundle = { | ||
let mainPath = \(mainPathSubstitution) | ||
let buildPath = "\(bundlePath.pathString.asSwiftStringLiteralConstant)" | ||
let preferredBundle = Bundle(path: mainPath) | ||
let preferredBundle = Bundle(path: mainPath) | ||
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else { | ||
fatalError("could not load resource bundle: from \\(mainPath) or \\(buildPath)") | ||
} | ||
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else { | ||
fatalError("could not load resource bundle: from \\(mainPath) or \\(buildPath)") | ||
} | ||
return bundle | ||
}() | ||
} | ||
""" | ||
return bundle | ||
}() | ||
} | ||
""" | ||
) | ||
|
||
let subpath = try RelativePath(validating: "resource_bundle_accessor.swift") | ||
|
||
|
@@ -671,21 +673,41 @@ public final class SwiftTargetBuildDescription { | |
let path = self.tempsPath.appending("output-file-map.json") | ||
let stream = BufferedOutputByteStream() | ||
|
||
stream <<< "{\n" | ||
|
||
let masterDepsPath = self.tempsPath.appending("master.swiftdeps") | ||
stream <<< " \"\": {\n" | ||
stream.send( | ||
#""" | ||
{ | ||
"": { | ||
"""# | ||
) | ||
if self.buildParameters.useWholeModuleOptimization { | ||
let moduleName = self.target.c99name | ||
stream <<< " \"dependencies\": \"" <<< self.tempsPath.appending(component: moduleName + ".d") | ||
.nativePathString(escaped: true) <<< "\",\n" | ||
stream.send( | ||
#""" | ||
"dependencies": "\#( | ||
self.tempsPath.appending(component: moduleName + ".d").nativePathString(escaped: true) | ||
)", | ||
"""# | ||
) | ||
// FIXME: Need to record this deps file for processing it later. | ||
stream <<< " \"object\": \"" <<< self.tempsPath.appending(component: moduleName + ".o") | ||
.nativePathString(escaped: true) <<< "\",\n" | ||
stream.send( | ||
#""" | ||
"object": "\#( | ||
self.tempsPath.appending(component: moduleName + ".o").nativePathString(escaped: true) | ||
)", | ||
"""# | ||
) | ||
} | ||
stream <<< " \"swift-dependencies\": \"" <<< masterDepsPath.nativePathString(escaped: true) <<< "\"\n" | ||
stream.send( | ||
#""" | ||
"swift-dependencies": "\#(masterDepsPath.nativePathString(escaped: true))" | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some lines in the string output here used 2-space indentation inconsistently, preserving just in case |
||
stream <<< " },\n" | ||
"""# | ||
) | ||
|
||
// Write out the entries for each source file. | ||
let sources = self.target.sources.paths + self.derivedSources.paths + self.pluginDerivedSources.paths | ||
|
@@ -697,23 +719,39 @@ public final class SwiftTargetBuildDescription { | |
|
||
let swiftDepsPath = objectDir.appending(component: sourceFileName + ".swiftdeps") | ||
|
||
stream <<< " \"" <<< source.nativePathString(escaped: true) <<< "\": {\n" | ||
stream.send( | ||
#""" | ||
"\#(source.nativePathString(escaped: true))": { | ||
"""# | ||
) | ||
|
||
if !self.buildParameters.useWholeModuleOptimization { | ||
let depsPath = objectDir.appending(component: sourceFileName + ".d") | ||
stream <<< " \"dependencies\": \"" <<< depsPath.nativePathString(escaped: true) <<< "\",\n" | ||
stream.send( | ||
#""" | ||
"dependencies": "\#(depsPath.nativePathString(escaped: true))", | ||
"""# | ||
) | ||
// FIXME: Need to record this deps file for processing it later. | ||
} | ||
|
||
stream <<< " \"object\": \"" <<< object.nativePathString(escaped: true) <<< "\",\n" | ||
|
||
let partialModulePath = objectDir.appending(component: sourceFileName + "~partial.swiftmodule") | ||
stream <<< " \"swiftmodule\": \"" <<< partialModulePath.nativePathString(escaped: true) <<< "\",\n" | ||
stream <<< " \"swift-dependencies\": \"" <<< swiftDepsPath.nativePathString(escaped: true) <<< "\"\n" | ||
stream <<< " }" <<< ((idx + 1) < sources.count ? "," : "") <<< "\n" | ||
|
||
stream.send( | ||
#""" | ||
"object": "\#(object.nativePathString(escaped: true))", | ||
"swiftmodule": "\#(partialModulePath.nativePathString(escaped: true))", | ||
"swift-dependencies": "\#(swiftDepsPath.nativePathString(escaped: true))" | ||
}\#((idx + 1) < sources.count ? "," : "") | ||
|
||
"""# | ||
) | ||
} | ||
|
||
stream <<< "}\n" | ||
stream.send("}\n") | ||
|
||
try self.fileSystem.createDirectory(path.parentDirectory, recursive: true) | ||
try self.fileSystem.writeFileContents(path, bytes: stream.bytes) | ||
|
@@ -724,19 +762,23 @@ public final class SwiftTargetBuildDescription { | |
private func generateModuleMap() throws -> AbsolutePath { | ||
let path = self.tempsPath.appending(component: moduleMapFilename) | ||
|
||
let stream = BufferedOutputByteStream() | ||
stream <<< "module \(self.target.c99name) {\n" | ||
stream <<< " header \"" <<< self.objCompatibilityHeaderPath.pathString <<< "\"\n" | ||
stream <<< " requires objc\n" | ||
stream <<< "}\n" | ||
let bytes = ByteString( | ||
#""" | ||
module \#(self.target.c99name) { | ||
header "\#(self.objCompatibilityHeaderPath.pathString)" | ||
requires objc | ||
} | ||
"""#.utf8 | ||
) | ||
|
||
// Return early if the contents are identical. | ||
if self.fileSystem.isFile(path), try self.fileSystem.readFileContents(path) == stream.bytes { | ||
if self.fileSystem.isFile(path), try self.fileSystem.readFileContents(path) == bytes { | ||
return path | ||
} | ||
|
||
try self.fileSystem.createDirectory(path.parentDirectory, recursive: true) | ||
try self.fileSystem.writeFileContents(path, bytes: stream.bytes) | ||
try self.fileSystem.writeFileContents(path, bytes: bytes) | ||
|
||
return path | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version that was using a stream operator created all parent directories of
path
if those didn't exist, which is inconsistent with the other overloads. This version feels quite redundant towriteFileContents(_ path: AbsolutePath, string: String)
, so I've cleaned it up and adjusted tests to create parent directories when needed.