fixes to backup restore options

This commit is contained in:
Ken Martin 2004-01-23 09:44:47 -05:00
parent 01e4c82bb4
commit da76ed122f
2 changed files with 97 additions and 32 deletions

View File

@ -2931,6 +2931,30 @@ const char* cmCTest::GetTestStatus(int status)
return statuses[status]; return statuses[status];
} }
void cmCTest::RestoreBackupDirectories(bool backup,
const char *srcDir,
const char *binDir,
const char *backupSrcDir,
const char *backupBinDir)
{
// if we backed up the dirs and the build failed, then restore
// the backed up dirs
if (backup)
{
// if for some reason those directories exist then first delete them
if (cmSystemTools::FileExists(srcDir))
{
cmSystemTools::RemoveADirectory(srcDir);
}
if (cmSystemTools::FileExists(binDir))
{
cmSystemTools::RemoveADirectory(binDir);
}
// rename the src and binary directories
rename(backupSrcDir, srcDir);
rename(backupBinDir, binDir);
}
}
int cmCTest::RunConfigurationScript() int cmCTest::RunConfigurationScript()
{ {
@ -2940,7 +2964,7 @@ int cmCTest::RunConfigurationScript()
// make sure the file exists // make sure the file exists
if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str())) if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str()))
{ {
return -1; return 1;
} }
// create a cmake instance to read the configuration script // create a cmake instance to read the configuration script
@ -2961,7 +2985,7 @@ int cmCTest::RunConfigurationScript()
m_ConfigurationScript).c_str()); m_ConfigurationScript).c_str());
if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str())) if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
{ {
return -2; return 2;
} }
// no popup widows // no popup widows
@ -2973,13 +2997,23 @@ int cmCTest::RunConfigurationScript()
const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY"); const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND"); const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT"); const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
const char *ctestRoot = mf->GetDefinition("CTEST_DASHBOARD_ROOT");
bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE"); bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE");
// in order to back we also must have the cvs root
const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
const char *cvsCheckOut = mf->GetDefinition("CTEST_CVS_CHECKOUT");
if (backup && !cvsCheckOut)
{
cmSystemTools::Error("Backup was requested without a cvs checkout");
return 3;
}
// make sure the required info is here // make sure the required info is here
if (!srcDir || !binDir || !ctestCmd) if (!srcDir || !binDir || !ctestCmd)
{ {
cmSystemTools::Error("Some required settings in the configuration file were missing"); cmSystemTools::Error("Some required settings in the configuration file were missing");
return -3; return 4;
} }
// set any environment variables // set any environment variables
@ -3010,6 +3044,12 @@ int cmCTest::RunConfigurationScript()
} }
} }
// local variables
std::string command;
std::string output;
int retVal = 0;
bool res;
// compute the backup names // compute the backup names
std::string backupSrcDir = srcDir; std::string backupSrcDir = srcDir;
backupSrcDir += "_CMakeBackup"; backupSrcDir += "_CMakeBackup";
@ -3032,6 +3072,30 @@ int cmCTest::RunConfigurationScript()
// first rename the src and binary directories // first rename the src and binary directories
rename(srcDir, backupSrcDir.c_str()); rename(srcDir, backupSrcDir.c_str());
rename(binDir, backupBinDir.c_str()); rename(binDir, backupBinDir.c_str());
// we must now checkout the src dir, first make the dir
if (!cmSystemTools::MakeDirectory(srcDir))
{
cmSystemTools::Error("Unable to create the src directory");
this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(),
backupBinDir.c_str());
return 5;
}
// then do the checkout
output = "";
res = cmSystemTools::RunSingleCommand(cvsCheckOut, &output,
&retVal, ctestRoot,
m_Verbose, 0 /*m_TimeOut*/);
if (!res || retVal != 0)
{
cmSystemTools::Error("Unable to perform cvs checkout ");
this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(),
backupBinDir.c_str());
return 6;
}
} }
// clear the binary directory? // clear the binary directory?
@ -3052,17 +3116,15 @@ int cmCTest::RunConfigurationScript()
if (!cmSystemTools::MakeDirectory(binDir)) if (!cmSystemTools::MakeDirectory(binDir))
{ {
cmSystemTools::Error("Unable to create the binary directory"); cmSystemTools::Error("Unable to create the binary directory");
return -4; this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(),
backupBinDir.c_str());
return 7;
} }
} }
std::string command;
std::string output;
int retVal = 0;
bool res;
// do an initial cvs update as required // do an initial cvs update as required
const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
if (cvsCmd) if (cvsCmd)
{ {
command = cvsCmd; command = cvsCmd;
@ -3089,7 +3151,10 @@ int cmCTest::RunConfigurationScript()
if (!res || retVal != 0) if (!res || retVal != 0)
{ {
cmSystemTools::Error("Unable to perform extra cvs updates"); cmSystemTools::Error("Unable to perform extra cvs updates");
return -5; this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(),
backupBinDir.c_str());
return 8;
} }
} }
} }
@ -3105,7 +3170,10 @@ int cmCTest::RunConfigurationScript()
std::ofstream fout(cacheFile.c_str()); std::ofstream fout(cacheFile.c_str());
if(!fout) if(!fout)
{ {
return -6; this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(),
backupBinDir.c_str());
return 9;
} }
fout.write(initCache, strlen(initCache)); fout.write(initCache, strlen(initCache));
@ -3150,34 +3218,27 @@ int cmCTest::RunConfigurationScript()
if (!res || cmakeFailed || if (!res || cmakeFailed ||
retVal & CTEST_BUILD_ERRORS) retVal & CTEST_BUILD_ERRORS)
{ {
// if we backed up the dirs and the build failed, then restore this->RestoreBackupDirectories(backup, srcDir, binDir,
// the backed up dirs backupSrcDir.c_str(),
if (backup) backupBinDir.c_str());
{
// if for some reason those directories exist then first delete them
if (cmSystemTools::FileExists(srcDir))
{
cmSystemTools::RemoveADirectory(srcDir);
}
if (cmSystemTools::FileExists(binDir))
{
cmSystemTools::RemoveADirectory(binDir);
}
// rename the src and binary directories
rename(backupSrcDir.c_str(), srcDir);
rename(backupBinDir.c_str(), binDir);
}
if (cmakeFailed) if (cmakeFailed)
{ {
cmSystemTools::Error("Unable to run cmake"); cmSystemTools::Error("Unable to run cmake");
return -7; return 10;
} }
cmSystemTools::Error("Unable to run ctest"); cmSystemTools::Error("Unable to run ctest");
if (!res) if (!res)
{ {
return -8; return 11;
} }
return retVal; return retVal * 100;
}
// if all was succesful, delete the backup dirs to free up disk space
if (backup)
{
cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
cmSystemTools::RemoveADirectory(backupBinDir.c_str());
} }
return 0; return 0;

View File

@ -147,6 +147,10 @@ public:
int GenerateNotesFile(const char* files); int GenerateNotesFile(const char* files);
void RestoreBackupDirectories(bool backup,
const char *srcDir, const char *binDir,
const char *backupSrc, const char *backupBin);
private: private:
enum { enum {
FIRST_TEST = 0, FIRST_TEST = 0,