@@ -309,23 +309,23 @@ public final class SwiftTargetBuildDescription {
309309 guard needsResourceEmbedding else { return }
310310
311311 let stream = BufferedOutputByteStream ( )
312- stream <<< """
313- struct PackageResources {
312+ stream. send (
313+ """
314+ struct PackageResources {
314315
315- """
316+ """
317+ )
316318
317319 try resources. forEach {
318320 guard $0. rule == . embedInCode else { return }
319321
320322 let variableName = $0. path. basename. spm_mangledToC99ExtendedIdentifier ( )
321323 let fileContent = try Data ( contentsOf: URL ( fileURLWithPath: $0. path. pathString) ) . map { String ( $0) } . joined ( separator: " , " )
322324
323- stream <<< " static let \( variableName) : [UInt8] = [ \( fileContent) ] \n "
325+ stream. send ( " static let \( variableName) : [UInt8] = [ \( fileContent) ] \n " )
324326 }
325327
326- stream <<< """
327- }
328- """
328+ stream. send ( " } " )
329329
330330 let subpath = try RelativePath ( validating: " embedded_resources.swift " )
331331 self . derivedSources. relativePaths. append ( subpath)
@@ -355,24 +355,26 @@ public final class SwiftTargetBuildDescription {
355355 }
356356
357357 let stream = BufferedOutputByteStream ( )
358- stream <<< """
359- \( self . toolsVersion < . vNext ? " import " : " @_implementationOnly import " ) class Foundation.Bundle
358+ stream. send (
359+ """
360+ \( self . toolsVersion < . vNext ? " import " : " @_implementationOnly import " ) class Foundation.Bundle
360361
361- extension Foundation.Bundle {
362- static let module: Bundle = {
363- let mainPath = \( mainPathSubstitution)
364- let buildPath = " \( bundlePath. pathString. asSwiftStringLiteralConstant) "
362+ extension Foundation.Bundle {
363+ static let module: Bundle = {
364+ let mainPath = \( mainPathSubstitution)
365+ let buildPath = " \( bundlePath. pathString. asSwiftStringLiteralConstant) "
365366
366- let preferredBundle = Bundle(path: mainPath)
367+ let preferredBundle = Bundle(path: mainPath)
367368
368- guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
369- fatalError( " could not load resource bundle: from \\ (mainPath) or \\ (buildPath) " )
370- }
369+ guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
370+ fatalError( " could not load resource bundle: from \\ (mainPath) or \\ (buildPath) " )
371+ }
371372
372- return bundle
373- }()
374- }
375- """
373+ return bundle
374+ }()
375+ }
376+ """
377+ )
376378
377379 let subpath = try RelativePath ( validating: " resource_bundle_accessor.swift " )
378380
@@ -671,21 +673,41 @@ public final class SwiftTargetBuildDescription {
671673 let path = self . tempsPath. appending ( " output-file-map.json " )
672674 let stream = BufferedOutputByteStream ( )
673675
674- stream <<< " { \n "
675-
676676 let masterDepsPath = self . tempsPath. appending ( " master.swiftdeps " )
677- stream <<< " \" \" : { \n "
677+ stream. send (
678+ #"""
679+ {
680+ "": {
681+
682+ """#
683+ )
678684 if self . buildParameters. useWholeModuleOptimization {
679685 let moduleName = self . target. c99name
680- stream <<< " \" dependencies \" : \" " <<< self . tempsPath. appending ( component: moduleName + " .d " )
681- . nativePathString ( escaped: true ) <<< " \" , \n "
686+ stream. send (
687+ #"""
688+ "dependencies": " \#(
689+ self . tempsPath. appending ( component: moduleName + " .d " ) . nativePathString ( escaped: true )
690+ ) ",
691+
692+ """#
693+ )
682694 // FIXME: Need to record this deps file for processing it later.
683- stream <<< " \" object \" : \" " <<< self . tempsPath. appending ( component: moduleName + " .o " )
684- . nativePathString ( escaped: true ) <<< " \" , \n "
695+ stream. send (
696+ #"""
697+ "object": " \#(
698+ self . tempsPath. appending ( component: moduleName + " .o " ) . nativePathString ( escaped: true )
699+ ) ",
700+
701+ """#
702+ )
685703 }
686- stream <<< " \" swift-dependencies \" : \" " <<< masterDepsPath. nativePathString ( escaped: true ) <<< " \" \n "
704+ stream. send (
705+ #"""
706+ "swift-dependencies": " \#( masterDepsPath. nativePathString ( escaped: true ) ) "
707+ },
687708
688- stream <<< " }, \n "
709+ """#
710+ )
689711
690712 // Write out the entries for each source file.
691713 let sources = self . target. sources. paths + self . derivedSources. paths + self . pluginDerivedSources. paths
@@ -697,23 +719,39 @@ public final class SwiftTargetBuildDescription {
697719
698720 let swiftDepsPath = objectDir. appending ( component: sourceFileName + " .swiftdeps " )
699721
700- stream <<< " \" " <<< source. nativePathString ( escaped: true ) <<< " \" : { \n "
722+ stream. send (
723+ #"""
724+ " \#( source. nativePathString ( escaped: true ) ) ": {
725+
726+ """#
727+ )
701728
702729 if !self . buildParameters. useWholeModuleOptimization {
703730 let depsPath = objectDir. appending ( component: sourceFileName + " .d " )
704- stream <<< " \" dependencies \" : \" " <<< depsPath. nativePathString ( escaped: true ) <<< " \" , \n "
731+ stream. send (
732+ #"""
733+ "dependencies": " \#( depsPath. nativePathString ( escaped: true ) ) ",
734+
735+ """#
736+ )
705737 // FIXME: Need to record this deps file for processing it later.
706738 }
707739
708- stream <<< " \" object \" : \" " <<< object. nativePathString ( escaped: true ) <<< " \" , \n "
709740
710741 let partialModulePath = objectDir. appending ( component: sourceFileName + " ~partial.swiftmodule " )
711- stream <<< " \" swiftmodule \" : \" " <<< partialModulePath. nativePathString ( escaped: true ) <<< " \" , \n "
712- stream <<< " \" swift-dependencies \" : \" " <<< swiftDepsPath. nativePathString ( escaped: true ) <<< " \" \n "
713- stream <<< " } " <<< ( ( idx + 1 ) < sources. count ? " , " : " " ) <<< " \n "
742+
743+ stream. send (
744+ #"""
745+ "object": " \#( object. nativePathString ( escaped: true ) ) ",
746+ "swiftmodule": " \#( partialModulePath. nativePathString ( escaped: true ) ) ",
747+ "swift-dependencies": " \#( swiftDepsPath. nativePathString ( escaped: true ) ) "
748+ } \#( ( idx + 1 ) < sources. count ? " , " : " " )
749+
750+ """#
751+ )
714752 }
715753
716- stream <<< " } \n "
754+ stream. send ( " } \n " )
717755
718756 try self . fileSystem. createDirectory ( path. parentDirectory, recursive: true )
719757 try self . fileSystem. writeFileContents ( path, bytes: stream. bytes)
@@ -724,19 +762,23 @@ public final class SwiftTargetBuildDescription {
724762 private func generateModuleMap( ) throws -> AbsolutePath {
725763 let path = self . tempsPath. appending ( component: moduleMapFilename)
726764
727- let stream = BufferedOutputByteStream ( )
728- stream <<< " module \( self . target. c99name) { \n "
729- stream <<< " header \" " <<< self . objCompatibilityHeaderPath. pathString <<< " \" \n "
730- stream <<< " requires objc \n "
731- stream <<< " } \n "
765+ let bytes = ByteString (
766+ #"""
767+ module \#( self . target. c99name) {
768+ header " \#( self . objCompatibilityHeaderPath. pathString) "
769+ requires objc
770+ }
771+
772+ """# . utf8
773+ )
732774
733775 // Return early if the contents are identical.
734- if self . fileSystem. isFile ( path) , try self . fileSystem. readFileContents ( path) == stream . bytes {
776+ if self . fileSystem. isFile ( path) , try self . fileSystem. readFileContents ( path) == bytes {
735777 return path
736778 }
737779
738780 try self . fileSystem. createDirectory ( path. parentDirectory, recursive: true )
739- try self . fileSystem. writeFileContents ( path, bytes: stream . bytes)
781+ try self . fileSystem. writeFileContents ( path, bytes: bytes)
740782
741783 return path
742784 }
0 commit comments