summaryrefslogtreecommitdiffstats
path: root/qmake/generators
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2019-12-22 09:36:31 +0200
committerOrgad Shaneh <orgads@gmail.com>2020-07-06 13:40:45 +0000
commitcd75446c1e6e9ce17f9bb536af97775ad62aef1a (patch)
tree931942dca1a3af38d8d5ff389151ccc78b5af9ef /qmake/generators
parent96cea3b1681dd24a0ec3a53078b78f902e3211a6 (diff)
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>
Diffstat (limited to 'qmake/generators')
-rw-r--r--qmake/generators/makefile.cpp44
-rw-r--r--qmake/generators/makefile.h2
-rw-r--r--qmake/generators/unix/unixmake2.cpp9
-rw-r--r--qmake/generators/win32/mingw_make.cpp17
4 files changed, 32 insertions, 40 deletions
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<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;
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);