Merge topic 'dev/fix-cache-variable-parsing-ambiguity'

8b143fa Condense parsing of cache entries
122ebf1 Support manual cache entries
90abc3a Use cmCacheManager to load entries from the cache
6fe8624 Fix parsing of cache variables without a type
This commit is contained in:
David Cole 2010-11-23 16:12:24 -05:00 committed by CMake Topic Stage
commit 5b00b2a201
5 changed files with 14 additions and 49 deletions

View File

@ -93,14 +93,14 @@ bool cmCacheManager::LoadCache(const char* path,
return this->LoadCache(path, internal, emptySet, emptySet); return this->LoadCache(path, internal, emptySet, emptySet);
} }
bool cmCacheManager::ParseEntry(const char* entry, static bool ParseEntryWithoutType(const char* entry,
std::string& var, std::string& var,
std::string& value) std::string& value)
{ {
// input line is: key:type=value // input line is: key=value
static cmsys::RegularExpression reg( static cmsys::RegularExpression reg(
"^([^:]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
// input line is: "key":type=value // input line is: "key"=value
static cmsys::RegularExpression regQuoted( static cmsys::RegularExpression regQuoted(
"^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$"); "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
bool flag = false; bool flag = false;
@ -169,6 +169,11 @@ bool cmCacheManager::ParseEntry(const char* entry,
value.size() - 2); value.size() - 2);
} }
if (!flag)
{
return ParseEntryWithoutType(entry, var, value);
}
return flag; return flag;
} }

View File

@ -139,10 +139,6 @@ public:
std::string& value, std::string& value,
CacheEntryType& type); CacheEntryType& type);
static bool ParseEntry(const char* entry,
std::string& var,
std::string& value);
///! Get a value from the cache given a key ///! Get a value from the cache given a key
const char* GetCacheValue(const char* key) const; const char* GetCacheValue(const char* key) const;

View File

@ -174,7 +174,8 @@ void cmLoadCacheCommand::CheckLine(const char* line)
// Check one line of the cache file. // Check one line of the cache file.
std::string var; std::string var;
std::string value; std::string value;
if(this->ParseEntry(line, var, value)) cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
if(cmCacheManager::ParseEntry(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())
@ -193,38 +194,3 @@ void cmLoadCacheCommand::CheckLine(const char* line)
} }
} }
} }
//----------------------------------------------------------------------------
bool cmLoadCacheCommand::ParseEntry(const char* entry, std::string& var,
std::string& value)
{
// input line is: key:type=value
cmsys::RegularExpression reg("^([^:]*):([^=]*)=(.*[^\t ]|[\t ]*)[\t ]*$");
// input line is: "key":type=value
cmsys::RegularExpression
regQuoted("^\"([^\"]*)\":([^=]*)=(.*[^\t ]|[\t ]*)[\t ]*$");
bool flag = false;
if(regQuoted.find(entry))
{
var = regQuoted.match(1);
value = regQuoted.match(3);
flag = true;
}
else if (reg.find(entry))
{
var = reg.match(1);
value = reg.match(3);
flag = true;
}
// if value is enclosed in single quotes ('foo') then remove them
// it is used to enclose trailing space or tab
if (flag &&
value.size() >= 2 &&
value[0] == '\'' &&
value[value.size() - 1] == '\'')
{
value = value.substr(1, value.size() - 2);
}
return flag;
}

View File

@ -83,7 +83,6 @@ protected:
bool ReadWithPrefix(std::vector<std::string> const& args); bool ReadWithPrefix(std::vector<std::string> const& args);
void CheckLine(const char* line); void CheckLine(const char* line);
bool ParseEntry(const char* entry, std::string& var, std::string& value);
}; };

View File

@ -363,8 +363,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
} }
std::string var, value; std::string var, value;
cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED; cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type) || if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
cmCacheManager::ParseEntry(entry.c_str(), var, value))
{ {
this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(), this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
"No help, variable specified on the command line.", type); "No help, variable specified on the command line.", type);