2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 Alexis Jeandet.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
#include "mesonbuildsystem.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2022-10-06 16:58:18 +02:00
|
|
|
#include "kithelper.h"
|
|
|
|
|
#include "machinefilemanager.h"
|
2020-05-01 18:20:56 +02:00
|
|
|
#include "mesonbuildconfiguration.h"
|
2022-10-10 09:14:04 +02:00
|
|
|
#include "mesonprojectmanagertr.h"
|
2022-10-06 16:58:18 +02:00
|
|
|
#include "mesontoolkitaspect.h"
|
|
|
|
|
#include "settings.h"
|
2020-10-29 10:20:14 +01:00
|
|
|
|
2020-06-29 09:27:15 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2020-12-01 14:57:54 +01:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
#include <qtsupport/qtcppkitinfo.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
|
2020-10-29 10:20:14 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
#define LEAVE_IF_BUSY() \
|
|
|
|
|
{ \
|
|
|
|
|
if (m_parseGuard.guardsProject()) \
|
|
|
|
|
return false; \
|
|
|
|
|
}
|
|
|
|
|
#define LOCK() \
|
|
|
|
|
{ \
|
|
|
|
|
m_parseGuard = guardParsingRun(); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define UNLOCK(success) \
|
|
|
|
|
{ \
|
|
|
|
|
if (success) \
|
|
|
|
|
m_parseGuard.markAsSuccess(); \
|
|
|
|
|
m_parseGuard = {}; \
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-01 14:57:54 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
namespace MesonProjectManager {
|
|
|
|
|
namespace Internal {
|
2020-12-01 14:57:54 +01:00
|
|
|
static Q_LOGGING_CATEGORY(mesonBuildSystemLog, "qtc.meson.buildsystem", QtWarningMsg);
|
2020-05-01 18:20:56 +02:00
|
|
|
|
|
|
|
|
MesonBuildSystem::MesonBuildSystem(MesonBuildConfiguration *bc)
|
|
|
|
|
: ProjectExplorer::BuildSystem{bc}
|
2020-09-07 15:56:18 +02:00
|
|
|
, m_parser{MesonToolKitAspect::mesonToolId(bc->kit()), bc->environment(), project()}
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesonBuildSystem::~MesonBuildSystem()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "dtor";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MesonBuildSystem::triggerParsing()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "Trigger parsing";
|
|
|
|
|
parseProject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MesonBuildSystem::needsSetup()
|
|
|
|
|
{
|
|
|
|
|
const Utils::FilePath &buildDir = buildConfiguration()->buildDirectory();
|
|
|
|
|
return (!isSetup(buildDir) || !m_parser.usesSameMesonVersion(buildDir)
|
|
|
|
|
|| !m_parser.matchesKit(m_kitData));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MesonBuildSystem::parsingCompleted(bool success)
|
|
|
|
|
{
|
|
|
|
|
if (success) {
|
|
|
|
|
setRootProjectNode(m_parser.takeProjectNode());
|
|
|
|
|
if (kit() && buildConfiguration()) {
|
|
|
|
|
ProjectExplorer::KitInfo kitInfo{kit()};
|
|
|
|
|
m_cppCodeModelUpdater.update(
|
|
|
|
|
{project(),
|
|
|
|
|
QtSupport::CppKitInfo(kit()),
|
|
|
|
|
buildConfiguration()->environment(),
|
|
|
|
|
m_parser.buildProjectParts(kitInfo.cxxToolChain, kitInfo.cToolChain)});
|
|
|
|
|
}
|
|
|
|
|
setApplicationTargets(m_parser.appsTargets());
|
|
|
|
|
UNLOCK(true);
|
|
|
|
|
emitBuildSystemUpdated();
|
|
|
|
|
} else {
|
2022-10-10 09:14:04 +02:00
|
|
|
TaskHub::addTask(BuildSystemTask(Task::Error, Tr::tr("Meson build: Parsing failed")));
|
2020-05-01 18:20:56 +02:00
|
|
|
UNLOCK(false);
|
|
|
|
|
emitBuildSystemUpdated();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Kit *MesonBuildSystem::MesonBuildSystem::kit()
|
|
|
|
|
{
|
2020-09-07 15:56:18 +02:00
|
|
|
return buildConfiguration()->kit();
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList MesonBuildSystem::configArgs(bool isSetup)
|
|
|
|
|
{
|
2021-01-02 20:14:56 +02:00
|
|
|
const QString ¶ms = mesonBuildConfiguration()->parameters();
|
|
|
|
|
if (!isSetup || params.contains("--cross-file") || params.contains("--native-file"))
|
2020-05-01 18:20:56 +02:00
|
|
|
return m_pendingConfigArgs + mesonBuildConfiguration()->mesonConfigArgs();
|
|
|
|
|
else {
|
2020-06-29 09:27:15 +02:00
|
|
|
return QStringList{
|
|
|
|
|
QString("--native-file=%1").arg(MachineFileManager::machineFile(kit()).toString())}
|
2020-05-01 18:20:56 +02:00
|
|
|
+ m_pendingConfigArgs + mesonBuildConfiguration()->mesonConfigArgs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MesonBuildSystem::configure()
|
|
|
|
|
{
|
|
|
|
|
LEAVE_IF_BUSY();
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "Configure";
|
|
|
|
|
if (needsSetup())
|
|
|
|
|
return setup();
|
|
|
|
|
LOCK();
|
|
|
|
|
if (m_parser.configure(projectDirectory(),
|
|
|
|
|
buildConfiguration()->buildDirectory(),
|
|
|
|
|
configArgs(false))) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
UNLOCK(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MesonBuildSystem::setup()
|
|
|
|
|
{
|
|
|
|
|
LEAVE_IF_BUSY();
|
|
|
|
|
LOCK();
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "Setup";
|
|
|
|
|
if (m_parser.setup(projectDirectory(), buildConfiguration()->buildDirectory(), configArgs(true)))
|
|
|
|
|
return true;
|
|
|
|
|
UNLOCK(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MesonBuildSystem::wipe()
|
|
|
|
|
{
|
|
|
|
|
LEAVE_IF_BUSY();
|
|
|
|
|
LOCK();
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "Wipe";
|
|
|
|
|
if (m_parser.wipe(projectDirectory(), buildConfiguration()->buildDirectory(), configArgs(true)))
|
|
|
|
|
return true;
|
|
|
|
|
UNLOCK(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesonBuildConfiguration *MesonBuildSystem::mesonBuildConfiguration()
|
|
|
|
|
{
|
|
|
|
|
return static_cast<MesonBuildConfiguration *>(buildConfiguration());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MesonBuildSystem::init()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "Init";
|
|
|
|
|
connect(buildConfiguration()->target(), &ProjectExplorer::Target::kitChanged, this, [this] {
|
|
|
|
|
updateKit(kit());
|
|
|
|
|
});
|
2020-06-29 09:27:15 +02:00
|
|
|
connect(mesonBuildConfiguration(), &MesonBuildConfiguration::buildDirectoryChanged, this, [this]() {
|
|
|
|
|
updateKit(kit());
|
|
|
|
|
this->triggerParsing();
|
|
|
|
|
});
|
2021-01-02 20:14:56 +02:00
|
|
|
connect(mesonBuildConfiguration(), &MesonBuildConfiguration::parametersChanged, this, [this]() {
|
|
|
|
|
updateKit(kit());
|
|
|
|
|
wipe();
|
|
|
|
|
});
|
2020-05-01 18:20:56 +02:00
|
|
|
connect(mesonBuildConfiguration(), &MesonBuildConfiguration::environmentChanged, this, [this]() {
|
|
|
|
|
m_parser.setEnvironment(buildConfiguration()->environment());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(project(), &ProjectExplorer::Project::projectFileIsDirty, this, [this]() {
|
|
|
|
|
if (buildConfiguration()->isActive())
|
|
|
|
|
parseProject();
|
|
|
|
|
});
|
2020-06-29 09:27:15 +02:00
|
|
|
connect(&m_parser, &MesonProjectParser::parsingCompleted, this, &MesonBuildSystem::parsingCompleted);
|
|
|
|
|
|
|
|
|
|
connect(&m_IntroWatcher, &Utils::FileSystemWatcher::fileChanged, this, [this]() {
|
|
|
|
|
if (buildConfiguration()->isActive())
|
|
|
|
|
parseProject();
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
updateKit(kit());
|
2020-06-29 09:27:15 +02:00
|
|
|
// as specified here https://mesonbuild.com/IDE-integration.html#ide-integration
|
|
|
|
|
// meson-info.json is the last written file, which ensure that all others introspection
|
|
|
|
|
// files are ready when a modification is detected on this one.
|
|
|
|
|
m_IntroWatcher.addFile(buildConfiguration()
|
|
|
|
|
->buildDirectory()
|
|
|
|
|
.pathAppended(Constants::MESON_INFO_DIR)
|
2023-01-23 13:54:54 +01:00
|
|
|
.pathAppended(Constants::MESON_INFO),
|
2020-10-26 15:02:16 +01:00
|
|
|
Utils::FileSystemWatcher::WatchModifiedDate);
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MesonBuildSystem::parseProject()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(buildConfiguration(), return false);
|
2021-03-31 17:46:20 +02:00
|
|
|
if (!isSetup(buildConfiguration()->buildDirectory()) && Settings::instance()->autorunMeson.value())
|
2020-05-01 18:20:56 +02:00
|
|
|
return configure();
|
|
|
|
|
LEAVE_IF_BUSY();
|
|
|
|
|
LOCK();
|
|
|
|
|
qCDebug(mesonBuildSystemLog) << "Starting parser";
|
|
|
|
|
if (m_parser.parse(projectDirectory(), buildConfiguration()->buildDirectory()))
|
|
|
|
|
return true;
|
|
|
|
|
UNLOCK(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MesonBuildSystem::updateKit(ProjectExplorer::Kit *kit)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(kit, return );
|
|
|
|
|
m_kitData = KitHelper::kitData(kit);
|
|
|
|
|
m_parser.setQtVersion(m_kitData.qtVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|