|
11 | 11 | #include "clang/Frontend/CompilerInvocation.h"
|
12 | 12 | #include "clang/Lex/HeaderSearchOptions.h"
|
13 | 13 | #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
|
14 |
| -#include "llvm/CAS/CachingOnDiskFileSystem.h" |
15 | 14 | #include "llvm/CAS/ObjectStore.h"
|
| 15 | +#include "llvm/Support/Path.h" |
16 | 16 | #include "llvm/Support/PrefixMapper.h"
|
17 | 17 |
|
18 | 18 | using namespace clang;
|
19 | 19 | using namespace clang::tooling::dependencies;
|
20 | 20 | using llvm::Error;
|
21 | 21 |
|
| 22 | +static void updateRelativePath(std::string &Path, |
| 23 | + const std::string &WorkingDir) { |
| 24 | + if (Path.empty() || llvm::sys::path::is_absolute(Path) || WorkingDir.empty()) |
| 25 | + return; |
| 26 | + |
| 27 | + SmallString<128> PathStorage(WorkingDir); |
| 28 | + llvm::sys::path::append(PathStorage, Path); |
| 29 | + Path = PathStorage.str(); |
| 30 | +} |
| 31 | + |
22 | 32 | void tooling::dependencies::configureInvocationForCaching(
|
23 | 33 | CompilerInvocation &CI, CASOptions CASOpts, std::string InputID,
|
24 | 34 | CachingInputKind InputKind, std::string WorkingDir) {
|
@@ -92,6 +102,14 @@ void tooling::dependencies::configureInvocationForCaching(
|
92 | 102 | }
|
93 | 103 | // Clear APINotes options.
|
94 | 104 | CI.getAPINotesOpts().ModuleSearchPaths = {};
|
| 105 | + |
| 106 | + // Update output paths, and clear working directory. |
| 107 | + auto CWD = FileSystemOpts.WorkingDir; |
| 108 | + updateRelativePath(FrontendOpts.OutputFile, CWD); |
| 109 | + updateRelativePath(CI.getDiagnosticOpts().DiagnosticSerializationFile, CWD); |
| 110 | + updateRelativePath(CI.getDiagnosticOpts().DiagnosticLogFile, CWD); |
| 111 | + updateRelativePath(CI.getDependencyOutputOpts().OutputFile, CWD); |
| 112 | + FileSystemOpts.WorkingDir.clear(); |
95 | 113 | break;
|
96 | 114 | }
|
97 | 115 | case CachingInputKind::FileSystemRoot: {
|
|
0 commit comments