Add support for Conan package manager

Task-number: QTCREATORBUG-21785
Change-Id: I4b2dbcc16a2504efe9fdc9e31fa2ef14bba7c33c
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jochen Seemann
2018-12-30 20:42:22 +01:00
committed by hjk
parent b97b7dc6f2
commit 3a4ede2e1b
12 changed files with 521 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ add_subdirectory(resourceeditor)
add_subdirectory(tasklist)
add_subdirectory(nim)
add_subdirectory(incredibuild)
add_subdirectory(conan)
# Level 4: (only depends on Level 3 and below)
add_subdirectory(clangpchmanager)

View File

@@ -0,0 +1,6 @@
add_qtc_plugin(Conan
PLUGIN_DEPENDS Core ProjectExplorer
SOURCES
conaninstallstep.cpp conaninstallstep.h
conanplugin.cpp conanplugin.h
)

View File

@@ -0,0 +1,20 @@
{
\"Name\" : \"Conan\",
\"Version\" : \"$$QTCREATOR_VERSION\",
\"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\",
\"Vendor\" : \"Jochen Seemann\",
\"Copyright\" : \"(C) 2018 Jochen Seemann, (C) $$QTCREATOR_COPYRIGHT_YEAR The Qt Company Ltd\",
\"License\" : [ \"Commercial Usage\",
\"\",
\"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and The Qt Company.\",
\"\",
\"GNU General Public License Usage\",
\"\",
\"Alternatively, this plugin 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 plugin. 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.\"
],
\"Category\" : \"Utilities\",
\"Experimental\" : true,
\"Description\" : \"Conan integration.\",
\"Url\" : \"http://www.qt.io\",
$$dependencyList
}

View File

@@ -0,0 +1,8 @@
include(../../qtcreatorplugin.pri)
SOURCES += \
conaninstallstep.cpp \
conanplugin.cpp
HEADERS += \
conaninstallstep.h \
conanplugin.h

View File

@@ -0,0 +1,19 @@
import qbs 1.0
QtcPlugin {
name: "Conan"
Depends { name: "Qt.widgets" }
Depends { name: "Utils" }
Depends { name: "Core" }
Depends { name: "ProjectExplorer" }
files: [
"conanplugin.h",
"conanplugin.cpp",
"conaninstallstep.h",
"conaninstallstep.cpp"
]
}

View File

@@ -0,0 +1,6 @@
QTC_PLUGIN_NAME = Conan
QTC_LIB_DEPENDS += \
utils
QTC_PLUGIN_DEPENDS += \
coreplugin \
projectexplorer

View File

