2016-01-20 12:19:16 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** 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 "builddirmanager.h"
|
2017-03-13 14:22:16 +01:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
#include "cmakebuildconfiguration.h"
|
2017-04-26 15:29:54 +02:00
|
|
|
#include "cmakebuildstep.h"
|
2016-01-20 12:19:16 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2016-10-06 11:31:15 +02:00
|
|
|
#include "cmakeprojectnodes.h"
|
2016-01-20 12:19:16 +01:00
|
|
|
#include "cmaketool.h"
|
|
|
|
|
|
2016-05-13 16:19:31 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/kit.h>
|
2016-10-10 10:22:06 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2016-02-24 18:00:24 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2016-02-24 18:00:24 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2016-10-10 10:22:06 +02:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2016-02-15 15:50:26 +01:00
|
|
|
#include <utils/fileutils.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2017-09-07 14:00:29 +02:00
|
|
|
#include <QDir>
|
2016-05-13 16:19:31 +02:00
|
|
|
#include <QMessageBox>
|
2017-07-16 10:41:54 +02:00
|
|
|
#include <QPushButton>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <QSet>
|
|
|
|
|
|
2016-10-06 11:31:15 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// BuildDirManager:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
BuildDirManager::BuildDirManager() = default;
|
2016-10-17 14:38:38 +02:00
|
|
|
BuildDirManager::~BuildDirManager() = default;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
Utils::FileName BuildDirManager::workDirectory(const BuildDirParameters ¶meters) const
|
2016-02-25 14:18:05 +01:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
const Utils::FileName bdir = parameters.buildDirectory;
|
|
|
|
|
const CMakeTool *cmake = parameters.cmakeTool;
|
2017-09-07 14:00:29 +02:00
|
|
|
if (bdir.exists()) {
|
2016-02-25 14:18:05 +01:00
|
|
|
return bdir;
|
2017-09-07 14:00:29 +02:00
|
|
|
} else {
|
|
|
|
|
if (cmake && cmake->autoCreateBuildDirectory()) {
|
|
|
|
|
if (!QDir().mkpath(bdir.toString()))
|
|
|
|
|
emitErrorOccured(tr("Failed to create build directory \"%1\".").arg(bdir.toUserOutput()));
|
|
|
|
|
return bdir;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-17 14:38:38 +02:00
|
|
|
if (!m_tempDir) {
|
2017-01-19 16:44:22 +01:00
|
|
|
m_tempDir.reset(new Utils::TemporaryDirectory("qtc-cmake-XXXXXXXX"));
|
2017-09-07 14:00:29 +02:00
|
|
|
if (!m_tempDir->isValid()) {
|
|
|
|
|
emitErrorOccured(tr("Failed to create temporary directory \"%1\".")
|
|
|
|
|
.arg(QDir::toNativeSeparators(m_tempDir->path())));
|
|
|
|
|
}
|
2016-10-17 14:38:38 +02:00
|
|
|
}
|
2016-10-17 13:55:54 +02:00
|
|
|
return Utils::FileName::fromString(m_tempDir->path());
|
2016-02-25 14:18:05 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-28 17:20:07 +02:00
|
|
|
void BuildDirManager::emitDataAvailable()
|
|
|
|
|
{
|
2016-12-04 03:36:12 +10:00
|
|
|
if (!isParsing())
|
2016-10-28 17:20:07 +02:00
|
|
|
emit dataAvailable();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 19:35:13 +01:00
|
|
|
void BuildDirManager::emitErrorOccured(const QString &message) const
|
|
|
|
|
{
|
|
|
|
|
m_isHandlingError = true;
|
|
|
|
|
emit errorOccured(message);
|
|
|
|
|
m_isHandlingError = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void BuildDirManager::updateReaderType(const BuildDirParameters &p,
|
|
|
|
|
std::function<void()> todo)
|
2016-02-24 18:00:24 +01:00
|
|
|
{
|
2016-10-17 13:55:54 +02:00
|
|
|
if (!m_reader || !m_reader->isCompatible(p)) {
|
|
|
|
|
m_reader.reset(BuildDirReader::createReader(p));
|
|
|
|
|
connect(m_reader.get(), &BuildDirReader::configurationStarted,
|
2017-09-28 11:32:39 +02:00
|
|
|
this, &BuildDirManager::parsingStarted);
|
2016-10-17 13:55:54 +02:00
|
|
|
connect(m_reader.get(), &BuildDirReader::dataAvailable,
|
2016-10-28 17:20:07 +02:00
|
|
|
this, &BuildDirManager::emitDataAvailable);
|
2016-10-17 13:55:54 +02:00
|
|
|
connect(m_reader.get(), &BuildDirReader::errorOccured,
|
2017-03-24 19:35:13 +01:00
|
|
|
this, &BuildDirManager::emitErrorOccured);
|
2016-10-17 13:55:54 +02:00
|
|
|
connect(m_reader.get(), &BuildDirReader::dirty, this, &BuildDirManager::becameDirty);
|
|
|
|
|
}
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(m_reader, return);
|
|
|
|
|
|
2016-10-17 13:55:54 +02:00
|
|
|
m_reader->setParameters(p);
|
2016-10-17 14:38:38 +02:00
|
|
|
|
|
|
|
|
if (m_reader->isReady())
|
|
|
|
|
todo();
|
|
|
|
|
else
|
|
|
|
|
connect(m_reader.get(), &BuildDirReader::isReadyNow, this, todo);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
bool BuildDirManager::hasConfigChanged()
|
2016-10-17 14:38:38 +02:00
|
|
|
{
|
|
|
|
|
checkConfiguration();
|
|
|
|
|
|
|
|
|
|
const QByteArray GENERATOR_KEY = "CMAKE_GENERATOR";
|
|
|
|
|
const QByteArray EXTRA_GENERATOR_KEY = "CMAKE_EXTRA_GENERATOR";
|
|
|
|
|
const QByteArray CMAKE_COMMAND_KEY = "CMAKE_COMMAND";
|
2016-12-01 12:15:40 +01:00
|
|
|
const QByteArray CMAKE_C_COMPILER_KEY = "CMAKE_C_COMPILER";
|
|
|
|
|
const QByteArray CMAKE_CXX_COMPILER_KEY = "CMAKE_CXX_COMPILER";
|
2016-10-17 14:38:38 +02:00
|
|
|
|
|
|
|
|
const QByteArrayList criticalKeys
|
2017-02-22 15:09:35 +01:00
|
|
|
= {GENERATOR_KEY, CMAKE_COMMAND_KEY, CMAKE_C_COMPILER_KEY, CMAKE_CXX_COMPILER_KEY};
|
2016-10-17 14:38:38 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
const CMakeConfig currentConfig = takeCMakeConfiguration();
|
2016-10-17 14:38:38 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
const CMakeTool *tool = m_parameters.cmakeTool;
|
|
|
|
|
QTC_ASSERT(tool, return false); // No cmake... we should not have ended up here in the first place
|
|
|
|
|
const QString extraKitGenerator = m_parameters.extraGenerator;
|
|
|
|
|
const QString mainKitGenerator = m_parameters.generator;
|
|
|
|
|
CMakeConfig targetConfig = m_parameters.configuration;
|
2016-10-17 14:38:38 +02:00
|
|
|
targetConfig.append(CMakeConfigItem(GENERATOR_KEY, CMakeConfigItem::INTERNAL,
|
|
|
|
|
QByteArray(), mainKitGenerator.toUtf8()));
|
|
|
|
|
if (!extraKitGenerator.isEmpty())
|
|
|
|
|
targetConfig.append(CMakeConfigItem(EXTRA_GENERATOR_KEY, CMakeConfigItem::INTERNAL,
|
|
|
|
|
QByteArray(), extraKitGenerator.toUtf8()));
|
|
|
|
|
targetConfig.append(CMakeConfigItem(CMAKE_COMMAND_KEY, CMakeConfigItem::INTERNAL,
|
|
|
|
|
QByteArray(), tool->cmakeExecutable().toUserOutput().toUtf8()));
|
|
|
|
|
Utils::sort(targetConfig, CMakeConfigItem::sortOperator());
|
|
|
|
|
|
|
|
|
|
bool mustReparse = false;
|
|
|
|
|
auto ccit = currentConfig.constBegin();
|
|
|
|
|
auto kcit = targetConfig.constBegin();
|
|
|
|
|
|
|
|
|
|
while (ccit != currentConfig.constEnd() && kcit != targetConfig.constEnd()) {
|
|
|
|
|
if (ccit->key == kcit->key) {
|
|
|
|
|
if (ccit->value != kcit->value) {
|
|
|
|
|
if (criticalKeys.contains(kcit->key)) {
|
2017-09-28 11:32:39 +02:00
|
|
|
clearCache();
|
|
|
|
|
return false; // no need to trigger a new reader, clearCache will do that
|
2016-10-17 14:38:38 +02:00
|
|
|
}
|
|
|
|
|
mustReparse = true;
|
|
|
|
|
}
|
|
|
|
|
++ccit;
|
|
|
|
|
++kcit;
|
|
|
|
|
} else {
|
|
|
|
|
if (ccit->key < kcit->key) {
|
|
|
|
|
++ccit;
|
|
|
|
|
} else {
|
|
|
|
|
++kcit;
|
|
|
|
|
mustReparse = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we have keys that do not exist yet, then reparse.
|
|
|
|
|
//
|
|
|
|
|
// The critical keys *must* be set in cmake configuration, so those were already
|
|
|
|
|
// handled above.
|
2017-09-28 11:32:39 +02:00
|
|
|
return mustReparse || kcit != targetConfig.constEnd();
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BuildDirManager::isParsing() const
|
2016-01-20 12:19:16 +01:00
|
|
|
{
|
2016-10-17 13:55:54 +02:00
|
|
|
return m_reader && m_reader->isParsing();
|
2016-01-20 12:19:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters ¶meters,
|
|
|
|
|
int newReaderReparseOptions,
|
|
|
|
|
int existingReaderReparseOptions)
|
2016-06-27 14:49:35 +02:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(parameters.isValid(), return);
|
2016-06-27 14:49:35 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
if (m_reader)
|
|
|
|
|
m_reader->stop();
|
2016-10-17 13:55:54 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
BuildDirReader *old = m_reader.get();
|
2016-10-17 13:55:54 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
m_parameters = parameters;
|
|
|
|
|
m_parameters.buildDirectory = workDirectory(parameters);
|
2016-06-27 14:49:35 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
updateReaderType(m_parameters,
|
|
|
|
|
[this, old, newReaderReparseOptions, existingReaderReparseOptions]() {
|
|
|
|
|
if (old != m_reader.get())
|
|
|
|
|
emit requestReparse(newReaderReparseOptions);
|
|
|
|
|
else
|
|
|
|
|
emit requestReparse(existingReaderReparseOptions);
|
|
|
|
|
});
|
2017-07-16 10:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeBuildConfiguration *BuildDirManager::buildConfiguration() const
|
2017-07-16 10:05:21 +02:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
return m_parameters.buildConfiguration;
|
2017-07-16 10:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void BuildDirManager::becameDirty()
|
2016-01-20 12:19:16 +01:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
if (isParsing())
|
|
|
|
|
return;
|
2017-03-24 19:35:13 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
if (!m_parameters.buildConfiguration || !m_parameters.buildConfiguration->isActive())
|
2016-03-16 16:33:54 +01:00
|
|
|
return;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
const CMakeTool *tool = m_parameters.cmakeTool;
|
|
|
|
|
if (!tool->isAutoRun())
|
|
|
|
|
return;
|
2016-01-20 12:19:16 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
emit requestReparse(REPARSE_CHECK_CONFIGURATION);
|
2016-01-20 12:19:16 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
void BuildDirManager::resetData()
|
2016-01-27 10:22:07 +01:00
|
|
|
{
|
2016-10-17 13:55:54 +02:00
|
|
|
if (m_reader)
|
|
|
|
|
m_reader->resetData();
|
2016-01-27 10:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 14:18:05 +01:00
|
|
|
bool BuildDirManager::persistCMakeState()
|
|
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(m_parameters.isValid(), return false);
|
|
|
|
|
|
2016-02-25 14:18:05 +01:00
|
|
|
if (!m_tempDir)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
const Utils::FileName buildDir = m_parameters.buildDirectory;
|
|
|
|
|
QDir dir(buildDir.toString());
|
|
|
|
|
dir.mkpath(buildDir.toString());
|
2016-02-25 14:18:05 +01:00
|
|
|
|
2016-10-17 13:55:54 +02:00
|
|
|
m_tempDir.reset(nullptr);
|
2016-02-25 14:18:05 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
emit requestReparse(REPARSE_URGENT | REPARSE_FORCE_CONFIGURATION | REPARSE_CHECK_CONFIGURATION);
|
2016-02-25 14:18:05 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void BuildDirManager::parse(int reparseParameters)
|
2016-10-06 11:31:15 +02:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(m_parameters.isValid(), return);
|
2016-10-17 13:55:54 +02:00
|
|
|
QTC_ASSERT(m_reader, return);
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT((reparseParameters & REPARSE_FAIL) == 0, return);
|
|
|
|
|
QTC_ASSERT((reparseParameters & REPARSE_IGNORE) == 0, return);
|
2016-11-04 09:31:46 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
m_reader->stop();
|
2016-11-04 09:31:46 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
|
|
|
|
|
|
|
|
|
if (reparseParameters & REPARSE_CHECK_CONFIGURATION) {
|
|
|
|
|
if (checkConfiguration())
|
|
|
|
|
reparseParameters |= REPARSE_FORCE_CONFIGURATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_reader->parse(reparseParameters & REPARSE_FORCE_CONFIGURATION);
|
2016-10-06 11:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void BuildDirManager::generateProjectTree(CMakeProjectNode *root, const QList<const FileNode *> &allFiles) const
|
2016-10-10 10:22:06 +02:00
|
|
|
{
|
2017-03-24 19:35:13 +01:00
|
|
|
QTC_ASSERT(!m_isHandlingError, return);
|
2017-02-06 16:59:53 +01:00
|
|
|
QTC_ASSERT(m_reader, return);
|
2017-09-28 11:32:39 +02:00
|
|
|
|
|
|
|
|
m_reader->generateProjectTree(root, allFiles);
|
2016-10-10 10:22:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void BuildDirManager::updateCodeModel(CppTools::RawProjectParts &rpps)
|
2016-01-20 12:19:16 +01:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(!m_isHandlingError, return);
|
|
|
|
|
QTC_ASSERT(m_reader, return);
|
|
|
|
|
return m_reader->updateCodeModel(rpps);
|
2016-01-20 12:19:16 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-10 12:01:30 +01:00
|
|
|
void BuildDirManager::clearCache()
|
|
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(m_parameters.isValid(), return);
|
2017-03-24 19:35:13 +01:00
|
|
|
QTC_ASSERT(!m_isHandlingError, return);
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
auto cmakeCache = workDirectory(m_parameters).appendPath("CMakeCache.txt");
|
|
|
|
|
auto cmakeFiles = workDirectory(m_parameters).appendPath("CMakeFiles");
|
2016-03-10 12:01:30 +01:00
|
|
|
|
|
|
|
|
const bool mustCleanUp = cmakeCache.exists() || cmakeFiles.exists();
|
|
|
|
|
if (!mustCleanUp)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Utils::FileUtils::removeRecursively(cmakeCache);
|
|
|
|
|
Utils::FileUtils::removeRecursively(cmakeFiles);
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
m_reader.reset();
|
2016-03-10 12:01:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-26 15:29:54 +02:00
|
|
|
static CMakeBuildTarget utilityTarget(const QString &title, const BuildDirManager *bdm)
|
|
|
|
|
{
|
|
|
|
|
CMakeBuildTarget target;
|
|
|
|
|
|
|
|
|
|
target.title = title;
|
|
|
|
|
target.targetType = UtilityType;
|
|
|
|
|
target.workingDirectory = bdm->buildConfiguration()->buildDirectory();
|
|
|
|
|
target.sourceDirectory = bdm->buildConfiguration()->target()->project()->projectDirectory();
|
|
|
|
|
|
|
|
|
|
return target;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
QList<CMakeBuildTarget> BuildDirManager::takeBuildTargets() const
|
2016-01-20 12:19:16 +01:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QList<CMakeBuildTarget> result = { utilityTarget(CMakeBuildStep::allTarget(), this),
|
|
|
|
|
utilityTarget(CMakeBuildStep::cleanTarget(), this),
|
|
|
|
|
utilityTarget(CMakeBuildStep::installTarget(), this),
|
|
|
|
|
utilityTarget(CMakeBuildStep::testTarget(), this) };
|
|
|
|
|
QTC_ASSERT(!m_isHandlingError, return result);
|
|
|
|
|
|
|
|
|
|
if (m_reader) {
|
|
|
|
|
result.append(Utils::filtered(m_reader->takeBuildTargets(), [](const CMakeBuildTarget &bt) {
|
2017-06-20 17:43:44 +02:00
|
|
|
return bt.title != CMakeBuildStep::allTarget()
|
|
|
|
|
&& bt.title != CMakeBuildStep::cleanTarget()
|
|
|
|
|
&& bt.title != CMakeBuildStep::installTarget()
|
|
|
|
|
&& bt.title != CMakeBuildStep::testTarget();
|
2017-06-20 12:21:24 +02:00
|
|
|
}));
|
2017-04-26 15:29:54 +02:00
|
|
|
}
|
2017-09-28 11:32:39 +02:00
|
|
|
return result;
|
2016-01-20 12:19:16 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeConfig BuildDirManager::takeCMakeConfiguration() const
|
2016-01-26 17:26:46 +01:00
|
|
|
{
|
2017-03-24 19:35:13 +01:00
|
|
|
QTC_ASSERT(!m_isHandlingError, return {});
|
|
|
|
|
|
2016-11-04 11:10:42 +01:00
|
|
|
if (!m_reader)
|
2017-09-28 11:32:39 +02:00
|
|
|
return CMakeConfig();
|
2017-01-18 16:53:01 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeConfig result = m_reader->takeParsedConfiguration();
|
|
|
|
|
for (auto &ci : result)
|
2017-01-18 16:53:01 +01:00
|
|
|
ci.inCMakeCache = true;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
return result;
|
2016-01-26 17:26:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeConfig BuildDirManager::parseCMakeConfiguration(const Utils::FileName &cacheFile,
|
|
|
|
|
QString *errorMessage)
|
2017-02-07 17:23:30 +01:00
|
|
|
{
|
|
|
|
|
if (!cacheFile.exists()) {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("CMakeCache.txt file not found.");
|
|
|
|
|
return { };
|
|
|
|
|
}
|
|
|
|
|
CMakeConfig result = CMakeConfigItem::itemsFromFile(cacheFile, errorMessage);
|
|
|
|
|
if (!errorMessage->isEmpty())
|
|
|
|
|
return { };
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
bool BuildDirManager::checkConfiguration()
|
2016-05-13 16:19:31 +02:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(m_parameters.isValid(), return false);
|
|
|
|
|
|
2016-05-13 16:19:31 +02:00
|
|
|
if (m_tempDir) // always throw away changes in the tmpdir!
|
2017-09-28 11:32:39 +02:00
|
|
|
return false;
|
2016-05-13 16:19:31 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
const CMakeConfig cache = m_parameters.buildConfiguration->configurationFromCMake();
|
2016-05-13 16:19:31 +02:00
|
|
|
if (cache.isEmpty())
|
2017-09-28 11:32:39 +02:00
|
|
|
return false; // No cache file yet.
|
2016-05-13 16:19:31 +02:00
|
|
|
|
|
|
|
|
CMakeConfig newConfig;
|
2017-09-29 23:34:52 +02:00
|
|
|
QHash<QString, QPair<QString, QString>> changedKeys;
|
|
|
|
|
foreach (const CMakeConfigItem &projectItem, m_parameters.configuration) {
|
|
|
|
|
const QString projectKey = QString::fromUtf8(projectItem.key);
|
|
|
|
|
const QString projectValue = projectItem.expandedValue(m_parameters.expander);
|
|
|
|
|
const CMakeConfigItem &cmakeItem
|
|
|
|
|
= Utils::findOrDefault(cache, [&projectItem](const CMakeConfigItem &i) { return i.key == projectItem.key; });
|
|
|
|
|
const QString iCacheValue = QString::fromUtf8(cmakeItem.value);
|
|
|
|
|
if (cmakeItem.isNull()) {
|
|
|
|
|
changedKeys.insert(projectKey, qMakePair(tr("<removed>"), projectValue));
|
|
|
|
|
} else if (iCacheValue != projectValue) {
|
|
|
|
|
changedKeys.insert(projectKey, qMakePair(iCacheValue, projectValue));
|
|
|
|
|
newConfig.append(cmakeItem);
|
2016-05-13 16:19:31 +02:00
|
|
|
} else {
|
2017-09-29 23:34:52 +02:00
|
|
|
newConfig.append(projectItem);
|
2016-05-13 16:19:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 23:34:52 +02:00
|
|
|
if (!changedKeys.isEmpty()) {
|
|
|
|
|
QStringList keyList = changedKeys.keys();
|
2016-05-13 16:19:31 +02:00
|
|
|
Utils::sort(keyList);
|
2017-09-29 23:34:52 +02:00
|
|
|
QString table = QString::fromLatin1("<table><tr><th>%1</th><th>%2</th><th>%3</th></tr>")
|
|
|
|
|
.arg(tr("Key")).arg(tr("CMake")).arg(tr("Project"));
|
2016-05-13 16:19:31 +02:00
|
|
|
foreach (const QString &k, keyList) {
|
2017-09-29 23:34:52 +02:00
|
|
|
const QPair<QString, QString> data = changedKeys.value(k);
|
|
|
|
|
table += QString::fromLatin1("\n<tr><td>%1</td><td>%2</td><td>%3</td></tr>")
|
|
|
|
|
.arg(k)
|
|
|
|
|
.arg(data.first.toHtmlEscaped())
|
|
|
|
|
.arg(data.second.toHtmlEscaped());
|
2016-05-13 16:19:31 +02:00
|
|
|
}
|
|
|
|
|
table += QLatin1String("\n</table>");
|
|
|
|
|
|
|
|
|
|
QPointer<QMessageBox> box = new QMessageBox(Core::ICore::mainWindow());
|
|
|
|
|
box->setText(tr("CMake configuration has changed on disk."));
|
2017-09-29 23:34:52 +02:00
|
|
|
box->setInformativeText(table);
|
2016-10-17 13:47:41 +02:00
|
|
|
auto *defaultButton = box->addButton(tr("Overwrite Changes in CMake"), QMessageBox::RejectRole);
|
2017-07-16 10:41:54 +02:00
|
|
|
auto *applyButton = box->addButton(tr("Apply Changes to Project"), QMessageBox::ApplyRole);
|
2016-10-17 13:47:41 +02:00
|
|
|
box->setDefaultButton(defaultButton);
|
2016-05-13 16:19:31 +02:00
|
|
|
|
2017-07-16 10:41:54 +02:00
|
|
|
box->exec();
|
2017-09-28 11:32:39 +02:00
|
|
|
if (box->clickedButton() == applyButton) {
|
|
|
|
|
m_parameters.configuration = newConfig;
|
|
|
|
|
QSignalBlocker blocker(m_parameters.buildConfiguration);
|
|
|
|
|
m_parameters.buildConfiguration->setConfigurationForCMake(newConfig);
|
|
|
|
|
return false;
|
|
|
|
|
} else if (box->clickedButton() == defaultButton)
|
|
|
|
|
return true;
|
2016-01-26 17:26:46 +01:00
|
|
|
}
|
2017-09-28 11:32:39 +02:00
|
|
|
return false;
|
2016-03-10 17:34:47 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CMakeProjectManager
|