diff --git a/include/swift/Frontend/Frontend.h b/include/swift/Frontend/Frontend.h index 9669e98d8488b..058c47bbab91a 100644 --- a/include/swift/Frontend/Frontend.h +++ b/include/swift/Frontend/Frontend.h @@ -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( diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index f855e8defcbbf..6856112b062bc 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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);