2019-06-13 14:24:04 +02: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 "fileapireader.h"
|
|
|
|
|
|
|
|
|
|
#include "fileapidataextractor.h"
|
2020-05-13 12:59:23 +02:00
|
|
|
#include "fileapiparser.h"
|
2019-06-13 14:24:04 +02:00
|
|
|
#include "projecttreehelper.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/runextensions.h>
|
|
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2020-01-15 14:39:23 +01:00
|
|
|
static Q_LOGGING_CATEGORY(cmakeFileApiMode, "qtc.cmake.fileApiMode", QtWarningMsg);
|
2019-06-13 14:24:04 +02:00
|
|
|
|
|
|
|
|
using namespace FileApiDetails;
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// FileApiReader:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2020-05-13 12:59:23 +02:00
|
|
|
FileApiReader::FileApiReader()
|
|
|
|
|
: m_lastReplyTimestamp()
|
|
|
|
|
{
|
|
|
|
|
QObject::connect(&m_watcher,
|
|
|
|
|
&FileSystemWatcher::directoryChanged,
|
|
|
|
|
this,
|
|
|
|
|
&FileApiReader::replyDirectoryHasChanged);
|
|
|
|
|
}
|
2019-06-13 14:24:04 +02:00
|
|
|
|
|
|
|
|
FileApiReader::~FileApiReader()
|
|
|
|
|
{
|
2020-04-03 11:43:29 +02:00
|
|
|
if (isParsing())
|
|
|
|
|
emit errorOccurred(tr("Parsing has been canceled."));
|
2019-06-13 14:24:04 +02:00
|
|
|
stop();
|
|
|
|
|
resetData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::setParameters(const BuildDirParameters &p)
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeFileApiMode)
|
|
|
|
|
<< "\n\n\n\n\n=============================================================\n";
|
|
|
|
|
|
|
|
|
|
// Update:
|
|
|
|
|
m_parameters = p;
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "Work directory:" << m_parameters.workDirectory.toUserOutput();
|
|
|
|
|
|
2020-05-13 12:59:23 +02:00
|
|
|
// Reset watcher:
|
|
|
|
|
m_watcher.removeFiles(m_watcher.files());
|
|
|
|
|
m_watcher.removeDirectories(m_watcher.directories());
|
2019-06-13 14:24:04 +02:00
|
|
|
|
2020-05-13 12:59:23 +02:00
|
|
|
FileApiParser::setupCMakeFileApi(m_parameters.workDirectory, m_watcher);
|
|
|
|
|
|
|
|
|
|
resetData();
|
2019-06-13 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::resetData()
|
|
|
|
|
{
|
|
|
|
|
m_cmakeFiles.clear();
|
|
|
|
|
if (!m_parameters.sourceDirectory.isEmpty())
|
|
|
|
|
m_cmakeFiles.insert(m_parameters.sourceDirectory.pathAppended("CMakeLists.txt"));
|
|
|
|
|
|
|
|
|
|
m_cache.clear();
|
|
|
|
|
m_buildTargets.clear();
|
|
|
|
|
m_projectParts.clear();
|
|
|
|
|
m_rootProjectNode.reset();
|
|
|
|
|
m_knownHeaders.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
void FileApiReader::parse(bool forceCMakeRun,
|
|
|
|
|
bool forceInitialConfiguration,
|
|
|
|
|
bool forceExtraConfiguration)
|
2019-06-13 14:24:04 +02:00
|
|
|
{
|
2019-08-09 12:20:49 +02:00
|
|
|
qCDebug(cmakeFileApiMode) << "Parse called with arguments: ForceCMakeRun:" << forceCMakeRun
|
2020-04-02 14:49:05 +02:00
|
|
|
<< " - forceConfiguration:" << forceInitialConfiguration
|
|
|
|
|
<< " - forceExtraConfiguration:" << forceExtraConfiguration;
|
2019-06-13 14:24:04 +02:00
|
|
|
startState();
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
const QStringList args = (forceInitialConfiguration ? m_parameters.initialCMakeArguments
|
|
|
|
|
: QStringList())
|
|
|
|
|
+ (forceExtraConfiguration ? m_parameters.extraCMakeArguments
|
|
|
|
|
: QStringList());
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "Parameters request these CMake arguments:" << args;
|
2019-06-13 14:24:04 +02:00
|
|
|
|
2020-05-13 12:59:23 +02:00
|
|
|
const QFileInfo replyFi = FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory);
|
2019-06-21 14:14:31 +02:00
|
|
|
// Only need to update when one of the following conditions is met:
|
2020-04-02 14:49:05 +02:00
|
|
|
// * The user forces the cmake run,
|
|
|
|
|
// * The user provided arguments,
|
2019-06-21 14:14:31 +02:00
|
|
|
// * There is no reply file,
|
|
|
|
|
// * One of the cmakefiles is newer than the replyFile and the user asked
|
|
|
|
|
// for creator to run CMake as needed,
|
2020-05-13 12:24:59 +02:00
|
|
|
// * A query file is newer than the reply file
|
2020-04-02 14:49:05 +02:00
|
|
|
const bool hasArguments = !args.isEmpty();
|
|
|
|
|
const bool replyFileMissing = !replyFi.exists();
|
|
|
|
|
const bool cmakeFilesChanged = m_parameters.cmakeTool() && m_parameters.cmakeTool()->isAutoRun()
|
|
|
|
|
&& anyOf(m_cmakeFiles, [&replyFi](const FilePath &f) {
|
|
|
|
|
return f.toFileInfo().lastModified()
|
|
|
|
|
> replyFi.lastModified();
|
|
|
|
|
});
|
|
|
|
|
const bool queryFileChanged = anyOf(FileApiParser::cmakeQueryFilePaths(
|
|
|
|
|
m_parameters.workDirectory),
|
|
|
|
|
[&replyFi](const QString &qf) {
|
|
|
|
|
return QFileInfo(qf).lastModified()
|
|
|
|
|
> replyFi.lastModified();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const bool mustUpdate = forceCMakeRun || hasArguments || replyFileMissing || cmakeFilesChanged
|
|
|
|
|
|| queryFileChanged;
|
|
|
|
|
qCDebug(cmakeFileApiMode) << QString("Do I need to run CMake? %1 "
|
|
|
|
|
"(force: %2 | args: %3 | missing reply: %4 | "
|
|
|
|
|
"cmakeFilesChanged: %5 | "
|
|
|
|
|
"queryFileChanged: %6)")
|
|
|
|
|
.arg(mustUpdate)
|
|
|
|
|
.arg(forceCMakeRun)
|
|
|
|
|
.arg(hasArguments)
|
|
|
|
|
.arg(replyFileMissing)
|
|
|
|
|
.arg(cmakeFilesChanged)
|
|
|
|
|
.arg(queryFileChanged);
|
2019-06-13 14:24:04 +02:00
|
|
|
|
|
|
|
|
if (mustUpdate) {
|
2020-04-02 14:49:05 +02:00
|
|
|
qCDebug(cmakeFileApiMode) << QString("FileApiReader: Starting CMake with \"%1\".")
|
|
|
|
|
.arg(args.join("\", \""));
|
|
|
|
|
startCMakeState(args);
|
|
|
|
|
} else {
|
|
|
|
|
endState(replyFi);
|
2019-06-13 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::stop()
|
|
|
|
|
{
|
2020-04-24 10:29:43 +02:00
|
|
|
if (m_cmakeProcess)
|
|
|
|
|
disconnect(m_cmakeProcess.get(), nullptr, this, nullptr);
|
2019-06-13 14:24:04 +02:00
|
|
|
m_cmakeProcess.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileApiReader::isParsing() const
|
|
|
|
|
{
|
|
|
|
|
return m_isParsing;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 18:34:12 +01:00
|
|
|
QSet<FilePath> FileApiReader::projectFilesToWatch() const
|
2019-08-15 12:22:09 +02:00
|
|
|
{
|
2020-03-02 18:34:12 +01:00
|
|
|
return m_cmakeFiles;
|
2019-08-15 12:22:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 14:24:04 +02:00
|
|
|
QList<CMakeBuildTarget> FileApiReader::takeBuildTargets(QString &errorMessage){
|
|
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
|
|
|
|
|
auto result = std::move(m_buildTargets);
|
|
|
|
|
m_buildTargets.clear();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeConfig FileApiReader::takeParsedConfiguration(QString &errorMessage)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
|
|
|
|
|
CMakeConfig cache = m_cache;
|
|
|
|
|
m_cache.clear();
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 15:10:04 +02:00
|
|
|
QString FileApiReader::ctestPath() const
|
|
|
|
|
{
|
|
|
|
|
// if we failed to run cmake we should not offer ctest information either
|
|
|
|
|
return m_lastCMakeExitCode == 0 ? m_ctestPath : QString();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 16:38:55 +01:00
|
|
|
bool FileApiReader::isMultiConfig() const
|
|
|
|
|
{
|
|
|
|
|
return m_isMultiConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileApiReader::usesAllCapsTargets() const
|
|
|
|
|
{
|
|
|
|
|
return m_usesAllCapsTargets;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 14:24:04 +02:00
|
|
|
std::unique_ptr<CMakeProjectNode> FileApiReader::generateProjectTree(
|
2020-10-26 15:36:59 +01:00
|
|
|
const QList<const FileNode *> &allFiles, QString &errorMessage, bool includeHeaderNodes)
|
2019-06-13 14:24:04 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
|
2020-10-26 15:36:59 +01:00
|
|
|
if (includeHeaderNodes) {
|
|
|
|
|
addHeaderNodes(m_rootProjectNode.get(), m_knownHeaders, allFiles);
|
|
|
|
|
}
|
|
|
|
|
addFileSystemNodes(m_rootProjectNode.get(), allFiles);
|
2019-06-13 14:24:04 +02:00
|
|
|
return std::move(m_rootProjectNode);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
RawProjectParts FileApiReader::createRawProjectParts(QString &errorMessage)
|
2019-06-13 14:24:04 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
RawProjectParts result = std::move(m_projectParts);
|
2019-06-13 14:24:04 +02:00
|
|
|
m_projectParts.clear();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::startState()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "FileApiReader: START STATE.";
|
|
|
|
|
QTC_ASSERT(!m_isParsing, return );
|
|
|
|
|
QTC_ASSERT(!m_future.has_value(), return );
|
|
|
|
|
|
|
|
|
|
m_isParsing = true;
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "FileApiReader: CONFIGURATION STARTED SIGNAL";
|
|
|
|
|
emit configurationStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::endState(const QFileInfo &replyFi)
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "FileApiReader: END STATE.";
|
|
|
|
|
QTC_ASSERT(m_isParsing, return );
|
|
|
|
|
QTC_ASSERT(!m_future.has_value(), return );
|
|
|
|
|
|
|
|
|
|
const FilePath sourceDirectory = m_parameters.sourceDirectory;
|
|
|
|
|
const FilePath buildDirectory = m_parameters.workDirectory;
|
2020-10-26 15:36:59 +01:00
|
|
|
const FilePath topCmakeFile = m_cmakeFiles.size() == 1 ? *m_cmakeFiles.begin() : FilePath{};
|
2021-01-14 16:38:55 +01:00
|
|
|
const QString cmakeBuildType = m_parameters.cmakeBuildType;
|
2019-06-13 14:24:04 +02:00
|
|
|
|
2020-05-13 12:59:23 +02:00
|
|
|
m_lastReplyTimestamp = replyFi.lastModified();
|
2019-07-25 15:16:55 +02:00
|
|
|
|
2019-06-13 14:24:04 +02:00
|
|
|
m_future = runAsync(ProjectExplorerPlugin::sharedThreadPool(),
|
2021-01-14 16:38:55 +01:00
|
|
|
[replyFi, sourceDirectory, buildDirectory, topCmakeFile, cmakeBuildType]() {
|
2019-06-13 14:24:04 +02:00
|
|
|
auto result = std::make_unique<FileApiQtcData>();
|
2021-01-14 16:38:55 +01:00
|
|
|
FileApiData data = FileApiParser::parseData(replyFi, cmakeBuildType, result->errorMessage);
|
2019-06-13 14:24:04 +02:00
|
|
|
if (!result->errorMessage.isEmpty()) {
|
|
|
|
|
qWarning() << result->errorMessage;
|
2020-10-26 15:36:59 +01:00
|
|
|
*result = generateFallbackData(topCmakeFile,
|
|
|
|
|
sourceDirectory,
|
|
|
|
|
buildDirectory,
|
|
|
|
|
result->errorMessage);
|
|
|
|
|
} else {
|
|
|
|
|
*result = extractData(data, sourceDirectory, buildDirectory);
|
2019-06-13 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
if (!result->errorMessage.isEmpty()) {
|
|
|
|
|
qWarning() << result->errorMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result.release();
|
|
|
|
|
});
|
|
|
|
|
onFinished(m_future.value(), this, [this](const QFuture<FileApiQtcData *> &f) {
|
|
|
|
|
std::unique_ptr<FileApiQtcData> value(f.result()); // Adopt the pointer again:-)
|
|
|
|
|
|
|
|
|
|
m_future = {};
|
|
|
|
|
m_isParsing = false;
|
|
|
|
|
m_cache = std::move(value->cache);
|
|
|
|
|
m_cmakeFiles = std::move(value->cmakeFiles);
|
|
|
|
|
m_buildTargets = std::move(value->buildTargets);
|
|
|
|
|
m_projectParts = std::move(value->projectParts);
|
|
|
|
|
m_rootProjectNode = std::move(value->rootProjectNode);
|
|
|
|
|
m_knownHeaders = std::move(value->knownHeaders);
|
2020-09-28 15:10:04 +02:00
|
|
|
m_ctestPath = std::move(value->ctestPath);
|
2021-01-14 16:38:55 +01:00
|
|
|
m_isMultiConfig = std::move(value->isMultiConfig);
|
|
|
|
|
m_usesAllCapsTargets = std::move(value->usesAllCapsTargets);
|
2019-06-13 14:24:04 +02:00
|
|
|
|
|
|
|
|
if (value->errorMessage.isEmpty()) {
|
|
|
|
|
emit this->dataAvailable();
|
|
|
|
|
} else {
|
2020-03-19 12:41:23 +01:00
|
|
|
emit this->errorOccurred(value->errorMessage);
|
2019-06-13 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::startCMakeState(const QStringList &configurationArguments)
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "FileApiReader: START CMAKE STATE.";
|
|
|
|
|
QTC_ASSERT(!m_cmakeProcess, return );
|
|
|
|
|
|
|
|
|
|
m_cmakeProcess = std::make_unique<CMakeProcess>();
|
|
|
|
|
|
|
|
|
|
connect(m_cmakeProcess.get(), &CMakeProcess::finished, this, &FileApiReader::cmakeFinishedState);
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeFileApiMode) << ">>>>>> Running cmake with arguments:" << configurationArguments;
|
|
|
|
|
m_cmakeProcess->run(m_parameters, configurationArguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::cmakeFinishedState(int code, QProcess::ExitStatus status)
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeFileApiMode) << "FileApiReader: CMAKE FINISHED STATE.";
|
|
|
|
|
|
|
|
|
|
Q_UNUSED(code)
|
|
|
|
|
Q_UNUSED(status)
|
|
|
|
|
|
2020-09-28 15:10:04 +02:00
|
|
|
m_lastCMakeExitCode = m_cmakeProcess->lastExitCode();
|
2019-10-08 12:45:06 +02:00
|
|
|
m_cmakeProcess.release()->deleteLater();
|
|
|
|
|
|
2020-05-13 12:59:23 +02:00
|
|
|
endState(FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileApiReader::replyDirectoryHasChanged(const QString &directory) const
|
|
|
|
|
{
|
|
|
|
|
if (m_isParsing)
|
|
|
|
|
return; // This has been triggered by ourselves, ignore.
|
|
|
|
|
|
|
|
|
|
const QFileInfo fi = FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory);
|
|
|
|
|
const QString dir = fi.absolutePath();
|
|
|
|
|
if (dir.isEmpty())
|
|
|
|
|
return; // CMake started to fill the result dir, but has not written a result file yet
|
|
|
|
|
QTC_ASSERT(dir == directory, return);
|
|
|
|
|
|
|
|
|
|
if (m_lastReplyTimestamp.isValid() && fi.lastModified() > m_lastReplyTimestamp)
|
|
|
|
|
emit dirty();
|
2019-06-13 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CMakeProjectManager
|