Skip to content

Commit 3e794c0

Browse files
authored
Merge pull request #1223 from artemcm/DepScanClangOutputPath
Adapt to dependency scanner outputting canonical Clang PCM output paths
2 parents 680581c + ee6fa00 commit 3e794c0

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,19 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
232232
let moduleMapPath = moduleDetails.moduleMapPath.path
233233
let modulePCMPath = moduleInfo.modulePath
234234
outputs.append(TypedVirtualPath(file: modulePCMPath.path, type: .pcm))
235-
commandLine.appendFlags("-emit-pcm", "-module-name", moduleId.moduleName,
236-
"-o", modulePCMPath.path.description)
235+
236+
// TODO: Remove this once toolchain is updated
237+
// If the dependency scanner did not append its own "-o", add it here.
238+
// This is temporary and is meant to handle both: the scanner that
239+
// appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
240+
// that appends '-o' always.
241+
let outputFlagIndeces = commandLine.enumerated().compactMap { $1 == .flag("-o") ? $0 : nil }
242+
// One '-o' is expected as an `-Xcc` flag.
243+
if outputFlagIndeces.count <= 1 {
244+
commandLine.appendFlags("-o", modulePCMPath.path.description)
245+
}
237246

247+
// TODO: Remove this once toolchain is updated
238248
// Fixup "-o -Xcc '<replace-me>'"
239249
if let outputIndex = commandLine.firstIndex(of: .flag("<replace-me>")) {
240250
commandLine[outputIndex] = .path(VirtualPath.lookup(modulePCMPath.path))

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,14 @@ extension Driver {
697697
}
698698
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
699699
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
700-
} else if case .clang(let clangDetails) = moduleInfo.details {
701-
let contextHash = clangDetails.contextHash
702-
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
703-
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
700+
}
701+
// TODO: Remove this once toolchain is updated
702+
else if case .clang(let clangDetails) = moduleInfo.details {
703+
if !moduleInfo.modulePath.path.description.contains(clangDetails.contextHash) {
704+
let contextHash = clangDetails.contextHash
705+
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
706+
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
707+
}
704708
}
705709
}
706710
}
@@ -711,17 +715,28 @@ extension Driver {
711715
throws {
712716
for (moduleId, moduleInfo) in dependencyGraph.modules {
713717
// Output path on the main module is determined by the invocation arguments.
714-
if case .swift(let name) = moduleId,
715-
name == dependencyGraph.mainModuleName {
716-
continue
718+
if case .swift(let name) = moduleId {
719+
if name == dependencyGraph.mainModuleName {
720+
continue
721+
}
722+
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
723+
// Use VirtualPath to get the OS-specific path separators right.
724+
let modulePathInCache =
725+
try VirtualPath(path: moduleCachePath)
726+
.appending(component: modulePath.basename)
727+
dependencyGraph.modules[moduleId]!.modulePath =
728+
TextualVirtualPath(path: modulePathInCache.intern())
729+
}
730+
// TODO: Remove this once toolchain is updated
731+
else if case .clang(_) = moduleId {
732+
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
733+
// Use VirtualPath to get the OS-specific path separators right.
734+
let modulePathInCache =
735+
try VirtualPath(path: moduleCachePath)
736+
.appending(component: modulePath.basename)
737+
dependencyGraph.modules[moduleId]!.modulePath =
738+
TextualVirtualPath(path: modulePathInCache.intern())
717739
}
718-
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
719-
// Use VirtualPath to get the OS-specific path separators right.
720-
let modulePathInCache =
721-
try VirtualPath(path: moduleCachePath)
722-
.appending(component: modulePath.basename)
723-
dependencyGraph.modules[moduleId]!.modulePath =
724-
TextualVirtualPath(path: modulePathInCache.intern())
725740
}
726741
}
727742

0 commit comments

Comments
 (0)