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
|
mesontools.h
|
||||||
mesonwrapper.cpp
|
mesonwrapper.cpp
|
||||||
mesonwrapper.h
|
mesonwrapper.h
|
||||||
nativefilegenerator.cpp
|
|
||||||
nativefilegenerator.h
|
|
||||||
ninjabuildstep.cpp
|
ninjabuildstep.cpp
|
||||||
ninjabuildstep.h
|
ninjabuildstep.h
|
||||||
ninjaparser.cpp
|
ninjaparser.cpp
|
||||||
|
@@ -5,115 +5,110 @@
|
|||||||
|
|
||||||
#include "kitdata.h"
|
#include "kitdata.h"
|
||||||
#include "kithelper.h"
|
#include "kithelper.h"
|
||||||
#include "nativefilegenerator.h"
|
|
||||||
|
|
||||||
#include <coreplugin/icore.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 <utils/macroexpander.h>
|
||||||
#include <QFile>
|
#include <utils/qtcassert.h>
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace MesonProjectManager {
|
using namespace ProjectExplorer;
|
||||||
namespace Internal {
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace MesonProjectManager::Internal {
|
||||||
|
|
||||||
const char MACHINE_FILE_PREFIX[] = "Meson-MachineFile-";
|
const char MACHINE_FILE_PREFIX[] = "Meson-MachineFile-";
|
||||||
const char MACHINE_FILE_EXT[] = ".ini";
|
const char MACHINE_FILE_EXT[] = ".ini";
|
||||||
|
|
||||||
template<typename F>
|
static FilePath machineFilesDir()
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
return Core::ICore::userResourcePath("Meson-machine-files");
|
return Core::ICore::userResourcePath("Meson-machine-files");
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineFileManager::MachineFileManager()
|
MachineFileManager::MachineFileManager()
|
||||||
{
|
{
|
||||||
using namespace ProjectExplorer;
|
connect(KitManager::instance(), &KitManager::kitAdded,
|
||||||
connect(KitManager::instance(),
|
this, &MachineFileManager::addMachineFile);
|
||||||
&KitManager::kitAdded,
|
connect(KitManager::instance(), &KitManager::kitUpdated,
|
||||||
this,
|
this, &MachineFileManager::updateMachineFile);
|
||||||
&MachineFileManager::addMachineFile);
|
connect(KitManager::instance(), &KitManager::kitRemoved,
|
||||||
connect(KitManager::instance(),
|
this, &MachineFileManager::removeMachineFile);
|
||||||
&KitManager::kitUpdated,
|
connect(KitManager::instance(), &KitManager::kitsLoaded,
|
||||||
this,
|
this, &MachineFileManager::cleanupMachineFiles);
|
||||||
&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 {});
|
QTC_ASSERT(kit, return {});
|
||||||
auto baseName
|
auto baseName
|
||||||
= QString("%1%2%3").arg(MACHINE_FILE_PREFIX).arg(kit->id().toString()).arg(MACHINE_FILE_EXT);
|
= QString("%1%2%3").arg(MACHINE_FILE_PREFIX).arg(kit->id().toString()).arg(MACHINE_FILE_EXT);
|
||||||
baseName = baseName.remove('{').remove('}');
|
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 );
|
QTC_ASSERT(!filePath.isEmpty(), return );
|
||||||
auto data = KitHelper::kitData(kit);
|
auto kitData = KitHelper::kitData(kit);
|
||||||
QTC_ASSERT(withFile(filePath,
|
|
||||||
[&data](QFile *file) { NativeFileGenerator::makeNativeFile(file, data); }),
|
auto entry = [](const QString &key, const QString &value) {
|
||||||
return );
|
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())
|
if (filePath.exists())
|
||||||
QFile::remove(filePath.toString());
|
filePath.removeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineFileManager::updateMachineFile(const ProjectExplorer::Kit *kit)
|
void MachineFileManager::updateMachineFile(const Kit *kit)
|
||||||
{
|
{
|
||||||
addMachineFile(kit);
|
addMachineFile(kit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineFileManager::cleanupMachineFiles()
|
void MachineFileManager::cleanupMachineFiles()
|
||||||
{
|
{
|
||||||
const auto kits = ProjectExplorer::KitManager::kits();
|
FilePath dir = machineFilesDir();
|
||||||
auto machineFilesDir = QDir(MachineFilesDir().toString());
|
dir.ensureWritableDir();
|
||||||
if (!machineFilesDir.exists()) {
|
|
||||||
machineFilesDir.mkdir(machineFilesDir.path());
|
const FileFilter filter = {{QString("%1*%2").arg(MACHINE_FILE_PREFIX).arg(MACHINE_FILE_EXT)}};
|
||||||
}
|
const FilePaths machineFiles = dir.dirEntries(filter);
|
||||||
auto machineFiles = QDir(MachineFilesDir().toString())
|
|
||||||
.entryList(
|
FilePaths expected;
|
||||||
{QString("%1*%2").arg(MACHINE_FILE_PREFIX).arg(MACHINE_FILE_EXT)});
|
for (Kit const *kit : KitManager::kits()) {
|
||||||
QStringList expected;
|
const FilePath fname = machineFile(kit);
|
||||||
for (auto const *kit : kits) {
|
|
||||||
QString fname = machineFile(kit).toString();
|
|
||||||
expected.push_back(fname);
|
expected.push_back(fname);
|
||||||
if (!machineFiles.contains(fname))
|
if (!machineFiles.contains(fname))
|
||||||
addMachineFile(kit);
|
addMachineFile(kit);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &file : machineFiles) {
|
for (const FilePath &file : machineFiles) {
|
||||||
if (!expected.contains(file))
|
if (!expected.contains(file))
|
||||||
QFile::remove(file);
|
file.removeFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // MesonProjectManager::Internal
|
||||||
} // namespace MesonProjectManager
|
|
||||||
|
@@ -3,17 +3,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/kit.h>
|
#include <utils/filepath.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
namespace ProjectExplorer { class Kit; }
|
||||||
|
|
||||||
namespace MesonProjectManager {
|
namespace MesonProjectManager::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class MachineFileManager final : public QObject
|
class MachineFileManager final : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
MachineFileManager();
|
MachineFileManager();
|
||||||
|
|
||||||
@@ -26,5 +23,4 @@ private:
|
|||||||
void cleanupMachineFiles();
|
void cleanupMachineFiles();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // MesonProjectManager::Internal
|
||||||
} // namespace MesonProjectManager
|
|
||||||
|
@@ -31,8 +31,6 @@ Project {
|
|||||||
"kithelper.h",
|
"kithelper.h",
|
||||||
"machinefilemanager.cpp",
|
"machinefilemanager.cpp",
|
||||||
"machinefilemanager.h",
|
"machinefilemanager.h",
|
||||||
"nativefilegenerator.cpp",
|
|
||||||
"nativefilegenerator.h",
|
|
||||||
"mesonactionsmanager.cpp",
|
"mesonactionsmanager.cpp",
|
||||||
"mesonactionsmanager.h",
|
"mesonactionsmanager.h",
|
||||||
"buildoptions.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