17 #include "llvm/ADT/iterator_range.h" 18 #include "llvm/Config/llvm-config.h" 19 #include "llvm/Support/FileSystem.h" 20 #include "llvm/Support/Path.h" 21 #include "llvm/Support/raw_ostream.h" 23 using namespace clang;
31 : Collector(Collector) {}
32 bool needsInputFileVisitation()
override {
return true; }
33 bool needsSystemInputFileVisitation()
override {
return true; }
34 bool visitInputFile(StringRef
Filename,
bool IsSystem,
bool IsOverridden,
35 bool IsExplicitModule)
override {
41 struct ModuleDependencyPPCallbacks :
public PPCallbacks {
46 : Collector(Collector), SM(SM) {}
49 StringRef FileName,
bool IsAngled,
51 StringRef SearchPath, StringRef RelativePath,
63 : Collector(Collector) {}
65 void moduleMapAddHeader(StringRef HeaderPath)
override {
66 if (llvm::sys::path::is_absolute(HeaderPath))
69 void moduleMapAddUmbrellaHeader(
FileManager *FileMgr,
71 StringRef HeaderFilename = Header->
getName();
72 moduleMapAddHeader(HeaderFilename);
86 StringRef UmbreallDirFromHeader =
87 llvm::sys::path::parent_path(HeaderFilename);
89 if (!UmbrellaDir.equals(UmbreallDirFromHeader)) {
91 llvm::sys::path::append(AltHeaderFilename, UmbrellaDir,
92 llvm::sys::path::filename(HeaderFilename));
93 if (FileMgr->
getFile(AltHeaderFilename))
94 moduleMapAddHeader(AltHeaderFilename);
102 R.
addListener(std::make_unique<ModuleDependencyListener>(*
this));
109 std::make_unique<ModuleDependencyMMCallbacks>(*
this));
115 if (llvm::sys::fs::real_path(Path, TmpDest))
125 if (!llvm::sys::fs::real_path(UpperDest, RealDest) && Path.equals(RealDest))
134 StringRef VFSDir = getDest();
138 VFSWriter.setOverlayDir(VFSDir);
146 VFSWriter.setUseExternalNames(
false);
150 llvm::sys::path::append(YAMLPath,
"vfs.yaml");
151 llvm::raw_fd_ostream OS(YAMLPath, EC, llvm::sys::fs::OF_Text);
159 bool ModuleDependencyCollector::getRealPath(StringRef SrcPath,
163 StringRef FileName = path::filename(SrcPath);
164 std::string Dir = path::parent_path(SrcPath).str();
165 auto DirWithSymLink = SymLinkMap.find(Dir);
170 if (DirWithSymLink == SymLinkMap.end()) {
171 if (llvm::sys::fs::real_path(Dir, RealPath))
173 SymLinkMap[Dir] = RealPath.str();
175 RealPath = DirWithSymLink->second;
178 path::append(RealPath, FileName);
179 Result.swap(RealPath);
183 std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src,
189 fs::make_absolute(AbsoluteSrc);
191 path::native(AbsoluteSrc);
193 AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
197 path::remove_dots(VirtualPath,
true);
203 if (!getRealPath(AbsoluteSrc, CopyFrom))
204 CopyFrom = VirtualPath;
210 path::append(CacheDst, path::relative_path(CopyFrom));
214 if (!fs::exists(Dst))
215 return std::error_code();
216 path::append(CacheDst, Dst);
221 if (std::error_code EC = fs::create_directories(path::parent_path(CacheDst),
224 if (std::error_code EC = fs::copy_file(CopyFrom, CacheDst))
232 addFileMapping(VirtualPath, CacheDst);
233 return std::error_code();
237 if (insertSeen(Filename))
238 if (copyToRoot(Filename, FileDst))
Implements support for file system lookup, file system caching, and directory search management...
void attachToASTReader(ASTReader &R) override
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Token - This structure provides full information about a lexed token.
Describes a module or submodule.
HeaderSearch & getHeaderSearchInfo() const
void attachToPreprocessor(Preprocessor &PP) override
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
Represents a character-granular source range.
Defines the clang::Preprocessor interface.
A mechanism to observe the actions of the module map parser as it reads module map files...
Record the location of an inclusion directive, such as an #include or #import statement.
Collects the dependencies for imported modules into a directory.
The result type of a method or function.
SourceManager & getSourceManager() const
const DirectoryEntry * getDir() const
Return the directory the file lives in.
virtual void writeFileMap()
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
Encodes a location in the source.
StringRef getName() const
Cached information about one file (either on disk or in the virtual file system). ...
virtual void addFile(StringRef Filename, StringRef FileDst={})
Dataflow Directional Tag Classes.
static bool isCaseSensitivePath(StringRef Path)
Reads an AST files chain containing the contents of a translation unit.
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Abstract interface for callback invocations by the ASTReader.
LLVM_READONLY char toUppercase(char c)
Converts the given ASCII character to its uppercase equivalent.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
StringRef getName() const