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 f3922a9a5b
commit ba404938a2
13 changed files with 117 additions and 115 deletions

View File

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

View File

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

View File

@ -1559,9 +1559,7 @@ void cmGlobalGenerator::CheckLocalGenerators()
cmSystemTools::IsNOTFOUND(lib->first.c_str())) cmSystemTools::IsNOTFOUND(lib->first.c_str()))
{ {
std::string varName = lib->first.substr(0, lib->first.size()-9); std::string varName = lib->first.substr(0, lib->first.size()-9);
cmCacheManager::CacheIterator it = if(manager->GetCacheEntryPropertyAsBool(varName, "ADVANCED"))
manager->GetCacheIterator(varName.c_str());
if(it.GetPropertyAsBool("ADVANCED"))
{ {
varName += " (ADVANCED)"; varName += " (ADVANCED)";
} }
@ -1592,9 +1590,7 @@ void cmGlobalGenerator::CheckLocalGenerators()
cmSystemTools::IsNOTFOUND(incDir->c_str())) cmSystemTools::IsNOTFOUND(incDir->c_str()))
{ {
std::string varName = incDir->substr(0, incDir->size()-9); std::string varName = incDir->substr(0, incDir->size()-9);
cmCacheManager::CacheIterator it = if(manager->GetCacheEntryPropertyAsBool(varName, "ADVANCED"))
manager->GetCacheIterator(varName.c_str());
if(it.GetPropertyAsBool("ADVANCED"))
{ {
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, this->GetCacheManager()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
type); doc, type);
// if there was a definition then remove it // if there was a definition then remove it
this->Internal->VarStack.top().Set(name, 0); this->Internal->VarStack.top().Set(name, 0);
} }
@ -2499,12 +2499,10 @@ std::vector<std::string> cmMakefile
this->Internal->VarStack.top().ClosureKeys(); this->Internal->VarStack.top().ClosureKeys();
res.insert(res.end(), definitions.begin(), definitions.end()); res.insert(res.end(), definitions.begin(), definitions.end());
} }
cmCacheManager::CacheIterator cit = std::vector<std::string> cacheKeys =
this->GetCacheManager()->GetCacheIterator(); this->GetCacheManager()->GetCacheEntryKeys();
for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() ) res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
{
res.push_back(cit.GetName());
}
std::sort(res.begin(), res.end()); std::sort(res.begin(), res.end());
return res; return res;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,9 +41,9 @@ bool cmVariableRequiresCommand
requirementsMet = false; requirementsMet = false;
notSet += args[i]; notSet += args[i];
notSet += "\n"; notSet += "\n";
cmCacheManager::CacheIterator it = cmCacheManager* manager = this->Makefile->GetCacheManager();
this->Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str()); if(manager->GetCacheEntryValue(args[i]) &&
if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED")) manager->GetCacheEntryPropertyAsBool(args[i], "ADVANCED"))
{ {
hasAdvanced = true; 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()); cmsys::Glob::PatternToRegex(entryPattern, true, true).c_str());
//go through all cache entries and collect the vars which will be removed //go through all cache entries and collect the vars which will be removed
std::vector<std::string> entriesToDelete; std::vector<std::string> entriesToDelete;
cmCacheManager::CacheIterator it = std::vector<std::string> cacheKeys =
this->CacheManager->GetCacheIterator(); this->CacheManager->GetCacheEntryKeys();
for ( it.Begin(); !it.IsAtEnd(); it.Next() ) 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) if(t != cmCacheManager::STATIC)
{ {
std::string entryName = it.GetName(); if (regex.find(it->c_str()))
if (regex.find(entryName.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 there is a CMakeCache.txt file, use its settings.
if(!cachePath.empty()) if(!cachePath.empty())
{ {
cmCacheManager* cachem = this->GetCacheManager(); if(this->LoadCache(cachePath))
cmCacheManager::CacheIterator it = cachem->NewIterator();
if(this->LoadCache(cachePath) &&
it.Find("CMAKE_HOME_DIRECTORY"))
{ {
this->SetHomeOutputDirectory(cachePath); const char* existingValue =
this->SetStartOutputDirectory(cachePath); this->CacheManager->GetCacheEntryValue("CMAKE_HOME_DIRECTORY");
this->SetHomeDirectory(it.GetValue()); if (existingValue)
this->SetStartDirectory(it.GetValue()); {
return; 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", ("CMAKE_USE_RELATIVE_PATHS", "OFF",
"If true, cmake will use relative paths in makefiles and projects.", "If true, cmake will use relative paths in makefiles and projects.",
cmCacheManager::BOOL); cmCacheManager::BOOL);
cmCacheManager::CacheIterator it = if (!this->CacheManager->GetCacheEntryProperty("CMAKE_USE_RELATIVE_PATHS",
this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS"); "ADVANCED"))
if ( !it.PropertyExists("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 = ""; std::string output = "";
if ( prop == "CACHE_VARIABLES" ) if ( prop == "CACHE_VARIABLES" )
{ {
cmCacheManager::CacheIterator cit = std::vector<std::string> cacheKeys =
this->GetCacheManager()->GetCacheIterator(); this->CacheManager->GetCacheEntryKeys();
for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() ) this->SetProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
{
if (!output.empty())
{
output += ";";
}
output += cit.GetName();
}
this->SetProperty("CACHE_VARIABLES", output.c_str());
} }
else if ( prop == "COMMANDS" ) else if ( prop == "COMMANDS" )
{ {
@ -2686,9 +2681,9 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
if(t == cmake::AUTHOR_WARNING) if(t == cmake::AUTHOR_WARNING)
{ {
// Allow suppression of these warnings. // Allow suppression of these warnings.
cmCacheManager::CacheIterator it = this->CacheManager const char* suppress = this->CacheManager->GetCacheEntryValue(
->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); "CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
if(!it.IsAtEnd() && it.GetValueAsBool()) if(suppress && cmSystemTools::IsOn(suppress))
{ {
return; return;
} }
@ -2801,37 +2796,42 @@ int cmake::Build(const std::string& dir,
} }
std::string cachePath = dir; std::string cachePath = dir;
cmSystemTools::ConvertToUnixSlashes(cachePath); cmSystemTools::ConvertToUnixSlashes(cachePath);
cmCacheManager::CacheIterator it = this->GetCacheManager()->NewIterator();
if(!this->LoadCache(cachePath)) if(!this->LoadCache(cachePath))
{ {
std::cerr << "Error: could not load cache\n"; std::cerr << "Error: could not load cache\n";
return 1; 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"; std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
return 1; return 1;
} }
cmsys::auto_ptr<cmGlobalGenerator> gen( cmsys::auto_ptr<cmGlobalGenerator> gen(
this->CreateGlobalGenerator(it.GetValue())); this->CreateGlobalGenerator(cachedGenerator));
if(!gen.get()) if(!gen.get())
{ {
std::cerr << "Error: could create CMAKE_GENERATOR \"" std::cerr << "Error: could create CMAKE_GENERATOR \""
<< it.GetValue() << "\"\n"; << cachedGenerator << "\"\n";
return 1; return 1;
} }
std::string output; std::string output;
std::string projName; 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"; std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
return 1; return 1;
} }
projName = it.GetValue(); projName = cachedProjectName;
bool verbose = false; 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, return gen->Build("", dir,
projName, target, projName, target,

View File

@ -328,25 +328,31 @@ int do_cmake(int ac, char const* const* av)
int res = cm.Run(args, view_only); int res = cm.Run(args, view_only);
if ( list_cached || list_all_cached ) if ( list_cached || list_all_cached )
{ {
cmCacheManager::CacheIterator it =
cm.GetCacheManager()->GetCacheIterator();
std::cout << "-- Cache values" << std::endl; 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 && if ( t != cmCacheManager::INTERNAL && t != cmCacheManager::STATIC &&
t != cmCacheManager::UNINITIALIZED ) t != cmCacheManager::UNINITIALIZED )
{ {
bool advanced = it.PropertyExists("ADVANCED"); const char* advancedProp =
if ( list_all_cached || !advanced) cm.GetCacheManager()->GetCacheEntryProperty(*it, "ADVANCED");
if ( list_all_cached || !advancedProp)
{ {
if ( list_help ) if ( list_help )
{ {
std::cout << "// " << it.GetProperty("HELPSTRING") << std::endl; std::cout << "// "
<< cm.GetCacheManager()->GetCacheEntryProperty(*it,
"HELPSTRING") << std::endl;
} }
std::cout << it.GetName() << ":" << std::cout << *it << ":" <<
cmCacheManager::TypeToString(it.GetType()) cmCacheManager::TypeToString(t)
<< "=" << it.GetValue() << std::endl; << "=" << cm.GetCacheManager()->GetCacheEntryValue(*it)
<< std::endl;
if ( list_help ) if ( list_help )
{ {
std::cout << std::endl; std::cout << std::endl;