diff --git a/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp b/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp index 38624986d8e..096eb7240b0 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp @@ -34,7 +34,7 @@ AutotoolsBuildSystem::~AutotoolsBuildSystem() = default; static void parseMakefile(QPromise &promise, const QString &makefile) { MakefileParser parser(makefile); - if (parser.parse()) + if (parser.parse(QFuture(promise.future()))) promise.addResult(parser.outputData()); else promise.future().cancel(); diff --git a/src/plugins/autotoolsprojectmanager/makefileparser.cpp b/src/plugins/autotoolsprojectmanager/makefileparser.cpp index c40f63c6886..5854667e69b 100644 --- a/src/plugins/autotoolsprojectmanager/makefileparser.cpp +++ b/src/plugins/autotoolsprojectmanager/makefileparser.cpp @@ -28,8 +28,14 @@ MakefileParser::~MakefileParser() bool MakefileParser::parse() { - m_cancel = false; + QFutureInterface fi; + fi.reportStarted(); // The default constructed future is canceled otherwise. + return parse(fi.future()); +} +bool MakefileParser::parse(const QFuture &future) +{ + m_future = future; m_success = true; m_outputData.m_executable.clear(); m_outputData.m_sources.clear(); @@ -70,16 +76,6 @@ bool MakefileParser::parse() return m_success; } -void MakefileParser::cancel() -{ - m_cancel = true; -} - -bool MakefileParser::isCanceled() const -{ - return m_cancel; -} - MakefileParser::TopTarget MakefileParser::topTarget() const { const QString line = m_line.simplified(); @@ -164,7 +160,7 @@ void MakefileParser::parseDefaultSourceExtensions() void MakefileParser::parseSubDirs() { QTC_ASSERT(m_line.contains(QLatin1String("SUBDIRS")), return); - if (isCanceled()) { + if (m_future.isCanceled()) { m_success = false; return; } @@ -222,7 +218,7 @@ void MakefileParser::parseSubDirs() MakefileParser parser(subDirMakefile); connect(&parser, &MakefileParser::status, this, &MakefileParser::status); - const bool success = parser.parse(); + const bool success = parser.parse(m_future); // Don't return, try to parse as many sub directories // as possible @@ -262,7 +258,7 @@ void MakefileParser::parseSubDirs() QStringList MakefileParser::directorySources(const QString &directory, const QStringList &extensions) { - if (isCanceled()) { + if (m_future.isCanceled()) { m_success = false; return {}; } diff --git a/src/plugins/autotoolsprojectmanager/makefileparser.h b/src/plugins/autotoolsprojectmanager/makefileparser.h index 0c432fe543d..82916d7a675 100644 --- a/src/plugins/autotoolsprojectmanager/makefileparser.h +++ b/src/plugins/autotoolsprojectmanager/makefileparser.h @@ -5,12 +5,10 @@ #include +#include +#include #include #include -#include -#include - -#include QT_BEGIN_NAMESPACE class QDir; @@ -71,22 +69,10 @@ public: * the makefile could not be opened. */ bool parse(); + bool parse(const QFuture &future); MakefileParserOutputData outputData() const { return m_outputData; } - /** - * Cancels the parsing. Calling this function only makes sense, if the - * parser runs in a different thread than the caller of this function. - * The function is thread-safe. - */ - void cancel(); - - /** - * @return True, if the parser has been cancelled by MakefileParser::cancel(). - * The function is thread-safe. - */ - bool isCanceled() const; - signals: /** * Is emitted periodically during parsing the Makefile.am files @@ -224,7 +210,7 @@ private: bool m_success = false; ///< Return value for MakefileParser::parse(). bool m_subDirsEmpty = false;///< States if last subdirs var was empty - std::atomic_bool m_cancel = false; ///< True, if the parsing should be cancelled. + QFuture m_future; ///< For periodic checking of cancelled state. QString m_makefile; ///< Filename of the makefile MakefileParserOutputData m_outputData;