Skip to content

Commit 8f65c26

Browse files
Merge pull request #357 from apple/cs_swiftHelpIntegrationTests
Install swift-help for integration tests. Suppress .noDriver options from being emitted by swift-help. Fix option handling where noDriver arguments were treated as valid.
2 parents 5e04a08 + 3c99ffc commit 8f65c26

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ extension Driver {
10481048
// Some output flags affect the compiler mode.
10491049
if let outputOption = parsedOptions.getLast(in: .modes) {
10501050
switch outputOption.option {
1051-
case .emitPch, .emitImportedModules:
1051+
case .emitImportedModules:
10521052
return .singleCompile
10531053

10541054
case .repl, .lldbRepl:
@@ -1090,8 +1090,6 @@ extension Driver {
10901090
parsedOptions.eraseArgument(.indexFile)
10911091
parsedOptions.eraseArgument(.indexFilePath)
10921092
parsedOptions.eraseArgument(.indexStorePath)
1093-
parsedOptions.eraseArgument(.indexIgnoreStdlib)
1094-
parsedOptions.eraseArgument(.indexSystemModules)
10951093
parsedOptions.eraseArgument(.indexIgnoreSystemModules)
10961094
return .standardCompile
10971095
}
@@ -1231,9 +1229,6 @@ extension Driver {
12311229
case .dumpAst:
12321230
compilerOutputType = .ast
12331231

1234-
case .emitPch:
1235-
compilerOutputType = .pch
1236-
12371232
case .emitPcm:
12381233
compilerOutputType = .pcm
12391234

Sources/SwiftOptions/Option.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ extension Option {
135135
public func isAccepted(by driverKind: DriverKind) -> Bool {
136136
switch driverKind {
137137
case .batch:
138-
return !attributes.contains(.noBatch)
138+
return attributes.isDisjoint(with: [.noDriver, .noBatch])
139139
case .interactive:
140-
return !attributes.contains(.noInteractive)
140+
return attributes.isDisjoint(with: [.noDriver, .noInteractive])
141141
}
142142
}
143143
}

Sources/SwiftOptions/OptionParsing.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ extension OptionTable {
3838
public func parse(_ arguments: [String],
3939
for driverKind: DriverKind) throws -> ParsedOptions {
4040
var trie = PrefixTrie<Option>()
41-
for opt in options {
41+
// Add all options, ignoring the .noDriver ones
42+
for opt in options where !opt.attributes.contains(.noDriver) {
4243
trie[opt.spelling] = opt
4344
}
4445

Tests/SwiftDriverTests/IntegrationTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ func makeDriverSymlinks(
3434
try makeDirectories(tempBinDir)
3535

3636
let swift = tempBinDir.appending(component: "swift")
37-
try createSymlink(swift, pointingAt: driver, relative: false)
37+
try localFileSystem.createSymbolicLink(swift, pointingAt: driver, relative: false)
3838

3939
let swiftc = tempBinDir.appending(components: "swiftc")
40-
try createSymlink(swiftc, pointingAt: driver, relative: false)
40+
try localFileSystem.createSymbolicLink(swiftc, pointingAt: driver, relative: false)
41+
42+
let swiftHelp = binDir.appending(component: "swift-help")
43+
let swiftHelpSimlink = tempBinDir.appending(component: "swift-help")
44+
try localFileSystem.createSymbolicLink(swiftHelpSimlink, pointingAt: swiftHelp, relative: false)
4145

4246
// If we've been given a build dir, link in its lib folder so we can find its
4347
// resource directory.
4448
if let swiftBuildDir = swiftBuildDir {
4549
let libDir = swiftBuildDir.appending(component: "lib")
4650
let tempLibDir = tempDir.appending(component: "lib" )
47-
try createSymlink(tempLibDir, pointingAt: libDir, relative: false)
51+
try localFileSystem.createSymbolicLink(tempLibDir, pointingAt: libDir, relative: false)
4852
}
4953

5054
return (swift: swift, swiftc: swiftc)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ final class SwiftDriverTests: XCTestCase {
15581558

15591559
func testMergeModulesOnly() throws {
15601560
do {
1561-
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module", "-disable-bridging-pch", "-import-objc-header", "TestInputHeader.h", "-emit-dependencies", "-emit-module-doc-path", "/foo/bar/Test.swiftdoc", "-emit-module-source-info-path", "/foo/bar/Test.swiftsourceinfo"])
1561+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module", "-disable-bridging-pch", "-import-objc-header", "TestInputHeader.h", "-emit-dependencies", "-emit-module-source-info-path", "/foo/bar/Test.swiftsourceinfo"])
15621562
let plannedJobs = try driver.planBuild()
15631563
XCTAssertEqual(plannedJobs.count, 3)
15641564
XCTAssertEqual(plannedJobs[0].outputs.count, 4)
@@ -1578,7 +1578,7 @@ final class SwiftDriverTests: XCTestCase {
15781578
XCTAssertTrue(plannedJobs[2].tool.name.contains("swift"))
15791579
XCTAssertEqual(plannedJobs[2].outputs.count, 3)
15801580
XCTAssertEqual(plannedJobs[2].outputs[0].file, .relative(RelativePath("Test.swiftmodule")))
1581-
XCTAssertEqual(plannedJobs[2].outputs[1].file, .absolute(AbsolutePath("/foo/bar/Test.swiftdoc")))
1581+
XCTAssertEqual(plannedJobs[2].outputs[1].file, .relative(RelativePath("Test.swiftdoc")))
15821582
XCTAssertEqual(plannedJobs[2].outputs[2].file, .absolute(AbsolutePath("/foo/bar/Test.swiftsourceinfo")))
15831583
XCTAssert(plannedJobs[2].commandLine.contains(.flag("-import-objc-header")))
15841584
}
@@ -1608,7 +1608,7 @@ final class SwiftDriverTests: XCTestCase {
16081608

16091609
do {
16101610
// Make sure the swiftdoc path is correct for an inferred module
1611-
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-doc", "-emit-module"])
1611+
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module"])
16121612
let plannedJobs = try driver.planBuild()
16131613
XCTAssertEqual(plannedJobs.count, 3)
16141614
XCTAssertTrue(plannedJobs[2].tool.name.contains("swift"))
@@ -2714,7 +2714,6 @@ final class SwiftDriverTests: XCTestCase {
27142714
"foo.swift",
27152715
"-index-file-path", "foo.swift",
27162716
"-index-store-path", "store/path",
2717-
"-index-ignore-stdlib", "-index-system-modules",
27182717
"-index-ignore-system-modules"]) {
27192718
$1.expect(.warning("ignoring '-index-file' because '-dump-ast' was also specified"))
27202719
let jobs = try $0.planBuild()
@@ -3805,15 +3804,6 @@ final class SwiftDriverTests: XCTestCase {
38053804
}
38063805

38073806
func testSourceInfoFileEmitOption() throws {
3808-
do {
3809-
var driver = try Driver(args: ["swiftc", "-emit-module-source-info", "foo.swift"])
3810-
let plannedJobs = try driver.planBuild()
3811-
let compileJob = plannedJobs[0]
3812-
XCTAssertTrue(compileJob.commandLine.contains(.flag("-emit-module-source-info-path")))
3813-
XCTAssertEqual(compileJob.outputs.count, 2)
3814-
XCTAssertEqual(compileJob.outputs[0].file, .temporary(RelativePath("foo.o")))
3815-
XCTAssertEqual(compileJob.outputs[1].file, .temporary(RelativePath("foo.swiftsourceinfo")))
3816-
}
38173807
// implicit
38183808
do {
38193809
var driver = try Driver(args: ["swiftc", "-emit-module", "foo.swift"])

0 commit comments

Comments
 (0)