cmCacheManager: Port consumers to non-iterator API.

This simplifies reasoning about the follow-up commit which ports
away from cmCacheManager to a class with the same method names.
This commit is contained in:
Stephen Kelly 2015-04-05 10:48:04 +02:00
parent 7b7ae3b1a1
commit 9410e24a4a
13 changed files with 117 additions and 115 deletions

View File

@ -366,18 +366,18 @@ bool cmFindBase::CheckForVariableInCache()
if(const char* cacheValue =
this->Makefile->GetDefinition(this->VariableName))
{
cmCacheManager::CacheIterator it =
this->Makefile->GetCacheManager()->
GetCacheIterator(this->VariableName.c_str());
cmCacheManager* manager = this->Makefile->GetCacheManager();
const char* cacheEntry = manager->GetCacheEntryValue(this->VariableName);
bool found = !cmSystemTools::IsNOTFOUND(cacheValue);
bool cached = !it.IsAtEnd();
bool cached = cacheEntry ? true : false;
if(found)
{
// If the user specifies the entry on the command line without a
// type we should add the type and docstring but keep the
// original value. Tell the subclass implementations to do
// this.
if(cached && it.GetType() == cmCacheManager::UNINITIALIZED)
if(cached && manager->GetCacheEntryType(this->VariableName)
== cmCacheManager::UNINITIALIZED)
{
this->AlreadyInCacheWithoutMetaInfo = true;
}
@ -385,7 +385,8 @@ bool cmFindBase::CheckForVariableInCache()
}
else if(cached)
{
const char* hs = it.GetProperty("HELPSTRING");
const char* hs = manager->GetCacheEntryProperty(this->VariableName,
"HELPSTRING");
this->VariableDocumentation = hs?hs:"(none)";
}
}

View File

@ -391,11 +391,10 @@ bool cmGetPropertyCommand::HandleCacheMode()
}
const char* value = 0;
cmCacheManager::CacheIterator it =
this->Makefile->GetCacheManager()->GetCacheIterator(this->Name.c_str());
if(!it.IsAtEnd())
if(this->Makefile->GetCacheManager()->GetCacheEntryValue(this->Name))
{
value = it.GetProperty(this->PropertyName);
value = this->Makefile->GetCacheManager()
->GetCacheEntryProperty(this->Name, this->PropertyName);
}
this->StoreResult(value);
return true;

View File

@ -1559,9 +1559,7 @@ void cmGlobalGenerator::CheckLocalGenerators()
cmSystemTools::IsNOTFOUND(lib->first.c_str()))
{
std::string varName = lib->first.substr(0, lib->first.size()-9);
cmCacheManager::CacheIterator it =
manager->GetCacheIterator(varName.c_str());
if(it.GetPropertyAsBool("ADVANCED"))
if(manager->GetCacheEntryPropertyAsBool(varName, "ADVANCED"))
{
varName += " (ADVANCED)";
}
@ -1592,9 +1590,7 @@ void cmGlobalGenerator::CheckLocalGenerators()
cmSystemTools::IsNOTFOUND(incDir->c_str()))
{
std::string varName = incDir->substr(0, incDir->size()-9);
cmCacheManager::CacheIterator it =
manager->GetCacheIterator(varName.c_str());
if(it.GetPropertyAsBool("ADVANCED"))
if(manager->GetCacheEntryPropertyAsBool(varName, "ADVANCED"))
{
varName += " (ADVANCED)";
}

View File

@ -1848,8 +1848,8 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
}
}
this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0, doc,
type);
this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
doc, type);
// if there was a definition then remove it
this->Internal->VarStack.top().Set(name, 0);
}
@ -2499,12 +2499,10 @@ std::vector<std::string> cmMakefile
this->Internal->VarStack.top().ClosureKeys();
res.insert(res.end(), definitions.begin(), definitions.end());
}
cmCacheManager::CacheIterator cit =
this->GetCacheManager()->GetCacheIterator();
for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
{
res.push_back(cit.GetName());
}
std::vector<std::string> cacheKeys =
this->GetCacheManager()->GetCacheEntryKeys();
res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
std::sort(res.begin(), res.end());
return res;
}

View File

