Skip to content

[DNM] Use normalized paths when emitting a module trace. #29967

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ static void computeSwiftModuleTraceInfo(
path::replace_extension(modPath, swiftInterfaceExt);
};

for (auto &depPath : depTracker.getDependencies()) {
SmallString<256> normalizedDepPathScratch;

for (auto &nonNormalizedDepPath : depTracker.getDependencies()) {
normalizedDepPathScratch.clear();
llvm::sys::path::native(nonNormalizedDepPath, normalizedDepPathScratch);
StringRef depPath = normalizedDepPathScratch.str();

// Decide if this is a swiftmodule based on the extension of the raw
// dependency path, as the true file may have a different one.
Expand Down Expand Up @@ -412,6 +417,9 @@ static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
for (std::pair<ModuleDecl::AccessPathTy, ModuleDecl *> &import : imports)
importedModules.insert(import.second);

SmallString<256> scratch;
std::vector<SmallString<256>> normalizedPathStorage;

llvm::DenseMap<StringRef, ModuleDecl *> pathToModuleDecl;
for (auto &module : ctxt.LoadedModules) {
ModuleDecl *loadedDecl = module.second;
Expand All @@ -424,8 +432,12 @@ static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
"Don't know how to handle modules with empty names."
" One potential reason for getting an empty module name might"
" be that the module could not be deserialized correctly.");
pathToModuleDecl.insert(
std::make_pair(loadedDecl->getModuleFilename(), loadedDecl));
// Normalize paths, otherwise we keep running into problems with being
// unable to write cross-platform tests that work on both Posix and Windows.
llvm::sys::path::native(loadedDecl->getModuleFilename(), scratch);
normalizedPathStorage.push_back(scratch);
StringRef path = normalizedPathStorage.back().str();
pathToModuleDecl.insert(std::make_pair(path, loadedDecl));
}

std::vector<SwiftModuleTraceInfo> swiftModules;
Expand Down