From 9d7ed92f6e63cd2d1a1388874e54b37b5cfd01b7 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 2 Jan 2020 13:51:19 +0100 Subject: Fix dependency resolution for extra compilers in VS projects De-duplicate the code that calls the extra compiler's depend_command by using the central function callExtraCompilerDependCommand. This one actually tries to resolve dependencies unlike the removed code that blindly resolved relative paths to the build directory. This fixes dependencies reported by uic which need to be resolved against what is in DEPENDPATH. Fixes: QTBUG-80579 Change-Id: If482e50ff3eff716fefffee82004acc076b3a547 Reviewed-by: Kai Koehne --- qmake/generators/makefile.cpp | 5 +++- qmake/generators/makefile.h | 3 ++- qmake/generators/win32/msvc_objectmodel.cpp | 36 ++++++++--------------------- qmake/generators/win32/msvc_vcproj.h | 2 ++ 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index ed7d057a88..dcb44239a0 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -1857,10 +1857,13 @@ void MakefileGenerator::callExtraCompilerDependCommand(const ProString &extraCom const QString &tmp_out, bool dep_lines, QStringList *deps, - bool existingDepsOnly) + bool existingDepsOnly, + bool checkCommandAvailability) { char buff[256]; QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, tmp_out, LocalShell); + if (checkCommandAvailability && !canExecute(dep_cmd)) + return; dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { QByteArray depData; diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index 47e4c7531c..ab970c966f 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -87,7 +87,8 @@ protected: void callExtraCompilerDependCommand(const ProString &extraCompiler, const QString &dep_cd_cmd, const QString &tmp_dep_cmd, const QString &inpf, const QString &tmp_out, bool dep_lines, QStringList *deps, - bool existingDepsOnly); + bool existingDepsOnly, + bool checkCommandAvailability = false); void writeExtraCompilerTargets(QTextStream &t); void writeExtraCompilerVariables(QTextStream &t); bool writeDummyMakefile(QTextStream &t); diff --git a/qmake/generators/win32/msvc_objectmodel.cpp b/qmake/generators/win32/msvc_objectmodel.cpp index 5396eba72e..2b39a4baaa 100644 --- a/qmake/generators/win32/msvc_objectmodel.cpp +++ b/qmake/generators/win32/msvc_objectmodel.cpp @@ -2351,33 +2351,15 @@ bool VCFilter::addExtraCompiler(const VCFilterFile &info) if (!tmp_dep.isEmpty()) deps = tmp_dep; if (!tmp_dep_cmd.isEmpty()) { - // Execute dependency command, and add every line as a dep - char buff[256]; - QString dep_cmd = Project->replaceExtraCompilerVariables( - tmp_dep_cmd, inFile, out, MakefileGenerator::LocalShell); - if(Project->canExecute(dep_cmd)) { - dep_cmd.prepend(QLatin1String("cd ") - + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) - + QLatin1String(" && ")); - if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { - QString indeps; - while(!feof(proc)) { - int read_in = (int)fread(buff, 1, 255, proc); - if(!read_in) - break; - indeps += QByteArray(buff, read_in); - } - QT_PCLOSE(proc); - if(!indeps.isEmpty()) { - QStringList extradeps = indeps.split(QLatin1Char('\n')); - for (int i = 0; i < extradeps.count(); ++i) { - QString dd = extradeps.at(i).simplified(); - if (!dd.isEmpty()) - deps += Project->fileFixify(dd, MakefileGenerator::FileFixifyFromOutdir); - } - } - } - } + const QString dep_cd_cmd = QLatin1String("cd ") + + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) + + QLatin1String(" && "); + Project->callExtraCompilerDependCommand(extraCompilerName, dep_cd_cmd, tmp_dep_cmd, + inFile, out, + true, // dep_lines + &deps, + configs.contains("dep_existing_only"), + true /* checkCommandAvailability */); } for (int i = 0; i < deps.count(); ++i) deps[i] = Option::fixPathToTargetOS( diff --git a/qmake/generators/win32/msvc_vcproj.h b/qmake/generators/win32/msvc_vcproj.h index 8f38252274..c565b709d2 100644 --- a/qmake/generators/win32/msvc_vcproj.h +++ b/qmake/generators/win32/msvc_vcproj.h @@ -69,6 +69,8 @@ public: bool pchIsCFile = false; VCProjectWriter *projectWriter; + using Win32MakefileGenerator::callExtraCompilerDependCommand; + protected: virtual VCProjectWriter *createProjectWriter(); bool doDepends() const override { return false; } // Never necessary -- cgit v1.2.3