From c0d67bb5c9370408ca68f21925de5ec9e89ad9cb Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 20 Nov 2014 16:20:16 +0100 Subject: fix filename handling in replaceExtraCompilerVariables() fixing and escaping is now a tri-state option: - none (this removes the need to unescape the result right afterwards in some cases) - local shell (for system()) - target shell (for Makefile) Change-Id: I5b78d9b70630fe4484dc964eff5f62793da35764 Reviewed-by: Joerg Bornemann --- qmake/generators/win32/msvc_vcproj.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'qmake/generators/win32/msvc_vcproj.cpp') diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 64252ff076..dd0fdafb49 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -893,7 +893,7 @@ void VcprojGenerator::init() extraCompilerSources[file] += quc.toQString(); } else { QString out = Option::fixPathToTargetOS(replaceExtraCompilerVariables( - compiler_out, file, QString()), false); + compiler_out, file, QString(), NoShell), false); extraCompilerSources[out] += quc.toQString(); extraCompilerOutputs[out] = QStringList(file); // Can only have one } @@ -1532,7 +1532,8 @@ void VcprojGenerator::initResourceFiles() if(!qrc_files.isEmpty()) { for (int i = 0; i < qrc_files.count(); ++i) { char buff[256]; - QString dep_cmd = replaceExtraCompilerVariables(rcc_dep_cmd, qrc_files.at(i).toQString(), ""); + QString dep_cmd = replaceExtraCompilerVariables( + rcc_dep_cmd, qrc_files.at(i).toQString(), QString(), LocalShell); dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false); if(canExecute(dep_cmd)) { @@ -1605,16 +1606,16 @@ void VcprojGenerator::initExtraCompilerOutputs() QString tmp_out = project->first(ProKey(*it + ".output")).toQString(); if (project->values(ProKey(*it + ".CONFIG")).indexOf("combine") != -1) { // Combined output, only one file result - extraCompile.addFile( - Option::fixPathToTargetOS(replaceExtraCompilerVariables(tmp_out, QString(), QString()), false)); + extraCompile.addFile(Option::fixPathToTargetOS( + replaceExtraCompilerVariables(tmp_out, QString(), QString(), NoShell), false)); } else { // One output file per input const ProStringList &tmp_in = project->values(project->first(ProKey(*it + ".input")).toKey()); for (int i = 0; i < tmp_in.count(); ++i) { const QString &filename = tmp_in.at(i).toQString(); if (extraCompilerSources.contains(filename)) - extraCompile.addFile( - Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, tmp_out, QString()), false)); + extraCompile.addFile(Option::fixPathToTargetOS( + replaceExtraCompilerVariables(filename, tmp_out, QString(), NoShell), false)); } } } else { @@ -1629,8 +1630,8 @@ void VcprojGenerator::initExtraCompilerOutputs() for (int i = 0; i < tmp_in.count(); ++i) { const QString &filename = tmp_in.at(i).toQString(); if (extraCompilerSources.contains(filename)) - extraCompile.addFile( - Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, QString(), QString()), false)); + extraCompile.addFile(Option::fixPathToTargetOS( + replaceExtraCompilerVariables(filename, QString(), QString(), NoShell), false)); } } } @@ -1650,9 +1651,10 @@ VCProjectWriter *VcprojGenerator::createProjectWriter() return new VCProjectWriter; } -QString VcprojGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out) +QString VcprojGenerator::replaceExtraCompilerVariables( + const QString &var, const QStringList &in, const QStringList &out, ReplaceFor forShell) { - QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out); + QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out, forShell); ProStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES"); if(defines.isEmpty()) -- cgit v1.2.3 From e3a7237d8214bb229997730775fd89d06b9db269 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Feb 2015 15:30:02 +0100 Subject: fix quoting issues. all of them. (*) instead of quoting more or less random variable contents early, consistently quote everything only right before it is needed. this way we can be sure that everything is correctly quoted, but not over-quoted. this removed the need for the insanity that unescapeFilePath() and similar ad-hoc contraptions were. this had the somewhat counter-intuitive effect that it was possible to remove escapeFilePath() calls from PBX::writeSettings() calls - these were actually only unescaping. [ChangeLog][qmake][Important Behavior Changes] A lot of quoting issues have been fixed. As a side effect, qmake has become more sensitive to over-quoted file names in project files. (*) ok, maybe not. close enough. Task-number: fatal: out of memory Change-Id: I8c51cfffb59ccd156b46bd5c56754c480667443a Reviewed-by: Joerg Bornemann --- qmake/generators/win32/msvc_vcproj.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'qmake/generators/win32/msvc_vcproj.cpp') diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index dd0fdafb49..5da6f5807d 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -505,7 +505,7 @@ ProStringList VcprojGenerator::collectDependencies(QMakeProject *proj, QHashfirst("QMAKE_PROJECT_NAME") + project->first("VCPROJ_EXTENSION")); + QString vcproj = tmp_vcproj.project->first("QMAKE_PROJECT_NAME") + project->first("VCPROJ_EXTENSION"); QString vcprojDir = qmake_getpwd(); // If file doesn't exsist, then maybe the users configuration @@ -535,7 +535,7 @@ ProStringList VcprojGenerator::collectDependencies(QMakeProject *proj, QHashvcprojFile = vcprojDir + Option::dir_sep + vcproj; - newDep->orig_target = unescapeFilePath(tmp_proj.first("QMAKE_ORIG_TARGET")).toQString(); + newDep->orig_target = tmp_proj.first("QMAKE_ORIG_TARGET").toQString(); newDep->target = tmp_proj.first("MSVCPROJ_TARGET").toQString().section(Option::dir_sep, -1); newDep->targetType = tmp_vcproj.projectTarget; newDep->uuid = tmp_proj.isEmpty("QMAKE_UUID") ? getProjectUUID(Option::fixPathToLocalOS(vcprojDir + QDir::separator() + vcproj)).toString().toUpper(): tmp_proj.first("QMAKE_UUID").toQString(); @@ -671,6 +671,7 @@ void VcprojGenerator::writeSubDirs(QTextStream &t) // write out projects for (QList::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) { + // ### quoting rules? t << _slnProjectBeg << _slnMSVCvcprojGUID << _slnProjectMid << "\"" << (*it)->orig_target << "\", \"" << (*it)->vcprojFile << "\", \"" << (*it)->uuid << "\""; @@ -799,9 +800,7 @@ void VcprojGenerator::init() const ProStringList &incs = project->values("INCLUDEPATH"); for (ProStringList::ConstIterator incit = incs.begin(); incit != incs.end(); ++incit) { QString inc = (*incit).toQString(); - if (!inc.startsWith('"') && !inc.endsWith('"')) - inc = QString("\"%1\"").arg(inc); // Quote all paths if not quoted already - project->values("MSVCPROJ_INCPATH").append("-I" + inc); + project->values("MSVCPROJ_INCPATH").append("-I" + escapeFilePath(inc)); } QString dest = Option::fixPathToTargetOS(project->first("TARGET").toQString()) + project->first("TARGET_EXT"); @@ -815,7 +814,7 @@ void VcprojGenerator::init() for (dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) { if (!copydll.isEmpty()) copydll += " && "; - copydll += "copy \"$(TargetPath)\" \"" + *dlldir + "\""; + copydll += "copy \"$(TargetPath)\" " + escapeFilePath(*dlldir); } QString deststr("Copy " + dest + " to "); @@ -842,8 +841,7 @@ void VcprojGenerator::init() projectTarget = Application; } else if(project->first("TEMPLATE") == "vclib") { if(project->isActiveConfig("staticlib")) { - if (!project->values("RES_FILE").isEmpty()) - project->values("QMAKE_LIBS") += escapeFilePaths(project->values("RES_FILE")); + project->values("QMAKE_LIBS") += project->values("RES_FILE"); projectTarget = StaticLib; } else projectTarget = SharedLib; @@ -856,7 +854,7 @@ void VcprojGenerator::init() if (usePCH) { precompHFilename = fileInfo(precompH).fileName(); // Created files - QString origTarget = unescapeFilePath(project->first("QMAKE_ORIG_TARGET").toQString()); + QString origTarget = project->first("QMAKE_ORIG_TARGET").toQString(); precompObj = origTarget + Option::obj_ext; precompPch = origTarget + ".pch"; // Add PRECOMPILED_HEADER to HEADERS @@ -947,7 +945,7 @@ void VcprojGenerator::initProject() initExtraCompilerOutputs(); // Own elements ----------------------------- - vcProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET").toQString()); + vcProject.Name = project->first("QMAKE_ORIG_TARGET").toQString(); switch (which_dotnet_version(project->first("MSVC_VER").toLatin1())) { case NET2013: vcProject.Version = "12.00"; @@ -1179,7 +1177,7 @@ void VcprojGenerator::initLinkerTool() ProStringList l = ProStringList(libs); conf.linker.parseOptions(l); } else { - conf.linker.AdditionalDependencies += libs.toQString(); + conf.linker.AdditionalDependencies << escapeFilePath(libs.toQString()); } } @@ -1239,7 +1237,7 @@ void VcprojGenerator::initPostBuildEventTools() !project->isHostBuild() && !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"); if (useSignature) { conf.postBuild.CommandLine.prepend( - QLatin1String("signtool sign /F ") + signature + QLatin1String(" \"$(TargetPath)\"")); + QLatin1String("signtool sign /F ") + escapeFilePath(signature) + QLatin1String(" \"$(TargetPath)\"")); conf.postBuild.ExcludedFromBuild = _False; } @@ -1682,7 +1680,7 @@ bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const ProString ext = project->first("VCPROJ_EXTENSION"); if(project->first("TEMPLATE") == "vcsubdirs") ext = project->first("VCSOLUTION_EXTENSION"); - ProString outputName = unescapeFilePath(project->first("TARGET")); + ProString outputName = project->first("TARGET"); if (!project->first("MAKEFILE").isEmpty()) outputName = project->first("MAKEFILE"); file.setFileName(outdir + outputName + ext); -- cgit v1.2.3 From e0962270d74db5950b9567d4996189f115a1c75a Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 24 Nov 2014 16:02:38 +0100 Subject: replace incorrect uses of fixPathToLocalOS() (mostly) in most cases, it actually means normalizePath() (because the file name is used with qt i/o functions afterwards). this affects QMakeLocalFile::local() as well, so many not immediately obvious places are affected as well. there was also one case of fixPathToTargetOS() falling into this category. this is mostly a no-op, as the qt functions are agnostic to the path separator. in some other cases (in particular in the vcproj generator), it actually means fixPathToTargetOS(). this is mostly a no-op as well, as the two functions are equal except on msys anyway. in the FileName() functions, the use of a fixPath*() function is bogus in the first place - fileFixify() already does fixPathToTargetOS(), and this is correct when the file name is used verbatim in a make command (which it is). otherwise it's irrelevant. Change-Id: I26712da8f888c704f8b7f42dbe24c941b6ad031d Reviewed-by: Joerg Bornemann --- qmake/generators/win32/msvc_vcproj.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'qmake/generators/win32/msvc_vcproj.cpp') diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 5da6f5807d..57557732c5 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -324,7 +324,8 @@ QUuid VcprojGenerator::getProjectUUID(const QString &filename) // If none, create one based on the MD5 of absolute project path if(uuid.isNull() || !filename.isEmpty()) { - QString abspath = Option::fixPathToLocalOS(filename.isEmpty()?project->first("QMAKE_MAKEFILE").toQString():filename); + QString abspath = Option::fixPathToTargetOS( + filename.isEmpty() ? project->first("QMAKE_MAKEFILE").toQString() : filename); QByteArray digest = QCryptographicHash::hash(abspath.toUtf8(), QCryptographicHash::Sha1); memcpy((unsigned char*)(&uuid), digest.constData(), sizeof(QUuid)); validUUID = !uuid.isNull(); @@ -457,14 +458,14 @@ ProStringList VcprojGenerator::collectDependencies(QMakeProject *proj, QHash subdir = collectedIt.next(); QString profile = subdir.first; - QFileInfo fi(fileInfo(Option::fixPathToLocalOS(profile, true))); + QFileInfo fi(fileInfo(Option::normalizePath(profile))); if (fi.exists()) { if (fi.isDir()) { if (!profile.endsWith(Option::dir_sep)) profile += Option::dir_sep; profile += fi.baseName() + Option::pro_ext; QString profileKey = fi.absoluteFilePath(); - fi = QFileInfo(fileInfo(Option::fixPathToLocalOS(profile, true))); + fi = QFileInfo(fileInfo(Option::normalizePath(profile))); if (!fi.exists()) continue; projLookup.insert(profileKey, fi.absoluteFilePath()); @@ -1344,13 +1345,13 @@ void VcprojGenerator::initDeploymentTool() || devicePath.at(0) == QLatin1Char('\\') || devicePath.at(0) == QLatin1Char('%'))) { // create output path - devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath)); + devicePath = Option::fixPathToTargetOS(targetPath + QLatin1Char('\\') + devicePath); } } // foreach d in item.files foreach (const ProString &src, project->values(ProKey(item + ".files"))) { QString itemDevicePath = devicePath; - QString source = Option::fixPathToLocalOS(src.toQString()); + QString source = Option::normalizePath(src.toQString()); QString nameFilter; QFileInfo info(source); QString searchPath; @@ -1359,7 +1360,7 @@ void VcprojGenerator::initDeploymentTool() itemDevicePath += "\\" + info.fileName(); searchPath = info.absoluteFilePath(); } else { - nameFilter = source.split('\\').last(); + nameFilter = info.fileName(); searchPath = info.absolutePath(); } @@ -1371,10 +1372,10 @@ void VcprojGenerator::initDeploymentTool() while(iterator.hasNext()) { iterator.next(); if (conf.WinRT) { - QString absoluteItemFilePath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absoluteFilePath()); + QString absoluteItemFilePath = Option::fixPathToTargetOS(QFileInfo(iterator.filePath()).absoluteFilePath()); vcProject.DeploymentFiles.addFile(absoluteItemFilePath); } else { - QString absoluteItemPath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absolutePath()); + QString absoluteItemPath = Option::fixPathToTargetOS(QFileInfo(iterator.filePath()).absolutePath()); // Identify if it is just another subdir int diffSize = absoluteItemPath.size() - pathSize; // write out rules -- cgit v1.2.3