Add API for cache loading, deleting and saving to the cmake class.

Migrate existing users of the CacheManager API to use the new
API.  The CacheManager will be going away soon.
This commit is contained in:
Stephen Kelly 2015-04-05 00:07:04 +02:00
parent 08c642c6ae
commit 1fe7f24c2b
9 changed files with 61 additions and 21 deletions

View File

@ -18,7 +18,6 @@
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include <cmsys/Process.h> #include <cmsys/Process.h>
#include "cmCTestTestHandler.h" #include "cmCTestTestHandler.h"
#include "cmCacheManager.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler() cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
@ -255,7 +254,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
cm.SetGeneratorToolset(this->BuildGeneratorToolset); cm.SetGeneratorToolset(this->BuildGeneratorToolset);
// Load the cache to make CMAKE_MAKE_PROGRAM available. // Load the cache to make CMAKE_MAKE_PROGRAM available.
cm.GetCacheManager()->LoadCache(this->BinaryDir); cm.LoadCache(this->BinaryDir);
} }
else else
{ {

View File

@ -639,7 +639,7 @@ int cmCursesMainForm::Configure(int noconfigure)
// always save the current gui values to disk // always save the current gui values to disk
this->FillCacheManagerFromUI(); this->FillCacheManagerFromUI();
this->CMakeInstance->GetCacheManager()->SaveCache( this->CMakeInstance->SaveCache(
this->CMakeInstance->GetHomeOutputDirectory()); this->CMakeInstance->GetHomeOutputDirectory());
this->LoadCache(0); this->LoadCache(0);

View File

@ -96,7 +96,7 @@ void QCMake::setBinaryDirectory(const QString& _dir)
emit this->binaryDirChanged(this->BinaryDirectory); emit this->binaryDirChanged(this->BinaryDirectory);
cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
this->setGenerator(QString()); this->setGenerator(QString());
if(!this->CMakeInstance->GetCacheManager()->LoadCache( if(!this->CMakeInstance->LoadCache(
this->BinaryDirectory.toLocal8Bit().data())) this->BinaryDirectory.toLocal8Bit().data()))
{ {
QDir testDir(this->BinaryDirectory); QDir testDir(this->BinaryDirectory);
@ -270,7 +270,7 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
} }
} }
cachem->SaveCache(this->BinaryDirectory.toLocal8Bit().data()); this->CMakeInstance->SaveCache(this->BinaryDirectory.toLocal8Bit().data());
} }
QCMakePropertyList QCMake::properties() const QCMakePropertyList QCMake::properties() const
@ -397,9 +397,9 @@ QStringList QCMake::availableGenerators() const
void QCMake::deleteCache() void QCMake::deleteCache()
{ {
// delete cache // delete cache
this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toLocal8Bit().data()); this->CMakeInstance->DeleteCache(this->BinaryDirectory.toLocal8Bit().data());
// reload to make our cache empty // reload to make our cache empty
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit no generator and no properties // emit no generator and no properties
this->setGenerator(QString()); this->setGenerator(QString());
QCMakePropertyList props = this->properties(); QCMakePropertyList props = this->properties();
@ -412,7 +412,7 @@ void QCMake::reloadCache()
QCMakePropertyList props; QCMakePropertyList props;
emit this->propertiesChanged(props); emit this->propertiesChanged(props);
// reload // reload
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit new cache properties // emit new cache properties
props = this->properties(); props = this->properties();
emit this->propertiesChanged(props); emit this->propertiesChanged(props);

View File

@ -2281,7 +2281,7 @@ bool cmCTest::AddVariableDefinition(const std::string &arg)
std::string value; std::string value;
cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED; cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
if (cmCacheManager::ParseEntry(arg, name, value, type)) if (cmake::ParseCacheEntry(arg, name, value, type))
{ {
this->Definitions[name] = value; this->Definitions[name] = value;
return true; return true;

View File

@ -223,7 +223,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(), mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
cacheEntryName.c_str(), cmCacheManager::STRING, cacheEntryName.c_str(), cmCacheManager::STRING,
true); true);
mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory()); mf->GetCMakeInstance()->SaveCache(mf->GetHomeOutputDirectory());
} }
else if (envVarValue==0 && cacheValue!=0) else if (envVarValue==0 && cacheValue!=0)
{ {
@ -244,7 +244,7 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(cmGeneratedFileStream& fout,
mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(), mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
cacheEntryName.c_str(), cmCacheManager::STRING, cacheEntryName.c_str(), cmCacheManager::STRING,
true); true);
mf->GetCacheManager()->SaveCache(mf->GetHomeOutputDirectory()); mf->GetCMakeInstance()->SaveCache(mf->GetHomeOutputDirectory());
} }
} }

View File

@ -3703,7 +3703,7 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
// Since this call may have created new cache entries, save the cache: // Since this call may have created new cache entries, save the cache:
// //
root->GetMakefile()->GetCacheManager()->SaveCache( root->GetMakefile()->GetCMakeInstance()->SaveCache(
root->GetMakefile()->GetHomeOutputDirectory()); root->GetMakefile()->GetHomeOutputDirectory());
} }

View File

