class DiagnosticsEngine;
class HeaderSearch;
class ModuleMapParser;
+
+/// \brief A mechanism to observe the actions of the module map parser as it
+/// reads module map files.
+class ModuleMapCallbacks {
+public:
+ virtual ~ModuleMapCallbacks() {}
+
+ /// \brief Called when a module map file has been read.
+ ///
+ /// \param FileStart A SourceLocation referring to the start of the file's
+ /// contents.
+ /// \param File The file itself.
+ /// \param IsSystem Whether this is a module map from a system include path.
+ virtual void moduleMapFileRead(SourceLocation FileStart,
+ const FileEntry &File, bool IsSystem) {}
+};
class ModuleMap {
SourceManager &SourceMgr;
const LangOptions &LangOpts;
const TargetInfo *Target;
HeaderSearch &HeaderInfo;
+
+ llvm::SmallVector<std::unique_ptr<ModuleMapCallbacks>, 1> Callbacks;
/// \brief The directory used for Clang-supplied, builtin include headers,
/// such as "stdint.h".
BuiltinIncludeDir = Dir;
}
+ /// \brief Add a module map callback.
+ void addModuleMapCallbacks(std::unique_ptr<ModuleMapCallbacks> Callback) {
+ Callbacks.push_back(std::move(Callback));
+ }
+
/// \brief Retrieve the module that owns the given header file, if any.
///
/// \param File The header file that is likely to be included.
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Lex/DirectoryLookup.h"
#include "clang/Lex/LexDiagnostic.h"
+#include "clang/Lex/ModuleMap.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Serialization/ASTReader.h"
}
};
+struct DepCollectorMMCallbacks : public ModuleMapCallbacks {
+ DependencyCollector &DepCollector;
+ DepCollectorMMCallbacks(DependencyCollector &DC) : DepCollector(DC) {}
+
+ void moduleMapFileRead(SourceLocation Loc, const FileEntry &Entry,
+ bool IsSystem) override {
+ StringRef Filename = Entry.getName();
+ DepCollector.maybeAddDependency(Filename, /*FromModule*/false,
+ /*IsSystem*/IsSystem,
+ /*IsModuleFile*/false,
+ /*IsMissing*/false);
+ }
+};
+
struct DepCollectorASTListener : public ASTReaderListener {
DependencyCollector &DepCollector;
DepCollectorASTListener(DependencyCollector &L) : DepCollector(L) { }
void DependencyCollector::attachToPreprocessor(Preprocessor &PP) {
PP.addPPCallbacks(
llvm::make_unique<DepCollectorPPCallbacks>(*this, PP.getSourceManager()));
+ PP.getHeaderSearchInfo().getModuleMap().addModuleMapCallbacks(
+ llvm::make_unique<DepCollectorMMCallbacks>(*this));
}
void DependencyCollector::attachToASTReader(ASTReader &R) {
R.addListener(llvm::make_unique<DepCollectorASTListener>(*this));
bool includeModuleFiles() const { return IncludeModuleFiles; }
};
+class DFGMMCallback : public ModuleMapCallbacks {
+ DFGImpl &Parent;
+public:
+ DFGMMCallback(DFGImpl &Parent) : Parent(Parent) {}
+ void moduleMapFileRead(SourceLocation Loc, const FileEntry &Entry,
+ bool IsSystem) override {
+ if (!IsSystem || Parent.includeSystemHeaders())
+ Parent.AddFilename(Entry.getName());
+ }
+};
+
class DFGASTReaderListener : public ASTReaderListener {
DFGImpl &Parent;
public:
DFGImpl *Callback = new DFGImpl(&PP, Opts);
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callback));
+ PP.getHeaderSearchInfo().getModuleMap().addModuleMapCallbacks(
+ llvm::make_unique<DFGMMCallback>(*Callback));
return new DependencyFileGenerator(Callback);
}
// Parse this module map file.
Lexer L(ID, SourceMgr.getBuffer(ID), SourceMgr, MMapLangOpts);
+ SourceLocation Start = L.getSourceLocation();
ModuleMapParser Parser(L, SourceMgr, Target, Diags, *this, File, Dir,
BuiltinIncludeDir, IsSystem);
bool Result = Parser.parseModuleMapFile();
ParsedModuleMap[File] = Result;
+
+ // Notify callbacks that we parsed it.
+ for (const auto &Cb : Callbacks)
+ Cb->moduleMapFileRead(Start, *File, IsSystem);
return Result;
}
// RUN: FileCheck %s < %t.d
// CHECK: dependency-gen-pch.m.o
// CHECK-NEXT: dependency-gen-pch.m
+// CHECK-NEXT: Inputs{{.}}module.map
// CHECK-NEXT: diamond_top.pcm
// CHECK-NEXT: Inputs{{.}}diamond_top.h
-// CHECK-NEXT: Inputs{{.}}module.map
#import "diamond_top.h"
// RUN: %clang_cc1 -x objective-c -isystem %S/Inputs/System/usr/include -dependency-file %t.d.1 -MT %s.o -I %S/Inputs -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t-mcp %s
// RUN: FileCheck %s < %t.d.1
// CHECK: dependency-gen.m
-// CHECK: Inputs{{.}}diamond_top.h
// CHECK: Inputs{{.}}module.map
+// CHECK: Inputs{{.}}diamond_top.h
// CHECK-NOT: usr{{.}}include{{.}}module.map
// CHECK-NOT: stdint.h
// RUN: %clang_cc1 -x objective-c -isystem %S/Inputs/System/usr/include -dependency-file %t.d.2 -MT %s.o -I %S/Inputs -sys-header-deps -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t-mcp %s
// RUN: FileCheck %s -check-prefix=CHECK-SYS < %t.d.2
// CHECK-SYS: dependency-gen.m
-// CHECK-SYS: Inputs{{.}}diamond_top.h
// CHECK-SYS: Inputs{{.}}module.map
+// CHECK-SYS: Inputs{{.}}diamond_top.h
// CHECK-SYS: usr{{.}}include{{.}}module.map
// CHECK-SYS: stdint.h
extern module "test-base2" "Inputs/dependency-gen-base2.modulemap"
extern module "test-base" "Inputs/dependency-gen-base.modulemap"
-// CHECK: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-included2.h
-// CHECK: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-base.modulemap
+// CHECK-DAG: {{[/\\]}}dependency-gen.modulemap
+// CHECK-DAG: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-base.modulemap
+// CHECK-DAG: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-base2.modulemap
+
+// CHECK-DAG: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen.h
+// CHECK-DAG: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-included.h
+// CHECK-DAG: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-included2.h
#include "Inputs/relative-dep-gen-1.h"
-// CHECK-BUILD: mod.pcm: Inputs/relative-dep-gen-1.h Inputs/relative-dep-gen-2.h
-// CHECK-USE: use.o: relative-dep-gen.cpp Inputs/relative-dep-gen-1.h
+// CHECK-BUILD: mod.pcm:
+// CHECK-BUILD: Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
+// CHECK-BUILD: Inputs/relative-dep-gen-1.h
+// CHECK-BUILD: Inputs/relative-dep-gen-2.h
+// CHECK-USE: use.o:
+// CHECK-USE: Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
+// CHECK-USE: relative-dep-gen.cpp
+// CHECK-USE: Inputs/relative-dep-gen-1.h