[Frontend] Default the prebuilt cache to <resourcedir>/<platform>/prebuilt-modules (#24295)

By default, prebuilt modules will live in
<resource-dir>/<platform>/prebuilt-modules, so make this explicit if it wasn't
passed in explicitly.
This commit is contained in:
Harlan Haskins
2019-04-26 13:52:41 -07:00
committed by GitHub
parent 102a3a816a
commit 81a68f28ef
3 changed files with 49 additions and 0 deletions

View File

@@ -42,6 +42,25 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
setRuntimeResourcePath(LibPath.str());
}
/// If we haven't explicitly passed -prebuilt-module-cache-path, set it to
/// the default value of <resource-dir>/<platform>/prebuilt-modules.
/// @note This should be called once, after search path options and frontend
/// options have been parsed.
static void setDefaultPrebuiltCacheIfNecessary(
FrontendOptions &frontendOpts, const SearchPathOptions &searchPathOpts,
const llvm::Triple &triple) {
if (!frontendOpts.PrebuiltModuleCachePath.empty())
return;
if (searchPathOpts.RuntimeResourcePath.empty())
return;
SmallString<64> defaultPrebuiltPath{searchPathOpts.RuntimeResourcePath};
StringRef platform = getPlatformNameForTriple(triple);
llvm::sys::path::append(defaultPrebuiltPath, platform, "prebuilt-modules");
frontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPath.str();
}
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
llvm::Triple &Triple) {
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
@@ -1308,6 +1327,8 @@ bool CompilerInvocation::parseArgs(
}
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
setDefaultPrebuiltCacheIfNecessary(FrontendOpts, SearchPathOpts,
LangOpts.Target);
return false;
}