[clang] 0f12f90 - Revert "[llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFiles"
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 4 06:58:21 PST 2019
Author: Kadir Cetinkaya
Date: 2019-12-04T15:58:01+01:00
New Revision: 0f12f9096e1e33d88cb0b5601b0e035a2674c19a
URL: https://github.com/llvm/llvm-project/commit/0f12f9096e1e33d88cb0b5601b0e035a2674c19a
DIFF: https://github.com/llvm/llvm-project/commit/0f12f9096e1e33d88cb0b5601b0e035a2674c19a.diff
LOG: Revert "[llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFiles"
This reverts commit 75656005dbc8866e1888932a68a830b0df403560.
Added:
Modified:
clang/include/clang/Tooling/CompilationDatabase.h
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/lib/Tooling/JSONCompilationDatabase.cpp
llvm/include/llvm/Support/CommandLine.h
llvm/lib/Support/CommandLine.cpp
llvm/unittests/Support/CommandLineTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/CompilationDatabase.h b/clang/include/clang/Tooling/CompilationDatabase.h
index b28a8a6d6e51..6f794e517875 100644
--- a/clang/include/clang/Tooling/CompilationDatabase.h
+++ b/clang/include/clang/Tooling/CompilationDatabase.h
@@ -222,6 +222,7 @@ inferTargetAndDriverMode(std::unique_ptr<CompilationDatabase> Base);
/// Returns a wrapped CompilationDatabase that will expand all rsp(response)
/// files on commandline returned by underlying database.
+/// Note: This may change the working directory of FS.
std::unique_ptr<CompilationDatabase>
expandResponseFiles(std::unique_ptr<CompilationDatabase> Base,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
diff --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
index 84936ba05b20..bb519277dfad 100644
--- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "clang/Tooling/CompilationDatabase.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConvertUTF.h"
@@ -48,6 +47,12 @@ class ExpandResponseFilesDatabase : public CompilationDatabase {
private:
std::vector<CompileCommand> expand(std::vector<CompileCommand> Cmds) const {
for (auto &Cmd : Cmds) {
+ // FIXME: we should rather propagate the current directory into
+ // ExpandResponseFiles as well in addition to FS.
+ if (std::error_code EC = FS->setCurrentWorkingDirectory(Cmd.Directory)) {
+ llvm::consumeError(llvm::errorCodeToError(EC));
+ continue;
+ }
bool SeenRSPFile = false;
llvm::SmallVector<const char *, 20> Argv;
Argv.reserve(Cmd.CommandLine.size());
@@ -59,8 +64,7 @@ class ExpandResponseFilesDatabase : public CompilationDatabase {
continue;
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver(Alloc);
- llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, *FS,
- llvm::StringRef(Cmd.Directory));
+ llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, *FS);
Cmd.CommandLine.assign(Argv.begin(), Argv.end());
}
return Cmds;
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 04dd4dbf6248..8dd460839020 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -29,7 +29,6 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"
-#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
@@ -170,7 +169,8 @@ class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin {
JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect);
return Base ? inferTargetAndDriverMode(
inferMissingCompileCommands(expandResponseFiles(
- std::move(Base), llvm::vfs::getRealFileSystem())))
+ std::move(Base),
+ llvm::vfs::createPhysicalFileSystem().release())))
: nullptr;
}
};
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 6c0bb6c2fc3a..5966febdf2b0 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -20,8 +20,6 @@
#define LLVM_SUPPORT_COMMANDLINE_H
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -1968,15 +1966,12 @@ bool readConfigFile(StringRef CfgFileName, StringSaver &Saver,
/// \param [in] RelativeNames true if names of nested response files must be
/// resolved relative to including file.
/// \param [in] FS File system used for all file access when running the tool.
-/// \param [in] CurrentDir Path used to resolve relative rsp files. If set to
-/// None, process' cwd is used instead.
/// \return true if all @files were expanded successfully or there were none.
bool ExpandResponseFiles(
StringSaver &Saver, TokenizerCallback Tokenizer,
SmallVectorImpl<const char *> &Argv, bool MarkEOLs = false,
bool RelativeNames = false,
- llvm::vfs::FileSystem &FS = *llvm::vfs::getRealFileSystem(),
- llvm::Optional<llvm::StringRef> CurrentDir = llvm::None);
+ llvm::vfs::FileSystem &FS = *llvm::vfs::getRealFileSystem());
/// Mark all options not part of this category as cl::ReallyHidden.
///
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 1f424075d47f..daeab6fade54 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -24,7 +24,6 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"
@@ -43,7 +42,6 @@
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <map>
-#include <string>
using namespace llvm;
using namespace cl;
@@ -1047,12 +1045,14 @@ static bool hasUTF8ByteOrderMark(ArrayRef<char> S) {
return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' && S[2] == '\xbf');
}
-// FName must be an absolute path.
-static llvm::Error ExpandResponseFile(
- StringRef FName, StringSaver &Saver, TokenizerCallback Tokenizer,
- SmallVectorImpl<const char *> &NewArgv, bool MarkEOLs, bool RelativeNames,
- llvm::vfs::FileSystem &FS) {
- assert(sys::path::is_absolute(FName));
+static llvm::Error ExpandResponseFile(StringRef FName, StringSaver &Saver,
+ TokenizerCallback Tokenizer,
+ SmallVectorImpl<const char *> &NewArgv,
+ bool MarkEOLs, bool RelativeNames,
+ llvm::vfs::FileSystem &FS) {
+ llvm::ErrorOr<std::string> CurrDirOrErr = FS.getCurrentWorkingDirectory();
+ if (!CurrDirOrErr)
+ return llvm::errorCodeToError(CurrDirOrErr.getError());
llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr =
FS.getBufferForFile(FName);
if (!MemBufOrErr)
@@ -1078,28 +1078,28 @@ static llvm::Error ExpandResponseFile(
// Tokenize the contents into NewArgv.
Tokenizer(Str, Saver, NewArgv, MarkEOLs);
- if (!RelativeNames)
- return Error::success();
- llvm::StringRef BasePath = llvm::sys::path::parent_path(FName);
// If names of nested response files should be resolved relative to including
// file, replace the included response file names with their full paths
// obtained by required resolution.
- for (auto &Arg : NewArgv) {
- // Skip non-rsp file arguments.
- if (!Arg || Arg[0] != '@')
- continue;
-
- StringRef FileName(Arg + 1);
- // Skip if non-relative.
- if (!llvm::sys::path::is_relative(FileName))
- continue;
+ if (RelativeNames)
+ for (unsigned I = 0; I < NewArgv.size(); ++I)
+ if (NewArgv[I]) {
+ StringRef Arg = NewArgv[I];
+ if (Arg.front() == '@') {
+ StringRef FileName = Arg.drop_front();
+ if (llvm::sys::path::is_relative(FileName)) {
+ SmallString<128> ResponseFile;
+ ResponseFile.append(1, '@');
+ if (llvm::sys::path::is_relative(FName)) {
+ ResponseFile.append(CurrDirOrErr.get());
+ }
+ llvm::sys::path::append(
+ ResponseFile, llvm::sys::path::parent_path(FName), FileName);
+ NewArgv[I] = Saver.save(ResponseFile.c_str()).data();
+ }
+ }
+ }
- SmallString<128> ResponseFile;
- ResponseFile.push_back('@');
- ResponseFile.append(BasePath);
- llvm::sys::path::append(ResponseFile, FileName);
- Arg = Saver.save(ResponseFile.c_str()).data();
- }
return Error::success();
}
@@ -1107,11 +1107,10 @@ static llvm::Error ExpandResponseFile(
/// StringSaver and tokenization strategy.
bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
- bool RelativeNames, llvm::vfs::FileSystem &FS,
- llvm::Optional<llvm::StringRef> CurrentDir) {
+ bool RelativeNames, llvm::vfs::FileSystem &FS) {
bool AllExpanded = true;
struct ResponseFileRecord {
- std::string File;
+ const char *File;
size_t End;
};
@@ -1145,17 +1144,6 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
}
const char *FName = Arg + 1;
- // Note that CurrentDir is only used for top-level rsp files, the rest will
- // always have an absolute path deduced from the containing file.
- SmallString<128> CurrDir;
- if (llvm::sys::path::is_relative(FName)) {
- if (!CurrentDir)
- llvm::sys::fs::current_path(CurrDir);
- else
- CurrDir = *CurrentDir;
- llvm::sys::path::append(CurrDir, FName);
- FName = CurrDir.c_str();
- }
auto IsEquivalent = [FName, &FS](const ResponseFileRecord &RFile) {
llvm::ErrorOr<llvm::vfs::Status> LHS = FS.status(FName);
if (!LHS) {
@@ -1218,12 +1206,6 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver,
SmallVectorImpl<const char *> &Argv) {
- SmallString<128> AbsPath;
- if (sys::path::is_relative(CfgFile)) {
- llvm::sys::fs::current_path(AbsPath);
- llvm::sys::path::append(AbsPath, CfgFile);
- CfgFile = AbsPath.str();
- }
if (llvm::Error Err =
ExpandResponseFile(CfgFile, Saver, cl::tokenizeConfigFile, Argv,
/*MarkEOLs*/ false, /*RelativeNames*/ true,
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 6adc93856763..1948413070ae 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -9,33 +9,23 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Config/config.h"
-#include "llvm/Support/Allocator.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/StringSaver.h"
-#include "llvm/Support/VirtualFileSystem.h"
-#include "llvm/Support/raw_ostream.h"
-#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <fstream>
#include <stdlib.h>
#include <string>
-#include <tuple>
using namespace llvm;
namespace {
-MATCHER(StringEquality, "Checks if two char* are equal as strings") {
- return std::string(std::get<0>(arg)) == std::string(std::get<1>(arg));
-}
-
class TempEnvVar {
public:
TempEnvVar(const char *name, const char *value)
@@ -788,90 +778,119 @@ TEST(CommandLineTest, ResponseFileWindows) {
}
TEST(CommandLineTest, ResponseFiles) {
- vfs::InMemoryFileSystem FS;
- FS.setCurrentWorkingDirectory("/");
+ llvm::SmallString<128> TestDir;
+ std::error_code EC =
+ llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+ EXPECT_TRUE(!EC);
// Create included response file of first level.
- llvm::StringRef IncludedFileName = "resp1";
- FS.addFile(IncludedFileName, 0,
- llvm::MemoryBuffer::getMemBuffer("-option_1 -option_2\n"
- "@incdir/resp2\n"
- "-option_3=abcd\n"
- "@incdir/resp3\n"
- "-option_4=efjk\n"));
+ llvm::SmallString<128> IncludedFileName;
+ llvm::sys::path::append(IncludedFileName, TestDir, "resp1");
+ std::ofstream IncludedFile(IncludedFileName.c_str());
+ EXPECT_TRUE(IncludedFile.is_open());
+ IncludedFile << "-option_1 -option_2\n"
+ "@incdir/resp2\n"
+ "-option_3=abcd\n"
+ "@incdir/resp3\n"
+ "-option_4=efjk\n";
+ IncludedFile.close();
// Directory for included file.
- llvm::StringRef IncDir = "incdir";
+ llvm::SmallString<128> IncDir;
+ llvm::sys::path::append(IncDir, TestDir, "incdir");
+ EC = llvm::sys::fs::create_directory(IncDir);
+ EXPECT_TRUE(!EC);
// Create included response file of second level.
llvm::SmallString<128> IncludedFileName2;
llvm::sys::path::append(IncludedFileName2, IncDir, "resp2");
- FS.addFile(IncludedFileName2, 0,
- MemoryBuffer::getMemBuffer("-option_21 -option_22\n"
- "-option_23=abcd\n"));
- llvm::errs() << "Added: " << IncludedFileName2 << '\n';
+ std::ofstream IncludedFile2(IncludedFileName2.c_str());
+ EXPECT_TRUE(IncludedFile2.is_open());
+ IncludedFile2 << "-option_21 -option_22\n";
+ IncludedFile2 << "-option_23=abcd\n";
+ IncludedFile2.close();
// Create second included response file of second level.
llvm::SmallString<128> IncludedFileName3;
llvm::sys::path::append(IncludedFileName3, IncDir, "resp3");
- FS.addFile(IncludedFileName3, 0,
- MemoryBuffer::getMemBuffer("-option_31 -option_32\n"
- "-option_33=abcd\n"));
+ std::ofstream IncludedFile3(IncludedFileName3.c_str());
+ EXPECT_TRUE(IncludedFile3.is_open());
+ IncludedFile3 << "-option_31 -option_32\n";
+ IncludedFile3 << "-option_33=abcd\n";
+ IncludedFile3.close();
// Prepare 'file' with reference to response file.
SmallString<128> IncRef;
IncRef.append(1, '@');
- IncRef.append(IncludedFileName);
- llvm::SmallVector<const char *, 4> Argv = {"test/test", "-flag_1",
- IncRef.c_str(), "-flag_2"};
+ IncRef.append(IncludedFileName.c_str());
+ llvm::SmallVector<const char *, 4> Argv =
+ { "test/test", "-flag_1", IncRef.c_str(), "-flag_2" };
// Expand response files.
llvm::BumpPtrAllocator A;
llvm::StringSaver Saver(A);
- ASSERT_TRUE(llvm::cl::ExpandResponseFiles(
- Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true, FS,
- /*CurrentDir=*/StringRef("/")));
- EXPECT_THAT(Argv, testing::Pointwise(
- StringEquality(),
- {"test/test", "-flag_1", "-option_1", "-option_2",
- "-option_21", "-option_22", "-option_23=abcd",
- "-option_3=abcd", "-option_31", "-option_32",
- "-option_33=abcd", "-option_4=efjk", "-flag_2"}));
+ bool Res = llvm::cl::ExpandResponseFiles(
+ Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true);
+ EXPECT_TRUE(Res);
+ EXPECT_EQ(Argv.size(), 13U);
+ EXPECT_STREQ(Argv[0], "test/test");
+ EXPECT_STREQ(Argv[1], "-flag_1");
+ EXPECT_STREQ(Argv[2], "-option_1");
+ EXPECT_STREQ(Argv[3], "-option_2");
+ EXPECT_STREQ(Argv[4], "-option_21");
+ EXPECT_STREQ(Argv[5], "-option_22");
+ EXPECT_STREQ(Argv[6], "-option_23=abcd");
+ EXPECT_STREQ(Argv[7], "-option_3=abcd");
+ EXPECT_STREQ(Argv[8], "-option_31");
+ EXPECT_STREQ(Argv[9], "-option_32");
+ EXPECT_STREQ(Argv[10], "-option_33=abcd");
+ EXPECT_STREQ(Argv[11], "-option_4=efjk");
+ EXPECT_STREQ(Argv[12], "-flag_2");
+
+ llvm::sys::fs::remove(IncludedFileName3);
+ llvm::sys::fs::remove(IncludedFileName2);
+ llvm::sys::fs::remove(IncDir);
+ llvm::sys::fs::remove(IncludedFileName);
+ llvm::sys::fs::remove(TestDir);
}
TEST(CommandLineTest, RecursiveResponseFiles) {
- vfs::InMemoryFileSystem FS;
- FS.setCurrentWorkingDirectory("/");
+ SmallString<128> TestDir;
+ std::error_code EC = sys::fs::createUniqueDirectory("unittest", TestDir);
+ EXPECT_TRUE(!EC);
- StringRef SelfFilePath = "self.rsp";
- std::string SelfFileRef = ("@" + SelfFilePath).str();
+ SmallString<128> SelfFilePath;
+ sys::path::append(SelfFilePath, TestDir, "self.rsp");
+ std::string SelfFileRef = std::string("@") + SelfFilePath.c_str();
- StringRef NestedFilePath = "nested.rsp";
- std::string NestedFileRef = ("@" + NestedFilePath).str();
+ SmallString<128> NestedFilePath;
+ sys::path::append(NestedFilePath, TestDir, "nested.rsp");
+ std::string NestedFileRef = std::string("@") + NestedFilePath.c_str();
- StringRef FlagFilePath = "flag.rsp";
- std::string FlagFileRef = ("@" + FlagFilePath).str();
+ SmallString<128> FlagFilePath;
+ sys::path::append(FlagFilePath, TestDir, "flag.rsp");
+ std::string FlagFileRef = std::string("@") + FlagFilePath.c_str();
- std::string SelfFileContents;
- raw_string_ostream SelfFile(SelfFileContents);
+ std::ofstream SelfFile(SelfFilePath.str());
+ EXPECT_TRUE(SelfFile.is_open());
SelfFile << "-option_1\n";
SelfFile << FlagFileRef << "\n";
SelfFile << NestedFileRef << "\n";
SelfFile << SelfFileRef << "\n";
- FS.addFile(SelfFilePath, 0, MemoryBuffer::getMemBuffer(SelfFile.str()));
+ SelfFile.close();
- std::string NestedFileContents;
- raw_string_ostream NestedFile(NestedFileContents);
+ std::ofstream NestedFile(NestedFilePath.str());
+ EXPECT_TRUE(NestedFile.is_open());
NestedFile << "-option_2\n";
NestedFile << FlagFileRef << "\n";
NestedFile << SelfFileRef << "\n";
NestedFile << NestedFileRef << "\n";
- FS.addFile(NestedFilePath, 0, MemoryBuffer::getMemBuffer(NestedFile.str()));
+ NestedFile.close();
- std::string FlagFileContents;
- raw_string_ostream FlagFile(FlagFileContents);
+ std::ofstream FlagFile(FlagFilePath.str());
+ EXPECT_TRUE(FlagFile.is_open());
FlagFile << "-option_x\n";
- FS.addFile(FlagFilePath, 0, MemoryBuffer::getMemBuffer(FlagFile.str()));
+ FlagFile.close();
// Ensure:
// Recursive expansion terminates
@@ -886,42 +905,47 @@ TEST(CommandLineTest, RecursiveResponseFiles) {
#else
cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine;
#endif
- ASSERT_FALSE(cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, FS,
- /*CurrentDir=*/llvm::StringRef("/")));
-
- EXPECT_THAT(Argv,
- testing::Pointwise(StringEquality(),
- {"test/test", "-option_1", "-option_x",
- "-option_2", "-option_x", SelfFileRef.c_str(),
- NestedFileRef.c_str(), SelfFileRef.c_str(),
- "-option_3"}));
+ bool Res = cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false);
+ EXPECT_FALSE(Res);
+
+ EXPECT_EQ(Argv.size(), 9U);
+ EXPECT_STREQ(Argv[0], "test/test");
+ EXPECT_STREQ(Argv[1], "-option_1");
+ EXPECT_STREQ(Argv[2], "-option_x");
+ EXPECT_STREQ(Argv[3], "-option_2");
+ EXPECT_STREQ(Argv[4], "-option_x");
+ EXPECT_STREQ(Argv[5], SelfFileRef.c_str());
+ EXPECT_STREQ(Argv[6], NestedFileRef.c_str());
+ EXPECT_STREQ(Argv[7], SelfFileRef.c_str());
+ EXPECT_STREQ(Argv[8], "-option_3");
}
TEST(CommandLineTest, ResponseFilesAtArguments) {
- vfs::InMemoryFileSystem FS;
- FS.setCurrentWorkingDirectory("/");
+ SmallString<128> TestDir;
+ std::error_code EC = sys::fs::createUniqueDirectory("unittest", TestDir);
+ EXPECT_TRUE(!EC);
- StringRef ResponseFilePath = "test.rsp";
+ SmallString<128> ResponseFilePath;
+ sys::path::append(ResponseFilePath, TestDir, "test.rsp");
- std::string ResponseFileContents;
- raw_string_ostream ResponseFile(ResponseFileContents);
+ std::ofstream ResponseFile(ResponseFilePath.c_str());
+ EXPECT_TRUE(ResponseFile.is_open());
ResponseFile << "-foo" << "\n";
ResponseFile << "-bar" << "\n";
- FS.addFile(ResponseFilePath, 0,
- MemoryBuffer::getMemBuffer(ResponseFile.str()));
+ ResponseFile.close();
// Ensure we expand rsp files after lots of non-rsp arguments starting with @.
constexpr size_t NON_RSP_AT_ARGS = 64;
SmallVector<const char *, 4> Argv = {"test/test"};
Argv.append(NON_RSP_AT_ARGS, "@non_rsp_at_arg");
- std::string ResponseFileRef = ("@" + ResponseFilePath).str();
+ std::string ResponseFileRef = std::string("@") + ResponseFilePath.c_str();
Argv.push_back(ResponseFileRef.c_str());
BumpPtrAllocator A;
StringSaver Saver(A);
- ASSERT_FALSE(cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
- false, false, FS,
- /*CurrentDir=*/StringRef("/")));
+ bool Res = cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
+ false, false);
+ EXPECT_FALSE(Res);
// ASSERT instead of EXPECT to prevent potential out-of-bounds access.
ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2);
@@ -933,28 +957,6 @@ TEST(CommandLineTest, ResponseFilesAtArguments) {
EXPECT_STREQ(Argv[i++], "-bar");
}
-TEST(CommandLineTest, ResponseFileRelativePath) {
- vfs::InMemoryFileSystem FS;
-
- StringRef OuterFile = "//net/dir/outer.rsp";
- StringRef OuterFileContents = "@inner.rsp";
- FS.addFile(OuterFile, 0, MemoryBuffer::getMemBuffer(OuterFileContents));
-
- StringRef InnerFile = "//net/dir/inner.rsp";
- StringRef InnerFileContents = "-flag";
- FS.addFile(InnerFile, 0, MemoryBuffer::getMemBuffer(InnerFileContents));
-
- 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, FS,
- /*CurrentDir=*/StringRef("//net")));
- EXPECT_THAT(Argv,
- testing::Pointwise(StringEquality(), {"test/test", "-flag"}));
-}
-
TEST(CommandLineTest, SetDefautValue) {
cl::ResetCommandLineParser();
More information about the cfe-commits
mailing list