cmDisallowedCommand: extract policy checking from cmCommand

Implement cmDisallowedCommand as a wrapper class for cmCommand.
This commit is contained in:
Daniel Pfeifer
2016-12-26 00:34:44 +01:00
parent 615e2a17e4
commit 7fb14775a3
14 changed files with 111 additions and 70 deletions

View File

@@ -440,6 +440,8 @@ set(SRCS
cmCreateTestSourceList.h
cmDefinePropertyCommand.cxx
cmDefinePropertyCommand.h
cmDisallowedCommand.cxx
cmDisallowedCommand.h
cmEnableLanguageCommand.cxx
cmEnableLanguageCommand.h
cmEnableTestingCommand.cxx

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;

View 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;
}

View 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

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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;