[Caching] Create clang importer from cc1 args directly

When caching build is enabled, teach dependency scanner to report
command-lines with `-direct-clang-cc1-module-build` so the later
compilation can instantiate clang importer with cc1 args directly. This
avoids running clang driver code, which might involve file system
lookups, which are the file deps that are not captured and might result
in different compilation mode.

rdar://119275464
This commit is contained in:
Steven Wu
2024-01-22 14:43:52 -08:00
parent 66801fd572
commit cdeef58e0f
13 changed files with 290 additions and 103 deletions

View File

@@ -346,6 +346,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(
{"-Xcc", "-target", "-Xcc", ScanASTContext.LangOpts.Target.str()});
std::string rootID;
std::vector<std::string> buildArgs;
if (tracker) {
tracker->startTracking();
for (auto fileUnit : mainModule->getFiles()) {
@@ -371,10 +372,22 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(
return std::make_error_code(std::errc::io_error);
}
rootID = root->getID().toString();
buildArgs.push_back("-direct-clang-cc1-module-build");
for (auto &arg : clangImporter->getSwiftExplicitModuleDirectCC1Args()) {
buildArgs.push_back("-Xcc");
buildArgs.push_back(arg);
}
}
auto mainDependencies =
ModuleDependencyInfo::forSwiftSourceModule(rootID, {}, {}, ExtraPCMArgs);
llvm::SmallVector<StringRef> buildCommands;
buildCommands.reserve(buildArgs.size());
llvm::for_each(buildArgs, [&](const std::string &arg) {
buildCommands.emplace_back(arg);
});
auto mainDependencies = ModuleDependencyInfo::forSwiftSourceModule(
rootID, buildCommands, {}, ExtraPCMArgs);
llvm::StringSet<> alreadyAddedModules;
// Compute Implicit dependencies of the main module