diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-09-18 14:53:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-18 14:53:40 -0700 |
commit | 152a2162a1a9c93358bb69ab839931d95b9537ad (patch) | |
tree | 287401779a7a607784aaa29c420d0c8ffeb682c8 /llvm/lib/Support/CommandLine.cpp | |
parent | cfaf23927c6b083646a431eb8eea2d286694c0a0 (diff) | |
download | llvm-152a2162a1a9c93358bb69ab839931d95b9537ad.zip llvm-152a2162a1a9c93358bb69ab839931d95b9537ad.tar.gz llvm-152a2162a1a9c93358bb69ab839931d95b9537ad.tar.bz2 |
[llvm][clang] Pass VFS to `llvm::cl` command line handling (#159174)
This PR passes the VFS down to `llvm::cl` functions so that they don't
assume the real file system.
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index be232f5..12a8d0c 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -188,6 +188,7 @@ public: bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs = nullptr, + vfs::FileSystem *VFS = nullptr, bool LongOptionsUseDoubleDash = false); void forEachSubCommand(Option &Opt, function_ref<void(SubCommand &)> Action) { @@ -1401,8 +1402,9 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, return true; } -ExpansionContext::ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T) - : Saver(A), Tokenizer(T), FS(vfs::getRealFileSystem().get()) {} +ExpansionContext::ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T, + vfs::FileSystem *FS) + : Saver(A), Tokenizer(T), FS(FS ? FS : vfs::getRealFileSystem().get()) {} bool ExpansionContext::findConfigFile(StringRef FileName, SmallVectorImpl<char> &FilePath) { @@ -1461,7 +1463,7 @@ Error ExpansionContext::readConfigFile(StringRef CfgFile, static void initCommonOptions(); bool cl::ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs, - const char *EnvVar, + vfs::FileSystem *VFS, const char *EnvVar, bool LongOptionsUseDoubleDash) { initCommonOptions(); SmallVector<const char *, 20> NewArgv; @@ -1482,8 +1484,8 @@ bool cl::ParseCommandLineOptions(int argc, const char *const *argv, int NewArgc = static_cast<int>(NewArgv.size()); // Parse all options. - return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview, - Errs, LongOptionsUseDoubleDash); + return GlobalParser->ParseCommandLineOptions( + NewArgc, &NewArgv[0], Overview, Errs, VFS, LongOptionsUseDoubleDash); } /// Reset all options at least once, so that we can parse different options. @@ -1503,17 +1505,17 @@ void CommandLineParser::ResetAllOptionOccurrences() { } } -bool CommandLineParser::ParseCommandLineOptions(int argc, - const char *const *argv, - StringRef Overview, - raw_ostream *Errs, - bool LongOptionsUseDoubleDash) { +bool CommandLineParser::ParseCommandLineOptions( + int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs, + vfs::FileSystem *VFS, bool LongOptionsUseDoubleDash) { assert(hasOptions() && "No options specified!"); ProgramOverview = Overview; bool IgnoreErrors = Errs; if (!Errs) Errs = &errs(); + if (!VFS) + VFS = vfs::getRealFileSystem().get(); bool ErrorParsing = false; // Expand response files. @@ -1524,7 +1526,7 @@ bool CommandLineParser::ParseCommandLineOptions(int argc, #else auto Tokenize = cl::TokenizeGNUCommandLine; #endif - ExpansionContext ECtx(A, Tokenize); + ExpansionContext ECtx(A, Tokenize, VFS); if (Error Err = ECtx.expandResponseFiles(newArgv)) { *Errs << toString(std::move(Err)) << '\n'; return false; |