cmake_language: Fix EXIT inside control flow blocks

These were missed in commit 1bb1769235 (cmake_language: Add EXIT
subcommand, 2024-01-05, v3.29.0-rc1~112^2).

Fixes: #25674
This commit is contained in:
Brad King
2024-02-13 16:45:43 -05:00
parent a3033d1a06
commit 86698eea85
21 changed files with 95 additions and 0 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!")