mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -42,6 +42,25 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
|
|||||||
setRuntimeResourcePath(LibPath.str());
|
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,
|
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
|
||||||
llvm::Triple &Triple) {
|
llvm::Triple &Triple) {
|
||||||
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
|
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
|
||||||
@@ -1308,6 +1327,8 @@ bool CompilerInvocation::parseArgs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
|
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
|
||||||
|
setDefaultPrebuiltCacheIfNecessary(FrontendOpts, SearchPathOpts,
|
||||||
|
LangOpts.Target);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// 1. Create folders for a) our Swift module, b) the module cache, and c) a
|
||||||
|
// fake resource dir with a default prebuilt module cache inside.
|
||||||
|
// RUN: %empty-directory(%t/PrebuiltModule.swiftmodule)
|
||||||
|
// RUN: %empty-directory(%t/ModuleCache)
|
||||||
|
// RUN: %empty-directory(%t/ResourceDir/%target-sdk-name/prebuilt-modules/PrebuiltModule.swiftmodule)
|
||||||
|
|
||||||
|
// 2. Define some public API
|
||||||
|
// RUN: echo 'public struct InPrebuiltModule {}' > %t/PrebuiltModule.swift
|
||||||
|
|
||||||
|
// 3. Compile this into a module and put it into the default prebuilt cache
|
||||||
|
// location relative to the fake resource dir. Also drop an interface into
|
||||||
|
// the build dir.
|
||||||
|
// RUN: %target-swift-frontend -emit-module %t/PrebuiltModule.swift -o %t/ResourceDir/%target-sdk-name/prebuilt-modules/PrebuiltModule.swiftmodule/%target-cpu.swiftmodule -module-name PrebuiltModule -parse-stdlib -emit-module-interface-path %t/PrebuiltModule.swiftmodule/%target-cpu.swiftinterface
|
||||||
|
|
||||||
|
// 4. Import this prebuilt module, but DON'T pass in -prebuilt-module-cache-path, it should use the implicit one.
|
||||||
|
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t
|
||||||
|
|
||||||
|
// 5. Make sure we installed a forwarding module in the module cache.
|
||||||
|
// RUN: %{python} %S/ModuleCache/Inputs/check-is-forwarding-module.py %t/ModuleCache/PrebuiltModule-*.swiftmodule
|
||||||
|
|
||||||
|
import PrebuiltModule
|
||||||
|
|
||||||
|
func x<T>(_ x: T) {}
|
||||||
|
|
||||||
|
x(InPrebuiltModule.self)
|
||||||
@@ -1072,6 +1072,9 @@ else:
|
|||||||
config.substitutions.append(('%module-target-triple',
|
config.substitutions.append(('%module-target-triple',
|
||||||
target_specific_module_triple))
|
target_specific_module_triple))
|
||||||
|
|
||||||
|
# Add 'target-sdk-name' as the name for platform-specific directories
|
||||||
|
config.substitutions.append(('%target-sdk-name', config.target_sdk_name))
|
||||||
|
|
||||||
# Different OS's require different prefixes for the environment variables to be
|
# Different OS's require different prefixes for the environment variables to be
|
||||||
# propagated to the calling contexts.
|
# propagated to the calling contexts.
|
||||||
# In order to make tests OS-agnostic, names of environment variables should be
|
# In order to make tests OS-agnostic, names of environment variables should be
|
||||||
|
|||||||
Reference in New Issue
Block a user