Merge topic 'dev/fix-cache-variable-parsing-ambiguity'
8b143fa
Condense parsing of cache entries122ebf1
Support manual cache entries90abc3a
Use cmCacheManager to load entries from the cache6fe8624
Fix parsing of cache variables without a type
This commit is contained in:
commit
5b00b2a201
|
@ -93,14 +93,14 @@ bool cmCacheManager::LoadCache(const char* path,
|
|||
return this->LoadCache(path, internal, emptySet, emptySet);
|
||||
}
|
||||
|
||||
bool cmCacheManager::ParseEntry(const char* entry,
|
||||
std::string& var,
|
||||
std::string& value)
|
||||
static bool ParseEntryWithoutType(const char* entry,
|
||||
std::string& var,
|
||||
std::string& value)
|
||||
{
|
||||
// input line is: key:type=value
|
||||
// input line is: key=value
|
||||
static cmsys::RegularExpression reg(
|
||||
"^([^:]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
|
||||
// input line is: "key":type=value
|
||||
"^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
|
||||
// input line is: "key"=value
|
||||
static cmsys::RegularExpression regQuoted(
|
||||
"^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
|
||||
bool flag = false;
|
||||
|
@ -169,6 +169,11 @@ bool cmCacheManager::ParseEntry(const char* entry,
|
|||
value.size() - 2);
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
return ParseEntryWithoutType(entry, var, value);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
|
|
@ -139,10 +139,6 @@ public:
|
|||
std::string& value,
|
||||
CacheEntryType& type);
|
||||
|
||||
static bool ParseEntry(const char* entry,
|
||||
std::string& var,
|
||||
std::string& value);
|
||||
|
||||
///! Get a value from the cache given a key
|
||||
const char* GetCacheValue(const char* key) const;
|
||||
|
||||
|
|
|
@ -174,7 +174,8 @@ void cmLoadCacheCommand::CheckLine(const char* line)
|
|||
// Check one line of the cache file.
|
||||
std::string var;
|
||||
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.
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,6 @@ protected:
|
|||
|
||||
bool ReadWithPrefix(std::vector<std::string> const& args);
|
||||
void CheckLine(const char* line);
|
||||
bool ParseEntry(const char* entry, std::string& var, std::string& value);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -363,8 +363,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||
}
|
||||
std::string var, value;
|
||||
cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
|
||||
if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type) ||
|
||||
cmCacheManager::ParseEntry(entry.c_str(), var, value))
|
||||
if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
|
||||
{
|
||||
this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
|
||||
"No help, variable specified on the command line.", type);
|
||||
|
|
Loading…
Reference in New Issue