@@ -21,15 +21,22 @@ public struct ArgsResolver {
21
21
private let fileSystem : FileSystem
22
22
23
23
/// Path to the directory that will contain the temporary files.
24
- private let temporaryDirectory : AbsolutePath
24
+ // FIXME: We probably need a dedicated type for this...
25
+ private let temporaryDirectory : VirtualPath
25
26
26
- public init ( fileSystem: FileSystem ) throws {
27
+ public init ( fileSystem: FileSystem , temporaryDirectory : VirtualPath ? = nil ) throws {
27
28
self . pathMapping = [ : ]
28
29
self . fileSystem = fileSystem
29
- self . temporaryDirectory = try withTemporaryDirectory ( removeTreeOnDeinit: false ) { path in
30
- // FIXME: TSC removes empty directories even when removeTreeOnDeinit is false. This seems like a bug.
31
- try fileSystem. writeFileContents ( path. appending ( component: " .keep-directory " ) ) { $0 <<< " " }
32
- return path
30
+
31
+ if let temporaryDirectory = temporaryDirectory {
32
+ self . temporaryDirectory = temporaryDirectory
33
+ } else {
34
+ let tmpDir : AbsolutePath = try withTemporaryDirectory ( removeTreeOnDeinit: false ) { path in
35
+ // FIXME: TSC removes empty directories even when removeTreeOnDeinit is false. This seems like a bug.
36
+ try fileSystem. writeFileContents ( path. appending ( component: " .keep-directory " ) ) { $0 <<< " " }
37
+ return path
38
+ }
39
+ self . temporaryDirectory = . absolute( tmpDir)
33
40
}
34
41
}
35
42
@@ -56,7 +63,7 @@ public struct ArgsResolver {
56
63
// Return the path from the temporary directory if this is a temporary file.
57
64
if path. isTemporary {
58
65
let actualPath = temporaryDirectory. appending ( component: path. name)
59
- return actualPath. pathString
66
+ return actualPath. name
60
67
}
61
68
62
69
// If there was a path mapping, use it.
@@ -76,17 +83,25 @@ public struct ArgsResolver {
76
83
" Platform does not support response files for job: \( job) " )
77
84
// Match the integrated driver's behavior, which uses response file names of the form "arguments-[0-9a-zA-Z].resp".
78
85
let responseFilePath = temporaryDirectory. appending ( component: " arguments- \( abs ( job. hashValue) ) .resp " )
79
- try fileSystem. writeFileContents ( responseFilePath) {
80
- $0 <<< resolvedArguments [ 1 ... ] . map{ $0. spm_shellEscaped ( ) } . joined ( separator: " \n " )
86
+
87
+ // FIXME: Need a way to support this for distributed build systems...
88
+ if let absPath = responseFilePath. absolutePath {
89
+ try fileSystem. writeFileContents ( absPath) {
90
+ $0 <<< resolvedArguments [ 1 ... ] . map{ $0. spm_shellEscaped ( ) } . joined ( separator: " \n " )
91
+ }
92
+ resolvedArguments = [ resolvedArguments [ 0 ] , " @ \( absPath. pathString) " ]
81
93
}
82
- resolvedArguments = [ resolvedArguments [ 0 ] , " @ \( responseFilePath . pathString ) " ]
94
+
83
95
return true
84
96
}
85
97
return false
86
98
}
87
99
88
100
/// Remove the temporary directory from disk.
89
101
public func removeTemporaryDirectory( ) throws {
90
- try fileSystem. removeFileTree ( temporaryDirectory)
102
+ // Only try to remove if we have an absolute path.
103
+ if let absPath = temporaryDirectory. absolutePath {
104
+ try fileSystem. removeFileTree ( absPath)
105
+ }
91
106
}
92
107
}
0 commit comments