Skip to content

Frontend: infer default blocklists to use when the explicit paths aren't given by swift-driver #65072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class CompilerInvocation {
/// options have been parsed.
void setDefaultPrebuiltCacheIfNecessary();

/// If we haven't explicitly passed -blocklist-paths, set it to the default value.
void setDefaultBlocklistsIfNecessary();

/// Computes the runtime resource path relative to the given Swift
/// executable.
static void computeRuntimeResourcePathFromExecutablePath(
Expand Down
26 changes: 26 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
(llvm::Twine(pair.first) + "preferred-interfaces" + pair.second).str();
}

void CompilerInvocation::setDefaultBlocklistsIfNecessary() {
if (!LangOpts.BlocklistConfigFilePaths.empty())
return;
if (SearchPathOpts.RuntimeResourcePath.empty())
return;
// XcodeDefault.xctoolchain/usr/lib/swift
SmallString<64> blocklistDir{SearchPathOpts.RuntimeResourcePath};
// XcodeDefault.xctoolchain/usr/lib
llvm::sys::path::remove_filename(blocklistDir);
// XcodeDefault.xctoolchain/usr
llvm::sys::path::remove_filename(blocklistDir);
// XcodeDefault.xctoolchain/usr/local/lib/swift/blocklists
llvm::sys::path::append(blocklistDir, "local", "lib", "swift", "blocklists");
std::error_code EC;
if (llvm::sys::fs::is_directory(blocklistDir)) {
for (llvm::sys::fs::directory_iterator F(blocklistDir, EC), FE;
F != FE; F.increment(EC)) {
StringRef ext = llvm::sys::path::extension(F->path());
if (ext == "yml" || ext == "yaml") {
LangOpts.BlocklistConfigFilePaths.push_back(F->path());
}
}
}
}

static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
llvm::Triple &Triple) {
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
Expand Down Expand Up @@ -2870,6 +2895,7 @@ bool CompilerInvocation::parseArgs(

updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
setDefaultPrebuiltCacheIfNecessary();
setDefaultBlocklistsIfNecessary();

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