Qmake: Proliferate FilePath use

Change-Id: Id9bdaf127b9b45ec01a12c21dccd8955e5fd2846
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-08-12 15:04:18 +02:00
parent a09bedf1cb
commit 4ec490e77e
7 changed files with 63 additions and 66 deletions

View File

@@ -26,28 +26,26 @@
#include "makefileparse.h" #include "makefileparse.h"
#include <qtsupport/qtversionmanager.h> #include <qtsupport/qtversionmanager.h>
#include <qtsupport/baseqtversion.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QLoggingCategory>
#include <QRegularExpression> #include <QRegularExpression>
#include <QTextStream> #include <QTextStream>
#include <QLoggingCategory>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;; using namespace QtSupport;
using namespace Utils;
using QtSupport::QtVersionManager;
using QtSupport::BaseQtVersion;
namespace QmakeProjectManager { namespace QmakeProjectManager {
namespace Internal { namespace Internal {
static QString findQMakeLine(const QString &makefile, const QString &key) static QString findQMakeLine(const FilePath &makefile, const QString &key)
{ {
QFile fi(makefile); QFile fi(makefile.toString());
if (fi.exists() && fi.open(QFile::ReadOnly)) { if (fi.exists() && fi.open(QFile::ReadOnly)) {
QTextStream ts(&fi); QTextStream ts(&fi);
while (!ts.atEnd()) { while (!ts.atEnd()) {
@@ -247,9 +245,9 @@ QList<QMakeAssignment> MakeFileParse::parseAssignments(const QList<QMakeAssignme
return filteredAssignments; return filteredAssignments;
} }
static FilePath findQMakeBinaryFromMakefile(const QString &makefile) static FilePath findQMakeBinaryFromMakefile(const FilePath &makefile)
{ {
QFile fi(makefile); QFile fi(makefile.toString());
if (fi.exists() && fi.open(QFile::ReadOnly)) { if (fi.exists() && fi.open(QFile::ReadOnly)) {
QTextStream ts(&fi); QTextStream ts(&fi);
const QRegularExpression r1(QLatin1String("^QMAKE\\s*=(.*)$")); const QRegularExpression r1(QLatin1String("^QMAKE\\s*=(.*)$"));
@@ -273,10 +271,10 @@ static FilePath findQMakeBinaryFromMakefile(const QString &makefile)
return FilePath(); return FilePath();
} }
MakeFileParse::MakeFileParse(const QString &makefile, Mode mode) : m_mode(mode) MakeFileParse::MakeFileParse(const FilePath &makefile, Mode mode) : m_mode(mode)
{ {
qCDebug(logging()) << "Parsing makefile" << makefile; qCDebug(logging()) << "Parsing makefile" << makefile;
if (!QFileInfo::exists(makefile)) { if (!makefile.exists()) {
qCDebug(logging()) << "**doesn't exist"; qCDebug(logging()) << "**doesn't exist";
m_state = MakefileMissing; m_state = MakefileMissing;
return; return;
@@ -297,7 +295,7 @@ MakeFileParse::MakeFileParse(const QString &makefile, Mode mode) : m_mode(mode)
project = project.trimmed(); project = project.trimmed();
// Src Pro file // Src Pro file
m_srcProFile = QDir::cleanPath(QFileInfo(makefile).absoluteDir().filePath(project)); m_srcProFile = makefile.parentDir().resolvePath(project);
qCDebug(logging()) << " source .pro file:" << m_srcProFile; qCDebug(logging()) << " source .pro file:" << m_srcProFile;
QString command = findQMakeLine(makefile, QLatin1String("# Command:")).trimmed(); QString command = findQMakeLine(makefile, QLatin1String("# Command:")).trimmed();
@@ -318,12 +316,12 @@ MakeFileParse::MakefileState MakeFileParse::makeFileState() const
return m_state; return m_state;
} }
Utils::FilePath MakeFileParse::qmakePath() const FilePath MakeFileParse::qmakePath() const
{ {
return m_qmakePath; return m_qmakePath;
} }
QString MakeFileParse::srcProFile() const FilePath MakeFileParse::srcProFile() const
{ {
return m_srcProFile; return m_srcProFile;
} }

View File

@@ -25,9 +25,9 @@
#pragma once #pragma once
#include <utils/fileutils.h>
#include <qtsupport/baseqtversion.h>
#include <qmakeprojectmanager/qmakestep.h> #include <qmakeprojectmanager/qmakestep.h>
#include <qtsupport/baseqtversion.h>
#include <utils/filepath.h>
namespace QmakeProjectManager { namespace QmakeProjectManager {
namespace Internal { namespace Internal {
@@ -43,13 +43,13 @@ class MakeFileParse
{ {
public: public:
enum class Mode { FilterKnownConfigValues, DoNotFilterKnownConfigValues }; enum class Mode { FilterKnownConfigValues, DoNotFilterKnownConfigValues };
MakeFileParse(const QString &makefile, Mode mode); MakeFileParse(const Utils::FilePath &makefile, Mode mode);
enum MakefileState { MakefileMissing, CouldNotParse, Okay }; enum MakefileState { MakefileMissing, CouldNotParse, Okay };
MakefileState makeFileState() const; MakefileState makeFileState() const;
Utils::FilePath qmakePath() const; Utils::FilePath qmakePath() const;
QString srcProFile() const; Utils::FilePath srcProFile() const;
QMakeStepConfig config() const; QMakeStepConfig config() const;
QString unparsedArguments() const; QString unparsedArguments() const;
@@ -78,7 +78,7 @@ private:
const Mode m_mode; const Mode m_mode;
MakefileState m_state; MakefileState m_state;
Utils::FilePath m_qmakePath; Utils::FilePath m_qmakePath;
QString m_srcProFile; Utils::FilePath m_srcProFile;
QmakeBuildConfig m_qmakeBuildConfig; QmakeBuildConfig m_qmakeBuildConfig;
QMakeStepConfig m_config; QMakeStepConfig m_config;

View File

@@ -171,9 +171,9 @@ QmakeBuildConfiguration::QmakeBuildConfiguration(Target *target, Utils::Id id)
this, &QmakeBuildConfiguration::kitChanged); this, &QmakeBuildConfiguration::kitChanged);
MacroExpander *expander = macroExpander(); MacroExpander *expander = macroExpander();
expander->registerVariable("Qmake:Makefile", "Qmake makefile", [this]() -> QString { expander->registerVariable("Qmake:Makefile", "Qmake makefile", [this]() -> QString {
const QString file = makefile(); const FilePath file = makefile();
if (!file.isEmpty()) if (!file.isEmpty())
return file; return file.path();
return QLatin1String("Makefile"); return QLatin1String("Makefile");
}); });
@@ -275,13 +275,8 @@ void QmakeBuildConfiguration::updateProblemLabel()
// we only show if we actually have a qmake and makestep // we only show if we actually have a qmake and makestep
QString errorString; QString errorString;
if (qmakeStep() && makeStep()) { if (qmakeStep() && makeStep()) {
QString makefile = buildDirectory().toString() + QLatin1Char('/'); const QString makeFile = this->makefile().isEmpty() ? "Makefile" : makefile().path();
if (this->makefile().isEmpty()) switch (compareToImportFrom(buildDirectory() / makeFile, &errorString)) {
makefile.append(QLatin1String("Makefile"));
else
makefile.append(this->makefile());
switch (compareToImportFrom(makefile, &errorString)) {
case QmakeBuildConfiguration::MakefileMatches: case QmakeBuildConfiguration::MakefileMatches:
allGood = true; allGood = true;
break; break;
@@ -382,9 +377,9 @@ void QmakeBuildConfiguration::setFileNodeBuild(FileNode *node)
m_fileNodeBuild = node; m_fileNodeBuild = node;
} }
QString QmakeBuildConfiguration::makefile() const FilePath QmakeBuildConfiguration::makefile() const
{ {
return m_buildSystem->rootProFile()->singleVariableValue(Variable::Makefile); return FilePath::fromString(m_buildSystem->rootProFile()->singleVariableValue(Variable::Makefile));
} }
BaseQtVersion::QmakeBuildConfigs QmakeBuildConfiguration::qmakeBuildConfiguration() const BaseQtVersion::QmakeBuildConfigs QmakeBuildConfiguration::qmakeBuildConfiguration() const
@@ -507,7 +502,7 @@ QmakeBuildSystem *QmakeBuildConfiguration::qmakeBuildSystem() const
} }
// Returns true if both are equal. // Returns true if both are equal.
QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportFrom(const QString &makefile, QString *errorString) QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportFrom(const FilePath &makefile, QString *errorString)
{ {
const QLoggingCategory &logs = MakeFileParse::logging(); const QLoggingCategory &logs = MakeFileParse::logging();
qCDebug(logs) << "QMakeBuildConfiguration::compareToImport"; qCDebug(logs) << "QMakeBuildConfiguration::compareToImport";
@@ -537,9 +532,9 @@ QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportF
return MakefileForWrongProject; return MakefileForWrongProject;
} }
const Utils::FilePath projectPath = const FilePath projectPath =
m_subNodeBuild ? m_subNodeBuild->filePath() : qs->project()->projectFilePath(); m_subNodeBuild ? m_subNodeBuild->filePath() : qs->project()->projectFilePath();
if (parse.srcProFile() != projectPath.toString()) { if (parse.srcProFile() != projectPath) {
qCDebug(logs) << "**Different profile used to generate the Makefile:" qCDebug(logs) << "**Different profile used to generate the Makefile:"
<< parse.srcProFile() << " expected profile:" << projectPath; << parse.srcProFile() << " expected profile:" << projectPath;
if (errorString) if (errorString)
@@ -548,8 +543,8 @@ QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportF
} }
if (version->qmakeFilePath() != parse.qmakePath()) { if (version->qmakeFilePath() != parse.qmakePath()) {
qCDebug(logs) << "**Different Qt versions, buildconfiguration:" << version->qmakeFilePath().toString() qCDebug(logs) << "**Different Qt versions, buildconfiguration:" << version->qmakeFilePath()
<< " Makefile:"<< parse.qmakePath().toString(); << " Makefile:" << parse.qmakePath();
return MakefileForWrongProject; return MakefileForWrongProject;
} }
@@ -567,7 +562,7 @@ QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportF
// now compare arguments lists // now compare arguments lists
// we have to compare without the spec/platform cmd argument // we have to compare without the spec/platform cmd argument
// and compare that on its own // and compare that on its own
QString workingDirectory = QFileInfo(makefile).absolutePath(); FilePath workingDirectory = makefile.parentDir();
QStringList actualArgs; QStringList actualArgs;
QString allArgs = macroExpander()->expandProcessArgs(qs->allArguments( QString allArgs = macroExpander()->expandProcessArgs(qs->allArguments(
QtKitAspect::qtVersion(target()->kit()), QMakeStep::ArgumentFlag::Expand)); QtKitAspect::qtVersion(target()->kit()), QMakeStep::ArgumentFlag::Expand));
@@ -639,7 +634,8 @@ QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportF
} }
QString QmakeBuildConfiguration::extractSpecFromArguments(QString *args, QString QmakeBuildConfiguration::extractSpecFromArguments(QString *args,
const QString &directory, const BaseQtVersion *version, const FilePath &directory,
const BaseQtVersion *version,
QStringList *outArgs) QStringList *outArgs)
{ {
FilePath parsedSpec; FilePath parsedSpec;
@@ -684,8 +680,8 @@ QString QmakeBuildConfiguration::extractSpecFromArguments(QString *args,
// if it is the former we need to get the canonical form // if it is the former we need to get the canonical form
// for the other one we don't need to do anything // for the other one we don't need to do anything
if (parsedSpec.toFileInfo().isRelative()) { if (parsedSpec.toFileInfo().isRelative()) {
if (QFileInfo::exists(directory + QLatin1Char('/') + parsedSpec.toString())) if (QFileInfo::exists(directory.path() + QLatin1Char('/') + parsedSpec.toString()))
parsedSpec = FilePath::fromUserInput(directory + QLatin1Char('/') + parsedSpec.toString()); parsedSpec = FilePath::fromUserInput(directory.path() + QLatin1Char('/') + parsedSpec.toString());
else else
parsedSpec = FilePath::fromUserInput(baseMkspecDir.toString() + QLatin1Char('/') + parsedSpec.toString()); parsedSpec = FilePath::fromUserInput(baseMkspecDir.toString() + QLatin1Char('/') + parsedSpec.toString());
} }

View File

@@ -79,12 +79,12 @@ public:
QmakeBuildSystem *qmakeBuildSystem() const; QmakeBuildSystem *qmakeBuildSystem() const;
QString makefile() const; Utils::FilePath makefile() const;
enum MakefileState { MakefileMatches, MakefileForWrongProject, MakefileIncompatible, MakefileMissing }; enum MakefileState { MakefileMatches, MakefileForWrongProject, MakefileIncompatible, MakefileMissing };
MakefileState compareToImportFrom(const QString &makefile, QString *errorString = nullptr); MakefileState compareToImportFrom(const Utils::FilePath &makefile, QString *errorString = nullptr);
static QString extractSpecFromArguments( static QString extractSpecFromArguments(
QString *arguments, const QString &directory, const QtSupport::BaseQtVersion *version, QString *arguments, const Utils::FilePath &directory, const QtSupport::BaseQtVersion *version,
QStringList *outArgs = nullptr); QStringList *outArgs = nullptr);
QVariantMap toMap() const override; QVariantMap toMap() const override;

View File

@@ -138,10 +138,10 @@ bool QmakeMakeStep::init()
m_makeFileToCheck = workingDirectory / makefile; m_makeFileToCheck = workingDirectory / makefile;
} else { } else {
QString makefile = bc->makefile(); FilePath makefile = bc->makefile();
if (!makefile.isEmpty()) { if (!makefile.isEmpty()) {
makeCmd.addArgs({"-f", makefile}); makeCmd.addArgs({"-f", makefile.path()});
m_makeFileToCheck = workingDirectory / makefile; m_makeFileToCheck = workingDirectory / makefile.path();
} else { } else {
m_makeFileToCheck = workingDirectory / "Makefile"; m_makeFileToCheck = workingDirectory / "Makefile";
} }
@@ -257,7 +257,7 @@ QStringList QmakeMakeStep::displayArguments() const
{ {
const auto bc = static_cast<QmakeBuildConfiguration *>(buildConfiguration()); const auto bc = static_cast<QmakeBuildConfiguration *>(buildConfiguration());
if (bc && !bc->makefile().isEmpty()) if (bc && !bc->makefile().isEmpty())
return {"-f", bc->makefile()}; return {"-f", bc->makefile().path()};
return {}; return {};
} }

View File

@@ -127,19 +127,18 @@ QList<void *> QmakeProjectImporter::examineDirectory(const FilePath &importPath,
qCDebug(logs) << " Parsing makefile" << file; qCDebug(logs) << " Parsing makefile" << file;
// find interesting makefiles // find interesting makefiles
QString makefile = importPath.toString() + QLatin1Char('/') + file; const FilePath makefile = importPath / file;
MakeFileParse parse(makefile, MakeFileParse::Mode::FilterKnownConfigValues); MakeFileParse parse(makefile, MakeFileParse::Mode::FilterKnownConfigValues);
if (parse.makeFileState() != MakeFileParse::Okay) { if (parse.makeFileState() != MakeFileParse::Okay) {
qCDebug(logs) << " Parsing the makefile failed" << makefile; qCDebug(logs) << " Parsing the makefile failed" << makefile;
continue; continue;
} }
if (parse.srcProFile() != projectFilePath().toString()) { if (parse.srcProFile() != projectFilePath()) {
qCDebug(logs) << " pro files doesn't match" << parse.srcProFile() << projectFilePath(); qCDebug(logs) << " pro files doesn't match" << parse.srcProFile() << projectFilePath();
continue; continue;
} }
QFileInfo qmakeFi = parse.qmakePath().toFileInfo(); data->canonicalQmakeBinary = parse.qmakePath().canonicalPath();
data->canonicalQmakeBinary = FilePath::fromString(qmakeFi.canonicalFilePath());
if (data->canonicalQmakeBinary.isEmpty()) { if (data->canonicalQmakeBinary.isEmpty()) {
qCDebug(logs) << " " << parse.qmakePath() << "doesn't exist anymore"; qCDebug(logs) << " " << parse.qmakePath() << "doesn't exist anymore";
continue; continue;
@@ -184,7 +183,7 @@ QList<void *> QmakeProjectImporter::examineDirectory(const FilePath &importPath,
data->additionalArguments = parse.unparsedArguments(); data->additionalArguments = parse.unparsedArguments();
qCDebug(logs) << " Unparsed arguments:" << data->additionalArguments; qCDebug(logs) << " Unparsed arguments:" << data->additionalArguments;
data->parsedSpec = data->parsedSpec =
QmakeBuildConfiguration::extractSpecFromArguments(&(data->additionalArguments), importPath.toString(), version); QmakeBuildConfiguration::extractSpecFromArguments(&(data->additionalArguments), importPath, version);
qCDebug(logs) << " Extracted spec:" << data->parsedSpec; qCDebug(logs) << " Extracted spec:" << data->parsedSpec;
qCDebug(logs) << " Arguments now:" << data->additionalArguments; qCDebug(logs) << " Arguments now:" << data->additionalArguments;

View File

@@ -220,20 +220,22 @@ bool QMakeStep::init()
// The Makefile is used by qmake and make on the build device, from that // The Makefile is used by qmake and make on the build device, from that
// perspective it is local. // perspective it is local.
QString makefile = workingDirectory.path() + '/';
QString make;
if (qmakeBc->subNodeBuild()) { if (qmakeBc->subNodeBuild()) {
QmakeProFileNode *pro = qmakeBc->subNodeBuild(); QmakeProFileNode *pro = qmakeBc->subNodeBuild();
if (pro && !pro->makefile().isEmpty()) if (pro && !pro->makefile().isEmpty())
makefile.append(pro->makefile()); make = pro->makefile();
else else
makefile.append("Makefile"); make = "Makefile";
} else if (!qmakeBc->makefile().isEmpty()) { } else if (!qmakeBc->makefile().isEmpty()) {
makefile.append(qmakeBc->makefile()); make = qmakeBc->makefile().path();
} else { } else {
makefile.append("Makefile"); make = "Makefile";
} }
FilePath makeFile = workingDirectory / make;
if (m_runMakeQmake) { if (m_runMakeQmake) {
const FilePath make = makeCommand(); const FilePath make = makeCommand();
if (make.isEmpty()) { if (make.isEmpty()) {
@@ -242,14 +244,14 @@ bool QMakeStep::init()
BuildStep::OutputFormat::ErrorMessage); BuildStep::OutputFormat::ErrorMessage);
return false; return false;
} }
m_makeCommand = CommandLine{make, makeArguments(makefile), CommandLine::Raw}; m_makeCommand = CommandLine{make, makeArguments(makeFile.path()), CommandLine::Raw};
} else { } else {
m_makeCommand = {}; m_makeCommand = {};
} }
// Check whether we need to run qmake // Check whether we need to run qmake
if (m_forced || QmakeSettings::alwaysRunQmake() if (m_forced || QmakeSettings::alwaysRunQmake()
|| qmakeBc->compareToImportFrom(makefile) != QmakeBuildConfiguration::MakefileMatches) { || qmakeBc->compareToImportFrom(makeFile) != QmakeBuildConfiguration::MakefileMatches) {
m_needToRunQMake = true; m_needToRunQMake = true;
} }
m_forced = false; m_forced = false;
@@ -433,20 +435,22 @@ QString QMakeStep::makeArguments(const QString &makefile) const
QString QMakeStep::effectiveQMakeCall() const QString QMakeStep::effectiveQMakeCall() const
{ {
BaseQtVersion *qtVersion = QtKitAspect::qtVersion(kit()); BaseQtVersion *qtVersion = QtKitAspect::qtVersion(kit());
QString qmake = qtVersion ? qtVersion->qmakeFilePath().toUserOutput() : QString(); FilePath qmake = qtVersion ? qtVersion->qmakeFilePath() : FilePath();
if (qmake.isEmpty()) if (qmake.isEmpty())
qmake = tr("<no Qt version>"); qmake = FilePath::fromString(tr("<no Qt version>"));
QString make = makeCommand().toUserOutput(); FilePath make = makeCommand();
if (make.isEmpty()) if (make.isEmpty())
make = tr("<no Make step found>"); make = FilePath::fromString(tr("<no Make step found>"));
QString result = qmake; CommandLine cmd(qmake, {});
QString result = qmake.toString();
if (qtVersion) { if (qtVersion) {
QmakeBuildConfiguration *qmakeBc = qmakeBuildConfiguration(); QmakeBuildConfiguration *qmakeBc = qmakeBuildConfiguration();
const QString makefile = qmakeBc ? qmakeBc->makefile() : QString(); const FilePath makefile = qmakeBc ? qmakeBc->makefile() : FilePath();
result += ' ' + allArguments(qtVersion, ArgumentFlag::Expand); result += ' ' + allArguments(qtVersion, ArgumentFlag::Expand);
if (qtVersion->qtVersion() >= QtVersionNumber(5, 0, 0)) if (qtVersion->qtVersion() >= QtVersionNumber(5, 0, 0))
result.append(QString::fromLatin1(" && %1 %2").arg(make).arg(makeArguments(makefile))); result.append(QString(" && %1 %2").arg(make.path()).arg(makeArguments(makefile.path())));
} }
return result; return result;
} }