mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-21 06:10:16 +08:00
instrumentation: Run preBuild and postBuild hooks before and after make
Updates the preBuild and postBuild instrumentation hooks to run before and after make is invoked.
This commit is contained in:
@@ -117,8 +117,8 @@ optional.
|
|||||||
should be one of the following:
|
should be one of the following:
|
||||||
|
|
||||||
* ``postGenerate``
|
* ``postGenerate``
|
||||||
* ``preBuild`` (called when ``ninja`` is invoked; unavailable on Windows)
|
* ``preBuild`` (called when ``ninja`` or ``make`` is invoked; unavailable on Windows)
|
||||||
* ``postBuild`` (called when ``ninja`` completes; unavailable on Windows)
|
* ``postBuild`` (called when ``ninja`` or ``make`` completes; unavailable on Windows)
|
||||||
* ``preCMakeBuild`` (called when ``cmake --build`` is invoked)
|
* ``preCMakeBuild`` (called when ``cmake --build`` is invoked)
|
||||||
* ``postCMakeBuild`` (called when ``cmake --build`` completes)
|
* ``postCMakeBuild`` (called when ``cmake --build`` completes)
|
||||||
* ``postInstall``
|
* ``postInstall``
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "cmGeneratorTarget.h"
|
#include "cmGeneratorTarget.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmGlobalUnixMakefileGenerator3.h"
|
#include "cmGlobalUnixMakefileGenerator3.h"
|
||||||
|
#include "cmInstrumentation.h"
|
||||||
#include "cmList.h"
|
#include "cmList.h"
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
#include "cmLocalGenerator.h"
|
#include "cmLocalGenerator.h"
|
||||||
@@ -71,6 +72,26 @@ std::string cmSplitExtension(std::string const& in, std::string& base)
|
|||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32)
|
||||||
|
// Helper function to add the Start Instrumentation command
|
||||||
|
void addInstrumentationCommand(cmInstrumentation* instrumentation,
|
||||||
|
std::vector<std::string>& commands)
|
||||||
|
{
|
||||||
|
// FIXME(#26668) This does not work on Windows
|
||||||
|
if (instrumentation->HasPreOrPostBuildHook()) {
|
||||||
|
std::string instrumentationCommand =
|
||||||
|
"$(CTEST_COMMAND) --start-instrumentation $(CMAKE_BINARY_DIR)";
|
||||||
|
/*
|
||||||
|
* On Unix systems, Make will prefix the command with `/bin/sh -c`.
|
||||||
|
* Use exec so that Make is the parent process of the command.
|
||||||
|
* Add a `;` to convince BSD make to not optimize out the shell.
|
||||||
|
*/
|
||||||
|
instrumentationCommand = cmStrCat("exec ", instrumentationCommand, " ;");
|
||||||
|
commands.push_back(instrumentationCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Helper predicate for removing absolute paths that don't point to the
|
// Helper predicate for removing absolute paths that don't point to the
|
||||||
// source or binary directory. It is used when CMAKE_DEPENDS_IN_PROJECT_ONLY
|
// source or binary directory. It is used when CMAKE_DEPENDS_IN_PROJECT_ONLY
|
||||||
// is set ON, to only consider in-project dependencies during the build.
|
// is set ON, to only consider in-project dependencies during the build.
|
||||||
@@ -651,19 +672,35 @@ void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto getShellCommand = [this](std::string command) -> std::string {
|
||||||
|
std::string shellCommand = this->MaybeConvertWatcomShellCommand(command);
|
||||||
|
return shellCommand.empty()
|
||||||
|
? this->ConvertToOutputFormat(command, cmOutputConverter::SHELL)
|
||||||
|
: shellCommand;
|
||||||
|
};
|
||||||
|
|
||||||
std::string cmakeShellCommand =
|
std::string cmakeShellCommand =
|
||||||
this->MaybeConvertWatcomShellCommand(cmSystemTools::GetCMakeCommand());
|
getShellCommand(cmSystemTools::GetCMakeCommand());
|
||||||
if (cmakeShellCommand.empty()) {
|
|
||||||
cmakeShellCommand = this->ConvertToOutputFormat(
|
makefileStream << "# The CMake executable.\n"
|
||||||
cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
|
"CMAKE_COMMAND = "
|
||||||
|
<< cmakeShellCommand << "\n";
|
||||||
|
|
||||||
|
#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32)
|
||||||
|
// FIXME(#26668) This does not work on Windows
|
||||||
|
if (this->GetCMakeInstance()
|
||||||
|
->GetInstrumentation()
|
||||||
|
->HasPreOrPostBuildHook()) {
|
||||||
|
std::string ctestShellCommand =
|
||||||
|
getShellCommand(cmSystemTools::GetCTestCommand());
|
||||||
|
makefileStream << "# The CTest executable.\n"
|
||||||
|
"CTEST_COMMAND = "
|
||||||
|
<< ctestShellCommand << "\n";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
makefileStream
|
makefileStream
|
||||||
<< "# The CMake executable.\n"
|
|
||||||
"CMAKE_COMMAND = "
|
|
||||||
<< cmakeShellCommand
|
|
||||||
<< "\n"
|
<< "\n"
|
||||||
"\n"
|
|
||||||
"# The command to remove a file.\n"
|
"# The command to remove a file.\n"
|
||||||
"RM = "
|
"RM = "
|
||||||
<< cmakeShellCommand
|
<< cmakeShellCommand
|
||||||
@@ -811,6 +848,10 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsBottom(
|
|||||||
|
|
||||||
std::vector<std::string> no_depends;
|
std::vector<std::string> no_depends;
|
||||||
commands.push_back(std::move(runRule));
|
commands.push_back(std::move(runRule));
|
||||||
|
#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32)
|
||||||
|
addInstrumentationCommand(this->GetCMakeInstance()->GetInstrumentation(),
|
||||||
|
commands);
|
||||||
|
#endif
|
||||||
if (!this->IsRootMakefile()) {
|
if (!this->IsRootMakefile()) {
|
||||||
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
||||||
this->GetCurrentBinaryDirectory());
|
this->GetCurrentBinaryDirectory());
|
||||||
@@ -1808,6 +1849,10 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
|
|||||||
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL),
|
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL),
|
||||||
" 1");
|
" 1");
|
||||||
commands.push_back(std::move(runRule));
|
commands.push_back(std::move(runRule));
|
||||||
|
#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32)
|
||||||
|
addInstrumentationCommand(this->GetCMakeInstance()->GetInstrumentation(),
|
||||||
|
commands);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
||||||
this->GetCurrentBinaryDirectory());
|
this->GetCurrentBinaryDirectory());
|
||||||
|
@@ -117,8 +117,8 @@ instrument(cmake-command-parallel-install
|
|||||||
CHECK_SCRIPT check-data-dir.cmake)
|
CHECK_SCRIPT check-data-dir.cmake)
|
||||||
|
|
||||||
# FIXME(#26668) This does not work on Windows
|
# FIXME(#26668) This does not work on Windows
|
||||||
if (UNIX AND ${RunCMake_GENERATOR} MATCHES "^Ninja")
|
if (UNIX)
|
||||||
instrument(cmake-command-ninja NO_WARN
|
instrument(cmake-command-make-program NO_WARN
|
||||||
BUILD_MAKE_PROGRAM
|
BUILD_MAKE_PROGRAM
|
||||||
CHECK_SCRIPT check-ninja-hooks.cmake)
|
CHECK_SCRIPT check-make-program-hooks.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
@@ -13,6 +13,7 @@ add_custom_command(
|
|||||||
COMMAND ${CMAKE_COMMAND} -E true
|
COMMAND ${CMAKE_COMMAND} -E true
|
||||||
OUTPUT output1 output2
|
OUTPUT output1 output2
|
||||||
)
|
)
|
||||||
|
set_property(SOURCE output1 output2 PROPERTY SYMBOLIC 1)
|
||||||
add_custom_target(customTarget ALL
|
add_custom_target(customTarget ALL
|
||||||
DEPENDS output1
|
DEPENDS output1
|
||||||
)
|
)
|
||||||
|
@@ -0,0 +1,7 @@
|
|||||||
|
file(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/../hook.cmake" hook_path)
|
||||||
|
cmake_instrumentation(
|
||||||
|
API_VERSION 1
|
||||||
|
DATA_VERSION 1
|
||||||
|
HOOKS preBuild postBuild
|
||||||
|
CALLBACK "\"${CMAKE_COMMAND}\" -P \"${hook_path}\" 0"
|
||||||
|
)
|
@@ -1,6 +0,0 @@
|
|||||||
cmake_instrumentation(
|
|
||||||
API_VERSION 1
|
|
||||||
DATA_VERSION 1
|
|
||||||
HOOKS preBuild postBuild
|
|
||||||
CALLBACK "\"${CMAKE_COMMAND}\" -P \"${CMAKE_SOURCE_DIR}/../hook.cmake\" 0"
|
|
||||||
)
|
|
Reference in New Issue
Block a user