diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2022-08-22 00:30:28 +0700 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2022-09-28 11:47:59 +0700 |
commit | 6e491c48d6b9cadcc5b77f730dd83a1448197329 (patch) | |
tree | 3bd4844ff52cac131d05cb7999550cafad182bb1 /llvm/unittests/Support/CommandLineTest.cpp | |
parent | 89e56e732d5e89d8715a501158793ac305bc4b70 (diff) | |
download | llvm-6e491c48d6b9cadcc5b77f730dd83a1448197329.zip llvm-6e491c48d6b9cadcc5b77f730dd83a1448197329.tar.gz llvm-6e491c48d6b9cadcc5b77f730dd83a1448197329.tar.bz2 |
[Support] Class for response file expansion (NFC)
Functions that implement expansion of response and config files depend
on many options, which are passes as arguments. Extending the expansion
requires new options, it in turn causes changing calls in various places
making them even more bulky.
This change introduces a class ExpansionContext, which represents set of
options that control the expansion. Its methods implements expansion of
responce files including config files. It makes extending the expansion
easier.
No functional changes.
Differential Revision: https://reviews.llvm.org/D132379
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index 4fd037e..7af8c89 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -869,10 +869,9 @@ TEST(CommandLineTest, ResponseFiles) { // Expand response files. llvm::BumpPtrAllocator A; - llvm::StringSaver Saver(A); - ASSERT_TRUE(llvm::cl::ExpandResponseFiles( - Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true, false, - /*CurrentDir=*/StringRef(TestRoot), FS)); + llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine); + ECtx.setVFS(&FS).setCurrentDir(TestRoot).setRelativeNames(true); + ASSERT_TRUE(ECtx.expandResponseFiles(Argv)); EXPECT_THAT(Argv, testing::Pointwise( StringEquality(), {"test/test", "-flag_1", "-option_1", "-option_2", @@ -927,15 +926,14 @@ TEST(CommandLineTest, RecursiveResponseFiles) { SmallVector<const char *, 4> Argv = {"test/test", SelfFileRef.c_str(), "-option_3"}; BumpPtrAllocator A; - StringSaver Saver(A); #ifdef _WIN32 cl::TokenizerCallback Tokenizer = cl::TokenizeWindowsCommandLine; #else cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine; #endif - ASSERT_FALSE( - cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, false, - /*CurrentDir=*/llvm::StringRef(TestRoot), FS)); + llvm::cl::ExpansionContext ECtx(A, Tokenizer); + ECtx.setVFS(&FS).setCurrentDir(TestRoot); + ASSERT_FALSE(ECtx.expandResponseFiles(Argv)); EXPECT_THAT(Argv, testing::Pointwise(StringEquality(), @@ -971,10 +969,9 @@ TEST(CommandLineTest, ResponseFilesAtArguments) { Argv.push_back(ResponseFileRef.c_str()); BumpPtrAllocator A; - StringSaver Saver(A); - ASSERT_FALSE(cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv, - false, false, false, - /*CurrentDir=*/StringRef(TestRoot), FS)); + llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine); + ECtx.setVFS(&FS).setCurrentDir(TestRoot); + ASSERT_FALSE(ECtx.expandResponseFiles(Argv)); // ASSERT instead of EXPECT to prevent potential out-of-bounds access. ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2); @@ -1006,10 +1003,9 @@ TEST(CommandLineTest, ResponseFileRelativePath) { SmallVector<const char *, 2> Argv = {"test/test", "@dir/outer.rsp"}; BumpPtrAllocator A; - StringSaver Saver(A); - ASSERT_TRUE(cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv, - false, true, false, - /*CurrentDir=*/StringRef(TestRoot), FS)); + llvm::cl::ExpansionContext ECtx(A, cl::TokenizeGNUCommandLine); + ECtx.setVFS(&FS).setCurrentDir(TestRoot).setRelativeNames(true); + ASSERT_TRUE(ECtx.expandResponseFiles(Argv)); EXPECT_THAT(Argv, testing::Pointwise(StringEquality(), {"test/test", "-flag"})); } @@ -1026,10 +1022,10 @@ TEST(CommandLineTest, ResponseFileEOLs) { MemoryBuffer::getMemBuffer("-Xclang -Wno-whatever\n input.cpp")); SmallVector<const char *, 2> Argv = {"clang", "@eols.rsp"}; BumpPtrAllocator A; - StringSaver Saver(A); - ASSERT_TRUE(cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, - Argv, true, true, false, - /*CurrentDir=*/StringRef(TestRoot), FS)); + llvm::cl::ExpansionContext ECtx(A, cl::TokenizeWindowsCommandLine); + ECtx.setVFS(&FS).setCurrentDir(TestRoot).setMarkEOLs(true).setRelativeNames( + true); + ASSERT_TRUE(ECtx.expandResponseFiles(Argv)); const char *Expected[] = {"clang", "-Xclang", "-Wno-whatever", nullptr, "input.cpp"}; ASSERT_EQ(std::size(Expected), Argv.size()); @@ -1125,9 +1121,8 @@ TEST(CommandLineTest, ReadConfigFile) { EXPECT_NE(CurrDir.str(), TestDir.path()); llvm::BumpPtrAllocator A; - llvm::StringSaver Saver(A); - bool Result = llvm::cl::readConfigFile(ConfigFile.path(), Saver, Argv, - *llvm::vfs::getRealFileSystem()); + llvm::cl::ExpansionContext ECtx(A, cl::tokenizeConfigFile); + bool Result = ECtx.readConfigFile(ConfigFile.path(), Argv); EXPECT_TRUE(Result); EXPECT_EQ(Argv.size(), 13U); |