qmake: get rid of (some) makefile expansions in dependency paths

the variables are quoted correctly for commands, which is incompatible
with quoting for dependencies under mingw. so insert the paths as
literals, where we can control quoting.

this fixes building in directories with spaces, which i broke in
7c34e0a7b by using different quoting styles for deps and commands in the
first place.

this breaks the hypothetical use case where somebody wants to override
TARGET or DESTDIR (or DESTDIR_TARGET under windows) on the *make*
command line. not sure why anyone would do that - just do it at the
*qmake* level.

we did not get rid of OBJECTS, because that would cause significant
duplication in the makefile (not that it would matter too much, given
the dependency lists ...). this isn't a problem, because these are
short relative paths which are not expected to contain "funny"
characters.

an alternative would have been to change the variables' quoting and
eliminate them from the commands instead, but that would be
backwards-incompatible, because commands are "user-servicable".
for the same reason, we cannot get rid of the variables entirely.

Change-Id: Ic7592c7fc67d8b7d2b64de80808365cd1c3f79d0
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Oswald Buddenhagen 2018-07-10 21:04:48 +02:00
parent 7a33f49e15
commit 6b4f2f7556
4 changed files with 20 additions and 18 deletions

View File

@ -280,11 +280,11 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
if (destd.endsWith('\\')) if (destd.endsWith('\\'))
destd += '\\'; destd += '\\';
t << "DESTDIR = " << destd << endl; t << "DESTDIR = " << destd << endl;
t << "TARGET = " << fileVar("TARGET") << endl; // ### mixed use! t << "TARGET = " << fileVar("TARGET") << endl;
if(project->isActiveConfig("plugin")) { if(project->isActiveConfig("plugin")) {
t << "TARGETD = " << fileVar("TARGET") << endl; t << "TARGETD = " << fileVar("TARGET") << endl;
} else if(!project->isActiveConfig("staticlib") && project->values("QMAKE_APP_FLAG").isEmpty()) { } else if(!project->isActiveConfig("staticlib") && project->values("QMAKE_APP_FLAG").isEmpty()) {
t << "TARGETA = " << fileVar("TARGETA") << endl; // ### mixed use! t << "TARGETA = " << fileVar("TARGETA") << endl;
if(!project->isEmpty("QMAKE_BUNDLE")) { if(!project->isEmpty("QMAKE_BUNDLE")) {
t << "TARGETD = " << fileVar("TARGET_x.y") << endl; t << "TARGETD = " << fileVar("TARGET_x.y") << endl;
t << "TARGET0 = " << fileVar("TARGET_") << endl; t << "TARGET0 = " << fileVar("TARGET_") << endl;
@ -502,7 +502,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
t << "\n\t" << var("QMAKE_POST_LINK"); t << "\n\t" << var("QMAKE_POST_LINK");
t << endl << endl; t << endl << endl;
} else { } else {
t << "$(TARGET): " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) " t << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) "
<< target_deps << ' ' << depVar("POST_TARGETDEPS") << "\n\t"; << target_deps << ' ' << depVar("POST_TARGETDEPS") << "\n\t";
if (project->first("TEMPLATE") != "aux") { if (project->first("TEMPLATE") != "aux") {
if (!destdir.isEmpty()) if (!destdir.isEmpty())
@ -515,7 +515,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
} }
t << endl << endl; t << endl << endl;
} }
allDeps = " $(TARGET)"; allDeps = ' ' + depVar("TARGET");
} else if(!project->isActiveConfig("staticlib")) { } else if(!project->isActiveConfig("staticlib")) {
QString destdir_r = project->first("DESTDIR").toQString(), incr_deps; QString destdir_r = project->first("DESTDIR").toQString(), incr_deps;
if(!project->isEmpty("QMAKE_BUNDLE")) { if(!project->isEmpty("QMAKE_BUNDLE")) {
@ -580,14 +580,14 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
} }
//real target //real target
t << destdir_d << "$(TARGET): " << depVar("PRE_TARGETDEPS") << ' ' t << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS") << ' '
<< incr_deps << " $(SUBLIBS) " << target_deps << ' ' << depVar("POST_TARGETDEPS"); << incr_deps << " $(SUBLIBS) " << target_deps << ' ' << depVar("POST_TARGETDEPS");
} else { } else {
t << destdir_d << "$(TARGET): " << depVar("PRE_TARGETDEPS") t << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS")
<< " $(OBJECTS) $(SUBLIBS) $(OBJCOMP) " << target_deps << " $(OBJECTS) $(SUBLIBS) $(OBJCOMP) " << target_deps
<< ' ' << depVar("POST_TARGETDEPS"); << ' ' << depVar("POST_TARGETDEPS");
} }
allDeps = ' ' + destdir_d + "$(TARGET)"; allDeps = ' ' + destdir_d + depVar("TARGET");
if(!destdir.isEmpty()) if(!destdir.isEmpty())
t << "\n\t" << mkdir_p_asstring(destdir, false); t << "\n\t" << mkdir_p_asstring(destdir, false);
if(!project->isEmpty("QMAKE_PRE_LINK")) if(!project->isEmpty("QMAKE_PRE_LINK"))
@ -604,7 +604,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
t << "\n\t" << var("QMAKE_POST_LINK"); t << "\n\t" << var("QMAKE_POST_LINK");
t << endl << endl; t << endl << endl;
} else if(!project->isEmpty("QMAKE_BUNDLE")) { } else if(!project->isEmpty("QMAKE_BUNDLE")) {
bundledFiles << destdir_r + "$(TARGET)"; bundledFiles << destdir_r + var("TARGET");
t << "\n\t" t << "\n\t"
<< "-$(DEL_FILE) $(TARGET) $(TARGET0) $(DESTDIR)$(TARGET0)\n\t" << "-$(DEL_FILE) $(TARGET) $(TARGET0) $(DESTDIR)$(TARGET0)\n\t"
<< var("QMAKE_LINK_SHLIB_CMD") << "\n\t" << var("QMAKE_LINK_SHLIB_CMD") << "\n\t"
@ -669,8 +669,8 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
t << endl << endl; t << endl << endl;
if (! project->isActiveConfig("plugin")) { if (! project->isActiveConfig("plugin")) {
t << "staticlib: $(TARGETA)\n\n"; t << "staticlib: " << depVar("TARGETA") << "\n\n";
t << "$(TARGETA): " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) $(OBJCOMP)"; t << depVar("TARGETA") << ": " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) $(OBJCOMP)";
if(do_incremental) if(do_incremental)
t << " $(INCREMENTAL_OBJECTS)"; t << " $(INCREMENTAL_OBJECTS)";
t << ' ' << depVar("POST_TARGETDEPS") << "\n\t"; t << ' ' << depVar("POST_TARGETDEPS") << "\n\t";
@ -690,11 +690,11 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
QString destdir_r = project->first("DESTDIR").toQString(); QString destdir_r = project->first("DESTDIR").toQString();
QString destdir_d = escapeDependencyPath(destdir_r); QString destdir_d = escapeDependencyPath(destdir_r);
QString destdir = escapeFilePath(destdir_r); QString destdir = escapeFilePath(destdir_r);
allDeps = ' ' + destdir_d + "$(TARGET)" allDeps = ' ' + destdir_d + depVar("TARGET")
+ varGlue("QMAKE_AR_SUBLIBS", ' ' + destdir_d, ' ' + destdir_d, ""); + varGlue("QMAKE_AR_SUBLIBS", ' ' + destdir_d, ' ' + destdir_d, "");
t << "staticlib: " << destdir_d << "$(TARGET)\n\n"; t << "staticlib: " << destdir_d << "$(TARGET)\n\n";
if(project->isEmpty("QMAKE_AR_SUBLIBS")) { if(project->isEmpty("QMAKE_AR_SUBLIBS")) {
t << destdir_d << "$(TARGET): " << depVar("PRE_TARGETDEPS") t << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS")
<< " $(OBJECTS) $(OBJCOMP) " << depVar("POST_TARGETDEPS") << "\n\t"; << " $(OBJECTS) $(OBJCOMP) " << depVar("POST_TARGETDEPS") << "\n\t";
if(!destdir.isEmpty()) if(!destdir.isEmpty())
t << mkdir_p_asstring(destdir, false) << "\n\t"; t << mkdir_p_asstring(destdir, false) << "\n\t";
@ -719,7 +719,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t)
QString ar; QString ar;
ProString lib = destdir + escapeFilePath(*libit); ProString lib = destdir + escapeFilePath(*libit);
if((*libit) == "$(TARGET)") { if((*libit) == "$(TARGET)") {
t << destdir_d << "$(TARGET): " << depVar("PRE_TARGETDEPS") t << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS")
<< ' ' << depVar("POST_TARGETDEPS") << valList(escapeDependencyPaths(build)) << "\n\t"; << ' ' << depVar("POST_TARGETDEPS") << valList(escapeDependencyPaths(build)) << "\n\t";
ar = project->first("QMAKE_AR_CMD").toQString(); ar = project->first("QMAKE_AR_CMD").toQString();
ar.replace(QLatin1String("$(OBJECTS)"), escapeFilePaths(build).join(' ')); ar.replace(QLatin1String("$(OBJECTS)"), escapeFilePaths(build).join(' '));

View File

@ -325,8 +325,9 @@ void MingwMakefileGenerator::writeBuildRulesPart(QTextStream &t)
{ {
t << "first: all\n"; t << "first: all\n";
t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName())) t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName()))
<< ' ' << depVar("ALL_DEPS") << " $(DESTDIR_TARGET)\n\n"; << ' ' << depVar("ALL_DEPS") << ' ' << depVar("DEST_TARGET") << "\n\n";
t << "$(DESTDIR_TARGET): " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) " << depVar("POST_TARGETDEPS"); t << depVar("DEST_TARGET") << ": "
<< depVar("PRE_TARGETDEPS") << " $(OBJECTS) " << depVar("POST_TARGETDEPS");
if (project->first("TEMPLATE") == "aux") { if (project->first("TEMPLATE") == "aux") {
t << "\n\n"; t << "\n\n";
return; return;

View File

@ -584,8 +584,9 @@ void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t)
t << "first: all\n"; t << "first: all\n";
t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName())) t << "all: " << escapeDependencyPath(fileFixify(Option::output.fileName()))
<< ' ' << depVar("ALL_DEPS") << " $(DESTDIR_TARGET)\n\n"; << ' ' << depVar("ALL_DEPS") << ' ' << depVar("DEST_TARGET") << "\n\n";
t << "$(DESTDIR_TARGET): " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) " << depVar("POST_TARGETDEPS"); t << depVar("DEST_TARGET") << ": "
<< depVar("PRE_TARGETDEPS") << " $(OBJECTS) " << depVar("POST_TARGETDEPS");
if (templateName == "aux") { if (templateName == "aux") {
t << "\n\n"; t << "\n\n";
return; return;

View File

@ -580,7 +580,7 @@ void Win32MakefileGenerator::writeStandardParts(QTextStream &t)
t << "DIST = " << fileVarList("DISTFILES") << ' ' t << "DIST = " << fileVarList("DISTFILES") << ' '
<< fileVarList("HEADERS") << ' ' << fileVarList("SOURCES") << endl; << fileVarList("HEADERS") << ' ' << fileVarList("SOURCES") << endl;
t << "QMAKE_TARGET = " << fileVar("QMAKE_ORIG_TARGET") << endl; t << "QMAKE_TARGET = " << fileVar("QMAKE_ORIG_TARGET") << endl; // unused
// The comment is important to maintain variable compatibility with Unix // The comment is important to maintain variable compatibility with Unix
// Makefiles, while not interpreting a trailing-slash as a linebreak // Makefiles, while not interpreting a trailing-slash as a linebreak
t << "DESTDIR = " << escapeFilePath(destDir) << " #avoid trailing-slash linebreak\n"; t << "DESTDIR = " << escapeFilePath(destDir) << " #avoid trailing-slash linebreak\n";