@@ -2719,17 +2719,16 @@ swift::SearchPathOptions &SwiftASTContext::GetSearchPathOptions() {
2719
2719
}
2720
2720
2721
2721
void SwiftASTContext::InitializeSearchPathOptions (
2722
- llvm::ArrayRef<std::string> module_search_paths,
2723
- llvm::ArrayRef<std::pair<std::string, bool >> framework_search_paths) {
2724
- swift::SearchPathOptions &search_path_opts =
2725
- GetCompilerInvocation ().getSearchPathOptions ();
2722
+ llvm::ArrayRef<std::string> extra_module_search_paths,
2723
+ llvm::ArrayRef<std::pair<std::string, bool >> extra_framework_search_paths) {
2724
+ swift::CompilerInvocation &invocation = GetCompilerInvocation ();
2726
2725
2727
2726
assert (!m_initialized_search_path_options);
2728
2727
m_initialized_search_path_options = true ;
2729
2728
2730
2729
bool set_sdk = false ;
2731
- if (!search_path_opts. SDKPath .empty ()) {
2732
- FileSpec provided_sdk_path (search_path_opts. SDKPath );
2730
+ if (!invocation. getSDKPath () .empty ()) {
2731
+ FileSpec provided_sdk_path (invocation. getSDKPath () );
2733
2732
if (FileSystem::Instance ().Exists (provided_sdk_path)) {
2734
2733
// We don't check whether the SDK supports swift because we figure if
2735
2734
// someone is passing this to us on the command line (e.g., for the
@@ -2742,7 +2741,7 @@ void SwiftASTContext::InitializeSearchPathOptions(
2742
2741
2743
2742
if (FileSystem::Instance ().Exists (platform_sdk) &&
2744
2743
SDKSupportsSwift (platform_sdk, SDKType::unknown)) {
2745
- search_path_opts. SDKPath = m_platform_sdk_path.c_str ();
2744
+ invocation. setSDKPath ( m_platform_sdk_path.c_str () );
2746
2745
set_sdk = true ;
2747
2746
}
2748
2747
}
@@ -2763,38 +2762,45 @@ void SwiftASTContext::InitializeSearchPathOptions(
2763
2762
if (sdk.sdk_type != SDKType::unknown) {
2764
2763
auto dir = GetSDKDirectory (sdk.sdk_type , sdk.min_version_major ,
2765
2764
sdk.min_version_minor );
2766
- search_path_opts.SDKPath = dir.AsCString (" " );
2765
+ // Note that calling setSDKPath() also recomputes all paths that
2766
+ // depend on the SDK path including the
2767
+ // RuntimeLibraryImportPaths, which are *only* initialized
2768
+ // through this mechanism.
2769
+ invocation.setSDKPath (dir.AsCString (" " ));
2767
2770
}
2768
2771
2769
- std::vector<std::string>& lpaths = search_path_opts.LibrarySearchPaths ;
2772
+ std::vector<std::string> &lpaths =
2773
+ invocation.getSearchPathOptions ().LibrarySearchPaths ;
2770
2774
lpaths.insert (lpaths.begin (), " /usr/lib/swift" );
2771
2775
}
2772
2776
2773
2777
llvm::StringMap<bool > processed;
2778
+ std::vector<std::string> &invocation_import_paths =
2779
+ invocation.getSearchPathOptions ().ImportSearchPaths ;
2774
2780
// Add all deserialized paths to the map.
2775
- for (const auto &path : search_path_opts. ImportSearchPaths )
2781
+ for (const auto &path : invocation_import_paths )
2776
2782
processed.insert ({path, false });
2777
2783
2778
2784
// Add/unique all extra paths.
2779
- for (const auto &path : module_search_paths) {
2780
- search_path_opts.ImportSearchPaths .push_back (path);
2785
+ for (const auto &path : extra_module_search_paths) {
2781
2786
auto it_notseen = processed.insert ({path, false });
2782
2787
if (it_notseen.second )
2783
- search_path_opts. ImportSearchPaths .push_back (path);
2788
+ invocation_import_paths .push_back (path);
2784
2789
}
2785
2790
2786
2791
// This preserves the IsSystem bit, but deduplicates entries ignoring it.
2787
2792
processed.clear ();
2793
+ auto &invocation_framework_paths =
2794
+ invocation.getSearchPathOptions ().FrameworkSearchPaths ;
2788
2795
// Add all deserialized paths to the map.
2789
- for (const auto &path : search_path_opts. FrameworkSearchPaths )
2796
+ for (const auto &path : invocation_framework_paths )
2790
2797
processed.insert ({path.Path , path.IsSystem });
2791
2798
2792
2799
// Add/unique all extra paths.
2793
- for (const auto &path : framework_search_paths ) {
2800
+ for (const auto &path : extra_framework_search_paths ) {
2794
2801
auto it_notseen = processed.insert (path);
2795
2802
if (it_notseen.second )
2796
- search_path_opts.FrameworkSearchPaths .push_back (
2797
- {path.first , path.second });
2803
+ invocation_framework_paths.push_back ({path.first , path.second });
2798
2804
}
2799
2805
}
2800
2806
0 commit comments