Skip to content

Commit 6343230

Browse files
Merge pull request #9780 from ian-twilightcoder/swift-import-paths
[lldb] Adjust to swift::SearchPathOptions enhancing the ImportSearchPaths type
2 parents e95ed6c + 6eef766 commit 6343230

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

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

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,10 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13111311
known_##NAME.insert(path KEY); \
13121312
}
13131313

1314-
INIT_SEARCH_PATH_SET(std::string, getImportSearchPaths(),
1315-
import_search_paths, );
1316-
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::FrameworkSearchPath,
1314+
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::SearchPath,
1315+
getImportSearchPaths(), import_search_paths,
1316+
.Path);
1317+
INIT_SEARCH_PATH_SET(swift::SearchPathOptions::SearchPath,
13171318
getFrameworkSearchPaths(), framework_search_paths,
13181319
.Path);
13191320

@@ -1397,10 +1398,12 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
13971398
for (auto &searchPath : searchPaths) {
13981399
std::string path = remap(searchPath.Path);
13991400
if (!searchPath.IsFramework) {
1401+
swift::SearchPathOptions::SearchPath
1402+
import_search_path(path, searchPath.IsSystem);
14001403
if (known_import_search_paths.insert(path).second)
1401-
import_search_paths.push_back(path);
1404+
import_search_paths.push_back(import_search_path);
14021405
} else {
1403-
swift::SearchPathOptions::FrameworkSearchPath
1406+
swift::SearchPathOptions::SearchPath
14041407
framework_search_path(path, searchPath.IsSystem);
14051408
if (known_framework_search_paths.insert(path).second)
14061409
framework_search_paths.push_back(framework_search_path);
@@ -1800,7 +1803,7 @@ static void applyOverrideOptions(std::vector<std::string> &args,
18001803

18011804
void SwiftASTContext::AddExtraClangArgs(
18021805
const std::vector<std::string> &ExtraArgs,
1803-
const std::vector<std::string> &module_search_paths,
1806+
const std::vector<std::pair<std::string, bool>> module_search_paths,
18041807
const std::vector<std::pair<std::string, bool>> framework_search_paths,
18051808
StringRef overrideOpts) {
18061809
swift::ClangImporterOptions &importer_options = GetClangImporterOptions();
@@ -1849,7 +1852,7 @@ void SwiftASTContext::AddExtraClangArgs(
18491852

18501853
void SwiftASTContext::AddExtraClangCC1Args(
18511854
const std::vector<std::string> &source,
1852-
const std::vector<std::string> &module_search_paths,
1855+
const std::vector<std::pair<std::string, bool>> module_search_paths,
18531856
const std::vector<std::pair<std::string, bool>> framework_search_paths,
18541857
std::vector<std::string> &dest) {
18551858
clang::CompilerInvocation invocation;
@@ -1870,7 +1873,7 @@ void SwiftASTContext::AddExtraClangCC1Args(
18701873
// additional clang modules when doing type reconstruction.
18711874
for (auto &path : module_search_paths) {
18721875
clangArgs.push_back("-I");
1873-
clangArgs.push_back(path.c_str());
1876+
clangArgs.push_back(path.first.c_str());
18741877
}
18751878
for (auto &path : default_paths) {
18761879
llvm::SmallString<128> search_path(GetPlatformSDKPath());
@@ -2203,7 +2206,7 @@ ProcessModule(Module &module, std::string m_description,
22032206
bool is_main_executable, StringRef module_filter,
22042207
llvm::Triple triple,
22052208
std::vector<swift::PluginSearchOption> &plugin_search_options,
2206-
std::vector<std::string> &module_search_paths,
2209+
std::vector<std::pair<std::string, bool>> &module_search_paths,
22072210
std::vector<std::pair<std::string, bool>> &framework_search_paths,
22082211
std::vector<std::string> &extra_clang_args,
22092212
std::string &error) {
@@ -2300,7 +2303,7 @@ ProcessModule(Module &module, std::string m_description,
23002303
bool exists = false;
23012304
llvm::sys::fs::is_directory(path, exists);
23022305
if (exists)
2303-
module_search_paths.push_back(std::string(path));
2306+
module_search_paths.push_back({std::string(path), /*system*/ false});
23042307
}
23052308

23062309
// Create a one-off CompilerInvocation as a place to load the
@@ -2333,9 +2336,8 @@ ProcessModule(Module &module, std::string m_description,
23332336
plugin_search_options.insert(plugin_search_options.end(),
23342337
opts.PluginSearchOpts.begin(),
23352338
opts.PluginSearchOpts.end());
2336-
module_search_paths.insert(module_search_paths.end(),
2337-
opts.getImportSearchPaths().begin(),
2338-
opts.getImportSearchPaths().end());
2339+
for (auto path : opts.getImportSearchPaths())
2340+
module_search_paths.push_back({path.Path, path.IsSystem});
23392341
for (auto path : opts.getFrameworkSearchPaths())
23402342
framework_search_paths.push_back({path.Path, path.IsSystem});
23412343
auto &clang_opts = invocation.getClangImporterOptions().ExtraArgs;
@@ -2372,7 +2374,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
23722374
ss << '"' << ')';
23732375
}
23742376
LLDB_SCOPED_TIMERF("%s::CreateInstance", m_description.c_str());
2375-
std::vector<std::string> module_search_paths;
2377+
std::vector<std::pair<std::string, bool>> module_search_paths;
23762378
std::vector<std::pair<std::string, bool>> framework_search_paths;
23772379

23782380
LOG_PRINTF(GetLog(LLDBLog::Types), "(Module)");
@@ -3024,7 +3026,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
30243026
ConfigureModuleCachePath(*swift_ast_sp);
30253027

30263028
std::vector<swift::PluginSearchOption> plugin_search_options;
3027-
std::vector<std::string> module_search_paths;
3029+
std::vector<std::pair<std::string, bool>> module_search_paths;
30283030
std::vector<std::pair<std::string, bool>> framework_search_paths;
30293031
std::vector<std::string> extra_clang_args;
30303032

@@ -3036,10 +3038,11 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
30363038
use_all_compiler_flags =
30373039
!got_serialized_options || target_sp->GetUseAllCompilerFlags();
30383040

3041+
const bool is_system = false;
3042+
30393043
for (const FileSpec &path : target_sp->GetSwiftModuleSearchPaths())
3040-
module_search_paths.push_back(path.GetPath());
3044+
module_search_paths.push_back({path.GetPath(), is_system});
30413045

3042-
const bool is_system = false;
30433046
for (const FileSpec &path : target_sp->GetSwiftFrameworkSearchPaths())
30443047
framework_search_paths.push_back({path.GetPath(), is_system});
30453048
}
@@ -3523,7 +3526,7 @@ swift::SearchPathOptions &SwiftASTContext::GetSearchPathOptions() {
35233526
}
35243527

35253528
void SwiftASTContext::InitializeSearchPathOptions(
3526-
llvm::ArrayRef<std::string> extra_module_search_paths,
3529+
llvm::ArrayRef<std::pair<std::string, bool>> extra_module_search_paths,
35273530
llvm::ArrayRef<std::pair<std::string, bool>> extra_framework_search_paths) {
35283531
LLDB_SCOPED_TIMER();
35293532
swift::CompilerInvocation &invocation = GetCompilerInvocation();
@@ -3602,24 +3605,24 @@ void SwiftASTContext::InitializeSearchPathOptions(
36023605
}
36033606

36043607
llvm::StringMap<bool> processed;
3605-
std::vector<std::string> invocation_import_paths(
3608+
std::vector<swift::SearchPathOptions::SearchPath> invocation_import_paths(
36063609
invocation.getSearchPathOptions().getImportSearchPaths());
36073610
// Add all deserialized paths to the map.
36083611
for (const auto &path : invocation_import_paths)
3609-
processed.insert({path, false});
3612+
processed.insert({path.Path, path.IsSystem});
36103613

36113614
// Add/unique all extra paths.
36123615
for (const auto &path : extra_module_search_paths) {
3613-
auto it_notseen = processed.insert({path, false});
3616+
auto it_notseen = processed.insert(path);
36143617
if (it_notseen.second)
3615-
invocation_import_paths.push_back(path);
3618+
invocation_import_paths.push_back({path.first, path.second});
36163619
}
36173620
invocation.getSearchPathOptions().setImportSearchPaths(
36183621
invocation_import_paths);
36193622

36203623
// This preserves the IsSystem bit, but deduplicates entries ignoring it.
36213624
processed.clear();
3622-
std::vector<swift::SearchPathOptions::FrameworkSearchPath>
3625+
std::vector<swift::SearchPathOptions::SearchPath>
36233626
invocation_framework_paths(
36243627
invocation.getSearchPathOptions().getFrameworkSearchPaths());
36253628
// Add all deserialized paths to the map.
@@ -4045,7 +4048,7 @@ SwiftASTContext::GetModule(const FileSpec &module_spec) {
40454048
std::string module_directory(module_spec.GetDirectory().GetCString());
40464049
bool add_search_path = true;
40474050
for (auto path : ast->SearchPathOpts.getImportSearchPaths()) {
4048-
if (path == module_directory) {
4051+
if (path.Path == module_directory) {
40494052
add_search_path = false;
40504053
break;
40514054
}
@@ -5458,7 +5461,7 @@ void SwiftASTContextForExpressions::ModulesDidLoad(ModuleList &module_list) {
54585461
unsigned num_images = module_list.GetSize();
54595462
for (size_t mi = 0; mi != num_images; ++mi) {
54605463
std::vector<swift::PluginSearchOption> plugin_search_options;
5461-
std::vector<std::string> module_search_paths;
5464+
std::vector<std::pair<std::string, bool>> module_search_paths;
54625465
std::vector<std::pair<std::string, bool>> framework_search_paths;
54635466
std::vector<std::string> extra_clang_args;
54645467
lldb::ModuleSP module_sp = module_list.GetModuleAtIndex(mi);
@@ -5552,9 +5555,9 @@ void SwiftASTContext::LogConfiguration(bool is_repl) {
55525555
(unsigned long long)m_ast_context_ap->SearchPathOpts
55535556
.getImportSearchPaths()
55545557
.size());
5555-
for (const std::string &import_search_path :
5558+
for (const auto &import_search_path :
55565559
m_ast_context_ap->SearchPathOpts.getImportSearchPaths())
5557-
HEALTH_LOG_PRINTF(" %s", import_search_path.c_str());
5560+
HEALTH_LOG_PRINTF(" %s", import_search_path.Path.c_str());
55585561

55595562
swift::ClangImporterOptions &clang_importer_options =
55605563
GetClangImporterOptions();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class SwiftASTContext : public TypeSystemSwift {
253253
swift::SearchPathOptions &GetSearchPathOptions();
254254

255255
void InitializeSearchPathOptions(
256-
llvm::ArrayRef<std::string> module_search_paths,
256+
llvm::ArrayRef<std::pair<std::string, bool>> module_search_paths,
257257
llvm::ArrayRef<std::pair<std::string, bool>> framework_search_paths);
258258

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

284284
void AddExtraClangCC1Args(
285285
const std::vector<std::string> &source,
286-
const std::vector<std::string> &module_search_paths,
286+
const std::vector<std::pair<std::string, bool>> module_search_paths,
287287
const std::vector<std::pair<std::string, bool>> framework_search_paths,
288288
std::vector<std::string> &dest);
289289
static void AddExtraClangArgs(const std::vector<std::string>& source,

0 commit comments

Comments
 (0)