llvm.org GIT mirror llvm / 21cc5d9
On Windows we need to be able to process response files with Windows-style path names. Differential Revision: https://reviews.llvm.org/D43988 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326737 91177308-0d34-0410-b5e6-96231b3b80d8 Dmitry Mikulin 2 years ago
2 changed file(s) with 40 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
2424 #include "llvm/ADT/SmallString.h"
2525 #include "llvm/ADT/StringExtras.h"
2626 #include "llvm/ADT/StringMap.h"
27 #include "llvm/ADT/Triple.h"
2728 #include "llvm/ADT/Twine.h"
2829 #include "llvm/Config/config.h"
2930 #include "llvm/Support/ConvertUTF.h"
10791080 SmallVector newArgv(argv, argv + argc);
10801081 BumpPtrAllocator A;
10811082 StringSaver Saver(A);
1082 ExpandResponseFiles(Saver, TokenizeGNUCommandLine, newArgv);
1083 ExpandResponseFiles(Saver,
1084 Triple(sys::getProcessTriple()).isOSWindows() ?
1085 cl::TokenizeWindowsCommandLine : cl::TokenizeGNUCommandLine,
1086 newArgv);
10831087 argv = &newArgv[0];
10841088 argc = static_cast(newArgv.size());
10851089
99 #include "llvm/Support/CommandLine.h"
1010 #include "llvm/ADT/STLExtras.h"
1111 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/Triple.h"
1213 #include "llvm/Config/config.h"
1314 #include "llvm/Support/FileSystem.h"
1415 #include "llvm/Support/Path.h"
628629 TEST(CommandLineTest, ArgumentLimit) {
629630 std::string args(32 * 4096, 'a');
630631 EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
632 }
633
634 TEST(CommandLineTest, ResponseFileWindows) {
635 if (!Triple(sys::getProcessTriple()).isOSWindows())
636 return;
637
638 static cl::list
639 InputFilenames(cl::Positional, cl::desc(""), cl::ZeroOrMore);
640 StackOption TopLevelOpt("top-level", cl::init(false));
641
642 // Create response file.
643 int FileDescriptor;
644 SmallString<64> TempPath;
645 std::error_code EC =
646 llvm::sys::fs::createTemporaryFile("resp-", ".txt", FileDescriptor, TempPath);
647 EXPECT_TRUE(!EC);
648
649 std::ofstream RspFile(TempPath.c_str());
650 EXPECT_TRUE(RspFile.is_open());
651 RspFile << "-top-level\npath\\dir\\file1\npath/dir/file2";
652 RspFile.close();
653
654 llvm::SmallString<128> RspOpt;
655 RspOpt.append(1, '@');
656 RspOpt.append(TempPath.c_str());
657 const char *args[] = {"prog", RspOpt.c_str()};
658 EXPECT_FALSE(TopLevelOpt);
659 EXPECT_TRUE(
660 cl::ParseCommandLineOptions(2, args, StringRef(), &llvm::nulls()));
661 EXPECT_TRUE(TopLevelOpt);
662 EXPECT_TRUE(InputFilenames[0] == "path\\dir\\file1");
663 EXPECT_TRUE(InputFilenames[1] == "path/dir/file2");
664
665 llvm::sys::fs::remove(TempPath.c_str());
631666 }
632667
633668 TEST(CommandLineTest, ResponseFiles) {