Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove -index-store-path for clang vendor is not Apple #142

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/SWBCore/Specs/Tools/CCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,19 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
let sparseSDKSearchPaths = GCCCompatibleCompilerSpecSupport.sparseSDKSearchPathArguments(producer.sparseSDKs, headerSearchPaths.headerSearchPaths, frameworkSearchPaths.frameworkSearchPaths)
commandLine += sparseSDKSearchPaths.searchPathArguments(for: self, scope: scope)

if let clangInfo = optionContext as? DiscoveredClangToolSpecInfo, !clangInfo.isAppleClang {
var filteredCommandLine: [String] = []
var iterator = commandLine.makeIterator()
while let arg = iterator.next() {
if arg == "-index-store-path" {
_ = iterator.next()
} else {
filteredCommandLine.append(arg)
}
}
commandLine = filteredCommandLine
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just not add the flag in the first place based on vendor? Or is the idea that it would often come in via OTHER_*FLAGS?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that would be better. Should be able to do that by providing a lookup closure to commandLineFromOptions (near line 622) and overriding COMPILER_INDEX_STORE_ENABLE to NO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Working on it 😄

if scope.evaluate(BuiltinMacros.CLANG_USE_RESPONSE_FILE) && (optionContext?.toolPath.basenameWithoutSuffix == "clang" || optionContext?.toolPath.basenameWithoutSuffix == "clang++") {
var responseFileCommandLine: [String] = []
var regularCommandLine: [String] = []
Expand Down
9 changes: 8 additions & 1 deletion Sources/SWBCore/ToolInfo/ClangToolInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
public let toolPath: Path
public let clangVersion: Version?
public let llvmVersion: Version?
public let isAppleClang: Bool

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

Expand Down Expand Up @@ -79,7 +80,7 @@ public func discoveredClangToolInfo(
) async throws -> DiscoveredClangToolSpecInfo {
// 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.
guard toolPath.basename.starts(with: "clang") else {
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, clangCachingBlocklist: nil, toolFeatures: .none)
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, isAppleClang: false, clangCachingBlocklist: nil, toolFeatures: .none)
}

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

var clangVersion: Version? = nil
var llvmVersion: Version? = nil
var isAppleClang = false

for line in outputString.components(separatedBy: "\n") {
if line.hasPrefix("#define ") {
Expand All @@ -123,6 +125,10 @@ public func discoveredClangToolInfo(
llvmVersion = try? Version(String(match.llvm))
}
}

if macroName == "__apple_build_version__" {
isAppleClang = true
}
}
}

Expand Down Expand Up @@ -157,6 +163,7 @@ public func discoveredClangToolInfo(
toolPath: toolPath,
clangVersion: clangVersion,
llvmVersion: llvmVersion,
isAppleClang: isAppleClang,
clangCachingBlocklist: getBlocklist(type: ClangCachingBlockListInfo.self, toolchainFilename: "clang-caching.json", delegate: delegate),
toolFeatures: getFeatures(at: toolPath)
)
Expand Down