@ -81,8 +81,8 @@ bool cmLoadCacheCommand
{ {
break; break;
} }
this->Makefile->GetCacheManager()->LoadCache(args[i], false, this->Makefile->GetCMakeInstance()->LoadCache(args[i], false,
excludes, includes); excludes, includes);
} }
@ -173,7 +173,7 @@ void cmLoadCacheCommand::CheckLine(const char* line)
std::string var; std::string var;
std::string value; std::string value;
cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED; cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
if(cmCacheManager::ParseEntry(line, var, value, type)) if(cmake::ParseCacheEntry(line, var, value, type))
{ {
// Found a real entry. See if this one was requested. // Found a real entry. See if this one was requested.
if(this->VariablesToRead.find(var) != this->VariablesToRead.end()) if(this->VariablesToRead.find(var) != this->VariablesToRead.end())

View File

@ -917,7 +917,7 @@ void cmake::SetDirectoriesFromFile(const char* arg)
{ {
cmCacheManager* cachem = this->GetCacheManager(); cmCacheManager* cachem = this->GetCacheManager();
cmCacheManager::CacheIterator it = cachem->NewIterator(); cmCacheManager::CacheIterator it = cachem->NewIterator();
if(cachem->LoadCache(cachePath) && if(this->LoadCache(cachePath) &&
it.Find("CMAKE_HOME_DIRECTORY")) it.Find("CMAKE_HOME_DIRECTORY"))
{ {
this->SetHomeOutputDirectory(cachePath); this->SetHomeOutputDirectory(cachePath);
@ -1860,10 +1860,18 @@ void cmake::AddDefaultGenerators()
#endif #endif
} }
bool cmake::ParseCacheEntry(const std::string& entry,
std::string& var,
std::string& value,
cmCacheManager::CacheEntryType& type)
{
return cmCacheManager::ParseEntry(entry, var, value, type);
}
int cmake::LoadCache() int cmake::LoadCache()
{ {
// could we not read the cache // could we not read the cache
if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory())) if (!this->LoadCache(this->GetHomeOutputDirectory()))
{ {
// if it does exist, but isn't readable then warn the user // if it does exist, but isn't readable then warn the user
std::string cacheFile = this->GetHomeOutputDirectory(); std::string cacheFile = this->GetHomeOutputDirectory();
@ -1886,6 +1894,28 @@ int cmake::LoadCache()
return 0; return 0;
} }
bool cmake::LoadCache(const std::string& path)
{
return this->CacheManager->LoadCache(path);
}
bool cmake::LoadCache(const std::string& path, bool internal,
std::set<std::string>& excludes,
std::set<std::string>& includes)
{
return this->CacheManager->LoadCache(path, internal, excludes, includes);
}
bool cmake::SaveCache(const std::string& path)
{
return this->CacheManager->SaveCache(path);
}
bool cmake::DeleteCache(const std::string& path)
{
return this->CacheManager->DeleteCache(path);
}
void cmake::SetProgressCallback(ProgressCallbackType f, void *cd) void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
{ {
this->ProgressCallback = f; this->ProgressCallback = f;
@ -2764,9 +2794,8 @@ int cmake::Build(const std::string& dir,
} }
std::string cachePath = dir; std::string cachePath = dir;
cmSystemTools::ConvertToUnixSlashes(cachePath); cmSystemTools::ConvertToUnixSlashes(cachePath);
cmCacheManager* cachem = this->GetCacheManager(); cmCacheManager::CacheIterator it = this->GetCacheManager()->NewIterator();
cmCacheManager::CacheIterator it = cachem->NewIterator(); if(!this->LoadCache(cachePath))
if(!cachem->LoadCache(cachePath))
{ {
std::cerr << "Error: could not load cache\n"; std::cerr << "Error: could not load cache\n";
return 1; return 1;

View File

@ -18,11 +18,11 @@
#include "cmPropertyDefinitionMap.h" #include "cmPropertyDefinitionMap.h"
#include "cmPropertyMap.h" #include "cmPropertyMap.h"
#include "cmInstalledFile.h" #include "cmInstalledFile.h"
#include "cmCacheManager.h"
class cmGlobalGeneratorFactory; class cmGlobalGeneratorFactory;
class cmGlobalGenerator; class cmGlobalGenerator;
class cmLocalGenerator; class cmLocalGenerator;
class cmCacheManager;
class cmMakefile; class cmMakefile;
class cmCommand; class cmCommand;
class cmVariableWatch; class cmVariableWatch;
@ -173,7 +173,19 @@ class cmake
int Configure(); int Configure();
int ActualConfigure(); int ActualConfigure();
///! Break up a line like VAR:type="value" into var, type and value
static bool ParseCacheEntry(const std::string& entry,
std::string& var,
std::string& value,
cmCacheManager::CacheEntryType& type);
int LoadCache(); int LoadCache();
bool LoadCache(const std::string& path);
bool LoadCache(const std::string& path, bool internal,
std::set<std::string>& excludes,
std::set<std::string>& includes);
bool SaveCache(const std::string& path);
bool DeleteCache(const std::string& path);
void PreLoadCMakeFiles(); void PreLoadCMakeFiles();
///! Create a GlobalGenerator ///! Create a GlobalGenerator