Skip to content

Commit 4c432c4

Browse files
authored
Merge pull request #6998 from rintaro/macros-plugin-search-opts-rdar110819182
2 parents 5eab514 + 3a58867 commit 4c432c4

File tree

1 file changed

+86
-84
lines changed

1 file changed

+86
-84
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 86 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,17 +1219,29 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12191219
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::FrameworkSearchPath,
12201220
getFrameworkSearchPaths(), framework_search_paths,
12211221
.Path);
1222-
INIT_SEARCH_PATH_SET(std::string, PluginSearchPaths, plugin_search_paths, );
1223-
INIT_SEARCH_PATH_SET(swift::ExternalPluginSearchPathAndServerPath,
1224-
ExternalPluginSearchPaths, external_plugin_search_paths,
1225-
.SearchPath);
1226-
INIT_SEARCH_PATH_SET(std::string, getCompilerPluginLibraryPaths(),
1227-
compiler_plugin_library_paths, );
1228-
INIT_SEARCH_PATH_SET(swift::PluginExecutablePathAndModuleNames,
1229-
getCompilerPluginExecutablePaths(),
1230-
compiler_plugin_executable_paths, .ExecutablePath);
1231-
1232-
1222+
1223+
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
1224+
llvm::StringSet<> known_plugin_search_paths;
1225+
llvm::StringSet<> known_external_plugin_search_paths;
1226+
llvm::StringSet<> known_compiler_plugin_library_paths;
1227+
llvm::StringSet<> known_compiler_plugin_executable_paths;
1228+
for (auto &elem : search_path_options.PluginSearchOpts) {
1229+
plugin_search_options.push_back(elem);
1230+
1231+
#define INSERT_PATH_SET(SET, TYPE, KEY) \
1232+
if (auto *opt = elem.dyn_cast<swift::PluginSearchOption::TYPE>()) { \
1233+
known_plugin_search_paths.insert(opt->KEY); \
1234+
continue; \
1235+
}
1236+
INSERT_PATH_SET(known_plugin_search_paths, PluginPath, SearchPath);
1237+
INSERT_PATH_SET(known_external_plugin_search_paths, ExternalPluginPath,
1238+
SearchPath);
1239+
INSERT_PATH_SET(known_compiler_plugin_library_paths, LoadPluginLibrary,
1240+
LibraryPath);
1241+
INSERT_PATH_SET(known_compiler_plugin_executable_paths,
1242+
LoadPluginExecutable, ExecutablePath);
1243+
}
1244+
12331245
// An AST section consists of one or more AST modules, optionally
12341246
// with headers. Iterate over all AST modules.
12351247
for (auto ast_file_data_sp : ast_file_datas) {
@@ -1310,7 +1322,9 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13101322
if (server.empty())
13111323
continue;
13121324
if (exists(path))
1313-
external_plugin_search_paths.push_back({path.str(), server});
1325+
plugin_search_options.emplace_back(
1326+
swift::PluginSearchOption::ExternalPluginPath{path.str(),
1327+
server});
13141328
}
13151329
}
13161330
}
@@ -1327,7 +1341,9 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13271341
continue;
13281342
if (known_external_plugin_search_paths.insert(plugin).second)
13291343
if (exists(plugin))
1330-
external_plugin_search_paths.push_back({plugin.str(), server});
1344+
plugin_search_options.emplace_back(
1345+
swift::PluginSearchOption::ExternalPluginPath{plugin.str(),
1346+
server});
13311347
}
13321348

13331349
for (auto dylib :
@@ -1353,7 +1369,9 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13531369
// means this our translation attempts only work for
13541370
// macro libraries following this convention. cf.
13551371
// PluginLoader::lookupExternalLibraryPluginByModuleName().
1356-
external_plugin_search_paths.push_back({dir.str().str(), server});
1372+
plugin_search_options.emplace_back(
1373+
swift::PluginSearchOption::ExternalPluginPath{dir.str().str(),
1374+
server});
13571375
}
13581376
}
13591377

@@ -1370,8 +1388,9 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13701388
modules_vec.push_back(m.str());
13711389
if (known_compiler_plugin_executable_paths.insert(path).second)
13721390
if (exists(plugin))
1373-
compiler_plugin_executable_paths.push_back(
1374-
{plugin.str(), modules_vec});
1391+
plugin_search_options.emplace_back(
1392+
swift::PluginSearchOption::LoadPluginExecutable{plugin.str(),
1393+
modules_vec});
13751394
}
13761395
return true;
13771396
};
@@ -1390,12 +1409,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13901409
search_path_options.setFrameworkSearchPaths(
13911410
std::move(framework_search_paths));
13921411
// (All PluginSearchPaths were rewritten to be external.)
1393-
search_path_options.ExternalPluginSearchPaths =
1394-
std::move(external_plugin_search_paths);
1395-
search_path_options.setCompilerPluginLibraryPaths(
1396-
std::move(compiler_plugin_library_paths));
1397-
search_path_options.setCompilerPluginExecutablePaths(
1398-
std::move(compiler_plugin_executable_paths));
1412+
search_path_options.PluginSearchOpts = plugin_search_options;
13991413
return found_validation_errors;
14001414
}
14011415

