Merge topic 'cmake-language-exit-code'

86698eea85 cmake_language: Fix EXIT inside control flow blocks
a3033d1a06 Tests: Remove unnecessary RunCMake.cmake_language expected result files

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Alex <leha-bot@yandex.ru>
Merge-request: !9250
This commit is contained in:
Brad King
2024-02-15 17:57:34 +00:00
committed by Kitware Robot
29 changed files with 95 additions and 3 deletions

View File

@@ -127,6 +127,10 @@ bool cmBlockFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
inStatus.SetContinueInvoked();
return true;
}
if (status.HasExitCode()) {
inStatus.SetExitCode(status.GetExitCode());
return true;
}
if (cmSystemTools::GetFatalErrorOccurred()) {
return true;
}

View File

@@ -272,6 +272,11 @@ auto cmForEachFunctionBlocker::invoke(
if (status.GetContinueInvoked()) {
break;
}
if (status.HasExitCode()) {
inStatus.SetExitCode(status.GetExitCode());
result.Break = true;
break;
}
if (cmSystemTools::GetFatalErrorOccurred()) {
result.Restore = false;
result.Break = true;

View File

@@ -124,6 +124,10 @@ bool cmFunctionHelperCommand::operator()(
makefile.RaiseScope(status.GetReturnVariables());
break;
}
if (status.HasExitCode()) {
inStatus.SetExitCode(status.GetExitCode());
break;
}
}
// pop scope on the makefile

View File

@@ -161,6 +161,10 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
inStatus.SetContinueInvoked();
return true;
}
if (status.HasExitCode()) {
inStatus.SetExitCode(status.GetExitCode());
return true;
}
}
}
return true;

View File

@@ -135,6 +135,10 @@ bool cmMacroHelperCommand::operator()(
inStatus.SetBreakInvoked();
return true;
}
if (status.HasExitCode()) {
inStatus.SetExitCode(status.GetExitCode());
return true;
}
}
return true;
}

View File

@@ -105,6 +105,10 @@ bool cmWhileFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
if (status.GetContinueInvoked()) {
break;
}
if (status.HasExitCode()) {
inStatus.SetExitCode(status.GetExitCode());
return true;
}
if (cmSystemTools::GetFatalErrorOccurred()) {
return true;
}

View File

@@ -91,6 +91,13 @@ run_cmake_script(exit_5_script)
run_cmake_script(exit_0_script_with_command)
run_cmake_script(exit_7_script_in_include)
run_cmake_script(exit_8_script_in_recursive_cmake_language)
run_cmake_script(exit_9_script_block)
run_cmake_script(exit_9_script_control)
run_cmake_script(exit_9_script_if)
run_cmake_script(exit_9_script_foreach)
run_cmake_script(exit_9_script_function)
run_cmake_script(exit_9_script_macro)
run_cmake_script(exit_9_script_while)
# Default log level
run_cmake_command(

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,5 @@
block()
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endblock()
message(FATAL_ERROR "This should not be reached!")

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,24 @@
function(exit_macro)
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endfunction()
function(exit_function)
exit_macro()
message(FATAL_ERROR "This should not be reached!")
endfunction()
block()
if(1)
foreach(i IN ITEMS a b)
while(1)
exit_function()
message(FATAL_ERROR "This should not be reached!")
endwhile()
message(FATAL_ERROR "This should not be reached!")
endforeach()
message(FATAL_ERROR "This should not be reached!")
endif()
message(FATAL_ERROR "This should not be reached!")
endblock()
message(FATAL_ERROR "This should not be reached!")

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,5 @@
foreach(i IN ITEMS a b)
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endforeach()
message(FATAL_ERROR "This should not be reached!")

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,6 @@
function(exit)
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endfunction()
exit()
message(FATAL_ERROR "This should not be reached!")

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,5 @@
if(1)
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endif()
message(FATAL_ERROR "This should not be reached!")

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,6 @@
macro(exit)
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endmacro()
exit()
message(FATAL_ERROR "This should not be reached!")

View File

@@ -0,0 +1 @@
^9$

View File

@@ -0,0 +1,5 @@
while(1)
cmake_language(EXIT 9)
message(FATAL_ERROR "This should not be reached!")
endwhile()
message(FATAL_ERROR "This should not be reached!")