qmake: escape colons and hashmarks in dependency paths

these characters can appear in file names, but are meta characters in
dependency context. they have different semantics in make commands, so
this required some reshuffling in the windows generator (which just
treated dependencies and commands the same way).

we don't actually escape colons for nmake, because it has magic
treatment of drive letters anyway (and colons cannot appear elsewhere).
also, if a target's filename gets quoted, batch rules will blow up.
therefore, "funny" file names are really only supported as inputs -
which is just enough to make resource embedding work.

Task-number: QTBUG-22863
Task-number: QTBUG-68635
Change-Id: I473b0bf47d045298fd2ae481a29de603a3c1be30
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Oswald Buddenhagen 2018-06-08 21:18:11 +02:00
parent 8e075dac8f
commit 7c34e0a7b4
7 changed files with 36 additions and 7 deletions

View File

@ -2823,6 +2823,19 @@ MakefileGenerator::escapeFilePaths(const ProStringList &paths) const
return ret;
}
QString
MakefileGenerator::escapeDependencyPath(const QString &path) const
{
QString ret = path;
if (!ret.isEmpty()) {
// Unix make semantics, to be inherited by unix and mingw generators.
static const QRegExp criticalChars(QStringLiteral("([\t :#])"));
ret.replace(criticalChars, QStringLiteral("\\\\1"));
debug_msg(2, "escapeDependencyPath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData());
}
return ret;
}
ProString
MakefileGenerator::escapeDependencyPath(const ProString &path) const
{

View File

@ -130,11 +130,11 @@ protected:
QMakeProject *project;
//escape
virtual QString escapeFilePath(const QString &path) const { return path; }
virtual QString escapeFilePath(const QString &path) const = 0;
ProString escapeFilePath(const ProString &path) const;
QStringList escapeFilePaths(const QStringList &paths) const;
ProStringList escapeFilePaths(const ProStringList &paths) const;
virtual QString escapeDependencyPath(const QString &path) const { return escapeFilePath(path); }
virtual QString escapeDependencyPath(const QString &path) const;
ProString escapeDependencyPath(const ProString &path) const;
QStringList escapeDependencyPaths(const QStringList &paths) const;
ProStringList escapeDependencyPaths(const ProStringList &paths) const;

View File

@ -42,6 +42,9 @@ class ProjectGenerator : public MakefileGenerator
protected:
virtual void init();
virtual bool writeMakefile(QTextStream &);
virtual QString escapeFilePath(const QString &path) const { Q_ASSERT(false); return QString(); }
public:
ProjectGenerator();
~ProjectGenerator();

View File

@ -46,8 +46,7 @@ QString MingwMakefileGenerator::escapeDependencyPath(const QString &path) const
{
QString ret = path;
ret.replace('\\', "/"); // ### this shouldn't be here
ret.replace(' ', QLatin1String("\\ "));
return ret;
return MakefileGenerator::escapeDependencyPath(ret);
}
QString MingwMakefileGenerator::getManifestFileForRcFile() const

View File

@ -39,8 +39,8 @@ public:
MingwMakefileGenerator();
~MingwMakefileGenerator();
protected:
QString escapeDependencyPath(const QString &path) const;
ProString escapeDependencyPath(const ProString &path) const { return MakefileGenerator::escapeDependencyPath(path); }
using MakefileGenerator::escapeDependencyPath;
virtual QString escapeDependencyPath(const QString &path) const;
virtual ProString fixLibFlag(const ProString &lib);
virtual QString getManifestFileForRcFile() const;
bool writeMakefile(QTextStream &);

View File

@ -773,6 +773,18 @@ QString Win32MakefileGenerator::escapeFilePath(const QString &path) const
return ret;
}
QString Win32MakefileGenerator::escapeDependencyPath(const QString &path) const
{
QString ret = path;
if (!ret.isEmpty()) {
static const QRegExp criticalChars(QStringLiteral("([\t #])"));
if (ret.contains(criticalChars))
ret = "\"" + ret + "\"";
debug_msg(2, "EscapeDependencyPath: %s -> %s", path.toLatin1().constData(), ret.toLatin1().constData());
}
return ret;
}
QString Win32MakefileGenerator::cQuoted(const QString &str)
{
QString ret = str;

View File

@ -47,8 +47,10 @@ protected:
virtual void writeObjectsPart(QTextStream &t);
virtual void writeImplicitRulesPart(QTextStream &t);
virtual void writeBuildRulesPart(QTextStream &);
using MakefileGenerator::escapeFilePath;
virtual QString escapeFilePath(const QString &path) const;
ProString escapeFilePath(const ProString &path) const { return MakefileGenerator::escapeFilePath(path); }
using MakefileGenerator::escapeDependencyPath;
virtual QString escapeDependencyPath(const QString &path) const;
virtual void writeRcFilePart(QTextStream &t);