Skip to content

Commit f335083

Browse files
authored
Don’t include compiler in the command line arguments (#7379)
The compiler itself is part of the command line invocation, not an argument in itself. rdar://123765692
1 parent f042ffd commit f335083

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Sources/SourceKitLSPAPI/BuildDescription.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ extension ClangTargetBuildDescription: BuildTarget {
3636

3737
public func compileArguments(for fileURL: URL) throws -> [String] {
3838
let filePath = try resolveSymlinks(try AbsolutePath(validating: fileURL.path))
39-
return try self.emitCommandLine(for: filePath)
39+
let commandLine = try self.emitCommandLine(for: filePath)
40+
// First element on the command line is the compiler itself, not an argument.
41+
return Array(commandLine.dropFirst())
4042
}
4143
}
4244

@@ -54,7 +56,9 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
5456
func compileArguments(for fileURL: URL) throws -> [String] {
5557
// Note: we ignore the `fileURL` here as the expectation is that we get a command line for the entire target
5658
// in case of Swift.
57-
return try description.emitCommandLine(scanInvocation: false)
59+
let commandLine = try description.emitCommandLine(scanInvocation: false)
60+
// First element on the command line is the compiler itself, not an argument.
61+
return Array(commandLine.dropFirst())
5862
}
5963
}
6064

Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class SourceKitLSPAPITests: XCTestCase {
5151
)
5252
let description = BuildDescription(buildPlan: plan)
5353

54-
try description.checkArguments(for: "exe", graph: graph, partialArguments: ["/fake/path/to/swiftc", "-module-name", "exe", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/exe.build/exe.swiftmodule"])
55-
try description.checkArguments(for: "lib", graph: graph, partialArguments: ["/fake/path/to/swiftc", "-module-name", "lib", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/Modules/lib.swiftmodule"])
54+
try description.checkArguments(for: "exe", graph: graph, partialArguments: ["-module-name", "exe", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/exe.build/exe.swiftmodule"])
55+
try description.checkArguments(for: "lib", graph: graph, partialArguments: ["-module-name", "lib", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/Modules/lib.swiftmodule"])
5656
}
5757
}
5858

0 commit comments

Comments
 (0)