From 0fbb927bddb97a59f80d5549543d79a9d7a60614 Mon Sep 17 00:00:00 2001 From: Martin Duffy Date: Wed, 5 Feb 2025 13:43:30 -0500 Subject: instrumentation: Disable preBuild and postBuild hooks on Windows The implementation does not work on Windows. Issue: #26668 --- Help/manual/cmake-instrumentation.7.rst | 8 ++++---- Source/cmGlobalNinjaGenerator.cxx | 11 +++++++---- Source/cmGlobalNinjaGenerator.h | 3 +++ Tests/RunCMake/Instrumentation/RunCMakeTest.cmake | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Help/manual/cmake-instrumentation.7.rst b/Help/manual/cmake-instrumentation.7.rst index da9c0ff..d3a1619 100644 --- a/Help/manual/cmake-instrumentation.7.rst +++ b/Help/manual/cmake-instrumentation.7.rst @@ -117,10 +117,10 @@ optional. should be one of the following: * ``postGenerate`` - * ``preBuild`` (:ref:`Ninja Generators`. only, when ``ninja`` is invoked) - * ``postBuild`` (:ref:`Ninja Generators`. only, when ``ninja`` completes) - * ``preCMakeBuild`` (when ``cmake --build`` is invoked) - * ``postCMakeBuild`` (when ``cmake --build`` completes) + * ``preBuild`` (called when ``ninja`` is invoked; unavailable on Windows) + * ``postBuild`` (called when ``ninja`` completes; unavailable on Windows) + * ``preCMakeBuild`` (called when ``cmake --build`` is invoked) + * ``postCMakeBuild`` (called when ``cmake --build`` completes) * ``postInstall`` * ``postTest`` diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index e3eee6a..6b57669 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1762,7 +1762,8 @@ void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os) this->WriteTargetRebuildManifest(os); this->WriteTargetClean(os); this->WriteTargetHelp(os); -#if !defined(CMAKE_BOOTSTRAP) +#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32) + // FIXME(#26668) This does not work on Windows if (this->GetCMakeInstance() ->GetInstrumentation() ->HasPreOrPostBuildHook()) { @@ -1843,7 +1844,8 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) } reBuild.ImplicitDeps.push_back(this->CMakeCacheFile); -#if !defined(CMAKE_BOOTSTRAP) +#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32) + // FIXME(#26668) This does not work on Windows if (this->GetCMakeInstance() ->GetInstrumentation() ->HasPreOrPostBuildHook()) { @@ -2196,6 +2198,8 @@ void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os) } } +#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32) +// FIXME(#26668) This does not work on Windows void cmGlobalNinjaGenerator::WriteTargetInstrument(std::ostream& os) { // Write rule @@ -2204,13 +2208,11 @@ void cmGlobalNinjaGenerator::WriteTargetInstrument(std::ostream& os) rule.Command = cmStrCat( "\"", cmSystemTools::GetCTestCommand(), "\" --start-instrumentation \"", this->GetCMakeInstance()->GetHomeOutputDirectory(), "\""); -#ifndef _WIN32 /* * On Unix systems, Ninja will prefix the command with `/bin/sh -c`. * Use exec so that Ninja is the parent process of the command. */ rule.Command = cmStrCat("exec ", rule.Command); -#endif rule.Description = "Collecting build metrics"; rule.Comment = "Rule to initialize instrumentation daemon."; rule.Restat = "1"; @@ -2231,6 +2233,7 @@ void cmGlobalNinjaGenerator::WriteTargetInstrument(std::ostream& os) WriteBuild(os, instrument); } } +#endif void cmGlobalNinjaGenerator::InitOutputPathPrefix() { diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index acc9ee4..66e3bbd 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -536,7 +536,10 @@ private: void WriteTargetRebuildManifest(std::ostream& os); bool WriteTargetCleanAdditional(std::ostream& os); void WriteTargetClean(std::ostream& os); +#if !defined(CMAKE_BOOTSTRAP) && !defined(_WIN32) + // FIXME(#26668) This does not work on Windows void WriteTargetInstrument(std::ostream& os); +#endif void WriteTargetHelp(std::ostream& os); void ComputeTargetDependsClosure( diff --git a/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake b/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake index d8e91f8..f98bb32 100644 --- a/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake +++ b/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake @@ -115,6 +115,8 @@ instrument(cmake-command-bad-arg NO_WARN) instrument(cmake-command-parallel-install BUILD INSTALL TEST NO_WARN INSTALL_PARALLEL DYNAMIC_QUERY CHECK_SCRIPT check-data-dir.cmake) + +# FIXME(#26668) This does not work on Windows if (UNIX AND ${RunCMake_GENERATOR} MATCHES "^Ninja") instrument(cmake-command-ninja NO_WARN BUILD_MAKE_PROGRAM -- cgit v0.12