From 553794e98706800a8c792bbcd81d49522333a50f Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 10 Nov 2022 18:15:08 -0500 Subject: cmake::CreateProfilingEntry: Refactor to take lambda for args --- Source/cmMakefile.cxx | 15 ++++++++++++++- Source/cmMakefileProfilingData.cxx | 29 +++++++++-------------------- Source/cmMakefileProfilingData.h | 14 +++----------- Source/cmake.h | 13 ++++++++++--- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2091f27..db8f785 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -376,7 +376,20 @@ public: this->Makefile->ExecutionStatusStack.push_back(&status); #if !defined(CMAKE_BOOTSTRAP) this->ProfilingDataRAII = - this->Makefile->GetCMakeInstance()->CreateProfilingEntry(lff, lfc); + this->Makefile->GetCMakeInstance()->CreateProfilingEntry( + "script", lff.LowerCaseName(), [&lff, &lfc]() -> Json::Value { + Json::Value argsValue = Json::objectValue; + if (!lff.Arguments().empty()) { + std::string args; + for (auto const& a : lff.Arguments()) { + args = cmStrCat(args, args.empty() ? "" : " ", a.Value); + } + argsValue["functionArgs"] = args; + } + argsValue["location"] = + cmStrCat(lfc.FilePath, ':', std::to_string(lfc.Line)); + return argsValue; + }); #endif } diff --git a/Source/cmMakefileProfilingData.cxx b/Source/cmMakefileProfilingData.cxx index e4844f3..e903ae1 100644 --- a/Source/cmMakefileProfilingData.cxx +++ b/Source/cmMakefileProfilingData.cxx @@ -6,9 +6,6 @@ #include #include #include -#include - -#include #include #include @@ -16,7 +13,6 @@ #include "cmsys/FStream.hxx" #include "cmsys/SystemInformation.hxx" -#include "cmListFileCache.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -47,22 +43,6 @@ cmMakefileProfilingData::~cmMakefileProfilingData() noexcept } } -void cmMakefileProfilingData::StartEntry(const cmListFileFunction& lff, - cmListFileContext const& lfc) -{ - cm::optional argsValue(cm::in_place, Json::objectValue); - if (!lff.Arguments().empty()) { - std::string args; - for (auto const& a : lff.Arguments()) { - args = cmStrCat(args, args.empty() ? "" : " ", a.Value); - } - (*argsValue)["functionArgs"] = args; - } - (*argsValue)["location"] = - cmStrCat(lfc.FilePath, ':', std::to_string(lfc.Line)); - this->StartEntry("script", lff.LowerCaseName(), std::move(argsValue)); -} - void cmMakefileProfilingData::StartEntry(const std::string& category, const std::string& name, cm::optional args) @@ -127,6 +107,15 @@ void cmMakefileProfilingData::StopEntry() } } +cmMakefileProfilingData::RAII::RAII(cmMakefileProfilingData& data, + const std::string& category, + const std::string& name, + cm::optional args) + : Data(&data) +{ + this->Data->StartEntry(category, name, std::move(args)); +} + cmMakefileProfilingData::RAII::RAII(RAII&& other) noexcept : Data(other.Data) { diff --git a/Source/cmMakefileProfilingData.h b/Source/cmMakefileProfilingData.h index e8d7dfa..4cf0bfa 100644 --- a/Source/cmMakefileProfilingData.h +++ b/Source/cmMakefileProfilingData.h @@ -3,7 +3,6 @@ #pragma once #include #include -#include #include @@ -15,15 +14,11 @@ namespace Json { class StreamWriter; } -class cmListFileContext; -class cmListFileFunction; - class cmMakefileProfilingData { public: cmMakefileProfilingData(const std::string&); ~cmMakefileProfilingData() noexcept; - void StartEntry(const cmListFileFunction& lff, cmListFileContext const& lfc); void StartEntry(const std::string& category, const std::string& name, cm::optional args = cm::nullopt); void StopEntry(); @@ -35,12 +30,9 @@ public: RAII(const RAII&) = delete; RAII(RAII&&) noexcept; - template - RAII(cmMakefileProfilingData& data, Args&&... args) - : Data(&data) - { - this->Data->StartEntry(std::forward(args)...); - } + RAII(cmMakefileProfilingData& data, const std::string& category, + const std::string& name, + cm::optional args = cm::nullopt); ~RAII(); diff --git a/Source/cmake.h b/Source/cmake.h index 2f7f7bd..6b585a1 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -638,13 +638,20 @@ public: cmMakefileProfilingData& GetProfilingOutput(); bool IsProfilingEnabled() const; - template cm::optional CreateProfilingEntry( - Args&&... args) + const std::string& category, const std::string& name) + { + return this->CreateProfilingEntry( + category, name, []() -> cm::nullopt_t { return cm::nullopt; }); + } + + template + cm::optional CreateProfilingEntry( + const std::string& category, const std::string& name, ArgsFunc&& argsFunc) { if (this->IsProfilingEnabled()) { return cm::make_optional( - this->GetProfilingOutput(), std::forward(args)...); + this->GetProfilingOutput(), category, name, argsFunc()); } return cm::nullopt; } -- cgit v0.12 From 09d7f947d68796e8fde923a47636f1c764b5a7af Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 11 Nov 2022 11:44:47 -0500 Subject: cmGeneratorExpression: Require cmake instance --- Source/cmCustomCommandGenerator.cxx | 5 ++- Source/cmExportFileGenerator.cxx | 2 +- Source/cmExportInstallFileGenerator.cxx | 4 +- Source/cmExportTryCompileFileGenerator.cxx | 2 +- Source/cmFileCommand.cxx | 6 ++- Source/cmFileSet.cxx | 9 ++-- Source/cmFileSet.h | 4 +- Source/cmGeneratorExpression.cxx | 15 ++++--- Source/cmGeneratorExpression.h | 13 ++++-- Source/cmGeneratorExpressionEvaluationFile.cxx | 2 +- Source/cmGeneratorExpressionNode.cxx | 2 +- Source/cmGeneratorTarget.cxx | 59 ++++++++++++++++---------- Source/cmInstalledFile.cxx | 4 +- Source/cmLocalGenerator.cxx | 2 +- Source/cmLocalNinjaGenerator.cxx | 2 +- Source/cmQtAutoGenInitializer.cxx | 2 +- Source/cmTarget.cxx | 5 ++- Source/cmTestGenerator.cxx | 3 +- Source/cmVisualStudio10TargetGenerator.cxx | 10 ++--- 19 files changed, 92 insertions(+), 59 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 41d4442..57b009a 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -172,7 +172,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator( }; } - cmGeneratorExpression ge(cc.GetBacktrace()); + cmGeneratorExpression ge(*lg->GetCMakeInstance(), cc.GetBacktrace()); cmGeneratorTarget const* target{ lg->FindGeneratorTargetToUse( this->Target) }; @@ -417,7 +417,8 @@ std::string cmCustomCommandGenerator::GetDepfile() const return ""; } - cmGeneratorExpression ge(this->CC->GetBacktrace()); + cmGeneratorExpression ge(*this->LG->GetCMakeInstance(), + this->CC->GetBacktrace()); return EvaluateDepfile(depfile, ge, this->LG, this->OutputConfig); } diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 2c61163..bd2b6af 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -379,7 +379,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( const char* propName = "INTERFACE_INCLUDE_DIRECTORIES"; cmValue input = target->GetProperty(propName); - cmGeneratorExpression ge; + cmGeneratorExpression ge(*target->Makefile->GetCMakeInstance()); std::string dirs = cmGeneratorExpression::Preprocess( cmJoin(target->Target->GetInstallIncludeDirectoriesEntries(te), ";"), diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 195737b..5e190f4 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -570,7 +570,7 @@ std::string cmExportInstallFileGenerator::GetFileSetDirectories( auto configs = gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); - cmGeneratorExpression ge; + cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance()); auto cge = ge.Parse(te->FileSetGenerators.at(fileSet)->GetDestination()); for (auto const& config : configs) { @@ -617,7 +617,7 @@ std::string cmExportInstallFileGenerator::GetFileSetFiles( auto fileEntries = fileSet->CompileFileEntries(); auto directoryEntries = fileSet->CompileDirectoryEntries(); - cmGeneratorExpression destGe; + cmGeneratorExpression destGe(*gte->Makefile->GetCMakeInstance()); auto destCge = destGe.Parse(te->FileSetGenerators.at(fileSet)->GetDestination()); diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index e98aa05..33c057d 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -70,7 +70,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets( return std::string(); } - cmGeneratorExpression ge; + cmGeneratorExpression ge(*tgt->Makefile->GetCMakeInstance()); std::unique_ptr parentDagChecker; if (propName == "INTERFACE_LINK_OPTIONS") { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index cc9b256..b1d238c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -2462,11 +2462,13 @@ void AddEvaluationFile(const std::string& inputName, { cmListFileBacktrace lfbt = status.GetMakefile().GetBacktrace(); - cmGeneratorExpression outputGe(lfbt); + cmGeneratorExpression outputGe(*status.GetMakefile().GetCMakeInstance(), + lfbt); std::unique_ptr outputCge = outputGe.Parse(outputExpr); - cmGeneratorExpression conditionGe(lfbt); + cmGeneratorExpression conditionGe(*status.GetMakefile().GetCMakeInstance(), + lfbt); std::unique_ptr conditionCge = conditionGe.Parse(condition); diff --git a/Source/cmFileSet.cxx b/Source/cmFileSet.cxx index d6665a2..b96ba6e 100644 --- a/Source/cmFileSet.cxx +++ b/Source/cmFileSet.cxx @@ -78,9 +78,10 @@ bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis) return false; } -cmFileSet::cmFileSet(std::string name, std::string type, +cmFileSet::cmFileSet(cmake& cmakeInstance, std::string name, std::string type, cmFileSetVisibility visibility) - : Name(std::move(name)) + : CMakeInstance(cmakeInstance) + , Name(std::move(name)) , Type(std::move(type)) , Visibility(visibility) { @@ -113,7 +114,7 @@ cmFileSet::CompileFileEntries() const for (auto const& entry : this->FileEntries) { for (auto const& ex : cmExpandedList(entry.Value)) { - cmGeneratorExpression ge(entry.Backtrace); + cmGeneratorExpression ge(this->CMakeInstance, entry.Backtrace); auto cge = ge.Parse(ex); result.push_back(std::move(cge)); } @@ -129,7 +130,7 @@ cmFileSet::CompileDirectoryEntries() const for (auto const& entry : this->DirectoryEntries) { for (auto const& ex : cmExpandedList(entry.Value)) { - cmGeneratorExpression ge(entry.Backtrace); + cmGeneratorExpression ge(this->CMakeInstance, entry.Backtrace); auto cge = ge.Parse(ex); result.push_back(std::move(cge)); } diff --git a/Source/cmFileSet.h b/Source/cmFileSet.h index 5357e77..54d430c 100644 --- a/Source/cmFileSet.h +++ b/Source/cmFileSet.h @@ -17,6 +17,7 @@ struct cmGeneratorExpressionDAGChecker; class cmGeneratorTarget; class cmLocalGenerator; class cmMakefile; +class cmake; enum class cmFileSetVisibility { @@ -33,7 +34,7 @@ bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis); class cmFileSet { public: - cmFileSet(std::string name, std::string type, + cmFileSet(cmake& cmakeInstance, std::string name, std::string type, cmFileSetVisibility visibility); const std::string& GetName() const { return this->Name; } @@ -77,6 +78,7 @@ public: static bool IsValidName(const std::string& name); private: + cmake& CMakeInstance; std::string Name; std::string Type; cmFileSetVisibility Visibility; diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index f988e54..8f0db47 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -13,11 +13,14 @@ #include "cmGeneratorExpressionEvaluator.h" #include "cmGeneratorExpressionLexer.h" #include "cmGeneratorExpressionParser.h" +#include "cmLocalGenerator.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -cmGeneratorExpression::cmGeneratorExpression(cmListFileBacktrace backtrace) - : Backtrace(std::move(backtrace)) +cmGeneratorExpression::cmGeneratorExpression(cmake& cmakeInstance, + cmListFileBacktrace backtrace) + : CMakeInstance(cmakeInstance) + , Backtrace(std::move(backtrace)) { } @@ -29,7 +32,8 @@ std::unique_ptr cmGeneratorExpression::Parse( std::string input) const { return std::unique_ptr( - new cmCompiledGeneratorExpression(this->Backtrace, std::move(input))); + new cmCompiledGeneratorExpression(this->CMakeInstance, this->Backtrace, + std::move(input))); } std::string cmGeneratorExpression::Evaluate( @@ -39,7 +43,8 @@ std::string cmGeneratorExpression::Evaluate( cmGeneratorTarget const* currentTarget, std::string const& language) { if (Find(input) != std::string::npos) { - cmCompiledGeneratorExpression cge(cmListFileBacktrace(), std::move(input)); + cmCompiledGeneratorExpression cge(*lg->GetCMakeInstance(), + cmListFileBacktrace(), std::move(input)); return cge.Evaluate(lg, config, headTarget, dagChecker, currentTarget, language); } @@ -97,7 +102,7 @@ const std::string& cmCompiledGeneratorExpression::EvaluateWithContext( } cmCompiledGeneratorExpression::cmCompiledGeneratorExpression( - cmListFileBacktrace backtrace, std::string input) + cmake& /*cmakeInstance*/, cmListFileBacktrace backtrace, std::string input) : Backtrace(std::move(backtrace)) , Input(std::move(input)) { diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 188993f..e22b8ab 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -12,10 +12,11 @@ #include #include "cmListFileCache.h" +#include "cmLocalGenerator.h" +class cmake; class cmCompiledGeneratorExpression; class cmGeneratorTarget; -class cmLocalGenerator; struct cmGeneratorExpressionContext; struct cmGeneratorExpressionDAGChecker; struct cmGeneratorExpressionEvaluator; @@ -33,7 +34,8 @@ class cmGeneratorExpression { public: /** Construct. */ - cmGeneratorExpression(cmListFileBacktrace backtrace = cmListFileBacktrace()); + cmGeneratorExpression(cmake& cmakeInstance, + cmListFileBacktrace backtrace = cmListFileBacktrace()); ~cmGeneratorExpression(); cmGeneratorExpression(cmGeneratorExpression const&) = delete; @@ -82,6 +84,7 @@ public: const std::string& replacement); private: + cmake& CMakeInstance; cmListFileBacktrace Backtrace; }; @@ -152,7 +155,8 @@ private: cmGeneratorExpressionContext& context, cmGeneratorExpressionDAGChecker* dagChecker) const; - cmCompiledGeneratorExpression(cmListFileBacktrace backtrace, + cmCompiledGeneratorExpression(cmake& cmakeInstance, + cmListFileBacktrace backtrace, std::string input); friend class cmGeneratorExpression; @@ -184,7 +188,8 @@ public: std::string config, cmGeneratorTarget const* headTarget, std::string language = std::string()) - : LocalGenerator(localGenerator) + : GeneratorExpression(*localGenerator->GetCMakeInstance()) + , LocalGenerator(localGenerator) , Config(std::move(config)) , HeadTarget(headTarget) , Language(std::move(language)) diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 8f3ed4d..817437e 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -165,7 +165,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) } cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace(); - cmGeneratorExpression contentGE(lfbt); + cmGeneratorExpression contentGE(*lg->GetCMakeInstance(), lfbt); std::unique_ptr inputExpression = contentGE.Parse(inputContent); diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 45d5a83..562c31e 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -57,7 +57,7 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression( cmGeneratorExpressionDAGChecker* dagChecker, cmGeneratorTarget const* currentTarget) { - cmGeneratorExpression ge(context->Backtrace); + cmGeneratorExpression ge(*lg->GetCMakeInstance(), context->Backtrace); std::unique_ptr cge = ge.Parse(prop); cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem); cge->SetQuiet(context->Quiet); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index becf244..6065285 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -241,15 +241,16 @@ private: std::unique_ptr< cmGeneratorTarget:: - TargetPropertyEntry> static CreateTargetPropertyEntry(const BT& + TargetPropertyEntry> static CreateTargetPropertyEntry(cmake& cmakeInstance, + const BT< + std::string>& propertyValue, bool evaluateForBuildsystem = false) { if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) { - cmGeneratorExpression ge(propertyValue.Backtrace); + cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace); std::unique_ptr cge = ge.Parse(propertyValue.Value); cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); @@ -262,12 +263,13 @@ std::unique_ptr< } static void CreatePropertyGeneratorExpressions( - cmBTStringRange entries, + cmake& cmakeInstance, cmBTStringRange entries, std::vector>& items, bool evaluateForBuildsystem = false) { for (auto const& entry : entries) { - items.push_back(CreateTargetPropertyEntry(entry, evaluateForBuildsystem)); + items.push_back( + CreateTargetPropertyEntry(cmakeInstance, entry, evaluateForBuildsystem)); } } @@ -343,29 +345,36 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) this->GlobalGenerator->ComputeTargetObjectDirectory(this); - CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetIncludeDirectoriesEntries(), this->IncludeDirectoriesEntries); - CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetCompileOptionsEntries(), this->CompileOptionsEntries); - CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetCompileFeaturesEntries(), this->CompileFeaturesEntries); - CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetCompileDefinitionsEntries(), this->CompileDefinitionsEntries); - CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetLinkOptionsEntries(), this->LinkOptionsEntries); - CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetLinkDirectoriesEntries(), this->LinkDirectoriesEntries); - CreatePropertyGeneratorExpressions(t->GetPrecompileHeadersEntries(), + CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), + t->GetPrecompileHeadersEntries(), this->PrecompileHeadersEntries); - CreatePropertyGeneratorExpressions(t->GetSourceEntries(), - this->SourceEntries, true); + CreatePropertyGeneratorExpressions( + *lg->GetCMakeInstance(), t->GetSourceEntries(), this->SourceEntries, true); this->PolicyMap = t->GetPolicyMap(); @@ -753,6 +762,7 @@ void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before) this->SourceEntries.insert( before ? this->SourceEntries.begin() : this->SourceEntries.end(), CreateTargetPropertyEntry( + *this->LocalGenerator->GetCMakeInstance(), BT(src, this->Makefile->GetBacktrace()), true)); this->ClearSourcesCache(); } @@ -780,6 +790,7 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, before ? this->IncludeDirectoriesEntries.begin() : this->IncludeDirectoriesEntries.end(), CreateTargetPropertyEntry( + *this->Makefile->GetCMakeInstance(), BT(src, this->Makefile->GetBacktrace()), true)); } @@ -1653,7 +1664,8 @@ void AddObjectEntries(cmGeneratorTarget const* headTarget, headTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely( lib.Target); std::string genex = "$"; - cmGeneratorExpression ge(lib.Backtrace); + cmGeneratorExpression ge(*headTarget->Makefile->GetCMakeInstance(), + lib.Backtrace); std::unique_ptr cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); @@ -4192,7 +4204,8 @@ std::vector> cmGeneratorTarget::GetCompileDefinitions( } case cmPolicies::OLD: { std::unique_ptr entry = - CreateTargetPropertyEntry(*configProp); + CreateTargetPropertyEntry( + *this->LocalGenerator->GetCMakeInstance(), *configProp); entries.Entries.emplace_back(EvaluateTargetPropertyEntry( this, config, language, &dagChecker, *entry)); } break; @@ -4778,8 +4791,8 @@ std::vector> cmGeneratorTarget::GetStaticLibraryLinkOptions( if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) { std::vector options = cmExpandedList(*linkOptions); for (const auto& option : options) { - std::unique_ptr entry = - CreateTargetPropertyEntry(option); + std::unique_ptr entry = CreateTargetPropertyEntry( + *this->LocalGenerator->GetCMakeInstance(), option); entries.Entries.emplace_back(EvaluateTargetPropertyEntry( this, config, language, &dagChecker, *entry)); } @@ -4931,8 +4944,8 @@ std::vector> cmGeneratorTarget::GetLinkDepends( if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) { std::vector depends = cmExpandedList(*linkDepends); for (const auto& depend : depends) { - std::unique_ptr entry = - CreateTargetPropertyEntry(depend); + std::unique_ptr entry = CreateTargetPropertyEntry( + *this->LocalGenerator->GetCMakeInstance(), depend); entries.Entries.emplace_back(EvaluateTargetPropertyEntry( this, config, language, &dagChecker, *entry)); } @@ -6756,7 +6769,8 @@ void cmGeneratorTarget::ExpandLinkItems( cmMakefile const* mf = this->LocalGenerator->GetMakefile(); LookupLinkItemScope scope{ this->LocalGenerator }; for (BT const& entry : entries) { - cmGeneratorExpression ge(entry.Backtrace); + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(), + entry.Backtrace); std::unique_ptr cge = ge.Parse(entry.Value); cge->SetEvaluateForBuildsystem(true); std::vector libs = cmExpandedList( @@ -8195,7 +8209,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( break; } } - cmGeneratorExpression ge(entry.Backtrace); + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(), + entry.Backtrace); std::unique_ptr const cge = ge.Parse(entry.Value); cge->SetEvaluateForBuildsystem(true); diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index 0974eea..5bf8320 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -21,7 +21,7 @@ cmInstalledFile::Property::~Property() = default; void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name) { cmListFileBacktrace backtrace = mf->GetBacktrace(); - cmGeneratorExpression ge(backtrace); + cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace); this->Name = name; this->NameExpression = ge.Parse(name); @@ -56,7 +56,7 @@ void cmInstalledFile::AppendProperty(cmMakefile const* mf, bool /*asString*/) { cmListFileBacktrace backtrace = mf->GetBacktrace(); - cmGeneratorExpression ge(backtrace); + cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace); Property& property = this->Properties[prop]; property.ValueExpressions.push_back(ge.Parse(value)); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index fb269b2..31c6504 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -4503,7 +4503,7 @@ std::vector cmLocalGenerator::ExpandCustomCommandOutputGenex( std::string const& o, cmListFileBacktrace const& bt) { std::vector allConfigOutputs; - cmGeneratorExpression ge(bt); + cmGeneratorExpression ge(*this->GetCMakeInstance(), bt); std::unique_ptr cge = ge.Parse(o); std::vector configs = this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index c11f5b4..1e2ea2a 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -701,7 +701,7 @@ bool cmLocalNinjaGenerator::HasUniqueByproducts( { std::vector configs = this->GetMakefile()->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); - cmGeneratorExpression ge(bt); + cmGeneratorExpression ge(*this->GetCMakeInstance(), bt); for (std::string const& p : byproducts) { if (cmGeneratorExpression::Find(p) == std::string::npos) { return false; diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 96649ab..6f78a46 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -2095,7 +2095,7 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars, // Evaluate generator expression { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - cmGeneratorExpression ge(lfbt); + cmGeneratorExpression ge(*this->Makefile->GetCMakeInstance(), lfbt); std::unique_ptr cge = ge.Parse(val); genVars.Executable = cge->Evaluate(this->LocalGen, ""); } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 874195b..2955d7c 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2656,8 +2656,9 @@ cmFileSet* cmTarget::GetFileSet(const std::string& name) std::pair cmTarget::GetOrCreateFileSet( const std::string& name, const std::string& type, cmFileSetVisibility vis) { - auto result = this->impl->FileSets.emplace( - std::make_pair(name, cmFileSet(name, type, vis))); + auto result = this->impl->FileSets.emplace(std::make_pair( + name, + cmFileSet(*this->GetMakefile()->GetCMakeInstance(), name, type, vis))); if (result.second) { auto bt = this->impl->Makefile->GetBacktrace(); if (type == this->impl->HeadersFileSets.TypeName) { diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index dbb0876..5e325dd 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -127,7 +127,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, this->TestGenerated = true; // Set up generator expression evaluation context. - cmGeneratorExpression ge(this->Test->GetBacktrace()); + cmGeneratorExpression ge(*this->Test->GetMakefile()->GetCMakeInstance(), + this->Test->GetBacktrace()); // Determine if policy CMP0110 is set to NEW. const bool quote_test_name = diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9393389..7e43bee 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2090,7 +2090,7 @@ void cmVisualStudio10TargetGenerator::ParseSettingsProperty( const std::string& settingsPropertyValue, ConfigToSettings& toolSettings) { if (!settingsPropertyValue.empty()) { - cmGeneratorExpression ge; + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance()); std::unique_ptr cge = ge.Parse(settingsPropertyValue); @@ -2190,7 +2190,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource( } // Figure out if there's any additional flags to use if (cmValue saf = sf->GetProperty("VS_SHADER_FLAGS")) { - cmGeneratorExpression ge; + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance()); std::unique_ptr cge = ge.Parse(*saf); for (const std::string& config : this->Configurations) { @@ -2203,7 +2203,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource( } // Figure out if debug information should be generated if (cmValue sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) { - cmGeneratorExpression ge; + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance()); std::unique_ptr cge = ge.Parse(*sed); for (const std::string& config : this->Configurations) { @@ -2217,7 +2217,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource( } // Figure out if optimizations should be disabled if (cmValue sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) { - cmGeneratorExpression ge; + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance()); std::unique_ptr cge = ge.Parse(*sdo); for (const std::string& config : this->Configurations) { @@ -2331,7 +2331,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource( this->FinishWritingSource(e2, toolSettings); if (!deployContent.empty()) { - cmGeneratorExpression ge; + cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance()); std::unique_ptr cge = ge.Parse(deployContent); // Deployment location cannot be set on a configuration basis -- cgit v0.12 From 4d70a94545629affd3d68dda74ec71c62a3bb0c4 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 10 Nov 2022 14:44:58 -0500 Subject: Profiling: Profile genex evaluation --- Source/cmGeneratorExpression.cxx | 13 ++++++++++++- Source/cmGeneratorExpressionEvaluator.cxx | 31 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 8f0db47..21ace89 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -16,6 +16,7 @@ #include "cmLocalGenerator.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +#include "cmake.h" cmGeneratorExpression::cmGeneratorExpression(cmake& cmakeInstance, cmListFileBacktrace backtrace) @@ -43,6 +44,11 @@ std::string cmGeneratorExpression::Evaluate( cmGeneratorTarget const* currentTarget, std::string const& language) { if (Find(input) != std::string::npos) { +#ifndef CMAKE_BOOTSTRAP + auto profilingRAII = lg->GetCMakeInstance()->CreateProfilingEntry( + "genex_compile_eval", input); +#endif + cmCompiledGeneratorExpression cge(*lg->GetCMakeInstance(), cmListFileBacktrace(), std::move(input)); return cge.Evaluate(lg, config, headTarget, dagChecker, currentTarget, @@ -102,10 +108,15 @@ const std::string& cmCompiledGeneratorExpression::EvaluateWithContext( } cmCompiledGeneratorExpression::cmCompiledGeneratorExpression( - cmake& /*cmakeInstance*/, cmListFileBacktrace backtrace, std::string input) + cmake& cmakeInstance, cmListFileBacktrace backtrace, std::string input) : Backtrace(std::move(backtrace)) , Input(std::move(input)) { +#ifndef CMAKE_BOOTSTRAP + auto profilingRAII = + cmakeInstance.CreateProfilingEntry("genex_compile", this->Input); +#endif + cmGeneratorExpressionLexer l; std::vector tokens = l.Tokenize(this->Input); this->NeedsEvaluation = l.GetSawGeneratorExpression(); diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index fec309c..b239408 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -4,8 +4,14 @@ #include +#ifndef CMAKE_BOOTSTRAP +# include +#endif + #include "cmGeneratorExpressionContext.h" #include "cmGeneratorExpressionNode.h" +#include "cmLocalGenerator.h" +#include "cmake.h" GeneratorExpressionContent::GeneratorExpressionContent( const char* startContent, size_t length) @@ -61,6 +67,12 @@ std::string GeneratorExpressionContent::Evaluate( cmGeneratorExpressionContext* context, cmGeneratorExpressionDAGChecker* dagChecker) const { +#ifndef CMAKE_BOOTSTRAP + auto evalProfilingRAII = + context->LG->GetCMakeInstance()->CreateProfilingEntry( + "genex_eval", this->GetOriginalExpression()); +#endif + std::string identifier; { for (const auto& pExprEval : this->IdentifierChildren) { @@ -101,7 +113,24 @@ std::string GeneratorExpressionContent::Evaluate( return std::string(); } - return node->Evaluate(parameters, context, this, dagChecker); + { +#ifndef CMAKE_BOOTSTRAP + auto execProfilingRAII = + context->LG->GetCMakeInstance()->CreateProfilingEntry( + "genex_exec", identifier, [¶meters]() -> Json::Value { + Json::Value args = Json::objectValue; + if (!parameters.empty()) { + args["genexArgs"] = Json::arrayValue; + for (auto const& parameter : parameters) { + args["genexArgs"].append(parameter); + } + } + return args; + }); +#endif + + return node->Evaluate(parameters, context, this, dagChecker); + } } std::string GeneratorExpressionContent::EvaluateParameters( -- cgit v0.12