diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -79,11 +79,11 @@ /// Gets the full command line suitable for passing to clang. /// - /// \param LookupPCMPath this function is called to fill in `-fmodule-file=` + /// \param LookupPCMPath This function is called to fill in `-fmodule-file=` /// flags and for the `-o` flag. It needs to return a /// path for where the PCM for the given module is to /// be located. - /// \param LookupModuleDeps this fucntion is called to collect the full + /// \param LookupModuleDeps This function is called to collect the full /// transitive set of dependencies for this /// compilation. std::vector getFullCommandLine( @@ -92,14 +92,13 @@ }; namespace detail { -/// Append the `-fmodule-file=` and `-fmodule-map-file=` arguments for the -/// modules in \c Modules transitively, along with other needed arguments to -/// use explicitly built modules. -void appendCommonModuleArguments( +/// Collect the paths of PCM and module map files for the modules in \c Modules +/// transitively. +void collectPCMAndModuleMapPaths( llvm::ArrayRef Modules, std::function LookupPCMPath, std::function LookupModuleDeps, - std::vector &Result); + std::vector &PCMPaths, std::vector &ModMapPaths); } // namespace detail class ModuleDepCollector; diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -18,8 +18,17 @@ std::function LookupModuleDeps) const { std::vector Ret = AdditionalNonPathCommandLine; - dependencies::detail::appendCommonModuleArguments( - ClangModuleDeps, LookupPCMPath, LookupModuleDeps, Ret); + Ret.push_back("-fno-implicit-modules"); + Ret.push_back("-fno-implicit-module-maps"); + + std::vector PCMPaths; + std::vector ModMapPaths; + dependencies::detail::collectPCMAndModuleMapPaths( + ClangModuleDeps, LookupPCMPath, LookupModuleDeps, PCMPaths, ModMapPaths); + for (const std::string &PCMPath : PCMPaths) + Ret.push_back("-fmodule-file=" + PCMPath); + for (const std::string &ModMapPath : ModMapPaths) + Ret.push_back("-fmodule-map-file=" + ModMapPath); return Ret; } diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -25,17 +25,26 @@ // TODO: Build full command line. That also means capturing the original // command line into NonPathCommandLine. - dependencies::detail::appendCommonModuleArguments( - ClangModuleDeps, LookupPCMPath, LookupModuleDeps, Ret); + Ret.push_back("-fno-implicit-modules"); + Ret.push_back("-fno-implicit-module-maps"); + + std::vector PCMPaths; + std::vector ModMapPaths; + dependencies::detail::collectPCMAndModuleMapPaths( + ClangModuleDeps, LookupPCMPath, LookupModuleDeps, PCMPaths, ModMapPaths); + for (const std::string &PCMPath : PCMPaths) + Ret.push_back("-fmodule-file=" + PCMPath); + for (const std::string &ModMapPath : ModMapPaths) + Ret.push_back("-fmodule-map-file=" + ModMapPath); return Ret; } -void dependencies::detail::appendCommonModuleArguments( +void dependencies::detail::collectPCMAndModuleMapPaths( llvm::ArrayRef Modules, std::function LookupPCMPath, std::function LookupModuleDeps, - std::vector &Result) { + std::vector &PCMPaths, std::vector &ModMapPaths) { llvm::StringSet<> AlreadyAdded; std::function)> AddArgs = @@ -46,15 +55,12 @@ const ModuleDeps &M = LookupModuleDeps(MID); // Depth first traversal. AddArgs(M.ClangModuleDeps); - Result.push_back(("-fmodule-file=" + LookupPCMPath(MID)).str()); - if (!M.ClangModuleMapFile.empty()) { - Result.push_back("-fmodule-map-file=" + M.ClangModuleMapFile); - } + PCMPaths.push_back(LookupPCMPath(MID).str()); + if (!M.ClangModuleMapFile.empty()) + ModMapPaths.push_back(M.ClangModuleMapFile); } }; - Result.push_back("-fno-implicit-modules"); - Result.push_back("-fno-implicit-module-maps"); AddArgs(Modules); } diff --git a/clang/test/ClangScanDeps/modules-full.cpp b/clang/test/ClangScanDeps/modules-full.cpp --- a/clang/test/ClangScanDeps/modules-full.cpp +++ b/clang/test/ClangScanDeps/modules-full.cpp @@ -148,8 +148,8 @@ // CHECK-NEXT: "-fno-implicit-modules", // CHECK-NEXT: "-fno-implicit-module-maps", // CHECK-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H1]]/header2-{{[A-Z0-9]+}}.pcm", -// CHECK-NEXT: "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap", // CHECK-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H1]]/header1-{{[A-Z0-9]+}}.pcm", +// CHECK-NEXT: "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap", // CHECK-NEXT: "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap" // CHECK-NEXT: ], // CHECK-NEXT: "file-deps": [