diff options
author | Brad King <brad.king@kitware.com> | 2016-10-20 14:38:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-10-20 15:04:21 (GMT) |
commit | 010560be6674def3ce02d05dcf2331230d0c4e91 (patch) | |
tree | 656b301004d07296a990f20eeb91573bcee81fb3 | |
parent | 2d3aa94225e259c9bc1c0d469e6326b476d225c1 (diff) | |
download | CMake-010560be6674def3ce02d05dcf2331230d0c4e91.zip CMake-010560be6674def3ce02d05dcf2331230d0c4e91.tar.gz CMake-010560be6674def3ce02d05dcf2331230d0c4e91.tar.bz2 |
Ninja: Fail early on when ninja build tool does not run
Diagnose failure to run `ninja --version` and abort early. Otherwise we
end up aborting with a confusing message about ninja version "" being
too old.
Closes: #16378
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 13 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/NinjaToolMissing-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/NinjaToolMissing-stderr.txt | 6 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/NinjaToolMissing.cmake | 0 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/RunCMakeTest.cmake | 6 |
5 files changed, 24 insertions, 2 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 50550aa..f023a2a 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -564,8 +564,17 @@ bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) command.push_back(this->NinjaCommand); command.push_back("--version"); std::string version; - cmSystemTools::RunSingleCommand(command, &version, CM_NULLPTR, CM_NULLPTR, - CM_NULLPTR, cmSystemTools::OUTPUT_NONE); + std::string error; + if (!cmSystemTools::RunSingleCommand(command, &version, &error, CM_NULLPTR, + CM_NULLPTR, + cmSystemTools::OUTPUT_NONE)) { + mf->IssueMessage(cmake::FATAL_ERROR, "Running\n '" + + cmJoin(command, "' '") + "'\n" + "failed with:\n " + + error); + cmSystemTools::SetFatalErrorOccured(); + return false; + } this->NinjaVersion = cmSystemTools::TrimWhitespace(version); this->CheckNinjaFeatures(); } diff --git a/Tests/RunCMake/Ninja/NinjaToolMissing-result.txt b/Tests/RunCMake/Ninja/NinjaToolMissing-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Ninja/NinjaToolMissing-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Ninja/NinjaToolMissing-stderr.txt b/Tests/RunCMake/Ninja/NinjaToolMissing-stderr.txt new file mode 100644 index 0000000..1214288 --- /dev/null +++ b/Tests/RunCMake/Ninja/NinjaToolMissing-stderr.txt @@ -0,0 +1,6 @@ +^CMake Error at CMakeLists.txt:[0-9]+ \(project\): + Running + + 'ninja-tool-missing' '--version' + + failed with: diff --git a/Tests/RunCMake/Ninja/NinjaToolMissing.cmake b/Tests/RunCMake/Ninja/NinjaToolMissing.cmake new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/Ninja/NinjaToolMissing.cmake diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 778f2c1..446dc3c 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -15,6 +15,12 @@ else() message(FATAL_ERROR "'ninja --version' reported:\n${ninja_out}") endif() +function(run_NinjaToolMissing) + set(RunCMake_MAKE_PROGRAM ninja-tool-missing) + run_cmake(NinjaToolMissing) +endfunction() +run_NinjaToolMissing() + function(run_CMP0058 case) # Use a single build tree for a few tests without cleaning. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0058-${case}-build) |