Skip to content

Commit f02904c

Browse files
committed
Infer object format when it can't be determined from a triple's successfully parsed environment
1 parent f92010d commit f02904c

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

Sources/SwiftDriver/Utilities/Triple.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public struct Triple {
167167
if let parsedEnv = parsedEnv {
168168
self.environment = parsedEnv.value.environment
169169
self.objectFormat = parsedEnv.value.objectFormat
170+
?? ObjectFormat.infer(arch: parsedArch?.value.arch,
171+
os: parsedOS?.value)
170172
}
171173
else {
172174
self.environment = Environment.infer(archName: parsedArch?.substring)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,52 +1310,49 @@ final class SwiftDriverTests: XCTestCase {
13101310
}
13111311

13121312
func testModuleWrapJob() throws {
1313+
// FIXME: These tests will fail when run on macOS, because
1314+
// swift-autolink-extract is not present
1315+
#if os(Linux)
13131316
do {
13141317
var driver = try Driver(args: ["swiftc", "-target", "x86_64-unknown-linux-gnu", "-g", "foo.swift"])
13151318
let plannedJobs = try driver.planBuild()
1316-
XCTAssertEqual(plannedJobs.count, 4)
1317-
// FIXME: There should also be an autolink-extract job. It looks like our
1318-
// triple parsing code is not detecting the object file format correctly.
1319-
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .mergeModule, .moduleWrap, .link])
1320-
XCTAssertEqual(plannedJobs[2].inputs.count, 1)
1321-
XCTAssertEqual(plannedJobs[2].inputs.count, 1)
1322-
XCTAssertTrue(plannedJobs[2].commandLine.contains(subsequence: ["-target", "x86_64-unknown-linux-gnu"]))
1323-
XCTAssertTrue(plannedJobs[1].outputs.contains(plannedJobs[2].inputs.first!))
1324-
XCTAssertTrue(plannedJobs[3].inputs.contains(plannedJobs[2].outputs.first!))
1325-
}
1326-
1327-
// dsymutil won't be found on other platforms
1328-
#if os(macOS)
1329-
do {
1330-
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-macosx10.15", "-g", "foo.swift"])
1331-
let plannedJobs = try driver.planBuild()
1332-
XCTAssertEqual(plannedJobs.count, 4)
1333-
// No module wrapping with Mach-O.
1334-
// FIXME: There should also be an autolink-extract job. It looks like our
1335-
// triple parsing code is not detecting the object file format correctly.
1336-
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .mergeModule, .link, .generateDSYM])
1319+
XCTAssertEqual(plannedJobs.count, 5)
1320+
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .autolinkExtract, .mergeModule, .moduleWrap, .link])
1321+
XCTAssertEqual(plannedJobs[3].inputs.count, 1)
1322+
XCTAssertEqual(plannedJobs[3].inputs.count, 1)
1323+
XCTAssertTrue(plannedJobs[3].commandLine.contains(subsequence: ["-target", "x86_64-unknown-linux-gnu"]))
1324+
XCTAssertTrue(plannedJobs[2].outputs.contains(plannedJobs[3].inputs.first!))
1325+
XCTAssertTrue(plannedJobs[4].inputs.contains(plannedJobs[3].outputs.first!))
13371326
}
1338-
#endif
13391327

13401328
do {
13411329
var driver = try Driver(args: ["swiftc", "-target", "x86_64-unknown-linux-gnu", "foo.swift"])
13421330
let plannedJobs = try driver.planBuild()
1343-
XCTAssertEqual(plannedJobs.count, 2)
1331+
XCTAssertEqual(plannedJobs.count, 3)
13441332
// No merge module/module wrap jobs.
1345-
// FIXME: There should also be an autolink-extract job. It looks like our
1346-
// triple parsing code is not detecting the object file format correctly.
1347-
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .link])
1333+
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .autolinkExtract, .link])
13481334
}
13491335

13501336
do {
13511337
var driver = try Driver(args: ["swiftc", "-target", "x86_64-unknown-linux-gnu", "-gdwarf-types", "foo.swift"])
13521338
let plannedJobs = try driver.planBuild()
1353-
XCTAssertEqual(plannedJobs.count, 3)
1339+
XCTAssertEqual(plannedJobs.count, 4)
13541340
// Merge module, but no module wrapping.
1341+
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .autolinkExtract, .mergeModule, .link])
1342+
}
1343+
#endif
1344+
// dsymutil won't be found on other platforms
1345+
#if os(macOS)
1346+
do {
1347+
var driver = try Driver(args: ["swiftc", "-target", "x86_64-apple-macosx10.15", "-g", "foo.swift"])
1348+
let plannedJobs = try driver.planBuild()
1349+
XCTAssertEqual(plannedJobs.count, 4)
1350+
// No module wrapping with Mach-O.
13551351
// FIXME: There should also be an autolink-extract job. It looks like our
13561352
// triple parsing code is not detecting the object file format correctly.
1357-
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .mergeModule, .link])
1353+
XCTAssertEqual(plannedJobs.map { $0.kind }, [.compile, .mergeModule, .link, .generateDSYM])
13581354
}
1355+
#endif
13591356
}
13601357

13611358
func testRepl() throws {

Tests/SwiftDriverTests/TripleTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,9 @@ final class TripleTests: XCTestCase {
933933
}
934934

935935
func testFileFormat() {
936-
// XCTAssertEqual(.elf, Triple("i686-unknown-linux-gnu").objectFormat)
936+
XCTAssertEqual(.elf, Triple("i686-unknown-linux-gnu").objectFormat)
937+
XCTAssertEqual(.elf, Triple("x86_64-unknown-linux-gnu").objectFormat)
938+
XCTAssertEqual(.elf, Triple("x86_64-gnu-linux").objectFormat)
937939
XCTAssertEqual(.elf, Triple("i686-unknown-freebsd").objectFormat)
938940
XCTAssertEqual(.elf, Triple("i686-unknown-netbsd").objectFormat)
939941
XCTAssertEqual(.elf, Triple("i686--win32-elf").objectFormat)

0 commit comments

Comments
 (0)