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:
Orgad Shaneh 2019-12-22 09:36:31 +02:00 committed by Orgad Shaneh
parent 96cea3b168
commit cd75446c1e
4 changed files with 31 additions and 39 deletions

View File

@ -3456,28 +3456,34 @@ ProKey MakefileGenerator::fullTargetVariable() const
return "TARGET"; 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; QString filePath = Option::output_dir + QDir::separator() + fileName;
QFile file(filePath); QFile file(filePath);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
QTextStream t(&file); return QString();
for (ProStringList::ConstIterator it = objList.constBegin(); it != objList.constEnd(); ++it) { QTextStream t(&file);
QString path = (*it).toQString(); for (ProStringList::ConstIterator it = objList.constBegin(); it != objList.constEnd(); ++it) {
// In response files, whitespace and special characters are QString path = (*it).toQString();
// escaped with a backslash; backslashes themselves can either // In response files, whitespace and special characters are
// be escaped into double backslashes, or, as this is a list of // escaped with a backslash; backslashes themselves can either
// path names, converted to forward slashes. // be escaped into double backslashes, or, as this is a list of
path.replace(QLatin1Char('\\'), QLatin1String("/")) // path names, converted to forward slashes.
.replace(QLatin1Char(' '), QLatin1String("\\ ")) path.replace(QLatin1Char('\\'), QLatin1String("/"))
.replace(QLatin1Char('\t'), QLatin1String("\\\t")) .replace(QLatin1Char(' '), QLatin1String("\\ "))
.replace(QLatin1Char('"'), QLatin1String("\\\"")) .replace(QLatin1Char('\t'), QLatin1String("\\\t"))
.replace(QLatin1Char('\''), QLatin1String("\\'")); .replace(QLatin1Char('"'), QLatin1String("\\\""))
t << path << Qt::endl; .replace(QLatin1Char('\''), QLatin1String("\\'"));
} t << path << Qt::endl;
t.flush();
file.close();
} }
t.flush();
file.close();
return fileName;
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -264,7 +264,7 @@ protected:
QStringView fixedBase, int slashOff); QStringView fixedBase, int slashOff);
bool processPrlFileCore(QString &origFile, QStringView origName, bool processPrlFileCore(QString &origFile, QStringView origName,
const QString &fixedFile); const QString &fixedFile);
void createResponseFile(const QString &fileName, const ProStringList &objList); QString createResponseFile(const QString &baseName, const ProStringList &objList);
public: public:
QMakeProject *projectFile() const; QMakeProject *projectFile() const;

View File

@ -1554,13 +1554,8 @@ std::pair<bool, QString> UnixMakefileGenerator::writeObjectsPart(QTextStream &t,
if (objMax.isEmpty() || project->values("OBJECTS").count() < objMax.toInt()) { if (objMax.isEmpty() || project->values("OBJECTS").count() < objMax.toInt()) {
objectsLinkLine = "$(OBJECTS)"; objectsLinkLine = "$(OBJECTS)";
} else { } else {
QString ld_response_file = fileVar("OBJECTS_DIR"); const QString ld_response_file = createResponseFile(
ld_response_file += var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("QMAKE_TARGET"); fileVar("OBJECTS_DIR") + var("QMAKE_LINK_OBJECT_SCRIPT"), objs);
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);
objectsLinkLine = "@" + escapeFilePath(ld_response_file); objectsLinkLine = "@" + escapeFilePath(ld_response_file);
} }
t << "OBJECTS = " << valList(escapeDependencyPaths(objs)) << Qt::endl; t << "OBJECTS = " << valList(escapeDependencyPaths(objs)) << Qt::endl;

View File

@ -231,25 +231,16 @@ void MingwMakefileGenerator::writeObjectsPart(QTextStream &t)
if (objmax.isEmpty() || project->values("OBJECTS").count() < objmax.toInt()) { if (objmax.isEmpty() || project->values("OBJECTS").count() < objmax.toInt()) {
objectsLinkLine = "$(OBJECTS)"; objectsLinkLine = "$(OBJECTS)";
} else if (project->isActiveConfig("staticlib") && project->first("TEMPLATE") == "lib") { } 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. // QMAKE_LIB is used for win32, including mingw, whereas QMAKE_AR is used on Unix.
QString ar_cmd = var("QMAKE_LIB"); QString ar_cmd = var("QMAKE_LIB");
if (ar_cmd.isEmpty()) if (ar_cmd.isEmpty())
ar_cmd = "ar -rc"; 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); objectsLinkLine = ar_cmd + ' ' + var("DEST_TARGET") + " @" + escapeFilePath(ar_response_file);
} else { } else {
QString ld_response_file = var("QMAKE_LINK_OBJECT_SCRIPT") + "." + var("TARGET"); const QString ld_response_file =
if (!var("BUILD_NAME").isEmpty()) createResponseFile(var("QMAKE_LINK_OBJECT_SCRIPT"), project->values("OBJECTS"));
ld_response_file += "." + var("BUILD_NAME");
if (!var("MAKEFILE").isEmpty())
ld_response_file += "." + var("MAKEFILE");
createResponseFile(ld_response_file, project->values("OBJECTS"));
objectsLinkLine = "@" + escapeFilePath(ld_response_file); objectsLinkLine = "@" + escapeFilePath(ld_response_file);
} }
Win32MakefileGenerator::writeObjectsPart(t); Win32MakefileGenerator::writeObjectsPart(t);