Makefile: Deduplicate logic for response file name
+ verify that the file was actually written. Change-Id: I14a3c0b75f41f926b469109a1d7f2f80368ec9bb Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
parent
96cea3b168
commit
cd75446c1e
@ -3456,28 +3456,34 @@ ProKey MakefileGenerator::fullTargetVariable() const
|
||||
return "TARGET";
|
||||
}
|
||||
|
||||
void MakefileGenerator::createResponseFile(const QString &fileName, const ProStringList &objList)
|
||||
QString MakefileGenerator::createResponseFile(const QString &baseName, const ProStringList &objList)
|
||||
{
|
||||
QString fileName = baseName + '.' + fileVar("QMAKE_ORIG_TARGET");
|
||||
if (!var("BUILD_NAME").isEmpty())
|
||||
fileName += '.' + var("BUILD_NAME");
|
||||
if (!var("MAKEFILE").isEmpty())
|
||||
fileName += '.' + var("MAKEFILE");
|
||||
QString filePath = Option::output_dir + QDir::separator() + fileName;
|
||||
QFile file(filePath);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream t(&file);
|
||||
for (ProStringList::ConstIterator it = objList.constBegin(); it != objList.constEnd(); ++it) {
|
||||
QString path = (*it).toQString();
|
||||
// In response files, whitespace and special characters are
|
||||
// escaped with a backslash; backslashes themselves can either
|
||||
// be escaped into double backslashes, or, as this is a list of
|
||||
// path names, converted to forward slashes.
|
||||
path.replace(QLatin1Char('\\'), QLatin1String("/"))
|
||||
.replace(QLatin1Char(' '), QLatin1String("\\ "))
|
||||
.replace(QLatin1Char('\t'), QLatin1String("\\\t"))
|
||||
.replace(QLatin1Char('"'), QLatin1String("\\\""))
|
||||
.replace(QLatin1Char('\''), QLatin1String("\\'"));
|
||||
t << path << Qt::endl;
|
||||
}
|
||||
t.flush();
|
||||
file.close();
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return QString();
|
||||
QTextStream t(&file);
|
||||
for (ProStringList::ConstIterator it = objList.constBegin(); it != objList.constEnd(); ++it) {
|
||||
QString path = (*it).toQString();
|
||||
// In response files, whitespace and special characters are
|
||||
// escaped with a backslash; backslashes themselves can either
|
||||
// be escaped into double backslashes, or, as this is a list of
|
||||
// path names, converted to forward slashes.
|
||||
path.replace(QLatin1Char('\\'), QLatin1String("/"))
|
||||
.replace(QLatin1Char(' '), QLatin1String("\\ "))
|
||||
.replace(QLatin1Char('\t'), QLatin1String("\\\t"))
|
||||
.replace(QLatin1Char('"'), QLatin1String("\\\""))
|
||||
.replace(QLatin1Char('\''), QLatin1String("\\'"));
|
||||
t << path << Qt::endl;
|
||||
}
|
||||
t.flush();
|
||||
file.close();
|
||||
return fileName;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -264,7 +264,7 @@ protected:
|
||||
QStringView fixedBase, int slashOff);
|
||||
bool processPrlFileCore(QString &origFile, QStringView origName,
|
||||
const QString &fixedFile);
|
||||
void createResponseFile(const QString &fileName, const ProStringList &objList);
|
||||
QString createResponseFile(const QString &baseName, const ProStringList &objList);
|
||||
|
||||
public:
|
||||
QMakeProject *projectFile() const;
|
||||
|
@ -1554,13 +1554,8 @@ std::pair<bool, QString> UnixMakefileGenerator::writeObjectsPart(QTextStream &t,
|
||||
if (objMax.isEmpty() || project->values("OBJECTS").count() < objMax.toInt()) {
|
||||
objectsLinkLine = "$(OBJECTS)";
|
||||
} else {
|
||||
QString ld_response_file = fileVar("OBJECTS_DIR");
|
||||
ld_response_file += var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("QMAKE_TARGET");
|
||||
if (!var("BUILD_NAME").isEmpty())
|
||||
ld_response_file += "." + var("BUILD_NAME");
|
||||
if (!var("MAKEFILE").isEmpty())
|
||||
ld_response_file += "." + var("MAKEFILE");
|
||||
createResponseFile(ld_response_file, objs);
|
||||
const QString ld_response_file = createResponseFile(
|
||||
fileVar("OBJECTS_DIR") + var("QMAKE_LINK_OBJECT_SCRIPT"), objs);
|
||||
objectsLinkLine = "@" + escapeFilePath(ld_response_file);
|
||||
}
|
||||
t << "OBJECTS = " << valList(escapeDependencyPaths(objs)) << Qt::endl;
|
||||
|
@ -231,25 +231,16 @@ void MingwMakefileGenerator::writeObjectsPart(QTextStream &t)
|
||||
if (objmax.isEmpty() || project->values("OBJECTS").count() < objmax.toInt()) {
|
||||
objectsLinkLine = "$(OBJECTS)";
|
||||
} else if (project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") {
|
||||
QString ar_response_file = var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("TARGET");
|
||||
if (!var("BUILD_NAME").isEmpty()) {
|
||||
ar_response_file += "." + var("BUILD_NAME");
|
||||
}
|
||||
if (!var("MAKEFILE").isEmpty())
|
||||
ar_response_file += "." + var("MAKEFILE");
|
||||
// QMAKE_LIB is used for win32, including mingw, whereas QMAKE_AR is used on Unix.
|
||||
QString ar_cmd = var("QMAKE_LIB");
|
||||
if (ar_cmd.isEmpty())
|
||||
ar_cmd = "ar -rc";
|
||||
createResponseFile(ar_response_file, project->values("OBJECTS"));
|
||||
const QString ar_response_file =
|
||||
createResponseFile(var("QMAKE_LINK_OBJECT_SCRIPT"), project->values("OBJECTS"));
|
||||
objectsLinkLine = ar_cmd + ' ' + var("DEST_TARGET") + " @" + escapeFilePath(ar_response_file);
|
||||
} else {
|
||||
QString ld_response_file = var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("TARGET");
|
||||
if (!var("BUILD_NAME").isEmpty())
|
||||
ld_response_file += "." + var("BUILD_NAME");
|
||||
if (!var("MAKEFILE").isEmpty())
|
||||
ld_response_file += "." + var("MAKEFILE");
|
||||
createResponseFile(ld_response_file, project->values("OBJECTS"));
|
||||
const QString ld_response_file =
|
||||
createResponseFile(var("QMAKE_LINK_OBJECT_SCRIPT"), project->values("OBJECTS"));
|
||||
objectsLinkLine = "@" + escapeFilePath(ld_response_file);
|
||||
}
|
||||
Win32MakefileGenerator::writeObjectsPart(t);
|
||||
|
Loading…
x
Reference in New Issue
Block a user