mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 19:00:54 -06:00
cmDisallowedCommand: extract policy checking from cmCommand
Implement cmDisallowedCommand as a wrapper class for cmCommand.
This commit is contained in:
@@ -440,6 +440,8 @@ set(SRCS
|
||||
cmCreateTestSourceList.h
|
||||
cmDefinePropertyCommand.cxx
|
||||
cmDefinePropertyCommand.h
|
||||
cmDisallowedCommand.cxx
|
||||
cmDisallowedCommand.h
|
||||
cmEnableLanguageCommand.cxx
|
||||
cmEnableLanguageCommand.h
|
||||
cmEnableTestingCommand.cxx
|
||||
|
||||
@@ -16,11 +16,6 @@ class cmExecutionStatus;
|
||||
bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(
|
||||
cmPolicies::CMP0036,
|
||||
"The build_name command should not be called; see CMP0036.")) {
|
||||
return true;
|
||||
}
|
||||
if (args.empty()) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "cmCommand.h"
|
||||
|
||||
#include "cmMakefile.h"
|
||||
#include "cmake.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
struct cmListFileArgument;
|
||||
@@ -32,20 +31,3 @@ void cmCommand::SetError(const std::string& e)
|
||||
{
|
||||
this->Error = e;
|
||||
}
|
||||
|
||||
bool cmCommand::Disallowed(cmPolicies::PolicyID pol, const char* e)
|
||||
{
|
||||
switch (this->Makefile->GetPolicyStatus(pol)) {
|
||||
case cmPolicies::WARN:
|
||||
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
|
||||
cmPolicies::GetPolicyWarning(pol));
|
||||
case cmPolicies::OLD:
|
||||
return false;
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::NEW:
|
||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmPolicies.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmMakefile;
|
||||
struct cmListFileArgument;
|
||||
@@ -104,9 +102,6 @@ public:
|
||||
*/
|
||||
void SetError(const std::string& e);
|
||||
|
||||
/** Check if the command is disallowed by a policy. */
|
||||
bool Disallowed(cmPolicies::PolicyID pol, const char* e);
|
||||
|
||||
private:
|
||||
cmCommand(cmCommand const&); // = delete;
|
||||
cmCommand& operator=(cmCommand const&); // = delete;
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
#include "cmAuxSourceDirectoryCommand.h"
|
||||
#include "cmBuildNameCommand.h"
|
||||
#include "cmCMakeHostSystemInformationCommand.h"
|
||||
#include "cmDisallowedCommand.h"
|
||||
#include "cmExportCommand.h"
|
||||
#include "cmExportLibraryDependenciesCommand.h"
|
||||
#include "cmFLTKWrapUICommand.h"
|
||||
@@ -208,33 +209,52 @@ std::vector<cmCommand*> GetPredefinedCommands()
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
commands.push_back(new cmAddCompileOptionsCommand);
|
||||
commands.push_back(new cmAuxSourceDirectoryCommand);
|
||||
commands.push_back(new cmBuildNameCommand);
|
||||
commands.push_back(new cmCMakeHostSystemInformationCommand);
|
||||
commands.push_back(new cmExportCommand);
|
||||
commands.push_back(new cmExportLibraryDependenciesCommand);
|
||||
commands.push_back(new cmFLTKWrapUICommand);
|
||||
commands.push_back(new cmIncludeExternalMSProjectCommand);
|
||||
commands.push_back(new cmInstallProgramsCommand);
|
||||
commands.push_back(new cmLinkLibrariesCommand);
|
||||
commands.push_back(new cmLoadCacheCommand);
|
||||
commands.push_back(new cmLoadCommandCommand);
|
||||
commands.push_back(new cmOutputRequiredFilesCommand);
|
||||
commands.push_back(new cmQTWrapCPPCommand);
|
||||
commands.push_back(new cmQTWrapUICommand);
|
||||
commands.push_back(new cmRemoveCommand);
|
||||
commands.push_back(new cmRemoveDefinitionsCommand);
|
||||
commands.push_back(new cmSourceGroupCommand);
|
||||
commands.push_back(new cmSubdirDependsCommand);
|
||||
commands.push_back(new cmTargetCompileDefinitionsCommand);
|
||||
commands.push_back(new cmTargetCompileFeaturesCommand);
|
||||
commands.push_back(new cmTargetCompileOptionsCommand);
|
||||
commands.push_back(new cmTargetIncludeDirectoriesCommand);
|
||||
commands.push_back(new cmTargetSourcesCommand);
|
||||
commands.push_back(new cmUseMangledMesaCommand);
|
||||
commands.push_back(new cmUtilitySourceCommand);
|
||||
commands.push_back(new cmVariableRequiresCommand);
|
||||
commands.push_back(new cmVariableWatchCommand);
|
||||
commands.push_back(new cmWriteFileCommand);
|
||||
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmBuildNameCommand, cmPolicies::CMP0036,
|
||||
"The build_name command should not be called; see CMP0036."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmExportLibraryDependenciesCommand, cmPolicies::CMP0033,
|
||||
"The export_library_dependencies command should not be called; "
|
||||
"see CMP0033."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmLoadCommandCommand, cmPolicies::CMP0031,
|
||||
"The load_command command should not be called; see CMP0031."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmOutputRequiredFilesCommand, cmPolicies::CMP0032,
|
||||
"The output_required_files command should not be called; "
|
||||
"see CMP0032."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmSubdirDependsCommand, cmPolicies::CMP0029,
|
||||
"The subdir_depends command should not be called; see CMP0029."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmUseMangledMesaCommand, cmPolicies::CMP0030,
|
||||
"The use_mangled_mesa command should not be called; see CMP0030."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmUtilitySourceCommand, cmPolicies::CMP0034,
|
||||
"The utility_source command should not be called; see CMP0034."));
|
||||
commands.push_back(new cmDisallowedCommand(
|
||||
new cmVariableRequiresCommand, cmPolicies::CMP0035,
|
||||
"The variable_requires command should not be called; see CMP0035."));
|
||||
#endif
|
||||
|
||||
return commands;
|
||||
|
||||
31
Source/cmDisallowedCommand.cxx
Normal file
31
Source/cmDisallowedCommand.cxx
Normal file
@@ -0,0 +1,31 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmDisallowedCommand.h"
|
||||
|
||||
#include "cmMakefile.h"
|
||||
#include "cmake.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
|
||||
bool cmDisallowedCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
switch (this->Makefile->GetPolicyStatus(this->Policy)) {
|
||||
case cmPolicies::WARN:
|
||||
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
|
||||
cmPolicies::GetPolicyWarning(this->Policy));
|
||||
break;
|
||||
case cmPolicies::OLD:
|
||||
break;
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::NEW:
|
||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, this->Message);
|
||||
return true;
|
||||
}
|
||||
|
||||
this->Command->SetMakefile(this->GetMakefile());
|
||||
bool const ret = this->Command->InitialPass(args, status);
|
||||
this->SetError(this->Command->GetError());
|
||||
return ret;
|
||||
}
|
||||
50
Source/cmDisallowedCommand.h
Normal file
50
Source/cmDisallowedCommand.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#ifndef cmDisallowedCommand_h
|
||||
#define cmDisallowedCommand_h
|
||||
|
||||
#include <cmConfigure.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cmCommand.h"
|
||||
#include "cmPolicies.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
|
||||
class cmDisallowedCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
cmDisallowedCommand(cmCommand* command, cmPolicies::PolicyID policy,
|
||||
const char* message)
|
||||
: Command(command)
|
||||
, Policy(policy)
|
||||
, Message(message)
|
||||
{
|
||||
}
|
||||
|
||||
~cmDisallowedCommand() CM_OVERRIDE { delete this->Command; }
|
||||
|
||||
cmCommand* Clone() CM_OVERRIDE
|
||||
{
|
||||
return new cmDisallowedCommand(this->Command->Clone(), this->Policy,
|
||||
this->Message);
|
||||
}
|
||||
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) CM_OVERRIDE;
|
||||
|
||||
bool IsScriptable() const CM_OVERRIDE
|
||||
{
|
||||
return this->Command->IsScriptable();
|
||||
}
|
||||
|
||||
std::string GetName() const CM_OVERRIDE { return this->Command->GetName(); }
|
||||
|
||||
private:
|
||||
cmCommand* Command;
|
||||
cmPolicies::PolicyID Policy;
|
||||
const char* Message;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -23,12 +23,6 @@ class cmExecutionStatus;
|
||||
bool cmExportLibraryDependenciesCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(
|
||||
cmPolicies::CMP0033,
|
||||
"The export_library_dependencies command should not be called; "
|
||||
"see CMP0033.")) {
|
||||
return true;
|
||||
}
|
||||
if (args.empty()) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
|
||||
@@ -174,11 +174,6 @@ cmLoadedCommand::~cmLoadedCommand()
|
||||
bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(
|
||||
cmPolicies::CMP0031,
|
||||
"The load_command command should not be called; see CMP0031.")) {
|
||||
return true;
|
||||
}
|
||||
if (args.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -495,11 +495,6 @@ protected:
|
||||
bool cmOutputRequiredFilesCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(cmPolicies::CMP0032, "The output_required_files "
|
||||
"command should not be called; "
|
||||
"see CMP0032.")) {
|
||||
return true;
|
||||
}
|
||||
if (args.size() != 2) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
|
||||
@@ -9,8 +9,5 @@ class cmExecutionStatus;
|
||||
bool cmSubdirDependsCommand::InitialPass(std::vector<std::string> const&,
|
||||
cmExecutionStatus&)
|
||||
{
|
||||
this->Disallowed(
|
||||
cmPolicies::CMP0029,
|
||||
"The subdir_depends command should not be called; see CMP0029.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,11 +13,6 @@ class cmExecutionStatus;
|
||||
bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(
|
||||
cmPolicies::CMP0030,
|
||||
"The use_mangled_mesa command should not be called; see CMP0030.")) {
|
||||
return true;
|
||||
}
|
||||
// expected two arguments:
|
||||
// arguement one: the full path to gl_mangle.h
|
||||
// arguement two : directory for output of edited headers
|
||||
|
||||
@@ -16,11 +16,6 @@ class cmExecutionStatus;
|
||||
bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(
|
||||
cmPolicies::CMP0034,
|
||||
"The utility_source command should not be called; see CMP0034.")) {
|
||||
return true;
|
||||
}
|
||||
if (args.size() < 3) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
|
||||
@@ -13,11 +13,6 @@ class cmExecutionStatus;
|
||||
bool cmVariableRequiresCommand::InitialPass(
|
||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
||||
{
|
||||
if (this->Disallowed(
|
||||
cmPolicies::CMP0035,
|
||||
"The variable_requires command should not be called; see CMP0035.")) {
|
||||
return true;
|
||||
}
|
||||
if (args.size() < 3) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user