Commit e820f577 authored by Daniel Teske's avatar Daniel Teske

ProWriter: Prepend $$PWD to files if adding to a .pri file

QMake's behavior for .pri files otherwise treats those paths as relative
to the .pro file. That's rarely what you want.

Also change the remove code to handle those files.

Change-Id: I5fe95035b470c32c365adbdee161f4a6cae05c2b
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@digia.com>
parent 47df753c
......@@ -1200,13 +1200,13 @@ void QmakePriFileNode::changeFiles(const QString &mimeType,
if (!includeFile)
return;
QDir priFileDir = QDir(m_qmakeProFileNode->m_projectDir);
if (change == AddToProFile) {
// Use the first variable for adding.
ProWriter::addFiles(includeFile, &lines, priFileDir, filePaths, varNameForAdding(mimeType));
ProWriter::addFiles(includeFile, &lines, filePaths, varNameForAdding(mimeType));
notChanged->clear();
} else { // RemoveFromProFile
QDir priFileDir = QDir(m_qmakeProFileNode->m_projectDir);
*notChanged = ProWriter::removeFiles(includeFile, &lines, priFileDir, filePaths, varNamesForRemoving());
}
......
......@@ -343,12 +343,15 @@ void ProWriter::putVarValues(ProFile *profile, QStringList *lines,
}
}
void ProWriter::addFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &values, const QString &var)
void ProWriter::addFiles(ProFile *profile, QStringList *lines, const QStringList &values, const QString &var)
{
QStringList valuesToWrite;
QString prefixPwd;
QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
if (profile->fileName().endsWith(QLatin1String(".pri")))
prefixPwd = QLatin1String("$$PWD/");
foreach (const QString &v, values)
valuesToWrite << proFileDir.relativeFilePath(v);
valuesToWrite << (prefixPwd + baseDir.relativeFilePath(v));
putVarValues(profile, lines, valuesToWrite, var, AppendValues | MultiLine | AppendOperator);
}
......@@ -508,8 +511,25 @@ QStringList ProWriter::removeFiles(ProFile *profile, QStringList *lines,
foreach (const QString &absoluteFilePath, values)
valuesToFind << proFileDir.relativeFilePath(absoluteFilePath);
QStringList notYetChanged;
foreach (int i, removeVarValues(profile, lines, valuesToFind, vars))
notYetChanged.append(values.at(i));
if (!profile->fileName().endsWith(QLatin1String(".pri")))
return notYetChanged;
// If we didn't find them with a relative path to the .pro file
// maybe those files can be found via $$PWD/relativeToPriFile
valuesToFind.clear();
QDir baseDir = QFileInfo(profile->fileName()).absoluteDir();
QString prefixPwd = QLatin1String("$$PWD/");
foreach (const QString &absoluteFilePath, notYetChanged)
valuesToFind << (prefixPwd + baseDir.relativeFilePath(absoluteFilePath));
QStringList notChanged;
foreach (int i, removeVarValues(profile, lines, valuesToFind, vars))
notChanged.append(values.at(i));
notChanged.append(notYetChanged.at(i));
return notChanged;
}
......@@ -60,8 +60,7 @@ public:
static QList<int> removeVarValues(ProFile *profile, QStringList *lines,
const QStringList &values, const QStringList &vars);
static void addFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &filePaths, const QString &var);
static void addFiles(ProFile *profile, QStringList *lines, const QStringList &filePaths, const QString &var);
static QStringList removeFiles(ProFile *profile, QStringList *lines,
const QDir &proFileDir, const QStringList &filePaths, const QStringList &vars);
......
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