Skip to content

Commit 07a35e9

Browse files
[CAS] Workaround the missing file system dependency from clang importer
1 parent 9a3573b commit 07a35e9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ class ClangImporter final : public ClangModuleLoader {
409409
/// Reads the original source file name from PCH.
410410
std::string getOriginalSourceFile(StringRef PCHFilename);
411411

412+
/// Add clang dependency file names.
413+
///
414+
/// \param files The list of file to append dependencies to.
415+
void addClangInvovcationDependencies(std::vector<std::string> &files);
416+
412417
/// Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
413418
/// module map into the replica and emits a PCM file for one of the modules it
414419
/// declares. Delegates to clang for everything except construction of the

lib/AST/ModuleDependencies.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ void SwiftDependencyScanningService::setupCachingDependencyScanningService(
446446
}
447447
}
448448

449+
// Fetch some dependency files from clang importer.
450+
auto clangImporter = static_cast<ClangImporter *>(
451+
Instance.getASTContext().getClangModuleLoader());
452+
clangImporter->addClangInvovcationDependencies(CommonDependencyFiles);
453+
449454
auto CachingFS =
450455
llvm::cas::createCachingOnDiskFileSystem(Instance.getObjectStore());
451456
if (!CachingFS) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,27 @@ std::string ClangImporter::getOriginalSourceFile(StringRef PCHFilename) {
939939
Impl.Instance->getPCHContainerReader(), Impl.Instance->getDiagnostics());
940940
}
941941

942+
void ClangImporter::addClangInvovcationDependencies(
943+
std::vector<std::string> &files) {
944+
auto addFiles = [&files](const auto &F) {
945+
files.insert(files.end(), F.begin(), F.end());
946+
};
947+
auto &invocation = *Impl.Invocation;
948+
// FIXME: Add file dependencies that are not accounted. The long term solution
949+
// is to do a dependency scanning for clang importer and use that directly.
950+
SmallVector<std::string, 4> HeaderMapFileNames;
951+
Impl.Instance->getPreprocessor().getHeaderSearchInfo().getHeaderMapFileNames(
952+
HeaderMapFileNames);
953+
addFiles(HeaderMapFileNames);
954+
addFiles(invocation.getHeaderSearchOpts().VFSOverlayFiles);
955+
// FIXME: Should not depend on working directory. Build system/swift driver
956+
// should not pass working directory here but if that option is passed,
957+
// repect that and add that into CASFS.
958+
auto CWD = invocation.getFileSystemOpts().WorkingDir;
959+
if (!CWD.empty())
960+
files.push_back(CWD);
961+
}
962+
942963
Optional<std::string>
943964
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
944965
StringRef SwiftPCHHash, bool &isExplicit) {

0 commit comments

Comments
 (0)