cmCommand Refactoring
Once !3574 (merged) is merged, we can remove some boilerplate from all commands. Do the following for each class that derives from cmCommand
:
-
To access the
cmMakefile
, callstatus.GetMakefile()
. Port away fromthis->Makefile
andthis->GetMakefile()
. Make sure that thecmExecutionStatus&
argument isstatus
rather than/*unused*/
. -
To set an error message, call
status.SetError(msg)
. Port away fromthis->SetError(msg)
. Make sure that thecmExecutionStatus&
argument isstatus
rather than/*unused*/
. -
Turn member functions into free functions in an unnamed namespace in the source file. Alternatively, extract a helper class that does not derive from
cmCommand
. It might be necessary to passcmExecutionStatus& status
or other parameters down to those commands. -
Turn member variables into local variables. Rationale: When the command is executed, the
Clone()
member function is called and then theInitialPass()
member function is called on the clone. Subsequently, the clone is discarded. This means that the lifetime of all the member variables that are not copied in theClone()
member function is limited to theInitialPass()
call anyway. -
Turn the class into a function: Delete the
Clone()
member function for good, turn theInitialPass()
member function into a free function with the original name of the class. IncmCommands.cxx
, pass that name tostate->AddBuiltinCommand()
without any decoration.