@@ -1259,13 +1259,83 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
1259
1259
SearchPathOpts.CandidateCompiledModules );
1260
1260
}
1261
1261
1262
+ static bool readSwiftInterfaceVersionAndArgs (
1263
+ SourceManager &SM, DiagnosticEngine &Diags, llvm::StringSaver &ArgSaver,
1264
+ SmallVectorImpl<const char *> &SubArgs, std::string &CompilerVersion,
1265
+ StringRef interfacePath, SourceLoc diagnosticLoc) {
1266
+ llvm::vfs::FileSystem &fs = *SM.getFileSystem ();
1267
+ auto FileOrError = swift::vfs::getFileOrSTDIN (fs, interfacePath);
1268
+ if (!FileOrError) {
1269
+ // Don't use this->diagnose() because it'll just try to re-open
1270
+ // interfacePath.
1271
+ Diags.diagnose (diagnosticLoc, diag::error_open_input_file, interfacePath,
1272
+ FileOrError.getError ().message ());
1273
+ return true ;
1274
+ }
1275
+ auto SB = FileOrError.get ()->getBuffer ();
1276
+ auto VersRe = getSwiftInterfaceFormatVersionRegex ();
1277
+ auto CompRe = getSwiftInterfaceCompilerVersionRegex ();
1278
+ SmallVector<StringRef, 1 > VersMatches, CompMatches;
1279
+
1280
+ if (!VersRe.match (SB, &VersMatches)) {
1281
+ InterfaceSubContextDelegateImpl::diagnose (
1282
+ interfacePath, diagnosticLoc, SM, &Diags,
1283
+ diag::error_extracting_version_from_module_interface);
1284
+ return true ;
1285
+ }
1286
+
1287
+ if (extractCompilerFlagsFromInterface (interfacePath, SB, ArgSaver, SubArgs)) {
1288
+ InterfaceSubContextDelegateImpl::diagnose (
1289
+ interfacePath, diagnosticLoc, SM, &Diags,
1290
+ diag::error_extracting_version_from_module_interface);
1291
+ return true ;
1292
+ }
1293
+
1294
+ assert (VersMatches.size () == 2 );
1295
+ // FIXME We should diagnose this at a location that makes sense:
1296
+ auto Vers = swift::version::Version (VersMatches[1 ], SourceLoc (), &Diags);
1297
+
1298
+ if (CompRe.match (SB, &CompMatches)) {
1299
+ assert (CompMatches.size () == 2 );
1300
+ CompilerVersion = ArgSaver.save (CompMatches[1 ]).str ();
1301
+ } else {
1302
+ // Don't diagnose; handwritten module interfaces don't include this field.
1303
+ CompilerVersion = " (unspecified, file possibly handwritten)" ;
1304
+ }
1305
+
1306
+ // For now: we support anything with the same "major version" and assume
1307
+ // minor versions might be interesting for debugging, or special-casing a
1308
+ // compatible field variant.
1309
+ if (Vers.asMajorVersion () != InterfaceFormatVersion.asMajorVersion ()) {
1310
+ InterfaceSubContextDelegateImpl::diagnose (
1311
+ interfacePath, diagnosticLoc, SM, &Diags,
1312
+ diag::unsupported_version_of_module_interface, interfacePath, Vers);
1313
+ return true ;
1314
+ }
1315
+ return false ;
1316
+ }
1317
+
1262
1318
bool ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface (
1263
1319
CompilerInstance &Instance, const StringRef moduleCachePath,
1264
1320
const StringRef backupInterfaceDir, const StringRef prebuiltCachePath,
1265
1321
const StringRef ABIDescriptorPath, StringRef interfacePath,
1266
1322
StringRef outputPath, bool ShouldSerializeDeps,
1267
- ArrayRef<std::string> CompiledCandidates, StringRef CompilerVersion,
1323
+ ArrayRef<std::string> CompiledCandidates,
1268
1324
DependencyTracker *tracker) {
1325
+
1326
+ // Read out the compiler version.
1327
+ llvm::BumpPtrAllocator alloc;
1328
+ llvm::StringSaver ArgSaver (alloc);
1329
+ std::string CompilerVersion;
1330
+ SmallVector<const char *, 64 > InterfaceArgs;
1331
+ readSwiftInterfaceVersionAndArgs (Instance.getSourceMgr (),
1332
+ Instance.getDiags (),
1333
+ ArgSaver,
1334
+ InterfaceArgs,
1335
+ CompilerVersion,
1336
+ interfacePath,
1337
+ SourceLoc ());
1338
+
1269
1339
auto Builder = ExplicitModuleInterfaceBuilder (
1270
1340
Instance, moduleCachePath, backupInterfaceDir, prebuiltCachePath,
1271
1341
ABIDescriptorPath);
@@ -1381,53 +1451,10 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
1381
1451
std::string &CompilerVersion,
1382
1452
StringRef interfacePath,
1383
1453
SourceLoc diagnosticLoc) {
1384
- llvm::vfs::FileSystem &fs = *SM.getFileSystem ();
1385
- auto FileOrError = swift::vfs::getFileOrSTDIN (fs, interfacePath);
1386
- if (!FileOrError) {
1387
- // Don't use this->diagnose() because it'll just try to re-open
1388
- // interfacePath.
1389
- Diags->diagnose (diagnosticLoc, diag::error_open_input_file,
1390
- interfacePath, FileOrError.getError ().message ());
1391
- return true ;
1392
- }
1393
- auto SB = FileOrError.get ()->getBuffer ();
1394
- auto VersRe = getSwiftInterfaceFormatVersionRegex ();
1395
- auto CompRe = getSwiftInterfaceCompilerVersionRegex ();
1396
- SmallVector<StringRef, 1 > VersMatches, CompMatches;
1397
-
1398
- if (!VersRe.match (SB, &VersMatches)) {
1399
- diagnose (interfacePath, diagnosticLoc,
1400
- diag::error_extracting_version_from_module_interface);
1401
- return true ;
1402
- }
1403
-
1404
- if (extractCompilerFlagsFromInterface (interfacePath, SB, ArgSaver, SubArgs)) {
1405
- diagnose (interfacePath, diagnosticLoc,
1406
- diag::error_extracting_version_from_module_interface);
1454
+ if (readSwiftInterfaceVersionAndArgs (SM, *Diags, ArgSaver, SubArgs,
1455
+ CompilerVersion, interfacePath,
1456
+ diagnosticLoc))
1407
1457
return true ;
1408
- }
1409
-
1410
- assert (VersMatches.size () == 2 );
1411
- // FIXME We should diagnose this at a location that makes sense:
1412
- auto Vers = swift::version::Version (VersMatches[1 ], SourceLoc (), Diags);
1413
-
1414
- if (CompRe.match (SB, &CompMatches)) {
1415
- assert (CompMatches.size () == 2 );
1416
- CompilerVersion = ArgSaver.save (CompMatches[1 ]).str ();
1417
- }
1418
- else {
1419
- // Don't diagnose; handwritten module interfaces don't include this field.
1420
- CompilerVersion = " (unspecified, file possibly handwritten)" ;
1421
- }
1422
-
1423
- // For now: we support anything with the same "major version" and assume
1424
- // minor versions might be interesting for debugging, or special-casing a
1425
- // compatible field variant.
1426
- if (Vers.asMajorVersion () != InterfaceFormatVersion.asMajorVersion ()) {
1427
- diagnose (interfacePath, diagnosticLoc,
1428
- diag::unsupported_version_of_module_interface, interfacePath, Vers);
1429
- return true ;
1430
- }
1431
1458
1432
1459
SmallString<32 > ExpectedModuleName = subInvocation.getModuleName ();
1433
1460
if (subInvocation.parseArgs (SubArgs, *Diags)) {
0 commit comments