18 #include "llvm/ADT/iterator_range.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) {}
51 StringRef SearchPath, StringRef RelativePath,
52 const Module *Imported)
override {
55 Collector.addFile(File->
getName());
62 : Collector(Collector) {}
64 void moduleMapAddHeader(StringRef HeaderPath)
override {
65 if (llvm::sys::path::is_absolute(HeaderPath))
68 void moduleMapAddUmbrellaHeader(
FileManager *FileMgr,
70 StringRef HeaderFilename = Header->
getName();
71 moduleMapAddHeader(HeaderFilename);
85 StringRef UmbreallDirFromHeader =
86 llvm::sys::path::parent_path(HeaderFilename);
88 if (!UmbrellaDir.equals(UmbreallDirFromHeader)) {
90 llvm::sys::path::append(AltHeaderFilename, UmbrellaDir,
91 llvm::sys::path::filename(HeaderFilename));
92 if (FileMgr->
getFile(AltHeaderFilename))
93 moduleMapAddHeader(AltHeaderFilename);
103 char CanonicalPath[PATH_MAX];
106 if (!realpath(SrcPath.str().c_str(), CanonicalPath))
110 RealPath.swap(RPath);
119 R.
addListener(llvm::make_unique<ModuleDependencyListener>(*
this));
126 llvm::make_unique<ModuleDependencyMMCallbacks>(*
this));
142 if (
real_path(UpperDest, RealDest) && Path.equals(RealDest))
171 llvm::sys::path::append(YAMLPath,
"vfs.yaml");
172 llvm::raw_fd_ostream OS(YAMLPath, EC, llvm::sys::fs::F_Text);
180 bool ModuleDependencyCollector::getRealPath(StringRef SrcPath,
182 using namespace llvm::sys;
184 StringRef FileName = path::filename(SrcPath);
185 std::string Dir = path::parent_path(SrcPath).str();
186 auto DirWithSymLink = SymLinkMap.find(Dir);
191 if (DirWithSymLink == SymLinkMap.end()) {
194 SymLinkMap[Dir] = RealPath.str();
196 RealPath = DirWithSymLink->second;
199 path::append(RealPath, FileName);
200 Result.swap(RealPath);
204 std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src,
206 using namespace llvm::sys;
210 fs::make_absolute(AbsoluteSrc);
212 path::native(AbsoluteSrc);
214 AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
218 path::remove_dots(VirtualPath,
true);
224 if (!getRealPath(AbsoluteSrc, CopyFrom))
225 CopyFrom = VirtualPath;
231 path::append(CacheDst, path::relative_path(CopyFrom));
235 if (!fs::exists(Dst))
236 return std::error_code();
237 path::append(CacheDst, Dst);
242 if (std::error_code EC = fs::create_directories(path::parent_path(CacheDst),
245 if (std::error_code EC = fs::copy_file(CopyFrom, CacheDst))
254 return std::error_code();
259 if (copyToRoot(Filename, FileDst))
SourceManager & getSourceManager() const
Implements support for file system lookup, file system caching, and directory search management...
void setOverlayDir(StringRef OverlayDirectory)
void attachToASTReader(ASTReader &R) override
void setIgnoreNonExistentContents(bool IgnoreContents)
This interface provides a way to observe the actions of the preprocessor as it does its thing...
void write(llvm::raw_ostream &OS)
Token - This structure provides full information about a lexed token.
Describes a module or submodule.
HeaderSearch & getHeaderSearchInfo() const
StringRef getName() const
void attachToPreprocessor(Preprocessor &PP) override
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
void addFile(StringRef Filename, StringRef FileDst="")
Represents a character-granular source range.
void addFileMapping(StringRef VPath, StringRef RPath)
Defines the clang::Preprocessor interface.
void setCaseSensitivity(bool CaseSensitive)
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.
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
Encodes a location in the source.
Cached information about one file (either on disk or in the virtual file system). ...
static bool isCaseSensitivePath(StringRef Path)
Reads an AST files chain containing the contents of a translation unit.
StringRef getName() const
Abstract interface for callback invocations by the ASTReader.
void setUseExternalNames(bool UseExtNames)
static LLVM_READONLY char toUppercase(char c)
Converts the given ASCII character to its uppercase equivalent.
const DirectoryEntry * getDir() const
Return the directory the file lives in.
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.
static bool real_path(StringRef SrcPath, SmallVectorImpl< char > &RealPath)
bool insertSeen(StringRef Filename)