@@ -1311,87 +1311,91 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1311
1311
return false ;
1312
1312
};
1313
1313
1314
- // Discover, rewrite, and unique compiler plugin paths.
1315
- for (auto path : extended_validation_info.getPluginSearchPaths ()) {
1316
- // System plugins shipping with the compiler.
1317
- // Rewrite them to go through an ABI-compatible swift-plugin-server.
1318
- if (known_plugin_search_paths.insert (path).second ) {
1319
- if (known_external_plugin_search_paths.insert (path).second ) {
1320
- std::string server = get_plugin_server (
1321
- path, [&]() { return GetPluginServer (path); });
1322
- if (server.empty ())
1323
- continue ;
1324
- if (exists (path))
1325
- plugin_search_options.emplace_back (
1326
- swift::PluginSearchOption::ExternalPluginPath{path.str (),
1327
- server});
1314
+ for (auto &opt : extended_validation_info.getPluginSearchOptions ()) {
1315
+ if (opt.first == " -plugin-path" ) {
1316
+ StringRef path = opt.second ;
1317
+ // System plugins shipping with the compiler.
1318
+ // Rewrite them to go through an ABI-compatible swift-plugin-server.
1319
+ if (known_plugin_search_paths.insert (path).second ) {
1320
+ if (known_external_plugin_search_paths.insert (path).second ) {
1321
+ std::string server = get_plugin_server (
1322
+ path, [&]() { return GetPluginServer (path); });
1323
+ if (server.empty ())
1324
+ continue ;
1325
+ if (exists (path))
1326
+ plugin_search_options.emplace_back (
1327
+ swift::PluginSearchOption::ExternalPluginPath{path.str (),
1328
+ server});
1329
+ }
1328
1330
}
1331
+ continue ;
1329
1332
}
1330
- }
1331
- for (auto path :
1332
- extended_validation_info.getExternalPluginSearchPaths ()) {
1333
- // Sandboxed system plugins shipping with some compiler.
1334
- // Keep the original plugin server path, it needs to be ABI
1335
- // compatible with the version of SwiftSyntax used by the plugin.
1336
- auto plugin_server = path.split (' #' );
1337
- llvm::StringRef plugin = plugin_server.first ;
1338
- std::string server = get_plugin_server (
1339
- plugin, [&]() { return plugin_server.second .str (); });
1340
- if (server.empty ())
1333
+ if (opt.first == " -external-plugin-path" ) {
1334
+ // Sandboxed system plugins shipping with some compiler.
1335
+ // Keep the original plugin server path, it needs to be ABI
1336
+ // compatible with the version of SwiftSyntax used by the plugin.
1337
+ auto plugin_server = opt.second .split (' #' );
1338
+ llvm::StringRef plugin = plugin_server.first ;
1339
+ std::string server = get_plugin_server (
1340
+ plugin, [&]() { return plugin_server.second .str (); });
1341
+ if (server.empty ())
1342
+ continue ;
1343
+ if (known_external_plugin_search_paths.insert (plugin).second )
1344
+ if (exists (plugin))
1345
+ plugin_search_options.emplace_back (
1346
+ swift::PluginSearchOption::ExternalPluginPath{plugin.str (),
1347
+ server});
1341
1348
continue ;
1342
- if (known_external_plugin_search_paths.insert (plugin).second )
1343
- if (exists (plugin))
1344
- plugin_search_options.emplace_back (
1345
- swift::PluginSearchOption::ExternalPluginPath{plugin.str (),
1346
- server});
1347
- }
1349
+ }
1350
+ if (opt.first == " -load-plugin-library" ) {
1351
+ // Compiler plugin libraries.
1352
+ StringRef dylib = opt.second ;
1353
+ if (known_compiler_plugin_library_paths.insert (dylib).second )
1354
+ if (exists (dylib)) {
1355
+ // We never want to directly load any plugins, since a crash in
1356
+ // the plugin would bring down LLDB. Here, we assume that the
1357
+ // correct plugin server for a direct compiler plugin is the one
1358
+ // from the SDK the compiler was building for. This is just a
1359
+ // heuristic.
1360
+ // This works because the Swift compiler enforces
1361
+ // '-load-plugin-library' dylibs to be named
1362
+ // libModuleName.[dylib|so|dll] just like
1363
+ // '-external-plugin-path'.
1364
+ llvm::SmallString<0 > dir (dylib);
1365
+ llvm::sys::path::remove_filename (dir);
1366
+ std::string server = get_plugin_server (dir, [&]() {
1367
+ return GetPluginServerForSDK (invocation.getSDKPath ());
1368
+ });
1369
+ if (server.empty ())
1370
+ continue ;
1348
1371
1349
- for (auto dylib :
1350
- extended_validation_info.getCompilerPluginLibraryPaths ()) {
1351
- // Compiler plugin libraries.
1352
- if (known_compiler_plugin_library_paths.insert (dylib).second )
1353
- if (exists (dylib)) {
1354
- // We never want to directly load any plugins, since a crash in
1355
- // the plugin would bring down LLDB. Here, we assume that the
1356
- // correct plugin server for a direct compiler plugin is the one
1357
- // from the SDK the compiler was building for. This is just a
1358
- // heuristic.
1359
- llvm::SmallString<0 > dir (dylib);
1360
- llvm::sys::path::remove_filename (dir);
1361
- std::string server = get_plugin_server (dir, [&]() {
1362
- return GetPluginServerForSDK (invocation.getSDKPath ());
1363
- });
1364
- if (server.empty ())
1365
- continue ;
1366
-
1367
- // FIXME: The Swift compiler expects external plugins
1368
- // to be named libModuleName.[dylib|so|dll]. This
1369
- // means this our translation attempts only work for
1370
- // macro libraries following this convention. cf.
1371
- // PluginLoader::lookupExternalLibraryPluginByModuleName().
1372
- plugin_search_options.emplace_back (
1373
- swift::PluginSearchOption::ExternalPluginPath{dir.str ().str (),
1374
- server});
1375
- }
1372
+ plugin_search_options.emplace_back (
1373
+ swift::PluginSearchOption::ExternalPluginPath{
1374
+ dir.str ().str (), server});
1375
+ }
1376
+ continue ;
1377
+ }
1378
+ if (opt.first == " -load-plugin-executable" ) {
1379
+ // Compiler plugin executables.
1380
+ auto plugin_modules = opt.second .split (' #' );
1381
+ llvm::StringRef plugin = plugin_modules.first ;
1382
+ llvm::StringRef modules_list = plugin_modules.second ;
1383
+ llvm::SmallVector<llvm::StringRef, 0 > modules;
1384
+ modules_list.split (modules, " ," );
1385
+ std::vector<std::string> modules_vec;
1386
+ for (auto m : modules)
1387
+ modules_vec.push_back (m.str ());
1388
+ if (known_compiler_plugin_executable_paths.insert (opt.second )
1389
+ .second )
1390
+ if (exists (plugin))
1391
+ plugin_search_options.emplace_back (
1392
+ swift::PluginSearchOption::LoadPluginExecutable{
1393
+ plugin.str (), modules_vec});
1394
+ continue ;
1395
+ }
1396
+ llvm_unreachable (" unhandled plugin search option kind" );
1376
1397
}
1377
1398
1378
- for (auto path :
1379
- extended_validation_info.getCompilerPluginExecutablePaths ()) {
1380
- // Compiler plugin executables.
1381
- auto plugin_modules = path.split (' #' );
1382
- llvm::StringRef plugin = plugin_modules.first ;
1383
- llvm::StringRef modules_list = plugin_modules.second ;
1384
- llvm::SmallVector<llvm::StringRef, 0 > modules;
1385
- modules_list.split (modules, " ," );
1386
- std::vector<std::string> modules_vec;
1387
- for (auto m : modules)
1388
- modules_vec.push_back (m.str ());
1389
- if (known_compiler_plugin_executable_paths.insert (path).second )
1390
- if (exists (plugin))
1391
- plugin_search_options.emplace_back (
1392
- swift::PluginSearchOption::LoadPluginExecutable{plugin.str (),
1393
- modules_vec});
1394
- }
1395
1399
return true ;
1396
1400
};
1397
1401
0 commit comments