16 using namespace clang;
17 using namespace tooling;
18 using namespace dependencies;
25 DependencyPrinter(std::unique_ptr<DependencyOutputOptions> Opts,
30 llvm::raw_string_ostream
OS(S);
31 outputDependencyFile(OS);
35 std::unique_ptr<DependencyOutputOptions> Opts;
41 class ProxyFileSystemWithoutChdir :
public llvm::vfs::ProxyFileSystem {
43 ProxyFileSystemWithoutChdir(
45 : ProxyFileSystem(
std::move(FS)) {}
47 llvm::ErrorOr<std::string> getCurrentWorkingDirectory()
const override {
48 assert(!CWD.empty() &&
"empty CWD");
52 std::error_code setCurrentWorkingDirectory(
const Twine &Path)
override {
65 DependencyScanningAction(StringRef WorkingDirectory,
66 std::string &DependencyFileContents)
67 : WorkingDirectory(WorkingDirectory),
68 DependencyFileContents(DependencyFileContents) {}
70 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
72 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
76 Compiler.setInvocation(std::move(Invocation));
78 Compiler.setFileManager(FileMgr);
81 Compiler.getDiagnosticOpts().ShowCarets =
false;
83 Compiler.createDiagnostics(DiagConsumer,
false);
84 if (!Compiler.hasDiagnostics())
87 Compiler.createSourceManager(*FileMgr);
96 auto Opts = llvm::make_unique<DependencyOutputOptions>(
97 std::move(Compiler.getInvocation().getDependencyOutputOpts()));
99 if (Opts->Targets.empty())
100 Opts->Targets = {
"clang-scan-deps dependency"};
101 Compiler.addDependencyCollector(std::make_shared<DependencyPrinter>(
102 std::move(Opts), DependencyFileContents));
104 auto Action = llvm::make_unique<PreprocessOnlyAction>();
105 const bool Result = Compiler.ExecuteAction(*Action);
111 StringRef WorkingDirectory;
113 std::string &DependencyFileContents;
120 PCHContainerOps = std::make_shared<PCHContainerOperations>();
123 WorkerFS =
new ProxyFileSystemWithoutChdir(llvm::vfs::getRealFileSystem());
128 StringRef WorkingDirectory,
132 std::string DiagnosticOutput;
133 llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
136 WorkerFS->setCurrentWorkingDirectory(WorkingDirectory);
143 DependencyScanningAction Action(WorkingDirectory, Output);
144 if (Tool.
run(&Action)) {
145 return llvm::make_error<llvm::StringError>(DiagnosticsOS.str(),
146 llvm::inconvertibleErrorCode());
Implements support for file system lookup, file system caching, and directory search management...
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Concrete class used by the front-end to report problems and issues.
Builds a dependency file when attached to a Preprocessor (for includes) and ASTReader (for module imp...
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Options for controlling the compiler diagnostics engine.
Dataflow Directional Tag Classes.
void clearStatCache()
Removes the FileSystemStatCache object from the manager.
Indicates that the tracking object is a descendant of a referenced-counted OSObject, used in the Darwin kernel.