Skip to content

Commit 3cb8d8e

Browse files
committed
DependencyScanner: inherit ASTContext options when configuring a sub compiler instance for interface scanner. NFC
1 parent 9bc036c commit 3cb8d8e

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ namespace swift {
124124

125125
class LangOptions;
126126
class SearchPathOptions;
127+
class CompilerInvocation;
127128

128129
/// A ModuleLoader that runs a subordinate \c CompilerInvocation and
129130
/// \c CompilerInstance to convert .swiftinterface files to .swiftmodule
@@ -210,6 +211,10 @@ bool extractSwiftInterfaceVersionAndArgs(SourceManager &SM,
210211
llvm::StringSaver &SubArgSaver,
211212
SmallVectorImpl<const char *> &SubArgs,
212213
SourceLoc diagnosticLoc = SourceLoc());
214+
215+
void inheritOptionsForBuildingInterface(CompilerInvocation &Invok,
216+
const SearchPathOptions &SearchPathOpts,
217+
const LangOptions &LangOpts);
213218
}
214219

215220
#endif

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,37 @@ void ModuleInterfaceBuilder::configureSubInvocationInputsAndOutputs(
8383
.setMainAndSupplementaryOutputs({MainOut}, {SOPs});
8484
}
8585

86-
void ModuleInterfaceBuilder::configureSubInvocation(
86+
void swift::inheritOptionsForBuildingInterface(
87+
CompilerInvocation &Invok,
8788
const SearchPathOptions &SearchPathOpts,
88-
const LangOptions &LangOpts,
89-
ClangModuleLoader *ClangLoader) {
89+
const LangOptions &LangOpts) {
9090
// Start with a SubInvocation that copies various state from our
9191
// invoking ASTContext.
92-
subInvocation.setImportSearchPaths(SearchPathOpts.ImportSearchPaths);
93-
subInvocation.setFrameworkSearchPaths(SearchPathOpts.FrameworkSearchPaths);
94-
subInvocation.setSDKPath(SearchPathOpts.SDKPath);
95-
subInvocation.setInputKind(InputFileKind::SwiftModuleInterface);
96-
subInvocation.setRuntimeResourcePath(SearchPathOpts.RuntimeResourcePath);
97-
subInvocation.setTargetTriple(LangOpts.Target);
92+
Invok.setImportSearchPaths(SearchPathOpts.ImportSearchPaths);
93+
Invok.setFrameworkSearchPaths(SearchPathOpts.FrameworkSearchPaths);
94+
Invok.setSDKPath(SearchPathOpts.SDKPath);
95+
Invok.setInputKind(InputFileKind::SwiftModuleInterface);
96+
Invok.setRuntimeResourcePath(SearchPathOpts.RuntimeResourcePath);
97+
Invok.setTargetTriple(LangOpts.Target);
98+
99+
// Inhibit warnings from the SubInvocation since we are assuming the user
100+
// is not in a position to fix them.
101+
Invok.getDiagnosticOptions().SuppressWarnings = true;
102+
103+
// Inherit this setting down so that it can affect error diagnostics (mostly
104+
// by making them non-fatal).
105+
Invok.getLangOptions().DebuggerSupport = LangOpts.DebuggerSupport;
106+
107+
// Disable this; deinitializers always get printed with `@objc` even in
108+
// modules that don't import Foundation.
109+
Invok.getLangOptions().EnableObjCAttrRequiresFoundation = false;
110+
}
98111

112+
void ModuleInterfaceBuilder::configureSubInvocation(
113+
const SearchPathOptions &SearchPathOpts,
114+
const LangOptions &LangOpts,
115+
ClangModuleLoader *ClangLoader) {
116+
inheritOptionsForBuildingInterface(subInvocation, SearchPathOpts, LangOpts);
99117
subInvocation.setModuleName(moduleName);
100118
subInvocation.setClangModuleCachePath(moduleCachePath);
101119
subInvocation.getFrontendOptions().PrebuiltModuleCachePath =
@@ -112,18 +130,6 @@ void ModuleInterfaceBuilder::configureSubInvocation(
112130
}
113131
}
114132

115-
// Inhibit warnings from the SubInvocation since we are assuming the user
116-
// is not in a position to fix them.
117-
subInvocation.getDiagnosticOptions().SuppressWarnings = true;
118-
119-
// Inherit this setting down so that it can affect error diagnostics (mostly
120-
// by making them non-fatal).
121-
subInvocation.getLangOptions().DebuggerSupport = LangOpts.DebuggerSupport;
122-
123-
// Disable this; deinitializers always get printed with `@objc` even in
124-
// modules that don't import Foundation.
125-
subInvocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
126-
127133
// Tell the subinvocation to serialize dependency hashes if asked to do so.
128134
auto &frontendOpts = subInvocation.getFrontendOptions();
129135
frontendOpts.SerializeModuleInterfaceDependencyHashes =

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ struct InterfaceSubASTContextDelegate: SubASTContextDelegate {
7676
return true;
7777
}
7878
CompilerInvocation invok;
79+
80+
// Inherit options from the parent ASTContext so we have all search paths, etc.
81+
inheritOptionsForBuildingInterface(invok, ctx.SearchPathOpts, ctx.LangOpts);
7982
CompilerInstance inst;
8083
// Use the additional flags to setup the compiler instance.
8184
if (invok.parseArgs(SubArgs, ctx.Diags)) {

0 commit comments

Comments
 (0)