Skip to content

Commit 8101d69

Browse files
author
David Ungar
authored
Merge pull request #385 from davidungar/allow-for-build-record-to-have-relative-path
[Incremental] Allow build record to reside at a relative path
2 parents 06dbb6f + f25cce8 commit 8101d69

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public struct Driver {
436436
self.buildRecordInfo = BuildRecordInfo(
437437
actualSwiftVersion: self.frontendTargetInfo.compilerVersion,
438438
compilerOutputType: compilerOutputType,
439+
workingDirectory: self.workingDirectory ?? fileSystem.currentWorkingDirectory,
439440
diagnosticEngine: diagnosticEngine,
440441
fileSystem: fileSystem,
441442
moduleOutputInfo: moduleOutputInfo,

Sources/SwiftDriver/Driver/OutputFileMap.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,3 @@ extension String {
246246
return self + "." + ext
247247
}
248248
}
249-
250-
extension VirtualPath {
251-
fileprivate func resolvedRelativePath(base: AbsolutePath) -> VirtualPath {
252-
guard case let .relative(relPath) = self else { return self }
253-
return .absolute(.init(base, relPath))
254-
}
255-
}

Sources/SwiftDriver/Incremental Compilation/BuildRecordInfo.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import SwiftOptions
3030
init?(
3131
actualSwiftVersion: String,
3232
compilerOutputType: FileType?,
33+
workingDirectory: AbsolutePath?,
3334
diagnosticEngine: DiagnosticsEngine,
3435
fileSystem: FileSystem,
3536
moduleOutputInfo: ModuleOutputInfo,
@@ -41,6 +42,7 @@ import SwiftOptions
4142
guard let buildRecordPath = Self.computeBuildRecordPath(
4243
outputFileMap: outputFileMap,
4344
compilerOutputType: compilerOutputType,
45+
workingDirectory: workingDirectory,
4446
diagnosticEngine: diagnosticEngine)
4547
else {
4648
return nil
@@ -80,6 +82,7 @@ import SwiftOptions
8082
private static func computeBuildRecordPath(
8183
outputFileMap: OutputFileMap?,
8284
compilerOutputType: FileType?,
85+
workingDirectory: AbsolutePath?,
8386
diagnosticEngine: DiagnosticsEngine
8487
) -> VirtualPath? {
8588
// FIXME: This should work without an output file map. We should have
@@ -93,7 +96,9 @@ import SwiftOptions
9396
diagnosticEngine.emit(.warning_incremental_requires_build_record_entry)
9497
return nil
9598
}
96-
return partialBuildRecordPath
99+
return workingDirectory
100+
.map(partialBuildRecordPath.resolvedRelativePath(base:))
101+
?? partialBuildRecordPath
97102
}
98103

99104
/// Write out the build record.

Sources/SwiftDriver/Utilities/VirtualPath.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ extension VirtualPath {
346346
}
347347
}
348348

349+
extension VirtualPath {
350+
/// Resolve a relative path into an absolute one, if possible.
351+
public func resolvedRelativePath(base: AbsolutePath) -> VirtualPath {
352+
guard case let .relative(relPath) = self else { return self }
353+
return .absolute(.init(base, relPath))
354+
}
355+
}
356+
349357
private extension String {
350358
func withoutExt(_ ext: String?) -> String {
351359
if let ext = ext {

0 commit comments

Comments
 (0)