@@ -48,7 +48,8 @@ class ModuleDependencyScanner {
4848 };
4949
5050 // / Scanning the single file specified by \param FilePath.
51- std::optional<ModuleDependencyInfo> scan (PathRef FilePath);
51+ std::optional<ModuleDependencyInfo>
52+ scan (PathRef FilePath, const ProjectModules::CommandMangler &Mangler);
5253
5354 // / Scanning every source file in the current project to get the
5455 // / <module-name> to <module-unit-source> map.
@@ -57,7 +58,7 @@ class ModuleDependencyScanner {
5758 // / a global module dependency scanner to monitor every file. Or we
5859 // / can simply require the build systems (or even the end users)
5960 // / to provide the map.
60- void globalScan ();
61+ void globalScan (const ProjectModules::CommandMangler &Mangler );
6162
6263 // / Get the source file from the module name. Note that the language
6364 // / guarantees all the module names are unique in a valid program.
@@ -69,7 +70,9 @@ class ModuleDependencyScanner {
6970
7071 // / Return the direct required modules. Indirect required modules are not
7172 // / included.
72- std::vector<std::string> getRequiredModules (PathRef File);
73+ std::vector<std::string>
74+ getRequiredModules (PathRef File,
75+ const ProjectModules::CommandMangler &Mangler);
7376
7477private:
7578 std::shared_ptr<const clang::tooling::CompilationDatabase> CDB;
@@ -87,7 +90,8 @@ class ModuleDependencyScanner {
8790};
8891
8992std::optional<ModuleDependencyScanner::ModuleDependencyInfo>
90- ModuleDependencyScanner::scan (PathRef FilePath) {
93+ ModuleDependencyScanner::scan (PathRef FilePath,
94+ const ProjectModules::CommandMangler &Mangler) {
9195 auto Candidates = CDB->getCompileCommands (FilePath);
9296 if (Candidates.empty ())
9397 return std::nullopt ;
@@ -97,10 +101,8 @@ ModuleDependencyScanner::scan(PathRef FilePath) {
97101 // DirectoryBasedGlobalCompilationDatabase::getCompileCommand.
98102 tooling::CompileCommand Cmd = std::move (Candidates.front ());
99103
100- static int StaticForMainAddr; // Just an address in this process.
101- Cmd.CommandLine .push_back (" -resource-dir=" +
102- CompilerInvocation::GetResourcesPath (
103- " clangd" , (void *)&StaticForMainAddr));
104+ if (Mangler)
105+ Mangler (Cmd, FilePath);
104106
105107 using namespace clang ::tooling::dependencies;
106108
@@ -130,9 +132,10 @@ ModuleDependencyScanner::scan(PathRef FilePath) {
130132 return Result;
131133}
132134
133- void ModuleDependencyScanner::globalScan () {
135+ void ModuleDependencyScanner::globalScan (
136+ const ProjectModules::CommandMangler &Mangler) {
134137 for (auto &File : CDB->getAllFiles ())
135- scan (File);
138+ scan (File, Mangler );
136139
137140 GlobalScanned = true ;
138141}
@@ -150,9 +153,9 @@ PathRef ModuleDependencyScanner::getSourceForModuleName(
150153 return {};
151154}
152155
153- std::vector<std::string>
154- ModuleDependencyScanner::getRequiredModules ( PathRef File) {
155- auto ScanningResult = scan (File);
156+ std::vector<std::string> ModuleDependencyScanner::getRequiredModules (
157+ PathRef File, const ProjectModules::CommandMangler &Mangler ) {
158+ auto ScanningResult = scan (File, Mangler );
156159 if (!ScanningResult)
157160 return {};
158161
@@ -177,20 +180,25 @@ class ScanningAllProjectModules : public ProjectModules {
177180 ~ScanningAllProjectModules () override = default ;
178181
179182 std::vector<std::string> getRequiredModules (PathRef File) override {
180- return Scanner.getRequiredModules (File);
183+ return Scanner.getRequiredModules (File, Mangler);
184+ }
185+
186+ void setCommandMangler (CommandMangler Mangler) override {
187+ this ->Mangler = std::move (Mangler);
181188 }
182189
183190 // / RequiredSourceFile is not used intentionally. See the comments of
184191 // / ModuleDependencyScanner for detail.
185192 PathRef
186193 getSourceForModuleName (llvm::StringRef ModuleName,
187194 PathRef RequiredSourceFile = PathRef()) override {
188- Scanner.globalScan ();
195+ Scanner.globalScan (Mangler );
189196 return Scanner.getSourceForModuleName (ModuleName);
190197 }
191198
192199private:
193200 ModuleDependencyScanner Scanner;
201+ CommandMangler Mangler;
194202};
195203
196204std::unique_ptr<ProjectModules> scanningProjectModules (
0 commit comments