@@ -47,6 +47,9 @@ public enum VirtualPath: Hashable {
4747 /// Standard output
4848 case standardOutput
4949
50+ /// ACTODO: Comment
51+ case buildArtifactWithKnownContents( AbsolutePath , Data )
52+
5053 /// We would like to direct clients to use the temporary file creation utilities `createUniqueTemporaryFile`, etc.
5154 /// To ensure temporary files are unique.
5255 /// TODO: If/When Swift gains enum access control, we can prohibit direct instantiation of temporary file cases,
@@ -72,6 +75,8 @@ public enum VirtualPath: Hashable {
7275 case . relative( let path) , . temporary( let path) ,
7376 . temporaryWithKnownContents( let path, _) , . fileList( let path, _) :
7477 return path. extension
78+ case . buildArtifactWithKnownContents( let path, _) :
79+ return path. extension
7580 case . absolute( let path) :
7681 return path. extension
7782 case . standardInput, . standardOutput:
@@ -82,7 +87,7 @@ public enum VirtualPath: Hashable {
8287 /// Whether this virtual path is to a temporary.
8388 public var isTemporary : Bool {
8489 switch self {
85- case . relative, . absolute, . standardInput, . standardOutput:
90+ case . relative, . absolute, . standardInput, . standardOutput, . buildArtifactWithKnownContents :
8691 return false
8792 case . temporary, . temporaryWithKnownContents, . fileList:
8893 return true
@@ -91,7 +96,7 @@ public enum VirtualPath: Hashable {
9196
9297 public var absolutePath : AbsolutePath ? {
9398 switch self {
94- case let . absolute ( absolutePath) :
99+ case . absolute ( let absolutePath ) , . buildArtifactWithKnownContents ( let absolutePath, _ ) :
95100 return absolutePath
96101 case . relative, . temporary, . temporaryWithKnownContents, . fileList, . standardInput, . standardOutput:
97102 return nil
@@ -111,15 +116,15 @@ public enum VirtualPath: Hashable {
111116 . fileList( let name, _) ,
112117 . temporaryWithKnownContents( let name, _) :
113118 return name
114- case . absolute, . relative, . standardInput, . standardOutput:
119+ case . absolute, . relative, . standardInput, . standardOutput, . buildArtifactWithKnownContents :
115120 return nil
116121 }
117122 }
118123
119124 /// Retrieve the basename of the path.
120125 public var basename : String {
121126 switch self {
122- case . absolute( let path) :
127+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
123128 return path. basename
124129 case . relative( let path) , . temporary( let path) , . temporaryWithKnownContents( let path, _) , . fileList( let path, _) :
125130 return path. basename
@@ -131,7 +136,7 @@ public enum VirtualPath: Hashable {
131136 /// Retrieve the basename of the path without the extension.
132137 public var basenameWithoutExt : String {
133138 switch self {
134- case . absolute( let path) :
139+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
135140 return path. basenameWithoutExt
136141 case . relative( let path) , . temporary( let path) , . temporaryWithKnownContents( let path, _) , . fileList( let path, _) :
137142 return path. basenameWithoutExt
@@ -143,7 +148,7 @@ public enum VirtualPath: Hashable {
143148 /// Retrieve the path to the parent directory.
144149 public var parentDirectory : VirtualPath {
145150 switch self {
146- case . absolute( let path) :
151+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
147152 return . absolute( path. parentDirectory)
148153 case . relative( let path) :
149154 return . relative( try ! RelativePath ( validating: path. dirname) )
@@ -162,7 +167,7 @@ public enum VirtualPath: Hashable {
162167 /// This should not be used with `.standardInput` or `.standardOutput`.
163168 public func appending( component: String ) -> VirtualPath {
164169 switch self {
165- case . absolute( let path) :
170+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
166171 return . absolute( path. appending ( component: component) )
167172 case . relative( let path) :
168173 return . relative( path. appending ( component: component) )
@@ -180,7 +185,7 @@ public enum VirtualPath: Hashable {
180185
181186 public func appending( components: String ... ) -> VirtualPath {
182187 switch self {
183- case . absolute( let path) :
188+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
184189 return . absolute( path. appending ( components: components) )
185190 case . relative( let path) :
186191 return . relative( path. appending ( components: components) )
@@ -201,7 +206,7 @@ public enum VirtualPath: Hashable {
201206 /// This should not be used with `.standardInput` or `.standardOutput`.
202207 public func appendingToBaseName( _ suffix: String ) throws -> VirtualPath {
203208 switch self {
204- case let . absolute( path) :
209+ case let . absolute( path) , . buildArtifactWithKnownContents ( let path , _ ) :
205210 return . absolute( try AbsolutePath ( validating: path. pathString + suffix) )
206211 case let . relative( path) :
207212 return . relative( try RelativePath ( validating: path. pathString + suffix) )
@@ -297,6 +302,8 @@ extension VirtualPath {
297302 return path. pathString
298303 case . absolute( let path) :
299304 return path. pathString
305+ case . buildArtifactWithKnownContents( let path, _) :
306+ return " buildArtifactWithKnownContents: " + path. pathString
300307 case . temporary( let path) :
301308 // N.B. Mangle in a discrimintor for temporaries so they intern apart
302309 // from normal kinds of paths.
@@ -429,6 +436,13 @@ extension VirtualPath {
429436 }
430437}
431438
439+ extension VirtualPath {
440+ public static func createBuildProductFileWithKnownContents( _ path: AbsolutePath , _ data: Data )
441+ throws -> VirtualPath {
442+ return . buildArtifactWithKnownContents( path, data)
443+ }
444+ }
445+
432446// MARK: Temporary File Creation
433447
434448/// Most client contexts require temporary files they request to be unique (e.g. auxiliary compile outputs).
@@ -511,7 +525,7 @@ extension VirtualPath.Handle: Hashable {}
511525extension VirtualPath : Codable {
512526 private enum CodingKeys : String , CodingKey {
513527 case relative, absolute, standardInput, standardOutput, temporary,
514- temporaryWithKnownContents, fileList
528+ temporaryWithKnownContents, buildProductWithKnownContents , fileList
515529 }
516530
517531 public func encode( to encoder: Encoder ) throws {
@@ -534,6 +548,10 @@ extension VirtualPath: Codable {
534548 var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . temporaryWithKnownContents)
535549 try unkeyedContainer. encode ( path)
536550 try unkeyedContainer. encode ( contents)
551+ case let . buildArtifactWithKnownContents( path, contents) :
552+ var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . buildProductWithKnownContents)
553+ try unkeyedContainer. encode ( path)
554+ try unkeyedContainer. encode ( contents)
537555 case . fileList( let path, let fileList) :
538556 var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . fileList)
539557 try unkeyedContainer. encode ( path)
@@ -568,6 +586,11 @@ extension VirtualPath: Codable {
568586 let path = try unkeyedValues. decode ( RelativePath . self)
569587 let contents = try unkeyedValues. decode ( Data . self)
570588 self = . temporaryWithKnownContents( path, contents)
589+ case . buildProductWithKnownContents:
590+ var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
591+ let path = try unkeyedValues. decode ( AbsolutePath . self)
592+ let contents = try unkeyedValues. decode ( Data . self)
593+ self = . buildArtifactWithKnownContents( path, contents)
571594 case . fileList:
572595 var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
573596 let path = try unkeyedValues. decode ( RelativePath . self)
@@ -593,7 +616,7 @@ public struct TextualVirtualPath: Codable, Hashable {
593616 public func encode( to encoder: Encoder ) throws {
594617 var container = encoder. singleValueContainer ( )
595618 switch VirtualPath . lookup ( self . path) {
596- case . absolute( let path) :
619+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
597620 try container. encode ( path. pathString)
598621 case . relative( let path) :
599622 try container. encode ( path. pathString)
@@ -612,7 +635,7 @@ extension VirtualPath: CustomStringConvertible {
612635 case . relative( let path) :
613636 return path. pathString
614637
615- case . absolute( let path) :
638+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
616639 return path. pathString
617640
618641 case . standardInput, . standardOutput:
@@ -632,6 +655,8 @@ extension VirtualPath: CustomDebugStringConvertible {
632655 return " .relative( \( path. pathString) ) "
633656 case . absolute( let path) :
634657 return " .absolute( \( path. pathString) ) "
658+ case . buildArtifactWithKnownContents( let path, _) :
659+ return " buildProductWithKnownContents( \( path. pathString) ) "
635660 case . standardInput:
636661 return " .standardInput "
637662 case . standardOutput:
@@ -653,6 +678,8 @@ extension VirtualPath {
653678 switch self {
654679 case let . absolute( path) :
655680 return . absolute( try AbsolutePath ( validating: path. pathString. withoutExt ( path. extension) . appendingFileTypeExtension ( fileType) ) )
681+ case let . buildArtifactWithKnownContents( path, content) :
682+ return . buildArtifactWithKnownContents( try AbsolutePath ( validating: path. pathString. withoutExt ( path. extension) . appendingFileTypeExtension ( fileType) ) , content)
656683 case let . relative( path) :
657684 return . relative( try RelativePath ( validating: path. pathString. withoutExt ( path. extension) . appendingFileTypeExtension ( fileType) ) )
658685 case let . temporary( path) :
@@ -700,6 +727,8 @@ extension TSCBasic.FileSystem {
700727 switch path {
701728 case let . absolute( absPath) :
702729 return try f ( absPath)
730+ case let . buildArtifactWithKnownContents( absPath, _) :
731+ return try f ( absPath)
703732 case let . relative( relPath) :
704733 guard let cwd = currentWorkingDirectory else {
705734 throw FileSystemError . noCurrentWorkingDirectory
0 commit comments