2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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:58:39 +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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "optionsparser.h"
|
|
|
|
|
|
2015-03-31 17:42:14 +02:00
|
|
|
#include "pluginmanager.h"
|
|
|
|
|
#include "pluginmanager_p.h"
|
2015-03-31 09:55:50 +02:00
|
|
|
#include "pluginspec_p.h"
|
|
|
|
|
|
2016-02-11 11:53:31 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ExtensionSystem;
|
|
|
|
|
using namespace ExtensionSystem::Internal;
|
|
|
|
|
|
2013-09-26 13:01:29 +02:00
|
|
|
const char END_OF_OPTIONS[] = "--";
|
2008-12-02 12:01:29 +01:00
|
|
|
const char *OptionsParser::NO_LOAD_OPTION = "-noload";
|
2013-02-12 13:19:15 +01:00
|
|
|
const char *OptionsParser::LOAD_OPTION = "-load";
|
2008-12-02 12:01:29 +01:00
|
|
|
const char *OptionsParser::TEST_OPTION = "-test";
|
2016-02-11 11:53:31 +01:00
|
|
|
const char *OptionsParser::NOTEST_OPTION = "-notest";
|
2010-03-02 12:33:51 +01:00
|
|
|
const char *OptionsParser::PROFILE_OPTION = "-profile";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
OptionsParser::OptionsParser(const QStringList &args,
|
|
|
|
|
const QMap<QString, bool> &appOptions,
|
|
|
|
|
QMap<QString, QString> *foundAppOptions,
|
|
|
|
|
QString *errorString,
|
|
|
|
|
PluginManagerPrivate *pmPrivate)
|
|
|
|
|
: m_args(args), m_appOptions(appOptions),
|
|
|
|
|
m_foundAppOptions(foundAppOptions),
|
|
|
|
|
m_errorString(errorString),
|
|
|
|
|
m_pmPrivate(pmPrivate),
|
|
|
|
|
m_it(m_args.constBegin()),
|
|
|
|
|
m_end(m_args.constEnd()),
|
|
|
|
|
m_isDependencyRefreshNeeded(false),
|
|
|
|
|
m_hasError(false)
|
|
|
|
|
{
|
|
|
|
|
++m_it; // jump over program name
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
m_errorString->clear();
|
|
|
|
|
if (m_foundAppOptions)
|
|
|
|
|
m_foundAppOptions->clear();
|
|
|
|
|
m_pmPrivate->arguments.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OptionsParser::parse()
|
|
|
|
|
{
|
|
|
|
|
while (!m_hasError) {
|
|
|
|
|
if (!nextToken()) // move forward
|
|
|
|
|
break;
|
|
|
|
|
if (checkForEndOfOptions())
|
|
|
|
|
break;
|
2013-02-12 13:19:15 +01:00
|
|
|
if (checkForLoadOption())
|
|
|
|
|
continue;
|
2008-12-02 12:01:29 +01:00
|
|
|
if (checkForNoLoadOption())
|
|
|
|
|
continue;
|
2010-03-02 12:33:51 +01:00
|
|
|
if (checkForProfilingOption())
|
|
|
|
|
continue;
|
2012-09-04 12:03:43 +02:00
|
|
|
#ifdef WITH_TESTS
|
2016-02-11 11:53:31 +01:00
|
|
|
if (checkForTestOptions())
|
2008-12-02 12:01:29 +01:00
|
|
|
continue;
|
2012-09-04 12:03:43 +02:00
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
if (checkForAppOption())
|
|
|
|
|
continue;
|
|
|
|
|
if (checkForPluginOption())
|
|
|
|
|
continue;
|
|
|
|
|
if (checkForUnknownOption())
|
|
|
|
|
break;
|
|
|
|
|
// probably a file or something
|
|
|
|
|
m_pmPrivate->arguments << m_currentArg;
|
|
|
|
|
}
|
2017-08-16 13:50:24 +02:00
|
|
|
if (PluginManager::testRunRequested()) {
|
|
|
|
|
m_isDependencyRefreshNeeded = true;
|
|
|
|
|
forceDisableAllPluginsExceptTestedAndForceEnabled();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_isDependencyRefreshNeeded)
|
2017-08-16 13:50:24 +02:00
|
|
|
m_pmPrivate->enableDependenciesIndirectly();
|
2008-12-02 12:01:29 +01:00
|
|
|
return !m_hasError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OptionsParser::checkForEndOfOptions()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentArg != QLatin1String(END_OF_OPTIONS))
|
|
|
|
|
return false;
|
|
|
|
|
while (nextToken()) {
|
|
|
|
|
m_pmPrivate->arguments << m_currentArg;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-11 11:53:31 +01:00
|
|
|
bool OptionsParser::checkForTestOptions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-02-11 11:53:31 +01:00
|
|
|
if (m_currentArg == QLatin1String(TEST_OPTION)) {
|
|
|
|
|
if (nextToken(RequiredToken)) {
|
|
|
|
|
if (m_currentArg == QLatin1String("all")) {
|
2016-06-22 13:03:00 +02:00
|
|
|
m_pmPrivate->testSpecs =
|
|
|
|
|
Utils::transform(m_pmPrivate->loadQueue(), [](PluginSpec *spec) {
|
|
|
|
|
return PluginManagerPrivate::TestSpec(spec);
|
|
|
|
|
});
|
2016-02-11 11:53:31 +01:00
|
|
|
} else {
|
|
|
|
|
QStringList args = m_currentArg.split(QLatin1Char(','));
|
|
|
|
|
const QString pluginName = args.takeFirst();
|
|
|
|
|
if (PluginSpec *spec = m_pmPrivate->pluginByName(pluginName)) {
|
|
|
|
|
if (m_pmPrivate->containsTestSpec(spec)) {
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
|
|
|
|
"The plugin \"%1\" is specified twice for testing.").arg(pluginName);
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
} else {
|
|
|
|
|
m_pmPrivate->testSpecs.append(PluginManagerPrivate::TestSpec(spec, args));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
|
|
|
|
"The plugin \"%1\" does not exist.").arg(pluginName);
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
}
|
2011-02-16 13:40:44 +01:00
|
|
|
}
|
2016-02-11 11:53:31 +01:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else if (m_currentArg == QLatin1String(NOTEST_OPTION)) {
|
|
|
|
|
if (nextToken(RequiredToken)) {
|
|
|
|
|
if (PluginSpec *spec = m_pmPrivate->pluginByName(m_currentArg)) {
|
|
|
|
|
if (!m_pmPrivate->containsTestSpec(spec)) {
|
2013-03-20 16:31:14 +01:00
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
2016-02-11 11:53:31 +01:00
|
|
|
"The plugin \"%1\" is not tested.").arg(m_currentArg);
|
2013-03-20 16:31:14 +01:00
|
|
|
m_hasError = true;
|
|
|
|
|
} else {
|
2016-02-11 11:53:31 +01:00
|
|
|
m_pmPrivate->removeTestSpec(spec);
|
2013-03-20 16:31:14 +01:00
|
|
|
}
|
2016-02-11 11:53:31 +01:00
|
|
|
} else {
|
2011-02-16 13:40:44 +01:00
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
2016-02-11 11:53:31 +01:00
|
|
|
"The plugin \"%1\" does not exist.").arg(m_currentArg);
|
2011-02-16 13:40:44 +01:00
|
|
|
m_hasError = true;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-02-11 11:53:31 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-02-11 11:53:31 +01:00
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-12 13:19:15 +01:00
|
|
|
bool OptionsParser::checkForLoadOption()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentArg != QLatin1String(LOAD_OPTION))
|
|
|
|
|
return false;
|
|
|
|
|
if (nextToken(RequiredToken)) {
|
2015-03-30 17:50:25 +02:00
|
|
|
if (m_currentArg == QLatin1String("all")) {
|
|
|
|
|
foreach (PluginSpec *spec, m_pmPrivate->pluginSpecs)
|
|
|
|
|
spec->d->setForceEnabled(true);
|
2013-02-12 13:19:15 +01:00
|
|
|
m_isDependencyRefreshNeeded = true;
|
2015-03-30 17:50:25 +02:00
|
|
|
} else {
|
|
|
|
|
PluginSpec *spec = m_pmPrivate->pluginByName(m_currentArg);
|
|
|
|
|
if (!spec) {
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
|
|
|
|
"The plugin \"%1\" does not exist.")
|
|
|
|
|
.arg(m_currentArg);
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
} else {
|
|
|
|
|
spec->d->setForceEnabled(true);
|
|
|
|
|
m_isDependencyRefreshNeeded = true;
|
|
|
|
|
}
|
2013-02-12 13:19:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool OptionsParser::checkForNoLoadOption()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentArg != QLatin1String(NO_LOAD_OPTION))
|
|
|
|
|
return false;
|
|
|
|
|
if (nextToken(RequiredToken)) {
|
2015-03-30 17:50:25 +02:00
|
|
|
if (m_currentArg == QLatin1String("all")) {
|
|
|
|
|
foreach (PluginSpec *spec, m_pmPrivate->pluginSpecs)
|
|
|
|
|
spec->d->setForceDisabled(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_isDependencyRefreshNeeded = true;
|
2015-03-30 17:50:25 +02:00
|
|
|
} else {
|
|
|
|
|
PluginSpec *spec = m_pmPrivate->pluginByName(m_currentArg);
|
|
|
|
|
if (!spec) {
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
|
|
|
|
"The plugin \"%1\" does not exist.").arg(m_currentArg);
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
} else {
|
|
|
|
|
spec->d->setForceDisabled(true);
|
|
|
|
|
// recursively disable all plugins that require this plugin
|
|
|
|
|
foreach (PluginSpec *dependantSpec, PluginManager::pluginsRequiringPlugin(spec))
|
|
|
|
|
dependantSpec->d->setForceDisabled(true);
|
|
|
|
|
m_isDependencyRefreshNeeded = true;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OptionsParser::checkForAppOption()
|
|
|
|
|
{
|
|
|
|
|
if (!m_appOptions.contains(m_currentArg))
|
|
|
|
|
return false;
|
|
|
|
|
QString option = m_currentArg;
|
|
|
|
|
QString argument;
|
|
|
|
|
if (m_appOptions.value(m_currentArg) && nextToken(RequiredToken)) {
|
|
|
|
|
//argument required
|
|
|
|
|
argument = m_currentArg;
|
|
|
|
|
}
|
|
|
|
|
if (m_foundAppOptions)
|
|
|
|
|
m_foundAppOptions->insert(option, argument);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-02 12:33:51 +01:00
|
|
|
bool OptionsParser::checkForProfilingOption()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentArg != QLatin1String(PROFILE_OPTION))
|
|
|
|
|
return false;
|
|
|
|
|
m_pmPrivate->initProfiling();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool OptionsParser::checkForPluginOption()
|
|
|
|
|
{
|
|
|
|
|
bool requiresParameter;
|
|
|
|
|
PluginSpec *spec = m_pmPrivate->pluginForOption(m_currentArg, &requiresParameter);
|
|
|
|
|
if (!spec)
|
|
|
|
|
return false;
|
|
|
|
|
spec->addArgument(m_currentArg);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (requiresParameter && nextToken(RequiredToken))
|
2008-12-02 12:01:29 +01:00
|
|
|
spec->addArgument(m_currentArg);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OptionsParser::checkForUnknownOption()
|
|
|
|
|
{
|
|
|
|
|
if (!m_currentArg.startsWith(QLatin1Char('-')))
|
|
|
|
|
return false;
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
|
|
|
|
"Unknown option %1").arg(m_currentArg);
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-16 13:50:24 +02:00
|
|
|
void OptionsParser::forceDisableAllPluginsExceptTestedAndForceEnabled()
|
|
|
|
|
{
|
2018-07-19 23:19:33 +02:00
|
|
|
for (const PluginManagerPrivate::TestSpec &testSpec : qAsConst(m_pmPrivate->testSpecs))
|
2017-08-16 13:50:24 +02:00
|
|
|
testSpec.pluginSpec->d->setForceEnabled(true);
|
2018-07-19 23:19:33 +02:00
|
|
|
for (PluginSpec *spec : qAsConst(m_pmPrivate->pluginSpecs)) {
|
2017-08-23 10:15:20 +02:00
|
|
|
if (!spec->isForceEnabled() && !spec->isRequired())
|
2017-08-16 13:50:24 +02:00
|
|
|
spec->d->setForceDisabled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool OptionsParser::nextToken(OptionsParser::TokenType type)
|
|
|
|
|
{
|
|
|
|
|
if (m_it == m_end) {
|
|
|
|
|
if (type == OptionsParser::RequiredToken) {
|
|
|
|
|
m_hasError = true;
|
|
|
|
|
if (m_errorString)
|
|
|
|
|
*m_errorString = QCoreApplication::translate("PluginManager",
|
|
|
|
|
"The option %1 requires an argument.").arg(m_currentArg);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
m_currentArg = *m_it;
|
|
|
|
|
++m_it;
|
|
|
|
|
return true;
|
|
|
|
|
}
|