forked from qt-creator/qt-creator
Meson: Inline NativeFileGenerator into its only user
Also, filepathify and simplify surrounding code a bit. Change-Id: I963bbc95a81d753918b6734870630b539378f03e Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -49,8 +49,6 @@ add_qtc_plugin(MesonProjectManager
|
||||
mesontools.h
|
||||
mesonwrapper.cpp
|
||||
mesonwrapper.h
|
||||
nativefilegenerator.cpp
|
||||
nativefilegenerator.h
|
||||
ninjabuildstep.cpp
|
||||
ninjabuildstep.h
|
||||
ninjaparser.cpp
|
||||
|
@@ -5,115 +5,110 @@
|
||||
|
||||
#include "kitdata.h"
|
||||
#include "kithelper.h"
|
||||
#include "nativefilegenerator.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QRegularExpression>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace MesonProjectManager::Internal {
|
||||
|
||||
const char MACHINE_FILE_PREFIX[] = "Meson-MachineFile-";
|
||||
const char MACHINE_FILE_EXT[] = ".ini";
|
||||
|
||||
template<typename F>
|
||||
bool withFile(const Utils::FilePath &path, const F &f)
|
||||
{
|
||||
QFile file(path.toString());
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
f(&file);
|
||||
return file.flush();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Utils::FilePath MachineFilesDir()
|
||||
static FilePath machineFilesDir()
|
||||
{
|
||||
return Core::ICore::userResourcePath("Meson-machine-files");
|
||||
}
|
||||
|
||||
MachineFileManager::MachineFileManager()
|
||||
{
|
||||
using namespace ProjectExplorer;
|
||||
connect(KitManager::instance(),
|
||||
&KitManager::kitAdded,
|
||||
this,
|
||||
&MachineFileManager::addMachineFile);
|
||||
connect(KitManager::instance(),
|
||||
&KitManager::kitUpdated,
|
||||
this,
|
||||
&MachineFileManager::updateMachineFile);
|
||||
connect(KitManager::instance(),
|
||||
&KitManager::kitRemoved,
|
||||
this,
|
||||
&MachineFileManager::removeMachineFile);
|
||||
connect(KitManager::instance(),
|
||||
&KitManager::kitsLoaded,
|
||||
this,
|
||||
&MachineFileManager::cleanupMachineFiles);
|
||||
connect(KitManager::instance(), &KitManager::kitAdded,
|
||||
this, &MachineFileManager::addMachineFile);
|
||||
connect(KitManager::instance(), &KitManager::kitUpdated,
|
||||
this, &MachineFileManager::updateMachineFile);
|
||||
connect(KitManager::instance(), &KitManager::kitRemoved,
|
||||
this, &MachineFileManager::removeMachineFile);
|
||||
connect(KitManager::instance(), &KitManager::kitsLoaded,
|
||||
this, &MachineFileManager::cleanupMachineFiles);
|
||||
}
|
||||
|
||||
Utils::FilePath MachineFileManager::machineFile(const ProjectExplorer::Kit *kit)
|
||||
FilePath MachineFileManager::machineFile(const Kit *kit)
|
||||
{
|
||||
QTC_ASSERT(kit, return {});
|
||||
auto baseName
|
||||
= QString("%1%2%3").arg(MACHINE_FILE_PREFIX).arg(kit->id().toString()).arg(MACHINE_FILE_EXT);
|
||||
baseName = baseName.remove('{').remove('}');
|
||||
return MachineFilesDir().pathAppended(baseName);
|
||||
return machineFilesDir().pathAppended(baseName);
|
||||
}
|
||||
|
||||
void MachineFileManager::addMachineFile(const ProjectExplorer::Kit *kit)
|
||||
void MachineFileManager::addMachineFile(const Kit *kit)
|
||||
{
|
||||
auto filePath = machineFile(kit);
|
||||
FilePath filePath = machineFile(kit);
|
||||
QTC_ASSERT(!filePath.isEmpty(), return );
|
||||
auto data = KitHelper::kitData(kit);
|
||||
QTC_ASSERT(withFile(filePath,
|
||||
[&data](QFile *file) { NativeFileGenerator::makeNativeFile(file, data); }),
|
||||
return );
|
||||
auto kitData = KitHelper::kitData(kit);
|
||||
|
||||
auto entry = [](const QString &key, const QString &value) {
|
||||
return QString("%1 = '%2'\n").arg(key).arg(value).toUtf8();
|
||||
};
|
||||
|
||||
QByteArray ba = "[binaries]\n";
|
||||
ba += entry("c", kitData.cCompilerPath);
|
||||
ba += entry("cpp", kitData.cxxCompilerPath);
|
||||
ba += entry("qmake", kitData.qmakePath);
|
||||
if (kitData.qtVersion == QtMajorVersion::Qt4)
|
||||
ba += entry("qmake-qt4", kitData.qmakePath);
|
||||
else if (kitData.qtVersion == QtMajorVersion::Qt5)
|
||||
ba += entry("qmake-qt5", kitData.qmakePath);
|
||||
else if (kitData.qtVersion == QtMajorVersion::Qt6)
|
||||
ba += entry("qmake-qt6", kitData.qmakePath);
|
||||
ba += entry("cmake", kitData.cmakePath);
|
||||
|
||||
filePath.writeFileContents(ba);
|
||||
}
|
||||
|
||||
void MachineFileManager::removeMachineFile(const ProjectExplorer::Kit *kit)
|
||||
void MachineFileManager::removeMachineFile(const Kit *kit)
|
||||
{
|
||||
auto filePath = machineFile(kit);
|
||||
FilePath filePath = machineFile(kit);
|
||||
if (filePath.exists())
|
||||
QFile::remove(filePath.toString());
|
||||
filePath.removeFile();
|
||||
}
|
||||
|
||||
void MachineFileManager::updateMachineFile(const ProjectExplorer::Kit *kit)
|
||||
void MachineFileManager::updateMachineFile(const Kit *kit)
|
||||
{
|
||||
addMachineFile(kit);
|
||||
}
|
||||
|
||||
void MachineFileManager::cleanupMachineFiles()
|
||||
{
|
||||
const auto kits = ProjectExplorer::KitManager::kits();
|
||||
auto machineFilesDir = QDir(MachineFilesDir().toString());
|
||||
if (!machineFilesDir.exists()) {
|
||||
machineFilesDir.mkdir(machineFilesDir.path());
|
||||
}
|
||||
auto machineFiles = QDir(MachineFilesDir().toString())
|
||||
.entryList(
|
||||
{QString("%1*%2").arg(MACHINE_FILE_PREFIX).arg(MACHINE_FILE_EXT)});
|
||||
QStringList expected;
|
||||
for (auto const *kit : kits) {
|
||||
QString fname = machineFile(kit).toString();
|
||||
FilePath dir = machineFilesDir();
|
||||
dir.ensureWritableDir();
|
||||
|
||||
const FileFilter filter = {{QString("%1*%2").arg(MACHINE_FILE_PREFIX).arg(MACHINE_FILE_EXT)}};
|
||||
const FilePaths machineFiles = dir.dirEntries(filter);
|
||||
|
||||
FilePaths expected;
|
||||
for (Kit const *kit : KitManager::kits()) {
|
||||
const FilePath fname = machineFile(kit);
|
||||
expected.push_back(fname);
|
||||
if (!machineFiles.contains(fname))
|
||||
addMachineFile(kit);
|
||||
}
|
||||
|
||||
for (const auto &file : machineFiles) {
|
||||
for (const FilePath &file : machineFiles) {
|
||||
if (!expected.contains(file))
|
||||
QFile::remove(file);
|
||||
file.removeFile();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace MesonProjectManager
|
||||
} // MesonProjectManager::Internal
|
||||
|
@@ -3,17 +3,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
namespace ProjectExplorer { class Kit; }
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
namespace MesonProjectManager::Internal {
|
||||
|
||||
class MachineFileManager final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MachineFileManager();
|
||||
|
||||
@@ -26,5 +23,4 @@ private:
|
||||
void cleanupMachineFiles();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace MesonProjectManager
|
||||
} // MesonProjectManager::Internal
|
||||
|
@@ -31,8 +31,6 @@ Project {
|
||||
"kithelper.h",
|
||||
"machinefilemanager.cpp",
|
||||
"machinefilemanager.h",
|
||||
"nativefilegenerator.cpp",
|
||||
"nativefilegenerator.h",
|
||||
"mesonactionsmanager.cpp",
|
||||
"mesonactionsmanager.h",
|
||||
"buildoptions.h",
|
||||
|
@@ -1,46 +0,0 @@
|
||||
// Copyright (C) 2020 Alexis Jeandet.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "nativefilegenerator.h"
|
||||
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
NativeFileGenerator::NativeFileGenerator() {}
|
||||
|
||||
inline void addEntry(QIODevice *nativeFile, const QString &key, const QString &value)
|
||||
{
|
||||
nativeFile->write(QString("%1 = '%2'\n").arg(key).arg(value).toUtf8());
|
||||
}
|
||||
|
||||
void writeBinariesSection(QIODevice *nativeFile, const KitData &kitData)
|
||||
{
|
||||
nativeFile->write("[binaries]\n");
|
||||
addEntry(nativeFile, "c", kitData.cCompilerPath);
|
||||
addEntry(nativeFile, "cpp", kitData.cxxCompilerPath);
|
||||
addEntry(nativeFile, "qmake", kitData.qmakePath);
|
||||
if (kitData.qtVersion == Utils::QtMajorVersion::Qt4)
|
||||
addEntry(nativeFile, QString{"qmake-qt4"}, kitData.qmakePath);
|
||||
else if (kitData.qtVersion == Utils::QtMajorVersion::Qt5)
|
||||
addEntry(nativeFile, QString{"qmake-qt5"}, kitData.qmakePath);
|
||||
else if (kitData.qtVersion == Utils::QtMajorVersion::Qt6)
|
||||
addEntry(nativeFile, QString{"qmake-qt6"}, kitData.qmakePath);
|
||||
addEntry(nativeFile, "cmake", kitData.cmakePath);
|
||||
}
|
||||
|
||||
void NativeFileGenerator::makeNativeFile(QIODevice *nativeFile, const KitData &kitData)
|
||||
{
|
||||
QTC_ASSERT(nativeFile, return );
|
||||
writeBinariesSection(nativeFile, kitData);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace MesonProjectManager
|
@@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2020 Alexis Jeandet.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kitdata.h"
|
||||
|
||||
#include <projectexplorer/kit.h>
|
||||
|
||||
#include <QIODevice>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class NativeFileGenerator
|
||||
{
|
||||
NativeFileGenerator();
|
||||
|
||||
public:
|
||||
static void makeNativeFile(QIODevice *nativeFile, const KitData &kitData);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace MesonProjectManager
|
Reference in New Issue
Block a user