diff options
Diffstat (limited to 'src/lib/corelib/api/jobs.cpp')
-rw-r--r-- | src/lib/corelib/api/jobs.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/lib/corelib/api/jobs.cpp b/src/lib/corelib/api/jobs.cpp index 7c30c39e2..035a0bf8f 100644 --- a/src/lib/corelib/api/jobs.cpp +++ b/src/lib/corelib/api/jobs.cpp @@ -29,7 +29,7 @@ #include "jobs.h" #include "internaljobs.h" -#include "project.h" +#include "project_p.h" #include <language/language.h> #include <tools/qbsassert.h> @@ -187,6 +187,7 @@ void AbstractJob::handleTaskProgress(int newProgressValue) void AbstractJob::handleFinished() { QBS_ASSERT(m_state != StateFinished, return); + finish(); m_state = StateFinished; unlockProject(); emit finished(!error().hasError(), this); @@ -220,13 +221,19 @@ Project SetupProjectJob::project() const return Project(job->project(), job->logger()); } -void SetupProjectJob::resolve(const SetupProjectParameters ¶meters) +void SetupProjectJob::resolve(const Project &existingProject, + const SetupProjectParameters ¶meters) { + m_existingProject = existingProject; + const TopLevelProjectPtr &existingInternalProject + = existingProject.d ? existingProject.d->internalProject : TopLevelProjectPtr(); + if (existingInternalProject && !lockProject(existingInternalProject)) + return; InternalJobThreadWrapper * const wrapper = qobject_cast<InternalJobThreadWrapper *>(internalJob()); InternalSetupProjectJob * const job = qobject_cast<InternalSetupProjectJob *>(wrapper->synchronousJob()); - job->init(parameters); + job->init(existingInternalProject, parameters); wrapper->start(); } @@ -239,6 +246,16 @@ void SetupProjectJob::reportError(const ErrorInfo &error) job->reportError(error); } +void SetupProjectJob::finish() +{ + // If the new project was successfully created, invalidate the existing one. + // The invariant is that there must always be at most one valid Project object + // for the same build directory, so that exclusive ownership of the build graph lock + // is ensured. + if (m_existingProject.isValid() && !error().hasError()) + m_existingProject.d->internalProject.clear(); +} + /*! * \class ProcessResult * \brief The \c ProcessResult class represents the result of one external program run by Qbs. |