Commit 2ca473d5 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Print command line args for debugging

...if qtc.clangbackend.verboselib=true.

Change-Id: Ibba408db955892daf055b2050d810ce55b9d8913
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 23fa5a7e
......@@ -30,9 +30,12 @@
#include "commandlinearguments.h"
#include <iostream>
namespace ClangBackEnd {
CommandLineArguments::CommandLineArguments(const std::vector<const char *> &projectPartArguments,
CommandLineArguments::CommandLineArguments(const char *filePath,
const std::vector<const char *> &projectPartArguments,
const Utf8StringVector &fileArguments,
bool addVerboseOption)
{
......@@ -46,6 +49,7 @@ CommandLineArguments::CommandLineArguments(const std::vector<const char *> &proj
m_arguments.push_back(argument.constData());
if (addVerboseOption)
m_arguments.push_back("-v");
m_arguments.push_back(filePath);
}
const char * const *CommandLineArguments::data() const
......@@ -58,4 +62,19 @@ int CommandLineArguments::count() const
return int(m_arguments.size());
}
const char *CommandLineArguments::at(int position) const
{
return m_arguments.at(uint(position));
}
void CommandLineArguments::print() const
{
using namespace std;
cerr << "Arguments to libclang:";
for (const auto &argument : m_arguments)
cerr << ' ' << argument;
cerr << endl;
}
} // namespace ClangBackEnd
......@@ -40,12 +40,16 @@ namespace ClangBackEnd {
class CommandLineArguments
{
public:
CommandLineArguments(const std::vector<const char *> &projectPartArguments,
CommandLineArguments(const char *filePath,
const std::vector<const char *> &projectPartArguments,
const Utf8StringVector &fileArguments,
bool addVerboseOption);
const char * const *data() const;
int count() const;
const char * at(int position) const;
void print() const;
private:
std::vector<const char *> m_arguments;
......
......@@ -276,11 +276,12 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
if (!d->translationUnit) {
d->translationUnit = CXTranslationUnit();
const bool verboseMode = isVerboseModeEnabled();
const CommandLineArguments args(d->projectPart.arguments(), d->fileArguments, verboseMode);
const auto args = commandLineArguments();
if (isVerboseModeEnabled())
args.print();
CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
d->filePath.constData(),
NULL,
args.data(),
args.count(),
unsavedFiles().cxUnsavedFiles(),
......@@ -292,7 +293,6 @@ void TranslationUnit::createTranslationUnitIfNeeded() const
updateIncludeFilePaths();
updateLastProjectPartChangeTimePoint();
}
}
......@@ -356,6 +356,14 @@ void TranslationUnit::updateIncludeFilePaths() const
d->translationUnits.addWatchedFiles(d->dependedFilePaths);
}
CommandLineArguments TranslationUnit::commandLineArguments() const
{
return CommandLineArguments(d->filePath.constData(),
d->projectPart.arguments(),
d->fileArguments,
isVerboseModeEnabled());
}
uint TranslationUnit::defaultOptions()
{
return CXTranslationUnit_CacheCompletionResults
......
......@@ -52,6 +52,7 @@ class ProjectPart;
class DiagnosticSet;
class FileContainer;
class TranslationUnits;
class CommandLineArguments;
using time_point = std::chrono::steady_clock::time_point;
......@@ -106,6 +107,8 @@ public:
void setDirtyIfDependencyIsMet(const Utf8String &filePath);
CommandLineArguments commandLineArguments() const;
private:
void checkIfNull() const;
void checkIfFileExists() const;
......
......@@ -28,6 +28,7 @@
**
****************************************************************************/
#include <commandlinearguments.h>
#include <diagnosticset.h>
#include <filecontainer.h>
#include <projectpart.h>
......@@ -61,6 +62,7 @@ using ClangBackEnd::TranslationUnits;
using testing::IsNull;
using testing::NotNull;
using testing::Eq;
using testing::Gt;
using testing::Contains;
using testing::EndsWith;
......@@ -148,6 +150,13 @@ TEST_F(TranslationUnit, ResetedTranslationUnitIsNull)
ASSERT_TRUE(translationUnit.isNull());
}
TEST_F(TranslationUnit, LastCommandLineArgumentIsFilePath)
{
const auto arguments = translationUnit.commandLineArguments();
ASSERT_THAT(arguments.at(arguments.count() - 1), Eq(translationUnitFilePath));
}
TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated)
{
auto lastChangeTimePoint = translationUnit.lastProjectPartChangeTimePoint();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment