2015-11-05 13:57:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-11-05 13:57:57 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-11-05 13:57:57 +01:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-11-05 13:57:57 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "commandlinearguments.h"
|
|
|
|
|
|
2016-07-01 15:07:32 +02:00
|
|
|
#include "clangfilepath.h"
|
|
|
|
|
|
2015-11-16 16:47:46 +01:00
|
|
|
#include <utf8string.h>
|
2016-07-05 11:02:56 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2015-11-16 16:47:46 +01:00
|
|
|
|
2016-07-01 15:07:32 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2015-11-05 13:57:57 +01:00
|
|
|
namespace ClangBackEnd {
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
CommandLineArguments::CommandLineArguments(const char *filePath,
|
2016-05-30 10:25:52 +02:00
|
|
|
const Utf8StringVector &projectPartArguments,
|
2015-11-05 13:57:57 +01:00
|
|
|
const Utf8StringVector &fileArguments,
|
|
|
|
|
bool addVerboseOption)
|
|
|
|
|
{
|
|
|
|
|
const auto elementsToReserve = projectPartArguments.size()
|
|
|
|
|
+ uint(fileArguments.size())
|
|
|
|
|
+ (addVerboseOption ? 1 : 0);
|
|
|
|
|
m_arguments.reserve(elementsToReserve);
|
|
|
|
|
|
2016-05-30 10:25:52 +02:00
|
|
|
for (const auto &argument : projectPartArguments)
|
|
|
|
|
m_arguments.push_back(argument.constData());
|
2015-11-05 13:57:57 +01:00
|
|
|
for (const auto &argument : fileArguments)
|
|
|
|
|
m_arguments.push_back(argument.constData());
|
|
|
|
|
if (addVerboseOption)
|
|
|
|
|
m_arguments.push_back("-v");
|
2016-07-01 15:07:32 +02:00
|
|
|
m_nativeFilePath = FilePath::toNativeSeparators(Utf8String::fromUtf8(filePath));
|
|
|
|
|
m_arguments.push_back(m_nativeFilePath.constData());
|
2015-11-05 13:57:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * const *CommandLineArguments::data() const
|
|
|
|
|
{
|
|
|
|
|
return m_arguments.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CommandLineArguments::count() const
|
|
|
|
|
{
|
|
|
|
|
return int(m_arguments.size());
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
const char *CommandLineArguments::at(int position) const
|
|
|
|
|
{
|
|
|
|
|
return m_arguments.at(uint(position));
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 16:47:46 +01:00
|
|
|
static Utf8String maybeQuoted(const char *argumentAsCString)
|
|
|
|
|
{
|
2016-07-05 11:02:56 +02:00
|
|
|
const QString argumentAsQString = QString::fromUtf8(argumentAsCString);
|
|
|
|
|
const QString quotedArgument = Utils::QtcProcess::quoteArg(argumentAsQString);
|
2015-11-16 16:47:46 +01:00
|
|
|
|
2016-07-05 11:02:56 +02:00
|
|
|
return Utf8String::fromString(quotedArgument);
|
2015-11-16 16:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-06 11:16:53 +01:00
|
|
|
void CommandLineArguments::print() const
|
|
|
|
|
{
|
|
|
|
|
using namespace std;
|
|
|
|
|
cerr << "Arguments to libclang:";
|
|
|
|
|
for (const auto &argument : m_arguments)
|
2015-11-16 16:47:46 +01:00
|
|
|
cerr << ' ' << maybeQuoted(argument).constData();
|
2015-11-06 11:16:53 +01:00
|
|
|
cerr << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-05 13:57:57 +01:00
|
|
|
} // namespace ClangBackEnd
|