|
25 | 25 | #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
|
26 | 26 | #include "llvm/ADT/STLExtras.h"
|
27 | 27 | #include "llvm/Support/Allocator.h"
|
| 28 | +#include "llvm/Support/Error.h" |
28 | 29 | #include "llvm/Support/FileSystem.h"
|
29 | 30 | #include "llvm/Support/Signals.h"
|
30 | 31 | #include "llvm/Support/Path.h"
|
@@ -265,17 +266,34 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
|
265 | 266 | swiftArgs.push_back(IncludeTree);
|
266 | 267 | }
|
267 | 268 |
|
| 269 | + // Ensure we get the external path to the modulemap because it is used as an |
| 270 | + // explicit input for the resulting compilation task. |
| 271 | + auto moduleMapFile = |
| 272 | + getClangInstance().getFileManager().getFileRef( |
| 273 | + clangModuleDep.ClangModuleMapFile); |
| 274 | + StringRef externalModuleMapPath; |
| 275 | + if (auto E = moduleMapFile.takeError()) { |
| 276 | + ctx.Diags.diagnose(SourceLoc(), |
| 277 | + diag::clang_dependency_no_modulemap_fileref, |
| 278 | + clangModuleDep.ClangModuleMapFile, |
| 279 | + llvm::toString(std::move(E))); |
| 280 | + externalModuleMapPath = clangModuleDep.ClangModuleMapFile; |
| 281 | + } else |
| 282 | + externalModuleMapPath = moduleMapFile.get().getName(); |
| 283 | + |
268 | 284 | // Module-level dependencies.
|
269 | 285 | llvm::StringSet<> alreadyAddedModules;
|
270 | 286 | auto dependencies = ModuleDependencyInfo::forClangModule(
|
271 |
| - pcmPath, clangModuleDep.ClangModuleMapFile, |
272 |
| - clangModuleDep.ID.ContextHash, swiftArgs, fileDeps, capturedPCMArgs, |
273 |
| - RootID, IncludeTree, /*module-cache-key*/ ""); |
| 287 | + pcmPath, externalModuleMapPath.str(), clangModuleDep.ID.ContextHash, |
| 288 | + swiftArgs, fileDeps, capturedPCMArgs, RootID, IncludeTree, |
| 289 | + /*module-cache-key*/ ""); |
274 | 290 | for (const auto &moduleName : clangModuleDep.ClangModuleDeps) {
|
275 | 291 | dependencies.addModuleImport(moduleName.ModuleName, &alreadyAddedModules);
|
276 |
| - // It is safe to assume that all dependencies of a Clang module are Clang modules. |
277 |
| - // Doing this allows us to skip "resolving" Clang modules down the line. |
278 |
| - dependencies.addModuleDependency({moduleName.ModuleName, ModuleDependencyKind::Clang}); |
| 292 | + // It is safe to assume that all dependencies of a Clang module are Clang |
| 293 | + // modules. Doing this allows us to skip "resolving" Clang modules down |
| 294 | + // the line. |
| 295 | + dependencies.addModuleDependency( |
| 296 | + {moduleName.ModuleName, ModuleDependencyKind::Clang}); |
279 | 297 | }
|
280 | 298 | dependencies.setIsResolved(true);
|
281 | 299 |
|
|
0 commit comments