From 96df877ebc190f4e2c258895fc230a95bf8257e8 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 28 May 2019 22:11:24 +0200 Subject: De-duplicate code for calling extra compiler depend_command Flesh out copy-and-pasted code into a function and adjust the coding style on the go. This refactoring is needed for a subsequent fix. Change-Id: I9b8a87d6dd5c33cc1ed9f613fe85daca52309369 Reviewed-by: Christian Kandeler (cherry picked from commit af7e0e735777d7f7d1606049e5261106a092665a) --- qmake/generators/makefile.cpp | 136 +++++++++++++++++------------------------- qmake/generators/makefile.h | 4 ++ 2 files changed, 60 insertions(+), 80 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index fcd0ccd43e..b0075ae66c 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -1870,6 +1870,58 @@ QString MakefileGenerator::resolveDependency(const QDir &outDir, const QString & return {}; } +void MakefileGenerator::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) +{ + char buff[256]; + QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, tmp_out, LocalShell); + dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); + if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { + QByteArray depData; + while (int read_in = feof(proc) ? 0 : (int)fread(buff, 1, 255, proc)) + depData.append(buff, read_in); + QT_PCLOSE(proc); + const QString indeps = QString::fromLocal8Bit(depData); + if (indeps.isEmpty()) + return; + QDir outDir(Option::output_dir); + QStringList dep_cmd_deps = splitDeps(indeps, dep_lines); + for (int i = 0; i < dep_cmd_deps.count(); ++i) { + QString &file = dep_cmd_deps[i]; + const QString absFile = outDir.absoluteFilePath(file); + if (absFile == file) { + // already absolute; don't do any checks. + } else if (exists(absFile)) { + file = absFile; + } else { + const QString localFile = resolveDependency(outDir, file); + if (localFile.isEmpty()) { + if (exists(file)) { + warn_msg(WarnDeprecated, ".depend_command for extra compiler %s" + " prints paths relative to source directory", + extraCompiler.toLatin1().constData()); + } else if (existingDepsOnly) { + file.clear(); + } else { + file = absFile; // fallback for generated resources + } + } else { + file = localFile; + } + } + if (!file.isEmpty()) + file = fileFixify(file); + } + deps->append(dep_cmd_deps); + } +} + void MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) { @@ -2000,46 +2052,8 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) deps += findDependencies(inpf); inputs += Option::fixPathToTargetOS(inpf, false); if(!tmp_dep_cmd.isEmpty() && doDepends()) { - char buff[256]; - QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, tmp_out, LocalShell); - dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); - if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { - QByteArray depData; - while (int read_in = feof(proc) ? 0 : (int)fread(buff, 1, 255, proc)) - depData.append(buff, read_in); - QT_PCLOSE(proc); - const QString indeps = QString::fromLocal8Bit(depData); - if(!indeps.isEmpty()) { - QDir outDir(Option::output_dir); - QStringList dep_cmd_deps = splitDeps(indeps, dep_lines); - for(int i = 0; i < dep_cmd_deps.count(); ++i) { - QString &file = dep_cmd_deps[i]; - QString absFile = outDir.absoluteFilePath(file); - if (absFile == file) { - // already absolute; don't do any checks. - } else if (exists(absFile)) { - file = absFile; - } else { - QString localFile = resolveDependency(outDir, file); - if (localFile.isEmpty()) { - if (exists(file)) - warn_msg(WarnDeprecated, ".depend_command for extra compiler %s" - " prints paths relative to source directory", - (*it).toLatin1().constData()); - else if (existingDepsOnly) - file.clear(); - else - file = absFile; // fallback for generated resources - } else { - file = localFile; - } - } - if(!file.isEmpty()) - file = fileFixify(file); - } - deps += dep_cmd_deps; - } - } + callExtraCompilerDependCommand(*it, dep_cd_cmd, tmp_dep_cmd, inpf, + tmp_out, dep_lines, &deps, existingDepsOnly); } } for(int i = 0; i < inputs.size(); ) { @@ -2087,46 +2101,8 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) for (ProStringList::ConstIterator it3 = vars.constBegin(); it3 != vars.constEnd(); ++it3) cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")"); if(!tmp_dep_cmd.isEmpty() && doDepends()) { - char buff[256]; - QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, out, LocalShell); - dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); - if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { - QByteArray depData; - while (int read_in = feof(proc) ? 0 : (int)fread(buff, 1, 255, proc)) - depData.append(buff, read_in); - QT_PCLOSE(proc); - const QString indeps = QString::fromLocal8Bit(depData); - if(!indeps.isEmpty()) { - QDir outDir(Option::output_dir); - QStringList dep_cmd_deps = splitDeps(indeps, dep_lines); - for(int i = 0; i < dep_cmd_deps.count(); ++i) { - QString &file = dep_cmd_deps[i]; - QString absFile = outDir.absoluteFilePath(file); - if (absFile == file) { - // already absolute; don't do any checks. - } else if (exists(absFile)) { - file = absFile; - } else { - QString localFile = resolveDependency(outDir, file); - if (localFile.isEmpty()) { - if (exists(file)) - warn_msg(WarnDeprecated, ".depend_command for extra compiler %s" - " prints paths relative to source directory", - (*it).toLatin1().constData()); - else if (existingDepsOnly) - file.clear(); - else - file = absFile; // fallback for generated resources - } else { - file = localFile; - } - } - if(!file.isEmpty()) - file = fileFixify(file); - } - deps += dep_cmd_deps; - } - } + callExtraCompilerDependCommand(*it, dep_cd_cmd, tmp_dep_cmd, inpf, + tmp_out, dep_lines, &deps, existingDepsOnly); //use the depend system to find includes of these included files QStringList inc_deps; for(int i = 0; i < deps.size(); ++i) { diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index 350ebd377a..fe77ea0e74 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -84,6 +84,10 @@ protected: void writeExtraVariables(QTextStream &t); void writeExtraTargets(QTextStream &t); QString resolveDependency(const QDir &outDir, const QString &file); + 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); void writeExtraCompilerTargets(QTextStream &t); void writeExtraCompilerVariables(QTextStream &t); bool writeDummyMakefile(QTextStream &t); -- cgit v1.2.3