Skip to content

Commit 4ff755a

Browse files
authored
Merge pull request #220 from owenv/response-file-path-resolution
Properly resolve paths to temporary response files when autolinking
2 parents d31563c + 7912ad3 commit 4ff755a

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

Sources/SwiftDriver/Execution/ArgsResolver.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public struct ArgsResolver {
7373

7474
// Otherwise, return the path.
7575
return path.name
76+
case .responseFilePath(let path):
77+
return "@\(try resolve(.path(path)))"
7678
}
7779
}
7880

Sources/SwiftDriver/Jobs/CommandLineArguments.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ extension Array where Element == Job.ArgTemplate {
169169
return string.spm_shellEscaped()
170170
case .path(let path):
171171
return path.name.spm_shellEscaped()
172+
case .responseFilePath(let path):
173+
return "@\(path.name.spm_shellEscaped())"
172174
}
173175
}.joined(separator: " ")
174176
}

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ extension GenericUnixToolchain {
161161
let inputFiles: [Job.ArgTemplate] = inputs.map { input in
162162
// Autolink inputs are handled specially
163163
if input.type == .autolink {
164-
return .flag("@\(input.file.name)")
164+
return .responseFilePath(input.file)
165165
}
166166
return .path(input.file)
167167
}
@@ -210,7 +210,7 @@ extension GenericUnixToolchain {
210210
guard fileSystem.isFile(linkFile) else {
211211
fatalError("\(linkFile.pathString) not found")
212212
}
213-
commandLine.appendFlag("@\(linkFile.pathString)")
213+
commandLine.append(.responseFilePath(.absolute(linkFile)))
214214
}
215215

216216
// Explicitly pass the target to the linker

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public struct Job: Codable, Equatable, Hashable {
4343

4444
/// Represents a virtual path on disk.
4545
case path(VirtualPath)
46+
47+
/// Represents a response file path prefixed by '@'.
48+
case responseFilePath(VirtualPath)
4649
}
4750

4851
/// The Swift module this job involves.
@@ -215,7 +218,7 @@ extension Job.Kind {
215218

216219
extension Job.ArgTemplate: Codable {
217220
private enum CodingKeys: String, CodingKey {
218-
case flag, path
221+
case flag, path, responseFilePath
219222
}
220223

221224
public func encode(to encoder: Encoder) throws {
@@ -227,6 +230,9 @@ extension Job.ArgTemplate: Codable {
227230
case let .path(a1):
228231
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .path)
229232
try unkeyedContainer.encode(a1)
233+
case let .responseFilePath(a1):
234+
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .responseFilePath)
235+
try unkeyedContainer.encode(a1)
230236
}
231237
}
232238

@@ -244,6 +250,10 @@ extension Job.ArgTemplate: Codable {
244250
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
245251
let a1 = try unkeyedValues.decode(VirtualPath.self)
246252
self = .path(a1)
253+
case .responseFilePath:
254+
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
255+
let a1 = try unkeyedValues.decode(VirtualPath.self)
256+
self = .responseFilePath(a1)
247257
}
248258
}
249259
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ final class SwiftDriverTests: XCTestCase {
857857
XCTAssertTrue(cmd.contains(.flag("-shared")))
858858
XCTAssertTrue(cmd.contains(.path(.temporary(RelativePath("foo.o")))))
859859
XCTAssertTrue(cmd.contains(.path(.temporary(RelativePath("bar.o")))))
860+
XCTAssertTrue(cmd.contains(.responseFilePath(.temporary(RelativePath("Test.autolink")))))
860861
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "libTest.so"))
861862

862863
XCTAssertFalse(cmd.contains(.flag("-dylib")))

0 commit comments

Comments
 (0)