Explorar o código

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
David Cole %!s(int64=15) %!d(string=hai) anos
pai
achega
5b00b2a201

+ 11 - 6
Source/cmCacheManager.cxx

@@ -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;
 }
 

+ 0 - 4
Source/cmCacheManager.h

@@ -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;
 

+ 2 - 36
Source/cmLoadCacheCommand.cxx

@@ -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;
-}

+ 0 - 1
Source/cmLoadCacheCommand.h

@@ -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);
 };
 
 

+ 1 - 2
Source/cmake.cxx

@@ -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);