Skip to content

Commit b6f7956

Browse files
author
David Ungar
authored
Merge pull request #359 from davidungar/incremental-11-6-autolink
Put the output of the (Linux) autolink step in the same place as the .o files
2 parents 07d23c0 + 962f3d0 commit b6f7956

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ extension Driver {
2121
}
2222

2323
mutating func autolinkExtractJob(inputs: [TypedVirtualPath]) throws -> Job? {
24-
guard inputs.count > 0 && isAutolinkExtractJobNeeded else {
24+
guard let firstInput = inputs.first, isAutolinkExtractJobNeeded else {
2525
return nil
2626
}
2727

2828
var commandLine = [Job.ArgTemplate]()
29-
let output = VirtualPath.temporary(RelativePath("\(moduleOutputInfo.name).autolink"))
29+
// Put output in same place as first .o, following legacy driver.
30+
// (See `constructInvocation(const AutolinkExtractJobAction` in `UnixToolChains.cpp`.)
31+
let outputBasename = "\(moduleOutputInfo.name).autolink"
32+
let dir = firstInput.file.parentDirectory
33+
// Go through a bit of extra rigmarole to keep the "./" out of the name for
34+
// the sake of the tests.
35+
let output: VirtualPath = dir == .temporary(RelativePath("."))
36+
? .temporary(RelativePath(outputBasename))
37+
: dir.appending(component: outputBasename)
3038

3139
commandLine.append(contentsOf: inputs.map { .path($0.file) })
3240
commandLine.appendFlag(.o)

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,18 @@ final class NonincrementalCompilationTests: XCTestCase {
190190

191191
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: file2 )]!.status,
192192
.needsCascadingBuild)
193-
XCTAssert(try! isCloseEnough(buildRecord.inputInfos[VirtualPath(path: file2 )]!
194-
.previousModTime.legacyDriverSecsAndNanos,
195-
[1570318778, 0]))
196-
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: gazorp)]!.status,
193+
XCTAssert(try! isCloseEnough(
194+
XCTUnwrap(buildRecord.inputInfos[VirtualPath(path: file2 )])
195+
.previousModTime.legacyDriverSecsAndNanos,
196+
[1570318778, 0]))
197+
XCTAssertEqual(try! XCTUnwrap(buildRecord.inputInfos[VirtualPath(path: gazorp)]).status,
197198
.needsNonCascadingBuild)
198-
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: gazorp)]!
199+
XCTAssertEqual(try! XCTUnwrap(buildRecord.inputInfos[VirtualPath(path: gazorp)])
199200
.previousModTime.legacyDriverSecsAndNanos,
200201
[0, 0])
201-
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: main )]!.status,
202+
XCTAssertEqual(try! XCTUnwrap(buildRecord.inputInfos[VirtualPath(path: main )]).status,
202203
.upToDate)
203-
XCTAssert(try! isCloseEnough( buildRecord.inputInfos[VirtualPath(path: main )]!
204+
XCTAssert(try! isCloseEnough( XCTUnwrap(buildRecord.inputInfos[VirtualPath(path: main )])
204205
.previousModTime.legacyDriverSecsAndNanos,
205206
[1570083660, 0]))
206207

@@ -488,13 +489,13 @@ final class IncrementalCompilationTests: XCTestCase {
488489

489490
func touch(_ name: String) {
490491
print("*** touching \(name) ***", to: &stderrStream); stderrStream.flush()
491-
let (path, contents) = inputPathsAndContents.filter {$0.0.pathString.contains(name)}.first!
492+
let (path, contents) = try! XCTUnwrap(inputPathsAndContents.filter {$0.0.pathString.contains(name)}.first)
492493
try! localFileSystem.writeFileContents(path) { $0 <<< contents }
493494
}
494495

495496
private func replace(contentsOf name: String, with replacement: String ) {
496497
print("*** replacing \(name) ***", to: &stderrStream); stderrStream.flush()
497-
let path = inputPathsAndContents.filter {$0.0.pathString.contains("/" + name + ".swift")}.first!.0
498+
let path = try! XCTUnwrap(inputPathsAndContents.filter {$0.0.pathString.contains("/" + name + ".swift")}.first).0
498499
let previousContents = try! localFileSystem.readFileContents(path).cString
499500
try! localFileSystem.writeFileContents(path) { $0 <<< replacement }
500501
let newContents = try! localFileSystem.readFileContents(path).cString
@@ -545,6 +546,31 @@ final class IncrementalCompilationTests: XCTestCase {
545546
print("", to: &stderrStream); stderrStream.flush()
546547
}
547548

549+
/// Ensure that autolink output file goes with .o directory, to not prevent incremental omission of
550+
/// autolink job.
551+
/// Much of the code below is taking from testLinking(), but uses the output file map code here.
552+
func testAutolinkOutputPath() {
553+
var env = ProcessEnv.vars
554+
env["SWIFT_DRIVER_TESTS_ENABLE_EXEC_PATH_FALLBACK"] = "1"
555+
env["SWIFT_DRIVER_SWIFT_AUTOLINK_EXTRACT_EXEC"] = "/garbage/swift-autolink-extract"
556+
env["SWIFT_DRIVER_DSYMUTIL_EXEC"] = "/garbage/dsymutil"
557+
558+
var driver = try! Driver(
559+
args: args
560+
+ ["-emit-library", "-target", "x86_64-unknown-linux"],
561+
env: env)
562+
let plannedJobs = try! driver.planBuild()
563+
let autolinkExtractJob = try! XCTUnwrap(
564+
plannedJobs
565+
.filter { $0.kind == .autolinkExtract }
566+
.first)
567+
let autoOuts = autolinkExtractJob.outputs.filter {$0.type == .autolink}
568+
XCTAssertEqual(autoOuts.count, 1)
569+
let autoOut = autoOuts[0]
570+
let expected = AbsolutePath(derivedDataPath, "\(module).autolink")
571+
XCTAssertEqual(autoOut.file.absolutePath, expected)
572+
}
573+
548574
private func generateOutputFileMapDict(module: String, inputPaths: [AbsolutePath],
549575
derivedData: AbsolutePath
550576
) -> [String: [String: String]] {

0 commit comments

Comments
 (0)