Skip to content

Commit 7912ad3

Browse files
committed
Properly resolve paths to temporary response files when autolinking
1 parent 0666f04 commit 7912ad3

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
@@ -42,6 +42,9 @@ public struct Job: Codable, Equatable, Hashable {
4242

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

4750
/// The Swift module this job involves.
@@ -211,7 +214,7 @@ extension Job.Kind {
211214

212215
extension Job.ArgTemplate: Codable {
213216
private enum CodingKeys: String, CodingKey {
214-
case flag, path
217+
case flag, path, responseFilePath
215218
}
216219

217220
public func encode(to encoder: Encoder) throws {
@@ -223,6 +226,9 @@ extension Job.ArgTemplate: Codable {
223226
case let .path(a1):
224227
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .path)
225228
try unkeyedContainer.encode(a1)
229+
case let .responseFilePath(a1):
230+
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .responseFilePath)
231+
try unkeyedContainer.encode(a1)
226232
}
227233
}
228234

@@ -240,6 +246,10 @@ extension Job.ArgTemplate: Codable {
240246
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
241247
let a1 = try unkeyedValues.decode(VirtualPath.self)
242248
self = .path(a1)
249+
case .responseFilePath:
250+
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
251+
let a1 = try unkeyedValues.decode(VirtualPath.self)
252+
self = .responseFilePath(a1)
243253
}
244254
}
245255
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

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

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

0 commit comments

Comments
 (0)