Skip to content

[Extra PR for CI][lldb] Adjust to swift::SearchPathOptions enhancing the ImportSearchPaths type #9790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,9 +1312,10 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
known_##NAME.insert(path KEY); \
}

INIT_SEARCH_PATH_SET(std::string, getImportSearchPaths(),
import_search_paths, );
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::FrameworkSearchPath,
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::SearchPath,
getImportSearchPaths(), import_search_paths,
.Path);
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::SearchPath,
getFrameworkSearchPaths(), framework_search_paths,
.Path);

Expand Down Expand Up @@ -1398,10 +1399,12 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
for (auto &searchPath : searchPaths) {
std::string path = remap(searchPath.Path);
if (!searchPath.IsFramework) {
swift::SearchPathOptions::SearchPath
import_search_path(path, searchPath.IsSystem);
if (known_import_search_paths.insert(path).second)
import_search_paths.push_back(path);
import_search_paths.push_back(import_search_path);
} else {
swift::SearchPathOptions::FrameworkSearchPath
swift::SearchPathOptions::SearchPath
framework_search_path(path, searchPath.IsSystem);
if (known_framework_search_paths.insert(path).second)
framework_search_paths.push_back(framework_search_path);
Expand Down Expand Up @@ -1801,7 +1804,7 @@ static void applyOverrideOptions(std::vector<std::string> &args,

void SwiftASTContext::AddExtraClangArgs(
const std::vector<std::string> &ExtraArgs,
const std::vector<std::string> &module_search_paths,
const std::vector<std::pair<std::string, bool>> module_search_paths,
const std::vector<std::pair<std::string, bool>> framework_search_paths,
StringRef overrideOpts) {
swift::ClangImporterOptions &importer_options = GetClangImporterOptions();
Expand Down Expand Up @@ -1850,7 +1853,7 @@ void SwiftASTContext::AddExtraClangArgs(

void SwiftASTContext::AddExtraClangCC1Args(
const std::vector<std::string> &source,
const std::vector<std::string> &module_search_paths,
const std::vector<std::pair<std::string, bool>> module_search_paths,
const std::vector<std::pair<std::string, bool>> framework_search_paths,
std::vector<std::string> &dest) {
clang::CompilerInvocation invocation;
Expand All @@ -1871,7 +1874,7 @@ void SwiftASTContext::AddExtraClangCC1Args(
// additional clang modules when doing type reconstruction.
for (auto &path : module_search_paths) {
clangArgs.push_back("-I");
clangArgs.push_back(path.c_str());
clangArgs.push_back(path.first.c_str());
}
for (auto &path : default_paths) {
llvm::SmallString<128> search_path(GetPlatformSDKPath());
Expand Down Expand Up @@ -2204,7 +2207,7 @@ ProcessModule(Module &module, std::string m_description,
bool is_main_executable, StringRef module_filter,
llvm::Triple triple,
std::vector<swift::PluginSearchOption> &plugin_search_options,
std::vector<std::string> &module_search_paths,
std::vector<std::pair<std::string, bool>> &module_search_paths,
std::vector<std::pair<std::string, bool>> &framework_search_paths,
std::vector<std::string> &extra_clang_args,
std::string &error) {
Expand Down Expand Up @@ -2301,7 +2304,7 @@ ProcessModule(Module &module, std::string m_description,
bool exists = false;
llvm::sys::fs::is_directory(path, exists);
if (exists)
module_search_paths.push_back(std::string(path));
module_search_paths.push_back({std::string(path), /*system*/ false});
}

// Create a one-off CompilerInvocation as a place to load the
Expand Down Expand Up @@ -2334,9 +2337,8 @@ ProcessModule(Module &module, std::string m_description,
plugin_search_options.insert(plugin_search_options.end(),
opts.PluginSearchOpts.begin(),
opts.PluginSearchOpts.end());
module_search_paths.insert(module_search_paths.end(),
opts.getImportSearchPaths().begin(),
opts.getImportSearchPaths().end());
for (auto path : opts.getImportSearchPaths())
module_search_paths.push_back({path.Path, path.IsSystem});
for (auto path : opts.getFrameworkSearchPaths())
framework_search_paths.push_back({path.Path, path.IsSystem});
auto &clang_opts = invocation.getClangImporterOptions().ExtraArgs;
Expand Down Expand Up @@ -2373,7 +2375,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
ss << '"' << ')';
}
LLDB_SCOPED_TIMERF("%s::CreateInstance", m_description.c_str());
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;

LOG_PRINTF(GetLog(LLDBLog::Types), "(Module)");
Expand Down Expand Up @@ -3025,7 +3027,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
ConfigureModuleCachePath(*swift_ast_sp);

std::vector<swift::PluginSearchOption> plugin_search_options;
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;
std::vector<std::string> extra_clang_args;

Expand All @@ -3037,10 +3039,11 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
use_all_compiler_flags =
!got_serialized_options || target_sp->GetUseAllCompilerFlags();

const bool is_system = false;

for (const FileSpec &path : target_sp->GetSwiftModuleSearchPaths())
module_search_paths.push_back(path.GetPath());
module_search_paths.push_back({path.GetPath(), is_system});

const bool is_system = false;
for (const FileSpec &path : target_sp->GetSwiftFrameworkSearchPaths())
framework_search_paths.push_back({path.GetPath(), is_system});
}
Expand Down Expand Up @@ -3528,7 +3531,7 @@ swift::SearchPathOptions &SwiftASTContext::GetSearchPathOptions() {
}

void SwiftASTContext::InitializeSearchPathOptions(
llvm::ArrayRef<std::string> extra_module_search_paths,
llvm::ArrayRef<std::pair<std::string, bool>> extra_module_search_paths,
llvm::ArrayRef<std::pair<std::string, bool>> extra_framework_search_paths) {
LLDB_SCOPED_TIMER();
swift::CompilerInvocation &invocation = GetCompilerInvocation();
Expand Down Expand Up @@ -3607,24 +3610,24 @@ void SwiftASTContext::InitializeSearchPathOptions(
}

llvm::StringMap<bool> processed;
std::vector<std::string> invocation_import_paths(
std::vector<swift::SearchPathOptions::SearchPath> invocation_import_paths(
invocation.getSearchPathOptions().getImportSearchPaths());
// Add all deserialized paths to the map.
for (const auto &path : invocation_import_paths)
processed.insert({path, false});
processed.insert({path.Path, path.IsSystem});

// Add/unique all extra paths.
for (const auto &path : extra_module_search_paths) {
auto it_notseen = processed.insert({path, false});
auto it_notseen = processed.insert(path);
if (it_notseen.second)
invocation_import_paths.push_back(path);
invocation_import_paths.push_back({path.first, path.second});
}
invocation.getSearchPathOptions().setImportSearchPaths(
invocation_import_paths);

// This preserves the IsSystem bit, but deduplicates entries ignoring it.
processed.clear();
std::vector<swift::SearchPathOptions::FrameworkSearchPath>
std::vector<swift::SearchPathOptions::SearchPath>
invocation_framework_paths(
invocation.getSearchPathOptions().getFrameworkSearchPaths());
// Add all deserialized paths to the map.
Expand Down Expand Up @@ -4049,7 +4052,7 @@ SwiftASTContext::GetModule(const FileSpec &module_spec) {
std::string module_directory(module_spec.GetDirectory().GetCString());
bool add_search_path = true;
for (auto path : ast->SearchPathOpts.getImportSearchPaths()) {
if (path == module_directory) {
if (path.Path == module_directory) {
add_search_path = false;
break;
}
Expand Down Expand Up @@ -5462,7 +5465,7 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
unsigned num_images = module_list.GetSize();
for (size_t mi = 0; mi != num_images; ++mi) {
std::vector<swift::PluginSearchOption> plugin_search_options;
std::vector<std::string> module_search_paths;
std::vector<std::pair<std::string, bool>> module_search_paths;
std::vector<std::pair<std::string, bool>> framework_search_paths;
std::vector<std::string> extra_clang_args;
lldb::ModuleSP module_sp = module_list.GetModuleAtIndex(mi);
Expand Down Expand Up @@ -5556,9 +5559,9 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
(unsigned long long)m_ast_context_ap->SearchPathOpts
.getImportSearchPaths()
.size());
for (const std::string &import_search_path :
for (const auto &import_search_path :
m_ast_context_ap->SearchPathOpts.getImportSearchPaths())
HEALTH_LOG_PRINTF(" %s", import_search_path.c_str());
HEALTH_LOG_PRINTF(" %s", import_search_path.Path.c_str());

swift::ClangImporterOptions &clang_importer_options =
GetClangImporterOptions();
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class SwiftASTContext : public TypeSystemSwift {
swift::SerializationOptions &GetSerializationOptions();

void InitializeSearchPathOptions(
llvm::ArrayRef<std::string> module_search_paths,
llvm::ArrayRef<std::pair<std::string, bool>> module_search_paths,
llvm::ArrayRef<std::pair<std::string, bool>> framework_search_paths);

swift::ClangImporterOptions &GetClangImporterOptions();
Expand All @@ -277,13 +277,13 @@ class SwiftASTContext : public TypeSystemSwift {
/// apply the working directory to any relative paths.
void AddExtraClangArgs(
const std::vector<std::string> &ExtraArgs,
const std::vector<std::string> &module_search_paths,
const std::vector<std::pair<std::string, bool>> module_search_paths,
const std::vector<std::pair<std::string, bool>> framework_search_paths,
llvm::StringRef overrideOpts = "");

void AddExtraClangCC1Args(
const std::vector<std::string> &source,
const std::vector<std::string> &module_search_paths,
const std::vector<std::pair<std::string, bool>> module_search_paths,
const std::vector<std::pair<std::string, bool>> framework_search_paths,
std::vector<std::string> &dest);
static void AddExtraClangArgs(const std::vector<std::string>& source,
Expand Down