From cd75446c1e6e9ce17f9bb536af97775ad62aef1a Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 22 Dec 2019 09:36:31 +0200 Subject: Makefile: Deduplicate logic for response file name + verify that the file was actually written. Change-Id: I14a3c0b75f41f926b469109a1d7f2f80368ec9bb Reviewed-by: Joerg Bornemann --- qmake/generators/makefile.cpp | 44 ++++++++++++++++++++--------------- qmake/generators/makefile.h | 2 +- qmake/generators/unix/unixmake2.cpp | 9 ++----- qmake/generators/win32/mingw_make.cpp | 17 ++++---------- 4 files changed, 32 insertions(+), 40 deletions(-) (limited to 'qmake/generators') diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index c64ed284c1..f6f4edef9d 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -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 diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index 131da4943f..2fd7df1e6a 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -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; diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp index e907114ac0..48352c0c47 100644 --- a/qmake/generators/unix/unixmake2.cpp +++ b/qmake/generators/unix/unixmake2.cpp @@ -1554,13 +1554,8 @@ std::pair 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; diff --git a/qmake/generators/win32/mingw_make.cpp b/qmake/generators/win32/mingw_make.cpp index 2ffcff9a3c..eb100764ae 100644 --- a/qmake/generators/win32/mingw_make.cpp +++ b/qmake/generators/win32/mingw_make.cpp @@ -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); -- cgit v1.2.3