18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/ADT/iterator_range.h"
20 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/Path.h"
22 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
32 : Collector(Collector) {}
33 bool needsInputFileVisitation()
override {
return true; }
34 bool needsSystemInputFileVisitation()
override {
return true; }
35 bool visitInputFile(StringRef
Filename,
bool IsSystem,
bool IsOverridden,
36 bool IsExplicitModule)
override {
45 : Collector(Collector) {}
47 void moduleMapAddHeader(StringRef HeaderPath)
override {
48 if (llvm::sys::path::is_absolute(HeaderPath))
51 void moduleMapAddUmbrellaHeader(
FileManager *FileMgr,
53 StringRef HeaderFilename = Header->
getName();
54 moduleMapAddHeader(HeaderFilename);
68 StringRef UmbreallDirFromHeader =
69 llvm::sys::path::parent_path(HeaderFilename);
71 if (!UmbrellaDir.equals(UmbreallDirFromHeader)) {
73 llvm::sys::path::append(AltHeaderFilename, UmbrellaDir,
74 llvm::sys::path::filename(HeaderFilename));
75 if (FileMgr->
getFile(AltHeaderFilename))
76 moduleMapAddHeader(AltHeaderFilename);
86 char CanonicalPath[PATH_MAX];
89 if (!realpath(SrcPath.str().c_str(), CanonicalPath))
102 R.
addListener(llvm::make_unique<ModuleDependencyListener>(*
this));
107 llvm::make_unique<ModuleDependencyMMCallbacks>(*
this));
123 if (
real_path(UpperDest, RealDest) && Path.equals(RealDest))
148 llvm::sys::path::append(YAMLPath,
"vfs.yaml");
149 llvm::raw_fd_ostream OS(YAMLPath, EC, llvm::sys::fs::F_Text);
157 bool ModuleDependencyCollector::getRealPath(StringRef SrcPath,
159 using namespace llvm::sys;
161 StringRef
FileName = path::filename(SrcPath);
162 std::string Dir = path::parent_path(SrcPath).str();
163 auto DirWithSymLink = SymLinkMap.find(Dir);
168 if (DirWithSymLink == SymLinkMap.end()) {
171 SymLinkMap[Dir] = RealPath.str();
173 RealPath = DirWithSymLink->second;
177 Result.swap(RealPath);
181 std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src) {
182 using namespace llvm::sys;
186 fs::make_absolute(AbsoluteSrc);
188 path::native(AbsoluteSrc);
190 AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
194 path::remove_dots(CanonicalPath,
true);
200 if (!getRealPath(AbsoluteSrc, RealPath))
201 RealPath = CanonicalPath;
203 path::append(Dest, path::relative_path(RealPath));
206 if (std::error_code EC = fs::create_directories(path::parent_path(Dest),
209 if (std::error_code EC = fs::copy_file(RealPath, Dest))
218 return std::error_code();
223 if (copyToRoot(Filename))
Implements support for file system lookup, file system caching, and directory search management...
void setOverlayDir(StringRef OverlayDirectory)
void attachToASTReader(ASTReader &R) override
void addFile(StringRef Filename)
void write(llvm::raw_ostream &OS)
HeaderSearch & getHeaderSearchInfo() 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 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...
Collects the dependencies for imported modules into a directory.
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
const char * getName() const
Cached information about one file (either on disk or in the virtual file system). ...
const char * getName() const
static bool isCaseSensitivePath(StringRef Path)
Reads an AST files chain containing the contents of a translation unit.
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.
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)