Skip to content

Commit 0344d18

Browse files
committed
[clang/DependencyScanning/ModuleDepCollector] Refactor part of makeCommonInvocationForModuleBuild into its own function, NFC
The function is named `removeUnnecessaryDependencies` and is a bit more general that could be used from other places as well.
1 parent a952c12 commit 0344d18

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ class ModuleDepCollector final : public DependencyCollector {
308308
ModuleDeps &Deps);
309309
};
310310

311+
/// Resets some options that introduce dependencies unnecessarily.
312+
void removeUnnecessaryDependencies(CompilerInvocation &CI, bool ForModuleBuild);
313+
311314
} // end namespace dependencies
312315
} // end namespace tooling
313316
} // end namespace clang

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ void ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
154154
}
155155
}
156156

157+
void dependencies::removeUnnecessaryDependencies(CompilerInvocation &CI,
158+
bool ForModuleBuild) {
159+
if (CI.getFrontendOpts().ProgramAction == frontend::GeneratePCH ||
160+
(ForModuleBuild && !CI.getLangOpts().ModulesCodegen)) {
161+
CI.getCodeGenOpts().DebugCompilationDir.clear();
162+
CI.getCodeGenOpts().CoverageCompilationDir.clear();
163+
CI.getCodeGenOpts().CoverageDataFile.clear();
164+
CI.getCodeGenOpts().CoverageNotesFile.clear();
165+
CI.getCodeGenOpts().ProfileInstrumentUsePath.clear();
166+
CI.getCodeGenOpts().SampleProfileFile.clear();
167+
CI.getCodeGenOpts().ProfileRemappingFile.clear();
168+
}
169+
}
170+
157171
static CowCompilerInvocation
158172
makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
159173
CI.resetNonModularOptions();
@@ -170,15 +184,8 @@ makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
170184
// TODO: Figure out better way to set options to their default value.
171185
CI.getCodeGenOpts().MainFileName.clear();
172186
CI.getCodeGenOpts().DwarfDebugFlags.clear();
173-
if (!CI.getLangOpts().ModulesCodegen) {
174-
CI.getCodeGenOpts().DebugCompilationDir.clear();
175-
CI.getCodeGenOpts().CoverageCompilationDir.clear();
176-
CI.getCodeGenOpts().CoverageDataFile.clear();
177-
CI.getCodeGenOpts().CoverageNotesFile.clear();
178-
CI.getCodeGenOpts().ProfileInstrumentUsePath.clear();
179-
CI.getCodeGenOpts().SampleProfileFile.clear();
180-
CI.getCodeGenOpts().ProfileRemappingFile.clear();
181-
}
187+
188+
removeUnnecessaryDependencies(CI, /*ForModuleBuild=*/true);
182189

183190
// Map output paths that affect behaviour to "-" so their existence is in the
184191
// context hash. The final path will be computed in addOutputPaths.

0 commit comments

Comments
 (0)