Просмотр исходного кода

Merge topic 'ctest_start_function_scope'

13347740 Help: add release notes, documentation for CTEST_RUN_CURRENT_SCRIPT behavior
74092d92 cmCTestScriptHandler: Add new field ShouldRunCurrentScript

Acked-by: Kitware Robot <[email protected]>
Merge-request: !1703
Brad King 8 лет назад
Родитель
Сommit
18153217e2

+ 1 - 0
Help/manual/cmake-variables.7.rst

@@ -513,6 +513,7 @@ Variables for CTest
    /variable/CTEST_P4_COMMAND
    /variable/CTEST_P4_OPTIONS
    /variable/CTEST_P4_UPDATE_OPTIONS
+   /variable/CTEST_RUN_CURRENT_SCRIPT
    /variable/CTEST_SCP_COMMAND
    /variable/CTEST_SITE
    /variable/CTEST_SOURCE_DIRECTORY

+ 8 - 0
Help/release/dev/ctest_start_function_scope.rst

@@ -0,0 +1,8 @@
+ctest_start_function_scope
+--------------------------
+
+* The :command:`ctest_start` command no longer sets
+  :variable:`CTEST_RUN_CURRENT_SCRIPT` due to issues with scoping if it is
+  called from inside a function. Instead, it sets an internal variable in
+  CTest. However, setting :variable:`CTEST_RUN_CURRENT_SCRIPT` to 0 at the
+  global scope still prevents the script from being re-run at the end.

+ 5 - 0
Help/variable/CTEST_RUN_CURRENT_SCRIPT.rst

@@ -0,0 +1,5 @@
+CTEST_RUN_CURRENT_SCRIPT
+------------------------
+
+Setting this to 0 prevents :manual:`ctest(1)` from being run again when it
+reaches the end of a script run by calling ``ctest -S``.

+ 9 - 2
Source/CTest/cmCTestScriptHandler.cxx

@@ -346,6 +346,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
   this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME",
                                 cmSystemTools::GetCMakeCommand().c_str());
   this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", true);
+  this->SetRunCurrentScript(true);
   this->UpdateElapsedTime();
 
   // add the script arg if defined
@@ -527,7 +528,8 @@ int cmCTestScriptHandler::RunConfigurationScript(
   }
 
   // only run the curent script if we should
-  if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT")) {
+  if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT") &&
+      this->ShouldRunCurrentScript) {
     return this->RunCurrentScript();
   }
   return result;
@@ -538,7 +540,7 @@ int cmCTestScriptHandler::RunCurrentScript()
   int result;
 
   // do not run twice
-  this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", false);
+  this->SetRunCurrentScript(false);
 
   // no popup widows
   cmSystemTools::SetRunCommandHideConsole(true);
@@ -980,3 +982,8 @@ cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed()
     std::chrono::steady_clock::now() - this->ScriptStartTime);
   return (timelimit - duration);
 }
+
+void cmCTestScriptHandler::SetRunCurrentScript(bool value)
+{
+  this->ShouldRunCurrentScript = value;
+}

+ 4 - 0
Source/CTest/cmCTestScriptHandler.h

@@ -107,6 +107,8 @@ public:
   void CreateCMake();
   cmake* GetCMake() { return this->CMake; }
 
+  void SetRunCurrentScript(bool value);
+
 private:
   // reads in a script
   int ReadInScript(const std::string& total_script_arg);
@@ -137,6 +139,8 @@ private:
   std::vector<std::string> ConfigurationScripts;
   std::vector<bool> ScriptProcessScope;
 
+  bool ShouldRunCurrentScript;
+
   bool Backup;
   bool EmptyBinDir;
   bool EmptyBinDirOnce;

+ 1 - 1
Source/CTest/cmCTestStartCommand.cxx

@@ -126,7 +126,7 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
     return false;
   }
 
-  this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
+  this->CTest->SetRunCurrentScript(false);
   this->CTest->SetSuppressUpdatingCTestConfiguration(true);
   int model = this->CTest->GetTestModelFromString(smodel);
   this->CTest->SetTestModel(model);

+ 8 - 0
Source/cmCTest.cxx

@@ -2797,6 +2797,14 @@ cmDuration cmCTest::MaxDuration()
   return cmDuration(1.0e7);
 }
 
+void cmCTest::SetRunCurrentScript(bool value)
+{
+  cmCTestScriptHandler* ch =
+    static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+
+  ch->SetRunCurrentScript(value);
+}
+
 void cmCTest::OutputTestErrors(std::vector<char> const& process_output)
 {
   std::string test_outputs("\n*** Test Failed:\n");

+ 2 - 0
Source/cmCTest.h

@@ -458,6 +458,8 @@ public:
   void GenerateSubprojectsOutput(cmXMLWriter& xml);
   std::vector<std::string> GetLabelsForSubprojects();
 
+  void SetRunCurrentScript(bool value);
+
 private:
   int RepeatTests;
   bool RepeatUntilFail;

+ 1 - 0
Tests/RunCMake/ctest_start/FunctionScope-stdout.txt

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

+ 2 - 0
Tests/RunCMake/ctest_start/RunCMakeTest.cmake

@@ -11,6 +11,8 @@ run_ctest_start(StartQuiet Experimental QUIET)
 
 run_ctest_start(ConfigInSource Experimental)
 
+run_ctest_start(FunctionScope Experimental QUIET)
+
 function(run_ConfigInBuild)
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ConfigInBuild-build)
   set(RunCMake_TEST_NO_CLEAN 1)

+ 9 - 1
Tests/RunCMake/ctest_start/test.cmake.in

@@ -9,5 +9,13 @@ set(CTEST_CMAKE_GENERATOR_PLATFORM      "@RunCMake_GENERATOR_PLATFORM@")
 set(CTEST_CMAKE_GENERATOR_TOOLSET       "@RunCMake_GENERATOR_TOOLSET@")
 set(CTEST_BUILD_CONFIGURATION           "$ENV{CMAKE_CONFIG_TYPE}")
 
+function(setup_tests)
+  ctest_start(${ctest_start_args})
+endfunction()
+
 set(ctest_start_args "@CASE_CTEST_START_ARGS@")
-ctest_start(${ctest_start_args})
+if("@CASE_NAME@" STREQUAL "FunctionScope")
+  setup_tests()
+else()
+  ctest_start(${ctest_start_args})
+endif()