Merge pull request #81621 from ian-twilightcoder/nostdimport-remove-framework-paths

[6.2][Driver][Frontend] -nostdimport and -nostdlibimport should remove the default framework search paths
This commit is contained in:
Ian Anderson
2025-05-29 12:51:10 -07:00
committed by GitHub
7 changed files with 110 additions and 66 deletions

View File

@@ -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()) {
SmallString<128> 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,
@@ -2381,8 +2412,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);
@@ -4046,6 +4077,7 @@ bool CompilerInvocation::parseArgs(
}
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
setDefaultPrebuiltCacheIfNecessary();
setDefaultBlocklistsIfNecessary();
setDefaultInProcessPluginServerPathIfNecessary();