@@ -309,23 +309,23 @@ public final class SwiftTargetBuildDescription {
309
309
guard needsResourceEmbedding else { return }
310
310
311
311
let stream = BufferedOutputByteStream ( )
312
- stream <<< """
313
- struct PackageResources {
312
+ stream. send (
313
+ """
314
+ struct PackageResources {
314
315
315
- """
316
+ """
317
+ )
316
318
317
319
try resources. forEach {
318
320
guard $0. rule == . embedInCode else { return }
319
321
320
322
let variableName = $0. path. basename. spm_mangledToC99ExtendedIdentifier ( )
321
323
let fileContent = try Data ( contentsOf: URL ( fileURLWithPath: $0. path. pathString) ) . map { String ( $0) } . joined ( separator: " , " )
322
324
323
- stream <<< " static let \( variableName) : [UInt8] = [ \( fileContent) ] \n "
325
+ stream. send ( " static let \( variableName) : [UInt8] = [ \( fileContent) ] \n " )
324
326
}
325
327
326
- stream <<< """
327
- }
328
- """
328
+ stream. send ( " } " )
329
329
330
330
let subpath = try RelativePath ( validating: " embedded_resources.swift " )
331
331
self . derivedSources. relativePaths. append ( subpath)
@@ -355,24 +355,26 @@ public final class SwiftTargetBuildDescription {
355
355
}
356
356
357
357
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
360
361
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) "
365
366
366
- let preferredBundle = Bundle(path: mainPath)
367
+ let preferredBundle = Bundle(path: mainPath)
367
368
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
+ }
371
372
372
- return bundle
373
- }()
374
- }
375
- """
373
+ return bundle
374
+ }()
375
+ }
376
+ """
377
+ )
376
378
377
379
let subpath = try RelativePath ( validating: " resource_bundle_accessor.swift " )
378
380
@@ -671,21 +673,41 @@ public final class SwiftTargetBuildDescription {
671
673
let path = self . tempsPath. appending ( " output-file-map.json " )
672
674
let stream = BufferedOutputByteStream ( )
673
675
674
- stream <<< " { \n "
675
-
676
676
let masterDepsPath = self . tempsPath. appending ( " master.swiftdeps " )
677
- stream <<< " \" \" : { \n "
677
+ stream. send (
678
+ #"""
679
+ {
680
+ "": {
681
+
682
+ """#
683
+ )
678
684
if self . buildParameters. useWholeModuleOptimization {
679
685
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
+ )
682
694
// 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
+ )
685
703
}
686
- stream <<< " \" swift-dependencies \" : \" " <<< masterDepsPath. nativePathString ( escaped: true ) <<< " \" \n "
704
+ stream. send (
705
+ #"""
706
+ "swift-dependencies": " \#( masterDepsPath. nativePathString ( escaped: true ) ) "
707
+ },
687
708
688
- stream <<< " }, \n "
709
+ """#
710
+ )
689
711
690
712
// Write out the entries for each source file.
691
713
let sources = self . target. sources. paths + self . derivedSources. paths + self . pluginDerivedSources. paths
@@ -697,23 +719,39 @@ public final class SwiftTargetBuildDescription {
697
719
698
720
let swiftDepsPath = objectDir. appending ( component: sourceFileName + " .swiftdeps " )
699
721
700
- stream <<< " \" " <<< source. nativePathString ( escaped: true ) <<< " \" : { \n "
722
+ stream. send (
723
+ #"""
724
+ " \#( source. nativePathString ( escaped: true ) ) ": {
725
+
726
+ """#
727
+ )
701
728
702
729
if !self . buildParameters. useWholeModuleOptimization {
703
730
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
+ )
705
737
// FIXME: Need to record this deps file for processing it later.
706
738
}
707
739
708
- stream <<< " \" object \" : \" " <<< object. nativePathString ( escaped: true ) <<< " \" , \n "
709
740
710
741
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
+ )
714
752
}
715
753
716
- stream <<< " } \n "
754
+ stream. send ( " } \n " )
717
755
718
756
try self . fileSystem. createDirectory ( path. parentDirectory, recursive: true )
719
757
try self . fileSystem. writeFileContents ( path, bytes: stream. bytes)
@@ -724,19 +762,23 @@ public final class SwiftTargetBuildDescription {
724
762
private func generateModuleMap( ) throws -> AbsolutePath {
725
763
let path = self . tempsPath. appending ( component: moduleMapFilename)
726
764
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
+ )
732
774
733
775
// 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 {
735
777
return path
736
778
}
737
779
738
780
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)
740
782
741
783
return path
742
784
}
0 commit comments