[Caching] Allow prefix mapping on legacy layout file

To support distributed caching for targets that need to use legacy
layout file, the path of legacy layout needs to be remapped.

Current handling of the legacy layout file is to ingest all layout files
to the CAS FileSystem as part of the compiler resource files. But it
cannot convey remapped legacy layout file path to the swift-frontend
when distributed caching is enabled. In order to properly support path
remapping, the legacy layout file is ingested on demand (thus it doesn't
need to be ingested for module compilation), and the remapped path is
communicated to swift-front via frontend flag.

rdar://162793678
This commit is contained in:
Steven Wu
2025-10-17 10:05:22 -07:00
parent 9120a535f4
commit bd2b3c7aeb
5 changed files with 110 additions and 25 deletions

View File

@@ -452,20 +452,6 @@ SwiftDependencyTracker::SwiftDependencyTracker(
"SDKSettings.json");
addCommonFile(SDKSettingPath);
// Add Legacy layout file.
const std::vector<std::string> AllSupportedArches = {
"arm64", "arm64e", "x86_64", "i386",
"armv7", "armv7s", "armv7k", "arm64_32"};
for (auto RuntimeLibPath : SearchPathOpts.RuntimeLibraryPaths) {
std::error_code EC;
for (auto &Arch : AllSupportedArches) {
SmallString<256> LayoutFile(RuntimeLibPath);
llvm::sys::path::append(LayoutFile, "layouts-" + Arch + ".yaml");
addCommonFile(LayoutFile);
}
}
// Add VFSOverlay file.
for (auto &Overlay: SearchPathOpts.VFSOverlayFiles)
addCommonFile(Overlay);
@@ -488,20 +474,21 @@ void SwiftDependencyTracker::startTracking(bool includeCommonDeps) {
}
}
void SwiftDependencyTracker::trackFile(const Twine &path) {
bool SwiftDependencyTracker::trackFile(const Twine &path) {
auto file = FS->openFileForRead(path);
if (!file)
return;
return false;
auto status = (*file)->status();
if (!status)
return;
return false;
auto CASFile = dyn_cast<llvm::cas::CASBackedFile>(*file);
if (!CASFile)
return;
return false;
auto fileRef = CASFile->getObjectRefForContent();
std::string realPath =
Mapper ? Mapper->mapToString(path.str()) : path.str();
TrackedFiles.try_emplace(realPath, fileRef, (size_t)status->getSize());
return true;
}
llvm::Expected<llvm::cas::ObjectProxy>