mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-26 01:38:43 +00:00
Exports: Capture context for diagnostics
Modify install exports to make use of the install generator's captured diagnostic context. Modify build exports to capture and use a diagnostic context. This allows diagnostics issued by export file generation to use the diagnostic context from the instigating command, and to provide a backtrace to the same.
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "cmDiagnosticContext.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmStateTypes.h"
|
||||
@@ -13,7 +15,11 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
|
||||
cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator() = default;
|
||||
cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator(
|
||||
cmDiagnosticContext context)
|
||||
: cmExportBuildFileGenerator(std::move(context))
|
||||
{
|
||||
}
|
||||
|
||||
bool cmExportBuildAndroidMKGenerator::GenerateMainFile(std::ostream& os)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "cmExportBuildFileGenerator.h"
|
||||
#include "cmStateTypes.h"
|
||||
|
||||
class cmDiagnosticContext;
|
||||
|
||||
/** \class cmExportBuildAndroidMKGenerator
|
||||
* \brief Generate a file exporting targets from a build tree.
|
||||
*
|
||||
@@ -25,7 +27,7 @@ class cmExportBuildAndroidMKGenerator
|
||||
, public cmExportAndroidMKGenerator
|
||||
{
|
||||
public:
|
||||
cmExportBuildAndroidMKGenerator();
|
||||
cmExportBuildAndroidMKGenerator(cmDiagnosticContext context);
|
||||
|
||||
/** Set whether to append generated code to the output file. */
|
||||
void SetAppendMode(bool append) { this->AppendMode = append; }
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "cmCryptoHash.h"
|
||||
#include "cmDiagnosticContext.h"
|
||||
#include "cmExportSet.h"
|
||||
#include "cmGenExContext.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
@@ -25,7 +26,9 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
|
||||
cmExportBuildCMakeConfigGenerator::cmExportBuildCMakeConfigGenerator()
|
||||
cmExportBuildCMakeConfigGenerator::cmExportBuildCMakeConfigGenerator(
|
||||
cmDiagnosticContext context)
|
||||
: cmExportBuildFileGenerator(std::move(context))
|
||||
{
|
||||
this->LG = nullptr;
|
||||
this->ExportSet = nullptr;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "cmExportBuildFileGenerator.h"
|
||||
#include "cmExportCMakeConfigGenerator.h"
|
||||
|
||||
class cmDiagnosticContext;
|
||||
|
||||
/** \class cmExportBuildCMakeConfigGenerator
|
||||
* \brief Generate a file exporting targets from a build tree.
|
||||
*
|
||||
@@ -25,7 +27,7 @@ class cmExportBuildCMakeConfigGenerator
|
||||
, public cmExportBuildFileGenerator
|
||||
{
|
||||
public:
|
||||
cmExportBuildCMakeConfigGenerator();
|
||||
cmExportBuildCMakeConfigGenerator(cmDiagnosticContext context);
|
||||
|
||||
/** Set whether to append generated code to the output file. */
|
||||
void SetAppendMode(bool append) { this->AppendMode = append; }
|
||||
|
||||
@@ -25,12 +25,22 @@
|
||||
|
||||
class cmSourceFile;
|
||||
|
||||
cmExportBuildFileGenerator::cmExportBuildFileGenerator()
|
||||
cmExportBuildFileGenerator::cmExportBuildFileGenerator(
|
||||
cmDiagnosticContext context)
|
||||
: Context(std::move(context))
|
||||
{
|
||||
this->LG = nullptr;
|
||||
this->ExportSet = nullptr;
|
||||
}
|
||||
|
||||
cmDiagnosticContext cmExportBuildFileGenerator::CaptureContext(
|
||||
cmMakefile const& mf)
|
||||
{
|
||||
cmDiagnosticContext context{ mf.GetBacktrace() };
|
||||
context.RecordDiagnostic(cmDiagnostics::CMD_AUTHOR, mf.GetStateSnapshot());
|
||||
return context;
|
||||
}
|
||||
|
||||
void cmExportBuildFileGenerator::Compute(cmLocalGenerator* lg)
|
||||
{
|
||||
this->LG = lg;
|
||||
@@ -246,7 +256,7 @@ void cmExportBuildFileGenerator::IssueMessage(MessageType type,
|
||||
void cmExportBuildFileGenerator::IssueDiagnostic(
|
||||
cmDiagnosticCategory category, std::string const& message) const
|
||||
{
|
||||
this->LG->GetMakefile()->IssueDiagnostic(category, message);
|
||||
this->LG->GetMakefile()->IssueDiagnostic(category, message, this->Context);
|
||||
}
|
||||
|
||||
std::string cmExportBuildFileGenerator::InstallNameDir(
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cm/optional>
|
||||
#include <cmext/algorithm>
|
||||
|
||||
#include "cmDiagnosticContext.h"
|
||||
#include "cmDiagnostics.h"
|
||||
#include "cmExportFileGenerator.h"
|
||||
#include "cmStateTypes.h"
|
||||
@@ -19,6 +20,7 @@
|
||||
class cmExportSet;
|
||||
class cmGeneratorTarget;
|
||||
class cmLocalGenerator;
|
||||
class cmMakefile;
|
||||
|
||||
/** \class cmExportBuildCMakeConfigGenerator
|
||||
* \brief Generate a file exporting targets from a build tree.
|
||||
@@ -43,7 +45,7 @@ public:
|
||||
std::string XcFrameworkLocation;
|
||||
};
|
||||
|
||||
cmExportBuildFileGenerator();
|
||||
cmExportBuildFileGenerator(cmDiagnosticContext context);
|
||||
|
||||
/** Set the list of targets to export. */
|
||||
void SetTargets(std::vector<TargetExport> const& targets)
|
||||
@@ -81,6 +83,9 @@ public:
|
||||
|
||||
void Compute(cmLocalGenerator* lg);
|
||||
|
||||
/** Capture context for generator. */
|
||||
static cmDiagnosticContext CaptureContext(cmMakefile const& mf);
|
||||
|
||||
protected:
|
||||
cmStateEnums::TargetType GetExportTargetType(
|
||||
cmGeneratorTarget const* target) const;
|
||||
@@ -144,6 +149,7 @@ protected:
|
||||
std::string XcFrameworkLocation;
|
||||
};
|
||||
|
||||
cmDiagnosticContext Context;
|
||||
std::vector<TargetExport> Targets;
|
||||
cmExportSet* ExportSet;
|
||||
std::vector<TargetExportPrivate> Exports;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <cm3p/json/value.h>
|
||||
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmDiagnosticContext.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmList.h"
|
||||
#include "cmPackageInfoArguments.h"
|
||||
@@ -20,8 +21,9 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
|
||||
cmExportBuildPackageInfoGenerator::cmExportBuildPackageInfoGenerator(
|
||||
cmPackageInfoArguments arguments)
|
||||
: cmExportPackageInfoGenerator(std::move(arguments))
|
||||
cmPackageInfoArguments arguments, cmDiagnosticContext context)
|
||||
: cmExportBuildFileGenerator(std::move(context))
|
||||
, cmExportPackageInfoGenerator(std::move(arguments))
|
||||
{
|
||||
this->SetNamespace(cmStrCat(this->GetPackageName(), "::"_s));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Json {
|
||||
class Value;
|
||||
}
|
||||
|
||||
class cmDiagnosticContext;
|
||||
class cmGeneratorTarget;
|
||||
class cmPackageInfoArguments;
|
||||
|
||||
@@ -31,7 +32,8 @@ class cmExportBuildPackageInfoGenerator
|
||||
, public cmExportPackageInfoGenerator
|
||||
{
|
||||
public:
|
||||
cmExportBuildPackageInfoGenerator(cmPackageInfoArguments arguments);
|
||||
cmExportBuildPackageInfoGenerator(cmPackageInfoArguments arguments,
|
||||
cmDiagnosticContext context);
|
||||
|
||||
protected:
|
||||
// Implement virtual methods from the superclass.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "cmArgumentParserTypes.h"
|
||||
#include "cmBuildSbomGenerator.h"
|
||||
#include "cmCryptoHash.h"
|
||||
#include "cmDiagnosticContext.h"
|
||||
#include "cmDiagnostics.h"
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmExperimental.h"
|
||||
@@ -219,14 +220,17 @@ static bool HandleTargetsMode(std::vector<std::string> const& args,
|
||||
}
|
||||
}
|
||||
|
||||
cmDiagnosticContext context = cmExportBuildFileGenerator::CaptureContext(mf);
|
||||
std::unique_ptr<cmExportBuildFileGenerator> ebfg = nullptr;
|
||||
if (android) {
|
||||
auto ebag = cm::make_unique<cmExportBuildAndroidMKGenerator>();
|
||||
auto ebag =
|
||||
cm::make_unique<cmExportBuildAndroidMKGenerator>(std::move(context));
|
||||
ebag->SetNamespace(arguments.Namespace);
|
||||
ebag->SetAppendMode(arguments.Append);
|
||||
ebfg = std::move(ebag);
|
||||
} else {
|
||||
auto ebcg = cm::make_unique<cmExportBuildCMakeConfigGenerator>();
|
||||
auto ebcg =
|
||||
cm::make_unique<cmExportBuildCMakeConfigGenerator>(std::move(context));
|
||||
ebcg->SetNamespace(arguments.Namespace);
|
||||
ebcg->SetAppendMode(arguments.Append);
|
||||
ebcg->SetExportOld(arguments.ExportOld);
|
||||
@@ -328,7 +332,8 @@ static bool HandleExportMode(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// Set up export file generation.
|
||||
auto ebcg = cm::make_unique<cmExportBuildCMakeConfigGenerator>();
|
||||
auto ebcg = cm::make_unique<cmExportBuildCMakeConfigGenerator>(
|
||||
cmExportBuildFileGenerator::CaptureContext(mf));
|
||||
ebcg->SetNamespace(arguments.Namespace);
|
||||
ebcg->SetExportPackageDependencies(arguments.ExportPackageDependencies);
|
||||
|
||||
@@ -395,7 +400,8 @@ static bool HandleSpecialExportMode(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// Create the export build generator
|
||||
auto ebpg = cm::make_unique<GeneratorType>(arguments);
|
||||
auto ebpg = cm::make_unique<GeneratorType>(
|
||||
arguments, cmExportBuildFileGenerator::CaptureContext(mf));
|
||||
AddExportGenerator(mf, gg, std::move(ebpg), fname, *exportSet,
|
||||
arguments.CxxModulesDirectory);
|
||||
return true;
|
||||
|
||||
@@ -321,7 +321,8 @@ void cmExportInstallFileGenerator::IssueDiagnostic(
|
||||
cmDiagnosticCategory category, std::string const& message) const
|
||||
{
|
||||
cmLocalGenerator const* const lg = this->IEGen->GetLocalGenerator();
|
||||
lg->GetMakefile()->IssueDiagnostic(category, message);
|
||||
lg->GetMakefile()->IssueDiagnostic(category, message,
|
||||
this->IEGen->GetDiagnosticContext());
|
||||
}
|
||||
|
||||
std::string cmExportInstallFileGenerator::InstallNameDir(
|
||||
|
||||
@@ -255,11 +255,11 @@ bool cmExportInstallPackageInfoGenerator::GenerateFileSetProperties(
|
||||
cmGeneratorFileSet const* fileSet = gte->GetFileSet(name);
|
||||
|
||||
if (!fileSet) {
|
||||
gte->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("File set \"", name,
|
||||
"\" is listed in interface file sets of ", gte->GetName(),
|
||||
" but has not been created"));
|
||||
this->IssueMessage(MessageType::FATAL_ERROR,
|
||||
cmStrCat("File set \"", name,
|
||||
"\" is listed in interface file sets of ",
|
||||
gte->GetName(),
|
||||
" but has not been created"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +264,7 @@ cmInstallGenerator::MessageLevel cmInstallGenerator::SelectMessageLevel(
|
||||
cmDiagnosticContext cmInstallGenerator::CaptureContext(cmMakefile const& mf)
|
||||
{
|
||||
cmDiagnosticContext context{ mf.GetBacktrace() };
|
||||
context.RecordDiagnostic(cmDiagnostics::CMD_AUTHOR, mf.GetStateSnapshot());
|
||||
context.RecordDiagnostic(cmDiagnostics::CMD_INSTALL_ABSOLUTE_DESTINATION,
|
||||
mf.GetStateSnapshot());
|
||||
return context;
|
||||
|
||||
@@ -85,6 +85,11 @@ public:
|
||||
return this->Context.GetBacktrace();
|
||||
}
|
||||
|
||||
cmDiagnosticContext const& GetDiagnosticContext() const
|
||||
{
|
||||
return this->Context;
|
||||
}
|
||||
|
||||
static std::string GetDestDirPath(std::string const& file);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
CMake Warning \(author\) in CMakeLists\.txt:
|
||||
CMake Warning \(author\) at VersionCheckWarning\.cmake:[0-9]+ \(export\):
|
||||
Package "foo" uses unrecognized version schema "unrecognized"\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:3 \(include\)
|
||||
This warning is for project developers\. Use -Wno-author to suppress it\.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
CMake Warning \(author\) in CMakeLists\.txt:
|
||||
CMake Warning \(author\) at VersionCheckWarning\.cmake:[0-9]+ \(install\):
|
||||
Package "foo" uses unrecognized version schema "unrecognized"\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:3 \(include\)
|
||||
This warning is for project developers\. Use -Wno-author to suppress it\.
|
||||
|
||||
Reference in New Issue
Block a user