1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

cmCommand refactor: cmWriteFileCommand

This commit is contained in:
Gabor Bencze
2019-08-09 11:56:34 +02:00
committed by Brad King
parent ca3b9186bb
commit 07ea93de54
3 changed files with 11 additions and 33 deletions

View File

@@ -204,8 +204,7 @@ void GetScriptingCommands(cmState* state)
cmCMakeHostSystemInformationCommand); cmCMakeHostSystemInformationCommand);
state->AddBuiltinCommand("remove", cmRemoveCommand); state->AddBuiltinCommand("remove", cmRemoveCommand);
state->AddBuiltinCommand("variable_watch", cmVariableWatchCommand); state->AddBuiltinCommand("variable_watch", cmVariableWatchCommand);
state->AddBuiltinCommand("write_file", state->AddBuiltinCommand("write_file", cmWriteFileCommand);
cm::make_unique<cmWriteFileCommand>());
state->AddDisallowedCommand( state->AddDisallowedCommand(
"build_name", cm::make_unique<cmBuildNameCommand>(), cmPolicies::CMP0036, "build_name", cm::make_unique<cmBuildNameCommand>(), cmPolicies::CMP0036,

View File

@@ -4,18 +4,17 @@
#include "cmsys/FStream.hxx" #include "cmsys/FStream.hxx"
#include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cm_sys_stat.h" #include "cm_sys_stat.h"
class cmExecutionStatus;
// cmLibraryCommand // cmLibraryCommand
bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args, bool cmWriteFileCommand(std::vector<std::string> const& args,
cmExecutionStatus&) cmExecutionStatus& status)
{ {
if (args.size() < 2) { if (args.size() < 2) {
this->SetError("called with incorrect number of arguments"); status.SetError("called with incorrect number of arguments");
return false; return false;
} }
std::string message; std::string message;
@@ -33,10 +32,10 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
} }
} }
if (!this->Makefile->CanIWriteThisFile(fileName)) { if (!status.GetMakefile().CanIWriteThisFile(fileName)) {
std::string e = std::string e =
"attempted to write a file: " + fileName + " into a source directory."; "attempted to write a file: " + fileName + " into a source directory.";
this->SetError(e); status.SetError(e);
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
@@ -68,7 +67,7 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
std::string error = "Internal CMake error when trying to open file: "; std::string error = "Internal CMake error when trying to open file: ";
error += fileName; error += fileName;
error += " for writing."; error += " for writing.";
this->SetError(error); status.SetError(error);
return false; return false;
} }
file << message << std::endl; file << message << std::endl;

View File

@@ -8,33 +8,13 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
class cmExecutionStatus; class cmExecutionStatus;
/** \class cmWriteFileCommand /**
* \brief Writes a message to a file * \brief Writes a message to a file
* *
*/ */
class cmWriteFileCommand : public cmCommand bool cmWriteFileCommand(std::vector<std::string> const& args,
{ cmExecutionStatus& status);
public:
/**
* This is a virtual constructor for the command.
*/
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmWriteFileCommand>();
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
};
#endif #endif