forked from qt-creator/qt-creator
AutotoolsPM: Make MakefileParser cancelable
Change-Id: Iccd3c54c401433b82f567cfef281a0043af2efff Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -34,7 +34,7 @@ AutotoolsBuildSystem::~AutotoolsBuildSystem() = default;
|
||||
static void parseMakefile(QPromise<MakefileParserOutputData> &promise, const QString &makefile)
|
||||
{
|
||||
MakefileParser parser(makefile);
|
||||
if (parser.parse())
|
||||
if (parser.parse(QFuture<void>(promise.future())))
|
||||
promise.addResult(parser.outputData());
|
||||
else
|
||||
promise.future().cancel();
|
||||
|
||||
@@ -28,8 +28,14 @@ MakefileParser::~MakefileParser()
|
||||
|
||||
bool MakefileParser::parse()
|
||||
{
|
||||
m_cancel = false;
|
||||
QFutureInterface<void> fi;
|
||||
fi.reportStarted(); // The default constructed future is canceled otherwise.
|
||||
return parse(fi.future());
|
||||
}
|
||||
|
||||
bool MakefileParser::parse(const QFuture<void> &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 {};
|
||||
}
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
#include <projectexplorer/projectmacro.h>
|
||||
|
||||
#include <QFuture>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDir;
|
||||
@@ -71,22 +69,10 @@ public:
|
||||
* the makefile could not be opened.
|
||||
*/
|
||||
bool parse();
|
||||
bool parse(const QFuture<void> &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<void> m_future; ///< For periodic checking of cancelled state.
|
||||
|
||||
QString m_makefile; ///< Filename of the makefile
|
||||
MakefileParserOutputData m_outputData;
|
||||
|
||||
Reference in New Issue
Block a user