From af7e0e735777d7f7d1606049e5261106a092665a 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. Change-Id: I9b8a87d6dd5c33cc1ed9f613fe85daca52309369 Reviewed-by: Christian Kandeler --- qmake/generators/makefile.cpp | 129 +++++++++++++++++------------------------- qmake/generators/makefile.h | 3 + 2 files changed, 56 insertions(+), 76 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index 95452e507c..f3ca192ab2 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -1862,6 +1862,55 @@ 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) +{ + 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 { + 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) { @@ -1991,44 +2040,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 - 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); } } for(int i = 0; i < inputs.size(); ) { @@ -2076,44 +2089,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 - 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); //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 ecda6eb257..c7b2bee0b4 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -84,6 +84,9 @@ 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); void writeExtraCompilerTargets(QTextStream &t); void writeExtraCompilerVariables(QTextStream &t); bool writeDummyMakefile(QTextStream &t); -- cgit v1.2.3