@@ -1220,7 +1220,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1220
1220
getFrameworkSearchPaths (), framework_search_paths,
1221
1221
.Path );
1222
1222
1223
- std::vector<swift::PluginSearchOption::Value > plugin_search_options;
1223
+ std::vector<swift::PluginSearchOption> plugin_search_options;
1224
1224
llvm::StringSet<> known_plugin_search_paths;
1225
1225
llvm::StringSet<> known_external_plugin_search_paths;
1226
1226
llvm::StringSet<> known_compiler_plugin_library_paths;
@@ -1311,87 +1311,93 @@ 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
+ switch (opt.first ) {
1316
+ case swift::PluginSearchOption::Kind::PluginPath: {
1317
+ StringRef path = opt.second ;
1318
+ // System plugins shipping with the compiler.
1319
+ // Rewrite them to go through an ABI-compatible swift-plugin-server.
1320
+ if (known_plugin_search_paths.insert (path).second ) {
1321
+ if (known_external_plugin_search_paths.insert (path).second ) {
1322
+ std::string server = get_plugin_server (
1323
+ path, [&]() { return GetPluginServer (path); });
1324
+ if (server.empty ())
1325
+ continue ;
1326
+ if (exists (path))
1327
+ plugin_search_options.emplace_back (
1328
+ swift::PluginSearchOption::ExternalPluginPath{path.str (),
1329
+ server});
1330
+ }
1328
1331
}
1332
+ continue ;
1329
1333
}
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 ())
1334
+ case swift::PluginSearchOption::Kind::ExternalPluginPath: {
1335
+ // Sandboxed system plugins shipping with some compiler.
1336
+ // Keep the original plugin server path, it needs to be ABI
1337
+ // compatible with the version of SwiftSyntax used by the plugin.
1338
+ auto plugin_server = opt.second .split (' #' );
1339
+ llvm::StringRef plugin = plugin_server.first ;
1340
+ std::string server = get_plugin_server (
1341
+ plugin, [&]() { return plugin_server.second .str (); });
1342
+ if (server.empty ())
1343
+ continue ;
1344
+ if (known_external_plugin_search_paths.insert (plugin).second )
1345
+ if (exists (plugin))
1346
+ plugin_search_options.emplace_back (
1347
+ swift::PluginSearchOption::ExternalPluginPath{plugin.str (),
1348
+ server});
1341
1349
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
- }
1350
+ }
1351
+ case swift::PluginSearchOption::Kind::LoadPluginLibrary: {
1352
+ // Compiler plugin libraries.
1353
+ StringRef dylib = opt.second ;
1354
+ if (known_compiler_plugin_library_paths.insert (dylib).second )
1355
+ if (exists (dylib)) {
1356
+ // We never want to directly load any plugins, since a crash in
1357
+ // the plugin would bring down LLDB. Here, we assume that the
1358
+ // correct plugin server for a direct compiler plugin is the one
1359
+ // from the SDK the compiler was building for. This is just a
1360
+ // heuristic.
1361
+ // This works because the Swift compiler enforces
1362
+ // '-load-plugin-library' dylibs to be named
1363
+ // libModuleName.[dylib|so|dll] just like
1364
+ // '-external-plugin-path'.
1365
+ llvm::SmallString<0 > dir (dylib);
1366
+ llvm::sys::path::remove_filename (dir);
1367
+ std::string server = get_plugin_server (dir, [&]() {
1368
+ return GetPluginServerForSDK (invocation.getSDKPath ());
1369
+ });
1370
+ if (server.empty ())
1371
+ continue ;
1348
1372
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
- }
1373
+ plugin_search_options.emplace_back (
1374
+ swift::PluginSearchOption::ExternalPluginPath{
1375
+ dir.str ().str (), server});
1376
+ }
1377
+ continue ;
1378
+ }
1379
+ case swift::PluginSearchOption::Kind::LoadPluginExecutable: {
1380
+ // Compiler plugin executables.
1381
+ auto plugin_modules = opt.second .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 (opt.second )
1390
+ .second )
1391
+ if (exists (plugin))
1392
+ plugin_search_options.emplace_back (
1393
+ swift::PluginSearchOption::LoadPluginExecutable{
1394
+ plugin.str (), modules_vec});
1395
+ continue ;
1396
+ }
1397
+ }
1398
+ llvm_unreachable (" unhandled plugin search option kind" );
1376
1399
}
1377
1400
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
1401
return true ;
1396
1402
};
1397
1403
@@ -2018,7 +2024,7 @@ static void ProcessModule(
2018
2024
ModuleSP module_sp, std::string m_description,
2019
2025
bool discover_implicit_search_paths, bool use_all_compiler_flags,
2020
2026
Target &target, llvm::Triple triple,
2021
- std::vector<swift::PluginSearchOption::Value > &plugin_search_options,
2027
+ std::vector<swift::PluginSearchOption> &plugin_search_options,
2022
2028
std::vector<std::string> &module_search_paths,
2023
2029
std::vector<std::pair<std::string, bool >> &framework_search_paths,
2024
2030
std::vector<std::string> &extra_clang_args) {
@@ -2164,7 +2170,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
2164
2170
2165
2171
LLDB_SCOPED_TIMER ();
2166
2172
std::string m_description = " SwiftASTContextForExpressions" ;
2167
- std::vector<swift::PluginSearchOption::Value > plugin_search_options;
2173
+ std::vector<swift::PluginSearchOption> plugin_search_options;
2168
2174
std::vector<std::string> module_search_paths;
2169
2175
std::vector<std::pair<std::string, bool >> framework_search_paths;
2170
2176
TargetSP target_sp = typeref_typesystem.GetTargetWP ().lock ();
@@ -4629,7 +4635,7 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
4629
4635
bool use_all_compiler_flags = target_sp->GetUseAllCompilerFlags ();
4630
4636
unsigned num_images = module_list.GetSize ();
4631
4637
for (size_t mi = 0 ; mi != num_images; ++mi) {
4632
- std::vector<swift::PluginSearchOption::Value > plugin_search_options;
4638
+ std::vector<swift::PluginSearchOption> plugin_search_options;
4633
4639
std::vector<std::string> module_search_paths;
4634
4640
std::vector<std::pair<std::string, bool >> framework_search_paths;
4635
4641
std::vector<std::string> extra_clang_args;
0 commit comments