Skip to content

Commit 9c33c92

Browse files
committed
Make the function to compute the prebuilt module cache path public
so it can be called by LLDB. (NFC). rdar://76112632 (cherry picked from commit ab3da16)
1 parent 89dee97 commit 9c33c92

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ class CompilerInvocation {
204204

205205
void setRuntimeResourcePath(StringRef Path);
206206

207+
/// Compute the default prebuilt module cache path for a given resource path
208+
/// and SDK version. This function is also used by LLDB.
209+
static std::string
210+
computePrebuiltCachePath(StringRef RuntimeResourcePath, llvm::Triple target,
211+
Optional<llvm::VersionTuple> sdkVer);
212+
207213
/// If we haven't explicitly passed -prebuilt-module-cache-path, set it to
208214
/// the default value of <resource-dir>/<platform>/prebuilt-modules.
209215
/// @note This should be called once, after search path options and frontend

lib/Frontend/CompilerInvocation.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,34 @@ getVersionedPrebuiltModulePath(Optional<llvm::VersionTuple> sdkVer,
101101
} while(true);
102102
}
103103

104-
void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
105-
106-
if (!FrontendOpts.PrebuiltModuleCachePath.empty())
107-
return;
108-
if (SearchPathOpts.RuntimeResourcePath.empty())
109-
return;
110-
111-
SmallString<64> defaultPrebuiltPath{SearchPathOpts.RuntimeResourcePath};
104+
std::string CompilerInvocation::computePrebuiltCachePath(
105+
StringRef RuntimeResourcePath, llvm::Triple target,
106+
Optional<llvm::VersionTuple> sdkVer) {
107+
SmallString<64> defaultPrebuiltPath{RuntimeResourcePath};
112108
StringRef platform;
113-
if (tripleIsMacCatalystEnvironment(LangOpts.Target)) {
114-
// The prebuilt cache for macCatalyst is the same as the one for macOS, not iOS
115-
// or a separate location of its own.
109+
if (tripleIsMacCatalystEnvironment(target)) {
110+
// The prebuilt cache for macCatalyst is the same as the one for macOS, not
111+
// iOS or a separate location of its own.
116112
platform = "macosx";
117113
} else {
118-
platform = getPlatformNameForTriple(LangOpts.Target);
114+
platform = getPlatformNameForTriple(target);
119115
}
120116
llvm::sys::path::append(defaultPrebuiltPath, platform, "prebuilt-modules");
121117

122118
// If the SDK version is given, we should check if SDK-versioned prebuilt
123119
// module cache is available and use it if so.
124-
FrontendOpts.PrebuiltModuleCachePath =
125-
getVersionedPrebuiltModulePath(LangOpts.SDKVersion, defaultPrebuiltPath);
120+
return getVersionedPrebuiltModulePath(sdkVer, defaultPrebuiltPath);
121+
}
122+
123+
void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
124+
125+
if (!FrontendOpts.PrebuiltModuleCachePath.empty())
126+
return;
127+
if (SearchPathOpts.RuntimeResourcePath.empty())
128+
return;
129+
130+
FrontendOpts.PrebuiltModuleCachePath = computePrebuiltCachePath(
131+
SearchPathOpts.RuntimeResourcePath, LangOpts.Target, LangOpts.SDKVersion);
126132
}
127133

128134
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,

0 commit comments

Comments
 (0)