@@ -47,6 +47,9 @@ public enum VirtualPath: Hashable {
47
47
/// Standard output
48
48
case standardOutput
49
49
50
+ /// ACTODO: Comment
51
+ case buildArtifactWithKnownContents( AbsolutePath , Data )
52
+
50
53
/// We would like to direct clients to use the temporary file creation utilities `createUniqueTemporaryFile`, etc.
51
54
/// To ensure temporary files are unique.
52
55
/// 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 {
72
75
case . relative( let path) , . temporary( let path) ,
73
76
. temporaryWithKnownContents( let path, _) , . fileList( let path, _) :
74
77
return path. extension
78
+ case . buildArtifactWithKnownContents( let path, _) :
79
+ return path. extension
75
80
case . absolute( let path) :
76
81
return path. extension
77
82
case . standardInput, . standardOutput:
@@ -82,7 +87,7 @@ public enum VirtualPath: Hashable {
82
87
/// Whether this virtual path is to a temporary.
83
88
public var isTemporary : Bool {
84
89
switch self {
85
- case . relative, . absolute, . standardInput, . standardOutput:
90
+ case . relative, . absolute, . standardInput, . standardOutput, . buildArtifactWithKnownContents :
86
91
return false
87
92
case . temporary, . temporaryWithKnownContents, . fileList:
88
93
return true
@@ -91,7 +96,7 @@ public enum VirtualPath: Hashable {
91
96
92
97
public var absolutePath : AbsolutePath ? {
93
98
switch self {
94
- case let . absolute ( absolutePath) :
99
+ case . absolute ( let absolutePath ) , . buildArtifactWithKnownContents ( let absolutePath, _ ) :
95
100
return absolutePath
96
101
case . relative, . temporary, . temporaryWithKnownContents, . fileList, . standardInput, . standardOutput:
97
102
return nil
@@ -111,15 +116,15 @@ public enum VirtualPath: Hashable {
111
116
. fileList( let name, _) ,
112
117
. temporaryWithKnownContents( let name, _) :
113
118
return name
114
- case . absolute, . relative, . standardInput, . standardOutput:
119
+ case . absolute, . relative, . standardInput, . standardOutput, . buildArtifactWithKnownContents :
115
120
return nil
116
121
}
117
122
}
118
123
119
124
/// Retrieve the basename of the path.
120
125
public var basename : String {
121
126
switch self {
122
- case . absolute( let path) :
127
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
123
128
return path. basename
124
129
case . relative( let path) , . temporary( let path) , . temporaryWithKnownContents( let path, _) , . fileList( let path, _) :
125
130
return path. basename
@@ -131,7 +136,7 @@ public enum VirtualPath: Hashable {
131
136
/// Retrieve the basename of the path without the extension.
132
137
public var basenameWithoutExt : String {
133
138
switch self {
134
- case . absolute( let path) :
139
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
135
140
return path. basenameWithoutExt
136
141
case . relative( let path) , . temporary( let path) , . temporaryWithKnownContents( let path, _) , . fileList( let path, _) :
137
142
return path. basenameWithoutExt
@@ -143,7 +148,7 @@ public enum VirtualPath: Hashable {
143
148
/// Retrieve the path to the parent directory.
144
149
public var parentDirectory : VirtualPath {
145
150
switch self {
146
- case . absolute( let path) :
151
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
147
152
return . absolute( path. parentDirectory)
148
153
case . relative( let path) :
149
154
return . relative( try ! RelativePath ( validating: path. dirname) )
@@ -162,7 +167,7 @@ public enum VirtualPath: Hashable {
162
167
/// This should not be used with `.standardInput` or `.standardOutput`.
163
168
public func appending( component: String ) -> VirtualPath {
164
169
switch self {
165
- case . absolute( let path) :
170
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
166
171
return . absolute( path. appending ( component: component) )
167
172
case . relative( let path) :
168
173
return . relative( path. appending ( component: component) )
@@ -180,7 +185,7 @@ public enum VirtualPath: Hashable {
180
185
181
186
public func appending( components: String ... ) -> VirtualPath {
182
187
switch self {
183
- case . absolute( let path) :
188
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
184
189
return . absolute( path. appending ( components: components) )
185
190
case . relative( let path) :
186
191
return . relative( path. appending ( components: components) )
@@ -201,7 +206,7 @@ public enum VirtualPath: Hashable {
201
206
/// This should not be used with `.standardInput` or `.standardOutput`.
202
207
public func appendingToBaseName( _ suffix: String ) throws -> VirtualPath {
203
208
switch self {
204
- case let . absolute( path) :
209
+ case let . absolute( path) , . buildArtifactWithKnownContents ( let path , _ ) :
205
210
return . absolute( try AbsolutePath ( validating: path. pathString + suffix) )
206
211
case let . relative( path) :
207
212
return . relative( try RelativePath ( validating: path. pathString + suffix) )
@@ -297,6 +302,8 @@ extension VirtualPath {
297
302
return path. pathString
298
303
case . absolute( let path) :
299
304
return path. pathString
305
+ case . buildArtifactWithKnownContents( let path, _) :
306
+ return " buildArtifactWithKnownContents: " + path. pathString
300
307
case . temporary( let path) :
301
308
// N.B. Mangle in a discrimintor for temporaries so they intern apart
302
309
// from normal kinds of paths.
@@ -429,6 +436,13 @@ extension VirtualPath {
429
436
}
430
437
}
431
438
439
+ extension VirtualPath {
440
+ public static func createBuildProductFileWithKnownContents( _ path: AbsolutePath , _ data: Data )
441
+ throws -> VirtualPath {
442
+ return . buildArtifactWithKnownContents( path, data)
443
+ }
444
+ }
445
+
432
446
// MARK: Temporary File Creation
433
447
434
448
/// Most client contexts require temporary files they request to be unique (e.g. auxiliary compile outputs).
@@ -511,7 +525,7 @@ extension VirtualPath.Handle: Hashable {}
511
525
extension VirtualPath : Codable {
512
526
private enum CodingKeys : String , CodingKey {
513
527
case relative, absolute, standardInput, standardOutput, temporary,
514
- temporaryWithKnownContents, fileList
528
+ temporaryWithKnownContents, buildProductWithKnownContents , fileList
515
529
}
516
530
517
531
public func encode( to encoder: Encoder ) throws {
@@ -534,6 +548,10 @@ extension VirtualPath: Codable {
534
548
var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . temporaryWithKnownContents)
535
549
try unkeyedContainer. encode ( path)
536
550
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)
537
555
case . fileList( let path, let fileList) :
538
556
var unkeyedContainer = container. nestedUnkeyedContainer ( forKey: . fileList)
539
557
try unkeyedContainer. encode ( path)
@@ -568,6 +586,11 @@ extension VirtualPath: Codable {
568
586
let path = try unkeyedValues. decode ( RelativePath . self)
569
587
let contents = try unkeyedValues. decode ( Data . self)
570
588
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)
571
594
case . fileList:
572
595
var unkeyedValues = try values. nestedUnkeyedContainer ( forKey: key)
573
596
let path = try unkeyedValues. decode ( RelativePath . self)
@@ -593,7 +616,7 @@ public struct TextualVirtualPath: Codable, Hashable {
593
616
public func encode( to encoder: Encoder ) throws {
594
617
var container = encoder. singleValueContainer ( )
595
618
switch VirtualPath . lookup ( self . path) {
596
- case . absolute( let path) :
619
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
597
620
try container. encode ( path. pathString)
598
621
case . relative( let path) :
599
622
try container. encode ( path. pathString)
@@ -612,7 +635,7 @@ extension VirtualPath: CustomStringConvertible {
612
635
case . relative( let path) :
613
636
return path. pathString
614
637
615
- case . absolute( let path) :
638
+ case . absolute( let path) , . buildArtifactWithKnownContents ( let path , _ ) :
616
639
return path. pathString
617
640
618
641
case . standardInput, . standardOutput:
@@ -632,6 +655,8 @@ extension VirtualPath: CustomDebugStringConvertible {
632
655
return " .relative( \( path. pathString) ) "
633
656
case . absolute( let path) :
634
657
return " .absolute( \( path. pathString) ) "
658
+ case . buildArtifactWithKnownContents( let path, _) :
659
+ return " buildProductWithKnownContents( \( path. pathString) ) "
635
660
case . standardInput:
636
661
return " .standardInput "
637
662
case . standardOutput:
@@ -653,6 +678,8 @@ extension VirtualPath {
653
678
switch self {
654
679
case let . absolute( path) :
655
680
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)
656
683
case let . relative( path) :
657
684
return . relative( try RelativePath ( validating: path. pathString. withoutExt ( path. extension) . appendingFileTypeExtension ( fileType) ) )
658
685
case let . temporary( path) :
@@ -700,6 +727,8 @@ extension TSCBasic.FileSystem {
700
727
switch path {
701
728
case let . absolute( absPath) :
702
729
return try f ( absPath)
730
+ case let . buildArtifactWithKnownContents( absPath, _) :
731
+ return try f ( absPath)
703
732
case let . relative( relPath) :
704
733
guard let cwd = currentWorkingDirectory else {
705
734
throw FileSystemError . noCurrentWorkingDirectory
0 commit comments