[PATCH] D34687: [Tooling] CompilationDatabase should be able to strip position arguments when `-fsyntax-only` is used
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 29 03:44:15 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306659: [Tooling] FixedCompilationDatabase should be able to strip positional (authored by arphaman).
Changed prior to commit:
https://reviews.llvm.org/D34687?vs=104161&id=104618#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34687
Files:
cfe/trunk/lib/Tooling/CompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
Index: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
===================================================================
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp
@@ -255,10 +255,12 @@
CompileJobAnalyzer CompileAnalyzer;
for (const auto &Cmd : Jobs) {
- // Collect only for Assemble jobs. If we do all jobs we get duplicates
- // since Link jobs point to Assemble jobs as inputs.
- if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
+ // Collect only for Assemble and Compile jobs. If we do all jobs we get
+ // duplicates since Link jobs point to Assemble jobs as inputs.
+ if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass ||
+ Cmd.getSource().getKind() == driver::Action::CompileJobClass) {
CompileAnalyzer.run(&Cmd.getSource());
+ }
}
if (CompileAnalyzer.Inputs.empty()) {
Index: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -586,6 +586,27 @@
EXPECT_EQ(2, Argc);
}
+TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsSyntaxOnly) {
+ // Adjust the given command line arguments to ensure that any positional
+ // arguments in them are stripped.
+ const char *Argv[] = {"--", "somefile.cpp", "-fsyntax-only", "-DDEF3"};
+ int Argc = llvm::array_lengthof(Argv);
+ std::string ErrorMessage;
+ std::unique_ptr<CompilationDatabase> Database =
+ FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMessage);
+ ASSERT_TRUE((bool)Database);
+ ASSERT_TRUE(ErrorMessage.empty());
+ std::vector<CompileCommand> Result = Database->getCompileCommands("source");
+ ASSERT_EQ(1ul, Result.size());
+ ASSERT_EQ(".", Result[0].Directory);
+ std::vector<std::string> Expected;
+ Expected.push_back("clang-tool");
+ Expected.push_back("-fsyntax-only");
+ Expected.push_back("-DDEF3");
+ Expected.push_back("source");
+ ASSERT_EQ(Expected, Result[0].CommandLine);
+}
+
TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"};
int Argc = sizeof(Argv) / sizeof(char*);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34687.104618.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170629/58fceba6/attachment-0001.bin>
More information about the cfe-commits
mailing list