Commit 2d4cfc90 authored by Tobias Hunger's avatar Tobias Hunger

Make sure to generate qmake friendly file names

According to Ossi the only safe characters in a path for qmake are
alphanumerical, underscore, dot and dash.

Task-number: QTCREATORBUG-10980
Change-Id: Ibacbfeb7f04f1f0524093f1d8fce637ea4ae6fd6
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent b684f0af
......@@ -236,6 +236,25 @@ QString FileUtils::fileSystemFriendlyName(const QString &name)
return result;
}
int FileUtils::indexOfQmakeUnfriendly(const QString &name, int startpos)
{
static QRegExp checkRegExp(QLatin1String("[^a-zA-Z0-9_.-]"));
return checkRegExp.indexIn(name, startpos);
}
QString FileUtils::qmakeFriendlyName(const QString &name)
{
QString result = name;
// Remove characters that might trip up a build system (especially qmake):
int pos = indexOfQmakeUnfriendly(result);
while (pos >= 0) {
result[pos] = QLatin1Char('_');
pos = indexOfQmakeUnfriendly(result, pos);
}
return fileSystemFriendlyName(result);
}
bool FileUtils::makeWritable(const FileName &path)
{
const QString fileName = path.toString();
......
......@@ -97,6 +97,8 @@ public:
static FileName resolveSymlinks(const FileName &path);
static QString shortNativePath(const FileName &path);
static QString fileSystemFriendlyName(const QString &name);
static int indexOfQmakeUnfriendly(const QString &name, int startpos = 0);
static QString qmakeFriendlyName(const QString &name);
static bool makeWritable(const FileName &path);
static QString normalizePathName(const QString &name);
};
......
......@@ -30,6 +30,8 @@
#include "projectnamevalidatinglineedit.h"
#include "filenamevalidatinglineedit.h"
#include "fileutils.h"
namespace Utils {
ProjectNameValidatingLineEdit::ProjectNameValidatingLineEdit(QWidget *parent)
......@@ -43,8 +45,12 @@ bool ProjectNameValidatingLineEdit::validateProjectName(const QString &name, QSt
if (!FileNameValidatingLineEdit::validateFileName(name, false, errorMessage))
return false;
// We don't want dots in the directory name for some legacy Windows
// reason. Since we are cross-platform, we generally disallow it.
int pos = FileUtils::indexOfQmakeUnfriendly(name);
if (pos >= 0) {
if (errorMessage)
*errorMessage = tr("Invalid character '%1' found!").arg(name.at(pos));
return false;
}
if (name.contains(QLatin1Char('.'))) {
if (errorMessage)
*errorMessage = tr("Invalid character '.'.");
......
......@@ -307,14 +307,14 @@ QStringList Kit::candidateNameList(const QString &base) const
QString Kit::fileSystemFriendlyName() const
{
QString name = Utils::FileUtils::fileSystemFriendlyName(displayName());
QString name = Utils::FileUtils::qmakeFriendlyName(displayName());
foreach (Kit *i, KitManager::kits()) {
if (i == this)
continue;
if (name == Utils::FileUtils::fileSystemFriendlyName(i->displayName())) {
if (name == Utils::FileUtils::qmakeFriendlyName(i->displayName())) {
// append part of the kit id: That should be unique enough;-)
// Leading { will be turned into _ which should be fine.
name = Utils::FileUtils::fileSystemFriendlyName(name + QLatin1Char('_') + (id().toString().left(7)));
name = Utils::FileUtils::qmakeFriendlyName(name + QLatin1Char('_') + (id().toString().left(7)));
break;
}
}
......
......@@ -51,7 +51,7 @@ QmakeProjectConfigWidget::QmakeProjectConfigWidget(QmakeBuildConfiguration *bc)
m_defaultShadowBuildDir
= QmakeProject::shadowBuildDirectory(bc->target()->project()->projectFilePath(),
bc->target()->kit(),
Utils::FileUtils::fileSystemFriendlyName(bc->displayName()));
Utils::FileUtils::qmakeFriendlyName(bc->displayName()));
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment