Skip to content

Adapt to dependency scanner outputting canonical Clang PCM output paths #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,19 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
let moduleMapPath = moduleDetails.moduleMapPath.path
let modulePCMPath = moduleInfo.modulePath
outputs.append(TypedVirtualPath(file: modulePCMPath.path, type: .pcm))
commandLine.appendFlags("-emit-pcm", "-module-name", moduleId.moduleName,
"-o", modulePCMPath.path.description)

// TODO: Remove this once toolchain is updated
// If the dependency scanner did not append its own "-o", add it here.
// This is temporary and is meant to handle both: the scanner that
// appends '-o' and one that doesn't, until we have a toolchain snapshot with the scanner
// that appends '-o' always.
let outputFlagIndeces = commandLine.enumerated().compactMap { $1 == .flag("-o") ? $0 : nil }
// One '-o' is expected as an `-Xcc` flag.
if outputFlagIndeces.count <= 1 {
commandLine.appendFlags("-o", modulePCMPath.path.description)
}

// TODO: Remove this once toolchain is updated
// Fixup "-o -Xcc '<replace-me>'"
if let outputIndex = commandLine.firstIndex(of: .flag("<replace-me>")) {
commandLine[outputIndex] = .path(VirtualPath.lookup(modulePCMPath.path))
Expand Down
43 changes: 29 additions & 14 deletions Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,14 @@ extension Driver {
}
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
} else if case .clang(let clangDetails) = moduleInfo.details {
let contextHash = clangDetails.contextHash
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
}
// TODO: Remove this once toolchain is updated
else if case .clang(let clangDetails) = moduleInfo.details {
if !moduleInfo.modulePath.path.description.contains(clangDetails.contextHash) {
let contextHash = clangDetails.contextHash
let updatedPath = plainPath.parentDirectory.appending(component: "\(plainPath.basenameWithoutExt)-\(contextHash).\(plainPath.extension!)")
dependencyGraph.modules[moduleId]!.modulePath = TextualVirtualPath(path: updatedPath.intern())
}
}
}
}
Expand All @@ -711,17 +715,28 @@ extension Driver {
throws {
for (moduleId, moduleInfo) in dependencyGraph.modules {
// Output path on the main module is determined by the invocation arguments.
if case .swift(let name) = moduleId,
name == dependencyGraph.mainModuleName {
continue
if case .swift(let name) = moduleId {
if name == dependencyGraph.mainModuleName {
continue
}
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
// Use VirtualPath to get the OS-specific path separators right.
let modulePathInCache =
try VirtualPath(path: moduleCachePath)
.appending(component: modulePath.basename)
dependencyGraph.modules[moduleId]!.modulePath =
TextualVirtualPath(path: modulePathInCache.intern())
}
// TODO: Remove this once toolchain is updated
else if case .clang(_) = moduleId {
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
// Use VirtualPath to get the OS-specific path separators right.
let modulePathInCache =
try VirtualPath(path: moduleCachePath)
.appending(component: modulePath.basename)
dependencyGraph.modules[moduleId]!.modulePath =
TextualVirtualPath(path: modulePathInCache.intern())
}
let modulePath = VirtualPath.lookup(moduleInfo.modulePath.path)
// Use VirtualPath to get the OS-specific path separators right.
let modulePathInCache =
try VirtualPath(path: moduleCachePath)
.appending(component: modulePath.basename)
dependencyGraph.modules[moduleId]!.modulePath =
TextualVirtualPath(path: modulePathInCache.intern())
}
}

Expand Down