diff --git a/src/plugins/conan/CMakeLists.txt b/src/plugins/conan/CMakeLists.txt index c9ad746a84d..80da66de4d2 100644 --- a/src/plugins/conan/CMakeLists.txt +++ b/src/plugins/conan/CMakeLists.txt @@ -3,7 +3,7 @@ add_qtc_plugin(Conan SOURCES conanconstants.h conaninstallstep.cpp conaninstallstep.h - conanplugin.cpp conanplugin.h + conanplugin.cpp conansettings.cpp conansettings.h conantr.h ) diff --git a/src/plugins/conan/conan.qbs b/src/plugins/conan/conan.qbs index 486df35f49f..b5beeb7d359 100644 --- a/src/plugins/conan/conan.qbs +++ b/src/plugins/conan/conan.qbs @@ -13,7 +13,6 @@ QtcPlugin { "conanconstants.h", "conaninstallstep.h", "conaninstallstep.cpp", - "conanplugin.h", "conanplugin.cpp", "conansettings.h", "conansettings.cpp", diff --git a/src/plugins/conan/conaninstallstep.cpp b/src/plugins/conan/conaninstallstep.cpp index c1957cc976a..fbc5999192d 100644 --- a/src/plugins/conan/conaninstallstep.cpp +++ b/src/plugins/conan/conaninstallstep.cpp @@ -4,7 +4,6 @@ #include "conaninstallstep.h" #include "conanconstants.h" -#include "conanplugin.h" #include "conansettings.h" #include "conantr.h" @@ -19,12 +18,40 @@ #include #include #include +#include using namespace ProjectExplorer; using namespace Utils; namespace Conan::Internal { +static FilePath conanFilePath(Project *project, const FilePath &defaultFilePath = {}) +{ + const FilePath projectDirectory = project->projectDirectory(); + // conanfile.py takes precedence over conanfile.txt when "conan install dir" is invoked + const FilePath conanPy = projectDirectory / "conanfile.py"; + if (conanPy.exists()) + return conanPy; + const FilePath conanTxt = projectDirectory / "conanfile.txt"; + if (conanTxt.exists()) + return conanTxt; + return defaultFilePath; +} + +static void connectTarget(Project *project, Target *target) +{ + if (!conanFilePath(project).isEmpty()) { + const QList buildConfigurations = target->buildConfigurations(); + for (BuildConfiguration *buildConfiguration : buildConfigurations) + buildConfiguration->buildSteps()->insertStep(0, Constants::INSTALL_STEP); + } + QObject::connect(target, &Target::addedBuildConfiguration, + target, [project] (BuildConfiguration *buildConfiguration) { + if (!conanFilePath(project).isEmpty()) + buildConfiguration->buildSteps()->insertStep(0, Constants::INSTALL_STEP); + }); +} + // ConanInstallStep class ConanInstallStep final : public AbstractProcessStep @@ -45,7 +72,7 @@ ConanInstallStep::ConanInstallStep(BuildStepList *bsl, Id id) auto conanFile = addAspect(); conanFile->setSettingsKey("ConanPackageManager.InstallStep.ConanFile"); - conanFile->setFilePath(ConanPlugin::conanFilePath(project(), + conanFile->setFilePath(conanFilePath(project(), project()->projectDirectory() / "conanfile.txt")); conanFile->setLabelText(Tr::tr("Conan file:")); conanFile->setToolTip(Tr::tr("Enter location of conanfile.txt or conanfile.py.")); @@ -68,7 +95,7 @@ ConanInstallStep::ConanInstallStep(BuildStepList *bsl, Id id) const QString buildType = bt == BuildConfiguration::Release ? QString("Release") : QString("Debug"); - CommandLine cmd(ConanPlugin::conanSettings()->conanFilePath()); + CommandLine cmd(settings().conanFilePath()); cmd.addArgs({"install", "-s", "build_type=" + buildType}); if (buildMissing->value()) cmd.addArg("--build=missing"); @@ -85,6 +112,12 @@ ConanInstallStep::ConanInstallStep(BuildStepList *bsl, Id id) setupProcessParameters(¶m); return param.summary(displayName()); }); + + connect(ProjectManager::instance(), &ProjectManager::projectAdded, this, [this](Project * project) { + connect(project, &Project::addedTarget, project, [project] (Target *target) { + connectTarget(project, target); + }); + }); } bool ConanInstallStep::init() diff --git a/src/plugins/conan/conanplugin.cpp b/src/plugins/conan/conanplugin.cpp index 3844b2983bd..13655b93b63 100644 --- a/src/plugins/conan/conanplugin.cpp +++ b/src/plugins/conan/conanplugin.cpp @@ -1,86 +1,26 @@ // Copyright (C) 2018 Jochen Seemann // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include "conanplugin.h" - -#include "conanconstants.h" #include "conaninstallstep.h" #include "conansettings.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace Core; -using namespace ProjectExplorer; -using namespace Utils; +#include namespace Conan::Internal { -class ConanPluginPrivate +class ConanPlugin final : public ExtensionSystem::IPlugin { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Conan.json") + public: - ConanInstallStepFactory installStepFactory; + ConanPlugin() + { + addManaged(); + addManaged(); + } }; -ConanPlugin::~ConanPlugin() -{ - delete d; -} - -void ConanPlugin::initialize() -{ - d = new ConanPluginPrivate; - conanSettings()->readSettings(ICore::settings()); - - connect(ProjectManager::instance(), &ProjectManager::projectAdded, - this, &ConanPlugin::projectAdded); -} - -static void connectTarget(Project *project, Target *target) -{ - if (!ConanPlugin::conanFilePath(project).isEmpty()) { - const QList buildConfigurations = target->buildConfigurations(); - for (BuildConfiguration *buildConfiguration : buildConfigurations) - buildConfiguration->buildSteps()->insertStep(0, Constants::INSTALL_STEP); - } - QObject::connect(target, &Target::addedBuildConfiguration, - target, [project] (BuildConfiguration *buildConfiguration) { - if (!ConanPlugin::conanFilePath(project).isEmpty()) - buildConfiguration->buildSteps()->insertStep(0, Constants::INSTALL_STEP); - }); -} - -void ConanPlugin::projectAdded(Project *project) -{ - connect(project, &Project::addedTarget, project, [project] (Target *target) { - connectTarget(project, target); - }); -} - -ConanSettings *ConanPlugin::conanSettings() -{ - static ConanSettings theSettings; - return &theSettings; -} - -FilePath ConanPlugin::conanFilePath(Project *project, const FilePath &defaultFilePath) -{ - const FilePath projectDirectory = project->projectDirectory(); - // conanfile.py takes precedence over conanfile.txt when "conan install dir" is invoked - const FilePath conanPy = projectDirectory / "conanfile.py"; - if (conanPy.exists()) - return conanPy; - const FilePath conanTxt = projectDirectory / "conanfile.txt"; - if (conanTxt.exists()) - return conanTxt; - return defaultFilePath; -} - } // Conan::Internal + +#include "conanplugin.moc" diff --git a/src/plugins/conan/conanplugin.h b/src/plugins/conan/conanplugin.h deleted file mode 100644 index 59fbe976d2e..00000000000 --- a/src/plugins/conan/conanplugin.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2018 Jochen Seemann -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include -#include - -namespace ProjectExplorer { class Project; } - -namespace Conan::Internal { - -class ConanSettings; - -class ConanPlugin final : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Conan.json") - -public: - static ConanSettings *conanSettings(); - static Utils::FilePath conanFilePath(ProjectExplorer::Project *project, - const Utils::FilePath &defaultFilePath = {}); - -private: - ~ConanPlugin() final; - void projectAdded(ProjectExplorer::Project *project); - - void initialize() final; - - class ConanPluginPrivate *d = nullptr; -}; - -} // Conan::Internal diff --git a/src/plugins/conan/conansettings.cpp b/src/plugins/conan/conansettings.cpp index 83e8f38d533..4aca2ddffbe 100644 --- a/src/plugins/conan/conansettings.cpp +++ b/src/plugins/conan/conansettings.cpp @@ -3,14 +3,22 @@ #include "conansettings.h" +#include + #include using namespace Utils; namespace Conan::Internal { +static ConanSettings *theSettings; + +ConanSettings &settings() { return *theSettings; } + ConanSettings::ConanSettings() { + theSettings = this; + setSettingsGroup("ConanSettings"); setAutoApply(false); @@ -18,6 +26,8 @@ ConanSettings::ConanSettings() conanFilePath.setSettingsKey("ConanFilePath"); conanFilePath.setExpectedKind(PathChooser::ExistingCommand); conanFilePath.setDefaultValue(HostOsInfo::withExecutableSuffix("conan")); + + readSettings(Core::ICore::settings()); } } // Conan::Internal diff --git a/src/plugins/conan/conansettings.h b/src/plugins/conan/conansettings.h index 69a836dcfe1..41b7a133188 100644 --- a/src/plugins/conan/conansettings.h +++ b/src/plugins/conan/conansettings.h @@ -15,4 +15,6 @@ public: Utils::FilePathAspect conanFilePath; }; +ConanSettings &settings(); + } // Conan::Internal