Skip to content

NFC: Dependency scanner cherry-picks #6604

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 2 commits into from
Apr 6, 2023
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
25 changes: 4 additions & 21 deletions clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,18 @@ class PrebuiltModuleListener : public ASTReaderListener {
public:
PrebuiltModuleListener(CompilerInstance &CI,
PrebuiltModuleFilesT &PrebuiltModuleFiles,
llvm::StringSet<> &InputFiles, bool VisitInputFiles,
llvm::SmallVector<std::string> &NewModuleFiles)
: CI(CI), PrebuiltModuleFiles(PrebuiltModuleFiles),
InputFiles(InputFiles), VisitInputFiles(VisitInputFiles),

NewModuleFiles(NewModuleFiles) {}

bool needsImportVisitation() const override { return true; }
bool needsInputFileVisitation() override { return VisitInputFiles; }
bool needsSystemInputFileVisitation() override { return VisitInputFiles; }

void visitImport(StringRef ModuleName, StringRef Filename) override {
if (PrebuiltModuleFiles.insert({ModuleName.str(), Filename.str()}).second)
NewModuleFiles.push_back(Filename.str());
}

bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
bool isExplicitModule) override {
InputFiles.insert(Filename);
return true;
}

bool readModuleCacheKey(StringRef ModuleName, StringRef Filename,
StringRef CacheKey) override {
CI.getFrontendOpts().ModuleCacheKeys.emplace_back(std::string(Filename),
Expand All @@ -106,22 +97,17 @@ class PrebuiltModuleListener : public ASTReaderListener {
private:
CompilerInstance &CI;
PrebuiltModuleFilesT &PrebuiltModuleFiles;
llvm::StringSet<> &InputFiles;
bool VisitInputFiles;
llvm::SmallVector<std::string> &NewModuleFiles;
};

/// Visit the given prebuilt module and collect all of the modules it
/// transitively imports and contributing input files.
static void visitPrebuiltModule(StringRef PrebuiltModuleFilename,
CompilerInstance &CI,
PrebuiltModuleFilesT &ModuleFiles,
llvm::StringSet<> &InputFiles,
bool VisitInputFiles) {
PrebuiltModuleFilesT &ModuleFiles) {
// List of module files to be processed.
llvm::SmallVector<std::string> Worklist{PrebuiltModuleFilename.str()};
PrebuiltModuleListener Listener(CI, ModuleFiles, InputFiles, VisitInputFiles,
Worklist);
PrebuiltModuleListener Listener(CI, ModuleFiles, Worklist);

while (!Worklist.empty())
ASTReader::readASTFileControlBlock(
Expand Down Expand Up @@ -375,16 +361,13 @@ class DependencyScanningAction : public tooling::ToolAction {

ScanInstance.createSourceManager(*FileMgr);

llvm::StringSet<> PrebuiltModulesInputFiles;
// Store the list of prebuilt module files into header search options. This
// will prevent the implicit build to create duplicate modules and will
// force reuse of the existing prebuilt module files instead.
if (!ScanInstance.getPreprocessorOpts().ImplicitPCHInclude.empty())
visitPrebuiltModule(
ScanInstance.getPreprocessorOpts().ImplicitPCHInclude, ScanInstance,
ScanInstance.getHeaderSearchOpts().PrebuiltModuleFiles,
PrebuiltModulesInputFiles,
/*VisitInputFiles=*/getDepScanFS() != nullptr);
ScanInstance.getHeaderSearchOpts().PrebuiltModuleFiles);

// Use the dependency scanning optimized file system if requested to do so.
if (DepFS) {
Expand Down
12 changes: 6 additions & 6 deletions clang/test/ClangScanDeps/modules-pch.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

// Scan dependencies of the PCH:
//
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb_pch.json
// RUN: clang-scan-deps -compilation-database %t/cdb_pch.json -format experimental-full \
// RUN: -module-files-dir %t/build > %t/result_pch.json
// RUN: cat %t/result_pch.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-PCH
//
Expand Down Expand Up @@ -94,8 +94,8 @@

// Scan dependencies of the TU:
//
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb_tu.json
// RUN: clang-scan-deps -compilation-database %t/cdb_tu.json -format experimental-full \
// RUN: -module-files-dir %t/build > %t/result_tu.json
// RUN: cat %t/result_tu.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-TU
//
Expand Down Expand Up @@ -142,8 +142,8 @@

// Scan dependencies of the TU that has common modules with the PCH:
//
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb.json
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb_tu_with_common.json
// RUN: clang-scan-deps -compilation-database %t/cdb_tu_with_common.json -format experimental-full \
// RUN: -module-files-dir %t/build > %t/result_tu_with_common.json
// RUN: cat %t/result_tu_with_common.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-TU-WITH-COMMON
//
Expand Down