Skip to content

Commit fb7275b

Browse files
authored
Merge pull request #65072 from nkcsgexi/infer-default-blocklist-files
Frontend: infer default blocklists to use when the explicit paths aren't given by swift-driver
2 parents 9b81421 + 1f395ec commit fb7275b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/swift/Frontend/Frontend.h

+3
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ class CompilerInvocation {
235235
/// options have been parsed.
236236
void setDefaultPrebuiltCacheIfNecessary();
237237

238+
/// If we haven't explicitly passed -blocklist-paths, set it to the default value.
239+
void setDefaultBlocklistsIfNecessary();
240+
238241
/// Computes the runtime resource path relative to the given Swift
239242
/// executable.
240243
static void computeRuntimeResourcePathFromExecutablePath(

lib/Frontend/CompilerInvocation.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,31 @@ void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
159159
(llvm::Twine(pair.first) + "preferred-interfaces" + pair.second).str();
160160
}
161161

162+
void CompilerInvocation::setDefaultBlocklistsIfNecessary() {
163+
if (!LangOpts.BlocklistConfigFilePaths.empty())
164+
return;
165+
if (SearchPathOpts.RuntimeResourcePath.empty())
166+
return;
167+
// XcodeDefault.xctoolchain/usr/lib/swift
168+
SmallString<64> blocklistDir{SearchPathOpts.RuntimeResourcePath};
169+
// XcodeDefault.xctoolchain/usr/lib
170+
llvm::sys::path::remove_filename(blocklistDir);
171+
// XcodeDefault.xctoolchain/usr
172+
llvm::sys::path::remove_filename(blocklistDir);
173+
// XcodeDefault.xctoolchain/usr/local/lib/swift/blocklists
174+
llvm::sys::path::append(blocklistDir, "local", "lib", "swift", "blocklists");
175+
std::error_code EC;
176+
if (llvm::sys::fs::is_directory(blocklistDir)) {
177+
for (llvm::sys::fs::directory_iterator F(blocklistDir, EC), FE;
178+
F != FE; F.increment(EC)) {
179+
StringRef ext = llvm::sys::path::extension(F->path());
180+
if (ext == "yml" || ext == "yaml") {
181+
LangOpts.BlocklistConfigFilePaths.push_back(F->path());
182+
}
183+
}
184+
}
185+
}
186+
162187
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
163188
llvm::Triple &Triple) {
164189
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
@@ -2870,6 +2895,7 @@ bool CompilerInvocation::parseArgs(
28702895

28712896
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
28722897
setDefaultPrebuiltCacheIfNecessary();
2898+
setDefaultBlocklistsIfNecessary();
28732899

28742900
// Now that we've parsed everything, setup some inter-option-dependent state.
28752901
setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts);

0 commit comments

Comments
 (0)