-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.cpp
147 lines (125 loc) · 4.97 KB
/
plugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/** @author Kamil Zaripov
@date 28.10.2018 */
#include "plugin.h"
#include "constants.h"
#include "project/installstep.h"
#include "settings/settingspage.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/deployconfiguration.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/buildstep.h>
#include <projectexplorer/projectnodes.h>
#include <QAction>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>
#include <QListWidget>
#include <QMetaObject>
using namespace Conan;
using namespace Conan::Internal;
namespace Conan {
namespace Internal {
class ConanPluginPrivate {
public:
InstallStepFactory installStepFactory;
SettingsPage settingsPage;
};
}
}
const auto recepieMatcher = [](const ProjectExplorer::Node * node) {
return node->filePath().endsWith("conanfile.py") || node->filePath().endsWith("conanfile.txt");
};
const auto buildStepFinder = [](const ProjectExplorer::BuildStep * build) -> bool {
return build->id() == Constants::C_CONANINSTALLSTEP_ID;
};
ConanPlugin::ConanPlugin() {
}
ConanPlugin::~ConanPlugin() {
delete d;
}
bool ConanPlugin::initialize(const QStringList & arguments, QString * errorString) {
Q_UNUSED(arguments)
Q_UNUSED(errorString)
d = new ConanPluginPrivate;
connect(&(d->settingsPage), &SettingsPage::conanLocationChanged,
this, &ConanPlugin::updateConanLocation);
auto sessionManager = ProjectExplorer::SessionManager::instance();
connect(sessionManager, &ProjectExplorer::SessionManager::projectAdded,
this, &ConanPlugin::addProject);
connect(sessionManager, &ProjectExplorer::SessionManager::projectRemoved,
this, &ConanPlugin::removeProject);
for(auto project : sessionManager->projects()) {
addProject(project);
}
return true;
}
void ConanPlugin::addProject(ProjectExplorer::Project * project) {
connect(project, &ProjectExplorer::Project::fileListChanged,
this, [this, project](){ this->handleProject(project); });
handleProject(project);
}
void ConanPlugin::removeProject(ProjectExplorer::Project * project) {
disconnect(project, nullptr, this, nullptr);
}
void ConanPlugin::handleProject(ProjectExplorer::Project * project) {
const auto & recepies = project->files(recepieMatcher);
const auto recipiesFound = !recepies.isEmpty();
const auto & tragets = project->targets();
for(auto target : tragets) {
auto buildConfigs = target->buildConfigurations();
for(auto buildConfig : buildConfigs) {
auto stepList = buildConfig->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
if(recipiesFound) {
auto steps = stepList->steps(buildStepFinder);
if(steps.empty()) {
auto step = d->installStepFactory.create(stepList, Constants::C_CONANINSTALLSTEP_ID);
auto conanInstallStep = dynamic_cast<InstallStep*>(step);
if(conanInstallStep) {
conanInstallStep->setConanLocation(d->settingsPage.conanLocation());
}
stepList->insertStep(0, step);
} else {
for(auto step : steps) {
auto conanInstallStep = dynamic_cast<InstallStep*>(step);
if(conanInstallStep) {
conanInstallStep->setConanLocation(d->settingsPage.conanLocation());
}
}
}
} else {
for(int i = stepList->count()-1; i>=0; --i) {
if(stepList->at(i)->id() == Constants::C_CONANINSTALLSTEP_ID) {
stepList->removeStep(i);
}
}
}
}
}
}
void ConanPlugin::updateConanLocation() {
auto sessionManager = ProjectExplorer::SessionManager::instance();
for(auto project : sessionManager->projects()) {
for(auto target : project->targets()) {
auto buildConfigs = target->buildConfigurations();
for(auto buildConfig : buildConfigs) {
auto stepList = buildConfig->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
auto steps = stepList->steps(buildStepFinder);
for(auto step : steps) {
auto conanInstallStep = dynamic_cast<InstallStep*>(step);
if(conanInstallStep) {
conanInstallStep->setConanLocation(d->settingsPage.conanLocation());
}
}
}
}
}
}