Skip to content

Commit

Permalink
Fix handling of the '--' argument followed by inputs for the immediat…
Browse files Browse the repository at this point in the history
…e compilation mode ('swift')

Resolves rdar://114191406
  • Loading branch information
artemcm committed Sep 8, 2023
1 parent f5df590 commit a213096
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/SwiftOptions/OptionParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extension OptionTable {
throw OptionParseError.unknownOption(
index: index - 1, argument: argument)
}
parsedOptions.addOption(.DASHDASH, argument: .single("--"))
parsedOptions.addOption(.DASHDASH, argument: .multiple(Array()))
arguments[index...].map { String($0) }.forEach { parsedOptions.addInput($0) }
index = arguments.endIndex

Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftOptions/ParsedOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ extension ParsedOption: CustomStringConvertible {
return option.spelling + " " + argument.asSingle.spm_shellEscaped()

case .remaining:
return argument.asSingle
let args = argument.asMultiple
if args.isEmpty {
return option.spelling
}
return option.spelling + " " + argument.asMultiple.map { $0.spm_shellEscaped() }.joined(separator: " ")
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2937,6 +2937,18 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testDashDashImmediateInput() throws {
do {
var driver = try Driver(args: ["swift", "--", "main.swift"])
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
XCTAssertFalse(driver.diagnosticEngine.hasErrors)
XCTAssertEqual(plannedJobs.count, 1)
XCTAssertEqual(plannedJobs[0].kind, .interpret)
XCTAssertEqual(plannedJobs[0].inputs.count, 1)
XCTAssertEqual(plannedJobs[0].inputs[0].file, VirtualPath.relative(RelativePath("main.swift")))
}
}

func testWholeModuleOptimizationOutputFileMap() throws {
let contents = """
{
Expand Down

0 comments on commit a213096

Please sign in to comment.