From fe9183d58802ecba0ff74e06190e7ecd22e075bd Mon Sep 17 00:00:00 2001 From: Michael Rawdon Date: Wed, 1 Oct 2025 17:28:06 -0700 Subject: [PATCH] Keep -target and -isysroot options on the clang command lines, rather than in response files rdar://161776508 --- .../SpecImplementations/Tools/CCompiler.swift | 20 ++++++++++++++++++- ...angResponseFileTaskConstructionTests.swift | 1 - 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift b/Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift index 72b5bb33..637a38a9 100644 --- a/Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift +++ b/Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift @@ -689,15 +689,32 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible let sparseSDKSearchPaths = GCCCompatibleCompilerSpecSupport.sparseSDKSearchPathArguments(producer.sparseSDKs, headerSearchPaths.headerSearchPaths, frameworkSearchPaths.frameworkSearchPaths) commandLine += sparseSDKSearchPaths.searchPathArguments(for: self, scope: scope) + // Extract arguments to write to the response file, if enabled. if scope.evaluate(BuiltinMacros.CLANG_USE_RESPONSE_FILE) && (optionContext?.toolPath.basenameWithoutSuffix == "clang" || optionContext?.toolPath.basenameWithoutSuffix == "clang++") { var responseFileCommandLine: [String] = [] var regularCommandLine: [String] = [] + // Filter out select arguments from the response file. var iterator = commandLine.makeIterator() var previousArg: ByteString? = nil while let arg = iterator.next() { let argAsByteString = ByteString(encodingAsUTF8: arg) - if ClangSourceFileIndexingInfo.skippedArgsWithValues.contains(argAsByteString) || arg == "-include" { + if arg == "-target" { + // Exclude -target from the response file to make reading the build log easier. + regularCommandLine.append(arg) + if let nextArg = iterator.next() { + regularCommandLine.append(nextArg) + } + } + else if arg == "-isysroot" || arg == "--sysroot" { + // Exclude the options to pass the path to the base SDK from the response file to make reading the build log easier. + // Sparse SDK options do not get similar treatment since they are passed as normal search paths. + regularCommandLine.append(arg) + if let nextArg = iterator.next() { + regularCommandLine.append(nextArg) + } + } + else if ClangSourceFileIndexingInfo.skippedArgsWithValues.contains(argAsByteString) || arg == "-include" { // Relevant to indexing, so exclude arg and value from response file. regularCommandLine.append(arg) if let nextArg = iterator.next() { @@ -713,6 +730,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible // Exclude from response file. regularCommandLine.append(arg) } else { + // All other args get added to the response file. responseFileCommandLine.append(arg) } previousArg = argAsByteString diff --git a/Tests/SWBTaskConstructionTests/ClangResponseFileTaskConstructionTests.swift b/Tests/SWBTaskConstructionTests/ClangResponseFileTaskConstructionTests.swift index 08cdc80a..896f792c 100644 --- a/Tests/SWBTaskConstructionTests/ClangResponseFileTaskConstructionTests.swift +++ b/Tests/SWBTaskConstructionTests/ClangResponseFileTaskConstructionTests.swift @@ -63,7 +63,6 @@ fileprivate struct ClangResponseFileTaskConstructionTests: CoreBasedTests { // The command arguments in the response file vary vastly between different platforms, so just check for some basics present in the content. let contentAsString = contents.asString - #expect(contentAsString.contains("-target ")) #expect(contentAsString.contains("Test-generated-files.hmap")) #expect(contentAsString.contains("Test-own-target-headers.hmap")) #expect(contentAsString.contains("Test-all-target-headers.hmap"))