mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
Ninja: add COMMENT to build statement descriptions
This allows users to recognize that something more than the basic action is happening. See: https://groups.google.com/g/ninja-build/c/Tv4wu2IBMdo Issue: #15461
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "cmCustomCommand.h" // IWYU pragma: keep
|
#include "cmCustomCommand.h" // IWYU pragma: keep
|
||||||
#include "cmCustomCommandGenerator.h"
|
#include "cmCustomCommandGenerator.h"
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmGeneratorOptions.h"
|
#include "cmGeneratorOptions.h"
|
||||||
#include "cmGeneratorTarget.h"
|
#include "cmGeneratorTarget.h"
|
||||||
#include "cmGlobalNinjaGenerator.h"
|
#include "cmGlobalNinjaGenerator.h"
|
||||||
@@ -446,8 +447,10 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules(
|
|||||||
this->GetGlobalGenerator()->AddRule(rule);
|
this->GetGlobalGenerator()->AddRule(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
|
void cmNinjaNormalTargetGenerator::WriteLinkRule(
|
||||||
std::string const& config)
|
bool useResponseFile, std::string const& config,
|
||||||
|
std::vector<std::string> const& preLinkComments,
|
||||||
|
std::vector<std::string> const& postBuildComments)
|
||||||
{
|
{
|
||||||
cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
|
cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
|
||||||
|
|
||||||
@@ -604,9 +607,19 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
|
|||||||
rule.Comment =
|
rule.Comment =
|
||||||
cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
|
cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
|
||||||
this->GetVisibleTypeName(), '.');
|
this->GetVisibleTypeName(), '.');
|
||||||
rule.Description =
|
char const* presep = "";
|
||||||
cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
|
char const* postsep = "";
|
||||||
this->GetVisibleTypeName(), " $TARGET_FILE");
|
auto prelink = cmJoin(preLinkComments, "; ");
|
||||||
|
if (!prelink.empty()) {
|
||||||
|
presep = "; ";
|
||||||
|
}
|
||||||
|
auto postbuild = cmJoin(postBuildComments, "; ");
|
||||||
|
if (!postbuild.empty()) {
|
||||||
|
postsep = "; ";
|
||||||
|
}
|
||||||
|
rule.Description = cmStrCat(
|
||||||
|
prelink, presep, "Linking ", this->TargetLinkLanguage(config), ' ',
|
||||||
|
this->GetVisibleTypeName(), " $TARGET_FILE", postsep, postbuild);
|
||||||
rule.Restat = "$RESTAT";
|
rule.Restat = "$RESTAT";
|
||||||
this->GetGlobalGenerator()->AddRule(rule);
|
this->GetGlobalGenerator()->AddRule(rule);
|
||||||
}
|
}
|
||||||
@@ -1398,12 +1411,19 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
|
|||||||
>->GetPostBuildCommands()
|
>->GetPostBuildCommands()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<std::string> preLinkComments;
|
||||||
|
std::vector<std::string> postBuildComments;
|
||||||
|
|
||||||
std::vector<std::string> preLinkCmdLines;
|
std::vector<std::string> preLinkCmdLines;
|
||||||
std::vector<std::string> postBuildCmdLines;
|
std::vector<std::string> postBuildCmdLines;
|
||||||
|
|
||||||
|
std::vector<std::string>* cmdComments[3] = { &preLinkComments,
|
||||||
|
&preLinkComments,
|
||||||
|
&postBuildComments };
|
||||||
std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines,
|
std::vector<std::string>* cmdLineLists[3] = { &preLinkCmdLines,
|
||||||
&preLinkCmdLines,
|
&preLinkCmdLines,
|
||||||
&postBuildCmdLines };
|
&postBuildCmdLines };
|
||||||
|
cmGeneratorExpression ge(*this->GetLocalGenerator()->GetCMakeInstance());
|
||||||
|
|
||||||
for (unsigned i = 0; i != 3; ++i) {
|
for (unsigned i = 0; i != 3; ++i) {
|
||||||
for (cmCustomCommand const& cc : *cmdLists[i]) {
|
for (cmCustomCommand const& cc : *cmdLists[i]) {
|
||||||
@@ -1413,6 +1433,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
|
|||||||
cmCustomCommandGenerator ccg(cc, fileConfig, this->GetLocalGenerator(),
|
cmCustomCommandGenerator ccg(cc, fileConfig, this->GetLocalGenerator(),
|
||||||
true, config);
|
true, config);
|
||||||
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
|
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
|
||||||
|
if (cc.GetComment()) {
|
||||||
|
auto cge = ge.Parse(cc.GetComment());
|
||||||
|
cmdComments[i]->emplace_back(
|
||||||
|
cge->Evaluate(this->GetLocalGenerator(), config));
|
||||||
|
}
|
||||||
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
|
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
|
||||||
byproducts.Add(ccByproducts);
|
byproducts.Add(ccByproducts);
|
||||||
std::transform(
|
std::transform(
|
||||||
@@ -1566,7 +1591,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
|
|||||||
bool usedResponseFile = false;
|
bool usedResponseFile = false;
|
||||||
globalGen->WriteBuild(this->GetImplFileStream(fileConfig), linkBuild,
|
globalGen->WriteBuild(this->GetImplFileStream(fileConfig), linkBuild,
|
||||||
commandLineLengthLimit, &usedResponseFile);
|
commandLineLengthLimit, &usedResponseFile);
|
||||||
this->WriteLinkRule(usedResponseFile, config);
|
this->WriteLinkRule(usedResponseFile, config, preLinkComments,
|
||||||
|
postBuildComments);
|
||||||
|
|
||||||
if (symlinkNeeded) {
|
if (symlinkNeeded) {
|
||||||
if (targetType == cmStateEnums::EXECUTABLE) {
|
if (targetType == cmStateEnums::EXECUTABLE) {
|
||||||
|
@@ -30,7 +30,9 @@ private:
|
|||||||
char const* GetVisibleTypeName() const;
|
char const* GetVisibleTypeName() const;
|
||||||
void WriteLanguagesRules(std::string const& config);
|
void WriteLanguagesRules(std::string const& config);
|
||||||
|
|
||||||
void WriteLinkRule(bool useResponseFile, std::string const& config);
|
void WriteLinkRule(bool useResponseFile, std::string const& config,
|
||||||
|
std::vector<std::string> const& preLinkComments,
|
||||||
|
std::vector<std::string> const& postBuildComments);
|
||||||
void WriteDeviceLinkRules(std::string const& config);
|
void WriteDeviceLinkRules(std::string const& config);
|
||||||
void WriteNvidiaDeviceLinkRule(bool useResponseFile,
|
void WriteNvidiaDeviceLinkRule(bool useResponseFile,
|
||||||
std::string const& config);
|
std::string const& config);
|
||||||
|
Reference in New Issue
Block a user