@@ -0,0 +1,252 @@
/****************************************************************************
**
** Copyright (C) 2018 Jochen Seemann
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "conaninstallstep.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtparser.h>
#include <utils/qtcprocess.h>
#include <QVariantMap>
#include <QLineEdit>
#include <QFormLayout>
using namespace ProjectExplorer;
using namespace ProjectExplorer::Constants;
using namespace Utils;
namespace ConanPackageManager {
namespace Internal {
const char INSTALL_STEP_ID[] = "ConanPackageManager.InstallStep";
const char INSTALL_STEP_CONANFILE_SUBDIR_KEY[] = "ConanPackageManager.InstallStep.ConanfileSubdir";
const char INSTALL_STEP_ADDITIONAL_ARGUMENTS_KEY[] = "ConanPackageManager.InstallStep.AdditionalArguments";
ConanInstallStepFactory::ConanInstallStepFactory()
{
registerStep<ConanInstallStep>(INSTALL_STEP_ID);
setDisplayName(ConanInstallStep::tr("conan install", "Install packages specified in Conanfile.txt"));
}
ConanInstallStep::ConanInstallStep(BuildStepList *bsl, Utils::Id id) : AbstractProcessStep(bsl, id)
{
setDefaultDisplayName(tr("conan install"));
}
bool ConanInstallStep::init()
{
BuildConfiguration *bc = buildConfiguration();
QTC_ASSERT(bc, return false);
QList<ToolChain *> tcList = ToolChainKitAspect::toolChains(target()->kit());
if (tcList.isEmpty())
emit addTask(Task::compilerMissingTask());
if (tcList.isEmpty() || !bc) {
emitFaultyConfigurationMessage();
return false;
}
ProcessParameters *pp = processParameters();
Utils::Environment env = bc->environment();
Utils::Environment::setupEnglishOutput(&env);
pp->setEnvironment(env);
pp->setWorkingDirectory(bc->buildDirectory());
pp->setCommandLine(Utils::CommandLine("conan", arguments()));
return AbstractProcessStep::init();
}
void ConanInstallStep::setupOutputFormatter(OutputFormatter *formatter)
{
formatter->addLineParser(new GnuMakeParser());
formatter->addLineParsers(kit()->createOutputParsers());
formatter->addSearchDir(processParameters()->effectiveWorkingDirectory());
AbstractProcessStep::setupOutputFormatter(formatter);
}
BuildStepConfigWidget *ConanInstallStep::createConfigWidget()
{
return new ConanInstallStepConfigWidget(this);
}
bool ConanInstallStep::immutable() const
{
return false;
}
QStringList ConanInstallStep::arguments() const
{
BuildConfiguration *bc = buildConfiguration();
if (!bc)
bc = target()->activeBuildConfiguration();
if (!bc)
return {};
const Utils::FilePath conanFileDir = relativeSubdir().isEmpty()
? bc->buildDirectory()
: bc->buildDirectory().pathAppended(relativeSubdir());
const QString buildType = bc->buildType() == BuildConfiguration::Release ? QString("Release")
: QString("Debug");
const QString relativePath
= bc->project()->projectDirectory().relativeChildPath(conanFileDir).toString();
QStringList installArguments;
installArguments << "install";
if (!relativePath.isEmpty())
installArguments << relativePath;
installArguments << "-s";
installArguments << "build_type=" + buildType;
installArguments << conanFileDir.toString();
installArguments << additionalArguments();
return installArguments;
}
QString ConanInstallStep::relativeSubdir() const
{
return m_relativeSubdir;
}
QStringList ConanInstallStep::additionalArguments() const
{
return Utils::QtcProcess::splitArgs(m_additionalArguments);
}
void ConanInstallStep::setRelativeSubdir(const QString &subdir)
{
if (subdir == m_relativeSubdir)
return;
m_relativeSubdir = subdir;
emit relativeSubdirChanged(subdir);
}
void ConanInstallStep::setAdditionalArguments(const QString &list)
{
if (list == m_additionalArguments)
return;
m_additionalArguments = list;
emit additionalArgumentsChanged(list);
}
QVariantMap ConanInstallStep::toMap() const
{
QVariantMap map = AbstractProcessStep::toMap();
map.insert(INSTALL_STEP_CONANFILE_SUBDIR_KEY, m_relativeSubdir);
map.insert(INSTALL_STEP_ADDITIONAL_ARGUMENTS_KEY, m_additionalArguments);
return map;
}
bool ConanInstallStep::fromMap(const QVariantMap &map)
{
m_relativeSubdir = map.value(INSTALL_STEP_CONANFILE_SUBDIR_KEY).toString();
m_additionalArguments = map.value(INSTALL_STEP_ADDITIONAL_ARGUMENTS_KEY).toString();
return BuildStep::fromMap(map);
}
///////////////////////////////
// ConanInstallStepConfigWidget class
///////////////////////////////
ConanInstallStepConfigWidget::ConanInstallStepConfigWidget(ConanInstallStep *installStep)
: ProjectExplorer::BuildStepConfigWidget(installStep)
, m_installStep(installStep)
, m_summaryText()
, m_relativeSubdir(nullptr)
, m_additionalArguments(nullptr)
{
QFormLayout *fl = new QFormLayout(this);
fl->setMargin(0);
fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
setLayout(fl);
m_relativeSubdir = new QLineEdit(this);
fl->addRow(tr("conanfile.txt subdirectory:"), m_relativeSubdir);
m_relativeSubdir->setText(m_installStep->relativeSubdir());
m_additionalArguments = new QLineEdit(this);
fl->addRow(tr("Additional arguments:"), m_additionalArguments);
m_additionalArguments->setText(Utils::QtcProcess::joinArgs(m_installStep->additionalArguments()));
updateDetails();
connect(m_relativeSubdir, &QLineEdit::textChanged,
m_installStep, &ConanInstallStep::setRelativeSubdir);
connect(m_additionalArguments, &QLineEdit::textChanged,
m_installStep, &ConanInstallStep::setAdditionalArguments);
connect(m_installStep, &ConanInstallStep::relativeSubdirChanged,
this, &ConanInstallStepConfigWidget::updateDetails);
connect(m_installStep, &ConanInstallStep::additionalArgumentsChanged,
this, &ConanInstallStepConfigWidget::updateDetails);
connect(installStep->buildConfiguration(), &BuildConfiguration::environmentChanged,
this, &ConanInstallStepConfigWidget::updateDetails);
}
QString ConanInstallStepConfigWidget::displayName() const
{
return tr("conan install", "ConanInstallStep::ConanInstallStepConfigWidget display name.");
}
QString ConanInstallStepConfigWidget::summaryText() const
{
return m_summaryText;
}
void ConanInstallStepConfigWidget::updateDetails()
{
BuildConfiguration *bc = m_installStep->buildConfiguration();
if (!bc)
bc = m_installStep->target()->activeBuildConfiguration();
QList<ToolChain *> tcList = ToolChainKitAspect::toolChains(m_installStep->target()->kit());
if (!tcList.isEmpty()) {
QString arguments = Utils::QtcProcess::joinArgs(m_installStep->arguments()
+ m_installStep->additionalArguments());
m_summaryText = "<b>conan install</b>: conan " + arguments;
setSummaryText(m_summaryText);
} else {
m_summaryText = "<b>" + ToolChainKitAspect::msgNoToolChainInTarget() + "</b>";
}
emit updateSummary();
}
} // namespace Internal
} // namespace ConanPackageManager

View File

@@ -0,0 +1,97 @@
/****************************************************************************
**
** Copyright (C) 2018 Jochen Seemann
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <projectexplorer/abstractprocessstep.h>
#include <projectexplorer/task.h>
QT_FORWARD_DECLARE_CLASS(QLineEdit)
namespace ConanPackageManager {
namespace Internal {
class AutotoolsProject;
class ConanInstallStep;
class ConanInstallStepFactory : public ProjectExplorer::BuildStepFactory
{
public:
ConanInstallStepFactory();
};
class ConanInstallStep : public ProjectExplorer::AbstractProcessStep
{
Q_OBJECT
friend class ConanInstallStepFactory;
public:
ConanInstallStep(ProjectExplorer::BuildStepList *bsl, Utils::Id id);
bool init() override;
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
bool immutable() const;
QStringList arguments() const;
QString relativeSubdir() const;
QStringList additionalArguments() const;
QVariantMap toMap() const override;
void setRelativeSubdir(const QString &subdir);
void setAdditionalArguments(const QString &list);
void setupOutputFormatter(Utils::OutputFormatter *formatter) final;
signals:
void relativeSubdirChanged(const QString &);
void additionalArgumentsChanged(const QString &);
private:
bool fromMap(const QVariantMap &map) override;
QString m_arguments;
QString m_relativeSubdir;
QString m_additionalArguments;
};
class ConanInstallStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
ConanInstallStepConfigWidget(ConanInstallStep *installStep);
QString displayName() const;
QString summaryText() const;
private:
void updateDetails();
ConanInstallStep *m_installStep;
QString m_summaryText;
QLineEdit *m_relativeSubdir;
QLineEdit *m_additionalArguments;
};
} // namespace Internal
} // namespace ConanPackageManager

View File

@@ -0,0 +1,60 @@
/****************************************************************************
**
** Copyright (C) 2018 Jochen Seemann
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "conanplugin.h"
#include "conaninstallstep.h"
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/buildmanager.h>
namespace ConanPackageManager {
namespace Internal {
class ConanPluginRunData
{
public:
ConanInstallStepFactory installStepFactory;
};
ConanPlugin::~ConanPlugin()
{
delete m_runData;
}
void ConanPlugin::extensionsInitialized()
{ }
bool ConanPlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
m_runData = new ConanPluginRunData;
return true;
}
} // namespace Internal
} // namespace ConanPackageManager

View File

@@ -0,0 +1,49 @@
/****************************************************************************
**
** Copyright (C) 2018 Jochen Seemann
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <extensionsystem/iplugin.h>
namespace ConanPackageManager {
namespace Internal {
class ConanPluginRunData;
class ConanPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Conan.json")
~ConanPlugin() final;
void extensionsInitialized() final;
bool initialize(const QStringList &arguments, QString *errorString) final;
ConanPluginRunData *m_runData = nullptr;
};
} // namespace Internal
} // namespace ConanPackageManager

View File

@@ -66,7 +66,8 @@ SUBDIRS = \
webassembly \
mcusupport \
marketplace \
incredibuild
incredibuild \
conan
qtHaveModule(serialport) {
SUBDIRS += serialterminal

View File

@@ -23,6 +23,7 @@ Project {
"cmakeprojectmanager/cmakeprojectmanager.qbs",
"mesonprojectmanager/mesonprojectmanager.qbs",
"compilationdatabaseprojectmanager/compilationdatabaseprojectmanager.qbs",
"conan/conan.qbs",
"coreplugin/coreplugin.qbs",
"coreplugin/images/logo/logo.qbs",
"cpaster/cpaster.qbs",