Skip to content

Commit 5dd92d6

Browse files
committed
Frontend: infer default blocklists to use when the explicit paths aren't given by swift-driver
Although swift-driver always passes down these blocklist for the compiler to consume, some frontend tools, like ABI checker, are invoked by the build system directly. Therefore, we need to teach the compiler to infer these blocklist files like prebuilt module cache.
1 parent 606476f commit 5dd92d6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ class CompilerInvocation {
232232
/// options have been parsed.
233233
void setDefaultPrebuiltCacheIfNecessary();
234234

235+
/// If we haven't explicitly passed -blocklist-paths, set it to the default value.
236+
void setDefaultBlocklistsIfNecessary();
237+
235238
/// Computes the runtime resource path relative to the given Swift
236239
/// executable.
237240
static void computeRuntimeResourcePathFromExecutablePath(

lib/Frontend/CompilerInvocation.cpp

Lines changed: 26 additions & 0 deletions
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);
@@ -2934,6 +2959,7 @@ bool CompilerInvocation::parseArgs(
29342959

29352960
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
29362961
setDefaultPrebuiltCacheIfNecessary();
2962+
setDefaultBlocklistsIfNecessary();
29372963

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

0 commit comments

Comments
 (0)