mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Driver][Frontend] -nostdimport and -nostdlibimport should remove the default framework search paths
-nostdimport and -nostdlibimport only remove the toolchain and usr/lib/swift search paths, and they leave the framework search paths intact. That makes it impossible to get a fully custom SDK environment. Make their behavior match clang's -nostdinc/-nostdlibinc behavior: treat framework and non-framework paths the same. In other words, -nostdinc removes *all* compiler provided search paths, and -nostdlibinc removes *all* SDK search paths. Rename SkipRuntimeLibraryImportPaths to SkipAllImportPaths, and ExcludeSDKPathsFromRuntimeLibraryImportPaths to SkipSDKImportPaths to reflect their updated behavior. Move the DarwinImplicitFrameworkSearchPaths handling from SearchPathOptions to CompilerInvocation, where RuntimeLibraryImportPaths is managed. Rename it to just ImplicitFrameworkSearchPaths, and filter for Darwin when it's set up so that all of the clients don't have to do Darwin filtering themselves later. rdar://150557632
This commit is contained in:
@@ -254,7 +254,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
|
||||
SearchPathOpts.RuntimeLibraryPaths.push_back(DARWIN_OS_LIBRARY_PATH);
|
||||
|
||||
// If this is set, we don't want any runtime import paths.
|
||||
if (SearchPathOpts.SkipRuntimeLibraryImportPaths) {
|
||||
if (SearchPathOpts.SkipAllImplicitImportPaths) {
|
||||
SearchPathOpts.setRuntimeLibraryImportPaths({});
|
||||
return;
|
||||
}
|
||||
@@ -270,7 +270,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
|
||||
RuntimeLibraryImportPaths.push_back(std::string(LibPath.str()));
|
||||
}
|
||||
|
||||
if (!SearchPathOpts.ExcludeSDKPathsFromRuntimeLibraryImportPaths && !SearchPathOpts.getSDKPath().empty()) {
|
||||
if (!SearchPathOpts.SkipSDKImportPaths && !SearchPathOpts.getSDKPath().empty()) {
|
||||
const char *swiftDir = FrontendOpts.UseSharedResourceFolder
|
||||
? "swift" : "swift_static";
|
||||
|
||||
@@ -300,6 +300,35 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
|
||||
SearchPathOpts.setRuntimeLibraryImportPaths(RuntimeLibraryImportPaths);
|
||||
}
|
||||
|
||||
static void
|
||||
updateImplicitFrameworkSearchPaths(SearchPathOptions &SearchPathOpts,
|
||||
const LangOptions &LangOpts) {
|
||||
if (SearchPathOpts.SkipAllImplicitImportPaths) {
|
||||
SearchPathOpts.setImplicitFrameworkSearchPaths({});
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> ImplicitFrameworkSearchPaths;
|
||||
if (LangOpts.Target.isOSDarwin()) {
|
||||
if (!SearchPathOpts.SkipSDKImportPaths &&
|
||||
!SearchPathOpts.getSDKPath().empty()) {
|
||||
StringRef SDKPath = SearchPathOpts.getSDKPath();
|
||||
SmallString<128> systemFrameworksScratch(SDKPath);
|
||||
llvm::sys::path::append(systemFrameworksScratch, "System", "Library",
|
||||
"Frameworks");
|
||||
SmallString<128> systemSubFrameworksScratch(SDKPath);
|
||||
llvm::sys::path::append(systemSubFrameworksScratch, "System", "Library",
|
||||
"SubFrameworks");
|
||||
SmallString<128> frameworksScratch(SDKPath);
|
||||
llvm::sys::path::append(frameworksScratch, "Library", "Frameworks");
|
||||
ImplicitFrameworkSearchPaths = {systemFrameworksScratch.str().str(),
|
||||
systemSubFrameworksScratch.str().str(),
|
||||
frameworksScratch.str().str()};
|
||||
}
|
||||
}
|
||||
SearchPathOpts.setImplicitFrameworkSearchPaths(ImplicitFrameworkSearchPaths);
|
||||
}
|
||||
|
||||
static void
|
||||
setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts,
|
||||
const FrontendOptions &FrontendOpts) {
|
||||
@@ -411,11 +440,13 @@ void CompilerInvocation::setTargetTriple(StringRef Triple) {
|
||||
void CompilerInvocation::setTargetTriple(const llvm::Triple &Triple) {
|
||||
LangOpts.setTarget(Triple);
|
||||
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
|
||||
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
|
||||
}
|
||||
|
||||
void CompilerInvocation::setSDKPath(const std::string &Path) {
|
||||
SearchPathOpts.setSDKPath(Path);
|
||||
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
|
||||
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
|
||||
}
|
||||
|
||||
bool CompilerInvocation::setModuleAliasMap(std::vector<std::string> args,
|
||||
@@ -2387,8 +2418,8 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
|
||||
if (const Arg *A = Args.getLastArg(OPT_resource_dir))
|
||||
Opts.RuntimeResourcePath = A->getValue();
|
||||
|
||||
Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport);
|
||||
Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport);
|
||||
Opts.SkipAllImplicitImportPaths |= Args.hasArg(OPT_nostdimport);
|
||||
Opts.SkipSDKImportPaths |= Args.hasArg(OPT_nostdlibimport);
|
||||
|
||||
Opts.DisableModulesValidateSystemDependencies |=
|
||||
Args.hasArg(OPT_disable_modules_validate_system_headers);
|
||||
@@ -4056,6 +4087,7 @@ bool CompilerInvocation::parseArgs(
|
||||
}
|
||||
|
||||
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
|
||||
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
|
||||
setDefaultPrebuiltCacheIfNecessary();
|
||||
setDefaultBlocklistsIfNecessary();
|
||||
setDefaultInProcessPluginServerPathIfNecessary();
|
||||
|
||||
Reference in New Issue
Block a user