This patch simplifies (and renames) the `appendCommonModuleArguments` function.
It no longer tries to construct the command line for explicitly building modules. Instead, it only performs the DFS traversal of modular dependencies and queries the callbacks to collect paths to `.pcm` and `.modulemap` files.
This makes it more flexible and usable in two contexts:
* Generating additional command line arguments for the main TU in modular build. The `std::vector<std::string>` output parameters can be used to manually generate appropriate command line flags.
* Generate full command line for a module. The output parameters can be the corresponding parts of `CompilerInvocation`. (In a follow-up patch.)
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D100531
/// 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<std::string> getFullCommandLine(
};
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<ModuleID> Modules,
std::function<StringRef(ModuleID)> LookupPCMPath,
std::function<const ModuleDeps &(ModuleID)> LookupModuleDeps,
- std::vector<std::string> &Result);
+ std::vector<std::string> &PCMPaths, std::vector<std::string> &ModMapPaths);
} // namespace detail
class ModuleDepCollector;
std::function<const ModuleDeps &(ModuleID)> LookupModuleDeps) const {
std::vector<std::string> Ret = AdditionalNonPathCommandLine;
- dependencies::detail::appendCommonModuleArguments(
- ClangModuleDeps, LookupPCMPath, LookupModuleDeps, Ret);
+ Ret.push_back("-fno-implicit-modules");
+ Ret.push_back("-fno-implicit-module-maps");
+
+ std::vector<std::string> PCMPaths;
+ std::vector<std::string> 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;
}
// 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<std::string> PCMPaths;
+ std::vector<std::string> 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<ModuleID> Modules,
std::function<StringRef(ModuleID)> LookupPCMPath,
std::function<const ModuleDeps &(ModuleID)> LookupModuleDeps,
- std::vector<std::string> &Result) {
+ std::vector<std::string> &PCMPaths, std::vector<std::string> &ModMapPaths) {
llvm::StringSet<> AlreadyAdded;
std::function<void(llvm::ArrayRef<ModuleID>)> AddArgs =
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);
}
// 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": [