@ -37,24 +37,19 @@ bool cmMarkAsAdvancedCommand
{
std::string variable = args[i];
cmCacheManager* manager = this->Makefile->GetCacheManager();
cmCacheManager::CacheIterator it =
manager->GetCacheIterator(variable.c_str());
if ( it.IsAtEnd() )
if (!manager->GetCacheEntryValue(variable))
{
this->Makefile->GetCacheManager()
->AddCacheEntry(variable, 0, 0,
cmCacheManager::UNINITIALIZED);
manager->AddCacheEntry(variable, 0, 0, cmCacheManager::UNINITIALIZED);
overwrite = true;
}
it.Find(variable);
if ( it.IsAtEnd() )
if (!manager->GetCacheEntryValue(variable))
{
cmSystemTools::Error("This should never happen...");
return false;
}
if ( !it.PropertyExists("ADVANCED") || overwrite )
if (!manager->GetCacheEntryProperty(variable, "ADVANCED") || overwrite)
{
it.SetProperty("ADVANCED", value);
manager->SetCacheEntryProperty(variable, "ADVANCED", value);
}
}
return true;

View File

@ -42,16 +42,16 @@ bool cmOptionCommand
std::string initialValue = "Off";
// Now check and see if the value has been stored in the cache
// already, if so use that value and don't look for the program
cmCacheManager::CacheIterator it =
this->Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
if(!it.IsAtEnd())
cmCacheManager* manager = this->Makefile->GetCacheManager();
const char* existingValue = manager->GetCacheEntryValue(args[0]);
if(existingValue)
{
if ( it.GetType() != cmCacheManager::UNINITIALIZED )
if (manager->GetCacheEntryType(args[0]) != cmCacheManager::UNINITIALIZED)
{
it.SetProperty("HELPSTRING", args[1].c_str());
manager->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
return true;
}
initialValue = it.GetValue();
initialValue = existingValue;
}
if(args.size() == 3)
{

View File

@ -136,9 +136,10 @@ bool cmSetCommand
}
// see if this is already in the cache
cmCacheManager::CacheIterator it =
this->Makefile->GetCacheManager()->GetCacheIterator(variable);
if(!it.IsAtEnd() && (it.GetType() != cmCacheManager::UNINITIALIZED))
cmCacheManager* manager = this->Makefile->GetCacheManager();
const char* existingValue = manager->GetCacheEntryValue(variable);
if(existingValue &&
(manager->GetCacheEntryType(variable) != cmCacheManager::UNINITIALIZED))
{
// if the set is trying to CACHE the value but the value
// is already in the cache and the type is not internal

View File

@ -452,11 +452,11 @@ bool cmSetPropertyCommand::HandleCacheMode()
// Get the source file.
cmMakefile* mf = this->GetMakefile();
cmake* cm = mf->GetCMakeInstance();
cmCacheManager::CacheIterator it =
cm->GetCacheManager()->GetCacheIterator(ni->c_str());
if(!it.IsAtEnd())
const char* existingValue
= cm->GetCacheManager()->GetCacheEntryValue(*ni);
if(existingValue)
{
if(!this->HandleCacheEntry(it))
if(!this->HandleCacheEntry(*ni))
{
return false;
}
@ -474,22 +474,25 @@ bool cmSetPropertyCommand::HandleCacheMode()
}
//----------------------------------------------------------------------------
bool cmSetPropertyCommand::HandleCacheEntry(cmCacheManager::CacheIterator& it)
bool cmSetPropertyCommand::HandleCacheEntry(std::string const& cacheKey)
{
// Set or append the property.
const char* name = this->PropertyName.c_str();
const char* value = this->PropertyValue.c_str();
cmCacheManager* manager = this->Makefile->GetCacheManager();
if (this->Remove)
{
value = 0;
manager->RemoveCacheEntryProperty(cacheKey, name);
return true;
}
if(this->AppendMode)
{
it.AppendProperty(name, value, this->AppendAsString);
manager->AppendCacheEntryProperty(cacheKey, name, value,
this->AppendAsString);
}
else
{
it.SetProperty(name, value);
manager->SetCacheEntryProperty(cacheKey, name, value);
}
return true;

View File

@ -61,7 +61,7 @@ private:
bool HandleTestMode();
bool HandleTest(cmTest* test);
bool HandleCacheMode();
bool HandleCacheEntry(cmCacheManager::CacheIterator&);
bool HandleCacheEntry(std::string const&);
bool HandleInstallMode();
bool HandleInstall(cmInstalledFile* file);
};

View File

@ -264,11 +264,12 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
comment.c_str(),
cmCacheManager::STRING);
cmCacheManager::CacheIterator it = this->Makefile->GetCacheManager()->
GetCacheIterator(this->RunResultVariable.c_str());
if ( !it.IsAtEnd() )
cmCacheManager* manager = this->Makefile->GetCacheManager();
const char* existingValue
= manager->GetCacheEntryValue(this->RunResultVariable);
if (existingValue)
{
it.SetProperty("ADVANCED", "1");
manager->SetCacheEntryProperty(this->RunResultVariable, "ADVANCED", "1");
}
error = true;
@ -290,11 +291,13 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
"PLEASE_FILL_OUT-NOTFOUND",
comment.c_str(),
cmCacheManager::STRING);
cmCacheManager::CacheIterator it = this->Makefile->GetCacheManager()->
GetCacheIterator(internalRunOutputName.c_str());
if ( !it.IsAtEnd() )
cmCacheManager* manager = this->Makefile->GetCacheManager();
const char* existing =
manager->GetCacheEntryValue(internalRunOutputName);
if (existing)
{
it.SetProperty("ADVANCED", "1");
manager->SetCacheEntryProperty(internalRunOutputName,
"ADVANCED", "1");
}
error = true;

