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.
This commit is contained in:
Xi Ge
2023-04-11 12:09:55 -07:00
parent bb2fc82b37
commit 1f395ec1a8
2 changed files with 29 additions and 0 deletions

View File

@@ -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);
@@ -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);