Skip to content

Commit b3f9992

Browse files
authored
Merge pull request #817 from owenv/owenv/clang-resp-2
Correct cross-platform formatting of clang response files
2 parents cb5ee46 + 3db0e78 commit b3f9992

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public struct ClangSourceFileIndexingInfo: SourceFileIndexingInfo {
235235
// Skip
236236
} else if arg.starts(with: ByteString(unicodeScalarLiteral: "@")),
237237
let attachmentPath = responseFileMapping[Path(arg.asString.dropFirst())],
238-
let responseFileArgs = try? ResponseFiles.expandResponseFiles(["@\(attachmentPath.str)"], fileSystem: localFS, relativeTo: workingDir, format: .unixShellQuotedSpaceSeparated) {
238+
let responseFileArgs = try? ResponseFiles.expandResponseFiles(["@\(attachmentPath.str)"], fileSystem: localFS, relativeTo: workingDir, format: .llvmStyleEscaping) {
239239
result.append(contentsOf: responseFileArgs.map { ByteString(encodingAsUTF8: $0) })
240240
} else {
241241
result.append(arg)
@@ -719,7 +719,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
719719
ctx.add(string: self.identifier)
720720

721721
let responseFilePath = scope.evaluate(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR).join("\(ctx.signature.asString)-common-args.resp")
722-
let attachmentPath = producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: producer, scope: scope, inputs: [], output: responseFilePath), delegate, contents: ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: responseFileCommandLine, format: .unixShellQuotedSpaceSeparated)), permissions: nil, logContents: true, preparesForIndexing: true, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
722+
let attachmentPath = producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: producer, scope: scope, inputs: [], output: responseFilePath), delegate, contents: ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: responseFileCommandLine, format: .llvmStyleEscaping)), permissions: nil, logContents: true, preparesForIndexing: true, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
723723

724724
return ConstantFlags(flags: regularCommandLine + ["@\(responseFilePath.str)"], headerSearchPaths: headerSearchPaths, inputs: [responseFilePath], responseFileMapping: [responseFilePath: attachmentPath])
725725
} else {

Sources/SWBTaskExecution/TaskActions/ClangScanTaskAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class ClangScanTaskAction: TaskAction, BuildValueValidatingTaskActi
7474
self.scanningOutput = parsedOutput
7575
if expandResponseFiles {
7676
do {
77-
self.commandLine = try ResponseFiles.expandResponseFiles(cliArguments, fileSystem: executionDelegate.fs, relativeTo: workingDirectory, format: .unixShellQuotedSpaceSeparated)
77+
self.commandLine = try ResponseFiles.expandResponseFiles(cliArguments, fileSystem: executionDelegate.fs, relativeTo: workingDirectory, format: .llvmStyleEscaping)
7878
} catch {
7979
outputDelegate.error(error.localizedDescription)
8080
return nil

Sources/SWBUtil/ResponseFiles.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public enum ResponseFileFormat: String, Equatable, Hashable, CaseIterable, Senda
1515
case unixShellQuotedNewlineSeparated
1616
case unixShellQuotedSpaceSeparated
1717
case windowsShellQuotedNewlineSeparated
18+
case llvmStyleEscaping
1819
}
1920

2021
public enum ResponseFiles: Sendable {
@@ -30,6 +31,8 @@ public enum ResponseFiles: Sendable {
3031
case .windowsShellQuotedNewlineSeparated:
3132
let escaper = WindowsProcessArgumentsCodec()
3233
return args.map { escaper.encode([$0]) + "\r\n" }.joined()
34+
case .llvmStyleEscaping:
35+
return LLVMStyleCommandCodec().encode(args)
3336
}
3437
}
3538

@@ -73,6 +76,8 @@ public enum ResponseFiles: Sendable {
7376
case .windowsShellQuotedNewlineSeparated:
7477
return content.split { $0 == "\n" || $0 == "\r\n" }
7578
.map { tokenizeWindowsShellQuotedResponseFileArg($0) }
79+
case .llvmStyleEscaping:
80+
return (try? LLVMStyleCommandCodec().decode(content)) ?? []
7681
}
7782
}
7883

0 commit comments

Comments
 (0)