Skip to content

Commit 072403e

Browse files
committed
Remove -index-store-path if not clang vendor not Apple
1 parent 2e6eb49 commit 072403e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,19 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
653653
let sparseSDKSearchPaths = GCCCompatibleCompilerSpecSupport.sparseSDKSearchPathArguments(producer.sparseSDKs, headerSearchPaths.headerSearchPaths, frameworkSearchPaths.frameworkSearchPaths)
654654
commandLine += sparseSDKSearchPaths.searchPathArguments(for: self, scope: scope)
655655

656+
if let clangInfo = optionContext as? DiscoveredClangToolSpecInfo, !clangInfo.isAppleClang {
657+
var filteredCommandLine: [String] = []
658+
var iterator = commandLine.makeIterator()
659+
while let arg = iterator.next() {
660+
if arg == "-index-store-path" {
661+
_ = iterator.next()
662+
} else {
663+
filteredCommandLine.append(arg)
664+
}
665+
}
666+
commandLine = filteredCommandLine
667+
}
668+
656669
if scope.evaluate(BuiltinMacros.CLANG_USE_RESPONSE_FILE) && (optionContext?.toolPath.basenameWithoutSuffix == "clang" || optionContext?.toolPath.basenameWithoutSuffix == "clang++") {
657670
var responseFileCommandLine: [String] = []
658671
var regularCommandLine: [String] = []

Sources/SWBCore/ToolInfo/ClangToolInfo.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
1616
public let toolPath: Path
1717
public let clangVersion: Version?
1818
public let llvmVersion: Version?
19+
public let isAppleClang: Bool
1920

2021
public var toolVersion: Version? { return self.clangVersion }
2122

@@ -79,7 +80,7 @@ public func discoveredClangToolInfo(
7980
) async throws -> DiscoveredClangToolSpecInfo {
8081
// Check that we call a clang variant, 'clang', 'clang++' etc. Note that a test sets `CC` to `/usr/bin/yes` so avoid calling that here.
8182
guard toolPath.basename.starts(with: "clang") else {
82-
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, clangCachingBlocklist: nil, toolFeatures: .none)
83+
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, isAppleClang: false, clangCachingBlocklist: nil, toolFeatures: .none)
8384
}
8485

8586
// Construct the command line to invoke.
@@ -102,6 +103,7 @@ public func discoveredClangToolInfo(
102103

103104
var clangVersion: Version? = nil
104105
var llvmVersion: Version? = nil
106+
var isAppleClang = false
105107

106108
for line in outputString.components(separatedBy: "\n") {
107109
if line.hasPrefix("#define ") {
@@ -116,6 +118,7 @@ public func discoveredClangToolInfo(
116118
// "8.1.0 (clang-802.1.38)"
117119
// "12.0.0 (clang-1200.0.22.5) [ptrauth objc isa mode: sign-and-strip]"
118120
if macroName == "__clang_version__" {
121+
isAppleClang = macroValue.contains("Apple")
119122
if let match: RegEx.MatchResult = clangVersionRe.firstMatch(in: macroValue) {
120123
llvmVersion = match["llvm"].map { try? Version($0) } ?? nil
121124
clangVersion = match["clang"].map { try? Version($0) } ?? nil
@@ -157,6 +160,7 @@ public func discoveredClangToolInfo(
157160
toolPath: toolPath,
158161
clangVersion: clangVersion,
159162
llvmVersion: llvmVersion,
163+
isAppleClang: isAppleClang,
160164
clangCachingBlocklist: getBlocklist(type: ClangCachingBlockListInfo.self, toolchainFilename: "clang-caching.json", delegate: delegate),
161165
toolFeatures: getFeatures(at: toolPath)
162166
)

0 commit comments

Comments
 (0)