cmake/Source/CTest/cmCTestScriptHandler.h

183 lines
5.0 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
2018-04-23 21:13:27 +02:00
#include <chrono>
2020-02-01 23:06:01 +01:00
#include <memory>
2016-10-30 18:24:19 +01:00
#include <string>
#include <vector>
2024-04-14 22:45:38 +02:00
#include "cmsys/Status.hxx"
2020-02-01 23:06:01 +01:00
#include "cmCTestGenericHandler.h"
#include "cmDuration.h"
2016-10-30 18:24:19 +01:00
class cmCTest;
class cmCTestCommand;
class cmGlobalGenerator;
2016-10-30 18:24:19 +01:00
class cmMakefile;
class cmake;
/** \class cmCTestScriptHandler
* \brief A class that handles ctest -S invocations
*
* CTest script is controlled using several variables that script has to
* specify and some optional ones. Required ones are:
* CTEST_SOURCE_DIRECTORY - Source directory of the project
* CTEST_BINARY_DIRECTORY - Binary directory of the project
* CTEST_COMMAND - Testing commands
*
* Optional variables are:
* CTEST_BACKUP_AND_RESTORE
* CTEST_CMAKE_COMMAND
* CTEST_CMAKE_OUTPUT_FILE_NAME
* CTEST_CONTINUOUS_DURATION
* CTEST_CONTINUOUS_MINIMUM_INTERVAL
* CTEST_CVS_CHECKOUT
* CTEST_CVS_COMMAND
* CTEST_UPDATE_COMMAND
* CTEST_DASHBOARD_ROOT
* CTEST_ENVIRONMENT
* CTEST_INITIAL_CACHE
* CTEST_START_WITH_EMPTY_BINARY_DIRECTORY
* CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE
*
* In addition the following variables can be used. The number can be 1-10.
* CTEST_EXTRA_UPDATES_1
* CTEST_EXTRA_UPDATES_2
* ...
* CTEST_EXTRA_UPDATES_10
*
* CTest script can use the following arguments CTest provides:
* CTEST_SCRIPT_ARG
* CTEST_SCRIPT_DIRECTORY
* CTEST_SCRIPT_NAME
*
*/
class cmCTestScriptHandler : public cmCTestGenericHandler
{
public:
2020-02-01 23:06:01 +01:00
using Superclass = cmCTestGenericHandler;
/**
* Add a script to run, and if is should run in the current process
*/
2021-09-14 00:13:48 +02:00
void AddConfigurationScript(const std::string&, bool pscope);
/**
2024-11-11 15:18:55 +01:00
* Run a dashboard using a specified configuration script
*/
2018-01-26 17:06:56 +01:00
int ProcessHandler() override;
/*
* Run a script
*/
2021-09-14 00:13:48 +02:00
static bool RunScript(cmCTest* ctest, cmMakefile* mf,
const std::string& script, bool InProcess,
int* returnValue);
int RunCurrentScript();
/*
* Empty Binary Directory
*/
2024-04-14 22:45:38 +02:00
static bool EmptyBinaryDirectory(const std::string& dir, std::string& err);
2009-10-04 10:30:41 +03:00
/*
* Write an initial CMakeCache.txt from the given contents.
*/
2021-09-14 00:13:48 +02:00
static bool WriteInitialCache(const std::string& directory,
const std::string& text);
2009-10-04 10:30:41 +03:00
/*
* Some elapsed time handling functions
*/
static void SleepInSeconds(unsigned int secondsToWait);
void UpdateElapsedTime();
2013-03-16 19:13:01 +02:00
/**
* Return the time remaianing that the script is allowed to run in
* seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
2018-04-23 21:13:27 +02:00
* not been set it returns a very large value.
*/
2018-04-23 21:13:27 +02:00
cmDuration GetRemainingTimeAllowed();
cmCTestScriptHandler();
2020-08-30 11:54:41 +02:00
cmCTestScriptHandler(const cmCTestScriptHandler&) = delete;
const cmCTestScriptHandler& operator=(const cmCTestScriptHandler&) = delete;
2018-01-26 17:06:56 +01:00
~cmCTestScriptHandler() override;
2018-01-26 17:06:56 +01:00
void Initialize() override;
void CreateCMake();
2020-08-30 11:54:41 +02:00
cmake* GetCMake() { return this->CMake.get(); }
2018-04-23 21:13:27 +02:00
void SetRunCurrentScript(bool value);
private:
// reads in a script
int ReadInScript(const std::string& total_script_arg);
int ExecuteScript(const std::string& total_script_arg);
// extract vars from the script to set ivars
int ExtractVariables();
// perform a CVS checkout of the source dir
int CheckOutSourceDir();
// perform any extra cvs updates that were requested
int PerformExtraUpdates();
// backup and restore dirs
int BackupDirectories();
void RestoreBackupDirectories();
int RunConfigurationScript(const std::string& script, bool pscope);
int RunConfigurationDashboard();
// Add ctest command
2020-02-01 23:06:01 +01:00
void AddCTestCommand(std::string const& name,
std::unique_ptr<cmCTestCommand> command);
2014-08-03 19:52:23 +02:00
// Try to remove the binary directory once
2024-04-14 22:45:38 +02:00
static cmsys::Status TryToRemoveBinaryDirectoryOnce(
const std::string& directoryPath);
2014-08-03 19:52:23 +02:00
2015-04-27 22:25:09 +02:00
std::vector<std::string> ConfigurationScripts;
std::vector<bool> ScriptProcessScope;
2018-04-23 21:13:27 +02:00
bool ShouldRunCurrentScript;
2020-08-30 11:54:41 +02:00
bool Backup = false;
bool EmptyBinDir = false;
bool EmptyBinDirOnce = false;
2015-04-27 22:25:09 +02:00
std::string SourceDir;
std::string BinaryDir;
std::string BackupSourceDir;
std::string BackupBinaryDir;
std::string CTestRoot;
std::string CVSCheckOut;
std::string CTestCmd;
std::string UpdateCmd;
std::string CTestEnv;
std::string InitialCache;
std::string CMakeCmd;
std::string CMOutFile;
std::vector<std::string> ExtraUpdates;
2020-08-30 11:54:41 +02:00
// the *60 is because the settings are in minutes but GetTime is seconds
double MinimumInterval = 30 * 60;
double ContinuousDuration = -1;
// what time in seconds did this script start running
2020-08-30 11:54:41 +02:00
std::chrono::steady_clock::time_point ScriptStartTime =
std::chrono::steady_clock::time_point();
2020-08-30 11:54:41 +02:00
std::unique_ptr<cmMakefile> Makefile;
cmMakefile* ParentMakefile = nullptr;
std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
std::unique_ptr<cmake> CMake;
};