diff --git a/src/plugins/qmakeprojectmanager/makefileparse.cpp b/src/plugins/qmakeprojectmanager/makefileparse.cpp index b5a6d82a1f9..de8ff427863 100644 --- a/src/plugins/qmakeprojectmanager/makefileparse.cpp +++ b/src/plugins/qmakeprojectmanager/makefileparse.cpp @@ -25,7 +25,13 @@ static QString findQMakeLine(const FilePath &makefile, const QString &key) { QFile fi(makefile.toString()); if (fi.exists() && fi.open(QFile::ReadOnly)) { + static const QString cmakeLine("# CMAKE generated file: DO NOT EDIT!"); QTextStream ts(&fi); + if (!ts.atEnd()) { + if (ts.readLine() == cmakeLine) + return {}; + ts.seek(0); + } while (!ts.atEnd()) { const QString line = ts.readLine(); if (line.startsWith(key)) @@ -48,7 +54,7 @@ void MakeFileParse::parseArgs(const QString &args, const QString &project, QList *assignments, QList *afterAssignments) { - const QRegularExpression regExp(QLatin1String("^([^\\s\\+-]*)\\s*(\\+=|=|-=|~=)(.*)$")); + static const QRegularExpression regExp(QLatin1String("^([^\\s\\+-]*)\\s*(\\+=|=|-=|~=)(.*)$")); bool after = false; bool ignoreNext = false; m_unparsedArguments = args; @@ -207,7 +213,7 @@ static FilePath findQMakeBinaryFromMakefile(const FilePath &makefile) QFile fi(makefile.toString()); if (fi.exists() && fi.open(QFile::ReadOnly)) { QTextStream ts(&fi); - const QRegularExpression r1(QLatin1String("^QMAKE\\s*=(.*)$")); + static const QRegularExpression r1(QLatin1String("^QMAKE\\s*=(.*)$")); while (!ts.atEnd()) { QString line = ts.readLine(); const QRegularExpressionMatch match = r1.match(line); @@ -228,7 +234,9 @@ static FilePath findQMakeBinaryFromMakefile(const FilePath &makefile) return {}; } -MakeFileParse::MakeFileParse(const FilePath &makefile, Mode mode) : m_mode(mode) +MakeFileParse::MakeFileParse(const FilePath &makefile, Mode mode, + std::optional projectPath) + : m_mode(mode) { qCDebug(logging()) << "Parsing makefile" << makefile; if (!makefile.exists()) { @@ -237,10 +245,6 @@ MakeFileParse::MakeFileParse(const FilePath &makefile, Mode mode) : m_mode(mode) return; } - // Qt Version! - m_qmakePath = findQMakeBinaryFromMakefile(makefile); - qCDebug(logging()) << " qmake:" << m_qmakePath; - QString project = findQMakeLine(makefile, QLatin1String("# Project:")).trimmed(); if (project.isEmpty()) { m_state = CouldNotParse; @@ -254,6 +258,14 @@ MakeFileParse::MakeFileParse(const FilePath &makefile, Mode mode) : m_mode(mode) // Src Pro file m_srcProFile = makefile.parentDir().resolvePath(project); qCDebug(logging()) << " source .pro file:" << m_srcProFile; + if (projectPath && m_srcProFile != *projectPath) { // shortcut when importing + m_state = Okay; + return; + } + + // Qt Version! + m_qmakePath = findQMakeBinaryFromMakefile(makefile); + qCDebug(logging()) << " qmake:" << m_qmakePath; QString command = findQMakeLine(makefile, QLatin1String("# Command:")).trimmed(); if (command.isEmpty()) { diff --git a/src/plugins/qmakeprojectmanager/makefileparse.h b/src/plugins/qmakeprojectmanager/makefileparse.h index 20bef6ce246..597ce717d13 100644 --- a/src/plugins/qmakeprojectmanager/makefileparse.h +++ b/src/plugins/qmakeprojectmanager/makefileparse.h @@ -7,6 +7,8 @@ #include #include +#include + namespace QmakeProjectManager { namespace Internal { @@ -21,7 +23,8 @@ class MakeFileParse { public: enum class Mode { FilterKnownConfigValues, DoNotFilterKnownConfigValues }; - MakeFileParse(const Utils::FilePath &makefile, Mode mode); + MakeFileParse(const Utils::FilePath &makefile, Mode mode, + std::optional projectFile = std::nullopt); enum MakefileState { MakefileMissing, CouldNotParse, Okay }; diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectimporter.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectimporter.cpp index 832fb1a6809..ccd78c243a2 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectimporter.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectimporter.cpp @@ -97,7 +97,7 @@ QList QmakeProjectImporter::examineDirectory(const FilePath &importPath, qCDebug(logs) << " Parsing makefile" << file; // find interesting makefiles const FilePath makefile = importPath / file; - MakeFileParse parse(makefile, MakeFileParse::Mode::FilterKnownConfigValues); + MakeFileParse parse(makefile, MakeFileParse::Mode::FilterKnownConfigValues, projectFilePath()); if (parse.makeFileState() != MakeFileParse::Okay) { qCDebug(logs) << " Parsing the makefile failed" << makefile; continue; @@ -108,7 +108,7 @@ QList QmakeProjectImporter::examineDirectory(const FilePath &importPath, } data->canonicalQmakeBinary = parse.qmakePath().canonicalPath(); - if (data->canonicalQmakeBinary.isEmpty()) { + if (!data->canonicalQmakeBinary.exists()) { qCDebug(logs) << " " << parse.qmakePath() << "doesn't exist anymore"; continue; }