diff options
author | hjk <hjk@qt.io> | 2019-10-25 09:55:32 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2019-11-19 11:05:52 +0000 |
commit | 27586827238ca9079860e77a7b23ae20d163143e (patch) | |
tree | 2197dc7f97a4a70524381071888336558dc0b4a3 /src/plugins/python/pythonproject.cpp | |
parent | 9073c46c9c431ec0e83987a5781163ca7b1f7ea7 (diff) | |
download | qt-creator-27586827238ca9079860e77a7b23ae20d163143e.tar.gz |
ProjectExplorer: Move BuildSystem owership to BuildConfiguration
... or Target.
This patch moves build system from conceptually "one per project"
to "one per target (i.e. per project-and-kit)" or "per
BuildConfigurations" for targets where the builds differ
significantly.
Building requires usually items from the kit (Qt version, compiler,
...) so a target-agnostic build is practically almost always wrong.
Moving the build system to the target also has the potential
to solve issues caused by switching targets while parsing, that
used Project::activeTarget() regularly, with potentially different
results before and after the switch.
This patch might create performance/size regressions when several
targets are set up per project as the build system implementation's
internal data are duplicated in this case.
The idea is to fix that by sharing per-project pieces again in
the project implementation once these problems occur.
Change-Id: I87f640ce418b93175b5029124eaa55f3b8721dca
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/python/pythonproject.cpp')
-rw-r--r-- | src/plugins/python/pythonproject.cpp | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/src/plugins/python/pythonproject.cpp b/src/plugins/python/pythonproject.cpp index 892b9f144f..357438dbb8 100644 --- a/src/plugins/python/pythonproject.cpp +++ b/src/plugins/python/pythonproject.cpp @@ -39,6 +39,7 @@ #include <QJsonObject> #include <QProcessEnvironment> #include <QRegularExpression> +#include <QTimer> #include <coreplugin/documentmanager.h> #include <coreplugin/icontext.h> @@ -57,7 +58,7 @@ namespace Internal { class PythonBuildSystem : public BuildSystem { public: - explicit PythonBuildSystem(Project *project); + explicit PythonBuildSystem(Target *target); bool supportsAction(Node *context, ProjectAction action, const Node *node) const override; bool addFiles(Node *, const QStringList &filePaths, QStringList *) override; @@ -74,11 +75,9 @@ public: bool writePyProjectFile(const QString &fileName, QString &content, const QStringList &rawList, QString *errorMessage); - void refresh(); + void triggerParsing() final; private: - PythonProject *project() const; - QStringList m_rawFileList; QStringList m_files; QHash<QString, QString> m_rawListEntries; @@ -191,12 +190,12 @@ PythonProject::PythonProject(const FilePath &fileName) setDisplayName(fileName.toFileInfo().completeBaseName()); setNeedsBuildConfigurations(false); - setBuildSystemCreator([](Project *p) { return new PythonBuildSystem(p); }); + setBuildSystemCreator([](Target *t) { return new PythonBuildSystem(t); }); } -void PythonBuildSystem::refresh() +void PythonBuildSystem::triggerParsing() { - Project::ParseGuard guard = project()->guardParsingRun(); + ParseGuard guard = guardParsingRun(); parse(); const QDir baseDir(projectDirectory().toString()); @@ -225,8 +224,7 @@ void PythonBuildSystem::refresh() } project()->setRootProjectNode(std::move(newRoot)); - if (Target *target = project()->activeTarget()) - target->setApplicationTargets(appTargets); + setApplicationTargets(appTargets); guard.markAsSuccess(); } @@ -423,27 +421,16 @@ Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *e if (res == RestoreResult::Ok) { if (!activeTarget()) addTargetForDefaultKit(); - - if (auto bs = dynamic_cast<PythonBuildSystem *>(buildSystem())) - bs->refresh(); } return res; } -bool PythonProject::setupTarget(Target *t) +PythonBuildSystem::PythonBuildSystem(Target *target) + : BuildSystem(target) { - bool res = Project::setupTarget(t); - if (auto bs = dynamic_cast<PythonBuildSystem *>(buildSystem())) - QTimer::singleShot(0, bs, &PythonBuildSystem::refresh); - return res; -} - -PythonBuildSystem::PythonBuildSystem(Project *project) - : BuildSystem(project) -{ - connect(project, &Project::projectFileIsDirty, this, [this]() { refresh(); }); - QTimer::singleShot(0, this, &PythonBuildSystem::refresh); + connect(target->project(), &Project::projectFileIsDirty, this, [this]() { triggerParsing(); }); + QTimer::singleShot(0, this, &PythonBuildSystem::triggerParsing); } bool PythonBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const @@ -460,10 +447,5 @@ bool PythonBuildSystem::supportsAction(Node *context, ProjectAction action, cons return BuildSystem::supportsAction(context, action, node); } -PythonProject *PythonBuildSystem::project() const -{ - return static_cast<PythonProject *>(BuildSystem::project()); -} - } // namespace Internal } // namespace Python |