12
12
13
13
#define DEBUG_TYPE " textual-module-interface"
14
14
15
+ #include " swift/Frontend/ModuleInterfaceLoader.h"
15
16
#include " ModuleInterfaceBuilder.h"
16
17
#include " swift/AST/ASTContext.h"
17
18
#include " swift/AST/DiagnosticsFrontend.h"
@@ -82,19 +83,37 @@ void ModuleInterfaceBuilder::configureSubInvocationInputsAndOutputs(
82
83
.setMainAndSupplementaryOutputs ({MainOut}, {SOPs});
83
84
}
84
85
85
- void ModuleInterfaceBuilder::configureSubInvocation (
86
+ void swift::inheritOptionsForBuildingInterface (
87
+ CompilerInvocation &Invok,
86
88
const SearchPathOptions &SearchPathOpts,
87
- const LangOptions &LangOpts,
88
- ClangModuleLoader *ClangLoader) {
89
+ const LangOptions &LangOpts) {
89
90
// Start with a SubInvocation that copies various state from our
90
91
// invoking ASTContext.
91
- subInvocation.setImportSearchPaths (SearchPathOpts.ImportSearchPaths );
92
- subInvocation.setFrameworkSearchPaths (SearchPathOpts.FrameworkSearchPaths );
93
- subInvocation.setSDKPath (SearchPathOpts.SDKPath );
94
- subInvocation.setInputKind (InputFileKind::SwiftModuleInterface);
95
- subInvocation.setRuntimeResourcePath (SearchPathOpts.RuntimeResourcePath );
96
- 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 ;
97
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
+ }
111
+
112
+ void ModuleInterfaceBuilder::configureSubInvocation (
113
+ const SearchPathOptions &SearchPathOpts,
114
+ const LangOptions &LangOpts,
115
+ ClangModuleLoader *ClangLoader) {
116
+ inheritOptionsForBuildingInterface (subInvocation, SearchPathOpts, LangOpts);
98
117
subInvocation.setModuleName (moduleName);
99
118
subInvocation.setClangModuleCachePath (moduleCachePath);
100
119
subInvocation.getFrontendOptions ().PrebuiltModuleCachePath =
@@ -111,18 +130,6 @@ void ModuleInterfaceBuilder::configureSubInvocation(
111
130
}
112
131
}
113
132
114
- // Inhibit warnings from the SubInvocation since we are assuming the user
115
- // is not in a position to fix them.
116
- subInvocation.getDiagnosticOptions ().SuppressWarnings = true ;
117
-
118
- // Inherit this setting down so that it can affect error diagnostics (mostly
119
- // by making them non-fatal).
120
- subInvocation.getLangOptions ().DebuggerSupport = LangOpts.DebuggerSupport ;
121
-
122
- // Disable this; deinitializers always get printed with `@objc` even in
123
- // modules that don't import Foundation.
124
- subInvocation.getLangOptions ().EnableObjCAttrRequiresFoundation = false ;
125
-
126
133
// Tell the subinvocation to serialize dependency hashes if asked to do so.
127
134
auto &frontendOpts = subInvocation.getFrontendOptions ();
128
135
frontendOpts.SerializeModuleInterfaceDependencyHashes =
@@ -134,35 +141,44 @@ void ModuleInterfaceBuilder::configureSubInvocation(
134
141
remarkOnRebuildFromInterface;
135
142
}
136
143
137
- bool ModuleInterfaceBuilder::extractSwiftInterfaceVersionAndArgs (
138
- swift::version::Version &Vers, StringRef &CompilerVersion,
139
- llvm::StringSaver &SubArgSaver, SmallVectorImpl<const char *> &SubArgs) {
140
- llvm::vfs::FileSystem &fs = *sourceMgr.getFileSystem ();
141
- auto FileOrError = swift::vfs::getFileOrSTDIN (fs, interfacePath);
144
+ bool swift::extractSwiftInterfaceVersionAndArgs (
145
+ SourceManager &SM,
146
+ DiagnosticEngine &Diags,
147
+ StringRef InterfacePath,
148
+ version::Version &Vers,
149
+ StringRef &CompilerVersion,
150
+ llvm::StringSaver &SubArgSaver,
151
+ SmallVectorImpl<const char *> &SubArgs,
152
+ SourceLoc diagnosticLoc) {
153
+ llvm::vfs::FileSystem &fs = *SM.getFileSystem ();
154
+ auto FileOrError = swift::vfs::getFileOrSTDIN (fs, InterfacePath);
142
155
if (!FileOrError) {
143
156
// Don't use this->diagnose() because it'll just try to re-open
144
157
// interfacePath.
145
- diags .diagnose (diagnosticLoc, diag::error_open_input_file,
146
- interfacePath , FileOrError.getError ().message ());
158
+ Diags .diagnose (diagnosticLoc, diag::error_open_input_file,
159
+ InterfacePath , FileOrError.getError ().message ());
147
160
return true ;
148
161
}
149
162
auto SB = FileOrError.get ()->getBuffer ();
150
163
auto VersRe = getSwiftInterfaceFormatVersionRegex ();
151
164
auto CompRe = getSwiftInterfaceCompilerVersionRegex ();
152
165
auto FlagRe = getSwiftInterfaceModuleFlagsRegex ();
153
166
SmallVector<StringRef, 1 > VersMatches, FlagMatches, CompMatches;
167
+
154
168
if (!VersRe.match (SB, &VersMatches)) {
155
- diagnose (diag::error_extracting_version_from_module_interface);
169
+ ModuleInterfaceBuilder::diagnose (Diags, SM, InterfacePath, diagnosticLoc,
170
+ diag::error_extracting_version_from_module_interface);
156
171
return true ;
157
172
}
158
173
if (!FlagRe.match (SB, &FlagMatches)) {
159
- diagnose (diag::error_extracting_flags_from_module_interface);
174
+ ModuleInterfaceBuilder::diagnose (Diags, SM, InterfacePath, diagnosticLoc,
175
+ diag::error_extracting_version_from_module_interface);
160
176
return true ;
161
177
}
162
178
assert (VersMatches.size () == 2 );
163
179
assert (FlagMatches.size () == 2 );
164
180
// FIXME We should diagnose this at a location that makes sense:
165
- Vers = swift::version::Version (VersMatches[1 ], SourceLoc (), &diags );
181
+ Vers = swift::version::Version (VersMatches[1 ], SourceLoc (), &Diags );
166
182
llvm::cl::TokenizeGNUCommandLine (FlagMatches[1 ], SubArgSaver, SubArgs);
167
183
168
184
if (CompRe.match (SB, &CompMatches)) {
@@ -177,6 +193,13 @@ bool ModuleInterfaceBuilder::extractSwiftInterfaceVersionAndArgs(
177
193
return false ;
178
194
}
179
195
196
+ bool ModuleInterfaceBuilder::extractSwiftInterfaceVersionAndArgs (
197
+ swift::version::Version &Vers, StringRef &CompilerVersion,
198
+ llvm::StringSaver &SubArgSaver, SmallVectorImpl<const char *> &SubArgs) {
199
+ return swift::extractSwiftInterfaceVersionAndArgs (sourceMgr, diags,
200
+ interfacePath, Vers, CompilerVersion, SubArgSaver, SubArgs, diagnosticLoc);
201
+ }
202
+
180
203
bool ModuleInterfaceBuilder::collectDepsForSerialization (
181
204
CompilerInstance &SubInstance, SmallVectorImpl<FileDependency> &Deps,
182
205
bool IsHashBased) {
0 commit comments