diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 70f8f42000b..86fd7096f2c 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -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) diff --git a/src/plugins/conan/CMakeLists.txt b/src/plugins/conan/CMakeLists.txt new file mode 100644 index 00000000000..fd19c478755 --- /dev/null +++ b/src/plugins/conan/CMakeLists.txt @@ -0,0 +1,6 @@ +add_qtc_plugin(Conan + PLUGIN_DEPENDS Core ProjectExplorer + SOURCES + conaninstallstep.cpp conaninstallstep.h + conanplugin.cpp conanplugin.h +) diff --git a/src/plugins/conan/Conan.json.in b/src/plugins/conan/Conan.json.in new file mode 100644 index 00000000000..ac2cfcd52ef --- /dev/null +++ b/src/plugins/conan/Conan.json.in @@ -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 +} diff --git a/src/plugins/conan/conan.pro b/src/plugins/conan/conan.pro new file mode 100644 index 00000000000..6fc42a8a62e --- /dev/null +++ b/src/plugins/conan/conan.pro @@ -0,0 +1,8 @@ +include(../../qtcreatorplugin.pri) + +SOURCES += \ + conaninstallstep.cpp \ + conanplugin.cpp +HEADERS += \ + conaninstallstep.h \ + conanplugin.h diff --git a/src/plugins/conan/conan.qbs b/src/plugins/conan/conan.qbs new file mode 100644 index 00000000000..8ed2f131d29 --- /dev/null +++ b/src/plugins/conan/conan.qbs @@ -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" + ] +} + diff --git a/src/plugins/conan/conan_dependencies.pri b/src/plugins/conan/conan_dependencies.pri new file mode 100644 index 00000000000..e9c05fe2e58 --- /dev/null +++ b/src/plugins/conan/conan_dependencies.pri @@ -0,0 +1,6 @@ +QTC_PLUGIN_NAME = Conan +QTC_LIB_DEPENDS += \ + utils +QTC_PLUGIN_DEPENDS += \ + coreplugin \ + projectexplorer diff --git a/src/plugins/conan/conaninstallstep.cpp b/src/plugins/conan/conaninstallstep.cpp new file mode 100644 index 00000000000..53770859e9f --- /dev/null +++ b/src/plugins/conan/conaninstallstep.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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(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 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 tcList = ToolChainKitAspect::toolChains(m_installStep->target()->kit()); + + if (!tcList.isEmpty()) { + QString arguments = Utils::QtcProcess::joinArgs(m_installStep->arguments() + + m_installStep->additionalArguments()); + m_summaryText = "conan install: conan " + arguments; + setSummaryText(m_summaryText); + } else { + m_summaryText = "" + ToolChainKitAspect::msgNoToolChainInTarget() + ""; + } + + emit updateSummary(); +} + +} // namespace Internal +} // namespace ConanPackageManager diff --git a/src/plugins/conan/conaninstallstep.h b/src/plugins/conan/conaninstallstep.h new file mode 100644 index 00000000000..d6dad5201d9 --- /dev/null +++ b/src/plugins/conan/conaninstallstep.h @@ -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 +#include + +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 diff --git a/src/plugins/conan/conanplugin.cpp b/src/plugins/conan/conanplugin.cpp new file mode 100644 index 00000000000..bf88c803fc7 --- /dev/null +++ b/src/plugins/conan/conanplugin.cpp @@ -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 +#include + +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 diff --git a/src/plugins/conan/conanplugin.h b/src/plugins/conan/conanplugin.h new file mode 100644 index 00000000000..d77409ec972 --- /dev/null +++ b/src/plugins/conan/conanplugin.h @@ -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 + +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 diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 12d87206ab3..abf6e510c08 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -66,7 +66,8 @@ SUBDIRS = \ webassembly \ mcusupport \ marketplace \ - incredibuild + incredibuild \ + conan qtHaveModule(serialport) { SUBDIRS += serialterminal diff --git a/src/plugins/plugins.qbs b/src/plugins/plugins.qbs index 5ef58f33ebf..e2310ee1ff5 100644 --- a/src/plugins/plugins.qbs +++ b/src/plugins/plugins.qbs @@ -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",