17#include "llvm/Config/llvm-config.h"
18#include "llvm/Support/FileSystem.h"
19#include "llvm/Support/IOSandbox.h"
20#include "llvm/Support/Path.h"
21#include "llvm/Support/raw_ostream.h"
28 ModuleDependencyCollector &Collector;
31 ModuleDependencyListener(ModuleDependencyCollector &Collector,
33 : Collector(Collector), FileMgr(FileMgr) {}
34 bool needsInputFileVisitation()
override {
return true; }
35 bool needsSystemInputFileVisitation()
override {
return true; }
36 bool visitInputFile(StringRef Filename,
bool IsSystem,
bool IsOverridden,
37 bool IsExplicitModule)
override {
40 if (
auto FE = FileMgr.getOptionalFileRef(Filename))
41 Filename = FE->getName();
42 Collector.addFile(Filename);
47struct ModuleDependencyPPCallbacks :
public PPCallbacks {
48 ModuleDependencyCollector &Collector;
50 ModuleDependencyPPCallbacks(ModuleDependencyCollector &Collector,
52 : Collector(Collector), SM(SM) {}
54 void InclusionDirective(SourceLocation HashLoc,
const Token &IncludeTok,
56 CharSourceRange FilenameRange,
58 StringRef RelativePath,
const Module *SuggestedModule,
63 Collector.addFile(
File->getName());
68 ModuleDependencyCollector &Collector;
69 ModuleDependencyMMCallbacks(ModuleDependencyCollector &Collector)
70 : Collector(Collector) {}
72 void moduleMapAddHeader(StringRef HeaderPath)
override {
73 if (llvm::sys::path::is_absolute(HeaderPath))
74 Collector.addFile(HeaderPath);
76 void moduleMapAddUmbrellaHeader(FileEntryRef Header)
override {
85 std::make_unique<ModuleDependencyListener>(*
this, R.
getFileManager()));
92 std::make_unique<ModuleDependencyMMCallbacks>(*
this));
98 if (VFS.getRealPath(Path, TmpDest))
108 if (!VFS.getRealPath(UpperDest, RealDest) && Path == RealDest)
121 VFSWriter.setOverlayDir(VFSDir);
125 VFSWriter.setCaseSensitivity(
130 VFSWriter.setUseExternalNames(
false);
134 llvm::sys::path::append(YAMLPath,
"vfs.yaml");
135 llvm::raw_fd_ostream OS(YAMLPath, EC, llvm::sys::fs::OF_TextWithCRLF);
143std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src,
145 using namespace llvm::sys;
146 llvm::FileCollector::PathCanonicalizer::PathStorage Paths =
147 Canonicalizer.canonicalize(Src);
154 path::append(CacheDst, path::relative_path(Paths.CopyFrom));
158 if (!Canonicalizer.getFileSystem().exists(Dst))
159 return std::error_code();
160 path::append(CacheDst, Dst);
161 Paths.CopyFrom = Dst;
167 auto BypassSandbox = sandbox::scopedDisable();
169 if (std::error_code EC = fs::create_directories(path::parent_path(CacheDst),
172 if (std::error_code EC = fs::copy_file(Paths.CopyFrom, CacheDst))
182 return std::error_code();
187 if (copyToRoot(Filename, FileDst))
llvm::MachO::FileType FileType
static bool isCaseSensitivePath(llvm::vfs::FileSystem &VFS, StringRef Path)
Defines the clang::Preprocessor interface.
Abstract interface for callback invocations by the ASTReader.
Reads an AST files chain containing the contents of a translation unit.
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
FileManager & getFileManager() const
StringRef getNameAsRequested() const
The name of this FileEntry, as originally requested without applying any remappings for VFS 'use-exte...
void attachToASTReader(ASTReader &R) override
virtual void addFileMapping(StringRef VPath, StringRef RPath)
void attachToPreprocessor(Preprocessor &PP) override
virtual void addFile(StringRef Filename, StringRef FileDst={})
virtual bool insertSeen(StringRef Filename)
virtual void writeFileMap()
A mechanism to observe the actions of the module map loader as it reads module map files.
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
SourceManager & getSourceManager() const
HeaderSearch & getHeaderSearchInfo() const
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
The JSON file list parser is used to communicate input to InstallAPI.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
LLVM_READONLY char toUppercase(char c)
Converts the given ASCII character to its uppercase equivalent.