[Cmake-commits] CMake branch, next, updated. v2.8.12-3865-g2857fd5

Nils Gladitz nilsgladitz at gmail.com
Fri Oct 11 13:08:23 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  2857fd506b632088aa548490ea15be694ac51e7d (commit)
       via  d73dc7f04e8530f16c60d96f218c63f7c5543272 (commit)
      from  08ec9ce928ce3f8891cf9c441402221f979f3a86 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2857fd506b632088aa548490ea15be694ac51e7d
commit 2857fd506b632088aa548490ea15be694ac51e7d
Merge: 08ec9ce d73dc7f
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Fri Oct 11 13:08:16 2013 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Oct 11 13:08:16 2013 -0400

    Merge topic 'wix-deterministic-ids' into next
    
    d73dc7f CPackWiX: generate deterministic ids for directories, components and files


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d73dc7f04e8530f16c60d96f218c63f7c5543272
commit d73dc7f04e8530f16c60d96f218c63f7c5543272
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Thu Oct 10 22:49:33 2013 +0200
Commit:     Nils Gladitz <nilsgladitz at gmail.com>
CommitDate: Thu Oct 10 22:49:33 2013 +0200

    CPackWiX: generate deterministic ids for directories, components and files

diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index cc9dec7..344d1ff 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -1,6 +1,6 @@
 /*============================================================================
   CMake - Cross Platform Makefile Generator
-  Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
+  Copyright 2000-2013 Kitware, Inc., Insight Software Consortium
 
   Distributed under the OSI-approved BSD License (the "License");
   see accompanying file Copyright.txt for details.
@@ -14,6 +14,7 @@
 
 #include <cmSystemTools.h>
 #include <cmGeneratedFileStream.h>
+#include <cmCryptoHash.h>
 #include <CPack/cmCPackLog.h>
 #include <CPack/cmCPackComponentGroup.h>
 
@@ -319,9 +320,6 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
     directoryDefinitions.AddAttribute("Name", install_root[i]);
   }
 
-  size_t directoryCounter = 0;
-  size_t fileCounter = 0;
-
   std::string fileDefinitionsFilename =
     cpackTopLevel + "/files.wxs";
 
@@ -367,7 +365,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
     if (!cpackVendor || !cpackPkgName)
       {
       cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_PACKAGE_VENDOR and "
-                    "CPACK_PACKAGE_NAME must be defined for shortcut creation" << std::endl);
+        "CPACK_PACKAGE_NAME must be defined for shortcut creation"
+        << std::endl);
       cpackPkgExecutables.clear();
       }
     else
@@ -380,7 +379,7 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
   AddDirectoryAndFileDefinitons(
     toplevel, "INSTALL_ROOT",
     directoryDefinitions, fileDefinitions, featureDefinitions,
-    directoryCounter, fileCounter, cpackPkgExecutables, dirIdExecutables);
+    cpackPkgExecutables, dirIdExecutables);
 
   directoryDefinitions.EndElement();
   directoryDefinitions.EndElement();
@@ -403,7 +402,10 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
       std::string directoryId = *it;
 
       fileDefinitions.BeginElement("Shortcut");
-      std::string shortcutName = fileName; // the iconName is mor likely to contain blanks early on
+
+      // the iconName is more likely to contain blanks early on
+      std::string shortcutName = fileName;
+
       std::string::size_type const dotPos = shortcutName.find('.');
       if(std::string::npos == dotPos)
         { shortcutName = shortcutName.substr(0, dotPos); }
@@ -531,8 +533,6 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
   cmWIXSourceWriter& directoryDefinitions,
   cmWIXSourceWriter& fileDefinitions,
   cmWIXSourceWriter& featureDefinitions,
-  size_t& directoryCounter,
-  size_t& fileCounter,
   const std::vector<std::string>& pkgExecutables,
   std::vector<std::string>& dirIdExecutables)
 {
@@ -550,11 +550,14 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
 
     std::string fullPath = topdir + "/" + fileName;
 
+    std::string relativePath = cmSystemTools::RelativePath(
+      toplevel.c_str(), fullPath.c_str());
+
+    std::string id = PathToId(relativePath);
+
     if(cmSystemTools::FileIsDirectory(fullPath.c_str()))
       {
-      std::stringstream tmp;
-      tmp << "DIR_ID_" << ++directoryCounter;
-      std::string subDirectoryId = tmp.str();
+      std::string subDirectoryId = std::string("CM_D") + id;
 
       directoryDefinitions.BeginElement("Directory");
       directoryDefinitions.AddAttribute("Id", subDirectoryId);
@@ -565,20 +568,14 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
         directoryDefinitions,
         fileDefinitions,
         featureDefinitions,
-        directoryCounter,
-        fileCounter,
         pkgExecutables,
         dirIdExecutables);
       directoryDefinitions.EndElement();
       }
     else
       {
-      std::stringstream tmp;
-      tmp << "_ID_" << ++fileCounter;
-      std::string idSuffix = tmp.str();
-
-      std::string componentId = std::string("CMP") + idSuffix;
-      std::string fileId = std::string("FILE") + idSuffix;
+      std::string componentId = std::string("CM_C") + id;
+      std::string fileId = std::string("CM_F") + id;
 
       fileDefinitions.BeginElement("DirectoryRef");
       fileDefinitions.AddAttribute("Id", directoryId);
@@ -686,3 +683,119 @@ std::string cmCPackWIXGenerator::GetRightmostExtension(
 
   return cmSystemTools::LowerCase(extension);
 }
+
+std::string cmCPackWIXGenerator::PathToId(const std::string& path)
+{
+  id_map_t::const_iterator i = pathToIdMap.find(path);
+  if(i != pathToIdMap.end()) return i->second;
+
+  std::string id = CreateNewIdForPath(path);
+  return id;
+}
+
+std::string cmCPackWIXGenerator::CreateNewIdForPath(const std::string& path)
+{
+  std::vector<std::string> components;
+  cmSystemTools::SplitPath(path.c_str(), components, false);
+
+  size_t replacementCount = 0;
+
+  std::string identifier;
+  std::string currentComponent;
+
+  for(std::size_t i = 1; i < components.size(); ++i)
+    {
+    if(i != 1) identifier += '.';
+
+    currentComponent = NormalizeComponentForId(
+      components[i], replacementCount);
+
+    identifier += currentComponent;
+    }
+
+  std::string idPrefix = "P";
+  size_t replacementPercent = replacementCount * 100 / identifier.size();
+  if(replacementPercent > 33 || identifier.size() > 60)
+    {
+    identifier = CreateHashedId(path, currentComponent);
+    idPrefix = "H";
+    }
+
+  std::stringstream result;
+  result << idPrefix << "_" << identifier;
+
+  size_t ambiguityCount = ++idAmbiguityCounter[identifier];
+
+  if(ambiguityCount > 999)
+    {
+    cmCPackLogger(cmCPackLog::LOG_ERROR,
+      "Error while trying to generate a unique Id for '" <<
+      path << "'" << std::endl);
+
+    return std::string();
+    }
+  else if(ambiguityCount > 1)
+    {
+    result << "_" << ambiguityCount;
+    }
+
+  std::string resultString = result.str();
+
+  pathToIdMap[path] = resultString;
+
+  return resultString;
+}
+
+std::string cmCPackWIXGenerator::CreateHashedId(
+  const std::string& path, const std::string& normalizedFilename)
+{
+  cmsys::auto_ptr<cmCryptoHash> sha1 = cmCryptoHash::New("SHA1");
+  std::string hash = sha1->HashString(path.c_str());
+
+  std::string identifier;
+  identifier += hash.substr(0, 7) + "_";
+
+  const size_t maxFileNameLength = 52;
+  if(normalizedFilename.length() > maxFileNameLength)
+    {
+    identifier += normalizedFilename.substr(0, maxFileNameLength - 3);
+    identifier += "...";
+    }
+  else
+    {
+    identifier += normalizedFilename;
+    }
+
+  return identifier;
+}
+
+std::string cmCPackWIXGenerator::NormalizeComponentForId(
+  const std::string& component, size_t& replacementCount)
+{
+  std::string result;
+  result.resize(component.size());
+
+  for(std::size_t i = 0; i < component.size(); ++i)
+    {
+    char c = component[i];
+    if(IsLegalIdCharacter(c))
+      {
+      result[i] = c;
+      }
+    else
+      {
+      result[i] = '_';
+      ++ replacementCount;
+      }
+    }
+
+  return result;
+}
+
+bool cmCPackWIXGenerator::IsLegalIdCharacter(char c)
+{
+  return (c >= '0' && c <= '9') ||
+      (c >= 'a' && c <= 'z') ||
+      (c >= 'A' && c <= 'Z') ||
+      c == '_' || c == '.';
+}
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h
index aaccf9d..1380a17 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.h
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.h
@@ -54,6 +54,9 @@ protected:
     }
 
 private:
+  typedef std::map<std::string, std::string> id_map_t;
+  typedef std::map<std::string, size_t> ambiguity_map_t;
+
   bool InitializeWiXConfiguration();
 
   bool PackageFilesImpl();
@@ -82,13 +85,10 @@ private:
     cmWIXSourceWriter& directoryDefinitions,
     cmWIXSourceWriter& fileDefinitions,
     cmWIXSourceWriter& featureDefinitions,
-    size_t& directoryCounter,
-    size_t& fileCounter,
     const std::vector<std::string>& pkgExecutables,
     std::vector<std::string>& dirIdExecutables
     );
 
-
   bool RequireOption(const std::string& name, std::string& value) const;
 
   std::string GetArchitecture() const;
@@ -99,7 +99,21 @@ private:
 
   static std::string GetRightmostExtension(const std::string& filename);
 
+  std::string PathToId(const std::string& path);
+
+  std::string CreateNewIdForPath(const std::string& path);
+
+  static std::string CreateHashedId(
+    const std::string& path, const std::string& normalizedFilename);
+
+  std::string NormalizeComponentForId(
+    const std::string& component, size_t& replacementCount);
+
+  static bool IsLegalIdCharacter(char c);
+
   std::vector<std::string> wixSources;
+  id_map_t pathToIdMap;
+  ambiguity_map_t idAmbiguityCounter;
 };
 
 #endif

-----------------------------------------------------------------------

Summary of changes:
 Source/CPack/WiX/cmCPackWIXGenerator.cxx |  153 ++++++++++++++++++++++++++----
 Source/CPack/WiX/cmCPackWIXGenerator.h   |   20 ++++-
 2 files changed, 150 insertions(+), 23 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list