qmake: Use more FileNames in Qmake*File

Change-Id: Id9f704d941a0f8df98bbb4e83e1ea773241a7023
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tobias Hunger
2017-02-15 12:53:30 +01:00
committed by Tim Jenssen
parent 5a223ca94e
commit bc64e91c5e
2 changed files with 64 additions and 58 deletions

View File

@@ -40,6 +40,7 @@
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <projectexplorer/nodesvisitor.h> #include <projectexplorer/nodesvisitor.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <qtsupport/profilereader.h> #include <qtsupport/profilereader.h>
@@ -197,8 +198,8 @@ class QmakeEvalInput
public: public:
QString projectDir; QString projectDir;
FileName projectFilePath; FileName projectFilePath;
QString buildDirectory; FileName buildDirectory;
QString sysroot; FileName sysroot;
QtSupport::ProFileReader *readerExact; QtSupport::ProFileReader *readerExact;
QtSupport::ProFileReader *readerCumulative; QtSupport::ProFileReader *readerCumulative;
QMakeGlobals *qmakeGlobals; QMakeGlobals *qmakeGlobals;
@@ -1338,7 +1339,7 @@ QmakeEvalInput QmakeProFile::evalInput() const
input.projectDir = directoryPath().toString(); input.projectDir = directoryPath().toString();
input.projectFilePath = filePath(); input.projectFilePath = filePath();
input.buildDirectory = buildDir(); input.buildDirectory = buildDir();
input.sysroot = m_project->qmakeSysroot(); input.sysroot = FileName::fromString(m_project->qmakeSysroot());
input.readerExact = m_readerExact; input.readerExact = m_readerExact;
input.readerCumulative = m_readerCumulative; input.readerCumulative = m_readerCumulative;
input.qmakeGlobals = m_project->qmakeGlobals(); input.qmakeGlobals = m_project->qmakeGlobals();
@@ -1381,7 +1382,7 @@ static bool evaluateOne(const QmakeEvalInput &input, ProFile *pro,
// We don't increase/decrease m_qmakeGlobalsRefCnt here, because the outer profilereaders keep m_qmakeGlobals alive anyway // We don't increase/decrease m_qmakeGlobalsRefCnt here, because the outer profilereaders keep m_qmakeGlobals alive anyway
auto bpReader = new QtSupport::ProFileReader(input.qmakeGlobals, input.qmakeVfs); // needs to access m_qmakeGlobals, m_qmakeVfs auto bpReader = new QtSupport::ProFileReader(input.qmakeGlobals, input.qmakeVfs); // needs to access m_qmakeGlobals, m_qmakeVfs
bpReader->setOutputDir(input.buildDirectory); bpReader->setOutputDir(input.buildDirectory.toString());
bpReader->setCumulative(cumulative); bpReader->setCumulative(cumulative);
bpReader->setExtraVars(basevars); bpReader->setExtraVars(basevars);
bpReader->setExtraConfigs(basecfgs); bpReader->setExtraConfigs(basecfgs);
@@ -1503,8 +1504,10 @@ QmakeEvalResult *QmakeProFile::evaluate(const QmakeEvalInput &input)
QHash<QString, QVector<ProFileEvaluator::SourceFile>> exactSourceFiles; QHash<QString, QVector<ProFileEvaluator::SourceFile>> exactSourceFiles;
QHash<QString, QVector<ProFileEvaluator::SourceFile>> cumulativeSourceFiles; QHash<QString, QVector<ProFileEvaluator::SourceFile>> cumulativeSourceFiles;
QStringList baseVPathsExact = baseVPaths(exactReader, input.projectDir, input.buildDirectory); QStringList baseVPathsExact
QStringList baseVPathsCumulative = baseVPaths(cumulativeReader, input.projectDir, input.buildDirectory); = baseVPaths(exactReader, input.projectDir, input.buildDirectory.toString());
QStringList baseVPathsCumulative
= baseVPaths(cumulativeReader, input.projectDir, input.buildDirectory.toString());
const QVector<QmakeStaticData::FileTypeData> &fileTypes = qmakeStaticData()->fileTypeData; const QVector<QmakeStaticData::FileTypeData> &fileTypes = qmakeStaticData()->fileTypeData;
for (int i = 0; i < fileTypes.size(); ++i) { for (int i = 0; i < fileTypes.size(); ++i) {
@@ -1535,12 +1538,12 @@ QmakeEvalResult *QmakeProFile::evaluate(const QmakeEvalInput &input)
// watching bogus paths. However, we accept the values even if the evaluation // watching bogus paths. However, we accept the values even if the evaluation
// failed, to at least have a best-effort result. // failed, to at least have a best-effort result.
result->installsList = installsList(exactBuildPassReader, input.projectFilePath.toString(), result->installsList = installsList(exactBuildPassReader, input.projectFilePath.toString(),
input.projectDir, input.buildDirectory); input.projectDir, input.buildDirectory.toString());
extractInstalls(proToResult, &result->includedFiles.result, result->installsList); extractInstalls(proToResult, &result->includedFiles.result, result->installsList);
if (result->state == QmakeEvalResult::EvalOk) { if (result->state == QmakeEvalResult::EvalOk) {
result->targetInformation = targetInformation(input.readerExact, exactBuildPassReader, result->targetInformation = targetInformation(input.readerExact, exactBuildPassReader,
input.buildDirectory, input.projectFilePath.toString()); input.buildDirectory, input.projectFilePath);
// update other variables // update other variables
result->newVarValues[Variable::Defines] = exactReader->values(QLatin1String("DEFINES")); result->newVarValues[Variable::Defines] = exactReader->values(QLatin1String("DEFINES"));
@@ -1562,7 +1565,7 @@ QmakeEvalResult *QmakeProFile::evaluate(const QmakeEvalInput &input)
result->newVarValues[Variable::CumulativeResource] = fileListForVar(cumulativeSourceFiles, QLatin1String("RESOURCES")); result->newVarValues[Variable::CumulativeResource] = fileListForVar(cumulativeSourceFiles, QLatin1String("RESOURCES"));
result->newVarValues[Variable::PkgConfig] = exactReader->values(QLatin1String("PKGCONFIG")); result->newVarValues[Variable::PkgConfig] = exactReader->values(QLatin1String("PKGCONFIG"));
result->newVarValues[Variable::PrecompiledHeader] = ProFileEvaluator::sourcesToFiles(exactReader->fixifiedValues( result->newVarValues[Variable::PrecompiledHeader] = ProFileEvaluator::sourcesToFiles(exactReader->fixifiedValues(
QLatin1String("PRECOMPILED_HEADER"), input.projectDir, input.buildDirectory)); QLatin1String("PRECOMPILED_HEADER"), input.projectDir, input.buildDirectory.toString()));
result->newVarValues[Variable::LibDirectories] = libDirectories(exactReader); result->newVarValues[Variable::LibDirectories] = libDirectories(exactReader);
result->newVarValues[Variable::Config] = exactReader->values(QLatin1String("CONFIG")); result->newVarValues[Variable::Config] = exactReader->values(QLatin1String("CONFIG"));
result->newVarValues[Variable::QmlImportPath] = exactReader->absolutePathValues( result->newVarValues[Variable::QmlImportPath] = exactReader->absolutePathValues(
@@ -1651,7 +1654,6 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult)
if (m_projectType == ProjectType::Invalid) if (m_projectType == ProjectType::Invalid)
return; return;
// delete files && folders && projects
makeEmpty(); makeEmpty();
m_projectType = ProjectType::Invalid; m_projectType = ProjectType::Invalid;
@@ -1679,7 +1681,7 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult)
// Add/Remove pri files, sub projects // Add/Remove pri files, sub projects
// //
QString buildDirectory = buildDir(); FileName buildDirectory = buildDir();
QList<QPair<QmakePriFile *, QmakeIncludedPriFile *>> toCompare; QList<QPair<QmakePriFile *, QmakeIncludedPriFile *>> toCompare;
@@ -1759,19 +1761,19 @@ void QmakeProFile::cleanupProFileReaders()
m_readerCumulative = nullptr; m_readerCumulative = nullptr;
} }
QString QmakeProFile::uiDirPath(QtSupport::ProFileReader *reader, const QString &buildDir) QString QmakeProFile::uiDirPath(QtSupport::ProFileReader *reader, const FileName &buildDir)
{ {
QString path = reader->value(QLatin1String("UI_DIR")); QString path = reader->value(QLatin1String("UI_DIR"));
if (QFileInfo(path).isRelative()) if (QFileInfo(path).isRelative())
path = QDir::cleanPath(buildDir + QLatin1Char('/') + path); path = QDir::cleanPath(buildDir.toString() + QLatin1Char('/') + path);
return path; return path;
} }
QString QmakeProFile::mocDirPath(QtSupport::ProFileReader *reader, const QString &buildDir) QString QmakeProFile::mocDirPath(QtSupport::ProFileReader *reader, const FileName &buildDir)
{ {
QString path = reader->value(QLatin1String("MOC_DIR")); QString path = reader->value(QLatin1String("MOC_DIR"));
if (QFileInfo(path).isRelative()) if (QFileInfo(path).isRelative())
path = QDir::cleanPath(buildDir + QLatin1Char('/') + path); path = QDir::cleanPath(buildDir.toString() + QLatin1Char('/') + path);
return path; return path;
} }
@@ -1791,8 +1793,8 @@ QString QmakeProFile::sysrootify(const QString &path, const QString &sysroot,
return !IoUtils::exists(sysrooted) ? path : sysrooted; return !IoUtils::exists(sysrooted) ? path : sysrooted;
} }
QStringList QmakeProFile::includePaths(QtSupport::ProFileReader *reader, const QString &sysroot, QStringList QmakeProFile::includePaths(QtSupport::ProFileReader *reader, const FileName &sysroot,
const QString &buildDir, const QString &projectDir) const FileName &buildDir, const QString &projectDir)
{ {
QStringList paths; QStringList paths;
foreach (const QString &cxxflags, reader->values(QLatin1String("QMAKE_CXXFLAGS"))) { foreach (const QString &cxxflags, reader->values(QLatin1String("QMAKE_CXXFLAGS"))) {
@@ -1801,8 +1803,8 @@ QStringList QmakeProFile::includePaths(QtSupport::ProFileReader *reader, const Q
} }
foreach (const ProFileEvaluator::SourceFile &el, foreach (const ProFileEvaluator::SourceFile &el,
reader->fixifiedValues(QLatin1String("INCLUDEPATH"), projectDir, buildDir)) { reader->fixifiedValues(QLatin1String("INCLUDEPATH"), projectDir, buildDir.toString())) {
paths << sysrootify(el.fileName, sysroot, projectDir, buildDir); paths << sysrootify(el.fileName, sysroot.toString(), projectDir, buildDir.toString());
} }
// paths already contains moc dir and ui dir, due to corrrectly parsing uic.prf and moc.prf // paths already contains moc dir and ui dir, due to corrrectly parsing uic.prf and moc.prf
// except if those directories don't exist at the time of parsing // except if those directories don't exist at the time of parsing
@@ -1878,7 +1880,9 @@ FileNameList QmakeProFile::subDirsPaths(QtSupport::ProFileReader *reader,
} }
TargetParserInformation QmakeProFile::targetInformation(QtSupport::ProFileReader *reader, TargetParserInformation QmakeProFile::targetInformation(QtSupport::ProFileReader *reader,
QtSupport::ProFileReader *readerBuildPass, const QString &buildDir, const QString &projectFilePath) QtSupport::ProFileReader *readerBuildPass,
const FileName &buildDir,
const FileName &projectFilePath)
{ {
TargetParserInformation result; TargetParserInformation result;
if (!reader || !readerBuildPass) if (!reader || !readerBuildPass)
@@ -1894,12 +1898,12 @@ TargetParserInformation QmakeProFile::targetInformation(QtSupport::ProFileReader
result.buildDir = buildDir; result.buildDir = buildDir;
if (readerBuildPass->contains(QLatin1String("DESTDIR"))) if (readerBuildPass->contains(QLatin1String("DESTDIR")))
result.destDir = readerBuildPass->value(QLatin1String("DESTDIR")); result.destDir = FileName::fromString(readerBuildPass->value(QLatin1String("DESTDIR")));
// Target // Target
result.target = readerBuildPass->value(QLatin1String("TARGET")); result.target = readerBuildPass->value(QLatin1String("TARGET"));
if (result.target.isEmpty()) if (result.target.isEmpty())
result.target = QFileInfo(projectFilePath).baseName(); result.target = projectFilePath.toFileInfo().baseName();
result.valid = true; result.valid = true;
@@ -1968,56 +1972,58 @@ InstallsParserList QmakeProFile::installsList() const
return m_installsList; return m_installsList;
} }
QString QmakeProFile::sourceDir() const FileName QmakeProFile::sourceDir() const
{ {
return directoryPath().toString(); return directoryPath();
} }
QString QmakeProFile::buildDir(QmakeBuildConfiguration *bc) const FileName QmakeProFile::buildDir(QmakeBuildConfiguration *bc) const
{ {
const QDir srcDirRoot = QDir(m_project->projectDirectory().toString()); const QDir srcDirRoot = QDir(m_project->projectDirectory().toString());
const QString relativeDir = srcDirRoot.relativeFilePath(directoryPath().toString()); const QString relativeDir = srcDirRoot.relativeFilePath(directoryPath().toString());
if (!bc && m_project->activeTarget()) if (!bc && m_project->activeTarget())
bc = static_cast<QmakeBuildConfiguration *>(m_project->activeTarget()->activeBuildConfiguration()); bc = static_cast<QmakeBuildConfiguration *>(m_project->activeTarget()->activeBuildConfiguration());
if (!bc) if (!bc)
return QString(); return { };
return QDir::cleanPath(QDir(bc->buildDirectory().toString()).absoluteFilePath(relativeDir)); return FileName::fromString(QDir::cleanPath(QDir(bc->buildDirectory().toString()).absoluteFilePath(relativeDir)));
} }
QStringList QmakeProFile::generatedFiles(const QString &buildDir, FileNameList QmakeProFile::generatedFiles(const Utils::FileName &buildDir,
const ProjectExplorer::FileNode *sourceFile) const const Utils::FileName &sourceFile) const
{ {
// The mechanism for finding the file names is rather crude, but as we // The mechanism for finding the file names is rather crude, but as we
// cannot parse QMAKE_EXTRA_COMPILERS and qmake has facilities to put // cannot parse QMAKE_EXTRA_COMPILERS and qmake has facilities to put
// ui_*.h files into a special directory, or even change the .h suffix, we // ui_*.h files into a special directory, or even change the .h suffix, we
// cannot help doing this here. // cannot help doing this here.
switch (sourceFile->fileType()) {
case FileType::Form: { Utils::MimeDatabase mdb;
MimeType sourceFileType = mdb.mimeTypeForFile(sourceFile.toString());
if (sourceFileType.matchesName(ProjectExplorer::Constants::FORM_MIMETYPE)) {
FileName location; FileName location;
auto it = m_varValues.constFind(Variable::UiDir); auto it = m_varValues.constFind(Variable::UiDir);
if (it != m_varValues.constEnd() && !it.value().isEmpty()) if (it != m_varValues.constEnd() && !it.value().isEmpty())
location = FileName::fromString(it.value().front()); location = FileName::fromString(it.value().front());
else else
location = FileName::fromString(buildDir); location = buildDir;
if (location.isEmpty()) if (location.isEmpty())
return QStringList(); return { };
location.appendPath(QLatin1String("ui_") location.appendPath(QLatin1String("ui_")
+ sourceFile->filePath().toFileInfo().completeBaseName() + sourceFile.toFileInfo().completeBaseName()
+ singleVariableValue(Variable::HeaderExtension)); + singleVariableValue(Variable::HeaderExtension));
return QStringList(QDir::cleanPath(location.toString())); return { Utils::FileName::fromString(QDir::cleanPath(location.toString())) };
} } else if (sourceFileType.matchesName(ProjectExplorer::Constants::SCXML_MIMETYPE)) {
case FileType::StateChart: {
if (buildDir.isEmpty()) if (buildDir.isEmpty())
return QStringList(); return { };
QString location = QDir::cleanPath(FileName::fromString(buildDir).appendPath( FileName location = buildDir;
sourceFile->filePath().toFileInfo().completeBaseName()).toString()); location.appendPath(sourceFile.toFileInfo().completeBaseName());
return QStringList({location + singleVariableValue(Variable::HeaderExtension), FileName header = location;
location + singleVariableValue(Variable::CppExtension)}); header.appendString(singleVariableValue(Variable::HeaderExtension));
} FileName cpp = location;
default: cpp.appendString(singleVariableValue(Variable::CppExtension));
// TODO: Other types will be added when adapters for their compilers become available.
return QStringList(); return { header, cpp };
} }
return { };
} }
QList<ExtraCompiler *> QmakeProFile::extraCompilers() const QList<ExtraCompiler *> QmakeProFile::extraCompilers() const
@@ -2025,7 +2031,7 @@ QList<ExtraCompiler *> QmakeProFile::extraCompilers() const
return m_extraCompilers; return m_extraCompilers;
} }
void QmakeProFile::updateGeneratedFiles(const QString &buildDir) void QmakeProFile::updateGeneratedFiles(const FileName &buildDir)
{ {
// We can do this because other plugins are not supposed to keep the compilers around. // We can do this because other plugins are not supposed to keep the compilers around.
qDeleteAll(m_extraCompilers); qDeleteAll(m_extraCompilers);

View File

@@ -229,8 +229,8 @@ class QMAKEPROJECTMANAGER_EXPORT TargetParserInformation
public: public:
bool valid = false; bool valid = false;
QString target; QString target;
QString destDir; Utils::FileName destDir;
QString buildDir; Utils::FileName buildDir;
QString buildTarget; QString buildTarget;
bool operator==(const TargetParserInformation &other) const bool operator==(const TargetParserInformation &other) const
{ {
@@ -287,11 +287,11 @@ public:
return !m_subProjectsNotToDeploy.contains(filePath); return !m_subProjectsNotToDeploy.contains(filePath);
} }
QString sourceDir() const; Utils::FileName sourceDir() const;
QString buildDir(QmakeBuildConfiguration *bc = nullptr) const; Utils::FileName buildDir(QmakeBuildConfiguration *bc = nullptr) const;
QStringList generatedFiles(const QString &buildDirectory, Utils::FileNameList generatedFiles(const Utils::FileName &buildDirectory,
const ProjectExplorer::FileNode *sourceFile) const; const Utils::FileName &sourceFile) const;
QList<ProjectExplorer::ExtraCompiler *> extraCompilers() const; QList<ProjectExplorer::ExtraCompiler *> extraCompilers() const;
QmakeProFile *findProFileFor(const Utils::FileName &string) const; QmakeProFile *findProFileFor(const Utils::FileName &string) const;
@@ -335,16 +335,16 @@ private:
using VariablesHash = QHash<Variable, QStringList>; using VariablesHash = QHash<Variable, QStringList>;
void updateGeneratedFiles(const QString &buildDir); void updateGeneratedFiles(const Utils::FileName &buildDir);
static QString uiDirPath(QtSupport::ProFileReader *reader, const QString &buildDir); static QString uiDirPath(QtSupport::ProFileReader *reader, const Utils::FileName &buildDir);
static QString mocDirPath(QtSupport::ProFileReader *reader, const QString &buildDir); static QString mocDirPath(QtSupport::ProFileReader *reader, const Utils::FileName &buildDir);
static QString sysrootify(const QString &path, const QString &sysroot, const QString &baseDir, const QString &outputDir); static QString sysrootify(const QString &path, const QString &sysroot, const QString &baseDir, const QString &outputDir);
static QStringList includePaths(QtSupport::ProFileReader *reader, const QString &sysroot, const QString &buildDir, const QString &projectDir); static QStringList includePaths(QtSupport::ProFileReader *reader, const Utils::FileName &sysroot, const Utils::FileName &buildDir, const QString &projectDir);
static QStringList libDirectories(QtSupport::ProFileReader *reader); static QStringList libDirectories(QtSupport::ProFileReader *reader);
static Utils::FileNameList subDirsPaths(QtSupport::ProFileReader *reader, const QString &projectDir, QStringList *subProjectsNotToDeploy, QStringList *errors); static Utils::FileNameList subDirsPaths(QtSupport::ProFileReader *reader, const QString &projectDir, QStringList *subProjectsNotToDeploy, QStringList *errors);
static TargetParserInformation targetInformation(QtSupport::ProFileReader *reader, QtSupport::ProFileReader *readerBuildPass, const QString &buildDir, const QString &projectFilePath); static TargetParserInformation targetInformation(QtSupport::ProFileReader *reader, QtSupport::ProFileReader *readerBuildPass, const Utils::FileName &buildDir, const Utils::FileName &projectFilePath);
static InstallsParserList installsList(const QtSupport::ProFileReader *reader, const QString &projectFilePath, const QString &projectDir, const QString &buildDir); static InstallsParserList installsList(const QtSupport::ProFileReader *reader, const QString &projectFilePath, const QString &projectDir, const QString &buildDir);
bool m_validParse = false; bool m_validParse = false;