From aeb1b0c9dfba7a3abc47dca709b639c6cdcaa459 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 22 Apr 2019 21:25:16 +0200 Subject: WIP Change-Id: I239f7f82780db7754a62bb20c2d377c844b187fe --- qmake/generators/makefile.cpp | 58 +++++++++++++++++++++++++++++++++++++------ qmake/generators/makefile.h | 2 ++ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index 2918a2ee58..5633955372 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -1107,13 +1107,7 @@ MakefileGenerator::write() if (compileCommands) { QFileInfo outputMakeFileInfo(fileInfo(Option::output.fileName())); - QString compileCommandsFileName = "compile_commands"; - QString infix = outputMakeFileInfo.completeSuffix(); - if (!infix.isEmpty()) { - compileCommandsFileName += '_'; - compileCommandsFileName += infix; - } - compileCommandsFileName += ".json"; + QString compileCommandsFileName = CompileCommandRecorder::compilationDatabaseFileNameForMakefile(outputMakeFileInfo); QFile f(compileCommandsFileName); if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { f.write(QJsonDocument(compileCommands->commands).toJson()); @@ -2719,6 +2713,44 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QListisActiveConfig("create_compile_commands") && !targets.isEmpty()) { +#if 1 + QString commands; + commands += "sed"; + for (QList::Iterator it = targets.begin(); it != targets.end(); ++it) { + if ((*it)->profile.isEmpty()) + continue; + auto subtarget = *it; + QString out_directory = subtarget->out_directory; + if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep)) + out_directory += Option::dir_sep; + commands += " " + out_directory + CompileCommandRecorder::compilationDatabaseFileNameForMakefile(fileInfo(subtarget->makefile)); + project->values("create_compile_commands.recurse") += subtarget->name; + } + + project->values("create_compile_commands.commands") += commands; + project->values("create_compile_commands.CONFIG") += "recursive"; + project->values("create_compile_commands.recurse_target") += "create_compile_commands"; + project->values("QMAKE_EXTRA_TARGETS") += "create_compile_commands"; +#else + t << "\ncreate_compile_commands:"; + if(!targets.isEmpty()) { + t << "\n\tsed"; + for (QList::Iterator it = targets.begin(); it != targets.end(); ++it) { + if ((*it)->profile.isEmpty()) + continue; + auto subtarget = *it; + QString out_directory = subtarget->out_directory; + if(!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep)) + out_directory += Option::dir_sep; + t << " " << out_directory + CompileCommandRecorder::compilationDatabaseFileNameForMakefile(fileInfo(subtarget->makefile)); + } + t << " > compile_commands.json"; + } + t << "\n"; +#endif + } + // user defined targets const ProStringList &qut = project->values("QMAKE_EXTRA_TARGETS"); for (ProStringList::ConstIterator qut_it = qut.begin(); qut_it != qut.end(); ++qut_it) { @@ -3502,4 +3534,16 @@ QString MakefileGenerator::shellQuote(const QString &str) return isWindowsShell() ? IoUtils::shellQuoteWin(str) : IoUtils::shellQuoteUnix(str); } +QString CompileCommandRecorder::compilationDatabaseFileNameForMakefile(const QFileInfo &makeFileInfo) +{ + QString compileCommandsFileName = "compile_commands"; + QString infix = makeFileInfo.completeSuffix(); + if (!infix.isEmpty()) { + compileCommandsFileName += '_'; + compileCommandsFileName += infix; + } + compileCommandsFileName += ".json"; + return compileCommandsFileName; +} + QT_END_NAMESPACE diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index f81fc3cb54..9cc1550fb5 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -40,6 +40,7 @@ QT_BEGIN_NAMESPACE +// ### rename to compilation database struct CompileCommandRecorder { QJsonArray commands; @@ -47,6 +48,7 @@ struct CompileCommandRecorder // values are coded in the makefile and also supplied here, for expansion before writing // compile_commands.json. QHash compilerVariables; + static QString compilationDatabaseFileNameForMakefile(const QFileInfo &makeFileInfo); }; #ifdef Q_OS_WIN32 -- cgit v1.2.1