Changeset View
Changeset View
Standalone View
Standalone View
plugins/meson/settings/mesonconfigpage.cpp
Show All 13 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "mesonconfigpage.h" | 20 | #include "mesonconfigpage.h" | ||
21 | #include "mesonbuilder.h" | 21 | #include "mesonbuilder.h" | ||
22 | #include "mesonintrospectjob.h" | ||||
22 | #include "mesonjob.h" | 23 | #include "mesonjob.h" | ||
23 | #include "mesonmanager.h" | 24 | #include "mesonmanager.h" | ||
24 | #include "mesonnewbuilddir.h" | 25 | #include "mesonnewbuilddir.h" | ||
25 | #include "ui_mesonconfigpage.h" | 26 | #include "ui_mesonconfigpage.h" | ||
26 | #include <QIcon> | 27 | #include <QIcon> | ||
27 | #include <debug.h> | 28 | #include <debug.h> | ||
28 | #include <executecompositejob.h> | 29 | #include <executecompositejob.h> | ||
29 | #include <interfaces/iplugin.h> | 30 | #include <interfaces/iplugin.h> | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
86 | { | 87 | { | ||
87 | qCDebug(KDEV_Meson) << "Applying meson config for build dir " << m_current.buildDir; | 88 | qCDebug(KDEV_Meson) << "Applying meson config for build dir " << m_current.buildDir; | ||
88 | readUI(); | 89 | readUI(); | ||
89 | writeConfig(); | 90 | writeConfig(); | ||
90 | 91 | | |||
91 | if (m_config.currentIndex >= 0 && m_configChanged) { | 92 | if (m_config.currentIndex >= 0 && m_configChanged) { | ||
92 | QList<KJob*> joblist; | 93 | QList<KJob*> joblist; | ||
93 | 94 | | |||
95 | auto options = m_ui->options->options(); | ||||
96 | if (!options) { | ||||
97 | qCWarning(KDEV_Meson) << "Options is nullptr. Can not update meson config"; | ||||
98 | return; | ||||
99 | } | ||||
100 | | ||||
101 | QStringList mesonArgs = options->getMesonArgs(); | ||||
102 | if (mesonArgs.empty()) { | ||||
103 | qCDebug(KDEV_Meson) << "Config has not changed --> nothing has to be updated"; | ||||
104 | return; | ||||
105 | } | ||||
106 | | ||||
94 | // Check if a configuration is required | 107 | // Check if a configuration is required | ||
95 | auto status = MesonBuilder::evaluateBuildDirectory(m_current.buildDir, m_current.mesonBackend); | 108 | auto status = MesonBuilder::evaluateBuildDirectory(m_current.buildDir, m_current.mesonBackend); | ||
96 | if (status != MesonBuilder::MESON_CONFIGURED) { | 109 | if (status != MesonBuilder::MESON_CONFIGURED) { | ||
97 | joblist << new MesonJob(m_current, m_project, MesonJob::CONFIGURE, {}, nullptr); | 110 | joblist << new MesonJob(m_current, m_project, MesonJob::CONFIGURE, mesonArgs, nullptr); | ||
98 | } | 111 | } | ||
99 | 112 | | |||
100 | joblist << new MesonJob(m_current, m_project, MesonJob::SET_CONFIG, {}, nullptr); | 113 | joblist << new MesonJob(m_current, m_project, MesonJob::SET_CONFIG, mesonArgs, nullptr); | ||
101 | joblist << new MesonJob(m_current, m_project, MesonJob::RE_CONFIGURE, {}, nullptr); | 114 | joblist << m_ui->options->repopulateFromBuildDir(m_project->path(), m_current); | ||
102 | KJob* job = new ExecuteCompositeJob(nullptr, joblist); | 115 | KJob* job = new ExecuteCompositeJob(nullptr, joblist); | ||
103 | connect(job, &KJob::result, this, [this]() { | 116 | connect(job, &KJob::result, this, [this]() { | ||
104 | setDisabled(false); | 117 | setDisabled(false); | ||
105 | updateUI(); | 118 | updateUI(); | ||
106 | }); | 119 | }); | ||
107 | setDisabled(true); | 120 | setDisabled(true); | ||
108 | m_configChanged = false; | 121 | m_configChanged = false; | ||
109 | job->start(); | 122 | job->start(); | ||
110 | } | 123 | } | ||
111 | } | 124 | } | ||
112 | 125 | | |||
113 | void MesonConfigPage::defaults() | 126 | void MesonConfigPage::defaults() | ||
114 | { | 127 | { | ||
115 | qCDebug(KDEV_Meson) << "Restoring build dir " << m_current.buildDir << " to it's default values"; | 128 | qCDebug(KDEV_Meson) << "Restoring build dir " << m_current.buildDir << " to it's default values"; | ||
116 | MesonManager* mgr = dynamic_cast<MesonManager*>(m_project->buildSystemManager()); | 129 | MesonManager* mgr = dynamic_cast<MesonManager*>(m_project->buildSystemManager()); | ||
117 | Q_ASSERT(mgr); | 130 | Q_ASSERT(mgr); | ||
118 | 131 | | |||
119 | m_current.mesonArgs.clear(); | 132 | m_current.mesonArgs.clear(); | ||
120 | m_current.mesonBackend = mgr->defaultMesonBackend(); | 133 | m_current.mesonBackend = mgr->defaultMesonBackend(); | ||
121 | m_current.mesonExecutable = mgr->findMeson(); | 134 | m_current.mesonExecutable = mgr->findMeson(); | ||
135 | m_ui->options->resetAll(); | ||||
122 | 136 | | |||
123 | updateUI(); | 137 | updateUI(); | ||
124 | } | 138 | } | ||
125 | 139 | | |||
126 | void MesonConfigPage::reset() | 140 | void MesonConfigPage::reset() | ||
127 | { | 141 | { | ||
128 | if (m_config.buildDirs.isEmpty()) { | 142 | if (m_config.buildDirs.isEmpty()) { | ||
129 | m_config.currentIndex = -1; | 143 | m_config.currentIndex = -1; | ||
130 | m_ui->i_buildDirs->clear(); | 144 | m_ui->i_buildDirs->clear(); | ||
131 | setWidgetsDisabled(true); | 145 | setWidgetsDisabled(true); | ||
132 | return; | 146 | return; | ||
133 | } else if (m_config.currentIndex < 0 || m_config.currentIndex >= m_config.buildDirs.size()) { | 147 | } else if (m_config.currentIndex < 0 || m_config.currentIndex >= m_config.buildDirs.size()) { | ||
134 | m_config.currentIndex = 0; | 148 | m_config.currentIndex = 0; | ||
135 | m_ui->i_buildDirs->blockSignals(true); | 149 | m_ui->i_buildDirs->blockSignals(true); | ||
136 | m_ui->i_buildDirs->setCurrentIndex(m_config.currentIndex); | 150 | m_ui->i_buildDirs->setCurrentIndex(m_config.currentIndex); | ||
137 | m_ui->i_buildDirs->blockSignals(false); | 151 | m_ui->i_buildDirs->blockSignals(false); | ||
138 | } | 152 | } | ||
139 | 153 | | |||
140 | setWidgetsDisabled(false); | 154 | setWidgetsDisabled(false); | ||
141 | qCDebug(KDEV_Meson) << "Resetting changes for build dir " << m_current.buildDir; | 155 | qCDebug(KDEV_Meson) << "Resetting changes for build dir " << m_current.buildDir; | ||
142 | 156 | | |||
143 | m_current = m_config.buildDirs[m_config.currentIndex]; | 157 | m_current = m_config.buildDirs[m_config.currentIndex]; | ||
158 | m_ui->options->repopulateFromBuildDir(m_project->path(), m_current)->start(); | ||||
144 | updateUI(); | 159 | updateUI(); | ||
145 | } | 160 | } | ||
146 | 161 | | |||
147 | void MesonConfigPage::updateUI() | 162 | void MesonConfigPage::checkStatus() | ||
148 | { | 163 | { | ||
149 | m_ui->i_buildType->setCurrentIndex(1); | | |||
150 | | ||||
151 | QStringList buildTypes = { QStringLiteral("plain"), QStringLiteral("debug"), QStringLiteral("debugoptimized"), | | |||
152 | QStringLiteral("release"), QStringLiteral("minsize"), QStringLiteral("custom") }; | | |||
153 | | ||||
154 | m_ui->i_buildType->clear(); | | |||
155 | m_ui->i_buildType->addItems(buildTypes); | | |||
156 | m_ui->i_buildType->setCurrentIndex(std::max(0, buildTypes.indexOf(m_current.buildType))); | | |||
157 | | ||||
158 | m_ui->i_installPrefix->setUrl(m_current.installPrefix.toUrl()); | | |||
159 | | ||||
160 | auto aConf = m_ui->advanced->getConfig(); | | |||
161 | aConf.args = m_current.mesonArgs; | | |||
162 | aConf.backend = m_current.mesonBackend; | | |||
163 | aConf.meson = m_current.mesonExecutable; | | |||
164 | m_ui->advanced->setConfig(aConf); | | |||
165 | | ||||
166 | // Get the config build dir status | 164 | // Get the config build dir status | ||
167 | auto status = MesonBuilder::evaluateBuildDirectory(m_current.buildDir, m_current.mesonBackend); | 165 | auto status = MesonBuilder::evaluateBuildDirectory(m_current.buildDir, m_current.mesonBackend); | ||
168 | auto setStatus = [this](QString const& msg, int color) -> void { | 166 | auto setStatus = [this](QString const& msg, int color) -> void { | ||
169 | KColorScheme scheme(QPalette::Normal); | 167 | KColorScheme scheme(QPalette::Normal); | ||
170 | KColorScheme::ForegroundRole role; | 168 | KColorScheme::ForegroundRole role; | ||
171 | switch (color) { | 169 | switch (color) { | ||
172 | case 0: | 170 | case 0: | ||
173 | role = KColorScheme::PositiveText; | 171 | role = KColorScheme::PositiveText; | ||
Show All 34 Lines | 204 | case MesonBuilder::DIR_NOT_EMPTY: | |||
208 | break; | 206 | break; | ||
209 | case MesonBuilder::EMPTY_STRING: | 207 | case MesonBuilder::EMPTY_STRING: | ||
210 | setStatus(i18n("Invalid build directory configuration (empty build direcory string)"), 2); | 208 | setStatus(i18n("Invalid build directory configuration (empty build direcory string)"), 2); | ||
211 | break; | 209 | break; | ||
212 | case MesonBuilder::___UNDEFINED___: | 210 | case MesonBuilder::___UNDEFINED___: | ||
213 | setStatus(i18n("Something went verry wrong. This is a bug"), 2); | 211 | setStatus(i18n("Something went verry wrong. This is a bug"), 2); | ||
214 | break; | 212 | break; | ||
215 | } | 213 | } | ||
214 | | ||||
215 | KColorScheme scheme(QPalette::Normal); | ||||
216 | KColorScheme::ForegroundRole role; | ||||
217 | int numChanged = 0; | ||||
218 | auto options = m_ui->options->options(); | ||||
219 | | ||||
220 | if (options) { | ||||
221 | numChanged = options->numChanged(); | ||||
222 | } | ||||
223 | | ||||
224 | if (numChanged == 0) { | ||||
225 | role = KColorScheme::NormalText; | ||||
226 | m_ui->l_changed->setText(i18n("No changes")); | ||||
227 | } else { | ||||
228 | role = KColorScheme::NeutralText; | ||||
229 | m_ui->l_changed->setText(i18n("%1 options changed", numChanged)); | ||||
230 | } | ||||
231 | | ||||
232 | QPalette pal = m_ui->l_changed->palette(); | ||||
233 | pal.setColor(QPalette::Foreground, scheme.foreground(role).color()); | ||||
234 | m_ui->l_changed->setPalette(pal); | ||||
235 | } | ||||
236 | | ||||
237 | void MesonConfigPage::updateUI() | ||||
238 | { | ||||
239 | auto aConf = m_ui->advanced->getConfig(); | ||||
240 | aConf.args = m_current.mesonArgs; | ||||
241 | aConf.backend = m_current.mesonBackend; | ||||
242 | aConf.meson = m_current.mesonExecutable; | ||||
243 | m_ui->advanced->setConfig(aConf); | ||||
244 | | ||||
245 | checkStatus(); | ||||
216 | } | 246 | } | ||
217 | 247 | | |||
218 | void MesonConfigPage::readUI() | 248 | void MesonConfigPage::readUI() | ||
219 | { | 249 | { | ||
220 | qCDebug(KDEV_Meson) << "Reading current build configuration from the UI " << m_current.buildDir.toLocalFile(); | 250 | qCDebug(KDEV_Meson) << "Reading current build configuration from the UI " << m_current.buildDir.toLocalFile(); | ||
221 | m_current.installPrefix = Path(m_ui->i_installPrefix->url()); | | |||
222 | m_current.buildType = m_ui->i_buildType->currentText(); | | |||
223 | 251 | | |||
224 | auto aConf = m_ui->advanced->getConfig(); | 252 | auto aConf = m_ui->advanced->getConfig(); | ||
225 | m_current.mesonArgs = aConf.args; | 253 | m_current.mesonArgs = aConf.args; | ||
226 | m_current.mesonBackend = aConf.backend; | 254 | m_current.mesonBackend = aConf.backend; | ||
227 | m_current.mesonExecutable = aConf.meson; | 255 | m_current.mesonExecutable = aConf.meson; | ||
228 | } | 256 | } | ||
229 | 257 | | |||
230 | void MesonConfigPage::setWidgetsDisabled(bool disabled) | 258 | void MesonConfigPage::setWidgetsDisabled(bool disabled) | ||
231 | { | 259 | { | ||
232 | m_ui->advanced->setDisabled(disabled); | 260 | m_ui->advanced->setDisabled(disabled); | ||
233 | m_ui->c_01_basic->setDisabled(disabled); | 261 | m_ui->i_buildDirs->setDisabled(disabled); | ||
234 | m_ui->c_02_buildConfig->setDisabled(disabled); | 262 | m_ui->b_addDir->setDisabled(disabled); | ||
235 | m_ui->b_rmDir->setDisabled(disabled); | 263 | m_ui->b_rmDir->setDisabled(disabled); | ||
264 | m_ui->options->setDisabled(disabled); | ||||
236 | } | 265 | } | ||
237 | 266 | | |||
238 | void MesonConfigPage::addBuildDir() | 267 | void MesonConfigPage::addBuildDir() | ||
239 | { | 268 | { | ||
240 | qCDebug(KDEV_Meson) << "Adding build directory"; | 269 | qCDebug(KDEV_Meson) << "Adding build directory"; | ||
241 | MesonManager* mgr = dynamic_cast<MesonManager*>(m_project->buildSystemManager()); | 270 | MesonManager* mgr = dynamic_cast<MesonManager*>(m_project->buildSystemManager()); | ||
242 | MesonBuilder* bld = dynamic_cast<MesonBuilder*>(mgr->builder()); | 271 | MesonBuilder* bld = dynamic_cast<MesonBuilder*>(mgr->builder()); | ||
243 | Q_ASSERT(mgr); | 272 | Q_ASSERT(mgr); | ||
244 | Q_ASSERT(bld); | 273 | Q_ASSERT(bld); | ||
245 | MesonNewBuildDir newBD(m_project); | 274 | MesonNewBuildDir newBD(m_project); | ||
246 | 275 | | |||
247 | if (!newBD.exec() || !newBD.isConfigValid()) { | 276 | if (!newBD.exec() || !newBD.isConfigValid()) { | ||
248 | qCDebug(KDEV_Meson) << "Failed to create a new build directory"; | 277 | qCDebug(KDEV_Meson) << "Failed to create a new build directory"; | ||
249 | return; | 278 | return; | ||
250 | } | 279 | } | ||
251 | 280 | | |||
252 | m_current = newBD.currentConfig(); | 281 | m_current = newBD.currentConfig(); | ||
282 | m_current.canonicalizePaths(); | ||||
253 | m_config.currentIndex = m_config.addBuildDir(m_current); | 283 | m_config.currentIndex = m_config.addBuildDir(m_current); | ||
254 | m_ui->i_buildDirs->blockSignals(true); | 284 | m_ui->i_buildDirs->blockSignals(true); | ||
255 | m_ui->i_buildDirs->addItem(m_current.buildDir.toLocalFile()); | 285 | m_ui->i_buildDirs->addItem(m_current.buildDir.toLocalFile()); | ||
256 | m_ui->i_buildDirs->setCurrentIndex(m_config.currentIndex); | 286 | m_ui->i_buildDirs->setCurrentIndex(m_config.currentIndex); | ||
257 | m_ui->i_buildDirs->blockSignals(false); | 287 | m_ui->i_buildDirs->blockSignals(false); | ||
258 | 288 | | |||
259 | setWidgetsDisabled(true); | 289 | setWidgetsDisabled(true); | ||
260 | writeConfig(); | 290 | writeConfig(); | ||
261 | KJob* job = bld->configure(m_project); | 291 | KJob* job = bld->configure(m_project, m_current, newBD.mesonArgs()); | ||
262 | connect(job, &KJob::result, this, [this]() { reset(); }); | 292 | connect(job, &KJob::result, this, [this]() { reset(); }); | ||
263 | job->start(); | 293 | job->start(); | ||
264 | } | 294 | } | ||
265 | 295 | | |||
266 | void MesonConfigPage::removeBuildDir() | 296 | void MesonConfigPage::removeBuildDir() | ||
267 | { | 297 | { | ||
268 | qCDebug(KDEV_Meson) << "Removing current build directory"; | 298 | qCDebug(KDEV_Meson) << "Removing current build directory"; | ||
269 | m_ui->i_buildDirs->blockSignals(true); | 299 | m_ui->i_buildDirs->blockSignals(true); | ||
Show All 26 Lines | 314 | { | |||
296 | m_config.currentIndex = index; | 326 | m_config.currentIndex = index; | ||
297 | reset(); | 327 | reset(); | ||
298 | writeConfig(); | 328 | writeConfig(); | ||
299 | } | 329 | } | ||
300 | 330 | | |||
301 | void MesonConfigPage::emitChanged() | 331 | void MesonConfigPage::emitChanged() | ||
302 | { | 332 | { | ||
303 | m_configChanged = true; | 333 | m_configChanged = true; | ||
334 | checkStatus(); | ||||
304 | emit changed(); | 335 | emit changed(); | ||
305 | } | 336 | } | ||
306 | 337 | | |||
307 | QString MesonConfigPage::name() const | 338 | QString MesonConfigPage::name() const | ||
308 | { | 339 | { | ||
309 | return i18n("Meson"); | 340 | return i18n("Meson"); | ||
310 | } | 341 | } | ||
311 | 342 | | |||
Show All 9 Lines |