Skip to content

Commit 7eb61ec

Browse files
authored
Merge pull request #71 from owenv/basename-fix
Make module naming consistent with the integrated driver when the output filename has 2+ extensions
2 parents ce4ee20 + b5ca5c6 commit 7eb61ec

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,12 +1163,12 @@ extension Driver {
11631163
private static func baseNameWithoutExtension(_ path: String, hasExtension: inout Bool) -> String {
11641164
if let absolute = try? AbsolutePath(validating: path) {
11651165
hasExtension = absolute.extension != nil
1166-
return absolute.basenameWithoutAllExts
1166+
return absolute.basenameWithoutExt
11671167
}
11681168

11691169
if let relative = try? RelativePath(validating: path) {
11701170
hasExtension = relative.extension != nil
1171-
return relative.basenameWithoutAllExts
1171+
return relative.basenameWithoutExt
11721172
}
11731173

11741174
hasExtension = false

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,19 @@ final class SwiftDriverTests: XCTestCase {
422422
XCTAssertTrue(plannedJobs3[0].commandLine.contains(.flag("-parse-as-library")))
423423
}
424424

425+
func testModuleNaming() throws {
426+
XCTAssertEqual(try Driver(args: ["swiftc", "foo.swift"]).moduleName, "foo")
427+
XCTAssertEqual(try Driver(args: ["swiftc", "foo.swift", "-o", "a.out"]).moduleName, "a")
428+
429+
// This is silly, but necesary for compatibility with the integrated driver.
430+
XCTAssertEqual(try Driver(args: ["swiftc", "foo.swift", "-o", "a.out.optimized"]).moduleName, "main")
431+
432+
XCTAssertEqual(try Driver(args: ["swiftc", "foo.swift", "-o", "a.out.optimized", "-module-name", "bar"]).moduleName, "bar")
433+
XCTAssertEqual(try Driver(args: ["swiftc", "foo.swift", "-o", "+++.out"]).moduleName, "main")
434+
XCTAssertEqual(try Driver(args: ["swift"]).moduleName, "REPL")
435+
XCTAssertEqual(try Driver(args: ["swiftc", "foo.swift", "-emit-library", "-o", "libBaz.dylib"]).moduleName, "Baz")
436+
}
437+
425438
func testOutputFileMapLoading() throws {
426439
let contents = """
427440
{

0 commit comments

Comments
 (0)