mirror of
https://github.com/reactos/CMake.git
synced 2025-03-03 17:39:10 +00:00
cmMakefile: Add OnExecuteCommand callback
In cmCTestScriptHandler, port away from cmFunctionBlocker and update the elapsed time with the new callback instead.
This commit is contained in:
parent
c76500949d
commit
b51fba6298
@ -24,7 +24,6 @@
|
|||||||
#include "cmCTestUploadCommand.h"
|
#include "cmCTestUploadCommand.h"
|
||||||
#include "cmCommand.h"
|
#include "cmCommand.h"
|
||||||
#include "cmDuration.h"
|
#include "cmDuration.h"
|
||||||
#include "cmFunctionBlocker.h"
|
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
@ -49,32 +48,8 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class cmExecutionStatus;
|
|
||||||
struct cmListFileFunction;
|
|
||||||
|
|
||||||
#define CTEST_INITIAL_CMAKE_OUTPUT_FILE_NAME "CTestInitialCMakeOutput.log"
|
#define CTEST_INITIAL_CMAKE_OUTPUT_FILE_NAME "CTestInitialCMakeOutput.log"
|
||||||
|
|
||||||
// used to keep elapsed time up to date
|
|
||||||
class cmCTestScriptFunctionBlocker : public cmFunctionBlocker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
|
|
||||||
cmExecutionStatus& /*status*/) override;
|
|
||||||
// virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
|
|
||||||
// virtual void ScopeEnded(cmMakefile &mf);
|
|
||||||
|
|
||||||
cmCTestScriptHandler* CTestScriptHandler;
|
|
||||||
};
|
|
||||||
|
|
||||||
// simply update the time and don't block anything
|
|
||||||
bool cmCTestScriptFunctionBlocker::IsFunctionBlocked(
|
|
||||||
const cmListFileFunction& /*lff*/, cmMakefile& /*mf*/,
|
|
||||||
cmExecutionStatus& /*status*/)
|
|
||||||
{
|
|
||||||
this->CTestScriptHandler->UpdateElapsedTime();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmCTestScriptHandler::cmCTestScriptHandler()
|
cmCTestScriptHandler::cmCTestScriptHandler()
|
||||||
{
|
{
|
||||||
this->Backup = false;
|
this->Backup = false;
|
||||||
@ -373,12 +348,8 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
|
|||||||
this->Makefile->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0");
|
this->Makefile->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// always add a function blocker to update the elapsed time
|
// set a callback function to update the elapsed time
|
||||||
{
|
this->Makefile->OnExecuteCommand([this] { this->UpdateElapsedTime(); });
|
||||||
auto fb = cm::make_unique<cmCTestScriptFunctionBlocker>();
|
|
||||||
fb->CTestScriptHandler = this;
|
|
||||||
this->Makefile->AddFunctionBlocker(std::move(fb));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Execute CTestScriptMode.cmake, which loads CMakeDetermineSystem and
|
/* Execute CTestScriptMode.cmake, which loads CMakeDetermineSystem and
|
||||||
CMakeSystemSpecificInformation, so
|
CMakeSystemSpecificInformation, so
|
||||||
|
@ -353,6 +353,11 @@ private:
|
|||||||
cmMakefile* Makefile;
|
cmMakefile* Makefile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void cmMakefile::OnExecuteCommand(std::function<void()> callback)
|
||||||
|
{
|
||||||
|
this->ExecuteCommandCallback = std::move(callback);
|
||||||
|
}
|
||||||
|
|
||||||
bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
|
bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
|
||||||
cmExecutionStatus& status)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
@ -364,6 +369,10 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->ExecuteCommandCallback) {
|
||||||
|
this->ExecuteCommandCallback();
|
||||||
|
}
|
||||||
|
|
||||||
// Place this call on the call stack.
|
// Place this call on the call stack.
|
||||||
cmMakefileCall stack_manager(this, lff, status);
|
cmMakefileCall stack_manager(this, lff, status);
|
||||||
static_cast<void>(stack_manager);
|
static_cast<void>(stack_manager);
|
||||||
|
@ -627,6 +627,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void PrintCommandTrace(const cmListFileFunction& lff) const;
|
void PrintCommandTrace(const cmListFileFunction& lff) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a callback that is invoked whenever ExecuteCommand is called.
|
||||||
|
*/
|
||||||
|
void OnExecuteCommand(std::function<void()> callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a single CMake command. Returns true if the command
|
* Execute a single CMake command. Returns true if the command
|
||||||
* succeeded or false if it failed.
|
* succeeded or false if it failed.
|
||||||
@ -964,6 +969,7 @@ private:
|
|||||||
bool EnforceUniqueDir(const std::string& srcPath,
|
bool EnforceUniqueDir(const std::string& srcPath,
|
||||||
const std::string& binPath) const;
|
const std::string& binPath) const;
|
||||||
|
|
||||||
|
std::function<void()> ExecuteCommandCallback;
|
||||||
using FunctionBlockerPtr = std::unique_ptr<cmFunctionBlocker>;
|
using FunctionBlockerPtr = std::unique_ptr<cmFunctionBlocker>;
|
||||||
using FunctionBlockersType =
|
using FunctionBlockersType =
|
||||||
std::stack<FunctionBlockerPtr, std::vector<FunctionBlockerPtr>>;
|
std::stack<FunctionBlockerPtr, std::vector<FunctionBlockerPtr>>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user