Skip to content

Commit 4089a3e

Browse files
committed
Revert "[Driver][Frontend] -nostdimport and -nostdlibimport should remove the default framework search paths"
This reverts commit a6e517e.
1 parent 634a7e9 commit 4089a3e

File tree

7 files changed

+66
-110
lines changed

7 files changed

+66
-110
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@ class ASTContext final {
10931093
/// Retrieve the module interface checker associated with this AST context.
10941094
ModuleInterfaceChecker *getModuleInterfaceChecker() const;
10951095

1096+
/// Compute the extra implicit framework search paths on Apple platforms:
1097+
/// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
1098+
std::vector<std::string> getDarwinImplicitFrameworkSearchPaths() const;
1099+
10961100
/// Load extensions to the given nominal type from the external
10971101
/// module loaders.
10981102
///

include/swift/AST/SearchPathOptions.h

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace swift {
3535
enum class ModuleSearchPathKind {
3636
Import,
3737
Framework,
38-
ImplicitFramework,
38+
DarwinImplicitFramework,
3939
RuntimeLibrary,
4040
};
4141

@@ -356,8 +356,12 @@ class SearchPathOptions {
356356
/// When on Darwin the framework paths that are implicitly imported.
357357
/// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
358358
///
359-
/// Must be modified through setter to keep \c Lookup in sync.
360-
std::vector<std::string> ImplicitFrameworkSearchPaths;
359+
/// On non-Darwin platforms these are populated, but ignored.
360+
///
361+
/// Computed when the SDK path is set and cached so we can reference the
362+
/// Darwin implicit framework search paths as \c StringRef from
363+
/// \c ModuleSearchPath.
364+
std::vector<std::string> DarwinImplicitFrameworkSearchPaths;
361365

362366
/// Compiler plugin library search paths.
363367
std::vector<std::string> CompilerPluginLibraryPaths;
@@ -397,6 +401,21 @@ class SearchPathOptions {
397401

398402
void setSDKPath(std::string NewSDKPath) {
399403
SDKPath = NewSDKPath;
404+
405+
// Compute Darwin implicit framework search paths.
406+
SmallString<128> systemFrameworksScratch(NewSDKPath);
407+
llvm::sys::path::append(systemFrameworksScratch, "System", "Library",
408+
"Frameworks");
409+
SmallString<128> systemSubFrameworksScratch(NewSDKPath);
410+
llvm::sys::path::append(systemSubFrameworksScratch, "System", "Library",
411+
"SubFrameworks");
412+
SmallString<128> frameworksScratch(NewSDKPath);
413+
llvm::sys::path::append(frameworksScratch, "Library", "Frameworks");
414+
DarwinImplicitFrameworkSearchPaths = {systemFrameworksScratch.str().str(),
415+
systemSubFrameworksScratch.str().str(),
416+
frameworksScratch.str().str()};
417+
418+
Lookup.searchPathsDidChange();
400419
}
401420

402421
/// Retrieves the corresponding parent platform path for the SDK, or
@@ -451,14 +470,8 @@ class SearchPathOptions {
451470

452471
/// The extra implicit framework search paths on Apple platforms:
453472
/// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
454-
ArrayRef<std::string> getImplicitFrameworkSearchPaths() const {
455-
return ImplicitFrameworkSearchPaths;
456-
}
457-
458-
void setImplicitFrameworkSearchPaths(
459-
std::vector<std::string> NewImplicitFrameworkSearchPaths) {
460-
ImplicitFrameworkSearchPaths = NewImplicitFrameworkSearchPaths;
461-
Lookup.searchPathsDidChange();
473+
ArrayRef<std::string> getDarwinImplicitFrameworkSearchPaths() const {
474+
return DarwinImplicitFrameworkSearchPaths;
462475
}
463476

464477
ArrayRef<std::string> getRuntimeLibraryImportPaths() const {
@@ -492,11 +505,11 @@ class SearchPathOptions {
492505
/// Path to in-process plugin server shared library.
493506
std::string InProcessPluginServerPath;
494507

495-
/// Don't automatically add any import paths.
496-
bool SkipAllImplicitImportPaths = false;
508+
/// Don't look in for compiler-provided modules.
509+
bool SkipRuntimeLibraryImportPaths = false;
497510

498-
/// Don't automatically add any import paths from the SDK.
499-
bool SkipSDKImportPaths = false;
511+
/// Don't include SDK paths in the RuntimeLibraryImportPaths
512+
bool ExcludeSDKPathsFromRuntimeLibraryImportPaths = false;
500513

501514
/// Scanner Prefix Mapper.
502515
std::vector<std::string> ScannerPrefixMapper;
@@ -606,8 +619,6 @@ class SearchPathOptions {
606619
RuntimeResourcePath,
607620
hash_combine_range(RuntimeLibraryImportPaths.begin(),
608621
RuntimeLibraryImportPaths.end()),
609-
hash_combine_range(ImplicitFrameworkSearchPaths.begin(),
610-
ImplicitFrameworkSearchPaths.end()),
611622
DisableModulesValidateSystemDependencies,
612623
ScannerModuleValidation,
613624
ModuleLoadMode);

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,12 @@ Identifier ASTContext::getRealModuleName(Identifier key, ModuleAliasLookupOption
22002200
return value.first;
22012201
}
22022202

2203+
std::vector<std::string> ASTContext::getDarwinImplicitFrameworkSearchPaths()
2204+
const {
2205+
assert(LangOpts.Target.isOSDarwin());
2206+
return SearchPathOpts.getDarwinImplicitFrameworkSearchPaths();
2207+
}
2208+
22032209
void ASTContext::loadExtensions(NominalTypeDecl *nominal,
22042210
unsigned previousGeneration) {
22052211
PrettyStackTraceDecl stackTrace("loading extensions for", nominal);

lib/AST/SearchPathOptions.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ void ModuleSearchPathLookup::rebuildLookupTable(const SearchPathOptions *Opts,
5858
Entry.value().IsSystem, Entry.index());
5959
}
6060

61-
for (auto Entry : llvm::enumerate(Opts->getImplicitFrameworkSearchPaths())) {
62-
addFilesInPathToLookupTable(FS, Entry.value(),
63-
ModuleSearchPathKind::ImplicitFramework,
64-
/*isSystem=*/true, Entry.index());
61+
// Apple platforms have extra implicit framework search paths:
62+
// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
63+
if (IsOSDarwin) {
64+
for (auto Entry : llvm::enumerate(Opts->getDarwinImplicitFrameworkSearchPaths())) {
65+
addFilesInPathToLookupTable(FS, Entry.value(),
66+
ModuleSearchPathKind::DarwinImplicitFramework,
67+
/*isSystem=*/true, Entry.index());
68+
}
6569
}
6670

6771
for (auto Entry : llvm::enumerate(Opts->getRuntimeLibraryImportPaths())) {
@@ -119,9 +123,12 @@ void SearchPathOptions::dump(bool isDarwin) const {
119123
<< Entry.value().Path << "\n";
120124
}
121125

122-
llvm::errs() << "Implicit framework search paths:\n";
123-
for (auto Entry : llvm::enumerate(getImplicitFrameworkSearchPaths())) {
124-
llvm::errs() << " [" << Entry.index() << "] " << Entry.value() << "\n";
126+
if (isDarwin) {
127+
llvm::errs() << "Darwin implicit framework search paths:\n";
128+
for (auto Entry :
129+
llvm::enumerate(getDarwinImplicitFrameworkSearchPaths())) {
130+
llvm::errs() << " [" << Entry.index() << "] " << Entry.value() << "\n";
131+
}
125132
}
126133

127134
llvm::errs() << "Runtime library import search paths:\n";

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
254254
SearchPathOpts.RuntimeLibraryPaths.push_back(DARWIN_OS_LIBRARY_PATH);
255255

256256
// If this is set, we don't want any runtime import paths.
257-
if (SearchPathOpts.SkipAllImplicitImportPaths) {
257+
if (SearchPathOpts.SkipRuntimeLibraryImportPaths) {
258258
SearchPathOpts.setRuntimeLibraryImportPaths({});
259259
return;
260260
}
@@ -270,7 +270,7 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
270270
RuntimeLibraryImportPaths.push_back(std::string(LibPath.str()));
271271
}
272272

273-
if (!SearchPathOpts.SkipSDKImportPaths && !SearchPathOpts.getSDKPath().empty()) {
273+
if (!SearchPathOpts.ExcludeSDKPathsFromRuntimeLibraryImportPaths && !SearchPathOpts.getSDKPath().empty()) {
274274
const char *swiftDir = FrontendOpts.UseSharedResourceFolder
275275
? "swift" : "swift_static";
276276

@@ -300,35 +300,6 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
300300
SearchPathOpts.setRuntimeLibraryImportPaths(RuntimeLibraryImportPaths);
301301
}
302302

303-
static void
304-
updateImplicitFrameworkSearchPaths(SearchPathOptions &SearchPathOpts,
305-
const LangOptions &LangOpts) {
306-
if (SearchPathOpts.SkipAllImplicitImportPaths) {
307-
SearchPathOpts.setImplicitFrameworkSearchPaths({});
308-
return;
309-
}
310-
311-
std::vector<std::string> ImplicitFrameworkSearchPaths;
312-
if (LangOpts.Target.isOSDarwin()) {
313-
if (!SearchPathOpts.SkipSDKImportPaths &&
314-
!SearchPathOpts.getSDKPath().empty()) {
315-
StringRef SDKPath = SearchPathOpts.getSDKPath();
316-
SmallString<128> systemFrameworksScratch(SDKPath);
317-
llvm::sys::path::append(systemFrameworksScratch, "System", "Library",
318-
"Frameworks");
319-
SmallString<128> systemSubFrameworksScratch(SDKPath);
320-
llvm::sys::path::append(systemSubFrameworksScratch, "System", "Library",
321-
"SubFrameworks");
322-
SmallString<128> frameworksScratch(SDKPath);
323-
llvm::sys::path::append(frameworksScratch, "Library", "Frameworks");
324-
ImplicitFrameworkSearchPaths = {systemFrameworksScratch.str().str(),
325-
systemSubFrameworksScratch.str().str(),
326-
frameworksScratch.str().str()};
327-
}
328-
}
329-
SearchPathOpts.setImplicitFrameworkSearchPaths(ImplicitFrameworkSearchPaths);
330-
}
331-
332303
static void
333304
setIRGenOutputOptsFromFrontendOptions(IRGenOptions &IRGenOpts,
334305
const FrontendOptions &FrontendOpts) {
@@ -440,13 +411,11 @@ void CompilerInvocation::setTargetTriple(StringRef Triple) {
440411
void CompilerInvocation::setTargetTriple(const llvm::Triple &Triple) {
441412
LangOpts.setTarget(Triple);
442413
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
443-
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
444414
}
445415

446416
void CompilerInvocation::setSDKPath(const std::string &Path) {
447417
SearchPathOpts.setSDKPath(Path);
448418
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
449-
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
450419
}
451420

452421
bool CompilerInvocation::setModuleAliasMap(std::vector<std::string> args,
@@ -2418,8 +2387,8 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
24182387
if (const Arg *A = Args.getLastArg(OPT_resource_dir))
24192388
Opts.RuntimeResourcePath = A->getValue();
24202389

2421-
Opts.SkipAllImplicitImportPaths |= Args.hasArg(OPT_nostdimport);
2422-
Opts.SkipSDKImportPaths |= Args.hasArg(OPT_nostdlibimport);
2390+
Opts.SkipRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdimport);
2391+
Opts.ExcludeSDKPathsFromRuntimeLibraryImportPaths |= Args.hasArg(OPT_nostdlibimport);
24232392

24242393
Opts.DisableModulesValidateSystemDependencies |=
24252394
Args.hasArg(OPT_disable_modules_validate_system_headers);
@@ -4087,7 +4056,6 @@ bool CompilerInvocation::parseArgs(
40874056
}
40884057

40894058
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
4090-
updateImplicitFrameworkSearchPaths(SearchPathOpts, LangOpts);
40914059
setDefaultPrebuiltCacheIfNecessary();
40924060
setDefaultBlocklistsIfNecessary();
40934061
setDefaultInProcessPluginServerPathIfNecessary();

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ std::optional<bool> forEachModuleSearchPath(
108108
callback(path.Path, ModuleSearchPathKind::Framework, path.IsSystem))
109109
return result;
110110

111-
for (const auto &path :
112-
Ctx.SearchPathOpts.getImplicitFrameworkSearchPaths()) {
113-
if (auto result = callback(path, ModuleSearchPathKind::ImplicitFramework,
114-
/*isSystem=*/true))
115-
return result;
111+
// Apple platforms have extra implicit framework search paths:
112+
// $SDKROOT/System/Library/Frameworks/ and $SDKROOT/Library/Frameworks/.
113+
if (Ctx.LangOpts.Target.isOSDarwin()) {
114+
for (const auto &path : Ctx.getDarwinImplicitFrameworkSearchPaths())
115+
if (auto result =
116+
callback(path, ModuleSearchPathKind::DarwinImplicitFramework,
117+
/*isSystem=*/true))
118+
return result;
116119
}
117120

118121
for (const auto &importPath :
@@ -237,7 +240,7 @@ void SerializedModuleLoaderBase::collectVisibleTopLevelModuleNamesImpl(
237240
return std::nullopt;
238241
}
239242
case ModuleSearchPathKind::Framework:
240-
case ModuleSearchPathKind::ImplicitFramework: {
243+
case ModuleSearchPathKind::DarwinImplicitFramework: {
241244
// Look for:
242245
// $PATH/{name}.framework/Modules/{name}.swiftmodule/{arch}.{extension}
243246
forEachDirectoryEntryPath(searchPath, [&](StringRef path) {
@@ -961,7 +964,7 @@ bool SerializedModuleLoaderBase::findModule(
961964
continue;
962965
}
963966
case ModuleSearchPathKind::Framework:
964-
case ModuleSearchPathKind::ImplicitFramework: {
967+
case ModuleSearchPathKind::DarwinImplicitFramework: {
965968
isFramework = true;
966969
llvm::sys::path::append(currPath, moduleName + ".framework");
967970

test/Frontend/default-search-paths.swift

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)