View File

@ -41,9 +41,9 @@ bool cmVariableRequiresCommand
requirementsMet = false;
notSet += args[i];
notSet += "\n";
cmCacheManager::CacheIterator it =
this->Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str());
if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
cmCacheManager* manager = this->Makefile->GetCacheManager();
if(manager->GetCacheEntryValue(args[i]) &&
manager->GetCacheEntryPropertyAsBool(args[i], "ADVANCED"))
{
hasAdvanced = true;
}

View File

@ -403,17 +403,18 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str());
//go through all cache entries and collect the vars which will be removed
std::vector<std::string> entriesToDelete;
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator();
for ( it.Begin(); !it.IsAtEnd(); it.Next() )
std::vector<std::string> cacheKeys =
this->CacheManager->GetCacheEntryKeys();
for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
it != cacheKeys.end(); ++it)
{
cmCacheManager::CacheEntryType t = it.GetType();
cmCacheManager::CacheEntryType t =
this->CacheManager->GetCacheEntryType(*it);
if(t != cmCacheManager::STATIC)
{
std::string entryName = it.GetName();
if (regex.find(entryName.c_str()))
if (regex.find(it->c_str()))
{
entriesToDelete.push_back(entryName);
entriesToDelete.push_back(*it);
}
}
}
@ -917,16 +918,18 @@ void cmake::SetDirectoriesFromFile(const char* arg)
// If there is a CMakeCache.txt file, use its settings.
if(!cachePath.empty())
{
cmCacheManager* cachem = this->GetCacheManager();
cmCacheManager::CacheIterator it = cachem->NewIterator();
if(this->LoadCache(cachePath) &&
it.Find("CMAKE_HOME_DIRECTORY"))
if(this->LoadCache(cachePath))
{
this->SetHomeOutputDirectory(cachePath);
this->SetStartOutputDirectory(cachePath);
this->SetHomeDirectory(it.GetValue());
this->SetStartDirectory(it.GetValue());
return;
const char* existingValue =
this->CacheManager->GetCacheEntryValue("CMAKE_HOME_DIRECTORY");
if (existingValue)
{
this->SetHomeOutputDirectory(cachePath);
this->SetStartOutputDirectory(cachePath);
this->SetHomeDirectory(existingValue);
this->SetStartDirectory(existingValue);
return;
}
}
}
@ -1575,11 +1578,11 @@ int cmake::ActualConfigure()
("CMAKE_USE_RELATIVE_PATHS", "OFF",
"If true, cmake will use relative paths in makefiles and projects.",
cmCacheManager::BOOL);
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
if ( !it.PropertyExists("ADVANCED") )
if (!this->CacheManager->GetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
"ADVANCED"))
{
it.SetProperty("ADVANCED", "1");
this->CacheManager->SetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
"ADVANCED", "1");
}
}
@ -2314,17 +2317,9 @@ const char *cmake::GetProperty(const std::string& prop,
std::string output = "";
if ( prop == "CACHE_VARIABLES" )
{
cmCacheManager::CacheIterator cit =
this->GetCacheManager()->GetCacheIterator();
for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
{
if (!output.empty())
{
output += ";";
}
output += cit.GetName();
}
this->SetProperty("CACHE_VARIABLES", output.c_str());
std::vector<std::string> cacheKeys =
this->CacheManager->GetCacheEntryKeys();
this->SetProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
}
else if ( prop == "COMMANDS" )
{
@ -2686,9 +2681,9 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
if(t == cmake::AUTHOR_WARNING)
{
// Allow suppression of these warnings.
cmCacheManager::CacheIterator it = this->CacheManager
->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
if(!it.IsAtEnd() && it.GetValueAsBool())
const char* suppress = this->CacheManager->GetCacheEntryValue(
"CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
if(suppress && cmSystemTools::IsOn(suppress))
{
return;
}
@ -2801,37 +2796,42 @@ int cmake::Build(const std::string& dir,
}
std::string cachePath = dir;
cmSystemTools::ConvertToUnixSlashes(cachePath);
cmCacheManager::CacheIterator it = this->GetCacheManager()->NewIterator();
if(!this->LoadCache(cachePath))
{
std::cerr << "Error: could not load cache\n";
return 1;
}
if(!it.Find("CMAKE_GENERATOR"))
const char* cachedGenerator =
this->CacheManager->GetCacheEntryValue("CMAKE_GENERATOR");
if(!cachedGenerator)
{
std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
return 1;
}
cmsys::auto_ptr<cmGlobalGenerator> gen(
this->CreateGlobalGenerator(it.GetValue()));
this->CreateGlobalGenerator(cachedGenerator));
if(!gen.get())
{
std::cerr << "Error: could create CMAKE_GENERATOR \""
<< it.GetValue() << "\"\n";
<< cachedGenerator << "\"\n";
return 1;
}
std::string output;
std::string projName;
if(!it.Find("CMAKE_PROJECT_NAME"))
const char* cachedProjectName =
this->CacheManager->GetCacheEntryValue("CMAKE_PROJECT_NAME");
if(!cachedProjectName)
{
std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
return 1;
}
projName = it.GetValue();
projName = cachedProjectName;
bool verbose = false;
if(it.Find("CMAKE_VERBOSE_MAKEFILE"))
const char* cachedVerbose =
this->CacheManager->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
if(cachedVerbose)
{
verbose = it.GetValueAsBool();
verbose = cmSystemTools::IsOn(cachedVerbose);
}
return gen->Build("", dir,
projName, target,

View File

@ -328,25 +328,31 @@ int do_cmake(int ac, char const* const* av)
int res = cm.Run(args, view_only);
if ( list_cached || list_all_cached )
{
cmCacheManager::CacheIterator it =
cm.GetCacheManager()->GetCacheIterator();
std::cout << "-- Cache values" << std::endl;
for ( it.Begin(); !it.IsAtEnd(); it.Next() )
std::vector<std::string> keys =
cm.GetCacheManager()->GetCacheEntryKeys();
for (std::vector<std::string>::const_iterator it = keys.begin();
it != keys.end(); ++it)
{
cmCacheManager::CacheEntryType t = it.GetType();
cmCacheManager::CacheEntryType t =
cm.GetCacheManager()->GetCacheEntryType(*it);
if ( t != cmCacheManager::INTERNAL && t != cmCacheManager::STATIC &&
t != cmCacheManager::UNINITIALIZED )
{
bool advanced = it.PropertyExists("ADVANCED");
if ( list_all_cached || !advanced)
const char* advancedProp =
cm.GetCacheManager()->GetCacheEntryProperty(*it, "ADVANCED");
if ( list_all_cached || !advancedProp)
{
if ( list_help )
{
std::cout << "// " << it.GetProperty("HELPSTRING") << std::endl;
std::cout << "// "
<< cm.GetCacheManager()->GetCacheEntryProperty(*it,
"HELPSTRING") << std::endl;
}
std::cout << it.GetName() << ":" <<
cmCacheManager::TypeToString(it.GetType())
<< "=" << it.GetValue() << std::endl;
std::cout << *it << ":" <<
cmCacheManager::TypeToString(t)
<< "=" << cm.GetCacheManager()->GetCacheEntryValue(*it)
<< std::endl;
if ( list_help )
{
std::cout << std::endl;