@@ -2000,17 +2014,14 @@ static SwiftASTContext *GetModuleSwiftASTContext(Module &module) {
20002014

20012015
/// Scan a newly added lldb::Module for Swift modules and report any errors in
20022016
/// its module SwiftASTContext to Target.
2003-
static void
2004-
ProcessModule(ModuleSP module_sp, std::string m_description,
2005-
bool discover_implicit_search_paths, bool use_all_compiler_flags,
2006-
Target &target, llvm::Triple triple,
2007-
std::vector<swift::ExternalPluginSearchPathAndServerPath>
2008-
&external_plugin_search_paths,
2009-
std::vector<swift::PluginExecutablePathAndModuleNames>
2010-
&compiler_plugin_executable_paths,
2011-
std::vector<std::string> &module_search_paths,
2012-
std::vector<std::pair<std::string, bool>> &framework_search_paths,
2013-
std::vector<std::string> &extra_clang_args) {
2017+
static void ProcessModule(
2018+
ModuleSP module_sp, std::string m_description,
2019+
bool discover_implicit_search_paths, bool use_all_compiler_flags,
2020+
Target &target, llvm::Triple triple,
2021+
std::vector<swift::PluginSearchOption::Value> &plugin_search_options,
2022+
std::vector<std::string> &module_search_paths,
2023+
std::vector<std::pair<std::string, bool>> &framework_search_paths,
2024+
std::vector<std::string> &extra_clang_args) {
20142025
{
20152026
llvm::raw_string_ostream ss(m_description);
20162027
ss << "::ProcessModule(" << '"';
@@ -2128,13 +2139,9 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
21282139

21292140
// Copy the interesting deserialized flags to the out parameters.
21302141
const auto &opts = invocation.getSearchPathOptions();
2131-
external_plugin_search_paths.insert(external_plugin_search_paths.end(),
2132-
opts.ExternalPluginSearchPaths.begin(),
2133-
opts.ExternalPluginSearchPaths.end());
2134-
compiler_plugin_executable_paths.insert(
2135-
compiler_plugin_executable_paths.end(),
2136-
opts.getCompilerPluginExecutablePaths().begin(),
2137-
opts.getCompilerPluginExecutablePaths().end());
2142+
plugin_search_options.insert(plugin_search_options.end(),
2143+
opts.PluginSearchOpts.begin(),
2144+
opts.PluginSearchOpts.end());
21382145
module_search_paths.insert(module_search_paths.end(),
21392146
opts.getImportSearchPaths().begin(),
21402147
opts.getImportSearchPaths().end());
@@ -2157,10 +2164,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
21572164

21582165
LLDB_SCOPED_TIMER();
21592166
std::string m_description = "SwiftASTContextForExpressions";
2160-
std::vector<swift::ExternalPluginSearchPathAndServerPath>
2161-
external_plugin_search_paths;
2162-
std::vector<swift::PluginExecutablePathAndModuleNames>
2163-
compiler_plugin_executable_paths;
2167+
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
21642168
std::vector<std::string> module_search_paths;
21652169
std::vector<std::pair<std::string, bool>> framework_search_paths;
21662170
TargetSP target_sp = typeref_typesystem.GetTargetWP().lock();
@@ -2334,8 +2338,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23342338
std::vector<std::string> extra_clang_args;
23352339
ProcessModule(target.GetImages().GetModuleAtIndex(mi), m_description,
23362340
discover_implicit_search_paths, use_all_compiler_flags,
2337-
target, triple, external_plugin_search_paths,
2338-
compiler_plugin_executable_paths, module_search_paths,
2341+
target, triple, plugin_search_options, module_search_paths,
23392342
framework_search_paths, extra_clang_args);
23402343
swift_ast_sp->AddExtraClangArgs(extra_clang_args);
23412344
}
@@ -2383,12 +2386,9 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23832386

23842387
// Initialize the compiler plugin search paths.
23852388
auto &opts = swift_ast_sp->GetSearchPathOptions();
2386-
opts.ExternalPluginSearchPaths.insert(opts.ExternalPluginSearchPaths.end(),
2387-
external_plugin_search_paths.begin(),
2388-
external_plugin_search_paths.end());
2389-
assert(opts.getCompilerPluginExecutablePaths().empty());
2390-
opts.setCompilerPluginExecutablePaths(
2391-
std::move(compiler_plugin_executable_paths));
2389+
opts.PluginSearchOpts.insert(opts.PluginSearchOpts.end(),
2390+
plugin_search_options.begin(),
2391+
plugin_search_options.end());
23922392

23932393
for (size_t mi = 0; mi != num_images; ++mi) {
23942394
std::vector<std::string> module_names;
@@ -4629,18 +4629,14 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
46294629
bool use_all_compiler_flags = target_sp->GetUseAllCompilerFlags();
46304630
unsigned num_images = module_list.GetSize();
46314631
for (size_t mi = 0; mi != num_images; ++mi) {
4632-
std::vector<swift::ExternalPluginSearchPathAndServerPath>
4633-
external_plugin_search_paths;
4634-
std::vector<swift::PluginExecutablePathAndModuleNames>
4635-
compiler_plugin_executable_paths;
4632+
std::vector<swift::PluginSearchOption::Value> plugin_search_options;
46364633
std::vector<std::string> module_search_paths;
46374634
std::vector<std::pair<std::string, bool>> framework_search_paths;
46384635
std::vector<std::string> extra_clang_args;
46394636
lldb::ModuleSP module_sp = module_list.GetModuleAtIndex(mi);
46404637
ProcessModule(module_sp, m_description, discover_implicit_search_paths,
46414638
use_all_compiler_flags, *target_sp, GetTriple(),
4642-
external_plugin_search_paths,
4643-
compiler_plugin_executable_paths, module_search_paths,
4639+
plugin_search_options, module_search_paths,
46444640
framework_search_paths, extra_clang_args);
46454641
// If the use-all-compiler-flags setting is enabled, the
46464642
// expression context is supposed to merge all search paths
@@ -4736,33 +4732,39 @@ void SwiftASTContext::LogConfiguration() {
47364732
HEALTH_LOG_PRINTF(" %s", extra_arg.c_str());
47374733
}
47384734

4739-
#define PRINT_PLUGIN_PATHS(ACCESSOR, NAME, TEMPLATE, ...) \
4740-
{ \
4741-
auto paths = m_ast_context_ap->SearchPathOpts.ACCESSOR; \
4742-
HEALTH_LOG_PRINTF(" %s: (%llu items)", NAME, \
4743-
(unsigned long long)paths.size()); \
4744-
for (auto &path : paths) { \
4745-
HEALTH_LOG_PRINTF(" " TEMPLATE, ##__VA_ARGS__); \
4746-
} \
4735+
HEALTH_LOG_PRINTF(" Plugin search options : (%llu items)",
4736+
(unsigned long long)m_ast_context_ap->SearchPathOpts
4737+
.PluginSearchOpts.size());
4738+
for (auto &elem : m_ast_context_ap->SearchPathOpts.PluginSearchOpts) {
4739+
if (auto *opt =
4740+
elem.dyn_cast<swift::PluginSearchOption::LoadPluginLibrary>()) {
4741+
HEALTH_LOG_PRINTF(" -load-plugin-library %s",
4742+
opt->LibraryPath.c_str());
4743+
continue;
4744+
}
4745+
if (auto *opt =
4746+
elem.dyn_cast<swift::PluginSearchOption::LoadPluginExecutable>()) {
4747+
HEALTH_LOG_PRINTF(" -load-plugin-executable %s#%s",
4748+
opt->ExecutablePath.c_str(),
4749+
[](auto path_names) -> std::string {
4750+
std::string s;
4751+
llvm::raw_string_ostream os(s);
4752+
llvm::interleaveComma(path_names, os);
4753+
return os.str();
4754+
}(opt->ModuleNames)
4755+
.c_str());
4756+
continue;
4757+
}
4758+
if (auto *opt = elem.dyn_cast<swift::PluginSearchOption::PluginPath>()) {
4759+
HEALTH_LOG_PRINTF(" -plugin-path %s", opt->SearchPath.c_str());
4760+
continue;
4761+
}
4762+
if (auto *opt =
4763+
elem.dyn_cast<swift::PluginSearchOption::ExternalPluginPath>()) {
4764+
HEALTH_LOG_PRINTF(" -external-plugin-path %s#%s",
4765+
opt->SearchPath.c_str(), opt->ServerPath.c_str());
4766+
}
47474767
}
4748-
PRINT_PLUGIN_PATHS(getCompilerPluginLibraryPaths(),
4749-
"Compiler Plugin Library Paths ",
4750-
"%s", path.c_str());
4751-
PRINT_PLUGIN_PATHS(getCompilerPluginExecutablePaths(),
4752-
"Compiler Plugin Executable Paths ", "%s: [%s]",
4753-
path.ExecutablePath.c_str(),
4754-
[](auto path_names) -> std::string {
4755-
std::string s;
4756-
llvm::raw_string_ostream os(s);
4757-
llvm::interleaveComma(path_names, os);
4758-
return os.str();
4759-
}(path.ModuleNames)
4760-
.c_str());
4761-
PRINT_PLUGIN_PATHS(PluginSearchPaths, "Plugin search paths ",
4762-
"%s", path.c_str());
4763-
PRINT_PLUGIN_PATHS(ExternalPluginSearchPaths,
4764-
"External plugin search paths ", "%s (server: %s)",
4765-
path.SearchPath.c_str(), path.ServerPath.c_str());
47664768
}
47674769

47684770
bool SwiftASTContext::HasTarget() {

0 commit comments

Comments
 (0)