forked from qt-creator/qt-creator
GenericProject: Use new setup for GenericProject itself
Change-Id: I8c18cd5372de1179bf6ebdcfabc6c50ac8f6d50f Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "genericprojectconstants.h"
|
#include "genericprojectconstants.h"
|
||||||
#include "genericprojectmanagertr.h"
|
#include "genericprojectmanagertr.h"
|
||||||
|
|
||||||
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -20,9 +21,11 @@
|
|||||||
#include <projectexplorer/headerpath.h>
|
#include <projectexplorer/headerpath.h>
|
||||||
#include <projectexplorer/kitaspects.h>
|
#include <projectexplorer/kitaspects.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
#include <projectexplorer/projectmanager.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
|
#include <projectexplorer/projectnodes.h>
|
||||||
|
#include <projectexplorer/projecttree.h>
|
||||||
#include <projectexplorer/projectupdater.h>
|
#include <projectexplorer/projectupdater.h>
|
||||||
|
|
||||||
#include <projectexplorer/selectablefilesmodel.h>
|
#include <projectexplorer/selectablefilesmodel.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <projectexplorer/taskhub.h>
|
#include <projectexplorer/taskhub.h>
|
||||||
@@ -51,8 +54,7 @@ using namespace Core;
|
|||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace GenericProjectManager {
|
namespace GenericProjectManager::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
enum RefreshOptions {
|
enum RefreshOptions {
|
||||||
Files = 0x01,
|
Files = 0x01,
|
||||||
@@ -60,13 +62,13 @@ enum RefreshOptions {
|
|||||||
Everything = Files | Configuration
|
Everything = Files | Configuration
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
//
|
||||||
// GenericProjectFile
|
// GenericProjectFile
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class GenericProjectFile : public Core::IDocument
|
class GenericProject;
|
||||||
|
|
||||||
|
class GenericProjectFile final : public IDocument
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GenericProjectFile(GenericProject *parent, const FilePath &fileName, RefreshOptions options)
|
GenericProjectFile(GenericProject *parent, const FilePath &fileName, RefreshOptions options)
|
||||||
@@ -82,7 +84,7 @@ public:
|
|||||||
return BehaviorSilent;
|
return BehaviorSilent;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GenericProject *m_project = nullptr;
|
GenericProject *m_project = nullptr;
|
||||||
@@ -90,13 +92,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
//
|
||||||
// GenericBuildSystem
|
// GenericBuildSystem
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class GenericBuildSystem : public BuildSystem
|
class GenericBuildSystem final : public BuildSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GenericBuildSystem(Target *target);
|
explicit GenericBuildSystem(Target *target);
|
||||||
@@ -131,7 +131,7 @@ public:
|
|||||||
SourceFiles processEntries(const QStringList &paths,
|
SourceFiles processEntries(const QStringList &paths,
|
||||||
QHash<QString, QString> *map = nullptr) const;
|
QHash<QString, QString> *map = nullptr) const;
|
||||||
|
|
||||||
Utils::FilePath findCommonSourceRoot();
|
FilePath findCommonSourceRoot();
|
||||||
void refreshCppCodeModel();
|
void refreshCppCodeModel();
|
||||||
void updateDeploymentData();
|
void updateDeploymentData();
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ private:
|
|||||||
SourceFiles m_files;
|
SourceFiles m_files;
|
||||||
QHash<QString, QString> m_rawListEntries;
|
QHash<QString, QString> m_rawListEntries;
|
||||||
QStringList m_rawProjectIncludePaths;
|
QStringList m_rawProjectIncludePaths;
|
||||||
ProjectExplorer::HeaderPaths m_projectIncludePaths;
|
HeaderPaths m_projectIncludePaths;
|
||||||
QStringList m_cxxflags;
|
QStringList m_cxxflags;
|
||||||
QStringList m_cflags;
|
QStringList m_cflags;
|
||||||
|
|
||||||
@@ -157,27 +157,39 @@ private:
|
|||||||
FileSystemWatcher m_deployFileWatcher;
|
FileSystemWatcher m_deployFileWatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
//
|
||||||
// GenericProject
|
// GenericProject
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static bool writeFile(const QString &filePath, const QString &contents)
|
static bool writeFile(const QString &filePath, const QString &contents)
|
||||||
{
|
{
|
||||||
Utils::FileSaver saver(Utils::FilePath::fromString(filePath),
|
FileSaver saver(FilePath::fromString(filePath),
|
||||||
QIODevice::Text | QIODevice::WriteOnly);
|
QIODevice::Text | QIODevice::WriteOnly);
|
||||||
return saver.write(contents.toUtf8()) && saver.finalize();
|
return saver.write(contents.toUtf8()) && saver.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericProject::GenericProject(const Utils::FilePath &fileName)
|
class GenericProject final : public Project
|
||||||
: Project(Constants::GENERICMIMETYPE, fileName)
|
|
||||||
{
|
{
|
||||||
setId(Constants::GENERICPROJECT_ID);
|
Q_OBJECT
|
||||||
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
|
||||||
setDisplayName(fileName.completeBaseName());
|
public:
|
||||||
setBuildSystemCreator([](Target *t) { return new GenericBuildSystem(t); });
|
explicit GenericProject(const FilePath &filePath)
|
||||||
}
|
: Project(Constants::GENERICMIMETYPE, filePath)
|
||||||
|
{
|
||||||
|
setId(Constants::GENERICPROJECT_ID);
|
||||||
|
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||||
|
setDisplayName(filePath.completeBaseName());
|
||||||
|
setBuildSystemCreator([](Target *t) { return new GenericBuildSystem(t); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void editFilesTriggered();
|
||||||
|
void removeFilesTriggered(const FilePaths &filesToRemove);
|
||||||
|
|
||||||
|
private:
|
||||||
|
RestoreResult fromMap(const Store &map, QString *errorMessage) final;
|
||||||
|
DeploymentKnowledge deploymentKnowledge() const final;
|
||||||
|
void configureAsExampleProject(Kit *kit) final;
|
||||||
|
};
|
||||||
|
|
||||||
GenericBuildSystem::GenericBuildSystem(Target *target)
|
GenericBuildSystem::GenericBuildSystem(Target *target)
|
||||||
: BuildSystem(target)
|
: BuildSystem(target)
|
||||||
@@ -276,7 +288,7 @@ bool GenericBuildSystem::saveRawList(const QStringList &rawList, const QString &
|
|||||||
const FilePath filePath = FilePath::fromString(fileName);
|
const FilePath filePath = FilePath::fromString(fileName);
|
||||||
FileChangeBlocker changeGuard(filePath);
|
FileChangeBlocker changeGuard(filePath);
|
||||||
// Make sure we can open the file for writing
|
// Make sure we can open the file for writing
|
||||||
Utils::FileSaver saver(filePath, QIODevice::Text);
|
FileSaver saver(filePath, QIODevice::Text);
|
||||||
if (!saver.hasError()) {
|
if (!saver.hasError()) {
|
||||||
QTextStream stream(saver.file());
|
QTextStream stream(saver.file());
|
||||||
for (const QString &filePath : rawList)
|
for (const QString &filePath : rawList)
|
||||||
@@ -404,7 +416,7 @@ void GenericBuildSystem::parse(RefreshOptions options)
|
|||||||
m_rawProjectIncludePaths = readLines(m_includesFileName);
|
m_rawProjectIncludePaths = readLines(m_includesFileName);
|
||||||
QStringList normalPaths;
|
QStringList normalPaths;
|
||||||
QStringList frameworkPaths;
|
QStringList frameworkPaths;
|
||||||
const auto baseDir = Utils::FilePath::fromString(m_includesFileName).parentDir();
|
const auto baseDir = FilePath::fromString(m_includesFileName).parentDir();
|
||||||
for (const QString &rawPath : std::as_const(m_rawProjectIncludePaths)) {
|
for (const QString &rawPath : std::as_const(m_rawProjectIncludePaths)) {
|
||||||
if (rawPath.startsWith("-F"))
|
if (rawPath.startsWith("-F"))
|
||||||
frameworkPaths << rawPath.mid(2);
|
frameworkPaths << rawPath.mid(2);
|
||||||
@@ -499,11 +511,11 @@ GenericBuildSystem::SourceFiles GenericBuildSystem::processEntries(
|
|||||||
{
|
{
|
||||||
const BuildConfiguration *const buildConfig = target()->activeBuildConfiguration();
|
const BuildConfiguration *const buildConfig = target()->activeBuildConfiguration();
|
||||||
|
|
||||||
const Utils::Environment buildEnv = buildConfig ? buildConfig->environment()
|
const Environment buildEnv = buildConfig ? buildConfig->environment()
|
||||||
: Utils::Environment::systemEnvironment();
|
: Environment::systemEnvironment();
|
||||||
|
|
||||||
const Utils::MacroExpander *expander = buildConfig ? buildConfig->macroExpander()
|
const MacroExpander *expander = buildConfig ? buildConfig->macroExpander()
|
||||||
: target()->macroExpander();
|
: target()->macroExpander();
|
||||||
|
|
||||||
const QDir projectDir(projectDirectory().toString());
|
const QDir projectDir(projectDirectory().toString());
|
||||||
|
|
||||||
@@ -518,7 +530,7 @@ GenericBuildSystem::SourceFiles GenericBuildSystem::processEntries(
|
|||||||
trimmedPath = buildEnv.expandVariables(trimmedPath);
|
trimmedPath = buildEnv.expandVariables(trimmedPath);
|
||||||
trimmedPath = expander->expand(trimmedPath);
|
trimmedPath = expander->expand(trimmedPath);
|
||||||
|
|
||||||
trimmedPath = Utils::FilePath::fromUserInput(trimmedPath).toString();
|
trimmedPath = FilePath::fromUserInput(trimmedPath).toString();
|
||||||
|
|
||||||
QStringList tagsForFile;
|
QStringList tagsForFile;
|
||||||
const int tagListPos = trimmedPath.indexOf('|');
|
const int tagListPos = trimmedPath.indexOf('|');
|
||||||
@@ -575,7 +587,7 @@ void GenericBuildSystem::refreshCppCodeModel()
|
|||||||
void GenericBuildSystem::updateDeploymentData()
|
void GenericBuildSystem::updateDeploymentData()
|
||||||
{
|
{
|
||||||
static const QString fileName("QtCreatorDeployment.txt");
|
static const QString fileName("QtCreatorDeployment.txt");
|
||||||
Utils::FilePath deploymentFilePath;
|
FilePath deploymentFilePath;
|
||||||
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
||||||
if (bc)
|
if (bc)
|
||||||
deploymentFilePath = bc->buildDirectory().pathAppended(fileName);
|
deploymentFilePath = bc->buildDirectory().pathAppended(fileName);
|
||||||
@@ -635,12 +647,12 @@ Project::RestoreResult GenericProject::fromMap(const Store &map, QString *errorM
|
|||||||
return RestoreResult::Ok;
|
return RestoreResult::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::DeploymentKnowledge GenericProject::deploymentKnowledge() const
|
DeploymentKnowledge GenericProject::deploymentKnowledge() const
|
||||||
{
|
{
|
||||||
return DeploymentKnowledge::Approximative;
|
return DeploymentKnowledge::Approximative;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericProject::configureAsExampleProject(ProjectExplorer::Kit *kit)
|
void GenericProject::configureAsExampleProject(Kit *kit)
|
||||||
{
|
{
|
||||||
QList<BuildInfo> infoList;
|
QList<BuildInfo> infoList;
|
||||||
const QList<Kit *> kits(kit != nullptr ? QList<Kit *>({kit}) : KitManager::kits());
|
const QList<Kit *> kits(kit != nullptr ? QList<Kit *>({kit}) : KitManager::kits());
|
||||||
@@ -689,5 +701,38 @@ void GenericProject::removeFilesTriggered(const FilePaths &filesToRemove)
|
|||||||
static_cast<GenericBuildSystem *>(t->buildSystem())->removeFiles(filesToRemove);
|
static_cast<GenericBuildSystem *>(t->buildSystem())->removeFiles(filesToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
void setupGenericProject(QObject *guard)
|
||||||
} // namespace GenericProjectManager
|
{
|
||||||
|
namespace PEC = ProjectExplorer::Constants;
|
||||||
|
|
||||||
|
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
|
||||||
|
|
||||||
|
ActionBuilder editAction(guard, "GenericProjectManager.EditFiles");
|
||||||
|
editAction.setContext(Constants::GENERICPROJECT_ID);
|
||||||
|
editAction.setText(Tr::tr("Edit Files..."));
|
||||||
|
editAction.setCommandAttribute(Command::CA_Hide);
|
||||||
|
editAction.setContainer(PEC::M_PROJECTCONTEXT, PEC::G_PROJECT_FILES);
|
||||||
|
editAction.setOnTriggered([] {
|
||||||
|
if (auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject()))
|
||||||
|
genericProject->editFilesTriggered();
|
||||||
|
});
|
||||||
|
|
||||||
|
ActionBuilder removeDirAction(guard, "GenericProject.RemoveDir");
|
||||||
|
removeDirAction.setContext(PEC::C_PROJECT_TREE);
|
||||||
|
removeDirAction.setText(Tr::tr("Remove Directory"));
|
||||||
|
removeDirAction.setContainer(PEC::M_FOLDERCONTEXT, PEC::G_FOLDER_OTHER);
|
||||||
|
removeDirAction.setOnTriggered([] {
|
||||||
|
const auto folderNode = ProjectTree::currentNode()->asFolderNode();
|
||||||
|
QTC_ASSERT(folderNode, return);
|
||||||
|
const auto project = qobject_cast<GenericProject *>(folderNode->getProject());
|
||||||
|
QTC_ASSERT(project, return);
|
||||||
|
const FilePaths filesToRemove = transform(
|
||||||
|
folderNode->findNodes([](const Node *node) { return node->asFileNode(); }),
|
||||||
|
[](const Node *node) { return node->filePath();});
|
||||||
|
project->removeFilesTriggered(filesToRemove);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // GenericProjectManager::Internal
|
||||||
|
|
||||||
|
#include "genericproject.moc"
|
||||||
|
|||||||
@@ -3,26 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <QObject>
|
||||||
|
|
||||||
namespace GenericProjectManager {
|
namespace GenericProjectManager::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class GenericProject : public ProjectExplorer::Project
|
void setupGenericProject(QObject *guard);
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
} // GenericProjectManager::Internal
|
||||||
explicit GenericProject(const Utils::FilePath &filename);
|
|
||||||
|
|
||||||
void editFilesTriggered();
|
|
||||||
void removeFilesTriggered(const Utils::FilePaths &filesToRemove);
|
|
||||||
|
|
||||||
private:
|
|
||||||
RestoreResult fromMap(const Utils::Store &map, QString *errorMessage) final;
|
|
||||||
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const final;
|
|
||||||
void configureAsExampleProject(ProjectExplorer::Kit *kit) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace GenericProjectManager
|
|
||||||
|
|||||||
@@ -4,30 +4,11 @@
|
|||||||
#include "genericbuildconfiguration.h"
|
#include "genericbuildconfiguration.h"
|
||||||
#include "genericmakestep.h"
|
#include "genericmakestep.h"
|
||||||
#include "genericproject.h"
|
#include "genericproject.h"
|
||||||
#include "genericprojectconstants.h"
|
|
||||||
#include "genericprojectfileseditor.h"
|
#include "genericprojectfileseditor.h"
|
||||||
#include "genericprojectmanagertr.h"
|
|
||||||
#include "genericprojectwizard.h"
|
#include "genericprojectwizard.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
#include <projectexplorer/projectmanager.h>
|
|
||||||
#include <projectexplorer/projectnodes.h>
|
|
||||||
#include <projectexplorer/projecttree.h>
|
|
||||||
#include <projectexplorer/selectablefilesmodel.h>
|
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
|
|
||||||
using namespace Core;
|
|
||||||
using namespace ProjectExplorer;
|
|
||||||
using namespace Utils;
|
|
||||||
namespace PEC = ProjectExplorer::Constants;
|
|
||||||
|
|
||||||
namespace GenericProjectManager::Internal {
|
namespace GenericProjectManager::Internal {
|
||||||
|
|
||||||
class GenericProjectPlugin final : public ExtensionSystem::IPlugin
|
class GenericProjectPlugin final : public ExtensionSystem::IPlugin
|
||||||
@@ -37,37 +18,11 @@ class GenericProjectPlugin final : public ExtensionSystem::IPlugin
|
|||||||
|
|
||||||
void initialize() final
|
void initialize() final
|
||||||
{
|
{
|
||||||
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
|
setupGenericProject(this);
|
||||||
|
|
||||||
setupGenericProjectWizard();
|
setupGenericProjectWizard();
|
||||||
setupGenericProjectFiles();
|
setupGenericProjectFiles();
|
||||||
setupGenericMakeStep();
|
setupGenericMakeStep();
|
||||||
setupGenericBuildConfiguration();
|
setupGenericBuildConfiguration();
|
||||||
|
|
||||||
ActionBuilder editAction(this, "GenericProjectManager.EditFiles");
|
|
||||||
editAction.setContext(Constants::GENERICPROJECT_ID);
|
|
||||||
editAction.setText(Tr::tr("Edit Files..."));
|
|
||||||
editAction.setCommandAttribute(Command::CA_Hide);
|
|
||||||
editAction.setContainer(PEC::M_PROJECTCONTEXT, PEC::G_PROJECT_FILES);
|
|
||||||
editAction.setOnTriggered([] {
|
|
||||||
if (auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject()))
|
|
||||||
genericProject->editFilesTriggered();
|
|
||||||
});
|
|
||||||
|
|
||||||
ActionBuilder removeDirAction(this, "GenericProject.RemoveDir");
|
|
||||||
removeDirAction.setContext(PEC::C_PROJECT_TREE);
|
|
||||||
removeDirAction.setText(Tr::tr("Remove Directory"));
|
|
||||||
removeDirAction.setContainer(PEC::M_FOLDERCONTEXT, PEC::G_FOLDER_OTHER);
|
|
||||||
removeDirAction.setOnTriggered([] {
|
|
||||||
const auto folderNode = ProjectTree::currentNode()->asFolderNode();
|
|
||||||
QTC_ASSERT(folderNode, return);
|
|
||||||
const auto project = qobject_cast<GenericProject *>(folderNode->getProject());
|
|
||||||
QTC_ASSERT(project, return);
|
|
||||||
const FilePaths filesToRemove = transform(
|
|
||||||
folderNode->findNodes([](const Node *node) { return node->asFileNode(); }),
|
|
||||||
[](const Node *node) { return node->filePath();});
|
|
||||||
project->removeFilesTriggered(filesToRemove);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user