Skip to content

Commit a4eb4d8

Browse files
committed
Keep -target and -isysroot options on the clang command lines, rather than in response files
rdar://161776508
1 parent 143dcf4 commit a4eb4d8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,15 +689,32 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
689689
let sparseSDKSearchPaths = GCCCompatibleCompilerSpecSupport.sparseSDKSearchPathArguments(producer.sparseSDKs, headerSearchPaths.headerSearchPaths, frameworkSearchPaths.frameworkSearchPaths)
690690
commandLine += sparseSDKSearchPaths.searchPathArguments(for: self, scope: scope)
691691

692+
// Extract arguments to write to the response file, if enabled.
692693
if scope.evaluate(BuiltinMacros.CLANG_USE_RESPONSE_FILE) && (optionContext?.toolPath.basenameWithoutSuffix == "clang" || optionContext?.toolPath.basenameWithoutSuffix == "clang++") {
693694
var responseFileCommandLine: [String] = []
694695
var regularCommandLine: [String] = []
695696

697+
// Filter out select arguments from the response file.
696698
var iterator = commandLine.makeIterator()
697699
var previousArg: ByteString? = nil
698700
while let arg = iterator.next() {
699701
let argAsByteString = ByteString(encodingAsUTF8: arg)
700-
if ClangSourceFileIndexingInfo.skippedArgsWithValues.contains(argAsByteString) || arg == "-include" {
702+
if arg == "-target" {
703+
// Exclude -target from the response file to make reading the build log easier.
704+
regularCommandLine.append(arg)
705+
if let nextArg = iterator.next() {
706+
regularCommandLine.append(nextArg)
707+
}
708+
}
709+
else if arg == "-isysroot" || arg == "--sysroot" {
710+
// Exclude the options to pass the path to the base SDK from the response file to make reading the build log easier.
711+
// Sparse SDK options do not get similar treatment since they are passed as normal search paths.
712+
regularCommandLine.append(arg)
713+
if let nextArg = iterator.next() {
714+
regularCommandLine.append(nextArg)
715+
}
716+
}
717+
else if ClangSourceFileIndexingInfo.skippedArgsWithValues.contains(argAsByteString) || arg == "-include" {
701718
// Relevant to indexing, so exclude arg and value from response file.
702719
regularCommandLine.append(arg)
703720
if let nextArg = iterator.next() {
@@ -713,6 +730,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
713730
// Exclude from response file.
714731
regularCommandLine.append(arg)
715732
} else {
733+
// All other args get added to the response file.
716734
responseFileCommandLine.append(arg)
717735
}
718736
previousArg = argAsByteString

Tests/SWBTaskConstructionTests/ClangResponseFileTaskConstructionTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ fileprivate struct ClangResponseFileTaskConstructionTests: CoreBasedTests {
6363

6464
// The command arguments in the response file vary vastly between different platforms, so just check for some basics present in the content.
6565
let contentAsString = contents.asString
66-
#expect(contentAsString.contains("-target "))
6766
#expect(contentAsString.contains("Test-generated-files.hmap"))
6867
#expect(contentAsString.contains("Test-own-target-headers.hmap"))
6968
#expect(contentAsString.contains("Test-all-target-headers.hmap"))

0 commit comments

Comments
 (0)