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 1f2c12ebd1
commit 14973054a2
9 changed files with 61 additions and 21 deletions

View File

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

View File

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

View File

@ -96,7 +96,7 @@ void QCMake::setBinaryDirectory(const QString& _dir)
emit this->binaryDirChanged(this->BinaryDirectory);
cmCacheManager *cachem = this->CMakeInstance->GetCacheManager();
this->setGenerator(QString());
if(!this->CMakeInstance->GetCacheManager()->LoadCache(
if(!this->CMakeInstance->LoadCache(
this->BinaryDirectory.toLocal8Bit().data()))
{
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
@ -397,9 +397,9 @@ QStringList QCMake::availableGenerators() const
void QCMake::deleteCache()
{
// delete cache
this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toLocal8Bit().data());
this->CMakeInstance->DeleteCache(this->BinaryDirectory.toLocal8Bit().data());
// 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
this->setGenerator(QString());
QCMakePropertyList props = this->properties();
@ -412,7 +412,7 @@ void QCMake::reloadCache()
QCMakePropertyList props;
emit this->propertiesChanged(props);
// reload
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit new cache properties
props = this->properties();
emit this->propertiesChanged(props);

View File

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

View File

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

View File

@ -81,8 +81,8 @@ bool cmLoadCacheCommand
{
break;
}
this->Makefile->GetCacheManager()->LoadCache(args[i], false,
excludes, includes);
this->Makefile->GetCMakeInstance()->LoadCache(args[i], false,
excludes, includes);
}
@ -173,7 +173,7 @@ void cmLoadCacheCommand::CheckLine(const char* line)
std::string var;
std::string value;
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.
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::CacheIterator it = cachem->NewIterator();
if(cachem->LoadCache(cachePath) &&
if(this->LoadCache(cachePath) &&
it.Find("CMAKE_HOME_DIRECTORY"))
{
this->SetHomeOutputDirectory(cachePath);
@ -1860,10 +1860,18 @@ void cmake::AddDefaultGenerators()
#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()
{
// 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
std::string cacheFile = this->GetHomeOutputDirectory();
@ -1886,6 +1894,28 @@ int cmake::LoadCache()
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)
{
this->ProgressCallback = f;
@ -2764,9 +2794,8 @@ int cmake::Build(const std::string& dir,
}
std::string cachePath = dir;
cmSystemTools::ConvertToUnixSlashes(cachePath);
cmCacheManager* cachem = this->GetCacheManager();
cmCacheManager::CacheIterator it = cachem->NewIterator();
if(!cachem->LoadCache(cachePath))
cmCacheManager::CacheIterator it = this->GetCacheManager()->NewIterator();
if(!this->LoadCache(cachePath))
{
std::cerr << "Error: could not load cache\n";
return 1;

View File

@ -18,11 +18,11 @@
#include "cmPropertyDefinitionMap.h"
#include "cmPropertyMap.h"
#include "cmInstalledFile.h"
#include "cmCacheManager.h"
class cmGlobalGeneratorFactory;
class cmGlobalGenerator;
class cmLocalGenerator;
class cmCacheManager;
class cmMakefile;
class cmCommand;
class cmVariableWatch;
@ -173,7 +173,19 @@ class cmake
int Configure();
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();
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();
///! Create a GlobalGenerator