Skip to content

Commit

Permalink
Merge pull request #230 from owenv/linker-inputs
Browse files Browse the repository at this point in the history
Fixup linker input handling and use -add_ast_path when needed
  • Loading branch information
owenv committed Aug 30, 2020
2 parents 0fe1d84 + 0368510 commit 3ea9371
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Expand Up @@ -303,7 +303,16 @@ extension DarwinToolchain {
}

// Add inputs.
commandLine.append(contentsOf: inputs.map { .path($0.file) })
commandLine.append(contentsOf: inputs.flatMap {
(path: TypedVirtualPath) -> [Job.ArgTemplate] in
if path.type == .swiftModule {
return [.flag("-add_ast_path"), .path(path.file)]
} else if path.type == .object {
return [.path(path.file)]
} else {
return []
}
})

// Add the output
commandLine.appendFlag("-o")
Expand Down
Expand Up @@ -158,12 +158,15 @@ extension GenericUnixToolchain {
)
commandLine.appendPath(swiftrtPath)

let inputFiles: [Job.ArgTemplate] = inputs.map { input in
let inputFiles: [Job.ArgTemplate] = inputs.compactMap { input in
// Autolink inputs are handled specially
if input.type == .autolink {
return .responseFilePath(input.file)
} else if input.type == .object {
return .path(input.file)
} else {
return nil
}
return .path(input.file)
}
commandLine.append(contentsOf: inputFiles)

Expand Down
24 changes: 24 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Expand Up @@ -839,6 +839,30 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertFalse(cmd.contains(.flag("-shared")))
}

#if os(macOS)
// dsymutil won't be found on Linux.
do {
var driver = try Driver(args: commonArgs + ["-emit-executable", "-emit-module", "-g", "-target", "x86_64-apple-macosx10.15"], env: env)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(5, plannedJobs.count)
XCTAssertEqual(plannedJobs.map(\.kind), [.compile, .compile, .mergeModule, .link, .generateDSYM])

let linkJob = plannedJobs[3]
XCTAssertEqual(linkJob.kind, .link)

let cmd = linkJob.commandLine
XCTAssertTrue(cmd.contains(.flag("-o")))
XCTAssertTrue(cmd.contains(.path(.temporary(RelativePath("foo.o")))))
XCTAssertTrue(cmd.contains(.path(.temporary(RelativePath("bar.o")))))
XCTAssertTrue(cmd.contains(subsequence: [.flag("-add_ast_path"), .path(.relative(.init("Test.swiftmodule")))]))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "Test"))

XCTAssertFalse(cmd.contains(.flag("-static")))
XCTAssertFalse(cmd.contains(.flag("-dylib")))
XCTAssertFalse(cmd.contains(.flag("-shared")))
}
#endif

// FIXME: This test will fail when run on macOS, because
// swift-autolink-extract is not present
#if os(Linux)
Expand Down

0 comments on commit 3ea9371

Please sign in to comment.