|
22 | 22 | #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
|
23 | 23 | #include "llvm/Support/FileSystem.h"
|
24 | 24 | #include "llvm/Support/Signals.h"
|
| 25 | +#include "llvm/Support/Path.h" |
25 | 26 |
|
26 | 27 | using namespace swift;
|
27 | 28 |
|
28 | 29 | using namespace clang::tooling;
|
29 | 30 | using namespace clang::tooling::dependencies;
|
30 | 31 |
|
31 |
| -static std::string lookupModuleOutput(const ModuleID &MID, |
32 |
| - ModuleOutputKind MOK) { |
33 |
| - // Deciding the output paths is done in swift-driver. |
| 32 | +static std::string moduleCacheRelativeLookupModuleOutput(const ModuleID &MID, |
| 33 | + ModuleOutputKind MOK, |
| 34 | + const std::string &moduleCachePathStr) { |
| 35 | + llvm::SmallString<128> outputPath(moduleCachePathStr); |
| 36 | + llvm::sys::path::append(outputPath, MID.ModuleName + "-" + MID.ContextHash); |
34 | 37 | switch (MOK) {
|
35 | 38 | case ModuleOutputKind::ModuleFile:
|
36 |
| - return "<replace-me>"; |
| 39 | + llvm::sys::path::replace_extension(outputPath, getExtension(swift::file_types::TY_ClangModuleFile)); |
| 40 | + break; |
37 | 41 | case ModuleOutputKind::DependencyFile:
|
38 |
| - return "<replace-me>"; |
| 42 | + llvm::sys::path::replace_extension(outputPath, getExtension(swift::file_types::TY_Dependencies)); |
| 43 | + break; |
39 | 44 | case ModuleOutputKind::DependencyTargets:
|
40 | 45 | return MID.ModuleName + "-" + MID.ContextHash;
|
41 | 46 | case ModuleOutputKind::DiagnosticSerializationFile:
|
42 |
| - return "<replace-me>"; |
| 47 | + llvm::sys::path::replace_extension(outputPath, getExtension(swift::file_types::TY_SerializedDiagnostics)); |
| 48 | + break; |
43 | 49 | }
|
44 |
| - llvm_unreachable("Fully covered switch above!"); |
| 50 | + return outputPath.str().str(); |
45 | 51 | }
|
46 | 52 |
|
47 | 53 | // Add search paths.
|
@@ -228,6 +234,12 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
|
228 | 234 | workingDir = *(clangWorkingDirPos - 1);
|
229 | 235 | }
|
230 | 236 |
|
| 237 | + auto moduleCachePath = getModuleCachePathFromClang(getClangInstance()); |
| 238 | + auto lookupModuleOutput = [moduleCachePath] (const ModuleID &MID, |
| 239 | + ModuleOutputKind MOK) -> std::string { |
| 240 | + return moduleCacheRelativeLookupModuleOutput(MID, MOK, moduleCachePath); |
| 241 | + }; |
| 242 | + |
231 | 243 | auto clangDependencies = cache.getClangScannerTool().getFullDependencies(
|
232 | 244 | commandLineArgs, workingDir, cache.getAlreadySeenClangModules(),
|
233 | 245 | lookupModuleOutput, moduleName);
|
@@ -284,6 +296,12 @@ bool ClangImporter::addBridgingHeaderDependencies(
|
284 | 296 | std::string workingDir =
|
285 | 297 | ctx.SourceMgr.getFileSystem()->getCurrentWorkingDirectory().get();
|
286 | 298 |
|
| 299 | + auto moduleCachePath = getModuleCachePathFromClang(getClangInstance()); |
| 300 | + auto lookupModuleOutput = [moduleCachePath] (const ModuleID &MID, |
| 301 | + ModuleOutputKind MOK) -> std::string { |
| 302 | + return moduleCacheRelativeLookupModuleOutput(MID, MOK, moduleCachePath); |
| 303 | + }; |
| 304 | + |
287 | 305 | auto clangDependencies = cache.getClangScannerTool().getFullDependencies(
|
288 | 306 | commandLineArgs, workingDir, cache.getAlreadySeenClangModules(),
|
289 | 307 | lookupModuleOutput);
|
|
0 commit comments