mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 11:22:21 -06:00
Makefiles: quote $(COLOR) expansions
This handles the case where `COLOR` is set to some ANSI-like color
sequence in the ambient environment. These sequences tend to include `;`
which terminates the command and tries to use the next component
(typically an integer, possibly with a trailing `m`) with errors like:
/bin/sh: line 1: 2: command not found
/bin/sh: line 1: 255: command not found
/bin/sh: line 1: 221: command not found
/bin/sh: line 1: 255m: command not found
Also add a test that sets `COLOR` in the environment which affects the
generated Makefiles behavior.
See: https://discourse.cmake.org/t/cmake-failing-gcc-compiler-checks/8277
This commit is contained in:
@@ -1222,7 +1222,7 @@ void cmLocalUnixMakefileGenerator3::AppendEcho(
|
||||
} else {
|
||||
// Use cmake to echo the text in color.
|
||||
cmd = cmStrCat(
|
||||
"@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ",
|
||||
"@$(CMAKE_COMMAND) -E cmake_echo_color \"--switch=$(COLOR)\" ",
|
||||
color_name);
|
||||
if (progress) {
|
||||
cmd += "--progress-dir=";
|
||||
|
||||
@@ -1525,7 +1525,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
|
||||
cmSystemTools::CollapseFullPath(this->InfoFileNameFull),
|
||||
cmOutputConverter::SHELL);
|
||||
if (this->LocalGenerator->GetColorMakefile()) {
|
||||
depCmd << " --color=$(COLOR)";
|
||||
depCmd << " \"--color=$(COLOR)\"";
|
||||
}
|
||||
commands.push_back(depCmd.str());
|
||||
|
||||
|
||||
9
Tests/RunCMake/Color/DiagColorInEnv.cmake
Normal file
9
Tests/RunCMake/Color/DiagColorInEnv.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
if (CMAKE_GENERATOR MATCHES "Makefiles")
|
||||
set(CMAKE_COLOR_DIAGNOSTICS 1)
|
||||
set(EXPECT_COLOR 1)
|
||||
endif ()
|
||||
include(DiagCommon.cmake)
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES "Makefiles" AND NOT DEFINED CMAKE_COLOR_MAKEFILE)
|
||||
message(FATAL_ERROR "CMAKE_COLOR_MAKEFILE incorrectly undefined.")
|
||||
endif()
|
||||
@@ -12,3 +12,9 @@ endfunction()
|
||||
run_Diag(On -DCMAKE_COLOR_DIAGNOSTICS=ON)
|
||||
run_Diag(Off -DCMAKE_COLOR_DIAGNOSTICS=OFF)
|
||||
run_Diag(Default)
|
||||
|
||||
# Test with `COLOR` in the ambient environment set to an ANSI-like color
|
||||
# sequence. `$(COLOR)` is used in the Makefiles generator to control whether or
|
||||
# not to do such color sequences itself.
|
||||
set(ENV{COLOR} "[38;2;255;221;255m")
|
||||
run_Diag(ColorInEnv)
|
||||
|
||||
Reference in New Issue
Block a user